 function validatePhone(textfield) {

     phoneOK = true; // phoneOK is GLOBAL

     var digits = 0;

     // Check that the phone number only contains

     // the characters "() -0-9" and contains the right

     // number of digits total

     for (var i=0; i < textfield.value.length; i++)

     {

        var theChar = textfield.value.charAt(i);

        if ((theChar >= "0") && (theChar <= "9")) {

           digits++;

           continue;

        }

        if (theChar == "-") continue;

        if (theChar == "(") continue;

        if (theChar == ")") continue;

        if (theChar == " ") continue;

        //phoneOK = false;

     }



     //additional checks (BSM) for '(', ')', and '-' in proper locations

     //if (textfield.value.charAt(0) != "(")

     //  phoneOK = false;

     //if (textfield.value.charAt(4) != ")")

     //  phoneOK = false;

     //if (textfield.value.charAt(8) != "-")

     //  phoneOK = false;



     // The string is OK if it contains only the allowed

     // characters and the number of digits in the

     // phone number is 10 total (area code + number)

     phoneOK = phoneOK && (digits == 10);

     if (!phoneOK) {

        alert("Unrecognized telephone number!");

        textfield.focus();

        textfield.select();

     }



     return phoneOK;

  }

function validateZIP(field) {



var valid = "0123456789-";

var hyphencount = 0;



if (field.length!=5) {

	//alert(field.length);

	alert("Please enter your 5 digit zip code.");
	return false;

}

for (var i=0; i < field.length; i++) {

temp = "" + field.substring(i, i+1);

if (temp == "-") hyphencount++;

if (valid.indexOf(temp) == "-1") {

alert("Invalid characters in your zip code.  Please try again.");

return false;

}

if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {

alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");

return false;

   }

}

return true;

}



function emailcheck(emailStr)

{



var emailPat=/^(.+)@(.+)$/

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"

var quotedUser="(\"[^\"]*\")"

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

var atom=validChars + '+'

var word="(" + atom + "|" + quotedUser + ")"

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")





var matchArray=emailStr.match(emailPat)

if (matchArray==null) {

  	return false

}

var user=matchArray[1]

var domain=matchArray[2]



if (user.match(userPat)==null) {

    return false

}



var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {

     for (var i=1;i<=4;i++) {

	    if (IPArray[i]>255) {

	        return false

	    }

    }

    return true

}



var domainArray=domain.match(domainPat)

if (domainArray==null) {

	return false

}



var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 ||

    domArr[domArr.length-1].length>3) {

   return false

}



if (len<2) {

   return false

}



return true;

}

function submitme(form)

{

if (form.firstname.value == "")

	{

	alert("Please fill in all required fields.  First name is required.");

	form.firstname.focus();

	return false;

	}
if (form.lastname.value == "")

	{

	alert("Please fill in all required fields.  Last name is required.");

	form.lastname.focus();

	return false;

	}
if (form.address1.value == "")

	{

	alert("Please fill in all required fields.  Address is required.");

	form.address1.focus();

	return false;

	}

if (form.city.value == "")

	{

	alert("Please fill in all required fields.  City is required.");

	form.city.focus();

	return false;

	}

if (form.state.value == "")

	{

	alert("Please fill in all required fields.  State is required.");

	form.state.focus();

	return false;

	}

if (form.zip.value == "")

	{

	alert("Please fill in all required fields.  Zip code is required.");

	form.zip.focus();

	return false;

	}

if (validateZIP(form.zip.value) == false)

	{
		form.zip.focus();
		return false;

	}

if (form.emailaddress.value == "")

	{

	alert("Please fill in all required fields.  Email is required.");

	form.emailaddress.focus();

	return false;

	}

if (form.emailconfirm.value == "")

	{

	alert("Please fill in all required fields.  Confirmation email is required.");

	form.emailconfirm.focus();

	return false;

	}

if (form.emailaddress.value != form.emailconfirm.value)

	{

	alert("The confirmation email you entered does not match your original email entry.");

	form.emailaddress.focus();

	return false;

	}



var myemail = form.emailaddress.value;

//var isvalid = emailcheck(myemail)

if (emailcheck(myemail)==false)

	{

	alert("The email address you have entered is not recognized as valid.");

	form.emailaddress.focus();

	return false;

	}

if (form.homephone.value != "")
{
	if (validatePhone(form.homephone) == false)

	{return false;

	}
}
if (form.workphone.value != "")
{
	if (validatePhone(form.workphone) == false)

	{return false;

	}
}

if (form.fax.value != "")
{
	if (validatePhone(form.fax) == false)

	{return false;

	}
}


form.submit();

}

