
function form_validator(theForm)
{

var vFirstName = true;
var vLastName = true;
var vFirm = true;
/*var vInsPolNum = true;*/
/*var vInsPolExp = true;*/
var vPhone = true;
var vEmail = true;
var vDisasterVolYN = true;
var alertmessage = "";
var regex = /^[0-9a-zA-Z]{6,10}$/;


 
 if (IsEmpty(document.UpdateProfile.FirstName.value)) 
 {
 	  alertmessage = alertmessage + "First Name Required" + "\n"
      vFirstName = false;
 }

if (IsEmpty(document.UpdateProfile.LastName.value)) 
 {
 	  alertmessage = alertmessage + "Last Name Required" + "\n"
      vLastName = false;
 }

if (IsEmpty(document.UpdateProfile.Firm.value)) 
 {
 	  alertmessage = alertmessage + "Firm Name Required" + "\n"
      vFirm = false;
 }
 
 if (IsEmpty(document.UpdateProfile.Phone.value)) 
 {
 	  alertmessage = alertmessage + "Phone Number Required" + "\n"
      vPhone = false;
 }
 
 if (IsEmpty(document.UpdateProfile.Email.value )) 
 {
 	  alertmessage = alertmessage + "Email Address Required" + "\n"
      vEmail = false;
 }
 
  if (!(document.UpdateProfile.DisasterVolYN[0].checked) && !(document.UpdateProfile.DisasterVolYN[1].checked))
{
  alertmessage = alertmessage + "Primary Registration Country is required." + "\n"
     vDisasterVolYN = false;
	  }
 


//(vInsPolNum == false) || (vInsPolExp == false) ||

// if ( document.contact_form.terms.checked == false )
if ((vFirstName == false) || (vLastName == false) || (vFirm == false) ||  (vPhone == false) || (vEmail == false) || (vDisasterVolYN == false)) 
	
{
	alert(alertmessage);
 	return (false); 
}
else
{
    return (true);
}
}

function IsNumeric(string)
{
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	
	if (string != "")
	{
		for (var i=0; i<string.length; i++) {
			temp = "" + string.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") ok = "no";
			}
		if (ok == "no" || string == "") {
			return false;
		}
		else
		{
			return true;
		}
	}
	else return false;
}

function IsEmpty(s)
{   
s = trim(s)
 return ((s == null) || (s.length == 0) || (s == ""))
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function IsDate(dateStr) 
{
//regex for date that requires 4 digit year
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;   - allows / or - 
	var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); 		// is the format ok?
	
	if (matchArray == null) 
	{
		//alert("Date is not in a valid format.")
		return false;
	}
	
	month = matchArray[1]; 							// parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	
	if (month < 1 || month > 12) 
	{ 												// check month range
		// alert("Month must be between 1 and 12.");
		return false;
	}
	
	if (day < 1 || day > 31) 
	{
		// alert("Day must be between 1 and 31.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		//alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	
	if (month == 2) 
	{ 
		// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			// alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	
	return true;  // date is valid

}

function IsEmail(emailstr)
{
// var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/  Nathan supposedly found error in this one.
 var filter = /^\w[-\.a-zA-Z0-9_]*@\w[-\.a-zA-Z0-9_]*\.\w{2,3}$/ ;

 
 if (filter.test(emailstr))
  return true;
 else
  return false;
}

function IsWWW(wwwstr)
{
// var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/  Nathan supposedly found error in this one.
 var filter = /^\w[-\.a-zA-Z0-9_]*\.\w{2,3}$/ ;

 
 if (filter.test(wwwstr))
  return true;
 else
  return false;
}

function IsZip(zipstr)
{
// var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/  .
 var filter = /^\d{5}([\-]\d{4})?$/;

 
 if (filter.test(trim(zipstr)))
  return true;
 else
  return false;
}

function IsPhoneNumber(phonestr) 
{
     // Check for correct phone number
     rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
 
     if (!rePhoneNumber.test(phonestr)) {
          return false;
     }
 
return true;
}



