function PostFormValidator(){
if (document.POSTER.body.value.length == 0){
  alert('Пожалуйста, введите текст!');
  return false;
}
if (document.POSTER.body.value.length > max){
  alert("Your message exceeds the allowed maximum by "+(document.POSTER.body.value.length-max)+" characters! Please, shorten your message or devide into parts!");
  return false;
}
if (document.POSTER.from.value.length == 0){
  alert('Вы не указали имя!');
  return false;
}
document.POSTER.submit();
document.POSTER.Send.disabled=true;
return true;
}

var codes_array = new Array(
new Array('b', '[b] - полужирное начертание', 'Тег [b] - полужирное начертание шрифта.\n\nПример: [b]полужирный[/b]', 'Введите текст, который будет выделен полужирным начертанием'),
new Array('i', '[i] - наклонное начертание', 'Тег [i] - курсив, наклонное начертание шрифта.\n\nПример: [i]курсив[/i]', 'Введите текст, который будет выделен курсивом'),
new Array('u', '[u] - подчёркивание', 'Тег [u] - подчеркнутое начертание шрифта.\n\nПример: [u]подчеркнутый[/u]', 'Введите текст, который будет выделен подчеркнутым начертанием')
)

function c1(num) {
	line1 = "["+codes_array[num][0]+"]";
	line2 = "[/"+codes_array[num][0]+"]";
	p4(line1, line2);
}

function p2(text){ 
if (text!="") paste("[i]"+text+"[/i]\n", 0);
}

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

function p4(text1, text2){ 
if ((document.selection)) {
	document.POSTER.body.focus()
	document.POSTER.document.selection.createRange().text = text1+document.POSTER.document.selection.createRange().text+text2
} else document.POSTER.body.value += text1+text2
}

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

function get_selection() {
   if (window.getSelection){
	selection = window.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 print_panel() {
	var mypanel = '<a href="javascript:get_selection();p2(selection);" title="Вставить выделение"><img src="/img/paste.gif" alt="Вставить выделение" width=20 height=19 border=0></a> ';
	mypanel += '<a href="javascript:c1(0)" title="'+codes_array[0][1]+'"><img src="/img/bold.gif" alt="'+codes_array[0][1]+'" width=15 height=15 border=0></a> ';
	mypanel += '<a href="javascript:c1(1)" title="'+codes_array[1][1]+'"><img src="/img/italic.gif" alt="'+codes_array[1][1]+'" width=15 height=15 border=0></a> ';
	mypanel += '<a href="javascript:c1(2)" title="'+codes_array[2][1]+'"><img src="/img/underline.gif" alt="'+codes_array[2][1]+'" width=15 height=15 border=0></a> ';
	return mypanel;
}

