<!--
//	##############################################
//  Please do not delete this text
//  
//  Created by: Capo
//	Creation date: 05/04/2004
//	Contact mail: capo@soulcreation.com
//  Website: http://www.soulcreation.com
//
//  Modified by: Alex Haynes
//  Modification date: 12/16/2005
//	Contact mail: hts@web-page-development.com
//  Website: http://www.web-page-development.com
//	##############################################
// -->

var d = document;

function FcheckForm(contactForm){
	
	//------------------------------------------------------------------------
	// Whenever you add a line, the appropriate field will be checked when 
	// pressing the SUBMIT button
	//------------------------------------------------------------------------
	
	// Most functions need 2 parameters: 
	// Fieldname (eg Name) and html-reference (f.name.value)
	//
	// Other functions for textarea, multiple selectboxes and checkboxes
	// require 3 or 4 parameters:
	// Fieldname, html-reference, min value, max value
	//
	// Function:
	// FcheckNameChanged  : checks if Name Field has been filed and is not still teh default form value
	// FcheckMinLength    : checks if the given amount or more characters are filled in
	// FcheckEmail        : email validation
	// validateUSPhone    : checks if phone number is formatted properly
	
	if(!checkNameChanged('Name',contactForm.D_Name.value)){contactForm.D_Name.focus();return (false); }
	if(!checkMinLength('Name',contactForm.D_Name.value,2)){contactForm.D_Name.focus();return (false); }
    
	if(!validateUSPhone(contactForm.D_Phone.value)){contactForm.D_Phone.focus();return (false); }
    if(!checkMinLength('Phone',contactForm.D_Phone.value,10)){contactForm.D_Name.focus();return (false); }

	if(!checkEmail('Email',contactForm.D_Email.value)){contactForm.D_Email.focus();return (false); }
	
	if (!fconfirm()) {return (false);}
	
	return (true);
}

//------------------------------------------------------------------------
//  Everything below this should not be changed, unless you want to use
//  this script for another language. then change text between "" in all
//  functions you are going to use.
//------------------------------------------------------------------------
function fconfirm(){
	var agree=confirm("All data appears to be filled in correctly!\nSend now?");
	if (agree)
		return true ;
	else
		return (false) ;
}

function checkNameChanged(n,v){ 
    var cname='Your Name'
	if(v=="" || v==cname){ alert(n+" is required!");return (false); }
	else { return true; }
}

function checkMinLength(n,v,num){ 
    var cphone='Phone';
    var cname='Name';
    
    if(v.length<num){ 
       if (n==cname) {alert("Min. chars for "+n+" is "+num+"!");return (false); }
       if (n==cphone){alert(n+" must be at least "+num+" digits including area code!");return (false); } 
	}
	else { return (true); }
}

function validateUSPhone(v) {
	/************************************************
	DESCRIPTION: Validates that a string contains valid
  		US phone pattern. 
  		Ex. (999) 999-9999 or (999)999-9999
  
	PARAMETERS:
   		strValue - String to be tested for validity
   
	RETURNS:
   		True if valid, otherwise false.
	*************************************************/
 	var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
 
  	//check for valid us phone with or without space between 
  	//area code
  	if (objRegExp.test(v)){
  		return (true)
  	}
  	alert("Please enter a valid phone number. Format = (XXX)XXX-XXXX")
  	return (false) 
}

function checkEmail(n,v){
	var a=0
	var p=0
	for(var i=1;i<v.length;i++){
		if(!v.charAt(i)){return (false);}
		else if(v.charAt(i)=='@'){a++;if(v.charAt(i+1)==''){ alert(n+" is not valid!");return (false); }}
		else if(v.charAt(i)=='.'){p++;if(v.charAt(i+1)==''||v.charAt(i+1)=='@'||v.charAt(i-1)=='@'){ alert(n+" is not valid!");return (false); }}
	}
	if(a==1&&p){ return (true); }
	else { alert(n+" is not valid!");return (false); }
}
