// JavaScript Document
//check a text feild for content
function checkfeild(strng, stmnt){
	if(strng == ""){
			return stmnt;
	}else{
			return "";
	}
}

//check email feild
function checkemail(strng, xVar){
var stmnt = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		   stmnt = xVar+" email address is not valid.\n";
	}
	
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   stmnt += xVar+" email address contains illegal characters.\n";	
	}
	
	if(stmnt != ""){
		return stmnt;
	}else{
			return "";
	}
}

//check phon number
function checkPhone(strng, location){
	var stmnt = "";
	var stripped = strng.replace(/[\(\)\.\-\ a-z A-Z]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	   stmnt += "The "+location+" phone number contains illegal characters.\n";
	}
	
	if (!(stripped.length == 10)) {
	stmnt += "The "+location+" phone number is the wrong length. Make sure you included an area code.\n";
	}
	
		if(stmnt != ""){
		return stmnt;
		}else{
		return "";
		}
	
}


//########### Validate Form
function fValidate(){	
	
	var error = "";
	var path = document.mgrfrm;	

//###############################################################################################################################
error += checkfeild(path.name.value, "Please enter your name.\n"); 						// name
error += checkemail(path.email.value, "Your"); 													//email
error += checkPhone(path.phone.value, ""); 														//Tel
error += checkfeild(path.challenge_response.value, "You must answer the anti spam question.\n"); //name
//###############################################################################################################################

	if(error != ""){
		alert(error);
	}else{
		//path.submit();
		//alert('worked');
		path.method = 'post';
		path.action = 'email/contact.email.php';
		path.submit();
	}	
	
}
