function initInfo(){
$('table.tabs_box_body tr')
.hover(
function(){
$(this).addClass('hover');
},
function(){
$(this).removeClass('hover');
}
).click(function(){
//var a = $(this).find('td.download a').eq(0).click();
//var durl = $(this).find('td.download a').eq(0).attr('href');
//alert(durl);
});
}
window.onload = function(){
$.preLoadImages('/css/cart_add_hover.gif','/css/cart_add.gif','/css/del.gif','/css/cart_loading.gif');
var lista = $('#lista_productos');
function initList(){
$('img.tooltip').tooltip({
'html' : '
'
});
$('a.tooltip').tooltip({
'html' : ''
});
$('a.varimg').tooltip({
'html' : '',
'width' : 'auto'
});
$('table.list a.add_cart img',lista).hover(
function(){ $(this).attr('src','/css/cart_add_hover.gif'); },
function(){ $(this).attr('src','/css/cart_add.gif') }
);
$('table.list a.del',lista).hover(
function(){ $('img',this).attr('src','/css/del.gif'); },
function(){ $('img',this).attr('src','/css/del_light.gif') }
);
$('table.list a.del',lista).click(function(){
var rel = parseInt($(this).closest('tr').attr('rel'));
setRowLoading($(this).closest('tr'));
$.get('/checkout/action/del/'+rel, { 'fp' : 1 }, function(){
loadCart();
$('#num_products').load('/checkout/num_items');
minicartLoad();
});
});
$('table.list input.count',lista).keyup(function(e){
$(this).removeClass('error');
if (e.keyCode==13){
$(this).closest('tr').find('a.add_cart').click();
}
});
$('table.list a.add_cart',lista).click(function(){
var q = parseInt($(this).closest('tr').find('input.count').val());
var rel = parseInt($(this).closest('tr').attr('rel'));
if (isNaN(q) || !q) {
$(this).closest('tr').find('input.count').addClass('error');
return false;
}
setRowLoading($(this).closest('tr'));
// guardar cantidades
var amounts = {};
$('table.list tr',lista).each(function(){
var $r = $(this).attr('rel');
if ($r){ amounts[$r] = $('input.count',this).val(); }
});
$.get('/checkout/action/add/'+rel, { 'q' : q, 'fp' : 1 }, function(error){
if (error){
jAlert(error, 'Carrito');
// continuamos para que se recarguen todos los datos
}
$('#num_products').load('/checkout/num_items');
minicartLoad();
// restaurar cantidades
$.each(amounts, function(i,val){
if (i != rel){
$('table.list tr[rel="'+i+'"] input.count',lista).val(val);
} else {
$('table.list tr[rel="'+i+'"] input.count',lista).val('').focus();
}
});
loadCart();
});
return false;
});
$('#gotocart').die().live('click',function(){
var url = $(this).attr('href');
var title = "Añadir productos al carrito";
var products = $('table.list input.count[value]',lista);
if (products.length){
$.alerts.okButton = ' Añadir '
jConfirm("Parece que hay algunos artículos con cantidades para solicitar pero aún no han sido añadidos al carrito.
¿Desea añadir todos estos productos al carrito?",
title,
function(ok){
$.alerts.okButton = ' Aceptar '
if (ok){
$.alerts._show(title, 'Añadiendo productos al carrito...
');
var errors = [];
products = products.closest('tr'); // recuperar las filas enteras
addMassiveProducts(products, errors, title, url);
} else {
window.location = url;
}
}
);
return false;
}
});
}
function setRowLoading(row){
var el = $('a.add_cart',row);
$('#tooltip').hide();
$('img',el).remove();
el.append('');
}
function addMassiveProducts(products, errors, title, url){
if (!products.length){
$.alerts._hide();
if (errors.length){
jAlert(errors.join("
"),title);
} else {
jAlert("Se han añadido los productos al carrito.",title, function(){
//window.location = url;
});
}
$('#num_products').load('/checkout/num_items');
minicartLoad();
loadCart();
return;
}
var row = products.first();
idp = row.attr('rel');
q = parseInt($('input.count', row).val());
setRowLoading(row);
$.get('/checkout/action/add/'+idp, { 'q' : q }, function(res){
if (res){ errors.push(res); }
$('input.count', row).val('');
addMassiveProducts(products.slice(1), errors, title, url);
});
}
function loadCart(){
var rel = parseInt($(this).closest('tr').attr('rel'));
var amounts = {};
$('table.list tr',lista).each(function(){
var $r = $(this).attr('rel');
if ($r){ amounts[$r] = $('input.count',this).val(); }
});
lista.load('/producto/'+prod_slug+'?ajax=1', function(){
// restaurar cantidades
$.each(amounts, function(i,val){
if (i != rel){
$('table.list tr[rel="'+i+'"] input.count',lista).val(val);
} else {
$('table.list tr[rel="'+i+'"] input.count',lista).focus();
}
});
initList();
});
}
loadCart();
//initInfo();
}