var timer;

function showSlide(num)
{
  counter=num;
  counter%=promotions.length;
  $('.promo-box .img').css('backgroundImage','url('+promotions[counter][0]+')');
  $('.promo-box .name p').html(promotions[counter][1]);
  $('.promo-box .name a').removeClass('current');
  $('#promo-anchor'+counter).addClass('current');
  $('.promo-box .url').attr('href',promotions[counter][2]);
  
  clearTimeout(timer);
  timer=setTimeout('showSlide(counter+1)',5000);
}

function setPaymentValue(value)
{
  var value_brutto = parseFloat($('#form_value_brutto').val());
  var delivery_cost = parseFloat($('#form_value_delivery_cost').html());
  var value_total = delivery_cost +  value_brutto + parseFloat(value);
  $('#value_total').html(value_total.toFixed(2));
  $('#total_value').val(value_total);
}

function search(id)
{
  $('#button_'+id).ajaxStart(function(){
    $(this).hide();
  });

  $.ajax({
    url: 'lib/helpers/ajax/good_search.php?ids=&base_goods=0&phrase='+$('#search_'+id).attr('value'),
    success: function(msg){
      if (msg != "")
      {
        $('#goods_id_'+id).empty();
        $('#goods_id_'+id).prepend(msg);
        $('#goods_id_'+id).attr('onchange', "refreshPrice('#goods_id_"+id+"')");
        refreshPrice('#goods_id_'+id);
      }
   },
   complete: function(){
     $('#button_'+id).show();
   }
  });
  return false;
}

function refreshPrice(o)
{
  var good_id = $(o).find(':selected').val();
  id = $(o).attr('id');
  if (id){
    $.ajax({
      url: 'lib/helpers/ajax/good_price.php?id='+good_id,
        success: function(price){
        if (price != "")
        {
          id = id.split("_");
          $('#price_brutto_'+id[2]).attr('value', price);
          $('#quantity_'+id[2]).attr('value', '1.00');
          $('#item_'+id[2]).find('td').eq(5).html(price);
        }
      }
  });
  }

  return false;

}

function addItem()
{
  o = $('#OrderList table');
  var good_id = o.find('tr:last select').attr('id').split("_")[2];
  $.ajax({
      url: 'lib/helpers/ajax/add_order_item.php?id='+good_id,
        success: function(tr){
        if (tr != "")
        {
           o.append(tr);
        }
      }
  });
  return false;
}
