// JavaScript Document

	$(function(){ // Register a ready event...onload of document
					   
		$("div#loading").hide();
		$("tr#sentFeedback").hide();

		$("#button").click(function (){
		
			if($("#fullName").val() == "") {
				//$("#name").addClass('ui-state-error');
				$("#validateTips").text("The Full Name field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#fullName").focus();
				//return false;
			
			} else if($("#emailAddress").val() == "") {
			
				$("#validateTips").text("The Email address field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#emailAddress").focus();
				//return false;
				
			} else if($("#emailAddress").val().indexOf("@") &&  $("#emailAddress").val().indexOf(".") == -1) {
				$("#validateTips").text("Invalid Email Address!");
				$("#validateTips").effect('highlight',{},500);
				$("#emailAddress").focus();
				//return false;
				
			} else if($("#telephone").val() == "") {
			
				$("#validateTips").text("The Telephone field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#telephone").focus();
				//return false;
				
			} else if($("#contactAddress").val() == "") {
			
				$("#validateTips").text("The Contact Address field is empty!");
				$("#validateTips").effect('highlight',{},500);
				$("#contactAddress").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 if($("#state").val() == "") {
			
				$("#validateTips").text("The State field is empty!").effect("highlight",{},500);
				$("#validateTips").effect('highlight',{},500);
				$("#state").focus();
				//return false;

			} else if($("#domainName").val() == "") {
			
				$("#validateTips").text("The Domain Name field is empty!").effect("highlight",{},500);
				$("#validateTips").effect('highlight',{},500);
				$("#domainName").focus();
				//return false;
				
			} else if($("#tld").val() == "Select Extension") {
			
				$("#validateTips").text("The Top Level field is empty!").effect("highlight",{},500);
				$("#validateTips").effect('highlight',{},500);
				$("#tld").focus();
				//return false;
				
			
			} else {
			
				if(confirm("Hi " + $("#fullName").val() + "! Did you check if the domain name www." + $("#domainName").val() + '' + $("#tld").val() + " is available?\n\nClicking on OK means you are certain that the domain name is available for us to proceed with your FREE Hosting order. If not, we suggest you confirm its availability before you proceed.")){
			
				$("#validateTips").text("");
				//$("$form > *").attr("disabled", "disabled");
				$("div#loading").slideDown(2000);
				
				// The AJAX part
				
				$.ajax({ 
				
				   type: "POST", 
				   url: "free-hosting-order-script.php", 
				   data: {fullName: $("#fullName").val(), emailAddress: $("#emailAddress").val(), telephone: $("#telephone").val(), contactAddress: $("#contactAddress").val(), state: $("#state").val(), domainName: $("#domainName").val(), tld: $("#tld").val()},
				   success: function(){ 
					 
					  $("div#loading").hide();
					 // $("#form2 > *").attr("disabled","disabled");
					  $("#tableForm").slideUp(3000, function(){
					  $("tr#sentFeedback").fadeIn(1000);
						 
					 });
					  //alert('message sent');
					 
				   }/*,
				   error: function() {
				   alert('Page not found...');
				   }*/
				 });
				 
					 
				} else {
					
					return false;
				
				}
				//$("form").submit();
				//return true;
			
			}
		
		});	
		

		//if(document.location.href.indexOf("#news1")!=-1) {
		
			
		
		//}		

	});
