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