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

//check email feild
function checkemail(strng){
var stmnt = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		   stmnt = "Please enter a valid email address.\n";
	}
	
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   stmnt += "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 "";
		}
	
}


//function to check the whole form
function validate_signup(){	
	
var error = "";
var path = document.emlfrm;

error += checkfeild(path.name.value, "Please enter your name.\n"); 							//Name
error += checkemail(path.email.value); 														//Email

	if(error != ""){
		alert(error);
	}else{
		
		
		//normally just submit the form but in this case we need to pass it through ajax functions to avoid refreshing the page
		//path.submit();
		//gater values from feilds
		vName = path.name.value;
		vEmail = path.email.value;
		
		//send info to actions signup via ajax
		//alert("working");
		sendRequest('actions/signup.php', 'pName='+vName+'&pEmail='+vEmail, signupResponce);
	}

}


