
function checkRegistrationForm(theForm) {
	
    var why = "";
    why += checkFirstName(theForm.first_name.value); 
   	why += checkLastName(theForm.last_name.value);
    //why += checkBusinessName(theForm.business_name.value); 
    why += checkState (theForm.country.value);   
    why += checkPhone(theForm.phone.value);  
    why += checkEmail(theForm.email.value);
    why += checkUsername(theForm.username.value);     
    why += checkPassword(theForm.password.value);
    why += ConfirmPassword (theForm.password.value,theForm.password_confirm.value);
      
    if (why != "") {
       alert(why);
       return false;
    }
    
return true;
}

function checkLoginForm(theForm)
{
	var why = "";
    why += checkUsername(theForm.username.value); 
    why += checkPassword(theForm.password.value);
    
    if (why != "") {
       alert(why);
       return false;
    }
    
return true;
	
}

function checkPassLookup(theForm)
{
	var why = "";
    why += checkEmail(theForm.email.value);     
    
    if (why != "") {
       alert(why);
       return false;
    }
    
return true;
	
}


function checkFirstName (strng)
{
	 var error = "";
	 if (strng == "") 
	    error = "You didn't enter a first name.\n";
	    
	  	
	var illegalChars = /\W | {\}/;
	  // allow only letters, numbers, and underscores
	    if (illegalChars.test(strng)) 
	       error = "The first name contains illegal characters.\n";

return error;	    
}

function checkLastName (strng)
{
	 var error = "";
	 if (strng == "") 
	    error = "You didn't enter a last name.\n";
	    
	  	
	var illegalChars = /\W | {\}/;
	  // allow only letters, numbers, and underscores
	    if (illegalChars.test(strng)) 
	       error = "The last name contains illegal characters.\n";

return error;	    
}

function checkBusinessName (strng)
{
	 var error = "";
	 if (strng == "") 
	    error = "You didn't enter a business name.\n";
	    
	  	
	var illegalChars = /\W | {\}/;
	  // allow only letters, numbers, and underscores
	    if (illegalChars.test(strng)) 
	       error = "The business name contains illegal characters.\n";

return error;	    
}

function checkState (strng)
{
	 var error = "";
	 if (strng == "n") 
	    error = "You didn't enter a country.\n";
	
return error;	    
}

function checkUsername (strng)
{
	 var error = "";
	 if (strng == "") 
	    error = "You didn't enter a username.\n";
	    
	  	
	var illegalChars = /\W/;
	  // allow only letters, numbers, and underscores
	    if (illegalChars.test(strng)) 
	       error = "The username contains illegal characters.\n";

return error;	    
}
 
 function checkPassword (strng) 
{
	 var error = "";
	 if (strng == "") 
	    error = "You didn't enter a password.\n";
	 
	    var illegalChars = /[\W_]/; // allow only letters and numbers
	    if ((strng.length < 6) || (strng.length > 15)) 
	       error = "The password is the wrong length.\n";
	    
	    else if (illegalChars.test(strng)) 
	      error = "The password contains illegal characters.\n";
	      
return error; 
}

function checkEmail(strng)
{
	var error = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) 
         error = "Please enter a valid email address.\n";

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\[\]]/
	if (strng.match(illegalChars)) 
   		error = "The email address contains illegal characters.\n";

  return error;  		
}

function checkPhone(strng)
{
	var error = "";

	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) 
   		error = "The phone number contains illegal characters. \n";
   		
   	/*	
   	if (!(stripped.length == 10))
	error = "The phone number is the wrong length.
	  Make sure you included an area code.\n";
	*/
return error; 
	
}

function ConfirmPassword (pass, pass_conf)
{
	var error = "";

		if (pass!=pass_conf)
			error = "Please confirm password again";	
			
return error; 	
}


	
