$(document).ready(function () {
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	
	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
      
	$('#rotate').cycle({ 
		fx:    'fade',
		speed: 3000, 
		timeout: 5000, 
		delay: -2000 
	});

   $('#nav>li:has(ul)>a').click(function () {
      $('#nav').find('ul').hide().end().find('.selected').removeClass('selected');
      $(this).closest('#nav > li').addClass('selected');
      $(this).siblings('ul').show();
      return false;
   });
   
   $('#nav a').each(function () {
      if(this.href == window.location.href) {
         var $navitem = $(this).closest('#nav > li');
         $navitem.addClass('selected');
         if($navitem.has('ul'))
            $navitem.find('>a').click();
      }
   });
   
   if($('#nav .selected').length == 0)
      $('#nav .default').click();

   var saturdayFilter = function (date) {
      return (date.getDay() != 6) ? [false, ''] : [true, ''];
   }
   
   var mydate = new Date();
   mydate.setFullYear(2012, 0, 1)
   
   $('.be-date').datepicker({
      showOn: 'button',
      buttonImage: '/images/icons/calendar.png',
      buttonImageOnly: true,
      beforeShowDay: saturdayFilter,
      maxDate: '+1Y',
      minDate: mydate
   });
    
    //maxDate: new Date( (new Date).getFullYear(), 11, 31 )
    //minDate: "+2d"
    
       
    //book now
    $('input[name=travelInsurance]').click(function(){
   	
   	  var insuranceVal = $(this).val();
   	  
   	  if(insuranceVal == 'No'){
   	    $('#declineInsuranceMessage').html('By declining travel insurance you are agreeing to all terms and conditions. We strongly recommend this insurance coverage from situations where you may not recover your financial investment.  This charge will be taken off on the second payment and will not be reflected on your initial receipt.');
   	  }else{
   	    $('#declineInsuranceMessage').hide();
   	  }
   	
   });
   
   //book now
   $('input[name=linens]').click(function(){
   	
   	  var linensVal = $(this).val();
   	  
   	  if(linensVal == 'No'){
   	    $('#declineLinensMessage').html('This charge will be taken off on the second payment and will not be reflected on your initial receipt.');
   	  }else{
   	    $('#declineLinensMessage').hide();
   	  }
   	
   });
   
   
   //Book Now CC Billing Info same as above
   $('#ccsame').click(function () {
      var $this = $(this);
      if($this.is(':checked')) {
         $('#strCCName').val($('#strFName').val() + ' ' + $('#strLName').val());
         $('#strCCAddress1').val($('#strAddress1').val());
         $('#strCCAddress2').val($('#strAddress2').val());
         $('#strCCCity').val($('#strCity').val());
         $('#strCCState').val($('#strState').val());
         $('#strCCZip').val($('#strZip').val());
         $('#strCCEmail').val($('#strEmail').val());        
      } 
   });
   
   //Used on /booking/book-now to validate the booking form info
	$('#booknowform').validate();
	
	
  $('#booknowform').submit(function(){
	   
	   var contactState = $('select[name=strState]').val();
	   var contactProvince = $('input[name=dbResProvince]').val();
	   
	   var ccState = $('select[name=strCCState]').val();
	   var ccProvince = $('input[name=strCCProvince]').val();
	   
	   if(contactState != '' && contactProvince != ''){
	     alert('Either province or state is required under Contact Information, not both. Please empty one of the fields and re-submit the form.');
	     return false;
	   }else if(contactState == 'Select one' && contactProvince == ''){
	     alert('Either province or state is required under Contact Information, but not both.');
	     return false;
	   }else if(ccState != '' && ccProvince != ''){
	     alert('Either province or state is required under Credit Card Billing Information, not both. Please empty one of the fields and re-submit the form.');
	     return false;
	   }else if(ccState == 'Select one' && ccProvince == ''){
	     alert('Either province or state is required under Credit Card Billing Information, but not both.');
	     return false;
	   }else{
	     return true;
	   }	
	      
	 	   
	});

   
});

