var showDateTime = '';
$(document).ready(
  function() {
    function bindHideImageEvents(){
      $('img[@id=sideBarTab].slideHide').unbind('click');
      $('img[@id=sideBarTab].slideHide').click(function () {
        $('#sideBar').fadeIn();
        $('#sideBarContents').animate({width:"300px"});
        $('img#sideBarTab').attr("src","images/slide-button-active.gif");
        $('#sideBarContents').slideDown("slow");
        $('#sideBarTab').removeClass('slideHide');
        $('#sideBarTab').addClass('slideShow');
        bindImageEvent();
      });
    }
    function bindImageEvent(){
      $('img[@id=sideBarTab].slideShow').unbind('click');
      $('img[@id=sideBarTab].slideShow').click(function () {
        $('sideBarTab').fadeOut();
        $('#sideBarContents').animate({width:"0px"});
        $('img#sideBarTab').attr("src","images/slide-button.gif");
        $('#sideBarContents').slideUp("slow");
        $('#sideBarTab').removeClass('slideShow');
        $('#sideBarTab').addClass('slideHide');
        bindHideImageEvents();
      });
    }
    bindHideImageEvents();

     function Schedule_bindHideImageEvents(){
      $('img[@id=Schedule_sideBarTab].Schedule_slideHide').unbind('click');
      $('img[@id=Schedule_sideBarTab].Schedule_slideHide').click(function () {
        $('#Schedule_sideBar').fadeIn();
        $('#Schedule_sideBarContents').animate({width:"430px"});
        $('img#Schedule_sideBarTab').attr("src","/sites/all/themes/centum/common/images/schedule_slidebutton_close.gif");
        $('#Schedule_sideBarContents').slideDown("slow");
        $('#Schedule_sideBarTab').removeClass('Schedule_slideHide');
        $('#Schedule_sideBarTab').addClass('Schedule_slideShow');
        Schedule_bindImageEvent();
      });
    }
    function Schedule_bindImageEvent(){
      $('img[@id=Schedule_sideBarTab].Schedule_slideShow').unbind('click');
      $('img[@id=Schedule_sideBarTab].Schedule_slideShow').click(function () {
        $('Schedule_sideBarTab').fadeOut();
        $('#Schedule_sideBarContents').animate({width:"0px"});
        $('img#Schedule_sideBarTab').attr("src","/sites/all/themes/centum/common/images/schedule_slidebutton_open.gif");
        $('#Schedule_sideBarContents').slideUp("slow");
        $('#Schedule_sideBarTab').removeClass('Schedule_slideShow');
        $('#Schedule_sideBarTab').addClass('Schedule_slideHide');
        Schedule_bindHideImageEvents();
      });
    }
    Schedule_bindHideImageEvents();

    $('#selectcinema').change(
      function() {
        $('#selectmovie').html('<option>loading....</option>');
        $('#selectdate').html('<option>Select Date:</option>');
        $('#selecttime').html('<option>Select Time:</option>');
        $('#selectprice').html('<option>Select Price:</option>');
        if(isWhitespace($(this).val())) {
          $('#selectmovie').html('<option>Select Movie:</option>');
          return false;
        }
        $.ajax({
          type: "POST",
          url: "web/ajax/get_films_by_cinema.php",
          data: "cinema_id="+$(this).val(),
          success: function(msg){
            $('#selectmovie').html(msg);
          }
        });
      }
    );
    $('#selectmovie').change(
      function() {
        get_date_of_movie($(this).val(), $('#selectcinema').val());
      }
    );
    $('#selectdate').change(
      function () {
        $('#selecttime').html('<option>loading....</option>');
        $('#selectprice').html('<option>Select Price:</option>');
        if(isWhitespace($('#selectmovie').val()) || isWhitespace($('#selectcinema').val()) || isWhitespace($(this).val())) {
          $('#selecttime').html('<option>Select Time:</option>');
          return false;
        }
        $.ajax({
          type: "POST",
          url: "web/ajax/get_time_of_movie.php",
          data: "film_id="+$('#selectmovie').val()+"&cinema_id="+$('#selectcinema').val()+"&date="+$(this).val(),
          success: function(responseData) {
            $('#selecttime').html(responseData);
          }
        });
      }
    );
    $('#selecttime').change(
      function() {
        if(isWhitespace($(this).val()) || isWhitespace($('#selectcinema').val())) {
          $('#selectprice').html('<option>Select Price:</option>');
          return false;
        } else {
          $('#selectprice').html('<option>loading....</option>');
        }
        $.ajax({
          type: "POST",
          url: "web/ajax/get_price_of_movie.php",
          data: "session_id="+$(this).val()+"&cinema_id="+$('#selectcinema').val(),
          success: function(responseData) {
            $('#selectprice').html(responseData);
          }
        });
      }
    );
    $('#selectcinema_booking').change(
      function() {
        $('#selectcinema').val($(this).val());
        get_date_of_movie($('#selectmovie').val(), $(this).val());
      }
    );
//     var scroll_amount = '';
    $('#marquee_speed').hover(
      function() {
        this.stop();
//         scroll_amount = this.scrollAmount;
//         this.scrollAmount = 0;
      },
      function() {
        this.start();
//         this.scrollAmount = scroll_amount;
      }
    );
    $('#marquee_speed_up').click (
      function() {
        $('#marquee_speed').attr('scrollAmount', $('#marquee_speed').attr('scrollAmount') + 1);
      }
    )
    $('#marquee_speed_down').click (
      function() {
        $('#marquee_speed').attr('scrollAmount', $('#marquee_speed').attr('scrollAmount') - 1);
      }
    )
    $('#open_login_detail').click (
      function() {
        var result = $('#login_detail').css("display");
        if (result == 'block') {
          $("#open_login_detail").html("<img src='images/plus.gif' style='cursor:pointer'>");
          $("#login_detail").slideUp("slow");
         // $('#login_detail').css({ display:"none" });
        } else {
          $("#open_login_detail").html("<img src='images/minus.gif' style='cursor:pointer'>");
          $("#login_detail").slideDown("slow");
         // $('#login_detail').css({ display:"block" });
        }
      }
    )
    $('#term_and_conditions_signature').click (
      function() {
        var term_and_conditions_signature = document.getElementById('term_and_conditions_signature').checked;
        if(!term_and_conditions_signature) {
          document.signature_booking.signature_city.disabled=true;
        } else {
          document.signature_booking.signature_city.disabled=false;
        }
      }
    )
    $('#select_region').change(
      function () {
        $('#selectcinema').html('<option>loading....</option>');
        $.ajax({
          type: "POST",
          url: "web/ajax/get_cinemas_by_region.php",
          data: "region_id="+$(this).val(),
          success: function(cinemas){
            $('#selectcinema').html(cinemas);
          }
        });
      }
    )
    $('#show_thickbox_ad').click();
    $('#show_logout_thickbox').click();
    $('#is_pvr_coupon').click (
      function() {
        var result =  document.getElementById('is_pvr_coupon').checked;
        if (result == true) {
          $("#coupon_module").slideDown("slow");
        } else {
          $("#coupon_module").slideUp("slow");
        }
      }
    )
    $('#check_coupon').click (
      function() {
        var radioObj = document.confirm_booking.payment_type;
        var radioLength = radioObj.length;
        if(radioLength == undefined) {
          if(radioObj.checked)
            payment_type = radioObj.value;
        } else {
          for (i=0;i<radioLength;i++) {
            if (radioObj[i].checked) {
              var payment_type = radioObj[i].value;
            }
          }
        }
        if(isWhitespace(payment_type)) {
          alert('Please select payment type.');
          return false;
        }
        var coupon_code = $('#coupon_code').val();
        if(isWhitespace(coupon_code)) {
          alert('Please fill coupon code.');
          return false;
        }
        var show_time = $('#show_time').val();
        var quantity = $('#quantity').val();
        $.ajax({
          type: "GET",
          url: "web/ajax/check_coupon.php",
          data: 'coupon_code='+ coupon_code +'&payment_type='+payment_type+'&show_time='+show_time+'&quantity='+quantity,
          success: function(return_data){
            return_data = eval("("+return_data+")");
            if( return_data['status'] == 1 ) {
              alert(return_data['msg']);
              $('#amount').html(return_data['amount']);
              $('#discount').html(return_data['discount']);
              $('#coupon_code_module').html(coupon_code);
              $('#ask_for_coupon').slideUp("slow");
              $('#payment_type_module').html('<label><input type="radio" name="payment_type" value="'+payment_type+'" checked />'+return_data['payment_title']+'</label>');
            } else {
              alert(return_data['msg']);
//               if(return_data['captcha'] == 'true') {
//                 var captcha_html = '<span><label>&nbsp;</label><dfn><iframe src="'+REDIRECT_URL+'captcha_new?width=100&height=40&characters=5" width=120 height=60 frameborder=0></iframe></dfn></span><span><label>Enter the characters you see in the image above</label><dfn><input type="text"  name="captcha" id="captcha_value" class="inputtext" /></dfn></span>'
//                 $('#capcha').html(captcha_html);
//               }
//               $('#gift_recharge_page_loader').css({ display:"none" });
//               $('#gift_recharge_page_submit').css({ display:"block" });
//               return false;
            }
          }
        });
      }
    )
  }
);


