// 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 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){
	var stmnt = "";
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	   stmnt += "The home phone number contains illegal characters.\n";
	}
	
	if (!(stripped.length == 10)) {
	stmnt += "The home 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.kafrm;	

//###############################################################################################################################
error += checkfeild(path.name.value, "Please enter your name.\n"); //name
error += checkPhone(path.phone.value); //phone
error += checkemail(path.email.value, "Your"); //email

error += checkfeild(path.challenge_response.value, "You must answer the anti spam question.\n"); //name
//###############################################################################################################################

	if(error != ""){
		alert(error);
	}else{
		path.submit();
	}	
	
}