jQuery(function() {

	

	//if submit button is clicked

	$('#submit_timecards').click(function () {		

		

		//Get the data from all the fields

		var name_timecards = $('input[name=name_timecards]');

		var email_timecards = $('input[name=email_timecards]');

		var phone_timecards = $('input[name=phone_timecards]');

		var model_timecards = $('input[name=model_timecards]');

		var make_timecards = $('input[name=make_timecards]');

		var coname_timecards = $('input[name=coname_timecards]');

		var comment_timecards = $('textarea[name=comment_timecards]');



		//Simple validation to make sure user entered something

		//If error found, add hightlight class to the text field

		if (name_timecards.val()=='') {

			name_timecards.addClass('hightlight');

			return false;

		} else name_timecards.removeClass('hightlight');

		

		if (email_timecards.val()=='') {

			email_timecards.addClass('hightlight');

			return false;

		} else email_timecards.removeClass('hightlight');

		

		if (phone_timecards.val()=='') {

			phone_timecards.addClass('hightlight');

			return false;

		} else phone_timecards.removeClass('hightlight');

		

		//organize the data properly

		var data = '&name_timecards=' + name_timecards.val() + '&coname_timecards=' + coname_timecards.val() + '&email_timecards=' + email_timecards.val() + '&phone_timecards=' + phone_timecards.val() + '&model_timecards=' + model_timecards.val() + '&make_timecards=' + make_timecards.val() +'&comment_timecards='  + encodeURIComponent(comment_timecards.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_timecards.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

					$('#timecards').fadeOut('slow');		

						

									

					//show the success message

					$('.done_timecards').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;

	});	

});	