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","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","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;
            }
          }
        });
      }
    )
  }
);

function get_date_of_movie(arg1, arg2) {
  $('#selectdate').html('<option>loading....</option>');
  $('#selecttime').html('<option>Select Time:</option>');
  $('#selectprice').html('<option>Select Price:</option>');
  if(isWhitespace(arg1) || isWhitespace(arg2)) {
    $('#selectdate').html('<option>Select Date:</option>');
    return false;
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/get_date_of_movie.php",
    data: "film_id="+arg1+"&cinema_id="+arg2,
    success: function(responseData) {
      $('#selectdate').html(responseData);
    }
  });
}

var menuwidth=455;
//configure scroll speed (1-10), where larger is faster
var scrollspeed=9;
//specify menu content
var loadedyes=0;

function moveleft() {
  if (loadedyes) {
    if ( parseInt(cross_scroll.style.left)>(menuwidth-actualwidth) ) {
      cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
    }
  }
 
  lefttime = setTimeout(function(){ moveleft() },50);
}

function moveright() {
  if (loadedyes) {
    if ( parseInt(cross_scroll.style.left)<0 )
      cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
  }
  righttime = setTimeout(function(){ moveright() },50);
}

var actualwidth1 = 0;
function fillup() {
  cross_scroll = document.getElementById('featured');
  actualwidth = actualwidth1;
  loadedyes=1;
}

function goto(url, arg) {
  url = REDIRECT_URL+url;
  window.open(url, arg);
}

function show_details(film_code) {
  $.ajax({
    type: "POST",
    url: "web/ajax/get_film_by_code.php",
    data: "film_code="+film_code,
    success: function(msg){
      $('#details').html(msg);
      location.hash = '#details';
    }
  });
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    while (obj = obj.offsetParent) { curleft += obj.offsetLeft }
  }
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) { curtop += obj.offsetTop }
  }
  return curtop;
}

function show_schedule_dates(id_position, id_show) {
  posX = findPosX(document.getElementById(id_position));
  posY = findPosY(document.getElementById(id_position));
  document.getElementById(id_show).style.top = (posY+20)+'px';
  document.getElementById(id_show).style.left = (posX-80)+'px';
  if(document.getElementById('schedule_dates').style.display == 'none') {
    document.getElementById('schedule_dates').style.display = 'block';
  } else {
    document.getElementById('schedule_dates').style.display = 'none';
  }
//   if ($("div:id_show").is(":hidden")) {
//     $("#schedule_dates").slideDown("slow");
//   } else {
//     $("#schedule_dates").slideUp("slow");
//   }
}

function change_schedule(date_str, day) {
  document.getElementById('schedule_dates').style.display = 'none';
  var loader = '<div style="color:#fff;padding-left:200px;"><img src="images/loadingAnimation.gif" alt="Loading....."></div>';
  $('#schedule').html(loader);

  $('#show_date_span').html(date_str);
  $.ajax({
    type: "POST",
    url: "web/ajax/get_schedule.php",
    data: "date_str="+date_str+'&day='+day,
    success: function(msg){
      $('#schedule').html(msg);
    }
  });
}

function isValidEmail(email, field_name) {
  if (! allValidChars(email)) {  // check to make sure all characters are valid
    alert('Invalid '+field_name+' email id.');
    return false;
  }
  if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
    alert('Invalid '+field_name+' email id.');
    return false;
  } else if (email.lastIndexOf(".") <= email.indexOf("@")) {
    alert('Invalid '+field_name+' email id.');
    return false;
  } else if (email.indexOf("@") == email.length) {
    alert('Invalid '+field_name+' email id.');
    return false;
  } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
    alert('Invalid '+field_name+' email id.');
    return false;
  } else if (email.indexOf(".") == email.length) {  // . must not be the last character
    alert('Invalid '+field_name+' email id.');
    return false;
  }
  return true;
}

