﻿function doReset () {
document.form1.name.value ="";
document.form1.email.value ="";
document.form1.city.value ="";
document.form1.message.value ="";
}

function ValidateAndSubmit() {
var isname, isemail, isgender, re;


re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;

isname = document.form1.name.value;
isemail = document.form1.email.value;
iscity = document.form1.city.value;
isgender = document.form1.gender.value;

while (isname.substring(0,1) == " ") isname = isname.substring(1);
while (isname.substring(isname.length-1,isname.length) == " ") isname = isname.substring(0,isname.length-1);
while (isemail.substring(0,1) == " ") isemail = isemail.substring(1);
while (isemail.substring(isemail.length-1,isemail.length) == " ") isemail = isemail.substring(0,isemail.length-1);



if (isname.length==0) {
	document.form1.name.value ="";
	document.form1.name.focus();
	alert("   Введите имя!   ");
	return false;
}

if (iscity.length==0) {
	document.form1.city.value ="";
	document.form1.city.focus();
	alert("   Введите город!   ");
	return false;
}

if (isemail.length==0) {
	document.form1.email.value ="";
	document.form1.email.focus();
	alert("   Введите E-mail!   ");
	return false;
}


if (isemail.length > 0) {
			 var supported = 0;
			   if (window.RegExp) {
			     var tempStr = "a";
			     var tempReg = new RegExp(tempStr);
			     if (tempReg.test(tempStr)) supported = 1;
		  	   }
			   if (!supported) {
			       isValid = (isemail.indexOf(".") > 2) && (isemail.indexOf("@") > 0);
			   } else {
				  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
				  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
				  var r3 = new RegExp("[а-яА-Я]");
			       isValid = (!r1.test(isemail) && r2.test(isemail) && !r3.test(isemail));
		       }
		       if (!isValid) {
		       	  alert("Внимание! Ошибка при вводе email!  ");	
				  document.form1.email.focus();
				  return false;	
		       }
			}


document.form1.submit();
return true;

}
