// JavaScript Document

<!-- validate entries found on account setup form using javascript regular expressions
<!--validation routine found on http://www.devarticles.com/c/a/JavaScript/Form-Validation-with-JavaScript-Regular-Expressions-Part-1/     & 
<!--http://www.devarticles.com/c/a/JavaScript/Form-Validation-with-JavaScript-Regular-Expressions-Part-2/ 

function validate()
{
//define account setup fields as variables on the account page
	var bizName = document.account.bizName.value;
	var firstName = document.account.firstName.value;
	var lastName = document.account.lastName.value;
	var asiNum 	= document.account.asiNum.value;
	var ppaiNum = document.account.ppaiNum.value;
	var taxID = document.account.taxID.value;
	var addr = document.account.addr.value;
	var addr2 = document.account.addr2.value;
	var city = document.account.city.value;
	var state = document.account.state.value;
	var zip = document.account.zip.value;
	var phone = document.account.phone.value;
	var fax = document.account.fax.value;
	var email = document.account.email.value;
	var userName = document.account.userName.value;
	var hint = document.account.hint.value;
	var password = document.account.password.value;
	var password2 = document.account.password2.value;
	var bizType = document.account.bizType.value;

type_bizType = typeof bizType;
//alert("bizName is: " + bizName);
//if (type_bizType == 'undefined'); alert("type of bizType is: " + type_bizType);

//define each regular expression to validate input from screen form
	var bizNameRegxp = /[0-9A-Za-z\s]/;	// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/
	
	var firstNameRegxp = /[0-9A-Za-z\s]/;	// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/

	var lastNameRegxp = /[0-9A-Za-z\s]/;	// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/
				
	var asiNumRegxp = /[0-9\s]/;		// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/

	var ppaiNumRegxp = /[0-9\s]/;		// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/

	var taxIDRegxp = /[0-9A-Za-z\s]/;		// to check for non-numbers, use \D, \W checks for non-words = is the equivalent of /[0-9a-zA-Z]/

	var addrRegxp = /[0-9A-Za-z\s]/;		// allows alphanumeric characters and spaces throughout string
	
	var addr2Regxp = /[0-9A-Za-z\s]/;		// allows alphanumeric characters and spaces throughout string
	
	var cityRegxp = /[0-9A-Za-z\s]/;		// allows alphanumeric characters throughout string
	
	var stateRegxp = /[0-9A-Za-z\s]/;		// allows alphanumeric characters and spaces throughout string
	
	var zipRegxp = /[0-9]{5}/;				// allow only numeric values up to five characters including a dash e.g. 55117
	
	var phoneRegxp = /[0-9A-Za-z\s]/; 		//allow only numeric values for a total of 10 characters /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;


	var faxRegxp = /^([0-9]{10})$/;	  		//allow only numeric values for a total of 10 characters
	
	/*EMAIL Validation
		any word character displayed one or more times can then be followed by a dot, 
		then any number of word characters displayed zero or more times, followed by the @ symbol, 
		followed by any word character displayed one or more times, 
		followed by a dot and two or three word characters repeated at least once but no more than twice
	
	var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
	*/
	
	var emailRegxp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	var userNameRegxp = /[0-9A-Za-z\s]/;
		
	var hintRegxp = /[0-9A-Za-z\s]/;	
		
	var passwordRegxp = /[0-9A-Za-z\s]/;	
		
	var password2Regxp = /[0-9A-Za-z\s]/;	
	
	var bizTypeRegxp = /[0-9A-Za-z]/;	
		
//Each variable is tested for passed validation or fails with an error message 
	if  (bizNameRegxp.test(bizName) != true) 
	{
	  alert("Company name appears to be blank or invalid.");
	return false;
	}
	else if (firstNameRegxp.test(firstName) != true)	
	{
	 alert("First name appears to be blank or invalid.");
	return false;
	}
	else if (lastNameRegxp.test(lastName) != true)	
	{
	 alert("Last name appears to be blank or invalid.");
	return false;
	}
		
	else if ((asiNum == '') && (ppaiNum == '') && (taxID == ''))
	{
		 alert("State Tax ID or Trade Association ID required for Resale Verification.");
	return false;
	}
	else if ( (asiNumRegxp.test(asiNum) != true) && (asiNum != '') )
	{
	 alert("ASI distributor number may only contain numerals.");
	return false;
	}
	else if ( (ppaiNumRegxp.test(ppaiNum) != true) && (ppaiNum != '') )	
	{
	 alert("PPAI distributor number may only contain numerals..");
	return false;
	}
	else if ( (taxIDRegxp.test(taxID) != true) && (taxID != '') )
	{
	 alert("Tax ID number appears to be blank or invalid.");
	return false;
	}
	else if (addrRegxp.test(addr) != true) 
	{
	 alert("Address1 appears to be blank or invalid.");
	return false;
	}
	else if ( (addr2Regxp.test(addr2) != true) && (addr2 != '') )
	{
	 alert("Address2 appears to be blank or invalid.");
	return false;
	}
	else if (cityRegxp.test(city) != true)	
	{
	 alert("City appears to be blank or invalid.");
	return false;
	}
	else if (stateRegxp.test(state) != true)	
	{
	 alert("State appears to be blank or invalid.");
	return false;
	}
	else if (zipRegxp.test(zip) != true)	
	{
     alert("Zip code appears to be blank or invalid.");
	 return false;
	}
	else if (phone == '')	//(phoneRegxp.test(phone) != true)
	{
	  alert("Phone number appears to be blank or invalid.");
	return false;
	}
	else if (emailRegxp.test(email) != true)	
	{
	  alert("Your email address appears to be blank or invalid.");
	return false;
	}
	else if (userNameRegxp.test(userName) != true)	
	{
	  alert("The username appears to be blank or invalid.");
	return false;
	}
	else if (hintRegxp.test(hint) != true)	
	{
	  alert("Your hint appears to be blank or invalid.");
	return false;
	}
	else if (passwordRegxp.test(password) != true)	
	{
	  alert("Your password1 appears to be blank or invalid.");
	return false;
	}
	else if (password2Regxp.test(password2) != true)	
	{
	  alert("Your password2 appears to be blank or invalid.");
	return false;
	}
	else if (password != password2)
	{
		alert("Your passwords do not match, please reenter your passwords");
	return false;
	}
}	