function valEmail_new(str){
  try {
    var at = "@", dot = ".", lat = str.indexOf(at), lstr = str.length, ldot = str.indexOf(dot);
    var f = false;
    if (str == '') return f;
    if (str.indexOf(at) == -1) return f;
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) return f;
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) return f;
    if (str.indexOf(at, (lat + 1)) != -1) return f;
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) return f;
    if (str.indexOf(dot, (lat + 2)) == -1) return f;
    if (str.indexOf(" ") != -1) return f;
    return true;
  }
  catch(e){
    showErr("valCard()", e);
  }
}
function check_login_form() {
  var email = document.getElementById('email').value;
  if(email.length == 0) {
    alert('Email Id cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }

  var password = document.getElementById('password').value;

  if(password.length == 0) {
    alert('Password field cannot be left blank.');
    return false;
  }
}
function check_login_form_floating() {
  var email = document.getElementById('floating_email').value;
  if(email.length == 0) {
    alert('Email Id cannot be left blank.');
    return false;
  }
  if(!isValidEmail(email, '')) {
    return false;
  }

  var password = document.getElementById('floating_password').value;

  if(password.length == 0) {
    alert('Password field cannot be left blank.');
    return false;
  }
}
function check_anonymous_login_form() {
  var email = document.getElementById('email').value;
  if(email.length == 0) {
    alert('Email Id cannot be left blank.');
    return false;
  }
  if(!isValidEmail(email, '')) {
    return false;
  }
  
  var radioObj = document.login_form.login_module;
  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 login mode.');
    return false;
  }
  if(payment_type == 'anonymous_login_module') {
    var confirmemail = document.getElementById('confirmemail').value;
    if(isWhitespace(confirmemail)) {
      alert('Confirm Email Id cannot be left blank.');
      return false;
    }
    if(confirmemail != email) {
      alert('Email id & Confirm Email Id do not match.');
      return false;
    }
    
    var captcha = document.getElementById('anonymous_captcha').value;
    if(captcha.length == 0) {
      alert('Please enter the characters given in the image below.');
      return false;
    }
  } else if(payment_type == 'login_module') {
    var password = document.getElementById('password').value;
    if(password.length == 0) {
      alert('Password field cannot be left blank.');
      return false;
    }
  }
}
function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function check_registration_form() {
  var email = document.getElementById('email').value; 
  if(email.length == 0) { 
    alert('Email Id cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }

  var password = document.getElementById('password').value;
  if(password.length == 0) {
    alert('Password cannot be left blank.');
    return false;
  }

  if(password.length < 6) {
    alert('Password must be atleast 6 characters long.');
    return false;
  }

  var confirm_password = document.getElementById('confirm_password').value;
  if(confirm_password.length == 0) {
    alert('Confirm password cannot be left blank.');
    return false;
  }
  if(confirm_password != password) {
    alert('Password and confirm password mismatch.');
    return false;
  }

  var question = document.getElementById('question');
  if(question.value == '0') {
    alert('Select any question.');
    return false;
  }
  var answer = document.getElementById('answer');
  if(question.value != '0' && answer.value == '') {
    alert('Answer the selected question.');
    return false;
  }

  var alt_email = document.getElementById('alt_email').value;
  if(alt_email.length == 0) {
    alert('Alternate email id cannot be blank.');
    return false;
  }
  if(!isValidEmail(alt_email, 'Alternate')) {
    return false;
  }
  if(alt_email == email) {
    alert('Alternate email id should be different from first email id');
    return false;
  }

  var first_name = document.getElementById('first_name').value;
  if(first_name.length == 0) {
    alert('First name cannot be blank');
    return false;
  }
  if( !validCharsForUserName(first_name) ) {
    alert('Invalid first name.');
    return false;
  }

  var last_name = document.getElementById('last_name').value;
  if(last_name.length == 0) {
    alert('Last name cannot be blank');
    return false;
  }
  if( !validCharsForUserName(last_name) ) {
    alert('Invalid last name.');
    return false;
  }


  var gender_male = document.getElementById('gender_male').checked;
  var gender_female = document.getElementById('gender_female').checked;
  if ( (!gender_male ) && (!gender_female) ) {
    alert('Gender cannot be blank');
    return false;
  }

  var city = document.getElementById('city').value;
  if(city == '0') {
    alert('Select any city.');
    return false;
  }

  var phone = document.getElementById('phone').value;
  if(phone.length != 0) {
    if(!IsNumeric(phone)) {
      alert('Phone No. invalid.');
      return false;
    }
    if( (phone.length < 10) || (phone.length > 15) ) {
      alert('Phone No. should be 10/15 digits long.');
      return false;
    }
  }

  var mobile = document.getElementById('mobile').value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }

  var terms = document.getElementById('terms');
  if(!terms.checked) {
    alert('Accept the terms and conditions.');
    return false;
  }

  var captcha = document.getElementById('captcha').value;
  if( captcha.length == 0) {
    alert("Please enter the characters in the image.");
    document.getElementById('captcha').focus();
    return false;
  }

}

function IsValidName(sText) {
  var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var IsCharacter=true;
  var Char;

  for (i = 0; i < sText.length && IsCharacter == true; i++) {
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsCharacter = false;
    }
  }
  return IsCharacter;
}

function IsNumeric(sText) {
  var ValidChars = "0123456789";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) {
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

function check_forgot_password() {
  var email = document.getElementById('email').value; 
  if(email.length == 0) { 
    alert('Email Id cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }

  document.forms['forgot_pwd'].submit();
}

function check_blank_field(id, field_name) {
  var field = document.getElementById(id).value; 
  if(field.length == 0) { 
    alert(field_name + ' cannot be left blank.');
    return false;
  }

  document.forms['pwd_recovery'].submit();
}

function check_password() {
  var field = document.getElementById('current_password').value; 
  if(field.length == 0) {
    alert('Current password cannot be left blank.');
    return false;
  }

  var new_pass = document.getElementById('new_password').value; 
  if(new_pass.length == 0) {
    alert('New password cannot be left blank.');
    return false;
  }
  if(new_pass.length < 6) {
    alert('New password must be atleast 6 characters long.');
    return false;
  }

  var conf_pass = document.getElementById('confirm_password').value; 
  if(conf_pass.length == 0) {
    alert('Confirm password cannot be left blank.');
    return false;
  }
  if(new_pass != conf_pass) {
    alert('New and confirm password mismatch.');
    return false;
  }
  document.forms['change_pwd'].submit();
}

var whitespace = " \t\n\r";
function isWhitespace (s) {
  var i;
  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
  }
  return true;
}

function isEmpty(s) {
  return ((s == null) || (s.length == 0))
}

function check_home_form_value() {
// Region check for internal ticket booking.
  if(document.getElementById('select_region')) {
    var region_id = document.getElementById('select_region').value;
    if(isWhitespace(region_id)) {
      alert('oops you skip the REGION field');
      return false;
    }
  }

  var cinema_id = document.getElementById('selectcinema').value;
  if(isWhitespace(cinema_id)) {
    alert('oops you skip the CINEMA field');
    return false;
  }
  var film_id = document.getElementById('selectmovie').value;
  if(isWhitespace(film_id)) {
    alert('oops you skip the MOVIE field');
    return false;
  }

  var time_id = document.getElementById('selectdate').value;
  if(isWhitespace(time_id)) {
    alert('oops you skip the DATE field');
    return false;
  }

  var price_id = document.getElementById('selecttime').value;
  if(isWhitespace(price_id)) {
    alert('oops you skip the TIME field');
    return false;
  }


  var quantitie_id = document.getElementById('selectprice').value;
  if(isWhitespace(quantitie_id)) {
    alert('oops you skip the PRICE field');
    return false;
  }

  var seats = document.getElementById('selectseat').value;
  if(isWhitespace(seats)) {
    alert('oops you skip the SEATS field');
    return false;
  }
  return true;
}

function check_edit_profile() {
  var email = document.getElementById('email').value;
  var alt_email = document.getElementById('alt_email').value;
  if(alt_email.length == 0) {
    alert('Alternate email id cannot be blank.');
    return false;
  }
  if(!isValidEmail(alt_email, 'Alternate')) {
    return false;
  }
  if(alt_email == email) {
    alert('Alternate email id should be different from first email id');
    return false;
  }

  var first_name = document.getElementById('first_name').value;
  if(first_name.length == 0) {
    alert('First name cannot be blank');
    return false;
  }
  if( !validCharsForUserName(first_name) ) {
    alert('Invalid first name.');
    return false;
  }

  var last_name = document.getElementById('last_name').value;
  if(last_name.length == 0) {
    alert('Last name cannot be blank');
    return false;
  }
  if( !validCharsForUserName(last_name) ) {
    alert('Invalid last name.');
    return false;
  }

  var gender_male = document.getElementById('gender_male').checked;
  var gender_female = document.getElementById('gender_female').checked;
  if ( (!gender_male ) && (!gender_female) ) {
    alert('Gender cannot be blank');
    return false;
  }

  var city = document.getElementById('city').value;
  if(city == '0') {
    alert('Select any city.');
    return false;
  }

  var phone = document.getElementById('phone').value;
  if(phone.length != 0) {
    if(!IsNumeric(phone)) {
      alert('Phone No. invalid.');
      return false;
    }
    if( (phone.length < 10) || (phone.length > 15) ) {
      alert('Phone No. should be 10/15 digits long.');
      return false;
    }
  }

  var mobile = document.getElementById('mobile').value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. should be 10 digits long.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
}

function submit_payment_info() {
  var cardno = document.getElementById('cardno').value;
  if(cardno.length != 16) {
    alert('Invalid card no');
    return false;
  }
  if(!IsNumeric(cardno)) {
    alert('Invalid card no, it should be numeric');
    return false;
  }
  var cardtype = document.getElementById('cardtype').value;
  var month = document.getElementById('expirymonth').value;
  var year = document.getElementById('expiryyear').value;
  if(month == '' || month == null) {
    alert('Enter expiry month.');
    return false;
  }
  if(year == '' || year == null) {
    alert('Enter expiry year.');
    return false;
  }
  var month_year = month+year;
  document.getElementById('expirydate').value = month_year;
  var cvv = document.getElementById('cvv').value;
  if(cvv.length != 3) {
    alert('Invalid cvv');
    return false;
  }
  if(!IsNumeric(cvv)) {
    alert('Invalid cvv, it should be numeric');
    return false;
  }
  var name_on_card = document.getElementById('name_on_card').value;
  if( isWhitespace(name_on_card) ) {
    alert('Oops you skip the name field');
    return false;
  }
  var mobile = document.getElementById('mobile').value;
  if(mobile.length != 10) {
    alert('Incorrect mobile no, it must be 10 digit');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  var extra_parms = '';
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      var extra_parms = '&tata=true';
    } else {
      var extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/submit_payment_info.php",
    data: "year="+month_year+"&cvv="+cvv+"&name_on_card="+name_on_card+"&term_and_conditions="+term_and_conditions+"&cardno="+cardno+"&cardcategory="+cardtype+"&mobile="+mobile+extra_parms,
    success: function(responseData) {
      document.payment_form.action = 'https://3dsecure.payseal.com/MultiMPI/from_icici_merchant.jsp';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['card_offer'] == 'signature' ) {
          if( return_data['msg'] == 'success') {
            document.payment_form.submit();
          } else if( return_data['msg'] ) {
            alert(return_data['msg']);
            goto('fresh_booking', '_self');
          } else {
            alert('Some server error occured. Please try again');
            goto('signature_booking', '_self');
          }
        } else if( return_data['card_offer'] =='notsignature' ) {
          if(return_data['amount'] && return_data['msg']) {
            var amount = return_data['amount'];
            var displayAmount = amount+'.00';
            var purchaseAmount = amount * 100;
            $('#displayAmount').val(displayAmount);
            $('#purchaseAmount').val(purchaseAmount);
            var display_msg = return_data['msg']+' Amount payable: '+return_data['amount'];
            if( confirm(display_msg) ) {
              document.payment_form.submit();
            } else {
              goto('fresh_booking', '_self');
            }
          } else {
            document.payment_form.submit();
          }
        } else {
          alert('Some server error occured. Please try again');
          goto('home', '_self');
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('home', '_self');
      }
    }
  });
}

function get_images(type1) {
  $.ajax({
    type: "POST",
    url: "web/ajax/get_images.php",
    data: "type_name="+type1,
    success: function(responseData) {
                if(type1 == 'now') {
                  document.getElementById('now_showing_tab1').style.display = 'block';
                  document.getElementById('now_showing_tab2').style.display = 'none';
                  document.getElementById('coming_soon_tab1').style.display = 'block';
                  document.getElementById('coming_soon_tab2').style.display = 'none';
                }
                if(type1 == 'soon') {
                  document.getElementById('coming_soon_tab2').style.display = 'block';
                  document.getElementById('coming_soon_tab1').style.display = 'none';
                  document.getElementById('now_showing_tab2').style.display = 'block';
                  document.getElementById('now_showing_tab1').style.display = 'none';
                }
      $('#featured').html(responseData);
    }
  });
}

function show_details_now(film_code, first_time) {
  $.ajax({
    type: "POST",
    url: "web/ajax/now_showing_info.php",
    data: "film_code="+film_code,
    success: function(msg) {
      $('#details').html(msg);
      if (!first_time) {
        location.hash = '#details';
      }
    }
  });
}

// function setCookie(c_name,cookie_value,expiredays) {
//   var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays)
//   document.cookie=c_name+ "=" +escape(cookie_value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
// }

function setCookie( name, value, expires, measure, path, domain  ) {
  if(!measure) {
    var measure = 'days';
  }

 if(!path) {
    var path = '/';
  }
  if(!domain) {
     var domain = '.pvrcinemas.com';
  }

  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );
  
  /*
  if the expires variable is set, make the correct
  expires time, the current script below will set
  it for x number of days, to make it for hours,
  delete * 24, for minutes, delete * 60 * 24
  */
  if ( expires ) {
    if(measure == 'days') {
      expires = expires * 1000 * 60 * 60 * 24;
    }
    if(measure == 'hours') {
      expires = expires * 1000 * 60 * 60;
    }
    if(measure == 'minutes') {
      expires = expires * 1000 * 60;
    }
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  ( ( path ) ? ";path=" + path : "" ) +
  ( ( domain ) ? ";domain=" + domain : "" );
}

function readCookie(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  cookieValue_arr = cookieValue.split('+');
  cookieValue = '';
  if (cookieValue_arr.length > 0) {
    for (i = 0; i < cookieValue_arr.length; i++) { cookieValue += cookieValue_arr[i]+' '; }
  }
  return cookieValue.replace(/^\s+|\s+$/g, "");
}

function change_city_cookie(selected_city) {
  setCookie('myregion', selected_city, 7);
  goto('home', '_self')
}

function display_timer(minutes, seconds) {
  if (seconds<=0) {
    seconds=59;
    minutes-=1;
  }
  if (minutes<=-1) {
    seconds=0 ;
    minutes+=1;
    alert('Sorry, your session has expired, please start booking process again');
    goto('fresh_booking?cancel=fresh', '_self');
    return false;
  } else {
    seconds-=1;
  }

  if (seconds <= 9) {
    var formated_seconds = '0'+seconds;
  } else {
    var formated_seconds = seconds;
  }
  document.getElementById('remaining_time').innerHTML = minutes+" : "+formated_seconds;
  setTimeout( function(){ display_timer(minutes, seconds) }, 1000);
}
var total_selected_seats = '';
var total_selected_seats_original = '';
function selectseat(id, quantity) {
  var result_arr = total_selected_seats.split(',');
  var total_selected_seats_new = '';
  var changeseat = false;

  if(id == result_arr[0]) {
        changeseat = true;
  } else {
    for(var i=1; i<quantity; i++) {
      if(result_arr[i]) {
        if(id == result_arr[i]) {
          changeseat = true;
        } else {
          total_selected_seats_new += result_arr[i]+',';
        }
      }
    }
  }
  if(!changeseat) {
    total_selected_seats = total_selected_seats_new+id;
    document.getElementById('new_seat_info').value = total_selected_seats;
    document.getElementById(id).className = 'current_selection';
    document.getElementById(result_arr[0]).className = 'seat_available';
  }
}
function change_seat(secure_url) {
  var new_seat_info = document.getElementById('new_seat_info').value;
  // If seats not changed, redirect directly to payment page
  if( new_seat_info == total_selected_seats_original ) {
    window.location = secure_url+'confirm_payment';
    return;
  }

  //Else Change seats at server and then redirect to payment page
  $('#seat_booking_container').html('<div style="float:left; width:100%; text-align:center; padding:250px 0;"><img src="images/loadingAnimation.gif"></div>');
  $.ajax({
    type: "POST",
    url: "web/ajax/change_seat.php",
    data: "new_seat_info="+new_seat_info,
    success: function(responseData) {
      return_data = eval("("+responseData+")");
      if(return_data['error_msg']) {
        alert(return_data['error_msg']);
        window.location = secure_url+'confirm_payment';
        return false;
      } else if( return_data['seat_details'] ) {
        $('#seat_details').html(return_data['seat_details']);
        //   hide loader
        $('#seat_booking_container').html('');
        //alert('Seats confirmed successfully');
        window.location = secure_url+'confirm_payment';
        return false;
      } else {
        alert('There may be a server problem, please change your seats again');
        window.location = REDIRECT_URL+'confirm_tickets';
        return false;
      }
    }
  });
}

function get_movie_details(movie) {
  var film_code = movie;
  if(film_code) {
    $.ajax({
      type: "POST",
      url: "web/ajax/now_showing_info.php",
      data: "film_code="+film_code,
      success: function(details) {
        $('#movie_details').html(details);
      }
    });
  } else {
    document.getElementById('movie_details').innerHTML = '<span style="font-weight:bold;color:red;padding-left:100px;height:30px;width:200px;">Select a movie to view its details.</span>';
  }
}

// function post_film_details(film_code, cinema_id, date, session_id, page_name, post_form_to, poster) {
//  
//   $.ajax({
//       type: "POST",
//       url: "web/ajax/post_film_details.php",
//       data: "film_code="+film_code+"&cinema_id="+cinema_id+"&date="+date+"&session_id="+session_id+"&page_name="+page_name+"&post_form_to="+post_form_to+"&poster="+poster,
//       success: function(form_data) {
//        
//         $('#post_film_details').html(form_data);
//         document.film_details_form.submit();
//       }
//     });
// }

function post_film_details(film_code, cinema_id, date, session_id, page_name, post_form_to, poster) {
  $.ajax({
      type: "POST",
      url: "web/ajax/post_film_details.php",
      data: "film_code="+film_code+"&cinema_id="+cinema_id+"&date="+date+"&session_id="+session_id+"&page_name="+page_name+"&post_form_to="+post_form_to+"&poster="+poster,
      success: function(form_data) {
        var split_data = form_data.split('@#$');
        var form_data_only = split_data[0];
        var form_name_only = split_data[1];
        if(form_name_only == 'film_details_form') {
          $('#post_film_details').html(form_data_only);
          document.film_details_form.submit();
        } else {
          $('#post_film_details_schedule').html(form_data_only);
          document.film_details_form_schedule.submit();
        }
      }
    });
}



function showCvv() {
  window.open(REDIRECT_URL+"what_is_cvv","_blank","toolbar=no,status=no,menubar=no,width=500, height=500");
}

function showTermsandconditions() {
  window.open(REDIRECT_URL+"terms_and_conditions","_blank","toolbar=no,status=no,menubar=no, scrollbars=yes,location=no, directories=no, status=no");
}

function get_values_of_signature_boxes(id1, id2, id3) {
  var city_name = $(id1).val();
  $('#'+id3).html($('#'+id2+city_name).html());
  return true;
//   var cinemaOptions = '<option value="">Select Cinema:</option>';
//   var dateOptions = '<option value="">Select Date:</option>';
//   var comfortOptions = '<option value="">Select Comfort:</option>';
//   var timeOptions = '<option value="">Select Time:</option>';
// 
//   if(city_name == 'bangalore') {
//     cinemaOptions += '<option value="BGLE">PVR Cinemas, Forum Mall Bangalore</option>';
//     dateOptions += '<option value="20090531">Sunday, May 31, 2009</option>';
//     timeOptions += '<option value="94240">7.00 pm</option>';
//     comfortOptions += '<option value="0001|0000000001">Normal</option>';
//   } else if(city_name == 'ncr') {
//     cinemaOptions += '<option value="GURM">PVR Cinemas, MGF Mall</option>';
//     dateOptions += '<option value="20090530">Saturday, May 30, 2009</option>';
//     timeOptions += '<option value="79445">7.15 pm | Audi 4</option>';
//     timeOptions += '<option value="79446">7.25 pm | Audi 5</option>';
//     comfortOptions += '<option value="0001|0000000001">Normal</option>';
//   } else if(city_name == 'mumbai') {
//     cinemaOptions += '<option value="PHNX">PVR Cinemas, Phoenix Mill</option>';
//     dateOptions += '<option value="20090603">Wednesday, June 03, 2009</option>';
//     timeOptions += '<option value="6255">8:00 pm</option>';
//     comfortOptions += '<option value="0001|0000000002">Star Normal</option>';
//     comfortOptions += '<option value="0002|0000000001">Prime Normal</option>';
//   }
// 
//   $('#signature_date').html(dateOptions);
//   $('#signature_time').html(timeOptions);
//   $('#signature_price').html(comfortOptions);

}
function get_date_of_signature_boxes(event_id, cinema_id, id1, id2) {
  var event = $(event_id).val();
  var cinema = $('#'+cinema_id).val();
  $('#'+id2).html($('#'+id1+cinema+'_'+event).html());
  return true;
}

function get_signature_area_code(id1, id2, id3) {
  $.ajax({
    type: "POST",
    url: "web/ajax/get_price_of_movie.php",
    data: "session_id="+$(id1).val()+"&cinema_id="+$('#'+id2).val(),
    success: function(responseData) {
      showPrice = eval("("+responseData+")");
      var priceOptions = '<option value="">Select Comfort</option>';
      for (var i in showPrice) {
        option_value = showPrice[i]['Price_strCode']+'|'+showPrice[i]['AreaCat_strCode'];
        var class_arr = showPrice[i]['Class_strName'].split('('); 
        priceOptions += '<option value="'+option_value+'">' + class_arr[0] + '</option>';
      }
      $('#'+id3).html(priceOptions);
    }
  });
  return true;
}

function check_signature_form_value() {
  var term_and_conditions_signature = document.getElementById('term_and_conditions_signature').checked;
  if(!term_and_conditions_signature) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }

  var city = document.getElementById('signature_city').value;
  if(isWhitespace(city)) {
    alert('oops you skip the CITY field');
    return false;
  }

  var cinema_id = document.getElementById('signature_cinema_id').value;
  if(isWhitespace(cinema_id)) {
    alert('oops you skip the CINEMA field');
    return false;
  }
  
  var movie = document.getElementById('signature_event_id').value;
  if(isWhitespace(movie)) {
    alert('oops you skip the MOVIE field');
    return false;
  }
  
  var date = document.getElementById('signature_date').value;
  if(isWhitespace(date)) {
    alert('oops you skip the DATE field');
    return false;
  }

  var price = document.getElementById('signature_price').value;
  if(isWhitespace(price)) {
    alert('oops you skip the COMFORT field');
    return false;
  }

  var seats = document.getElementById('selectseat').value;
  if(isWhitespace(seats)) {
    alert('oops you skip the SEATS field');
    return false;
  }
  return true;
}

