// JavaScript Document
function phoneCheck(phoneStr,phoneOrFax){
        var digitCount=0;
   	
   	//Count the number of digits in the phone number
        for(var i=0;i<phoneStr.length;i++){
            if( (phoneStr.charAt(i) >= '0') && (phoneStr.charAt(i) <= '9') )
              digitCount++;
            else if( phoneStr.charAt(i) != ' ' && phoneStr.charAt(i) != '(' && 
                      phoneStr.charAt(i) != ')' && phoneStr.charAt(i) != '-' ){
                      alert("Invalid format for " + phoneOrFax + " number");
                      return false;
                  }
        }
        //If the number of digits is not 10, then it is an incorrect phone number
        if(digitCount != 10){
        	//If the number of digits is 7, then prompt for area code
		if(digitCount == 7){
		    alert("Please enter the 3 digit area code for your " + phoneOrFax + " number");
            	}
            	else{//Prompt for correct number
            	    alert("Please enter a correct " + phoneOrFax + " number");
            	}
            	return false;
        }

        return true;
    }
function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect.");
		return false;
	}
	return true;
}
function checkSubmit(){	
	var msg = "";            
	//alert(contact);
	if(document.contact.name.value.length<1){
		alert("Please enter your name.");
		return false;
	}
		
   if(document.contact.email.value==""){
	alert("Please enter your email.");
	return false;
   }
   else if(!emailCheck(document.contact.email.value))
   {
		   return false;
   }
	
	if(document.contact.phone.value==""){
		alert("Please enter your phone.");
		return false;
	}
	else if(!phoneCheck(document.contact.phone.value,"phone")){
		return false;
	}
		
	if(document.contact.message.value==""){
		alert("Please enter your message.");
		return false;
	}	
	return true;
}
