
function form_validator(theForm)
{

var vCUSTOMERALTCD = true;

var vFullName = true;
var vBadgeName = true;
var vAddress1 = true;
var vCity = true;
var vState = true;
var vZip = true;
var vPhone = true;
var vEmail = true;

var alertmessage = "";
var regex = /^[0-9a-zA-Z]{6,10}$/;


if (IsEmpty(document.NewForm.CUSTOMERALTCD.value) || !(document.NewForm.CUSTOMERALTCD.value.length == 5) || (!IsNumeric(document.NewForm.CUSTOMERALTCD.value)))
 {
 	  alertmessage = alertmessage + "Please enter your Numeric Bar ID." + "\n"
      vCUSTOMERALTCD = false;
 }
 if (IsEmpty(document.NewForm.FullName.value))
 {
 	  alertmessage = alertmessage + "Please enter your Full Name." + "\n"
      vFullName = false;
 }
 
 if (IsEmpty(document.NewForm.BadgeName.value))
 {
 	  alertmessage = alertmessage + "Please enter a name for your Badge." + "\n"
      vBadgeName = false;
 }
 
  if (IsEmpty(document.NewForm.Address1.value))
 {
 	  alertmessage = alertmessage + "Please enter Address." + "\n"
      vAddress1 = false;
 }
 
  if (IsEmpty(document.NewForm.City.value))
 {
 	  alertmessage = alertmessage + "Please enter your City." + "\n"
      vCity = false;
 }
 
  if (IsEmpty(document.NewForm.State.value))
 {
 	  alertmessage = alertmessage + "Please enter your State." + "\n"
      vState = false;
 }
 
  if (IsEmpty(document.NewForm.Zip.value) || (!IsZip(document.NewForm.Zip.value)))
 {
 	  alertmessage = alertmessage + "Please enter a valid Zip Code." + "\n"
      vZip = false;
 }

 
  if (IsEmpty(document.NewForm.Phone.value) || (!IsPhoneNumber(document.NewForm.Phone.value)))
 {
 	  alertmessage = alertmessage + "Please enter your Phone Number formatted - (111) 111-2222." + "\n"
      vPhone = false;
 }


if (IsEmpty(document.NewForm.Email.value ) || !(IsEmail(document.NewForm.Email.value)))
 {
 	  alertmessage = alertmessage + "Email Address Required" + "\n"
      vEmail = false;
 }


// if ( document.contact_form.terms.checked == false )
if ((vCUSTOMERALTCD == false) || (vFullName == false) || (vBadgeName == false) || (vAddress1 == false) || (vCity == false) || (vState == false) || (vZip == false) || (vPhone == false) || (vEmail == 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;
}



