// JavaScript Document
function validatePhone(phoneNum)
{
	var phoneFormat1= /^\d{10}$/;
	var phoneFormat2= /^\d{3}-\d{3}-\d{4}$/;
	if( !phoneNum.match(phoneFormat1) && !phoneNum.match(phoneFormat2)   )
	{
		alert("Phone number must be of format 1234567890 or 123-456-7890 ");
		return(false);
	}
    return(true);

}

function validateZipCode(zipCode)
{
	var zipFormat = /\b\d{5}\b/;
    if( isNaN ( zipCode ) )
    {
      alert("Zipcode must be numeric");
      return( false );
    }
	if(zipCode.match(zipFormat) )
    {
      return(true);
    }
    else
    {
		alert("The zipcode format must be 12345");
		return(false);
    }
	
}

function validateSSN(ssn)
{
	var ssnFormat = /^\d{3}-\d{2}-\d{4}$/;
	if( !ssn.match(ssnFormat) )
	{
		alert("SSN must be of format 123-45-6789");
		return(false);
	}
	return(true);
}

function validateEmail( email )
{
	var emailFormat = /.*@.*\..*/;
    if( !email.match(emailFormat) )
	{
		alert("Invalid email format");
		return false;
	}
	if(-1 == email.indexOf("@")) { 
       alert("Your email must have a '@'."); 
       return false; 
       }
    if(-1 != email.indexOf(",")) { 
       alert("Your email must not have a ',' in it"); 
       return false; 
       }
    if(-1 != email.indexOf("#")) { 
       alert("Your email must not have an '#' in it." ); 
       return false; 
       }
    if(-1 != email.indexOf("!")) { 
       alert("Your email must not have a '!' in it." ); 
       return false; 
       }
    if(-1 != email.indexOf(" ")) { 
       alert("Your email must not have a space in it." ); 
       return false; 
       }
    if(email.length ==
         (email.indexOf("@")+1) ) {
       alert("Your email must have a domain name after the '@'.");
       return false;
       }

    if(email.length == 0) { 
      alert("Please enter your email."); 
      return false; 
      }

    return true;
}