function set_position(id) {
  if(document.getElementById('pop_up'+id).style.display == 'none') {
    posX = findPosX(document.getElementById(id));
    posY = findPosY(document.getElementById(id));
    document.getElementById('pop_up'+id).style.top = posY + 20 + 'px';
    document.getElementById('pop_up'+id).style.left = posX - 500 + 'px';
    document.getElementById('pop_up'+id).style.display = 'block';
  } else {
    document.getElementById('pop_up'+id).style.display = 'none'; 
  }
}

function month_days(days_month, id, year_id) { 
  var days = days_month.split('-');
  var total_days = days[0];
  var month_name = days[1];
  if(document.getElementById(year_id).value == '') {
    alert('Select year first.');
    return false;
  }

  var year = document.getElementById(year_id).value;
  if(checkleapyear(year) && parseInt(total_days) == 28) {
    total_days = 29;
  }
  var days = '<option value="">Select Day</option>';
  for(var i = 1; i <= total_days; i++) {
    days = days + '<option value='+i+'>'+i+'</option>';
  }
  document.getElementById(id).innerHTML = days;
}


function checkleapyear(year) {
  year = parseInt(year);
  if(year%4 == 0) {
    if(year%100 != 0) {
      return true;
    } else {
        if(year%400 == 0)
          return true;
        else
          return false;
    }
  }
  return false;
}

function check_transaction_report1(form_name) {

  var select_region = document.getElementById('select_region').value; 
  var selectcinema = document.getElementById('selectcinema').value;
  var selectmovie = document.getElementById('selectmovie').value;
  var transaction_type = document.getElementById('transaction_type').value;
  var mobile = document.getElementById('mobile').value;
  var email_id = document.getElementById('email_id').value;
  var booking_id = document.getElementById('booking_id').value;
  var exclude_region = document.getElementById('exclude_region').checked; 
  var exclude_cinema = document.getElementById('exclude_cinema').checked;
  var full_report = document.getElementById('full_report').checked;
  var start_day = document.getElementById('select_start_day').value;
  var start_month = document.getElementById('select_start_month').value;
  var start_year = document.getElementById('select_start_year').value;
  var end_day = document.getElementById('select_end_day').value;
  var end_month = document.getElementById('select_end_month').value;
  var end_year = document.getElementById('select_end_year').value;

  if(select_region == '' && selectcinema == '' && selectmovie == '' && (start_year == '' || start_month == ''  || start_day == '') &&  (end_year == '' ||  end_month == '' || end_day == '') && transaction_type == '' && email_id == '' && mobile == '' && booking_id == '' &&  exclude_region == false && full_report == false && exclude_cinema == false) {
    alert("Select atleast one criterion for search.");
    return false;
  }

  if((end_day != '') && (end_month != '') && (end_year != '')) {
    if((start_day == '') && (start_month == '') && (start_year == '')) {
      alert('Select start date first');
      return false;
    }
  }

  var email = document.getElementById('email_id').value; 
 
  if((email != '') && !isValidEmail(email, '')) {
    return false;
  }


//   if(start_year > end_year) { 
//     alert('End date should be greater than start date.1');
//     return false;
//   }
//   if( (start_year <= end_year) && (start_month > end_month) ) { 
//     alert('End date should be greater than start date.2');
//     return false;
//   }
//   if( (start_year <= end_year) && (start_month <= end_month) && (start_day > end_day) ) { 
//     alert('End date should be greater than start date.3');
//     return false;
//   }

}
function check_payment_type(secure_url) {
  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;
  }

  if(payment_type == 'creditcard' || payment_type == 'master_credit_card' || payment_type == 'visa_debit_card' || payment_type == 'oxicash' || payment_type == 'ccavenue' || payment_type == 'amex' || payment_type == 'wallet' || payment_type == 'mchek' || payment_type == 'giftcard' ) {
    if(payment_type == 'wallet') {
      $.ajax({
        type: "POST",
        url: "web/ajax/check_wallet_balance.php",
        data: "&wallet=1",
        success: function(responseData) {
          if(responseData) {
            return_data = eval("("+responseData+")");
            if( (return_data['wallet_balance'] == 'sufficient') ) {
              //Show updated convenience fee and ticket amount message
              alert(return_data['total_amount']);
               check_payment_gateway(payment_type, secure_url);
            } else {
              if( return_data['wallet_convenience'] == 'default') {
                if( return_data['wallet_balance'] == 'no convenience' ) {
                  check_payment_gateway(payment_type, secure_url);
                } else {
                  alert(return_data['wallet_balance']);
                  return false;
                }
              } else {
                  if( return_data['wallet_balance'] == 'balance error') {
                  alert("Error occured while checking user's wallet balance.Try again or you can use other payment options.");
                  return false;
                } else {
                  alert(return_data['wallet_balance']);
                  return false;
                }
              }
            }
          } else {
            alert('Some server error occured. Please try again');
            goto('home', '_self');
          }
        }
      });
    } else {
      check_payment_gateway(payment_type, secure_url);
    }
  } else {
    alert('Please select Payment type');
    return false;
  }
}
function check_payment_gateway(payment_type, secure_url){
  $.ajax({
      type: "POST",
      url: "web/ajax/check_payment_gateway.php",
      data: "payment_type="+payment_type,
      success: function(responseData) {
        if(responseData) {
          return_data = eval("("+responseData+")");
          if( return_data['msg'] == 'success' ) {
            document.confirm_booking.action = secure_url+return_data['action'];
            document.confirm_booking.submit();
          } else if (return_data['msg'] == 'error'){
            alert(return_data['alert']);
            return false;
          } else {
            alert('There is some system or network problem, Please try again later');
            return false;
          }
        }
      },
      error:function(XMLHttpRequest,status,error){
        alert('There is some system or network problem, Please try again later');
        return false;
      }
    });
}
function submit_edit_admin_form(edit, form_name, key) {
  if(edit == 'edit') {
    var new_password = document.getElementById('new_password'+key).value;
    if(new_password == '') {
      alert('Fill the new password.');
      return false;
    }
    var confirm_password = document.getElementById('confirm_password'+key).value;
    if(confirm_password == '') {
      alert('Fill the confirm password.');
      return false;
    }
    if(new_password != confirm_password) {
      alert('New and confirm  password mismatch.');
      return false;
    }
    document.getElementById('edit'+key).value = 'edit';
    document.forms[form_name].submit();
  }
  if(edit == 'delete') {
    if(confirm('Do you want to delete this user ?')) {
      document.getElementById('edit'+key).value = 'delete';
      document.forms[form_name].submit();
    } else {
      return false;
    }
  }
  return false;
}

function submit_edit_user_form(edit, form_name, key) {
  if(edit == 'edit') {
    document.getElementById('edit'+key).value = 'edit';
    document.forms[form_name].submit();
  }
  if(edit == 'delete') {
    if(confirm('Do you want to delete this user ?')) {
      document.getElementById('edit'+key).value = 'delete';
      document.forms[form_name].submit();
    } else {
      return false;
    }
  }
}

