$(document).ready(function(){
$("#basketItemsWrap li:first").hide();
$("#slidingTopContent").hide();
$(document).on("click","#slidingTopTrigger", function(event) {
$("#slidingTopContent").slideToggle("slow", function(){
if ($("#slidingTopContent").is(":visible")) {
$("#slidingTopFooterLeft").html(' Ocultar Carrito');
} else {
$("#slidingTopFooterLeft").html(' Mostrar Cesta');
}
});
});
$(".productPriceWrapRight a").click(function() {
var productIDValSplitter = (this.id).split("_");
var productIDVal = productIDValSplitter[1];
var varcampo = $("#prodqty_" + productIDVal).val();
var vartalla = $("#fldtalla_" + productIDVal).val();
if (vartalla == null || vartalla.length == 0) { vartalla = 0};
var varcolor = $("#fldcolor_" + productIDVal).val();
if (varcolor == null || varcolor.length == 0) { varcolor = 0};
if ($("#slidingTopContent").is(":visible")) {
$("#notificationsLoader").html('');
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: { productID: productIDVal, action: "addToBasket", qty: varcampo, talla: vartalla, color: varcolor},
success: function(theResponse) {
if( $("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).length > 0){
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 0 }, 500);
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).before(theResponse).remove();
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 0 }, 500);
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 1 }, 500);
$("#notificationsLoader").empty();
} else {
$("#basketItemsWrap li:first").before(theResponse);
$("#basketItemsWrap li:first").hide();
$("#basketItemsWrap li:first").show("slow");
$("#notificationsLoader").empty();
}
}
});
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: {action: "getcart"},
success: function(theResponse) {
$("#notifullinvoice").html(theResponse);
}
});
} else {
$("#slidingTopContent").slideToggle("slow", function(){
$("#slidingTopFooterLeft").html(' Ocultar Carrito');
$("#notificationsLoader").html('');
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: { productID: productIDVal, action: "addToBasket", qty: varcampo, talla: vartalla, color: varcolor},
success: function(theResponse) {
if( $("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).length > 0){
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 0 }, 500);
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).before(theResponse).remove();
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 0 }, 500);
$("#productID_" + productIDVal + "_" + vartalla + "_" + varcolor).animate({ opacity: 1 }, 500);
$("#notificationsLoader").empty();
} else {
$("#basketItemsWrap li:first").before(theResponse);
$("#basketItemsWrap li:first").hide();
$("#basketItemsWrap li:first").show("slow");
$("#notificationsLoader").empty();
}
}
});
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: {action: "getcart"},
success: function(theResponse) {
$("#notifullinvoice").html(theResponse);
}
});
$("#slidingTopTrigger").fadeTo(5000, 1, function(){
$("#slidingTopContent").slideToggle("slow", function(){
$("#slidingTopFooterLeft").html(' Mostrar Cesta');
});
});
});
}
});
$(document).on("click","#basketItemsWrap li img", function(event) {
var productIDValSplitter = (this.id).split("_");
var productIDVal = productIDValSplitter[1];
var tallaval = productIDValSplitter[2];
var colorval = productIDValSplitter[3];
$("#notificationsLoader").html('');
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: { productID: productIDVal, action: "deleteFromBasket", talla: tallaval, color: colorval},
success: function(theResponse) {
$("#productID_" + productIDVal + "_" + tallaval + "_" + colorval).hide("slow", function() {
$(this).remove();
});
$("#notificationsLoader").empty();
}
});
$.ajax({
type: "POST",
url: "/eshopproc.asp",
data: {action: "getcart"},
success: function(theResponse) {
$("#notifullinvoice").html(theResponse);
}
});
});
$(document).on("change",'select[id*="fldcolor"]', function(event) {
var title="";
var total=0;
var colorsplit=(this.id).split("_");
var colorVal = colorsplit[1];
var sttalla= $("#fldtalla_" + colorVal + " option:selected").attr("title");
if (sttalla==undefined) {sttalla='0'};
sttalla = sttalla.replace('.','');
var stprice= $("#spvp_" + colorVal).attr("title");
title = $("#fldcolor_" + colorVal + " option:selected").attr("title");
title = title.replace('.','');
stprice = stprice.replace('.','');
var total=parseFloat(title.replace(',','.'))+parseFloat(sttalla.replace(',','.') )+parseFloat(stprice.replace(',','.') );
var result = total.toFixed(2);
result = result.replace('.',',');
$("#spvp_" + colorVal + " .shpprice").html(formatea(result));
});
$(document).on("change",'select[id*="fldtalla"]', function(event) {
var title="";
var total=0;
var tallasplit=(this.id).split("_");
var tallaVal = tallasplit[1];
var stcolor= $("#fldcolor_" + tallaVal + " option:selected").attr("title");
if (stcolor==undefined) {stcolor='0'};
stcolor = stcolor.replace('.','');
var stprice= $("#spvp_" + tallaVal).attr("title");
title = $("#fldtalla_" + tallaVal + " option:selected").attr("title");
title = title.replace('.','');
stprice = stprice.replace('.','');
var total=parseFloat(title.replace(',','.'))+parseFloat(stcolor.replace(',','.') )+parseFloat(stprice.replace(',','.') );
var result = total.toFixed(2);
result = result.replace('.',',');
$("#spvp_" + tallaVal + " .shpprice").html(formatea(result));
});
function formatea(entrada)
{
var num = entrada.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1.');
num = num.split('').reverse().join('').replace(/^[\.]/,'');
return num;
}
});