/* Persistant Cart (universal cart) Javascript */
/* --------------------------------------------- */
// Commands
// persistantCartCommands[0] = "showProduct" action
// persistantCartCommands[1] = "addProduct" action
// persistantCartCommands[2] = "addEnsemble" action
// persistantCartCommands[3] = "remove" action
// persistantCartCommands[4] = "addProductWishlist" action
// persistantCartCommands[5] = "addAllProductsWishlist" action
var persistantCartCommands = new Array(4);
persistantCartCommands[0] = '/checkout/universal_cart.jsp';
persistantCartCommands[1] = '/checkout/add_item_pc.cmd';
persistantCartCommands[2] = '/checkout/add_items_pc.cmd';
persistantCartCommands[3] = '/checkout/delete_item_in_cart.cmd';
persistantCartCommands[4] = '/user/add_wishlist_item_to_basket_pc.cmd';
persistantCartCommands[5] = '/user/add_all_wishlist_items_to_basket_pc.cmd';
var ucartActive = 0;
var requestURL = "";
var persistantCartContainerId = "#widget-ucart";
var persistantCartCloseButClass = ".widget-ucart-close-but";
var hideTimeOuts= new Array();
var ucartTimer;
var ucartLoadingHTML = '
';
function errorCheck(action,params) {
var dataContainer = '';
$("body").append(dataContainer);
if( (action == "show") || (action == "showFromQuickview") ) {
requestURL = persistantCartCommands[0];
} else if(action == "addProduct") {
requestURL = persistantCartCommands[1];
} else if(action == "addEnsemble") {
requestURL = persistantCartCommands[2];
} else if(action == "remove") {
requestURL = persistantCartCommands[3];
} else if(action == "addProductWishlist") {
requestURL = persistantCartCommands[4];
} else if(action == "addAllProductsWishlist") {
requestURL = persistantCartCommands[5];
} else {
alert("missing action");
}
$.ajax({
type: "POST",
url: requestURL,
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
$("body").append('' + action + '');
$("body").append('' + params + '');
$(dataContainer).append(data);
return true;
},
error: function() {
return false;
}
});
};
/* Function(s) to Show the Basket Layer */
function showBasket(action,params) {
if(typeof ucartTimer != "undefined")
{ clearTimeout(ucartTimer); }
ucartActive = 1;
showloading();
/*if( exp.utils.isIE6() )
{ exp.utils.iframeFix.add(persistantCartContainerId); }
*/
requestURL = requestURL;
params = "ts=" + timestamp() + "&action=" + action + "&" + params;
$.ajax({
type: "POST",
url: '/checkout/universal_cart.jsp',
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
hideloading();
$(persistantCartContainerId).append(data);
$(persistantCartContainerId).show();
return true;
},
error: function() {
hideBasket();
return false;
}
});
};
function showloading() {
$(persistantCartContainerId).remove();
//load, position, show new cart
$("body").append(ucartLoadingHTML);
positionPersistantCart();
$(persistantCartContainerId).show();
};
function hideloading() {
$(persistantCartContainerId + " *").remove();
$(persistantCartContainerId).html("");
};
function addToCart() {
resetErrorFields();
params = "productName=" + $("input[@name=productName]").val() +
"&productId=" + $("input[@name=productId]").val() +
"&categoryId=" + $("input[@name=categoryId]").val() +
"&parentCategoryId=" + $("input[@name=parentCategoryId]").val() +
"&subCategoryId=" + $("input[@name=subCategoryId]").val() +
"&shipTo=" + $("select[@name=shipTo]").val() +
"&shipToZip=" + $("input[@name=shipToZip]").val() +
"&newShipTo=" + $("input[@name=newShipTo]").val() +
"&newShipToZip=" + $("input[@name=newShipToZip]").val()+
"&useNewShiptoView=" + $("input[@name=useNewShiptoView]").val();
//see if this is an update.
if( $("input[@name=itemGUID]").size() > 0 )
{ params = params + "&itemGUID=" + $("input[@name=itemGUID]").val() + "&isUpdate=1"; }
// iterate through products in the ensemble for variant id
$(".the-variant-ids").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
// iterate through products for qty
$(".the-variant-qtys").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
params = params + "&productCount=" + $(".the-variant-ids").length;
errorCheck('addProduct',params);
};
function wishListAddToCart(params) {
showBasket('addProductWishlist',params);
showBasket('show', '');
};
function wishListAddAllToCart(params) {
showBasket('addAllProductsWishlist',params);
showBasket('show', '');
};
function addEnsembleToCart(type) {
resetErrorFields();
params = "ensembleId=" + $("input[@name=ensembleId]").val()+
"&categoryId=0&parentCategoryId=0&subCategoryId=0"+
"&shipTo=" + $("select[@name=shipTo]").val() +
"&shipToZip=" + $("input[@name=shipToZip]").val() +
"&newShipTo=" + $("input[@name=newShipTo]").val() +
"&newShipToZip=" + $("input[@name=newShipToZip]").val()+
"&useNewShiptoView=" + $("input[@name=useNewShiptoView]").val();
// iterate through products for productIds
// iterate through products in the ensemble for variant id
$(".the-variant-ids").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
// iterate through products for qty
$(".the-variant-qtys").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
params = params + "&productCount=" + $(".the-variant-ids").length;
errorCheck('addEnsemble',params);
};
function updateHeader(amt) {
if(amt == 1)
{ $("#widget-ucart-item-count").text(amt); }
else
{ $("#widget-ucart-item-count").text(amt); }
};
function errorAppend(area,msg) {
$(area).html(msg.replace(/&/g, "&").replace(/</g,
"<").replace(/>/g, ">").replace(/'/g, "'"));
$(area).show();
};
function resetErrorFields() {
$(".important").hide();
$(".important").html("");
};
function messageAppend(area,msg) {
$(area).html(msg);
$(area).show();
};
function resetMessageFields() {
$(".glo-tex-info").hide();
};
function timestamp() { return new Date().getTime(); }
//Edit this function if need to do something special on basket close.
function hideBasket() {
if(typeof ucartTimer != "undefined")
{ clearTimeout(ucartTimer); }
ucartActive = 0;
$(persistantCartContainerId).hide();
$(persistantCartContainerId).remove();
//if not on basket page reset the header link
if ( $(".che-bas-header-left").size() == 0 )
{
shoppingBagBut = $("#widget-header-active-link").eq(0);
$(shoppingBagBut).attr("id","")
$(shoppingBagBut).mouseout();
$(shoppingBagBut).parent().parent().removeClass("glo-header-link-span-active");
}
};
//edit this function to update the setup
function setupPersistentCartButtons() {
// draw focus near this
//window.location = "#";
$(persistantCartCloseButClass).unbind("click").click(function() {
hideBasket();
});
/*$("#widget-ucart-but-checkout").widgetButton({ cssButton: 1, cssOn: "glo-but-css-on2", cssHover: "glo-but-css-hover2", cssOff: "glo-but-css-off2" });*/
$(persistantCartCloseButClass).attr("href","javascript:void(0)");
/* setup the timer */
ucartTimer = setTimeout(function() { hideBasket(); }, 4000);
$("#widget-ucart").unbind("mousemove").mousemove(function() {
if(typeof ucartTimer != "undefined")
{ clearTimeout(ucartTimer); }
});
$("#widget-ucart").hover(
function() {},
function() {
if(typeof ucartTimer != "undefined")
{ ucartTimer = setTimeout(function() { hideBasket(); }, 750); }
}
);
};
//edit this function to position cart.
function positionPersistantCart() {
var pos = lib.utils.getPosition("#pe_wrapper")[0];
var ucartXPos = (pos[0] + $("#pe_wrapper").width() - $("#widget-ucart").width());
var ucartYPos = (pos[1] + 97);
$(persistantCartContainerId).css("top", ucartYPos + "px").css("left", ucartXPos + "px");
};
/* ---------------------------------------- */