

$(document).ready(function(){

	var FormObj=$("#cform");


	// Place ID's of all required fields here.
	var required = ["cformfullname", "cformemail", "cformmessage"];
	var labels = ["namelabel", "emaillabel", "messagelabel"];


	// If using an ID other than #email or #error then replace it here
	var email 		= FormObj.find("#cformemail");
	var emaillabel 	= FormObj.find("#emaillabel");
	var errornotice = FormObj.find("#cformerror");
	// The text to show up within a field when it is incorrect
	var emptyerror = "";
	var emailerror = "";

	//FormObj.submit
        $('#formsubmit').click(function(event){
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = FormObj.find('#'+required[i]);
			var label = FormObj.find('#'+labels[i]);
			if ((input.val() == "") || (input.val() == emptyerror)) {
				input.addClass("needsfilled");
				label.addClass("labelalert");
				input.val(emptyerror);
				errornotice.fadeIn(750);
			} else {
				input.removeClass("needsfilled");
				label.removeClass("labelalert");
			}
		}

                // 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");
			emaillabel.addClass("labelalert");
			email.val(emailerror);
		}
			
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if (FormObj.find(":input").hasClass("needsfilled")) {
			event.preventDefault();
                        return false;
		} else {
			errornotice.hide();
			return true;
		}
	});

	// Clears any fields in the form when the user clicks on them
	FormObj.find(":input").focus(function(){
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});


	//Change form name
	//Change input names to match the ones they want me to submit as in html
	//change the input names in the js
	//watch the beuatiful submit take place.

	var FormReg=$("#formreg");


	// Place ID's of all required fields here.
	var required2 = ["user_fullname","user_login","user_company", "user_email", "user_email2", "user_location", "user_phone", "password", "password2"];
	var labels2 = ["namelabel", "usernamelabel","user_companylabel", "emaillabel", "emaillabel2", "userlocationlabel", "user_phonelabel", "passwordlabel", "passwordlabel2"];


	// If using an ID other than #email or #error then replace it here
	var email2 	= FormReg.find("#user_email");
	var emaillabel2 	= FormReg.find("#emaillabel");
	var errornotice2 = FormReg.find("#cformerror");
	// The text to show up within a field when it is incorrect
	var emptyerror2 = "";
	var emailerror2 = "";

	$("#formsubmita").click(function(event){
		//Validate required fields
		for (i=0;i<required2.length;i++) {
			var input = FormReg.find('#'+required2[i]);
			var label = FormReg.find('#'+labels2[i]);
			if ((input.val() == "") || (input.val() == emptyerror2)) {
				input.addClass("needsfilled");
				label.addClass("labelalert");
				input.val(emptyerror);
				errornotice2.fadeIn(750);
			} else {
				input.removeClass("needsfilled");
				label.removeClass("labelalert");
			}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email2.val())) {
			email2.addClass("needsfilled");
			emaillabel2.addClass("labelalert");
			email2.val(emailerror2);
		}

		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if (FormReg.find(":input").hasClass("needsfilled")) {
                        event.preventDefault();
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});

	// Clears any fields in the form when the user clicks on them
	FormReg.find(":input").focus(function(){
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});
});	
