// JavaScript Document
function validateFormEN() {
	var hasErrors = false;
	var errOutput = "The following errors occurred:\n";
	
	$('.validate').each(function (i) {
		// Look for the attribute "check" which tells us 
		// what to check for in the validation process								  
		var checking = $(this).attr("check");
		
		// Available options for checking:
		//		filled - not empty
		//		email - valid email format
		
		
		
		if(checking=="filled") {
			
			if ($(this).val() == "") {
				hasErrors = true;
				//var fieldName = $(this).attr("name").replace("_"," ");
				var fieldTitle = $(this).attr("title");
				errOutput += "\n- '"+ fieldTitle +"' is a required field";
				$(this).css('background-color','#ffeeee');
			}
			
		} 
		
		if(checking=="email") {			
			var filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;			
			if ($(this).val() == "" || !filter.test($(this).val())) {
				hasErrors = true;
				errOutput += "\n- Your email address is invalid. Please provide a valid email address.";
				$(this).css('background-color','#ffeeee');
			}				
		}
		
		if(checking=="telnum") {
			
			var filter = /^[0-9-()]+$/;			
			if ($(this).val() == "" || !filter.test($(this).val())) {				
				hasErrors = true;
				errOutput += "\n- Your phone number is invalid. Please use only numbers or the dash.";
				$(this).css('background-color','#ffeeee');
			}		
			
		} 
		
		if(checking=="password") {
			var passwordToCompare = $('#passwordcheck');
			if($(this).val() != passwordToCompare.val()) {
				hasErrors = true;
				errOutput += "\n- Your passwords do not match.";
				// make the fields red:
				$(this).css('background-color','#ffeeee');
				passwordToCompare.css('background-color','#ffeeee');
			} else if($(this).val().length == 0) {
				hasErrors = true;
				errOutput += "\n- You need to supply a password.";
				// make the fields red:
				$(this).css('background-color','#ffeeee');
				passwordToCompare.css('background-color','#ffeeee');
			}
			
		}
		
								 
	});
	
	
	if (hasErrors) {
		alert(errOutput + "\n\nPlease fix these errors and try re-submitting your request.");
	} else {
		//alert("Submit Successful");
		
		document.form.jsSubmitForm.submit();
	}
}

var debugcounter = 0;

$(document).ready(function() {
	 $('input.large').focus(function() {
		//$('#debugoutput').html($(this).attr('name') + ' ' +debugcounter);								
		$(this).css('background-color','#ffffff');
  	    //debugcounter++;
	});
});



