/*
Created 09/27/09										
Questions/Comments: jorenrapini@gmail.com						
COPYRIGHT NOTICE		
Copyright 2009 Joren Rapini

First Name, Last Name, E-mail, Company,   notes
*/

	

jQuery(document).ready(function(){
	// Place ID's of all required fields here.
	required = ["FirstName", "LastName", "kiklty-kiklty",  "BusinessTel",  "Company"];
	

	// If using an ID other than #email or #error then replace it here
	email = jQuery("#kiklty-kiklty");
	errornotice = jQuery("#error");
	// The text to show up within a field when it is incorrect
	emptyerror = "Required field.";
	emailerror = "Require a valid email.";

	jQuery("#subForm").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("needsfilled");
				input.val(emptyerror);
				errornotice.fadeIn(750);
			} 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 (jQuery(":input").hasClass("needsfilled")) {
			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("needsfilled") ) {
			jQuery(this).val("");
			jQuery(this).removeClass("needsfilled");
	   }
	});
});	// JavaScript Document
