$(document).ready(function() {

  // toggleContent
  $('.toggleContent').click(function(){
    $("#"+$(this).attr('rel')).toggle();
  });

  // order : changes item's quantity
  $('select.itemQty').change(function(){
    var item = $(this).attr('rel');
    var qty = $(this).children("[@selected]").text();
    var reload = '/frontend_dev.php/fr/order/add/item/'+item+'/qty/'+qty;
    if(qty==0)
      var reload = '/frontend_dev.php/fr/order/remove/item/'+item;
    document.location.href = reload;
  });

  // order address form : fills delivery address
  $('#useaddress').change(function(){
    if ($(this).is(":checked"))
    {

      $('#orderInfo input').each(function() {
        var value = $(this).attr('value')
        var element = $(this).attr('id')
        if($("#shipping_"+element))
        {
          $("#shipping_"+element).attr('value', value)
        }
        $("#shipping_title option[@value='"+$("#title").attr('value')+"']").attr("selected","selected")
        $("#shipping_country option[@value='"+$("#country").attr('value')+"']").attr("selected","selected")
      });
    }
    else
    {
      $('#shippingInfo input').each(function() {
        $(this).attr('value', null)
      });
      $("#shipping_country option[@value='BE']").attr("selected","selected")
    }
  });




});
