function validateUserData(form) {
	    var error = "";
	    var firstName = trim(form.firstName.value);
  	    var lastName = trim(form.lastName.value);
		var email = trim(form.email.value);
		var title = trim(form.title.value);
	    var companyName = trim(form.companyName.value);
	    var address = trim(form.address.value);
	    var city = trim(form.city.value);
	    //var state = form.state.value;
	    var zip = trim(form.zip.value);
	    var areaCode = trim(form.areaCode.value);
	    var exchangeNumber = trim(form.exchangeNumber.value);
	    var lineNumber = trim(form.lineNumber.value);
	    var phone = areaCode + exchangeNumber + lineNumber;	    
	    
            // First Name
		    if (firstName == null || firstName.length < 1) {
		        error += "You must enter your First Name. \n";
            } else if (firstName.length > 25 || firstName.length < 3) {
                error += "Your First Name must have a minimum of 3 characters and a maximum of 25 characters. \n";
		    } else if (!isValidName(firstName)) {
		    	error += "Your First Name must contain letters and punctuation only. \n";
		    }
            
            // Last Name
		    if (lastName == null || lastName.length < 1){
		        error += "You must enter your Last Name. \n";
            } else if (lastName.length > 50 || lastName.length < 3) {
                error += "Your Last Name must have a minimum of 3 characters and a maximum of 50 characters. \n";
		    } else if (!isValidName(lastName)) {
		    	error += "Your Last Name must contain letters and punctuation only. \n";
		    }
			
			// Email Address
		    if (email == null || email.length < 1) {
		        error += "You must enter your Email Address. \n";
            } else if (!validateEmail(email)) {
                error += "Your Email Address must be in the format name@domain.domaintype. \n";
		    }
   
            // Title Name
		    if (title == null || title.length < 1){
		        error += "You must enter your Title. \n";
            } else if (title.length > 100 || title.length < 2) {
                error+= "Your Title must have a minimum of 2 characters and a maximum of 100 characters. \n"
		    } else if (!isAlphanumericPuncWithSpaces(title)) {
		    	error += "Your Title must contain letters, punctuation, or numeric characters only. \n";
		    }
			
			// Company Name
		    if (companyName == null || companyName.length < 1){
		        error += "You must enter your Company. \n";
            } else if (companyName.length > 100 || companyName.length < 2) {
                error+= "Your Company must have a minimum of 2 characters and a maximum of 100 characters. \n"
		    } else if (!isAlphanumericPuncWithSpaces(companyName)) {
		    	error += "Your Company must contain letters, punctuation, or numeric characters only. \n";
		    }
			
            
            // Address
		    if (address.length > 0){
		        if (address.length > 100 || address.length < 2) {
                	error+= "Your Address must have a minimum of 2 characters and a maximum of 100 characters. \n"
		    	} else if (!isAlphanumericPuncWithSpaces(address)) {
		    		error += "Your Address must contain letters, punctuation, or numeric characters only. \n";
		   		}
		   	}
            
            // City
			if (city.length > 0){
		        if (city.length > 100 || city.length < 3 ) {
                	error += "Your City must have a minimum of 3 characters and a maximum of 100 characters. \n";
		    	} else if (!isAlphanumericWithSpaces(city)) {
		    		error += "Your City must contain letters or punctuation only. \n";
		    	}
		    }
		    
            /*
            // State
		    if (state != null && state.length < 1){
		        error += "You must select your State. \n";
		    } else if (!isStateCode(state)) {
		    	error += "You must select your State. \n";
		    }
            */
            
            // Zip Code
		    if (zip.length > 0){
		        if (zip.length > 5 || zip.length < 5 ) {
                	error += "Your Zip must have 5 numeric characters. \n";
				} else if (!isZIPCode(zip)) {
		    		error += "Your Zip Code must be 5 numeric characters. \n";
		    	}
            }
            
			// Area code
		    if (areaCode.length > 0){
		        if (areaCode.length > 3 || areaCode.length < 3 ) {
                	error += "Your Area Code must have 3 numeric characters. \n";
		    	}
		    }
			
			// exchange number
		    if (exchangeNumber.length > 0){
		        if (exchangeNumber.length > 3 || exchangeNumber.length < 3 ) {
                	error += "Your Exchange Number must have 3 numeric characters. \n";
                }
		    }
			
			// line number
		    if (lineNumber.length > 0){
		        if (lineNumber.length > 4 || lineNumber.length < 4 ) {
                	error += "Your Line Number must have 4 numeric characters. \n";
               	}
		    }
            
		    
            // Telephone Number
		    if (phone.length > 0){
				if (! (isUSPhoneNumber(phone) && isValidPhone(phone))) {
		    		error += "Your Telephone Number must be 10 numeric characters and all characters must not be the same. \n";
		    	}
		    }
            
		    if (error != "") {
		        alert(error);
		        return false;
		    } else {
		        return true;
		    }
	}

function isAlphanumericPuncWithSpaces (s) {

   var i;
    if (isEmpty(s)) 
       if (isAlphanumericWithSpaces.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumericWithSpaces.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)  {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) || c == " ") ) {
        	 if (!(c == "'" || c == "-" || c == "," || c == "_" || c == "." || c == ":" || c == "?" || c == "(" || c == ")" || c== "&" || c == "#" || c == " ")) {
	                   return false;
	          }
        }
    }
    
    // All characters are numbers or letters.
    return true;
}


function isValidName(s)

{   var i;

    if (isEmpty(s)) 
       if (isValidName.arguments.length == 1) return defaultEmptyOK;
       else return (isValidName.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c)) {
        	if (!(c == "'" || c == "," || c == "-" || c == "_" || c == "." || c == ":" || c == "?" || c == "("
	         || c == ")" || c== "&" || c == "#" || c == " "))
	         {
	            return false;
	         }
        }
    }

    // All characters are letters or allowable punctuation.
    return true;
}

function isValidPhone(s)

{   var i;

    if (isEmpty(s)) 
       if (isValidPhone.arguments.length == 1) return defaultEmptyOK;
       else return (isValidPhone.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a number repeating in all places.
    // When we do, return false; if we don't, return true.
	var firstChar = s.substring(0, 1);
	var repeatNumber = 1;
    for (i = 1; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (c == firstChar) {
        	repeatNumber++;
        }
    }
	if (repeatNumber == s.length) {
		return false;
	} else {
    	return true;
    }
}

function trim(s) 
   {
   	// Remove leading spaces and carriage returns
   	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }
     
   	// Remove trailing spaces and carriage returns
 	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }
	
   	return s;
  }
function isAlphanumericWithSpaces (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumericWithSpaces.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumericWithSpaces.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) || c == " ") )
        	return false;
    }

    // All characters are numbers or letters.
    return true;
}
function isValidPassword(s) 
{	var i;

	if (isEmpty(s)) 
       if (isValidPassword.arguments.length == 1) return defaultEmptyOK;
       else return (isValidPassword.arguments[1] == true);
	  for (i = 0; i < s.length; i++)
	  {   
	        // Check that current character is number or letter.
	        var c = s.charAt(i);
	
	        if (! (isLetter(c) || isDigit(c)) )
	        	return false;
	  }     
}
function validateEmail(s)
{
  //Validating the email field
  var regex = /^([a-zA-Z0-9_\-\.])+@(([0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5])|((([a-zA-Z0-9\-])+\.)+([a-zA-Z\-])+))$/;
  return regex.test(s);
}