var fancybox_bg = '#fff';
if ($.browser.msie ){
   var fancybox_bg = '#000';
}

$(document).ready(function() {
   $("a.reservation_pop").fancybox({
   	"autoScale" : false,
   	"showCloseButton" : false, 
      "width"	:	620,
   	"height" : 600,
   	"padding" : 0,
   	"type" : "iframe",
   	'scrolling'   : 'no',
   	"overlayColor" : fancybox_bg,
   	"overlayOpacity" : 0.8,
   	'scrolling'   : 'no'
   });
})

function showChangeReservationBox(box, content, box_contents){
   
   $(box+" .reservation-top").removeClass("top-yellow").addClass("top");
   $(box+" .reservation-middle").removeClass("middle-yellow").addClass("middle");
   $(box+" .reservation-bottom").removeClass("bottom-yellow").addClass("bottom");
   
   $(box_contents).hide();
   $(content).show(300);
}

function close(object){
   $(object).slideUp(200);   
}

var reservation_submitted = false;

function validate(step, form, box, box_contents, err_box){
   if ($(form).validateForm("error", "", error_msg, 1)){
      //$("#error_div").hide();

      if (!reservation_submitted){
         reservation_submitted = true;
         $.post(ajax_url,{action : "submit", data : $(form).serialize(), step : step},function(data){
             reservation_submitted = false;
         //alert("-"+data+"-");
            if (step == "step1"){
               if (box == "#reserve_box_bottom"){
                  content_to_show = "#reserve_box_bottom_step2";
                  form_to_update = document.frmBottomReservation2;
                  email_field = "#reservation_bottom_email";
               }else{
                  content_to_show = "#reserve_box_top_step2";
                  form_to_update = document.frmTopReservation2;
                  email_field = "#reservation_top_email";
               }
               
               showChangeReservationBox(box, content_to_show, box_contents);
               form_to_update.reservation_id.value = parseInt(data);
               $(email_field).html(form.email.value);
               form_to_update.email.value = form.email.value;
               
               _gaq.push(["_trackPageview", "/funnel_artist_reservation/step2.html"]);
            }else if (step == "step2"){
               if (box == "#reserve_box_bottom"){
                  content_to_show = "#reserve_box_bottom_step3";
                  form_to_update = document.frmBottomReservation3;
               }else{
                  content_to_show = "#reserve_box_top_step3";
                  form_to_update = document.frmTopReservation3;
               }
               
               showChangeReservationBox(box, content_to_show, box_contents);
               form_to_update.reservation_id.value = data;
               
               _gaq.push(["_trackPageview", "/funnel_artist_reservation/step3.html"]);   
            }else if (step == "step3"){
               //close(box);
               $("#reserve_box_top_step3").hide();
               $("#reserve_box_top_step4").show(300);
               
               _gaq.push(["_trackPageview", "/funnel_artist_reservation/step4.html"]);
            }
              
         },"text");
      }
   }
}

function checkReservationCellNumber(){
   var area_code = $('#cell_area').val();
   var cell1 = $('#cell1').val();
   var cell2 = $('#cell2').val();
   
   var cellNumber = area_code+cell1+cell2;
   
   if ((/^[0-9]{10}$/).test(cellNumber)){
      $('#textChkSms').removeClass('disabled');
      $('#chksms').attr('disabled','');
   }else{
      $('#textChkSms').addClass('disabled');
      $('#chksms').attr('checked','');
      $('#chksms').attr('disabled','disabled');
   }
}
