// JavaScript Document

/************************************************
ValidateEmail(string input)
 Return true or false
 if the email is valid or not.
 checks for @ and .
**************************************************/
function ValidateEmail(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
 if(s.indexOf)
 {
  at_character=s.indexOf('@');
  if(at_character<=0 || at_character+4>s.length)
   return false;
 }
 if(s.length<6)
  return false;
 else
  return true;
}
 
/************************************************
ValidateName(string input)
 Return true or false
 if the email is valid or not.
**************************************************/
function ValidateName(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^[^&'^`]+$","gi"))>=0);
 if(s.length<2)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidatePhone(string input)
 Return true or false
 if the phone number is valid or not.
 acepts - and + symbols
**************************************************/
function ValidatePhone(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
 if(s.length<5)
  return false;
 else
  return true;
}
	 

/************************************************/
// Validate Forms 
/************************************************/

/************************************************
FORM checkFreePortfolioReview
**************************************************/

function checkFreePortfolioReview(){
	var error="";
	if(!ValidateName(document.frmFreePortfolioReview.fname.value)){
		error+="   * First Name\n";
	}
	if(!ValidateName(document.frmFreePortfolioReview.lname.value)){
		error+="   * Last Name\n";
	}	
	if(!ValidateName(document.frmFreePortfolioReview.address.value)){
		error+="   * Street address\n";
	}	
	if(!ValidateName(document.frmFreePortfolioReview.city.value)){
		error+="   * City\n";
	}	
	if(!ValidateName(document.frmFreePortfolioReview.state.value)){
		error+="   * State\n";
	}	
	if(!ValidateName(document.frmFreePortfolioReview.zip.value)){
		error+="   * ZIP\n";
	}	
	if(!ValidatePhone(document.frmFreePortfolioReview.phone.value)){
		error+="   * Daytime phone\n";
	}	
	if(!ValidateName(document.frmFreePortfolioReview.contacttime.value)){
		error+="   * Best time to call\n";
	}	
	if(!ValidateEmail(document.frmFreePortfolioReview.email.value)){
		error+="   * Email address\n";
	}	
	if(error=="")
		document.frmFreePortfolioReview.submit();
	else
		alert("Error! Please check:\n"+error);
}

