$(document).ready(function() {

	//if submit button is clicked
	$('#submit').click(function () {

		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var phone = $('input[name=phone]');
	
		var limoservice = $('select[name=limoservice]');
		
		var limovehicle = $('select[name=limovehicle]');
		
		var city = $('select[name=city]');
		
		var date = $('input[name=date]');
		
		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field


		var ck_name = /^[A-Za-z ]{3,25}$/;
		var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		var ck_phone= /\d{3}\-\d{3}\-\d{4}/;
		var ck_date= /^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/;
		
		if (!ck_name.test(name.val())) {
			name.addClass('hightlight');
			document.getElementById('entername').style.display = 'block';
			document.form.name.focus();

			return false;
		} else {

		name.removeClass('hightlight');

		document.getElementById('entername').style.display = 'none';
		}


		if (!ck_email.test(email.val())) {
		email.addClass('hightlight');
		document.getElementById('enteremail').style.display = 'block';
		document.form.email.focus();
		return false;
		} else {
		email.removeClass('hightlight');
		document.getElementById('enteremail').style.display = 'none';
		}


		if (!ck_phone.test(phone.val())) {
		phone.addClass('hightlight');
		document.getElementById('enterphone').style.display = 'block';
		document.form.phone.focus();
		return false;
		} else {

		phone.removeClass('hightlight');
		document.getElementById('enterphone').style.display = 'none';
		}

		

		if (limoservice.val()=='') {
				limoservice.addClass('hightlight');
				document.getElementById('enterservice').style.display = 'block';
				document.form.limoservice.focus();
				return false;
				} else {
				limoservice.removeClass('hightlight');
				document.getElementById('enterservice').style.display = 'none';
		}

	if (limovehicle.val()=='') {
				limovehicle.addClass('hightlight');
				document.getElementById('entervehicle').style.display = 'block';
				document.form.limovehicle.focus();
				return false;
				} else {
				limovehicle.removeClass('hightlight');
				document.getElementById('enterservice').style.display = 'none';
		}
		
	if (city.val()=='') {
				city.addClass('hightlight');
				document.getElementById('entercity').style.display = 'block';
				document.form.city.focus();
				return false;
				} else {
				city.removeClass('hightlight');
				document.getElementById('enterservice').style.display = 'none';
		}
		
		if (!ck_date.test(date.val())) {
		date.addClass('hightlight');
		document.getElementById('enterdate').style.display = 'block';
		document.form.date.focus();
		return false;
		} else {

		date.removeClass('hightlight');
		document.getElementById('enterphone').style.display = 'none';
		}
		

		

		//organize the data properly
		var data = 'name=' + encodeURIComponent(name.val()) + '&email=' + encodeURIComponent(email.val()) + '&phone=' + encodeURIComponent(phone.val()) + '&limoservice=' + encodeURIComponent(limoservice.val()) + '&limovehicle=' + limovehicle.val() + '&city=' + encodeURIComponent(city.val()) + '&date=' + date.val();

		//disabled all the text fields
		$('.text').attr('disabled','true');

		//show the loading sign
		$('.loading').show();

		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "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) {
					//hide the form
					$('.form').fadeOut(1600, "linear");

					//show the success message
					$('.done').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;
	});
});
