// JavaScript Document
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function CheckForm( theform )
{
	var bMissingEmail = false;
	var bMissingFields = false;
	var validateEmail = false;
	var strFields = "";
	
	if( theform.First_Name.value == '' ){
		bMissingFields = true;
		strFields += "     Billing: First Name\n";
	}
	if( theform.Last_Name.value == '' ){
		bMissingFields = true;
		strFields += "     Billing: Last Name\n";
	}
	
	
	if( theform.Phone.value == '' ){
		bMissingFields = true;
		strFields += "     Billing: Phone\n";
	}
	
	
	
	if( validateEmailv2(theform.Email.value)){
		validateEmail = true;
		}

	if( bMissingFields ) {
		alert( "I'm sorry, but you must provide the following field(s) before continuing:\n" + strFields );
		return false;
	}
	if( validateEmail == false ) {
		alert( "Please enter a valid E-mail address");
		return false;
	}
		
	return true;
}

