$(document).ready(function(){

//global vars
	var form = $("#myform");
	var name = $("#name");
	var nameInfo = $("#nameInfo");
	var email = $("#cemail");
	var emailInfo = $("#emailInfo");
	var subject = $("#Search");
	var subjectInfo = $("#subjectInfo");
	var hostingPackage = $("#hostingPackage");
	var hostingInfo = $("#hostingInfo");
	var message = $("#message");
	var messageInfo = $("#messageInfo");
	var orderNow = $(".orderNow");
		
// Show Form On Click Button
	orderNow.click(function() {
	$('.features').hide('slow'); 
	$('.orderButton').hide('slow'); 
	$('#contactus_form').show('slow');
	return false; });	
	
	//On blur
	name.blur(validateName);
	email.blur(validateEmail);
	message.focus(validateMessage);
	hostingPackage.blur(validateHosting);
	
	
	

//validation functions
function validateHosting(){
		//if it's NOT valid
		if(hostingPackage.val()== 1){
			hostingInfo.html("<span class='errorSuccess'>Rs.2500/- Yearly with 1 Free Domain</span>");
			return true;
		}
		if(hostingPackage.val()== 2){
			hostingInfo.html("<span class='errorSuccess'>Rs.5000/- Yearly with 1 Free Domain</span>");
			return true;
		}
		
	}
function validateName(){
		//if it's NOT valid
		if(name.val().length < 4){
			nameInfo.text("This field is required");
			return false;
		}
		//if it's valid
		else{
			nameInfo.text("");
			return true;
		}
	}
function validateSubject(){
		//if it's NOT valid
		if(subject.val().length < 3){
			subjectInfo.text("Please enter a domain name");
			return false;
		}
		//if it's valid
		else{
			subjectInfo.text("");
			return true;
		}
	}	
function validateEmail(){
		//testing regular expression
		var a = email.val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			emailInfo.text("");
			return true;
		}
		//if it's NOT valid
		else{
			emailInfo.text("Please enter valid email.");
			return false;
		}
	}
function validateMessage(){
		//it's NOT valid
		
			messageInfo.html("<span class='errorSuccess'>If you have any specific instructions please mention here</span>");
			return true;
		
	}	
	

form.submit(function(){

		if(validateName() & validateEmail() & validateSubject())
		{
var str = form.serialize();

   $.ajax({
   type: "POST",
   url: "http://www.ngtech.pk/wp-content/themes/ngtech/functions/hosting_process.php",
   data: str,
   success: function(msg){
    
$("#note").ajaxComplete(function(event, request, settings){

result = msg;

$(this).html(result);

});
}

 });			
		}
		else
		{
		return false;
		}


return false;

});

});