function check_transaction_report(form_name) {
  var select_region = document.getElementById('select_region').value; 
  var selectcinema = document.getElementById('selectcinema').value;
  var selectmovie = document.getElementById('selectmovie').value;
  var transaction_type = document.getElementById('transaction_type').value;
  var mobile = document.getElementById('mobile').value;
  var email_id = document.getElementById('email_id').value;
  var cwsip = document.getElementById('cwsip').value;
  var booking_id = document.getElementById('booking_id').value;
  var exclude_region = document.getElementById('exclude_region').checked; 
  var exclude_cinema = document.getElementById('exclude_cinema').checked;
  var full_report = document.getElementById('full_report').checked;
  var tata_aig = document.getElementById('tata_aig').checked;
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if(select_region == '' && selectcinema == '' && selectmovie == '' && start_date == '' &&  end_date == '' && transaction_type == '' && email_id == '' && cwsip == '' && mobile == '' && booking_id == '' &&  exclude_region == false && full_report == false && exclude_cinema == false && tata_aig == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }

  var email = document.getElementById('email_id').value; 
  if((email != '') && !isValidEmail(email, '')) {
    return false;
  }
}

function check_visalimit_report(form_name) {
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if( start_date == '' &&  end_date == '' ) {
    alert('Select date.');
    return false;
  }


  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  var regEx = /^(\d){1,2}-(\d){1,2}-(\d){4}$/;
  if(start_date != '') {
    if( !(start_date.match(regEx)) ) {
      alert('Invalid start date.');
      return false;
    }
  }

  if(end_date != '') {
    if( !(end_date.match(regEx)) ) {
      alert('Invalid end date.');
      return false;
    }
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }
}

function check_site_user_report(form_name) {
  var email_id = document.getElementById('email_id').value;
  var mobile = document.getElementById('mobile').value;
  var user_name = document.getElementById('user_name').value;

  if(email_id == '' && mobile == '' && user_name == '') {
    alert('Enter atleast one search criterion.');
    return false;
  }

  if((email_id != '') && !isValidEmail(email_id, '')) {
    return false;
  }

  if(!IsNumeric(mobile)) {
    alert('Invalid. mobile no. ');
    return false;
  }
}

function submit_edit_siteuser_form(form_name, key) {
  document.getElementById('edit'+key).value = 'password';
  document.forms[form_name].submit();
}

function check_person_entry() {
  var person_name = document.getElementById('person_name').value;
  if(person_name  == '') {
    alert('Enter person name.');
    return;
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/get_similar_persons.php",
    data: "person_name="+person_name,
    success: function(result){
      msg = result.split('!@#@!');
      if(msg[0] == 'similar_persons') {
        $('#similar_persons').html(msg[1]);
        document.getElementById('add_person_div').style.display = 'none';
        document.getElementById('message').style.display = 'none';
        document.getElementById('similar_persons').style.display = 'block';
      } else {
        document.forms['add_person_form'].submit();
      }
    }
  });
}

function add_new_person() {
  document.forms['add_person_form'].submit(); 
}

function skip_person_addition() {
  window.location.href = "admin_person_list?add_person=1&msg=skip";
}

function check_promotype_report(form_name) {
  var promo_type = document.getElementById('promo_type').value;

//   var select_region = document.getElementById('select_region').value; 
//   var selectcinema = document.getElementById('selectcinema').value;
//   var selectmovie = document.getElementById('selectmovie').value;
//   var mobile = document.getElementById('mobile').value;
  var email_id = document.getElementById('email_id').value;
//   var booking_id = document.getElementById('booking_id').value;
//   var exclude_region = document.getElementById('exclude_region').checked; 
//   var exclude_cinema = document.getElementById('exclude_cinema').checked;

  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if(promo_type == '') {
    alert('Select promotion type');
    return false;
  }

//   if(select_region == '' && selectcinema == '' && selectmovie == '' && start_date == '' &&  end_date == '' && email_id == '' && mobile == '' && booking_id == '' &&  exclude_region == false &&  exclude_cinema == false) {
//     alert('Select atleast one more search criterion.');
//     return false;
//   }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }

  var email = document.getElementById('email_id').value; 
  if((email != '') && !isValidEmail(email, '')) {
    return false;
  }
}

function check_genre_form() {
  var genre_name = document.getElementById('genre_name').value;
  if(genre_name == '' || genre_name == null) {
    alert('Genre name cannot be blank.');
    return false;
  }
}

function check_user_report() {
  var user_name = document.getElementById('user_name').value;
  var email_id = document.getElementById('email_id').value;
  var mobile = document.getElementById('mobile').value;
  var city = document.getElementById('city').value;
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;
  var male = document.getElementById('male').checked;
  var female = document.getElementById('female').checked;

  if(user_name == '' && email_id == '' && city == '' && mobile == '' && start_date == '' &&  end_date == '' && male == false && female == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if((email_id != '') && !isValidEmail(email_id, '')) {
    return false;
  }

  var phone = document.getElementById('mobile').value;
  if(phone.length != 0) {
    if(!IsNumeric(phone)) {
      alert('Mobile No. invalid.');
      return false;
    }
    if( (phone.length < 10) || (phone.length > 11)  ) {
      alert('Mobile No. should be 10/11 digits long.');
      return false;
    }
  }

  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }
}

function confirm_bin_delete() {
  if(confirm('Do you want to delete this bin?')) {
    return true;
  }
  return false;
}

function check_bin_entry () {
  var bin_no = document.getElementById('bin_no').value;
  if(bin_no == '' || bin_no == null) {
    alert('Fill bin number.');
    return false;
  }
  if(bin_no.length != 6) {
    alert('Bin number length should be 6 digits long.');
    return false;
  }
  if(!IsNumeric(bin_no)) {
    alert('Bin Number invalid');
    return false;
  }
}

function check_mobile_no(id) {
  var mobile = document.getElementById(id).value;
  var extra_parms = '';
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      extra_parms = '&tata=true';
    } else {
      extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_to_session.php",
    data: "mobile="+mobile + extra_parms,
    success: function(responseData) {
      document.payment_form.action = 'https://oxicash.in/Oxipay.asp';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('fresh_booking?cancel=fresh', '_self');
      }
    }
  });
  return true;
}

function check_film_search_form() {
  var film_name = document.getElementById('film_name').value;
  var film_code = document.getElementById('film_code').value;

  if(film_name == '' && film_code == '') {
    alert('Fill a search criterion.');
    return false;
  }

}

function check_internal_booking() {
  var viewer_name = document.getElementById('viewer_name').value;
  if(viewer_name == '' || viewer_name == null) {
    alert('Fill viewer name.');
    return false;
  }
  var viewer_email_id = document.getElementById('viewer_email_id').value;
  if(!isWhitespace(viewer_email_id)) {
    if(!isValidEmail(viewer_email_id, 'viewer')) {
      return false;
    }
  }

  var viewer_mobile = document.getElementById('viewer_mobile').value;
  if(viewer_mobile != '') {
    if(!IsNumeric(viewer_mobile)) {
      alert('Viewer mobile number invalid.');
      return false;
    }
  }
  var comments = document.getElementById('comments').value;
  if(isWhitespace(comments)) {
    alert('Please write the comments.');
    return false;
  }
}

function check_ccavenue_form(id, obj) {
  var radioObj = obj.form.elements;
  var radioLength = radioObj.length;
  if(radioLength == undefined) {
    if(radioObj.checked && radioObj.type == 'radio')
      select_internet_banking = radioObj.name;
  } else {
    for (i=0;i<radioLength;i++) {
      if (radioObj[i].checked && radioObj[i].type == 'radio') {
        select_internet_banking = radioObj[i].value;
      }
    }
  }
  var select_card = document.getElementById('cardOption').value;
  if( select_card == '' && select_internet_banking == '') {
    alert('Please select payment type');
    return false;
  }

  var mobile = document.getElementById(id).value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  extra_parms = '';
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      var extra_parms = '&tata=true';
    } else {
      var extra_parms = '&tata=false';
    }
  }

  // customer's mobile number for ccavenue's mail.
  document.getElementById('billing_cust_tel').value = document.getElementById(id).value;
  document.getElementById('delivery_cust_tel').value = document.getElementById(id).value;

  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_to_session.php",
    data: "mobile="+mobile + extra_parms,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('home', '_self');
      }
    }
  });
  return true;
}

function now_showing() {
  var j = 1;
  for(var k = 1; k <= total_films; k++) {
    if(cinema_regions[k] == selected_region) {
      now_showing_film_code[j] = film_code[k];
      now_showing_film_title[j] = film_title[k];
      now_showing_film_image[j++] = film_image[k];
    }
  }
  var films_count = j-1;
  if(films_count) {
    var total_rows = parseInt(films_count / 4);
    var last_row_count = (films_count % 4);
    if( last_row_count == 0) {
      last_row_count = 4;
    } else {
      total_rows += 1;
    }

    var carry_on = 1;
    var row_count = 1;
    var html = '';
    var chopped_title = '';
    var order = 1;
      for(var row = 1; row <= total_rows; row++) {
        if( row == total_rows ) {
          row_count = last_row_count;
        } else {
          row_count = 4;
        }
        html += '<div class="movie_module_text now_showing_movie_module_text">';
        for(var l = 1; l <= row_count; l++) {
          html += '<span onmouseover="this.className=\'active\'" onmouseout="this.className=\'\'">';
            html += '<label>';
              chopped_title = now_showing_film_title[order].substr(0, 10);
              html += '<a href="#" onclick="post_film_details(\''+now_showing_film_code[order]+'\', \'\', \'\', \'\', \'now_showing\', \'film_details\', \''+now_showing_film_image[order]+'\');return false;">'+chopped_title+'</a>';
            html += '</label>';
            html += '<em>';
              html += '<a href="#" onclick="post_film_details(\''+now_showing_film_code[order]+'\', \'\', \'\', \'\', \'now_showing\', \'film_details\', \''+now_showing_film_image[order]+'\');return false;"><img src="'+now_showing_film_image[order]+'" alt="Thumbnail" width="104" height="134" /></a>';
            html += '</em>';
            html += '<dfn>';
              html += '<a style="text-decoration:none;" href="#" onclick="post_film_details(\''+now_showing_film_code[order]+'\', \'\', \'\', \'\', \'now_showing\', \'booking\', \''+now_showing_film_image[order]+'\');return false;">Book</a>';
            html += '</dfn>';
            html += '<b>';
              html += '<a href="#" onclick="post_film_details(\''+now_showing_film_code[order]+'\', \'\', \'\', \'\', \'now_showing\', \'film_details\', \''+now_showing_film_image[order]+'\');return false;">Details</a>';
            html += '</b>';
          html += '</span>';
          order++;
        }
        html += '</div>';
      }
  } else {
    html = '<div class="movie_module_text now_showing_movie_module_text"><b style="color:red;">No movies available for selected city/state.</b></div>';
  }
  document.getElementById('fill_nowshowing').innerHTML = html;
}

function  nowShowingHome() {
  var j = 1;
  for(var k = 1; k <= total_films; k++) {
    if(cinema_regions[k] == selected_region) {
      now_showing_film_code[j] = film_code[k];
      now_showing_film_title[j] = film_title[k];
      now_showing_film_image[j++] = film_image[k];
    }
  }
  var films_count = j-1;
  actualwidth1 =  ( 113.4 * films_count);
  var posters = '';
  for(var k = 1; k <= films_count; k++) {
    posters += '<dfn><a href="#"  title="'+now_showing_film_title[k]+'" onclick="post_film_details(\''+now_showing_film_code[k]+'\', \'\', \'\', \'\', \'home\', \'film_details\', \''+now_showing_film_image[k]+'\');return false;"><img src="'+now_showing_film_image[k]+'" width="109" height="145" alt="Thumnails" /></a></dfn>';
  }
  document.getElementById('featured').innerHTML = posters;
}


