function validateFormReg(form){
var errors='';
if (form.login.value == "") errors = 'Вы не указали логин\n';
if ((form.login.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина логина за пределами 3-15 символов\n';
if (form.pass.value == "") errors = errors + 'Вы не ввели пароль\n';
if ((form.pass.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина пароля за пределами 3-15 символов\n';
if (form.pass.value != form.pass2.value) errors = errors + 'Подтверждение пароля не верно\n';
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function validateFormСReg(form){
var errors='';
if (form.pass.value == "") errors = 'Вы не ввели пароль\n';
if ((form.pass.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина пароля за пределами 3-15 символов\n';
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function validateFormEt(form){
var errors='';
if (form.login.value == "") errors = 'Вы не указали логин\n';
if ((form.login.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина логина за пределами 3-15 символов\n';
if (form.pass.value == "") errors = errors + 'Вы не ввели пароль\n';
if ((form.pass.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина пароля за пределами 3-15 символов\n';
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function validateFormPs(form){
var errors='';
if (form.login.value == "") errors = 'Вы не указали логин\n';
if ((form.login.value.length<3) || (form.login.value.length>15)) errors = errors + 'длина логина за пределами 3-15 символов\n';
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function validateFormFind(form){
var errors='';
if (form.src.value == "" && form.avt.value == "") errors = 'Вы не ввели слова для поиска\n';
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function substrCount(s, substr) {
	var cnt = 0;
	for (var i = s.indexOf(substr); i!=-1; i = s.indexOf(substr, i+1)) {
		cnt++;
	}
	return cnt;
}

function checkMessage(msg) {
	var errors='';
	if (msg == "") errors += 'Вы не ввели сообщение\n';
	if (substrCount(msg, "[font") != substrCount(msg, "[/font]")) errors = errors + 'Не закрыт тэг [font\n';
	if (substrCount(msg, "[quote") != substrCount(msg, "[/quote]")) errors = errors + 'Не закрыт тэг [quote]\n';
	if (substrCount(msg, "[td]") != substrCount(msg, "[/td]")) errors = errors + 'Не закрыт тэг [td]\n';
	if (substrCount(msg, "[tr]") != substrCount(msg, "[/tr]")) errors = errors + 'Не закрыт тэг [tr]\n';
	if (substrCount(msg, "[table]") != substrCount(msg, "[/table]")) errors = errors + 'Не закрыт тэг [table]\n';
	if (substrCount(msg, "[b]") != substrCount(msg, "[/b]")) errors = errors + 'Не закрыт тэг [b]\n';
	if (substrCount(msg, "[i]") != substrCount(msg, "[/i]")) errors = errors + 'Не закрыт тэг [i]\n';
	if (substrCount(msg, "[u]") != substrCount(msg, "[/u]")) errors = errors + 'Не закрыт тэг [u]\n';
	if (substrCount(msg, "[small]") != substrCount(msg, "[/small]")) errors = errors + 'Не закрыт тэг [small]\n';
	return errors;
}

function validateFormNew(form){
var errors='';
if (form.title.value == "") errors = 'Вы не ввели тему сообщения\n';
errors += checkMessage(form.soob.value);
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function validateFormNewAn(form){
var errors='';
errors += checkMessage(form.soob.value);
if (errors) alert(errors);
document.returnValue = (errors == '')
}

function go_raz(form){
   var url="raz_id" + form.value+ ".htm";
   window.location=url;
}

function go_top(form){
   var url="v_id" + form.value+ ".htm";
   window.location=url;
}

function paste(form, text, flag){
form.soob.focus();
if ((document.selection)&&(flag)) {
	form.document.selection.createRange().text = text
} else form.soob.value += text
}

function bol(form, text){
if (text!="") paste(form,"[b]"+text+"[/b]\n", 1)
}

function bol_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[b]"+vd.text+"[/b]";}
	else {
		text = prompt('\nвведите текст:','') || "";
	    bol(form, text);
		}
} else {
	text = prompt('\nвведите текст:','') || "";
    bol(form, text);
	}
}

function it_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[i]"+vd.text+"[/i]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[i]"+text+"[/i]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[i]"+text+"[/i]\n", 1)
	}
}

function un_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[u]"+vd.text+"[/u]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[u]"+text+"[/u]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[u]"+text+"[/u]\n", 1)
	}
}

function s_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[small]"+vd.text+"[/small]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[small]"+text+"[/small]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[small]"+text+"[/small]\n", 1)
	}
}

function sp_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[sup]"+vd.text+"[/sup]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[sup]"+text+"[/sup]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[sup]"+text+"[/sup]\n", 1)
	}
}

function sb_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[sub]"+vd.text+"[/sub]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[sub]"+text+"[/sub]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[sub]"+text+"[/sub]\n", 1)
	}
}

function off_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[off]"+vd.text+"[/off]";}
	else {
		text = prompt('\nвведите текст:','') || "";
		if (text!="") paste(form,"[off]"+text+"[/off]\n", 1)
		}
} else {
	text = prompt('\nвведите текст:','') || "";
	if (text!="") paste(form,"[off]"+text+"[/off]\n", 1)
	}
}

function color_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[font color=black]"+vd.text+"[/font]";}
	else {
		color = prompt('\nвведите цвет:','') || "";
		text = prompt('\nвведите текст:','') || "";
		if (text!="") {
        	if (color!="") {paste(form,"[font color="+color+"]"+text+"[/font]\n", 1);}
            else {paste(form,"[font color=black]"+text+"[/font]\n", 1);}
        }
		}
} else {
	color = prompt('\nвведите цвет:','') || "";
	text = prompt('\nвведите текст:','') || "";
	if (text!="") {
       	if (text!="") {paste(form,"[font color="+color+"]"+text+"[/font]\n", 1);}
        else {paste(form,"[font color=black]"+text+"[/font]\n", 1);}
    }
	}
}

