$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var a1 = $('input[name=a1]');
		var a2 = $('input[name=a2]');
		var a3 = $('input[name=a3]');
		var a4 = $('input[name=a4]');
		var ad = $('textarea[name=ad]');
		
		

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		
	
		
		if (a1.val()=='') {
			a1.addClass('hightlight');
		alert('Please Enter your First Name');
			return false;
		} else a1.removeClass('hightlight');
		
		if (a2.val()=='') {
			a2.addClass('hightlight');
		alert('Please Enter your Last Name');
			return false;
		} else a2.removeClass('hightlight');
		
		if (a3.val()=='') {
			a3.addClass('hightlight');
		alert('Please Enter your Email Address');
			return false;
		} else a3.removeClass('hightlight');
		
	 
		
		//organize the data properly
		var data = 
		'a1=' + a1.val() 
		+ '&a2=' + a2.val() 
		+ '&a3=' + a3.val()
		+ '&a4=' + a4.val() 
		+ '&ad=' + encodeURIComponent(ad.val())
		

		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "/contact-process/contact-process.php",	
			
			//GET method is used
			type: "GET",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				
				//if process.php returned 1/true (send mail success)
				if (html==1) {	
				
					//disabled all the text fields
					$('.text').attr('disabled','true');
					
					//show the loading sign
					$('.loading-form').fadeIn(1000);
					
					$('.processing-form-header').fadeIn(1000);
					
					$('.done-padding').fadeIn(1000);
					
				
					setTimeout (function(){
					$('.loading-form').hide(); },2800);

					//hide the form and the contact form header and the required text statement 
					$('.myform').hide();

					//hide the submit button since it is in a tag and not inside the form
					$('#start-now-submit-btn').hide();	
					
					
					setTimeout (function(){
					//show the success message and the thank-you message
					$('.done').fadeIn(1000); },2800);
					
					setTimeout (function(){
					//show the success message and the thank-you message
					$('.thank-you-header').fadeIn(1000); },2800);
					
					setTimeout (function(){
					//show the success message and the thank-you message
					$('.processing-form-header').hide(); },2800);
					

				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');				
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	