function setLoginCookies(email, first_name, last_name, keep_loggedin) {
  setCookie('email', email, 24, 'minutes');
  setCookie('first_name', first_name, 24, 'minutes');
  setCookie('last_name', last_name, 24, 'minutes');

  if(keep_loggedin != 'keep_loggedin') {
    setCookie('login_message', 'You have successfully logged in.', 2, 'minutes');
  }
}

function unsetLoginCookies() {
  setCookie('email', '', 1);
  setCookie('first_name', '', 1);
  setCookie('last_name', '', 1);
  setCookie('logout_message', 'You have successfully logged out.', 2, 'minutes');
}

function reset_freshform(region_id) {
  $.ajax({
    type: "POST",
    url: "web/ajax/get_cinemas_by_region.php",
    data: "region_id="+region_id,
    success: function(cinemas){
      $('#selectcinema').html(cinemas);
    }
  });
  $('#selectmovie').html('<option>Select Movie:</option>');
  $('#selectdate').html('<option>Select Date:</option>');
  $('#selecttime').html('<option>Select Time:</option>');
  $('#selectprice').html('<option>Select Price:</option>');
}

function edit_wallet_balance() {
  var status1 = document.getElementById('status').value;
  if(status1 != 'Y') {
    alert('Please enable the status first.');
    return false;
  }

  var convenience_rate = document.getElementById('convenience_rate').value;

  if(convenience_rate != '' || convenience_rate != null) {
    if(!IsNumeric(convenience_rate))  {
      alert('Convenience rate invalid.');
      return false;
    }
  }

  var amount = document.getElementById('amount').value;
  if(amount == '' || amount == null) {
    alert('Please enter amount first.');
    return false;
  }

  if(!IsNumeric(amount))  {
    alert('Amount is invalid.');
    return false;
  }

}

function check_wallet_form(id) {
  var mobile = document.getElementById(id).value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  var extra_parms = '';
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      var extra_parms = '&tata=true';
    } else {
      var extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_to_session.php",
    data: "mobile="+mobile+ extra_parms,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('home', '_self');
      }
    }
  });
  return true;
}


function check_wallet_transaction_report(form_name) {

  var email_id = document.getElementById('email_id').value;
  var mobile = document.getElementById('mobile').value;
  var user_name = document.getElementById('user_name').value;
  var booking_id = document.getElementById('booking_id').value;
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;
  var full_report = document.getElementById('full_report').checked;

  if(start_date == '' &&  end_date == '' && email_id == '' && mobile == '' && user_name =='' && booking_id == '' &&  full_report == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }

  var email = document.getElementById('email_id').value; 
  if((email != '') && !isValidEmail(email, '')) {
    return false;
  }
}

function check_wallet_balance_report(form_name) {

  var email_id = document.getElementById('email_id').value;
  var mobile = document.getElementById('mobile').value;
  var user_name = document.getElementById('user_name').value;
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;
  var full_report = document.getElementById('full_report').checked;

  if(start_date == '' &&  end_date == '' && email_id == '' && mobile == '' && user_name == '' &&  full_report == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date.split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];
    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/');
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];
    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }

  var email = document.getElementById('email_id').value; 
  if((email != '') && !isValidEmail(email, '')) {
    return false;
  }

  if(  mobile.length != 0 ) {
    if(mobile.length < 10) {
      alert('Mobile No. should be atleast 10 digits long.');
      return false;
    }
    if(!IsNumeric(mobile)) {
      alert('Mobile No. invalid');
      return false;
    }
  }
}

function check_wallet_balance_report_pvr(form_name) {
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;
  var full_report = document.getElementById('full_report').checked;

  if(start_date == '' &&  end_date == '' &&  full_report == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date.split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];
    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/');
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];
    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }
}

function display_timer_admin(minutes, seconds) {
  if (seconds<=0) {
    seconds=59;
    minutes-=1;
  }
  if (minutes<=-1) {
    seconds=0 ;
    minutes+=1;
    alert('Sorry, your session has expired, please start booking process again');
    goto('admin_ticket_booking?cancel=done', '_self');
    return false;
  } else {
    seconds-=1;
  }

  if (seconds <= 9) {
    var formated_seconds = '0'+seconds;
  } else {
    var formated_seconds = seconds;
  }
  document.getElementById('remaining_time').innerHTML = minutes+" : "+formated_seconds;
  setTimeout( function(){ display_timer_admin(minutes, seconds) }, 1000);
}

function enable_disable_options(card_option1, card_option2) {
  document.getElementById(card_option1).disabled = false;
  document.getElementById(card_option2).disabled = true;
}

function check_amex_form() {
  var cardno = document.getElementById('cardno').value;
  if( isWhitespace(cardno) ) {
    alert('Enter the card number.');
    return false;
  }
  if(cardno.length != 15) {
    alert('Invalid card number.');
    return false;
  }

  if(!IsNumeric(cardno)) {
    alert('Invalid card number, it should be numeric.');
    return false;
  }

  var month = document.getElementById('expirymonth').value;
  var year = document.getElementById('expiryyear').value;

  if(month == '' || month == null) {
    alert('Enter card expiry month.');
    return false;
  }

  if(year == '' || year == null) {
    alert('Enter card expiry year.');
    return false;
  }

  var month_year = year+month;
  document.getElementById('vpc_CardExp').value = month_year;

  var cvv = document.getElementById('cvv').value;
  if( isWhitespace(cvv) ) {
    alert('Enter the CVV/CSC');
    return false;
  }

  if(cvv.length != 4) {
    alert('Invalid Card Security Code(cvv/csc).');
    return false;
  }
  if(!IsNumeric(cvv)) {
    alert('Invalid Card Security Code(cvv/csc), it should be numeric.');
    return false;
  }
  document.getElementById('vpc_CardSecurityCode').value = cvv;

  var name_on_card = document.getElementById('name_on_card').value;
  if( isWhitespace(name_on_card) ) {
    alert('Enter the name(as on card).');
    return false;
  }

  var zip_code = document.getElementById('zip_code').value;
  if( isWhitespace(zip_code) ) {
    alert('Enter the zip code');
    return false;
  }
  if(zip_code.length < 5) {
    alert('Incorrect zip code, it should be atleast 5 digits long.');
    return false;
  }
  document.getElementById('vpc_AVS_PostCode').value = zip_code;

  var mobile = document.getElementById('mobile').value;

  if( isWhitespace(mobile) ) {
    alert('Enter the mobile number.');
    return false;
  }
  if(mobile.length != 10) {
    alert('Incorrect mobile number, it must be 10 digits long.');
    return false;
  }

  if(!IsNumeric(mobile)) {
    alert('Mobile number invalid.');
    return false;
  }

  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  var extra_parms = '';
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      var extra_parms = '&tata=true';
    } else {
      var extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_to_session.php",
    data: "mobile="+mobile+ extra_parms,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('home', '_self');
      }
    }
  });
  return true;
}

function check_fbconnect_form() {
  var email = document.getElementById('email').value; 
  if(email.length == 0) { 
    alert('Email cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }

  var email_confirm = document.getElementById('email_confirm').value; 
  if(email_confirm.length == 0) { 
    alert('Confirm email cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email_confirm, 'confirm')) {
    return false;
  }

  if(email != email_confirm) {
    alert('Email id and Confirm Email id mismatch.');
    return false;
  }
  document.forms['fbconnect_data'].submit();
}

function form_validation() {

  var card_name = document.getElementById('gift_card_name').value;
  if(card_name.length == 0) {
    alert('Please Enter the Card Name');
    return false;
  }

  if(card_name.length > 20) {
    alert('Maximum Name Length should be 20 characters');
    return false;
  }

  if(!IsValidName(card_name)) {
    alert('Please Enter Alphabets Only');
    return false;
  }

  var card_desc = document.getElementById('gift_card_description').value;
  if(card_desc.length == 0) {
    alert('Please Enter the Card Description');
    return false;
  }

  if(card_desc.length >= 200) {
    alert('Maximum Description Length should be 200 characters');
    return false;
  }

  if(document.getElementById('gift_card_file').value == '') {
    alert('Please Upload a file');
    return false;
  }

  var card_denom = document.getElementById('gift_card_denom').value;
  if(card_denom == '') {
    alert('Please Enter the Card Denominations');
    return false;
  }
  var card_denom_array = card_denom.split(',');
  if (card_denom_array.length > 0) {
    for (var i = 0; i < card_denom_array.length; i++) { 
      if(!IsNumeric(card_denom_array[i])) {
        alert('Please Enter Numbers');
        return false;
      }

      if(card_denom_array[i].length > 4) {
        alert('Value Should Not Be More Than 9999');
        return false;
      }
    }
  }
}

function my_selected_card(card_id, card_name) {
  document.getElementById('selected_card_id').value= card_id;
  document.getElementById('selected_card_name').value= card_name;
  document.card_selection_form.submit();
}

function select_card_value(card_id, card_value) {
  document.getElementById('selected_card').value= card_id;
  document.getElementById('card_value').value= card_value;
  document.card_processing_form.submit();
}

function  check_giftcard_mobile_no(id) {
  
  var mobile = document.getElementById(id).value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_giftcard_mobile_to_session.php",
    data: "mobile="+mobile,
    success: function(responseData) {
      document.payment_form.action = 'https://oxicash.in/Oxipay.asp';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('select_gift_card', '_self');
      }
    }
  });
  return true;
}

function check_giftcard_ccavenue_form(id) {
  var select_card = document.getElementById('select_card').value;
  var select_internet_banking = document.getElementById('select_internet_banking').value;

  if( select_card == '' && select_internet_banking == '') {
    alert('Please select payment type');
    return false;
  }

  var mobile = document.getElementById(id).value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }

  // customer's mobile number for ccavenue's mail.
  document.getElementById('billing_cust_tel').value = document.getElementById(id).value;
  document.getElementById('delivery_cust_tel').value = document.getElementById(id).value;

  $.ajax({
    type: "POST",
    url: "web/ajax/save_giftcard_mobile_to_session.php",
    data: "mobile="+mobile,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('select_gift_card', '_self');
      }
    }
  });
  return true;
}

function check_giftcard_amex_form() {
  var cardno = document.getElementById('cardno').value;
  if(cardno.length != 15) {
    alert('Invalid card number.');
    return false;
  }

  if(!IsNumeric(cardno)) {
    alert('Invalid card number, it should be numeric.');
    return false;
  }

  var month = document.getElementById('expirymonth').value;
  var year = document.getElementById('expiryyear').value;

  if(month == '' || month == null) {
    alert('Enter card expiry month.');
    return false;
  }

  if(year == '' || year == null) {
    alert('Enter card expiry year.');
    return false;
  }

  var month_year = year+month;
  document.getElementById('vpc_CardExp').value = month_year;

  var cvv = document.getElementById('cvv').value;
  if(cvv.length != 4) {
    alert('Invalid Card Security Code(cvv/csc).');
    return false;
  }
  if(!IsNumeric(cvv)) {
    alert('Invalid Card Security Code(cvv/csc), it should be numeric.');
    return false;
  }
  document.getElementById('vpc_CardSecurityCode').value = cvv;

  var name_on_card = document.getElementById('name_on_card').value;
  if( isWhitespace(name_on_card) ) {
    alert('oops you skip the name field');
    return false;
  }

  var mobile = document.getElementById('mobile').value;
  if(mobile.length != 10) {
    alert('Incorrect mobile number, it must be 10 digits long.');
    return false;
  }

  if(!IsNumeric(mobile)) {
    alert('Mobile number invalid.');
    return false;
  }

  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  cardtype = 'American Express';

  $.ajax({
    type: "POST",
    url: "web/ajax/save_giftcard_mobile_to_session.php",
    data: "year="+month_year+"&cvv="+cvv+"&name_on_card="+name_on_card+"&term_and_conditions="+term_and_conditions+"&cardno="+cardno+"&cardcategory="+cardtype+"&mobile="+mobile,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('home', '_self');
      }
    }
  });
  return true;
}


