$(document).ready(function() {
	$( "input#Date" ).datepicker({
            dateFormat: 'dd MM yy',                                     
            defaultDate: "+0d",
            changeMonth: false,
            numberOfMonths: 1,
            minDate: 0});
			

$(".booknow").click(function(){
	var haserror = false;
	
	$("#quoteform input").css("border","solid 1px red")
	$("#quoteform input").css("background","#FAEDD1");
	$("#quoteform input").each(function(){
		if($(this).val() =="")
		{
			$(this).css("border","solid 1px red")
			$(this).css("background","#FAEDD1");
			haserror = true;
		} else
		{
			$(this).css("border","solid 1px #ccc")
			$(this).css("background","#Fff");
		}
		
		});


$("#quoteform select").each(function(){
		if($(this).val() =="0")
		{
			$(this).css("border","solid 1px red")
			$(this).css("background","#FAEDD1");
						haserror = true;
		}
		else
		{
			$(this).css("border","solid 1px #ccc")
			$(this).css("background","#Fff");
		}
		});
		
		if (haserror == false){
			var query ="";
			$("#quoteform input").each(function(){
				query += this.id+"=" + $(this).val() +"&"		
		     });
			query += "House Type=" + $("#quoteform select option:selected").text() ;	
			

    jQuery.ajax({
        type: 'POST',
        cache: false,
        url: '/wp-ajax/contactform.aspx',
        data: query,
        success: function (data) {
          //  if (data == "good")
//			{
//				alert("Thank you for requesting quote,\n We'll get back to you as soon as we can.");
//			}
//			else
//			{
				
				$.fancybox({
		 'width' : 490,
		 'height' : 429,
		 'autoScale' : false,
		 'scrolling' : 'no',
		 'transitionIn' : 'none',
		 'transitionOut' : 'none',
		 'type' : 'iframe',
		 'href' : 'http://www.bookfresh.com/index.html?id=62d68e749e106f631bab8df7f2bea203&view=buyer_flow'
	 });
			//}
        },
        error: function (xhr, ajaxOptions, thrownError) {
            //alert(xhr.status + " - " + xhr.statusText + "\n" + xhr.responseText);
        }
    });
    return false;		

		}
});
});


