function isEmail(email){return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);}
function isPhone(phone){return (/^[0-9\+\(\)\-]+$/i).test(phone);}
function isEmpty(str){return (/(^$)|(^[\s]+)$/).test(str);}
function isPass(pass){return (/^[a-z0-9_\-]+$/i).test(pass);}
function isName(str){return (/^[а-яА-Я]+[а-яА-Я\s.]+$/i).test(str);}

function ajax(url, callback)
 {
	var req = init();
	req.onreadystatechange = processRequest;
	function init()
	 {
	  try
	   {
		return new XMLHttpRequest();
	   }
	  catch(trymicrosoft)
	   {
		try
		 {
		  return new ActiveXObject("Msxml2.XMLHTTP");
		 }
		catch(othermicrosoft)
		 {
		  try
		   {
			return new ActiveXObject("Microsoft.XMLHTTP");
		   }
		  catch(failed)
		   {
			return false;
		   }
		 }
	   }
	 }
	function processRequest()
	 {
		if(req.readyState == 4) if(req.status == 200) if(callback) callback(req.responseText);
	 }
	this.doGet=function(){ req.open("GET",url,true);req.send(null); }
	this.doPost = function(body)
	 {
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(body);
	 }
 }

function isEmail(email){return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);}
function isPass(pass){return (/^[a-z0-9_\-]+$/i).test(pass);}
function isPhone(phone){return (/^[0-9\+\(\)\-]+$/i).test(phone);}

function ShowSendMsg(msg)
{
 document.getElementById('status').innerHTML = msg;
}

function SendMsg()
{
 var fail = false;
 var name = document.getElementById('name').value;
 document.getElementById('name_msg').innerHTML = '';
 if(!isName(name))
  {
   document.getElementById('name_msg').innerHTML = '<div class="error">Это не ФИО!</div>';
   fail = true;
  }
 var phone_num = document.getElementById('phone_num').value;
 var e_mail = document.getElementById('e_mail').value;
 document.getElementById('e_mail_msg').innerHTML = '';
 if(!isEmail(e_mail))
  {
   document.getElementById('e_mail_msg').innerHTML = '<div class="error">Это не адрес!</div>';
   fail = true;
  }
 var subject = document.getElementById('subject').value;
 document.getElementById('subject_msg').innerHTML = '';
 if(isEmpty(subject))
  {
   document.getElementById('subject_msg').innerHTML = '<div class="error">Нет темы!</div>';
   fail = true;
  }
 var msg = document.getElementById('msg').value;
 document.getElementById('msg_msg').innerHTML = '';
 if(isEmpty(msg))
  {
   document.getElementById('msg_msg').innerHTML = '<div class="error">Нет сообщения!</div>';
   fail = true;
  }
 if(fail) return;
 var name = document.getElementById('name').value;
 var phone_num = document.getElementById('phone_num').value;
 var e_mail = document.getElementById('e_mail').value;
 var subject = document.getElementById('subject').value;
 var msg = document.getElementById('msg').value;
 var post_body = 'name=' + encodeURIComponent(name) + '&phone_num=' + encodeURIComponent(phone_num) + '&e_mail=' + encodeURIComponent(e_mail) + '&subject=' + encodeURIComponent(subject) + '&msg=' + encodeURIComponent(msg);
 var request = new ajax('/contacts/send.php', ShowSendMsg);
 request.doPost(post_body);
}

function Over(elem)
{
 if(elem.className.indexOf('_over') == -1) elem.className = elem.className + '_over';
}

function Out(elem)
{
 var index = elem.className.indexOf('_over');
 if(index != -1) elem.className = elem.className.substring(0, index);
}

function ShowDescr(id)
{
 document.getElementById('page_id').value = id;
 document.getElementById('post_page').submit();
}

function ShowImg(id, sender)
{
 if(sender && sender.win_op && !sender.win_op.closed) {	sender.win_op.focus(); return; }
 var new_window = window.open('', '', 'resizable=yes,width=300,height=300,screenX=200,screenY=200,left=50,top=50');
 new_window.location.href = '/works/image.php?id=' + id;
 sender.win_op = new_window;
}
 
function ShowMap()
 {
	var win_op = window.open('', '', 'resizable=yes,width=200,height=200,screenX=200,screenY=200,left=50,top=50');
	win_op.document.open();
	win_op.document.writeln('<html>');
	win_op.document.writeln("<head><script type='text/javascript' src='/ajax.js'></script>");
	win_op.document.writeln('<title>Схема проезда</title>');
	win_op.document.writeln('<script type="text/javascript">');
	win_op.document.writeln('window.onload = function() {');
	win_op.document.writeln('function GetImgProps(text) { if(text) { var response = text.split("|");');
	win_op.document.writeln('var height;');
	win_op.document.writeln('if(response[0] && response[1] && !isNaN(parseInt(response[0])) && !isNaN(parseInt(response[1]))) {');
	win_op.document.writeln('document.image.width = response[0]; document.image.height = response[1]; document.image.src = "/contacts/map." + response[2];');
	win_op.document.writeln('if(typeof(window.innerHeight) != "undefined") height = window.outerHeight - window.innerHeight + document.image.height + 1;');
	win_op.document.writeln('else height = document.image.height + 25;');
	win_op.document.writeln('self.resizeTo(document.image.width + 14, height); } } }');
	win_op.document.writeln('var request = new ajax("/contacts/show_map.php", GetImgProps);');
	win_op.document.writeln('request.doGet();');
	win_op.document.writeln('}');
	win_op.document.writeln('</script>');	
	win_op.document.writeln('</head>');
	win_op.document.writeln('<body style="margin:0px;text-align:center;">');
	win_op.document.writeln('<img name="image" alt="Схема проезда" style="display:block;margin:auto;border:none;" />');
	win_op.document.writeln('</body>');
	win_op.document.writeln('</html>');		
	win_op.document.close();
 }