// ****************************************************************************
//
//  Checkform: alerts, confirms and prompts
//
//	Written by Lisa S. Chang
//
// ****************************************************************************

// verify the required fields are entered

	function isblank(s) {
		for(var i=0; i<s.length; i++) {
			var c=s.charAt(i);
			if ((c!=' ') && (c!='\n') && (c!='\t')) return false;
		}
		return true;
	}

	//form verification function
	function verify(f) {
		var msg, error_message;
		var checkedname = "";
		var empty_fields = "";
		for (var i=0; i<f.length; i++) {
			var e=f.elements[i];
			
			if (((e.type=="text") || (e.type=="textarea")) && !e.optional) {
				//check for an empty field first
				if ((e.value==null) || (e.value=="") || isblank(e.value)) {
					empty_fields += "\n  " + e.name;
					//continue;
					msg = "The following field is required:" + empty_fields
					alert(msg);
					return false;
				}
				
				//display any recognized errors and return false to prevent form submission
				//otherwise, return true and submit form
				
			}
			/*			
			if (e.type == "select-one") {
				alert(e.name);
				if ((e.selectedIndex = -1) || (e.selectedIndex = 0)) { 
					error_message = "Please indicate the location being evaluated.  It would help us to serve our customers better to know the location you are evaluating.";
					alert (error_message);
					return false;
				}			
			}
			*/
				
			if (e.type == "radio") {
				//loops through the 5 value survey to check each radio button with the same name
				onechecked = false; //resets the onechecked variable
				if (e.name != checkedname) {
					for (n=0; n < 4; n++) {
						e=f.elements[i+n];
						if (e.checked)
							onechecked = true;
					}
					
				i=i+3; //increments the element number so that it will check the next set of radio buttons			
				}
				
				if (!onechecked) {
					if (e.name == "business")
						error_message = "Please enter the 'Type of Business' that most resembles your operations.\n          For further clarification, feel free to write us comments.";
														 					
					alert(error_message);
	                return false;
				}
			}	
			 
			
		} //ends the for loop 
	}