// 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 "";
		}
	
}


//check checkbox
function checkcheck(frmVar, stmnt){
	
	if(!frmVar.checked){
		return stmnt;
	}else{
		return "";
	}
	
}

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

//###############################################################################################################################
error += checkfeild(path.name.value, "Please enter your name.\n"); 							// name
error += checkemail(path.email.value, "Your"); 												//email
error += checkcheck(path.agree, "You must agree to the terms.");
//###############################################################################################################################

	if(error != ""){
		alert(error);
	}else{
	
		path.action = "email/submit_event.email.php";
		path.submit();

	}	
	
}
