/*
Created 09/27/09										
Questions/Comments: jorenrapini@gmail.com						
COPYRIGHT NOTICE		
Copyright 2009 Joren Rapini
*/

	
// Place ID's of all required fields here.
required = ["name", "password_one", "password_two", "email_address", "device", "cert"];
// If using an ID other than #email then replace it here
email = $("#email_address");

// The text to show up within a field when it is incorrect
error = ""
emailerror = "Please enter a valid e-mail"

$(document).ready(function(){
	$("#register_member_form").submit(function(){	
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == error)) {
				input.addClass("needsfilled");
				input.val(error);
			} else {input.removeClass("needsfilled");}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("needsfilled");
			email.val(emailerror);
		}

		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if ($(":input").hasClass("needsfilled")) {
			return false;
		} else {return true;}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").click(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
	   }
	});
	
});	