function submit_giftcard_payment_info() {

  var cardno = document.getElementById('cardno').value;
  if(cardno.length != 16) {
    alert('Invalid card no');
    return false;
  }

  if(!IsNumeric(cardno)) {
    alert('Invalid card no, it should be numeric');
    return false;
  }

  var cardtype = document.getElementById('cardtype').value;

  var month = document.getElementById('expirymonth').value;
  var year = document.getElementById('expiryyear').value;

  if(month == '' || month == null) {
    alert('Enter expiry month.');
    return false;
  }

  if(year == '' || year == null) {
    alert('Enter expiry year.');
    return false;
  }

  var month_year = month+year;
  document.getElementById('expirydate').value = month_year;

  var cvv = document.getElementById('cvv').value;
  if(cvv.length != 3) {
    alert('Invalid cvv');
    return false;
  }

  if(!IsNumeric(cvv)) {
    alert('Invalid cvv, it should be numeric');
    return false;
  }

  var name_on_card = document.getElementById('name_on_card').value;
  if( isWhitespace(name_on_card) ) {
    alert('oops you skip the name field');
    return false;
  }

  var mobile = document.getElementById('mobile').value;
  if(mobile.length != 10) {
    alert('incorrect mobile no, it must be 10 digit');
    return false;
  }

  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }

  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }

  $.ajax({
    type: "POST",
    url: "web/ajax/save_giftcard_mobile_to_session.php",
    data: "year="+month_year+"&cvv="+cvv+"&name_on_card="+name_on_card+"&term_and_conditions="+term_and_conditions+"&cardno="+cardno+"&cardcategory="+cardtype+"&mobile="+mobile,
    success: function(responseData) {
      document.payment_form.action = 'https://3dsecure.payseal.com/MultiMPI/from_icici_merchant.jsp';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('select_gift_card', '_self');
      }
    }
  });
}


function check_visa_messages() {
  var booking_id = document.getElementById('booking_id').value;
  var card_number = document.getElementById('card_number').value;
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if( (!booking_id || booking_id == '') && ( !card_number || card_number == '') && (!start_date || start_date == '') && ( !end_date || end_date == '') ) {
    alert('Please provide the search criterion.');
    return false;
  }

  if( !IsNumeric(card_number) ) {
    alert('Card number invalid.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }
}

function display_info_form(id, show_form) {
  if(show_form == 'yes') {
    document.getElementById(id).style.display = 'block';
  } else {
    document.getElementById(id).style.display = 'none';
  }
}

function validCharsForUserName(name1) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz";
  for (var i=0; i < name1.length; i++) {
    var letter = name1.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}



function verify_form_data() {

  if(document.getElementById('is_card_gifted_yes').checked) {

    var holder_firstname = document.getElementById('card_holder_firstname').value;

    if(holder_firstname.length == 0) {
      alert('Card Holder First Name can not be left blank');
      return false;
    }
    
    if(!IsValidName(holder_firstname)) {
      alert('Please Enter Alphabets Only in Card Holder First Name Field');
      return false;
    }
    
    var holder_lastname = document.getElementById('card_holder_lastname').value;

    if(holder_lastname.length == 0) {
      alert('Card Holder Last Name can not be left blank');
      return false;
    }

    if(!IsValidName(holder_lastname)) {
      alert('Please Enter Alphabets Only in Card Holder Last Name Field');
      return false;
    }

    var m = document.getElementById('card_holder_sex_m');
    var f = document.getElementById('card_holder_sex_f');

    if((m.checked == false ) && (f.checked == false )) {
      alert('Please select Card Holder Gender');
      return false;
    }

    var email = document.getElementById('card_holder_email').value; 
    if(email.length == 0) { 
      alert('Card Holder Email cannot be left blank.');
      return false;
    }

    if(!isValidEmail(email, 'Card Holder')) {
      return false;
    }

    if(document.getElementById('card_holder_address').value == '') {
      alert('Card Holder Address can not be left blank');
      return false;
    }

    if(document.gift_card_trans.payment_type.selectedIndex == 0) {
      alert('Please select payment type');
      return false;
    }

    var sender_firstname = document.getElementById('card_sender_firstname').value;

    if(sender_firstname.length == 0) {
      alert('Card Sender First Name can not be left blank');
      return false;
    }

    if(!IsValidName(sender_firstname)) {
      alert('Please Enter Alphabets Only in Card Sender First Name Field');
      return false;
    }
    
    var sender_lastname = document.getElementById('card_sender_lastname').value;

    if(sender_lastname.length == 0) {
      alert('Card Sender last name can not be left blank');
      return false;
    }

    if(!IsValidName(sender_lastname)) {
      alert('Please Enter Alphabets Only in Card Sender Last Name Field');
      return false;
    } 
    var m = document.getElementById('card_sender_sex_m');
    var f = document.getElementById('card_sender_sex_f');

    if((m.checked == false ) && (f.checked == false )) {
      alert('Please select Your Gender');
      return false;
    }

    var email = document.getElementById('card_sender_email').value; 
    if(email.length == 0) { 
      alert('Card Sender Email cannot be left blank.');
      return false;
    }

    if(!isValidEmail(email, 'Card Sender')) {
      return false;
    }
    

    if(document.getElementById('card_sender_address').value == '') {
      alert('Card Sender adress can not be left blank');
      return false;
    }
    document.gift_card_trans.submit();
  } else if(document.getElementById('is_card_gifted_no').checked) {

    var holder_firstname = document.getElementById('card_holder_firstname').value;

    if(holder_firstname.length == 0) {
      alert('Card Holder First Name can not be left blank');
      return false;
    }

    if(!IsValidName(holder_firstname)) {
      alert('Please Enter Alphabets Only in Card Holder First Name Field');
      return false;
    }

    var holder_lastname = document.getElementById('card_holder_lastname').value;

    if(holder_lastname.length == 0) {
      alert('Card Holder Last Name can not be left blank');
      return false;
    }

    if(!IsValidName(holder_lastname)) {
      alert('Please Enter Alphabets Only in Card Holder Last Name Field');
      return false;
    }
  
    var m = document.getElementById('card_holder_sex_m');
    var f = document.getElementById('card_holder_sex_f');

    if((m.checked == false ) && (f.checked == false )) {
      alert('Please select Card Holder Gender');
      return false;
    }

    var email = document.getElementById('card_holder_email').value; 
    if(email.length == 0) { 
      alert('Card Holder Email cannot be left blank.');
      return false;
    }

    if(!isValidEmail(email, 'Card Holder')) {
      return false;
    }

    if(document.getElementById('card_holder_address').value == '') {
      alert('Card Holder Address can not be left blank');
      return false;
    }

    if(document.gift_card_trans.payment_type.selectedIndex == 0) {
      alert('Please Select payment type');
      return false;
    }

  } else {
    alert('Please select whether you are gifting this card or not');
    return false;
  }
  document.gift_card_trans.submit();
}

function clear_form_fields(oForm) {
    var frm_elements = oForm.elements;
    for(i=0; i<frm_elements.length; i++) {
      field_type = frm_elements[i].type.toLowerCase();
      switch(field_type) {
      case "text":
      case "password":
      case "textarea":
      case "hidden":
        frm_elements[i].value = "";
        break;

      case "radio":
      case "checkbox":
        if (frm_elements[i].checked) {
          frm_elements[i].checked = false;
        }
        break;

      case "select-one":
      case "select-multi":
        frm_elements[i].selectedIndex = -1;
        break;

      default:
      break;
    }
  }
}

function verify_transaction() {
  if(document.getElementById('transaction_id').value == '') {
    alert('Please Insert Transaction Id');
    return false;
  }
  var email = document.getElementById('email_id').value; 
  if(email.length == 0) { 
    alert('Email Id cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }
  document.get_transaction.submit();
  return true;
}

function perform_action_on_giftcard(act, form_no, formname) {

  document.getElementById('hidden_field'+form_no).innerHTML = '<input type="hidden" name="option" id="option" value=""><input type="hidden" name="action_perform" id="action_perform" value="">';
  if(act == 'edit') {
    var answer = confirm("Do you really want to edit this card details");
    if(answer == true) { 
      document.getElementById('option').value = 'edit_card';
      document.getElementById('action_perform').value = 'edit_card';
      document.forms[formname].submit();
    } else {
      return false;
    }
  } else if(act == 'delete') {
    var answer = confirm("Do you really want to delete this card");
    if(answer == true) {
      document.getElementById('option').value = 'delete_card';
      document.getElementById('action_perform').value = 'delete_card';
      document.forms[formname].submit();
    } else {
      return false;
    }
  }  
}

function check_comingsoon_form() {
  var film_name = document.getElementById('name').value;
  if(!film_name || film_name == '' || film_name == null || film_name == 'undefined') {
    alert('Film name cannot be blank');
     return false;
  }
    document.forms['add'].submit();
}
function showAmexCvv() {
  $('#cvv_button').click();
}

function check_gift_card_form(cardno, pin, mobileno) {
  var cardno = document.getElementById(cardno).value;
  if(cardno.length == 0) {
    alert('Card No. cannot be blank');
    return false;
  }

  var pin = document.getElementById(pin).value;
  if(pin.length == 0) {
    alert('Pin cannot be blank');
    return false;
  }

  var mobile = document.getElementById(mobileno).value;
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  var extra_parms = '';
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      extra_parms = '&tata=true';
    } else {
      extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_cardno_for_giftcard.php",
    data: "mobile="+mobile+"&cardno="+cardno+"&pin="+pin+ extra_parms,
    success: function(responseData) {
      document.payment_form.action = 'payment_by_giftcard';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('fresh_booking?cancel=fresh', '_self');
      }
    }
  });
  return true;
}

function gift_card_options(opt) {
  if(opt == 'recharge') {
    if(isEmpty(readCookie('email'))){
      goto('login?next=select_gift_card&tb=rc', '_self');
      return true;
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/get_gift_recharge_form.php",
    data: "gift_card="+opt,
    success: function(responseData) {
      $('#booking_module').html(responseData);
      parent.location.hash = opt;
    },
    error:function() {
      alert('error');
    }
  });
}
function check_gift_recharge_page(){
  var gift_card = document.getElementById('gift_card').value;
  if(gift_card.length == 0) {
    alert('Gift card No. cannot be blank');
    return false;
  }

  var pin = document.getElementById('pin').value;
  if(pin.length == 0) {
    alert('Pin cannot be blank');
    return false;
  }
  
  var amount = document.getElementById('amount').value;
  if(amount.length == 0) {
    alert('Amount No. cannot be blank');
    return false;
  }
  if(!IsNumeric(amount)) {
    alert('Amount No. invalid');
    return false;
  }
  if(amount < 200) {
    alert('Amount must be 200 or greater.');
    return false;
  }
  var track_data = '';
  var track_data = document.getElementById('track_data').value;
  if(isEmpty(track_data)) {
    var track_data = '';
  } else {
    var track_data = '&track_data='+track_data;
  }
  var additional_transaction_reference = '';
  var additional_transaction_reference = document.getElementById('additional_transaction_reference').value;
  if(isEmpty(additional_transaction_reference)) {
    var additional_transaction_reference = '';
  } else {
    var additional_transaction_reference = '&additional_transaction_reference='+additional_transaction_reference;
  }
  captcha_value = '';
  if($('#captcha_value').val()) {
    captcha_value = document.getElementById('captcha_value').value;
    if(isEmpty(captcha_value)) {
      var captcha_value = '';
    } else {
      var captcha_value = '&captcha_value='+captcha_value;
    }
  }
//   var payment_type = $('#payment_type').val();
  var radioObj = document.payment_form.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;
  }
  $('#gift_recharge_page_loader').css({ display:"block" });
  $('#gift_recharge_page_submit').css({ display:"none" });

  $.ajax({
    type: "POST",
    url: "web/ajax/check_gift_recharge_page.php",
    data: "gift_card="+gift_card+"&pin="+pin+"&amount="+amount+track_data+additional_transaction_reference+captcha_value,
    success: function(responseData) {
      document.payment_form.action = 'pay_payment_gift_card';
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } 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;
        }
      } else {
        alert('Some server error occured. Please try again');
        $('#gift_recharge_page_loader').css({ display:"none" });
        $('#gift_recharge_page_submit').css({ display:"block" });
        return false;
      }
    }
  });
  return true;
}

