// Form Validation Script 2.0
// For Becoming Peace (http://www.becomingpeace.org)

function check_contact(){
	var theForm = document.contact;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var userRE2 = new RegExp("((@))+","g");
	var userRE0 = new RegExp("((@))+","g");
	var errMsg = "";
	var setfocus = "";
	if (theForm['comments'].value == ""){errMsg = "Please enter your comments\.";setfocus = "['comments']";}
	if ((theForm['country'].value == "") || (userRE2.test(theForm['country'].value))){errMsg = "Please enter your country, this should not contain special characters\.";setfocus = "['country']";}
	if (!emailRE.test(theForm['email'].value)){errMsg = "Please enter your email address\.";setfocus = "['email']";}
	if ((theForm['name'].value == "") || (userRE0.test(theForm['name'].value))){errMsg = "Please enter your correct name, this should not contain special characters\.\.";setfocus = "['name']";}
	if (errMsg != ""){alert(errMsg);eval("theForm" + setfocus + ".focus()");}
	else theForm.submit();
}

function check_sign(){
	var theForm = document.sign;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var dte_dobRE = /^(0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/(19|20)\d\d$/;
	var sFlg_sex = false;
	var errMsg = "";
	var setfocus = "";
	
	for(var s3=0;s3<theForm['sex'].length;s3++){if(theForm['sex'].options[s3].selected){if(theForm['sex'].options[s3].text==theForm['sex'].options[0].text)sFlg_sex=true;}}
	
	if (theForm['email'].value != ""){if (!emailRE.test(theForm['email'].value)){errMsg = "Please make sure your email address is in the correct format: name@domain\.com";setfocus = "['email']";}}
	if (theForm['city'].value == ""){errMsg = "Please enter your town or city\.";setfocus = "['city']";}
	if (sFlg_sex){errMsg = "Please select your sex\/gender\.";setfocus = "['sex']";}
	if (!dte_dobRE.test(theForm['dob'].value)){errMsg = "Please enter your date of birth using the format MM\/DD\/YYYY\.";setfocus = "['dob']";}
	if (theForm['lastname'].value == ""){errMsg = "Please enter your last name\.";setfocus = "['lastname']";}
	if (theForm['firstname'].value == ""){errMsg = "Please enter your first name\.";setfocus = "['firstname']";}
	if (errMsg != ""){alert(errMsg);eval("theForm" + setfocus + ".focus()");}
	else theForm.submit();
}