<!-- Begin hiding from older browsers
// This file contains the scripts for the survey form page.  The functions are as follows:



//		GLOBAL VARIABLES
var nowdate = new Date();



//		GLOBAL FUNCTIONS



// function intializeYear()
// Initializes the value of the VISITYEAR hidden field on the page for use in later function calls.
// It is called by the onLoad event in the BODY tag.
// 
function initializeYear(thisDocument) { thisDocument.SURVEYFORM.VISITYEAR.value = nowdate.getYear(); }



// function setVisitField()
// Performs the toggling of the DISABLED attribute of the FREQUENCY field based on user choice in 
// FIRSTVISIT field.
//
function setVisitField(thisForm) {
	if (thisForm.FIRSTVISIT.checked) {
		thisForm.FREQUENCY.selectedIndex = 5;
		thisForm.FREQUENCY.disabled = true;
	}
	else {
		thisForm.FREQUENCY.selectedIndex = 0;
		thisForm.FREQUENCY.disabled = false;
	}
}



// function resetForm()
// Performs the work and housekeeping required for the statuses of the page fields when the user clicks
// "Reset Form" button.
//
function resetForm(thisForm) {
	thisForm.reset();
	thisForm.FREQUENCY.disabled = false;
	thisForm.VISITMONTH.disabled = true;
	thisForm.VISITDAY.disabled = true;
}



// function setVisitDateField()
// Performs the toggling of the DISABLED attribute of the VISITMONTH & VISITDAY fields based on user
// choice in the KNOWDATE field. 
//
function setVisitDateField(thisForm) {
	if (thisForm.KNOWDATE.checked) {
		thisForm.VISITMONTH.disabled = false;
		thisForm.VISITDAY.disabled = false;
		thisForm.VISITMONTH.options[nowdate.getMonth()].selected = true;
		changeMonth(thisForm);
	}
	else {
		thisForm.VISITMONTH.options[0].selected = true;
		changeMonth(thisForm);
		thisForm.VISITMONTH.disabled = true;
		thisForm.VISITDAY.disabled = true;
	}
}



// functon changeMonth
// Scripting for the main loop to adjust the VISITDAY options when VISITMONTH is changed.
//
function changeMonth(thisForm) {
// Realigns the value of the VISITYEAR field based on the month selected.  The logic assumes
// that if the month selected has not begun yet in the current year, then the intended date is
// in the previous year.  This accomodates surveys which might not be submitted in the same month/year
// as the actual visit date.  NOTE:  This logic also limits the ability to submit a survey for a visit
// date that occurred more than 11 months in the past.  However, this is highly unlikely to occur and
// a decision had to be made on how complicated it was necessary to get in codind this logic.  Whaddidah!
	var sCurrentMonth = nowdate.getMonth()+1;
	var iYearMod = parseInt(thisForm.VISITYEAR.value) % 4;
	if (parseInt(thisForm.VISITMONTH.value) > sCurrentMonth) {
	thisForm.VISITYEAR.value = nowdate.getFullYear()-1;
	}
		else {
		thisForm.VISITYEAR.value = nowdate.getFullYear();
		}
// Major branching statement to determines the number of days in the month after the year decision 
//is made above, then executes the subloop to change the options in the page field.
	switch (thisForm.VISITMONTH.value) {
		case "1" : 	setVistDaySelect(thisForm,31); break;
		case "2" : 	if (iYearMod = 0) {	setVistDaySelect(thisForm,29); break; }
					else { setVistDaySelect(thisForm,28); break; }
		case "3" : 	setVistDaySelect(thisForm,31); break;
		case "4" : 	setVistDaySelect(thisForm,30); break;
		case "5" : 	setVistDaySelect(thisForm,31); break;
		case "6" : 	setVistDaySelect(thisForm,30); break;
		case "7" : 	setVistDaySelect(thisForm,31); break;
		case "8" : 	setVistDaySelect(thisForm,31); break;
		case "9" : 	setVistDaySelect(thisForm,30); break;
		case "10" : setVistDaySelect(thisForm,31); break;
		case "11" : setVistDaySelect(thisForm,30); break;
		case "12" : setVistDaySelect(thisForm,31); break;
		default :	alert("Error: CASE statement value for changeMonth() is out of range."); break;
	}
// Sub loop to execute the changes to the VISITDAY options within the braching control above.
				function setVistDaySelect(thisForm,daysInMonth) {
					var dVisitDate = new Date(thisForm.VISITMONTH.value+"/1/"+nowdate.getFullYear());
					thisForm.VISITDAY.length = 0;
					for (var i = 0; i < daysInMonth; i++) {
						thisForm.VISITDAY.options[i] = new Option(i+1,i+1);
					}
					return;
				}

}



// function validateSurvey
// Performs all validation of page data and finalizes values of all fields prior to execution 
// of the form action following submit event.
//
function validateSurvey(thisForm) {
// Validate ZIPCODE field length = 5 and a valid number
	if (thisForm.ZIPCODE.value.length != 5 || isNaN(thisForm.ZIPCODE.value)) {
		alert("The ZIPCODE field must be exactly 5 numeric digits.  Please enter a proper ZIPCODE and re-submit.");
		thisForm.ZIPCODE.focus();
		thisForm.ZIPCODE.select();
		return (false);
	}
// Validate FREQUENCY field for proper value
	if (thisForm.FREQUENCY.selectedIndex < 1) {
		alert("You indicated that this was NOT your first visit to the Torch Bar.  Please specify how often you visit, and re-submit.");
		thisForm.FREQUENCY.focus();
		return (false);	
	}
// Compute CSI score and set into form field
	thisForm.CSI.value = (
		parseInt(thisForm.MENU.value) + 
		parseInt(thisForm.QUALITY.value) + 
		parseInt(thisForm.ACCURATE.value) +
		parseInt(thisForm.ORDERSPEED.value) + 
		parseInt(thisForm.SERVESPEED.value) + 
		parseInt(thisForm.STAFF.value) + 
		parseInt(thisForm.PRICES.value) + 
		parseInt(thisForm.CLEAN.value)) / 8;
// Display Total CSI Score
	alert("You gave a Customer Satisfaction Index rating of ... " + 
			parseFloat(thisForm.CSI.value).toFixed(2) + 
			"\n\nClick OK to continue."
			);
// Finalize variables and field states before submit
	if (thisForm.KNOWDATE.checked) {
		thisForm.VISITDATE.value = 
			thisForm.VISITMONTH.value + "/" + thisForm.VISITDAY.value + "/" + thisForm.VISITYEAR.value;
	}
		else {
			thisForm.VISITDATE.value = "";
		}
	thisForm.EMAILONADD.value = "torchsurvey@torchbar.com"
	thisForm.EMAILADDFROM.value = "torchsurvey@torchbar.com"
	thisForm.EMAILCONTACT.value = "torchsurvey@torchbar.com"
//// Delete this Section on live launch of Db
//	alert("End of Test:  Form validates TRUE for submission to the server.\n\nEMAILONADD = "+thisForm.EMAILONADD.value);
//	return false;
////
// Submit form
	thisForm.FREQUENCY.disabled = false;
	return true;
}



// End hiding from older broswers -->