function check_mchek_mobile_no(id) {
  var mobile = document.getElementById(id).value;
  var extra_parms = '';
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var term_and_conditions = document.getElementById('term_and_conditions').checked;
  if(!term_and_conditions) {
    alert('oops you forgot to check the "terms and conditions" field');
    return false;
  }
  if(document.getElementById('tata_aig')) {
    if(document.getElementById('tata_aig').checked) {
      extra_parms = '&tata=true';
    } else {
      extra_parms = '&tata=false';
    }
  }
  $.ajax({
    type: "POST",
    url: "web/ajax/save_mobile_to_session.php",
    data: "mobile="+mobile + extra_parms,
    success: function(responseData) {
      if(responseData) {
        return_data = eval("("+responseData+")");
        if( return_data['msg'] == 'success' ) {
          document.payment_form.submit();
        } else {
          alert(return_data['msg']);
          return false;
        }
      } else {
        alert('Some server error occured. Please try again');
        goto('fresh_booking?cancel=fresh', '_self');
      }
    }
  });
  return true;
}

function check_fbconnect_mapping_form() {
  var email = document.getElementById('email_map').value;
  if(email.length == 0) {
    alert('Email Id cannot be left blank.');
    return false;
  }

  if(!isValidEmail(email, '')) {
    return false;
  }

  var password = document.getElementById('password_map').value;

  if(password.length == 0) {
    alert('Password field cannot be left blank.');
    return false;
  }
  document.forms['fbconnect_mapping'].submit();
}

function change_wallet_status_button() {
  var status_button = document.getElementById('status_button').value;
  if(status_button == 'Activated') {
    document.getElementById('status_button').value = 'Deactivated';
    document.getElementById('status').value = '';
    return;
  }
  if(status_button == 'Deactivated') {
    document.getElementById('status_button').value = 'Activated';
    document.getElementById('status').value = 'Y';
    return;
  }
}

function open_form(obj) {
   // hide error messages
    if(document.getElementById('error1') && document.getElementById('error1').style.display == 'block') {
      document.getElementById('error1').style.display = 'none';
    }
    if(document.getElementById('error2') && document.getElementById('error2').style.display == 'block') {
      document.getElementById('error2').style.display = 'none';
    }

  var radio_id = obj.id;

  if(radio_id == 'open_new_user_form') {
    if(document.getElementById('existing_user_mapping_form').style.display == 'block') {
      $('#existing_user_mapping_form').slideUp("slow");
    }
    $('#new_user_form').slideDown("slow");
  }  else {
    $('#existing_user_mapping_form').slideDown("slow");
    if(document.getElementById('new_user_form').style.display == 'block') {
      $('#new_user_form').slideUp("slow");
    }
  }
}

function check_facebook_user() {
  var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;
  var full_report = document.getElementById('full_report').checked;

  if(start_date == '' &&  end_date == '' &&  full_report == false) {
    alert('Select atleast one search criterion.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date.split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];
    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/');
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];
    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }

  if(start_date != '') {
    document.getElementById('start_date').value = start_day+'-'+start_month+'-'+start_year;
  }
  if(end_date != '') {
    document.getElementById('end_date').value = end_day+'-'+end_month+'-'+end_year;
  }
}

function check_wallet_convenience_rate() {
  var convenience_rate = document.getElementById('convenience_rate').value;
  if(!isWhitespace(convenience_rate)) {
    if(!IsNumeric(convenience_rate))  {
      alert('Convenience rate invalid.');
      return false;
    }
  }
  document.getElementById('convenience').value = '1';
  document.forms['wallet_edit_form'].submit();
}

// function change_seat_() {
//   var transaction_id = document.getElementById('transaction_id').value;
//   if(isWhitespace(transaction_id)){
//     return false;
//   }
//   var email_id = document.getElementById('email_id').value;
//   if(isWhitespace(email_id)){
//     return false;
//   }
//   $('#transaction_module').html('<div style="float:left; width:100%; text-align:center; padding:55px 0;"><img src="images/loadingAnimation.gif"></div>');
//   $.ajax({
//     type: "POST",
//     url: "web/track_transaction.php",
//     data: "transaction_id="+transaction_id+"&email_id="+email_id,
//     success: function(responseData) {
//       return_data = responseData.split('!@#@!');
//       //tb_remove();
//       if(return_data[0] == 'success') {
//         $('#transaction_module').html(return_data[1]);
//         return false;
//       } else {
//         $('#transaction_module').html(return_data[0]);
//         return false;
//       }
//     }
//   });
// }
function check_questions() {
  var temp=new Array();
  for(var j=1; j < 4; j++) {
    temp[j] = 4;
    var len = eval("document.pvr_contest.group" + j);
    for (var i=0; i < len.length; i++) {
        if (eval("document.pvr_contest.group" + j + "["+i+"].checked") == true){
         temp[j] = 1;
      }
    }
    if(temp[j] != 1){
      alert('Please answer question '+j);
      return false;
    }
  }
  var uname = document.getElementById('uname').value;
  if(isWhitespace(uname)) {
    alert('Please fill in your Name.');
    return false;
  }

  var mobile = document.getElementById('mobile').value;
  if(isWhitespace(mobile)) {
    alert('Please fill in your Mobile No.');
    return false;
  }
  if(mobile.length == 0) {
    alert('Mobile No. cannot be blank');
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Mobile No. invalid');
    return false;
  }
  var email = document.getElementById('email').value;
  if(email.length == 0) {
    alert('Please fill in your e-mail address.');
    return false;
  }
  if(!isValidEmail(email, '')) {
    return false;
  }
  var address = document.getElementById('address').value;
  if(isWhitespace(address)) {
    alert('Please fill in your Address.');
    return false;
  }
  return true;
}
function ads_counter(ad_name){
  $.ajax({
    type: "POST",
    url: "web/ajax/ads_counter.php",
    data: "ad_name="+ad_name,
    success: function(responseData) {
    }
  });
}

function movie_schedule() {
  $('#schedule_msg').html('');
  var selected_movie_index = document.getElementById('schedule_movie').selectedIndex;
  var selected_movie = document.getElementById('schedule_movie')[selected_movie_index].value;

  if(!selected_movie_index) {
    $('#schedule_msg').html('Select movie.');
    return false;
  } else {
    var selected_movie_dateIndex = document.getElementById('schedule_date_movie').selectedIndex;
    var selected_movie_date = document.getElementById('schedule_date_movie')[selected_movie_dateIndex].value;
    if(!selected_movie_dateIndex) {
      var only_date = selected_movie_date.split('_');
      var selected_date = only_date[1];
      $('#schedule_msg').html('Select date.');
      return false;
    } else {
      var loader = '<div style="padding-top: 50px;padding-left:150px; "><img src="images/ajax-loader_circle.gif" alt="Loading....."></div>';
      $('#schedule').html(loader);
      var only_date = selected_movie_date.split('_');
      var day = only_date[0];
      var date_str = only_date[1];
      $.ajax({
        type: "POST",
        url: "web/ajax/get_schedule_sidebar.php",
        data: 'movie='+selected_movie+'&date_str='+date_str+'&day='+day,
        success: function(msg){
          $('#schedule').html(msg);
        }
      });
     }
   }
}

function cinema_schedule() {
  $('#schedule_msg_cinema').html('');
  var selected_cinema_index = document.getElementById('schedule_cinema').selectedIndex;
  var selected_cinema = document.getElementById('schedule_cinema')[selected_cinema_index].value;

  if(!selected_cinema_index) {
    $('#schedule_msg_cinema').html('Select cinema.');
    return false;
  } else {
    var selected_cinema_dateIndex = document.getElementById('schedule_date_cinema').selectedIndex;
    var selected_cinema_date = document.getElementById('schedule_date_cinema')[selected_cinema_dateIndex].value;
    if(!selected_cinema_dateIndex) {
      var only_date = selected_cinema_date.split('_');
      var selected_date = only_date[1];
      $('#schedule_msg_cinema').html('Select date.');
      return false;
    } else {
      var loader = '<div style="padding-top:50px;padding-left:150px; "><img src="images/ajax-loader_circle.gif" alt="Loading....."></div>';
      $('#schedule').html(loader);
      var only_date = selected_cinema_date.split('_');
      var day = only_date[0];
      var date_str = only_date[1];
      $.ajax({
        type: "POST",
        url: "web/ajax/get_schedule_sidebar.php",
        data: 'cinema='+selected_cinema+'&date_str='+date_str+'&day='+day,
        success: function(msg){
          $('#schedule').html(msg);
        }
      });
     }
   }
}
function checkcardoptionccavenue(obj){
  if(obj.name == 'NonMotoCardType') {
    $('#cardOption').val('NonMoto');
    var radioObj = obj.form.netBankingCards;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
      if(radioObj.checked)
         radioObj.checked = false;
    } else {
      for (i=0;i<radioLength;i++) {
        if (radioObj[i].checked) {
          radioObj[i].checked = false;
        }
      }
    }
  } else {
    $('#cardOption').val('netBanking');
    var radioObj = obj.form.NonMotoCardType;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
      if(radioObj.checked)
         radioObj.checked = false;
    } else {
      for (i=0;i<radioLength;i++) {
        if (radioObj[i].checked) {
          radioObj[i].checked = false;
        }
      }
    }
  }
}
function download(file_name) {
  window.location=REDIRECT_URL+'download?fname='+file_name;
}
function KeyCheck(e) {
  var KeyID = (window.event) ? event.keyCode : e.keyCode;
  var KeyName = '';
  switch(KeyID) {
    case 16:
    KeyName = "Shift";
    break; 

    case 17:
    KeyName = "Ctrl";
    break;

    case 18:
    KeyName = "Alt";
    break;

    case 19:
    KeyName = "Pause";
    break;

    case 37:
    KeyName = "Arrow Left";
    break;

    case 38:
    KeyName = "Arrow Up";
    break;

    case 39:
    KeyName = "Arrow Right";
    break;

    case 40:
    keyName = "Arrow Down";
    break;
  }
  return KeyName;
}

function play_slides_by_key(e) {
  var keyName = KeyCheck(e);
  switch(keyName) {
    case '':
    break; 

    case 'Arrow Left':
    ss.previous();
    break;

    case 'Arrow Right':
    ss.next();
    break;

    case 'Pause':
    hide_button('ss_stop','ss_start');
    ss.pause();
    break;
  }
}
function hide_button(id1, id2){
  document.getElementById(id1).style.display = 'none';
  document.getElementById(id2).style.display = 'block';
}

