// Copyright (c) 2000-2002 N.Mikhailov, mn@ixbt.com, http://forum.iXBT.com
// Some functions from initial scripts are used without permission.

function p1(text){ 
if (text!="") paste("[b]"+text+"[/b]\n", 1);
}

function p2(text){ 
if (text!="") paste("[i]"+text+"[/i]\n", 0);
}

function paste(text, flag){ 
if ((document.selection)&&(flag)) {
	document.postform.message.focus();
	document.postform.document.selection.createRange().text = text;
} else document.postform.message.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 PostFormValidator(){
var max = 8000;
if (document.postform.message.value.length == 0){
  alert('Напишите, пожалуйста, что-нибудь!');
  return false;
}
if (document.postform.username.value.length == 0){
  alert('Укажите, пожалуйста, своё имя!');
  return false;
}
if (document.postform.username.value.length < 2){
  alert('Укажите, пожалуйста, своё имя!\nИмя должно быть не менее двух символов.');
  return false;
}
if (document.postform.message.value.length > max){
  alert("Размер Вашего сообщения превышает максимум на "+(document.postform.message.value.length-max)+" символов! Пожалуйста, уменьшите его, разбив на несколько частей!");
  return false;
}
if (document.postform.username.value.length == 0){
  alert('Вы забыли указать своё имя!');
  return false;
}
return true;
}

// Copyright (c) 2002 Y.Feofanov aka Neutron , bn@hotbox.ru, http://www.yarik.com

function get_mail(part1,part2,part3,part4) {
	document.write('<a href=mailto:');
	document.write(part1);
	document.write('@');
	document.write(part2);
	var myclass = "";
	if (part3 != "") {
		myclass = " class=" + part3;
		document.write(myclass);
	}
	document.write('>');
	if (part4) {
		subtext = part4;
	} else {
		subtext = part1 + '@' + part2;
	}
	document.write(subtext);	
	document.write("</a>"); 
}

function getCookie(name) {
  var prefix = name + "=";
  var begin = document.cookie.indexOf("; " + prefix);
  if (begin == -1) {
    begin = document.cookie.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = document.cookie.length;
  return unescape(document.cookie.substring(begin + prefix.length, end));
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=0;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
