
// Copyright (c) 2000-2002 N.Mikhailov, mn@ixbt.com, http://forum.iXBT.com

var old_action = "";

function p1(text){ 
if (text!="") paste("[b]"+text+"[/b]\n", 1);
}

function p2(text){ 
if (text!="") paste("[quote]"+text+"[/quote]\n", 0);
}

function paste(text, flag){ 
if ((document.selection)&&(flag)) {
	document.post.txt.focus();
	document.post.document.selection.createRange().text = text;
} else document.post.txt.value += text;
}

function get_selection() {
   if (document.getSelection){
	selection = document.getSelection();
	selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_");
	selection = selection.replace(/\r\n/gi, " ");
       while (selection.indexOf("  ") !=-1) selection = selection.replace(/  /gi, ""); 
	selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n");
  } else
      selection = document.selection.createRange().text;
}

function setup_post(enablefocus){
if (enablefocus) {document.post.UserName.focus()}
var testUserName = getCookie("user")
var testPassword = getCookie("pass")
if ((document.cookie)&&(testUserName != null)) {
	document.post.UserName.value = testUserName
	if (testPassword!=null) {document.post.Password.value = testPassword}
	if (enablefocus) {document.post.txt.focus()}
}
if (getCookie("setup")!=null){
	if (getCookie("setup").indexOf("D") != -1) {document.post.without_smilies.checked = true}
}
if ((!enablefocus)&&(document.post.txt.style!=null)){ 
//	var i=1;
//	while (document.all("tbl"+i) != null) {document.all("tbl"+i).style.tableLayout="fixed"; i++}

	var testform_cookie = getCookie('setup2')
	if (testform_cookie!=null){
		form_cookie=testform_cookie.split("|");
		if ((form_cookie[3] != null)&&(form_cookie[3] >=20)&&(form_cookie[3]<=250)) {document.post.txt.cols=form_cookie[3]} else {document.post.txt.style.width="100%"};
		if (form_cookie[4] != null) {document.post.txt.rows=form_cookie[4]}
		if (form_cookie[5] != null) {document.post.txt.style.fontSize=form_cookie[5]}
		if (form_cookie[6] != null) {document.post.txt.accessKey=form_cookie[6]}
	} else {document.post.txt.style.width="100%"}
}

switch(navigator.appName) {
   case "Microsoft Internet Explorer":
      Key = "event.ctrlKey && event.keyCode == 13";
      document.onkeydown = get_key;
      break;
   case "Netscape":
      Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
      document.captureEvents(Event.KEYDOWN);
      document.onkeydown = get_key;
      break;
}
}

function get_key(e) {
if (eval(Key)) {
	if (check_post()){
		check_submit();
		document.post.submit();
		submit_once(document.post);
	} else {return false}
}
}


function setup_loginform(){
var testUserName = getCookie("user")
var testPassword = getCookie("pass")
if ((document.cookie)&&(testUserName != null)) {
	document.loginform.UserName.value = testUserName
	if (testPassword!=null) {document.loginform.Password.value = testPassword}
	}
}

function check_post(){
var max = 42000;
if (document.post.txt.value.length == 0){
	alert('Напишите, пожалуйста, что-нибудь!');
	return false;
}
if (document.post.txt.value.length > max){
	alert("Размер Вашего сообщения превышает максимум на "+(document.post.txt.value.length-max)+" символов! Пожалуйста, уменьшите его, разбив на несколько частей!");
	return false;
}
if (document.post.UserName.value.length == 0){
	alert('Вы забыли указать своё имя!');
	return false;
}
return true;
}


function check_loginform(){
if ((document.loginform.UserName.value.length == 0)||(document.loginform.Password.value.length == 0)){
	alert('Вы заполнили не все поля! Укажите своё имя и пароль!')
	return false;
 }
return true;
}

function check_submit() {
if (old_action!="") document.post.id.value=old_action
document.post.target="_self";
}

function submit_once(theform){
if (theform.target=="preview") {return}
if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {tempobj.disabled=true}
}
}
}

function getCookie(name) {
var prefix = name + "="
var StartIndex = document.cookie.indexOf(prefix)
if (StartIndex == -1)
return null
var EndIndex = document.cookie.indexOf(";", StartIndex + prefix.length)
if (EndIndex == -1)
EndIndex = document.cookie.length
return unescape(document.cookie.substring(StartIndex + prefix.length, EndIndex))
}


function chg(mmm)
{
if (mmm.options[mmm.selectedIndex].value == "no") { mmm.selectedIndex = 0; }
else { mmm.form.submit(); }
}
