// validation functions

// email
function checkEmail(str) {
	var error = "";
	
	if (str == "")
   		return "Email address is required.\n";

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(str))) 
       error = "Please enter a valid email address.\n";
    else 
    {
		//test email for illegal characters
    	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (str.match(illegalChars))
          error = "The email address contains illegal characters.\n";
    }
    
	return error;    
}

// zip
function checkZip(str)
{
	var error = "";
	if (str == "")
		return "Zip code is required.\n";
	
	var zipFilter = /^\d{5}([\-]\d{4})?$/;
	if (!(zipFilter.test(str)))
		error = "Please enter a valid zip code (ex: 92120 or 92120-2030).\n";
	
	return error;
}

// phone number - strip out delimiters and check for 10 digits
function checkPhone(str) 
{
	var error = "";
	if (str == "")
		return "Phone Number is required.\n";

	var stripped = str.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped)))
    	error = "Phone number contains illegal characters.\n";
    else if (!(stripped.length == 10))
		error = "Phone number is the wrong length. Make sure you included an area code.\n";

	return error;
}

// first name/last name
function checkName(str, val) 
{
	if (str == "") 
   		return val + " is required.\n";
   		
   	/*
	var validName = /^[a-zA-Z]+$/;
	if (!(validName.test(str)))
		return val + " is not valid.\n";	
	*/
	return "";
}       

// company
function checkCompany(str) 
{
	if (str == "") 
   		return "Company Name is required.\n";
   		
   	/*
	var validName = /^[a-zA-Z ]+$/;
	if (!(validName.test(str)))
		return "Company Name is not valid.\n";	
	*/

	return "";
}       
