﻿// JScript File

function cartMiniInfoInstance()
{
    this.callBack = null;
    this.callerContext = null;
    this.productCount = 0;
    this.price = 0;
    this.priceClub = 0;
    this.priceRetail = 0;
    this.weightOunces = 0;
    this.products = new Array();
    return this;
}

var __cartMiniInfo = new cartMiniInfoInstance();

function cartMiniInfoComplete(postHttp, success, callerContext)
{
    cartMiniInfoZero();
    if(success)
        cartMiniInfoFill(postHttp.responseXML);
    else
        alert(postHttp.statusText + "\r\n" + postHttp.responseText);
    callerContext.callerContext.callBack(callerContext.callerContext);    
}

function cartMiniInfoZero()
{        
    __cartMiniInfo.productCount = 0;
    __cartMiniInfo.price = 0;
    __cartMiniInfo.priceClub = 0;
    __cartMiniInfo.priceRetail = 0;
    __cartMiniInfo.weightOunces = 0;

    while(__cartMiniInfo.products.length)
        __cartMiniInfo.products.pop();
}

function cartMiniInfoFill(xmlDoc)
{
    __cartMiniInfo.productCount = xmlSelectNodes(xmlDoc, "/cart/productcount")[0].nodeValue;
    __cartMiniInfo.price = xmlSelectNodes(xmlDoc, "/cart/price")[0].nodeValue;
    __cartMiniInfo.priceClub = xmlSelectNodes(xmlDoc, "/cart/priceclub")[0].nodeValue;
    __cartMiniInfo.priceRetail = xmlSelectNodes(xmlDoc, "/cart/priceretail")[0].nodeValue;        
    __cartMiniInfo.weightOunces = xmlSelectNodes(xmlDoc, "/cart/weightounces")[0].nodeValue;
    __cartMiniInfo.Discount = xmlSelectNodes(xmlDoc, "/cart/Discount")[0].nodeValue;
    __cartMiniInfo.DiscountMember = xmlSelectNodes(xmlDoc, "/cart/DiscountMember")[0].nodeValue;
    
    var products = xmlSelectNodes(xmlDoc, "/cart/products");
    var size = 0;
    for(var c = 0; c < products.length; c++)
    {
        if(products[c].tagName == "product" && products[c].childNodes)
        {
            __cartMiniInfo.products[size] = new Array();
            var childNodes = products[c].childNodes;
            for(var i = 0; i < childNodes.length; i++)
            {
                if(childNodes[i].firstChild)
                    __cartMiniInfo.products[size][childNodes[i].tagName] = childNodes[i].firstChild.nodeValue;
            }
            size++;
        }
    }
}

function cartMiniInfoProductAdd(catalogId, callerContext)
{
    __cartMiniInfo.callBack = cartMiniInfoComplete;
    __cartMiniInfo.callerContext = callerContext;
    var d = new Date();
    asyncPostUrl("/WSCartInfo.asmx/RequestCartProductAdd?__j__=" + d.getTime(), "catalogId=" + catalogId, __cartMiniInfo);
}

function cartMiniInfoProductRemove(catalogId, callerContext)
{
    __cartMiniInfo.callBack = cartMiniInfoComplete;
    __cartMiniInfo.callerContext = callerContext;
    var d = new Date();
    asyncPostUrl("/WSCartInfo.asmx/RequestCartProductRemove?__j__=" + d.getTime(), "catalogId=" + catalogId, __cartMiniInfo);
}

function cartMiniInfoGet(callerContext)
{
    __cartMiniInfo.callBack = cartMiniInfoComplete;
    __cartMiniInfo.callerContext = callerContext;
    var d = new Date();
    asyncPostUrl("/WSCartInfo.asmx/RequestCartInfo?__j__=" + d.getTime(), "", __cartMiniInfo);
}
