function _getElementById(id){
  var item = null;

  if (document.getElementById){
    item = document.getElementById(id);
  } else if (document.all){
    item = document.all[id];
  } else if (document.layers){
    item = document.layers[id];
  }

  return item;
}

function ShowOrHide(d1, d2) {
  if (d1 != ''){
  	DoDiv(d1);
  }

  if (d2 != ''){
  	DoDiv(d2);
  }
}

function DoDiv(id) {
  var item = _getElementById(id);

  if (!item){
  } else if (item.style){
    if (item.style.display == 'none'){
    	item.style.display = '';
    } else {
    	item.style.display = 'none';
  	}
  } else {
  	item.visibility = 'show';
  }
}

function smile(str){
	obj = document.Sad_Raven.text;
	obj.focus();
	obj.value =	obj.value + str;
}

function openBrWindow(theURL,winName,features){
  	window.open(theURL,winName,features);
}
function inserttags(st_t, en_t){ 
	obj = document.Sad_Raven.text;
	obj2 = document.Sad_Raven;
	if ((document.selection)) {
		obj.focus();
		obj2.document.selection.createRange().text = st_t+obj2.document.selection.createRange().text+en_t;
	}
	else 
	{
		obj.focus();
		obj.value += st_t+en_t;
	}
}


 // var maxKeys = 2000;
	var maxKeys;
	var keysSoFar = 0;
	var alerted = false;

function change(what, whatValue, maxKeys) {
    if (!alerted) alert('Ââåäåííûé òåêñò íå äîëæåí ïðåâûøàòü ' + maxKeys + ' ñèìâîëîâ!');
	if ((maxKeys-1) < 0) {
	    what.value = "0";
	}
	else {
	    what.value = what.value.substring(0,maxKeys-1); // chop after maxlength
	}
    alerted = true;
}

function keyup(what,whatValue, maxKeys) {
    keysSoFar++;
    if (keysSoFar >= maxKeys) {
        if (!alerted) alert('Ââåäåííûé òåêñò íå äîëæåí ïðåâûøàòü ' + maxKeys + ' ñèìâîëîâ!');
		if ((maxKeys-1) < 0) {
		    what.value = "0";
		}
		else {
	        what.value = what.value.substring(0,maxKeys-1); // chop the last typed char
		}
        alerted = true;
		
		// DISPLAY MESSAGE
		change(what,whatValue, maxKeys);
    }
	else {
        alerted = false;
	}

	// DISPLAY LENGTH
	if ((maxKeys - whatValue.length - 1) > 0) {
		document.forms['Sad_Raven'].elements['counter'].value = (maxKeys - whatValue.length - 1);
	}
	else {
		document.forms['Sad_Raven'].elements['counter'].value = "0";
	}
	keysSoFar = whatValue.length;
}

function blockEnter(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13) {
		return false;
	} 
	else {
		return true;
	}
}