// JavaScript Document
function validate(f){
	// name of mandatory fields
	var fieldRequired = Array("Feedback");
	// field description to appear in the dialog box
	var fieldDescription = Array("Comments");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	var blnValidEmail = false;
	

///////////////////////////////////////////////////////////////////////////////	
	// have the required fields been filled out at all?
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = f.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

///////////////////////////////////////////////////////////////////////////////
	// was the email submitted a valid email address? 
	blnValidEmail = isValidEmail(f.Contact_Email.value)
	if (!blnValidEmail && f.Contact_Email.value != "") {
		alertMsg += "\nPlease enter a valid Email address.\n";
	}
///////////////////////////////////////////////////////////////////////////////	
	// determine whether to submit form or display error message
	if (alertMsg.length == l_Msg){
		document.PulseForm.action = "pulse_submit.asp";
		document.PulseForm.submit();
		return true;
	}
	else{
		alert(alertMsg);
		return false;
	}
///////////////////////////////////////////////////////////////////////////////
	//utility functions
	function isValidEmail(strEmailTxt){
		validEmail = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/;
		if(!validEmail.test(strEmailTxt)){
			return false;
		} else {
			return true;
		}
	}	
}



 