var imageTag = false;
var theSelection = false;
var clientPC = navigator.userAgent.toLowerCase(); 
var clientVer = parseInt(navigator.appVersion); 
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_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[q]','[/q]','[list]','[/list]','[listn]','[/listn]','(url)','(/url)','[TRANS]','[/TRANS]');
imageTag = false;

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function checkForm() {
	formErrors = false;    
bbstyle(-1);
		return true;
}

function emoticon(text) {
	var txtarea = document.postform.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.postform.message;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}

function bbstyle(bbnumber) {
	var txtarea = document.postform.message;

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.postform.addbbcode' + butnumber + '.value');
			eval('document.postform.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.postform.addbbcode' + butnumber + '.value');
				eval('document.postform.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags
		
		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 15) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.postform.addbbcode'+bbnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

function ins(name){
if (document.postform) {
var input=document.postform.message;
input.value=input.value+"[b]"+"Re"+"[/b]"+name+" \n";
}
}

function translit(name){
  if (document.postform) {
     var input=document.postform.message;
     input.value=input.value+name;
    }
}


if (document.selection||document.getSelection) {Q=true} else {var Q=false}
var txt=''
function copyQ() {
txt=''
if (document.getSelection) {txt=document.getSelection()}
else if (document.selection) {txt=document.selection.createRange().text;}
txt='[q]'+txt+'[/q]\n'
}
function pasteQ() {
document.postform.message.value=document.postform.message.value+txt;
}

function sm(text){
if (text!="") paste(text, 1);
}

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;
       }
    }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function WERX(Url,path){
   document.write('<a href="#" ');
   document.write('OnClick="window.open(\''+Url+'?act=IP_new&ip_opred='+path+'\', ');
   document.write('\'\', \'height=650,width=400,left=600,toolbar=no,scrollbars=yes\', ');
   document.write('false); return true;" title=\'&#1087;&#1086;&#1089;&#1084;&#1086;&#1090;&#1088;&#1077;&#1090;&#1100; &#1080;&#1085;&#1092;&#1086;&#1088;&#1084;&#1072;&#1094;&#1080;&#1102; &#1086;&#1073; Ip\'>');
 }
function NIZ(){ document.write( '</a>' ); }
function gosub() {
  var a=document.f.day.value;
  var b=document.f.month.value;
  var c=document.f.year.value;
  var url='all.php?act=GOR&day='+a+'&month='+b+'&year='+c;
  WRSubs=window.open(url,'WRSubs','width=330,height=170,toolbar=no');
  WRSubsfocus();
}
function Myform() {
 var i
 var f='<p align="justify">&nbsp;</p><form name="f" method="post">\n&#1055;&#1088;&#1086;&#1074;&#1077;&#1088;&#1100;&#1090;&#1077; &#1042;&#1072;&#1096; &#1079;&#1085;&#1072;&#1082; &#1047;&#1086;&#1076;&#1080;&#1072;&#1082;&#1072;: ';
 var day='<select name="day" class="dats">\n<option value="" selected>&#1044;&#1077;&#1085;&#1100;</option>\n';
 var month='<select name="month" class="dats">\n<option value="" selected>&#1052;&#1077;&#1089;&#1103;&#1094;</option>\n<option value="1">&#1071;&#1085;&#1074;&#1072;&#1088;&#1100;</option>\n<option value="2">&#1060;&#1077;&#1074;&#1088;&#1072;&#1083;&#1100;</option>\n<option value="3">&#1052;&#1072;&#1088;&#1090;</option>\n<option value="4">&#1040;&#1087;&#1088;&#1077;&#1083;&#1100;</option>\n<option value="5">&#1052;&#1072;&#1081;</option>\n<option value="6">&#1048;&#1102;&#1085;&#1100;</option>n<option value="7">&#1048;&#1102;&#1083;&#1100;</option>\n<option value="8">&#1040;&#1074;&#1075;&#1091;&#1089;&#1090;</option>\n<option value="9">&#1057;&#1077;&#1085;&#1090;&#1103;&#1073;&#1088;&#1100;</option>\n<option value="10">&#1054;&#1082;&#1090;&#1103;&#1073;&#1088;&#1100;</option>\n<option value="11">&#1053;&#1086;&#1103;&#1073;&#1088;&#1100;</option>\n<option value="12">&#1044;&#1077;&#1082;&#1072;&#1073;&#1088;&#1100;</option>\n</select>\n';
 var year='<select name="year" class="dats"><option value="" selected>&#1043;&#1086;&#1076;</option>\n';
 for(i =1; i < 32; i++){
   day +='<option value="'+i+'">'+i+'</option>\n';
 }
 day +='</select>\n';
 for(i=2009; i > 1899; i--){
   year +='<option value="'+i+'">'+i+'</option>\n';
 }
 year +='</select>\n';
 f += day+month+year+'<input class="submit" name="submit" value="go" type="submit" onclick="gosub(this);">\n</form><p align="justify">&nbsp;</p>';
 document.write(f);
}
function Return_Mail(a,b,c) {  
  var path='<a href="mailto:'+a+'@'+c+'"><img border="0" src="'+b+'/img/mail.gif" width="14" height="10"></a>';
  document.write(path);  
  }
function crop(maxlen){ 
  if(document.postform.message.value.length > maxlen) {
    document.postform.message.value = document.postform.message.value.substring(0, maxlen); 
   }                          
  len = maxlen - document.postform.message.value.length; 
  if(len < 0) { len = 0; }
  document.postform.limit.value = len;    
} 
function MyformPR(){
 document.write('<form name="fff" method="post">Url: <input class="dats" type="text" name="url" value="" size="60">  <input class="submit" name="submit" value="go" type="submit" onclick="PR(this);">\n</form>');
}  
function PR() {
  var urls='all.php?act=GooglePR&prurl='+escape(document.fff.url.value);
  RSubs=window.open(urls,'RSubs','width=600,height=500,toolbar=no');
  RSubsfocus();
}
function MyformPR_TIZ(){
 document.write('<form name="ff" method="post">PR: <input class="dats" type="text" name="Sait_Page_Rank" value="" size="3"> Tиц: <input class="dats" type="text" name="Sait_TIZ" value="" size="3"> Количество внешних ссылок: <input class="dats" type="text" name="Sait_LINK" value="" size="3">  <input class="submit" name="submit" value="go" type="submit" onclick="PR_TIZ(this);">\n</form>');
}  
function PR_TIZ() {
  var urls='all.php?act=price_tiz_pr&Sait_Page_Rank='+document.ff.Sait_Page_Rank.value+'&Sait_TIZ='+document.ff.Sait_TIZ.value+'&Sait_LINK='+document.ff.Sait_LINK.value;
  Subs=window.open(urls,'Subs','width=600,height=500,toolbar=no');
  Subsfocus();
}
function show_menu(id) {
  var menu = document.getElementById('menu_'+id);
  if(menu.style.display == 'none') {menu.style.display = 'block';}
  else {menu.style.display = 'none';};
}
function zajavka_ok(url,tel) {
  var TEL='';
  if(tel){ TEL = ".telefon."+tel; }
  var URL=url+TEL+'.html';
  SSubs=window.open(URL,'SSubs','width=200,height=200,toolbar=no');
  SSubsfocus();
}
