/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

jQuery(document).ready(function(){



    jQuery("a.atcZoom").fancybox({
        'width'				: '50%',
        'height'			: '80%',
        'autoScale'     	: false,
        'transitionIn'		: 'elastic',
        'transitionOut'		: 'elastic',
        'type'				: 'iframe'

    });


    
    jQuery("form#bookingForm").submit(function() {


        var $this = jQuery(this);
        var datas = $this.serialize();


        jQuery('label',$this).removeClass('error');

        jQuery.ajax({
            type: "POST",
            url: ASAP.LIVESITE.URL+"/json.php",
            data:datas,
            success: function(response){
                response =  JSON.parse(response);
                var errordiv = jQuery("div.error");
                if(response.success){
                    errordiv.hide();
                    jQuery.scrollTo("#book-form", 500);
                    jQuery('#bookingForm').fadeOut(500, function(){
                        jQuery('p.intro').hide();
                        jQuery('#successDiv').fadeIn(500);
                    });
                    

                }else{

                    var rr = response.required;
                    if(rr){
                        for(var i=0; i< rr.length ; i++){
                            var token = rr[i];
                            jQuery("label[for="+ token +"]").addClass('error');
                        }
                    }
            
                    var errordiv = jQuery("div.error");
                    if(response.message!=""){
                        jQuery.scrollTo("#book-form", 500);
                        errordiv.html(response.message).fadeIn(1000);
                    }

                }

            }
        });
        return false;
    });


});




