<!--
//FORM VALIDATION JAVASCRIPT
//VERSION 1.0 -- 02.24.00
//construct javascripting to check required fields and valid emails
//extends form validation into server-side javascript


//checks for a valid zip code IN U.S. ONLY!!!
//THIS FUNCTION IS CURRENTLY INACTIVE
//ENABLE ONLY IF PROMOTION IS STRICTLY U.S. ONLY
function isnumeric(f) {
	alert(f);
	var numeric = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<f.elements.zip.value.length; i++) {
		temp = "" + f.elements.zip.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no") {
		alert("Invalid");
		field.focus();
		field.select();
		}
	}	

//function returning true if a string contains only
//whitespace characters.
	
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;
}

//function performs form verfication. invoked from the onSubmit() event handler.
//handler return whatever value this function returns.

function verify_form(f)
{
	var msg;
	var empty_fields="";
	var errors="";
	
	//checks for valid email address by looking for an @ and a following .
	//error key:
	//error 1.2 - no @ symbol
	//error 1.3 - no "." in string
	//error 1.4 - "." in the last or penultimate index of string
	//error 1.5 - no "." following @
	//error 1.6 - "." immediately follows or precedes @
	//error 1.7 - no age selected in form 	

	var e=f.elements.email;
	for (var i=0; i<f.length; i++) {
		var z = f.elements[i];
		if (((z.type=="text") || (z.type=="textarea")) && z.required) {
			//check if field is empty
			if ((z.value==null) || (z.value=="") || isblank(z.value)) {
				//insert 10 spaces after newline
				empty_fields += "\n          " + z.name;
			}
		}
	}
	
	var at_index=e.value.lastIndexOf('@');
	//check for @
	if (at_index==-1) {
		errors += "\n" + "- Invalid email (error 1.2)";
		}
	else {
		var dot_index=e.value.lastIndexOf('.');
		var email_length=(e.value.length-1);
		//check for .
		if (dot_index==-1) {
			errors += "\n" + "- Invalid email (error 1.3)";
			}
		else {
			if (((email_length-dot_index)==0) || ((email_length-dot_index)==1)){
				errors += "\n" + "- Invalid email (error 1.4)";
			}
			else {
				if (at_index>dot_index) {
					errors += "\n" + "- Invalid email (error 1.5)";
				}
				else {
					if ((Math.abs(at_index-dot_index))==1) {
						errors += "\n" + "- Invalid email (error 1.6)";
					}
				}
			}
		}
	}
	
	//make sure the user selects an age
	//returns boolean expression indicating whether 
	//user selected a valid age group
	//if (f.elements.age.options[0].selected) {
	//errors += "\n" + "- Please select your age (error 1.7)";
	//}

//display errors, if any
if (!empty_fields && !errors) return true;

msg="___________________________________\n\n"
msg +="The form was not submitted because of the following error(s).\n";
msg +="___________________________________\n\n"

if (empty_fields) {
	msg += "- The following required field(s) are empty:" + empty_fields;
	}
	
if (errors) msg += "\n";
msg += errors;
alert(msg);
return false;
}
