// 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 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 username1 = document.account.username1.value;
	var username2 = document.account.username2.value;
	var hint = document.account.hint.value;
	var password = document.account.password.value;
	var password2 = document.account.password2.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 asiNumRegxp = /[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 ppaiNumRegxp = /[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 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 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 (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(username1) != true)	
	{
	  alert("Your username 1st choice appears to be blank or invalid.");
	return false;
	}
		else if (userNameRegxp.test(username2) != true)	
	{
	  alert("The username 2nd choice appears to be blank or invalid.");
	return false;
	}
}	

