// JavaScript Document



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

//check a text date feild for content
function checkdatefeild(strng, stmnt){
	if((strng == "")||(strng == '(YYYY-MM-DD)')){
			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 += location+"Phone number contains illegal characters.\n";
	}
	
	if (!(stripped.length == 10)) {
	stmnt += location+"Phone number is the wrong length. (inlcude area code).\n";
	}
	
		if(stmnt != ""){
		return stmnt;
		}else{
		return "";
		}
	
}


function CheckDropDown(value, Dflt, stmnt){
	if(value == Dflt){
		return stmnt;
	}else{
		return "";
	}
}

//check radio buttons
function checkradio(path_radioname, stmnt){
	
	function checkRadio(checkvalue) {
	var errorr = "";
		if (!(checkvalue)) {
		   errorr = stmnt;
		}
	return errorr;    
	}
	
for (i=0, n=path_radioname.length; i<n; i++) {
	  if (path_radioname[i].checked) {
		 var checkvalue = path_radioname[i].value;
		 break;
	  }
}	
return checkRadio(checkvalue);
}

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

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

error += CheckDropDown(path.mgr_restaurant_location.value, "", "Please choose a MGR location.\n");				// loc 
error += checkdatefeild(path.visit_date.value, "Please enter the date of your visit.\n"); 							// date
error += CheckDropDown(path.time_of_day.value, "", "Please choose a time of day.\n");							// time of day 
/*error += checkfeild(path.server_name.value, "Please enter server's name.\n"); 									// server name*/

error += checkradio(path.taste, "Please choose a level of taste.\n"); 											// taste
error += checkradio(path.freshness, "Please choose a level of freshness.\n"); 									// freshness
error += checkradio(path.portion_size, "Please  choose a level of portion size.\n"); 							// portion size
error += checkradio(path.temperature, "Please  choose a level of temperature.\n"); 								// temp

error += checkradio(path.hostess_greeting, "Please rate your host/hostess greeting.\n"); 					// host greeting
error += checkradio(path.knowledge_of_server, "Please rate your server's knowledge.\n"); 						// server knoledge
error += checkradio(path.overall_attitude_of_server, "Please rate your overall attitude of service.\n"); 		// overall attitude
error += checkradio(path.speed_of_service, "Please rate the speed of service.\n"); 								// speed of service

error += checkradio(path.atmosphere, "Please rate the atmosphere.\n"); 											// atmosphere
error += checkradio(path.cleanliness_of_restaurant, "Please rate the cleanliness of the restaurant.\n"); 	// restaurant cleanliness
error += checkradio(path.cleanliness_of_washrooms, "Please rate the cleanliness of the washrooms.\n"); 		// washroom cleanliness
error += checkradio(path.audio_level_of_music, "Please rate the audio level of the music.\n"); 				// audio level of misic
error += checkradio(path.menu_selection_or_variety, "Please rate the menu selection or variety.\n"); 		// menu selection
error += checkradio(path.overall_dining_experience, "Please your overall dining experience.\n");			// overall dinning experience

error += checkradio(path.did_you_see_a_manager_on_duty, "Did you see a manager on duty?\n"); 							// did you see manager
error += checkradio(path.did_a_manager_visit_your_table, "Did a manager visit your table?\n"); 							// did manager visit table
error += checkradio(path.first_time_this_location, "Was this your first visit to this MGR location?\n"); 							// was this your first mgr
error += checkradio(path.will_you_visit_again, "Will you visit again?\n"); 							// will you visit again
error += checkradio(path.would_you_recommend, "Would you recommend us to a friend?\n"); 							// would you reccomend 
/*error += checkfeild(path.name.value, "If no, why?\n"); 						// if no why*/
error += checkradio(path.receive_communications, "Please indicate if you would like to receive comunications from MGR.\n"); 							// receive communications


//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/guest.email.php';
		path.submit();
	}	
	
}