function add_txt(form, text){
	form.soob.focus();
	if (document.selection) {
		vd = form.document.selection.createRange();
    	vd.text = text;
	} else {
		paste(form, text, 1)
	}
}

function add_hyperlink(form){
	form.soob.focus();
	if (document.selection) {
		vd = form.document.selection.createRange();
    	var _url = prompt('\nВведите адрес :', 'http://');
		if (_url) {
    		if (vd.text == "") {
				var text = prompt('\nВведите текст :', '');
				vd.text = "[url="+_url+"]" + text + "[/url]";
			} else {
				vd.text = "[url="+_url+"]" + vd.text + "[/url]";
			}
    	}
	}
	return;
}

function add_picture(form){
	form.soob.focus();
   	var _url = prompt('\nВведите URL картинки :', 'http://');
   	if (_url) {
   		paste(form, "[img]" + _url + "[/img]");
   	}
	return;
}
function im_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[img]"+vd.text+"[/img]";}
	else {
		img = prompt('\nвведите ссылку на рисунок:','http://') || "";
		text = prompt('\nвведите текст подсказки:','') || "";
		if (img!="") {
        	if (text!="") {paste(form,"[img="+text+"]"+img+"[/img]\n", 1);}
            else {paste(form,"[img]"+img+"[/img]\n", 1);}
        }
		}
} else {
	img = prompt('\nвведите ссылку на рисунок:','http://') || "";
	text = prompt('\nвведите текст подсказки:','') || "";
	if (img!="") {
       	if (text!="") {paste(form,"[img="+text+"]"+img+"[/img]\n", 1);}
        else {paste(form,"[img]"+img+"[/img]\n", 1);}
    }
	}
}

function ln_ins(form){
form.soob.focus();
if (document.selection) {
	vd = form.document.selection.createRange();
    if (vd.text != "") {vd.text = "[url]"+vd.text+"[/url]";}
	else {
		ln = prompt('\nвведите ссылку:','http://') || "";
		text = prompt('\nвведите текст:','') || "";
		if (ln!="") {
        	if (text!="") {paste(form,"[img="+ln+"]"+text+"[/img]\n", 1);}
            else {paste(form,"[img]"+ln+"[/img]\n", 1);}
        }
		}
} else {
	ln = prompt('\nвведите ссылку:','http://') || "";
	text = prompt('\nвведите текст:','') || "";
	if (ln!="") {
       	if (text!="") {paste(form,"[img="+ln+"]"+text+"[/img]\n", 1);}
        else {paste(form,"[img]"+ln+"[/img]\n", 1);}
    }
	}
}

var IE5 = (navigator.userAgent.indexOf('MSIE')!=-1) && (navigator.userAgent.indexOf('Opera')==-1)
var Opera7 = (navigator.userAgent.indexOf('Opera')!=-1) && (navigator.userAgent.charAt(navigator.userAgent.indexOf('Opera')+6)>=7)

function on_scroll(){
if (document.answer != null) 
	if (post.style.position != "") setTimeout('post.style.top=document.body.scrollTop+document.body.offsetHeight-post.offsetHeight-5', 50)
}

/*function on_mouseup(){
	setTimeout("paste_window("+window.event.clientX+","+window.event.clientY+")", 50);
}*/

function float_tab(){
if (IE5 || Opera7){
	document.writeln('<br><div id=float_link><a class=small3 href="javascript:do_float(1)">\"плавающее\" окно ответа</a></div>');
	window.onscroll = on_scroll;
	//document.onmouseup = on_mouseup;
}
}

function do_float(isfloat){
if (isfloat) {
	post.style.position="absolute"
	post.style.border="2px #003B84 solid"
	post.style.backgroundColor="white"
	float_link.innerHTML='<a class=s href="javascript:do_float(0)">обычное окно ответа</a>'
	setTimeout("answer.style.top=document.body.scrollTop+document.body.offsetHeight-post.offsetHeight-5", 10);
} else {
	post.style.position=""
	post.style.border=""
	post.style.backgroundColor="white"
	float_link.innerHTML='<a class=small3 href="javascript:do_float(1)">\"плавающее\" окно ответа</a>'
}
}

function close_topic(id,status){
	if (status == 1){
		text = prompt('\nвведите причину закрытия темы:','') || "";
	} else {
		text = "";
	}
	href = "refer.php?action=changetop_closed_status&t_id="+id+"&new_status="+status+"&t_reason="+text;
	window.location = href;
	//	alert(href);
}