  function textCounter (field, countfield, maxlimit)

  {

  	if (field.value.length > maxlimit)

  	field.value = field.value.substring(0, maxlimit);

  	else

  	countfield.value = maxlimit - field.value.length;

  }

  function newWindow (mypage,myname,w,h,features)

  {

  	if(screen.width)

  	{

  		var winl = (screen.width-w)/2;
  		var wint = (screen.height-h)/2;

  	}

  	else

  	{

  		winl = 0;wint =0;

  	}

  	if (winl < 0) winl = 0;
  	if (wint < 0) wint = 0;

  	var settings = 'height=' + h + ',';
  	settings += 'width=' + w + ',';
  	settings += 'top=' + wint + ',';
  	settings += 'left=' + winl + ',';
  	settings += features;
  	settings += ' scrollbars=yes ';

  	win = window.open(mypage,myname,settings);

  	win.window.focus();

  }

function checkemail (emailStr) 
{
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) 
{
alert("E-mail адрес введен неправильно");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("E-mail адрес введен неправильно");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("E-mail адрес введен неправильно");
return false;
   }
}

if (user.match(userPat)==null) 
{
alert("E-mail адрес введен неправильно");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("E-mail адрес введен неправильно");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("E-mail адрес введен неправильно");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("E-mail адрес введен неправильно");
return false;
}

if (len<2) {
alert("E-mail адрес введен неправильно");
return false;
}

return true;
}

var notepad_max=20;
		var notepad_time=1296126585;
function notepadCurId()
{
	var elm = document.getElementById('notepad_link');

	if (!elm)
	{
		return false;
	}

	elm = elm.onclick.toString();
	var tmp = 'notepadAdd(';

	elm = elm.substring(elm.indexOf(tmp) + tmp.length, elm.length);
	elm = elm.substring(0, elm.indexOf(')'));

	return parseInt(elm);
}

function notepadGet()
{
	var data = '', saver = 'notepad=', cookie = '' + unescape(document.cookie);
	var offset = cookie.indexOf(saver);

	if (offset != -1)
	{
		var end = cookie.indexOf(';', offset);
		if (end == -1)
		{
			end = cookie.length;
		}

		data = cookie.substring(offset + saver.length, end);
	}

	return data;
}

function notepadInit()
{
	var data = notepadGet();
	var total = 0, p = data.length, off = 0;
	var cur_date = new Date();

	while (p != -1)
	{
		off = p;
		if (++total > notepad_max)
		{
			data = data.substring(off + 1, data.length);
			--total;
		}

		p = data.lastIndexOf(',', --off);
	}

	cur_date.setTime(cur_date.getTime() + notepad_time * 1000);
	document.cookie = 'notepad=' + data + '; expires=' + cur_date.toGMTString();

	if ( !document.getElementById('notepad_empty') )
	{
		return;
	}

	if (data == '')
	{
		document.getElementById('notepad_empty').style.display = '';
		document.getElementById('notepad_full').style.display = 'none';
	}
	else
	{
		p = document.getElementById('notepad_num');
		p.replaceChild(document.createTextNode(total), p.firstChild);

		document.getElementById('notepad_empty').style.display = 'none';
		document.getElementById('notepad_full').style.display = '';
	}

	if ( !document.getElementById('notepad_link') )
	{
		return;
	}

	data += ',';
	p = notepadCurId();
	if (p && data.indexOf(p + ',') != -1)
	{
		document.getElementById('notepad_link').style.display = 'none';
		document.getElementById('notepad_link_del').style.display = '';
	}
	else
	{
		document.getElementById('notepad_link').style.display = '';
		document.getElementById('notepad_link_del').style.display = 'none';
	}
}


function notepadAdd(num)
{
	num = parseInt(num);
	if (num <= 0)
	{
		return false;
	}

	var data = notepadGet();
	var cur_date = new Date();

	if (data != '')
	{
		data = ',' + data + ',';
	}

	if (data.indexOf(',' + num + ',') == -1)
	{
		cur_date.setTime(cur_date.getTime() + notepad_time * 1000);
		document.cookie = 'notepad=' + data.substring(1, data.length) + num
			+ '; expires=' + cur_date.toGMTString();
		notepadInit();
	}

	return false;
}

function notepadDel(num)
{
	num = parseInt(num);
	if (num <= 0)
	{
		return false;
	}

	var data = notepadGet();
	var cur_date = new Date();

	if (data != '')
	{
		data = ',' + data + ',';
	}

	if (data.indexOf(',' + num + ',') != -1)
	{
		cur_date.setTime(cur_date.getTime() + notepad_time * 1000);
		data = data.replace(num + ',', '');
		data = (data == ',' ? '' : data.substring(1, data.length - 1));

		document.cookie = 'notepad=' + data	+ '; expires=' + cur_date.toGMTString();
		notepadInit();
	}

	return false;
}