	 // Startup variables
	 var theSelection = false;

	 // Check for Browser & Platform for PC & IE specific bits
	 // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
	 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
	 var clientVer = parseInt(navigator.appVersion); // Get browser version

	 var is_ie = ((clientPC.indexOf("msie") != -1) || (clientPC.indexOf("opera") == -1));
	 var is_nav  = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
     	             && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
        	         && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

	 var is_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
	 var is_mac    = (clientPC.indexOf("mac")!=-1);
     function storeCaret (textEl) {
       if (textEl.createTextRange)
         textEl.caretPos = document.selection.createRange().duplicate();
     }

     function insertAtCaret (textEl,txt) {
         var bbopen  = '[' + txt + ']';
         var bbclose = '[/' + txt + ']';
         var all = bbopen + 'xxx' + bbclose;

	  	if ((clientVer >= 4) && is_ie && is_win) {
		  theSelection = document.selection.createRange().text;
		  if (!theSelection) {
			  document.postform.inpost.value += all;
			  document.postform.inpost.focus();
			  return;
		  }		  
		   document.selection.createRange().text = bbopen + theSelection + bbclose;
		   document.postform.inpost.focus();

		  return;
		}
		else if (document.postform.inpost.selectionEnd &&
				     (document.postform.inpost.selectionEnd - document.postform.inpost.selectionStart > 0)){
			mozWrap(document.postform.inpost, bbopen, bbclose);
			return;
		}
		else{
			document.postform.inpost.value += all;
			txtarea.focus();
		}
		storeCaret(document.postform.inpost);
}     




     
//     function insertAtCaret1 (textEl,txt) {
//     }

     function mozWrap(txtarea, open, close){
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd == 1 || selEnd == 2)
			selEnd = selLength;

		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);

		if (open == 'trans'){
			 txtarea.value = s1 + translate(s2) + s3;
		}
		else {
			 txtarea.value = s1 + open + s2 + close + s3;
		}
	return;
	}

function SubmitControl(tocheack){ 
 if (document.all || document.getElementById){ 
     for (i=0; i < tocheack.length;i++){ 
          if(tocheack.elements[i].type.toLowerCase()=="submit"||tocheack.elements[i].type.toLowerCase()=="reset") { 
             tocheack.elements[i].disabled = true;              
             tocheack.elements[i].style.backgroundColor = "#C1C1C1";
            } 
         } 
    } 
}

function EnableButton(tocheack){ 
 if (document.all || document.getElementById){ 
     for (i=0; i < tocheack.length;i++){
          if(tocheack.elements[i].type.toLowerCase()=="submit"||tocheack.elements[i].type.toLowerCase()=="reset") { 
             tocheack.elements[i].disabled = false;              
             tocheack.elements[i].style.backgroundColor = "#000000";
            } 
         } 
    } 
}

function copyQ(name) { 
if (name != '') {
	var bname = "[b]" + name + " пишет:[/b]\n";
}
txt='' 
if (document.getSelection) {txt=document.getSelection()} 
else if (document.selection) {txt=document.selection.createRange().text;} 
txt='[q]'+bname+txt+'[/q]\n'} 

//function pasteQ1() { 
//document.postform.inpost.value=document.postform.inpost.value+txt;
//document.postform.inpost.focus();
//} 

function pasteQ(name) { 
//IE 
if (document.selection) { 
document.postform.inpost.focus(); 
sel = document.selection.createRange(); 
sel.text = txt; 
} 
//others 
else if (document.postform.inpost.selectionStart || document.postform.inpost.selectionStart == 0) { 
var startPos = document.postform.inpost.selectionStart; 
var endPos = document.postform.inpost.selectionEnd; 
document.postform.inpost.value = document.postform.inpost.value.substring(0, startPos) 
+ txt 
+ document.postform.inpost.value.substring(endPos, document.postform.inpost.value.length); 
} else { 
document.postform.inpost.value += txt; 
}
} 

function paste(name){ 
if (name != '') document.postform.inpost.value = document.postform.inpost.value+"[b]"+name+"[/b]\n";
}
function sm_gigi() { 
txt=''
txt=':gigi:' 
} 
function sm_lol() { 
txt=''
txt=':lol:' 
} 
function sm_up() { 
txt=''
txt=':up:' 
} 
function sm_down() { 
txt=''
txt=':down:' 
} 
function sm_super() { 
txt=''
txt=':super:' 
} 
function sm_kruto() { 
txt=''
txt=':kruto:' 
} 
function sm_uhm() { 
txt=''
txt=':-\\' 
} 
function sm_abuse() { 
txt=''
txt=':abuse:' 
} 
function SelectAll (chbox, chtext){        
 for(var i =0; i < chbox.form.elements.length; i++){
     if(chbox.form.elements[i].name.indexOf(chtext) == 0){
        chbox.form.elements[i].checked = chbox.checked;
       }
    }
}
