function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


function isNumeric(strString) {
   //  check for valid numeric strings 		   
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1) 
	  {
		 blnResult = false;
	  }
   }
   return blnResult;
}


function validate(theForm) {

	var error = "Please fill in :\n"; 
	
	if (theForm.first_name.value == "")	{
		error += "  First name\n";
	}  
	if (theForm.last_name.value == "")	{
		error += "  Last Name\n";
	}
	if (theForm.area_code.value ==""||theForm.phone1.value ==""||theForm.phone2.value =="")
	{
		error += "  Telephone\n";
	}else if (isNumeric(theForm.area_code.value) == false||isNumeric(theForm.phone1.value) == false||isNumeric(theForm.phone2.value) == false)
	{
		error += "  Phone Number must be numeric\n";
	}
	if (isEmail(theForm.contact_email.value) == false)
	{
		error += "  E-mail\n";
	} 	
	
	if (isEmail(theForm.verify_email.value) == false)
	{
		error += "  Verify E-mail\n";
	} 	else if (theForm.verify_email.value!=theForm.contact_email.value)
	{
		error += "  Verify E-mail address doesn't match\n";
	}
	
	if (error != "Please fill in :\n")	{
		alert(error);
		return false;
	} else {
		return trackContactForm();
	}
}