jQuery(function() {

	

	//if submit button is clicked

	$('#submit_dieplates').click(function () {		

		

		//Get the data from all the fields

		var name_dieplates = $('input[name=name_dieplates]');

		var email_dieplates = $('input[name=email_dieplates]');

		var phone_dieplates = $('input[name=phone_dieplates]');

		var model_dieplates = $('input[name=model_dieplates]');

		var make_dieplates = $('input[name=make_dieplates]');

		var coname_dieplates = $('input[name=coname_dieplates]');
		
		var top1_dieplates = $('input[name=top1_dieplates]');
		
		var top2_dieplates = $('input[name=top2_dieplates]');
		
		var top3_dieplates = $('input[name=top3_dieplates]');
		
		var top4_dieplates = $('input[name=top4_dieplates]');

		var bottom1_dieplates = $('input[name=bottom1_dieplates]');
		
		var bottom2_dieplates = $('input[name=bottom2_dieplates]');
		
		var bottom3_dieplates = $('input[name=bottom3_dieplates]');
		
		var bottom4_dieplates = $('input[name=bottom4_dieplates]');
		
		var comment_dieplates = $('textarea[name=comment_dieplates]');



		//Simple validation to make sure user entered something

		//If error found, add hightlight class to the text field

		if (name_dieplates.val()=='') {

			name_dieplates.addClass('hightlight');

			return false;

		} else name_dieplates.removeClass('hightlight');

		

		if (email_dieplates.val()=='') {

			email_dieplates.addClass('hightlight');

			return false;

		} else email_dieplates.removeClass('hightlight');

		

		if (phone_dieplates.val()=='') {

			phone_dieplates.addClass('hightlight');

			return false;
			
		} else phone_dieplates.removeClass('hightlight');

		
		if (make_dieplates.val()=='') {

			make_dieplates.addClass('hightlight');

			return false;

		} else make_dieplates.removeClass('hightlight');
		
		
		if (model_dieplates.val()=='') {

			model_dieplates.addClass('hightlight');

			return false;

		} else model_dieplates.removeClass('hightlight');

		//organize the data properly

		var data = 'name_dieplates=' + name_dieplates.val() + '&coname_dieplates=' + coname_dieplates.val() + '&top1_dieplates=' + top1_dieplates.val() + '&top2_dieplates=' + top2_dieplates.val() + '&top3_dieplates=' + top3_dieplates.val() + '&top4_dieplates=' + top4_dieplates.val() +	'&bottom1_dieplates=' + bottom1_dieplates.val() + '&bottom2_dieplates=' + bottom2_dieplates.val() + '&bottom3_dieplates=' + bottom3_dieplates.val() +	'&bottom4_dieplates=' + bottom4_dieplates.val() + '&email_dieplates=' + email_dieplates.val() + '&phone_dieplates=' + phone_dieplates.val() + '&model_dieplates=' + model_dieplates.val() + '&make_dieplates=' + make_dieplates.val() +'&comment_dieplates='  + encodeURIComponent(comment_dieplates.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_dieplates.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

					$('#dieplates').fadeOut('slow');		

						

									

					//show the success message

					$('.done_dieplates').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;

	});	

});	