//this function takes in 
			

//global variables
var msg;
var empty_fields;
var errors;


function validate(f) {
	msg = "";
	empty_fields = "";
	errors = "";
	
	//select the proper validation function based on the form name.
	switch(f.name){
		case "":
		default:
			valContact(f);
	}
	
	//return true if there are no errors
	if (!empty_fields && !errors) return true;
	msg  = "___________________________________________________________________\n\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "___________________________________________________________________\n\n";
	if (empty_fields) {
		msg += "- The following required field(s) are empty:" + empty_fields + "\n";
		if ( errors ) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
	/**/
} // end validate()

//validations for the contact fields
function valContact(f){
	var radio_ok;
	
	if ( isEmpty(f.fname.value)) {
		empty_fields += "\n First Name";
	}
	if (  isEmpty(f.lname.value)) {
		empty_fields += "\n Last Name";
	}
	if (  isEmpty(f.address.value)) {
		empty_fields += "\n Address";
	}
	if (  isEmpty(f.phone.value)) {
		empty_fields += "\n Phone";
	}
	if ( isEmpty(f.email.value)) {
		
		empty_fields += "\n Email"; 
		
	}
	else if(!isEmail(f.email.value)){
		
		errors +=  "\n- Please enter a valid email address";
	}
}

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;
} // end isblank()
