jQuery(function() {

	

	//if submit button is clicked

	$('#submit_keys').click(function () {		

		

		//Get the data from all the fields

		var name_keys = $('input[name=name_keys]');

		var email_keys = $('input[name=email_keys]');

		var phone_keys = $('input[name=phone_keys]');

		var model_keys = $('input[name=model_keys]');

		var make_keys = $('input[name=make_keys]');

		var coname_keys = $('input[name=coname_keys]');

		var comment_keys = $('textarea[name=comment_keys]');



		//Simple validation to make sure user entered something

		//If error found, add hightlight class to the text field

		if (name_keys.val()=='') {

			name_keys.addClass('hightlight');

			return false;

		} else name_keys.removeClass('hightlight');

		

		if (email_keys.val()=='') {

			email_keys.addClass('hightlight');

			return false;

		} else email_keys.removeClass('hightlight');

		

		if (phone_keys.val()=='') {

			phone_keys.addClass('hightlight');

			return false;

		} else phone_keys.removeClass('hightlight');

		

		//organize the data properly

		var data = '&name_keys=' + name_keys.val() + '&coname_keys=' + coname_keys.val() + '&email_keys=' + email_keys.val() + '&phone_keys=' + phone_keys.val() + '&model_keys=' + model_keys.val() + '&make_keys=' + make_keys.val() +'&comment_keys='  + encodeURIComponent(comment_keys.val()) ;

		



		

		//show the loading sign

		$('.loading').show();

		

		//start the ajax

		$.ajax({

			//this is the php file that processes the data and send mail

			url: "../js/process_watchclockkeys.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) {					

					//hide the form

					$('#keys').fadeOut('slow');		

						

									

					//show the success message

					$('.done_keys').fadeIn('slow');

					

				//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;

	});	

});	