function check_bad_transactions_populate(form_name) {
   var start_date = document.getElementById('start_date').value;
  var end_date = document.getElementById('end_date').value;

  if(start_date == '' &&  end_date == '' ) {
    alert('Select  date first.');
    return false;
  }

  if(end_date != '' && start_date == '') {
    alert('Select start date first.');
    return false;
  }

  if(start_date != '') {
    start_date_parts = start_date.split(' ');
    start_dat = start_date_parts[0].split('-');
    start_month = start_dat[0];
    start_day = start_dat[1];
    start_year = start_dat[2];

    var date_start = new Date(start_month+'/'+start_day+'/'+start_year+'/'); 
  }
  if(end_date != '') {
    end_date_parts = end_date.split(' ');
    end_dat = end_date_parts[0].split('-');
    end_month = end_dat[0];
    end_day = end_dat[1];
    end_year = end_dat[2];

    var date_end = new Date(end_month+'/'+end_day+'/'+end_year+'/');
  }

  if(date_start != '') {
    var curdate = new Date();
    if(date_start > curdate) {
      alert('Start date cannot be greater than today.');
      return false;
    }
  }

  if(date_end != '') {
    var curdate = new Date();
    if(date_end > curdate) {
      alert('End date cannot be greater than today.');
      return false;
    }
  }

  if(end_date != '' && start_date != '') {
    if(date_start > date_end) {
      alert('Start date cannot be greater than end date.');
      return false;
    }
  }
}

function validateBulkBooking() {
  if(document.getElementById('name').value=="")  {
    alert("Please enter name");
    document.getElementById('name').focus();
    return false;
  }
  if(document.getElementById('address').value=="") {
    alert("Please enter address");
    document.getElementById('address').focus();
    return false;
  }
   if(document.getElementById('ename').value=="")  {
    alert("Please enter name of event coordinator");
    document.getElementById('ename').focus();
    return false;
  }
  var email = document.getElementById('email').value;
  if(email == "")  {
    alert("Please enter email id ");
    document.getElementById('email').focus();
    return false;
  } 
  if(!isValidEmail(email, '')) {
    document.getElementById('email').focus();
    return false;
  }

 var mobile = document.getElementById('mobile').value;

  if(mobile.length == 0) {
    alert('Please enter mobile number.');
    document.getElementById('mobile').focus();
    return false;
  }
  if(!IsNumeric(mobile)) {
    alert('Please enter valid mobile number.');
    document.getElementById('mobile').focus();
    return false;
  }
  if(mobile.length != 10) {
    alert('Mobile No. length should be 10 digits.');
    return false;
  }

  var no_of_tickets = document.getElementById('nticket').value;
  if(no_of_tickets.length == 0) {
    alert('Please enter number of tickets.');
    document.getElementById('nticket').focus();
    return false;
  }

  if(!IsNumeric(no_of_tickets)) {
    alert('Please enter valid number of tickets.');
    document.getElementById('nticket').focus();
    return false;
  }


   if(document.getElementById('movie').value=="")
  {
    alert("Please enter movie prefered");
    document.getElementById('movie').focus();
    return false;
  }

  if( (document.getElementById('tprice')) && document.getElementById('tprice').length != 0 ) {
    if(!IsNumeric(document.getElementById('tprice').value)) {
      alert('Please enter valid approx. tickets price.');
      document.getElementById('tprice').focus();
      return false;
    }
  }

  if(document.getElementById('comments').value=="")
  {
    alert("Please enter comments ");
    document.getElementById('comments').focus();
    return false;
  }

  if(document.getElementById('captcha').value == "") {
    alert("Please enter image characters shown. ");
    document.getElementById('captcha').focus();
    return false;
  }
}

function create_movie_content(movie_name, language, genre, censor, duration, actors, director, synopsis, poster) {
  $('#film_title').html(movie_name);
  $('#language').html(language);
  $('#censor').html(censor);
  $('#duration').html(duration);
  $('#actors').html(actors);
  $('genre').html(genre);
  $('#director').html(director);
  $('#synopsis').html(synopsis);
  var poster_image = '<img src="'+REDIRECT_URL+'posters/'+poster+'" alt="poster">';
  $('#poster').html(poster_image);
}

function change_film(movie_code, cinema_code, cinema_name) {
  if( !isWhitespace(movie_code) && !isWhitespace(cinema_code) && !isWhitespace(cinema_name) ) {
    $('#movie_code_id').val(movie_code);
    $('#cinema_code_id').val(cinema_code);
    $('#cinema_name_id').val(cinema_name);
    $('#change_film_form').submit();
  }
}

function change_show_times() {
  // hide ticket type
  hide_ticket_type();
  // hide ticket type details
  hide_ticket_type_details();

  var show_time_string = $('#date_show_times_'+$('#movie_dates').val()).html();
  show_time_string = show_time_string.split(',');

  var select_options = '<select id="show_times" onchange="fetch_ticket_type_radio_options();">';
    select_options += '<option value="no" >Select Time</option>';
  for(var i = 0; i < show_time_string.length; i++) {
    select_options += '<option value="'+show_time_string[i]+'" >'+show_time_string[i]+'</option>';
  }
  select_options += '</select>';

  $('#show_times_div').html(select_options);
}


function hide_ticket_type() {
  $('#ticket_types').slideUp('slow');
  $('#ticket_types').html();
}

function hide_ticket_type_details() {
  $('#ticket_type_details').fadeOut('slow');
  $('#selected_seats').val('no');
  $('#sub_total1').html('Rs. 0');
  $('#sub_total2').html('Sub-total Rs. 0');
  $('#convenience_fee').html('Convenience Fee: Rs. 0');
  $('#total_cost').html('Total: Rs. 0');
}

function fetch_ticket_type_radio_options() {
  var movie_code = $('#selected_movie_code').html();
  var cinema_code =  $('#selected_cinema_code').html();
  var selected_date = $('#movie_dates').val();
  var show_time  = $('#show_times').val();

  // hide ticket type
  hide_ticket_type();
  // hide ticket type details
  hide_ticket_type_details();
  if( show_time == 'no' ) {
    return false;
  }

  if(show_time != 'no' && !isWhitespace(show_time) && !isWhitespace(movie_code) && !isWhitespace(cinema_code) && !isWhitespace(selected_date)) {
    // Hide ticket type details
    $('#ticket_type_details').slideUp('slow');
    $.ajax({
      type: "POST",
      url: "web/ajax/fetch_movie_prices.php",
      data: "movie_code="+movie_code+"&cinema_code="+cinema_code+"&selected_date="+selected_date+"&show_time="+show_time,
      success: function(ajax_result) {
        if(ajax_result != 'parameters_missing' && ajax_result != 'no_region_cookie' && ajax_result != 'no_data_found' && ajax_result != '') {
            // hide ticket type
            hide_ticket_type();
            // $('#ticket_types').fadeOut();
          $('#ticket_types').html(ajax_result);
          $('#ticket_types').slideDown('slow');
        } else {
          if(ajax_result == 'parameters_missing') {
            alert('There is some system or network problem, Please select show time again');
            return;
          } else {
            if(ajax_result == 'no_region_cookie') {
              alert('There is some system or network problem, Please select your region again.');
              return;
            } else {
              if(ajax_result == 'no_data_found') {
                alert('There is some system or network problem, No data found for selected show.');
                return;
              } else {
                if(ajax_result == '') {
                  alert('There is some system or network problem, Please change show time.');
                  return;
                }
              }
            }
          }
        }
      },
    error:function(XMLHttpRequest,status,error){
        alert('There is some system or network problem, Please try again later');
        return false;
      }
    });
  }
}

function open_ticket_type(price_class_name, session_id, price_code, area_category_code, price) {
  $('#ticket_type_details').hide();
  $('#price_class_name_id').val(price_class_name);
  $('#session_id').val(session_id);
  $('#price_code').val(price_code+'|'+area_category_code);
  $('#class_name').html(price_class_name);
  $('#price_per_ticket').html(price);
  $('#selected_seats').val('no');
  $('#sub_total1').html('Rs. 0');
  $('#sub_total2').html('Sub-total Rs. 0');
  $('#convenience_fee').html('Convenience Fee: Rs. 0');
  $('#total_cost').html('Total: Rs. 0');
  $('#ticket_type_details').fadeIn('slow');
}

function show_all_films_in_cinema() {
  var inner_html = '<big class="movie_heading font_14" onclick="hide_all_films_in_cinema();" style="cursor:pointer;" >                          Hide All Films at this Cinema </big>';
  $('#show_all_films_in_cinema_div').html(inner_html);
  $('#see_all_films').slideDown('slow');
}

function hide_all_films_in_cinema() {
  var inner_html = '<big class="movie_heading font_14" onclick="show_all_films_in_cinema();" style="cursor:pointer;" >                          Show All Films at this Cinema </big>';
  $('#show_all_films_in_cinema_div').html(inner_html);
  $('#see_all_films').slideUp('slow');
}

function calculate_booking_charges() {
  var total_seats = $('#selected_seats').val();
  var convenience_fee = $('#seat_'+$('#selected_seats').val()).html();
  if (total_seats == 'no') {
    $('#sub_total1').html('Rs. 0');
    $('#sub_total2').html('Sub-total Rs. 0');
    $('#convenience_fee').html('Convenience Fee: Rs. 0');
    $('#total_cost').html('Total: Rs. 0');
    return false;
  }
  var total_convenience = parseInt(convenience_fee);
  var cost_per_ticket = $('#price_per_ticket').html();
  var sub_total = parseInt(cost_per_ticket) * parseInt(total_seats);
  var total_cost = parseInt(sub_total) + parseInt(total_convenience);

  $('#sub_total1').html('Rs. '+sub_total);
  $('#sub_total2').html('Sub-total Rs. '+sub_total);
  $('#convenience_fee').html('Convenience Fee: Rs. '+total_convenience);
  $('#total_cost').html('Total: Rs. '+total_cost);
}

function check_ticket_confirmation() {
  var movie_code = $('#selected_movie_code').html();
  var cinema_code =  $('#selected_cinema_code').html();
  var selected_date = $('#movie_dates').val();
  var show_time  = $('#show_times').val();
  var selected_seats = $('#selected_seats').val();
  var check_captcha = $('#check_captcha').html();
  var captcha_value  = $('#captcha').val();

  if( isWhitespace(selected_date) ) {
    alert('Please select show date.');
    return false;
  }
  if( show_time == 'no' || isWhitespace(show_time) ) {
    alert('Please select show time.');
    return false;
  }

  var class_selected = 0;
  $('#ticket_types > ul > li').children().each(function() {
    if( $(this).attr('checked') ) {
      class_selected =1;
    }
  });
  if( class_selected == 0 ) {
    alert('Please select ticket type.');
    return false;
  }
  if( selected_seats == 'no' || isWhitespace(selected_seats) ) {
    alert('Please select seats.');
    return false;
  }
  if( check_captcha == '1' && isWhitespace(captcha_value) ) {
    alert('Please fill the characters shown in the image.');
    return false;
  } else {
    $('#captcha_id').val($('#captcha').val());
  }

  // Fill  tickets info  booking form
  $('#film_id').val(movie_code);
  $('#cinema_id').val(cinema_code);
  $('#seat').val(selected_seats);
  $('#date').val(selected_date);
  $('#selected_show_time').val(show_time);

  $('#book_ticket_form').submit();
}

function edit_comingsoon_form() {
  var film_name = document.getElementById('name').value;
  if(!film_name || film_name == '' || film_name == null || film_name == 'undefined') {
    alert('Film name cannot be blank');
    return false;
  }
  var release_date = document.getElementById('release_date').value;
  if(isWhitespace(release_date)) {
    alert('Release date cannot be blank');
    return false;
  }
    document.forms['edit'].submit();
}
