/******
v.1 - kinda quick and dirty, but it does the job for now

Checks for custom "required" attribute for required elements. If "required" exists, the field is required. Later, I'll add a password and email check.

Alert lists the required fields that were left blank and turns them red (plus their label, if there is one) and focuses on the first unfilled required field.

Submit check makes sure only first click of "submit" button registers, so user doesn't keep clicking submit.

******/



function verify(frm){
	var strMsg = "";
	focused = false;
	labels = document.getElementsByTagName('label');
	for(var i=0; i<frm.elements.length; i++){
		if(frm.elements(i).required){
			var requiredField = frm.elements(i).id;
			if(frm.elements(i).value == ""){
				strMsg += "- " + requiredField + " is a required field\n";
				// highlight fields and labels
				if (labels[i]) {
					labels[i].style.color = "#CC3333";
				}
				frm.elements(i).style.backgroundColor = "#CC3333";
				if (!focused) {
					frm.elements(i).focus();
					focused = 1;
				}
				//alert(i);
			} // if
		} // if required
	} // for
	
	if (strMsg) {
		alert("The form was not submitted for the following reasons:\n\n"+strMsg+"\nPlease revise the highlighted field(s) and try again.\n");
		return false;
	} else {
		if (!submitCheck()){
			return false;
		}
		return true;
	}

	/*
	if(frm.elements('password').value != frm.elements('password_val').value){
		strMsg = strMsg + "- " + "The 'password' and 'confirm password' fields must match.\n";		
		alert(strMsg);
		return false;
	}
	
	if(frm.elements('password').value.length < 6){
		strMsg = strMsg + "- " + "Passwords must be at least 6 characters.\n";
		alert(strMsg);
		return false;
		break;
	} else {
	
		if (!submitCheck()){
			return false;
			break;
		}
		return true;
	} // if
	*/
var submitted = false;	

function submitCheck(){
	if (submitted){
		alert("You have already submitted this form. Please wait ...");
		return false;
	} else {
		submitted = true;
		return true;
	}
} // function
} // function

