function alCarrito(aform,idproducto,cantidad) {
   aform.action = "/shop/ai/oppedido.aspx";
   aform.op.value = "add";
   aform.id.value = idproducto;
   aform.cantidad.value = cantidad;
   aform.urlretorno.value = location.href;
   aform.submit();
}


function delCarrito(aform,idproducto) {
   aform.action = "/shop/ai/oppedido.aspx";
   aform.op.value = "del";
   aform.id.value = idproducto;   
   aform.urlretorno.value = location.href;
   aform.submit();
}


function showCarrito(aform) {
   aform.action = "/shop/ai/oppedido.aspx";
   aform.op.value = "show";
   aform.urlretorno.value = location.href;
   aform.submit();
}



function checkCantidad(cant){   
   if(isNaN(parseInt(cant)))
      return false;
   else
      var ic = parseInt(cant) 
      return (ic>0 && ic<=99)
}



function modCantidad(aform,idproducto,cantField) {
   if (checkCantidad(cantField.value)) { 
       aform.action = "/shop/ai/oppedido.aspx";
       aform.op.value = "modcant";
       aform.id.value = idproducto;
       aform.cantidad.value = parseInt(cantField.value);
       aform.urlretorno.value = location.href;
       aform.submit();   
   }
   else {
       alert("Introduzca una cantidad correcta");
       cantField.value = "1";
       cantField.focus();
       cantField.select();       
   }
}


function resizeImg(imgid,h,w) {
    var maxwidth = w;
    var maxheight = h;
    var imagen = document.getElementById(imgid);
    if (imagen.width>maxwidth || imagen.height>maxheight) {
        var scale = Math.min((maxwidth/imagen.width),(maxheight/imagen.height), 1 );
        var new_width = Math.floor(scale*imagen.width);
        var new_height = Math.floor(scale*imagen.height);
        imagen.width = new_width;
        imagen.height = new_height;        
    }
    imagen.style.visibility = "visible";
}

