// JavaScript Document

	function compareFields() { 
		var userEmail=document.getElementById("userEmail");
		var confirmEmail=document.getElementById("confirmEmail");
		var formLength=document.getElementById("projectform").length;
		var alertEmptyField="Field required.";
		var alertEmailMismatch="Addreses do not match.";
		//Check for required fields
		for(var i=0; i<formLength-1; i++) {
			var formElement=document.getElementById("projectform").elements[i];
			
			var thisField=formElement.value;
			var alertBoxName=formElement.name+"Alert";
			
			
			if(thisField.length==0) {
				document.getElementById(alertBoxName).innerHTML="<strong>" + alertEmptyField + "</strong>";
				formElement.style.backgroundColor= "#fafba1";
				formElement.focus();
				return false;
			} 
			else{
				formElement.style.backgroundColor= "white";
				document.getElementById(alertBoxName).innerHTML="&nbsp;";
				}
			
			} 
	
		//confirm email and highlight both fields
		if(userEmail.value != confirmEmail.value) {
			document.getElementById("userEmailAlert").innerHTML="<strong>" + alertEmailMismatch +"</strong>"
			userEmail.style.backgroundColor="#fafba1";
			confirmEmail.style.backgroundColor="#fafba1";
			//alert("Email addresses do not match.");
		//	//this clears the fields
			userEmail.value="";
		confirmEmail.value="";
			userEmail.focus();//this puts the cursor back into the userEmail field
			return false;
		}
		return true;	// all test pass, form is ready to submit
	}

