$(document).ready(
	function() {
		$("#lazer_indirim").submit(function(){return false;});
		$("#contactButton").click(function(){checkForm();});
	}
);

function checkForm()
{
	var stp = false;
	var requiredFields = ["ad","soyad","telefon1","telefon2","fax1","fax2","sehir","ulke","address","eposta"];

    $.each(requiredFields, function() {
		if ($("#" + this).val() == '') {$("#" + this).addClass("errorInput"); stp = true; }
		else {$("#" + this).removeClass("errorInput"); }
    });

	var eposta = $("#eposta").val();
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;

	if (!eposta.match(re)) { $("#eposta").addClass("errorInput"); stp = true; }
	else{ $("#eposta").removeClass("errorInput"); }


	if (stp == true) {
		alert("Please check your information!");
	} else {

		$("#contactButton").css({display:"none"});
		$.ajax({
			type: "POST",
			url: "/forms/booking.php",
			dataType: "html",
			data: $("#lazer_indirim").serialize(),
			success: function(response){
				alert(response);
				document.forms["lazer_indirim"].reset();
			},
			error: function(){
				alert("Error occured . Please try again later.");
			},
			complete: function(){
				$("#contactButton").css({display:"block"});
			}
		});
		return false;
	}
	return false;
}