var intResTimeslot = 0;

function update_res_time() {
   $('#res_time_slot_' + intResTimeslot).hide();
   intResTimeslot = $('#res_time').val();
   $('#res_time_slot_' + intResTimeslot).show();
   
   $('.text_leftcol').height('auto');
   
   prepColumnHeights();
}


/* **************************************************
   Following code was copied from kadobonnen.js and 
   adjusted for the webshop
  ************************************************** */

// auto calculation 
$(document).ready(function() {
   $(".quantity").keyup(function() {
      
      // calc row total
      var _id = ($(this).attr("name")).substring(9, $(this).attr("name").length);
      var _price = parseFloat($("#price_"+_id).attr("value").replace(",", "."));
      _price = _price *$(this).attr("value");
      _price = _price.toFixed(2);
      $("#total_"+_id).attr("value", _price.toString().replace(".", ","));
      
      // update server side shopping cart through ajax
      $.get("/templates/snippets/ajax_updatecart.asp?id=" +_id+ "&value="+$(this).attr("value"));

   })
   
   // fire once to initialize
   $(".quantity").keyup();
});

/*
   Choice form validity check
   
   Errormessages are specified as global variables in procedures/kadobonnen.asp
*/
$(document).ready(function() {
   $("#form_choice").submit(function() {
      if (($("#grandtotal").attr("value") == "") || ($("#grandtotal").attr("value") == "0")) {
         alert(G__NO_ORDER);
         return false;
      }
      
      var bResult = true;
      $(".total").each(function() {
         if (($(this).attr("value") == "NaN") || ($(this).attr("value") < 0)) {
            alert(G__INVALID_ORDER);
            bResult = false;
         }
      });

      return bResult;
   })
});


/*
   + and -  sign for choice form inputboxes
*/
$(document).ready(function() { 
   $(".increment").click(function() {
      var _id = ($(this).attr("id")).substring(10, $(this).attr("id").length);

      // increase
      var _value = $("#quantity_" + _id).attr("value") || 0;
      $("#quantity_" + _id).attr("value", parseInt(_value) +1);
      
      // update server side shopping cart through ajax
      $.get("/templates/snippets/ajax_updatecart.asp?id=" +_id+ "&value="+_value);
      
      // fire keyup to update the total fields
      $(".quantity").keyup();
   })

   $(".decrement").click(function() {
      var _id = ($(this).attr("id")).substring(10, $(this).attr("id").length);

      // decrease
      var _value = $("#quantity_" + _id).attr("value") || 0;
      if (_value < 1) _value = 1; // hard bottom cap = 0
      $("#quantity_" + _id).attr("value", parseInt(_value) -1);
      
      // update server side shopping cart through ajax
      $.get("/templates/snippets/ajax_updatecart.asp?id=" +_id+ "&value="+_value);
      
      // fire keyup to update the total fields
      $(".quantity").keyup();
   })
});