
function checkAcct() {

   AcctForm = document.accountform;

   var pattern = /\s*\w+@[^\.]+\.[^\.]+(\.[^\.])*\s*/;
   legalChars = "~0123456789.-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@+";
   errorMsg = "";

//CONTACT INFO CHECK

	if (AcctForm.Password.value.length < 6)
		errorMsg += "\nAccount Password must be at least 6 characters";
	if (AcctForm.Password.value != AcctForm.Re_Password.value)
		errorMsg += "\nPassword and Confirmation Password must match";

	if (AcctForm.ContactLName.value.length < 1)
		errorMsg += "\nContact Last Name is required";
	if (AcctForm.ContactFName.value.length < 1)
		errorMsg += "\nContact First Name is required";
	if (AcctForm.ContactPhone.value.length < 10)
		errorMsg += "\nContact Phone must be at least 10 characters";
	if (AcctForm.ContactComp.value.length < 1) {
		errorMsg += "\nContact Company Name is required";
		errorMsg += "\nIf no Company Name enter: None";
	}
	if (AcctForm.ContactAddr1.value.length < 1)
		errorMsg += "\nContact  Address is required";
	if (AcctForm.ContactCity.value.length < 1)
		errorMsg += "\nContact City is required";
	if (getSelectValue(AcctForm.ContactState) == "XX")
		errorMsg += "\nYou must choose a Contact State";
	if (AcctForm.ContactZip.value.length < 5)
		errorMsg += "\nContact Zip Code must be at least 5 numbers";

//EMAIL CHECK
	if (AcctForm.ContactEmail.value.length < 7) {
		errorMsg += "\nContact E-mail address must be at least 7 characters";
		errorMsg += "\n\tIf you do NOT have an email address please enter:\n\t\t NE-YourName@charitycards.com";
	}
	if (AcctForm.ContactEmail.value.toLowerCase() == "ne-yourname@charitycards.com") {
		errorMsg += "\n\tIf you do NOT have an email address please enter:\n\t\t NE-YourName@charitycards.com";
		errorMsg += "\n\tEnter your actual name, not 'YourName'";
	}
	//Validate ContactEmail against pattern match
	if (AcctForm.ContactEmail.value != "") {
	    if(!pattern.test(AcctForm.ContactEmail.value)) {
			errorMsg += "\nInvalid Contact E-mail Address."
	    }
	}
	//This enhances the previous email check. This checks for legal values and returns illegal values
	if (AcctForm.ContactEmail.value != "" && AcctForm.ContactEmail.value.length > 1) {
	    for(x=0; x < AcctForm.ContactEmail.value.length; x++) {
		if (legalChars.indexOf(AcctForm.ContactEmail.value.substring(x,x+1)) < 0)
		    errorMsg = errorMsg + "\n" + "Illegal character '"+AcctForm.ContactEmail.value.substring(x,x+1)+"' at position " +(x+1)+ " in Contact E-mail Address.";
	    }
	}

//BILLING INFO CHECK

	if (AcctForm.BillLName.value.length < 1)
		errorMsg += "\nBilling Last Name is required";
	if (AcctForm.BillFName.value.length < 1)
		errorMsg += "\nBilling First Name is required";
	if (AcctForm.BillPhone.value.length < 10)
		errorMsg += "\nBilling Phone must be at least 10 characters";

	if (AcctForm.BillAddress1.value.length < 1)
		errorMsg += "\nBilling  Address is required";
	if (AcctForm.BillCity.value.length < 1)
		errorMsg += "\nBilling City is required";
	if (getSelectValue(AcctForm.BillState) == "XX")
		errorMsg += "\nYou must choose a Billing State";
	if (AcctForm.BillZip.value.length < 5)
		errorMsg += "\nBilling Zip Code must be at least 5 numbers";


//EXEMPTION CHECK
//	if (getSelectValue(AcctForm.TaxExempt) != "N")
//	    if (AcctForm.ExemptNum.value.length < 16)
//		errorMsg += "\nIf Tax Exempt then Exemption Number must be 16 characters";

//SHIPPING INFO CHECK
	if (AcctForm.ShipAddress1.value.length < 1)
		errorMsg += "\nShipping  Address is required";
	if (AcctForm.ShipCity.value.length < 1)
		errorMsg += "\nShipping City is required";
	if (getSelectValue(AcctForm.ShipState) == "XX")
		errorMsg += "\nYou must choose a Shipping State";
	if (AcctForm.ShipZip.value.length < 5)
		errorMsg += "\nShipping Zip Code must be at least 5 numbers";


	if (errorMsg.length > 0) {
		errorMsg = "The following corrections must be made before submitting this form:\n" + errorMsg
		alert (errorMsg);
		return false;
	}

return true;


}
function getRadioValue(radioName) {
	for (x=0; x< radioName.length; x++) {
		if (radioName[x].checked) {
			return radioName[x].value;
		}
	}
	return "no answer";
}
function getSelectValue(selectName) {
	for (x=0; x< selectName.length; x++) {
		if (selectName[x].selected) {
			return selectName[x].value;
		}
	}
	return "no answer";
}

