// JavaScript Document

	$(function(){ // Register a ready event...onload of document
					   
		$("div#loading").hide();
		$("tr#sentFeedback").hide();

		$("#button").click(function (){
		
			if($("#name").val() == "") {
				//$("#name").addClass('ui-state-error');
				$("#validateTips").text("The Name field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#name").focus();
				return false;
			
			} else if($("#email").val() == "") {
			
				$("#validateTips").text("The Email address field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#email").focus();
				return false;
				
			} else if($("#email").val().indexOf("@") &&  $("#email").val().indexOf(".") == -1) {
				$("#validateTips").text("Invalid Email Address!");
				$("#validateTips").effect('highlight',{},500);
				$("#email").focus();
				return false;
				
			} else if($("#telephone").val() == "") {
			
				$("#validateTips").text("The Telephone field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#telephone").focus();
				return false;
				
			} else if($("#subject").val() == "Select a subject") {
			
				$("#validateTips").text("The Subject field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#subject").focus();
				return false;

			} else if($("#comment").val() == "") {
			
				$("#validateTips").text("The Comment field is empty!").effect("highlight",{},500);
				$("#validateTips").effect('highlight',{},500);
				$("#comment").focus();
				return false;
			
			} else {
			
				$("#validateTips").text("");
				$(":input", ":select", ":textarea").attr("disabled", "disabled");
				$("div#loading").slideDown(2000);
				
				// The AJAX part
				
				$.ajax({ 
				
				   type: "POST", 
				   url: "send-the-feedback.php", // The Script it should post to...
				   data: {name: $("#name").val(), email: $("#email").val(), telephone: $("#telephone").val(), subject: $("#subject").val(), state: $("#state").val(), comment: $("#comment").val()},
				   success: function(){ 
					 
					  
					  //$(":input", ":select", ":textarea").attr("disabled", "disabled");
					  $("#tableForm").slideUp(3000, function(){
					  $("div#loading").fadeOut(800);
					  $("tr#sentFeedback").fadeIn(1000);
						 
					 });
					 
				   }
				   
				 });
				 
					 
			
			}
		
		});	
		


	});
