var BookingForm={form:$("#booking"),checkIn:$("#exp_checkin"),checkOut:$("#exp_checkout"),checkInDate:!1,checkOutDate:!1,init:function(){var a=this;this.setDate("checkIn"),this.checkIn.datepicker({numberOfMonths:2,minDate:new Date,onSelect:function(a,b){BookingForm.setDate("checkIn",a)}}),this.checkOut.datepicker({numberOfMonths:2,minDate:1,onSelect:function(a,b){BookingForm.setDate("checkOut",a)}}),this.form.live("submit",function(b){b.preventDefault(),$("#booking").fadeTo(150,.4);if(a.validate()){$("#sending").show(200);var c={};c.action="doBookingForm",c.fields={},c.fields.Name=$("#exp_name").val(),c.fields.Email=$("#exp_email").val(),c.fields.Phone=$("#exp_phone").val(),c.fields.Rooms=$("#exp_rooms").val(),c.fields["Check In"]=$("#exp_checkin").val(),c.fields["Check Out"]=$("#exp_checkout").val(),c.fields.Adults=$("#exp_adults").val(),c.fields.Children=$("#exp_children").val(),c.fields.Comments=$("#exp_comments").val(),$("#exp_name,#exp_email,#exp_phone,#exp_comments").val(""),$.ajax({type:"post",url:BookingFormAJAX.ajaxurl,data:c,success:function(a){$("#sending").hide(200,function(){$("#sent").slideDown(200,function(){$(this).delay(2500).slideUp(200,function(){$("#booking").fadeTo(150,1)})})})}})}})},validate:function(){var a=this,b=!0;this.form.find("input").css("borderColor","#f5dba4"),this.form.find("label.required").each(function(c){var d=$("#"+$(this).attr("for"));if(!$.trim(d.val()).length||d.attr("id")=="exp_email"&&!a.isValidEmail(d.val()))d.css("borderColor","#f00").animate({backgroundColor:"#f00"},75,function(){$(this).animate({backgroundColor:"#fff"},150)}),b=!1}),b||$("html, body").animate({scrollTop:a.form.offset().top},400);return b},isValidEmail:function(a){var b=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return b.test(a)},setDate:function(a,b){var c,d,e,f,g=new Date;b=b?b:this[a].val(),b?(g=new Date(Date.parse(b)),g=="Invalid Date"&&(g=new Date(parseInt(b)))):a=="checkOut"&&g.setDate(g.getDate()+1),c=g.getDate(),d=g.getMonth()-0+1,e=g.getFullYear(),this[a+"Date"]=g;var f=d+"/"+c+"/"+e;this[a].css("background","url(media/images/calendarImage.php?date="+c+"&month="+d+"&size="+this[a].width()+") 0 0 no-repeat").val(f);if(a=="checkIn"){var h=new Date(g.valueOf()+864e5);this.checkOutDate<=this.checkInDate&&this.setDate("checkOut",h.toString()),this.checkOut.datepicker("option","minDate",h)}else if(a=="checkOut"){var i=new Date(parseInt(g.valueOf())-864e5);this.checkInDate>=this.checkOutDate&&this.setDate("checkIn",i.toString()),this.checkIn.datepicker("option","maxDate",i)}}};$(document).ready(function(){BookingForm.init()})
