//document.old_onkeypress = document.onkeypress;
document.onkeypress = function(e)
{ 
//   document.old_onkeypress(e); 
   Key = window.event; 
   if (Key.keyCode == 10 || (Key.keyCode == 13 && Key.ctrlKey)) 
       insert_teg("[br]"); 
} 

function insert_teg(a) 
{
var form_id = event.srcElement.id;
 if(form_id != "")
 {
	if (document.getElementById(form_id).createTextRange) 
		{
		document.getElementById(form_id).focus();
		document.selection.createRange().duplicate().text = a;
		}
	else 
		{
		document.getElementById(form_id).value += a;
		}
 }
}

function alert_text(a)
{
alert(a);
}

function my_submit(a)
{ 
 document.all.value_submit.value = a;
 return true; 
}

function TextAreaLineNum(id, is_rows)
{
//alert(id);
var obj = document.getElementById(id);
//alert (obj.rows);
//var is_rows = obj.rows;
var rowHeight = obj.clientHeight/obj.rows;
var curHeight = obj.createTextRange().boundingHeight;
var count = parseInt(curHeight/rowHeight)+(obj.value!=''?1:0);
var count_is = obj.rows; 
obj.rows = count+1;
//alert (obj.rows);
if(count > 40)obj.rows = 40;
if(count < is_rows)obj.rows = is_rows;
}

function img_id(id, is_rows)
{
alert(id);
}

function insertAtCursor(IdField, myValue) {
  //  Для MSIE
  MyField = document.getElementById(IdField);
  if (document.selection) {
    MyField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  // Для нормальных браузеров
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
  }
  // Для остальных ;)
  else {
    myField.value += myValue;
  }
} // insertAtCursor 


function insertTagAround(elem, tagstart, tagend) {
  // Mozilla и другие вменяемые браузеры
  if (elem.setSelectionRange) {
	elem.value = elem.value.substring(0, elem.selectionStart) +
				  tagstart +
				  elem.value.substring(elem.selectionStart, elem.selectionEnd) +
				  tagend +
				  elem.value.substring(elem.selectionEnd, elem.value.length);
  }
  // MSIE
  else {
	var selectedText = document.selection.createRange().text;
	if (selectedText != "") {
	  var newText = tagstart + selectedText + tagend;
	  document.selection.createRange().text = newText;
	}
  }
} // insertTag


function $(v) { return(document.getElementById(v)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }
function dragOBJ(d,e)
{
 function drag(e){ if(!stop){ d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } }
 var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;
 document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; };
}
