﻿// JScript File

function cartMiniListInfoInstance()
{
    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 __cartMiniListInfo = new cartMiniListInfoInstance();

function cartMiniListInfoComplete(postHttp, success, callerContext)
{
    cartMiniListInfoZero();
 
    if(success)
        cartMiniListInfoFill(postHttp.responseXML);
    else
        alert(postHttp.statusText + "\r\n" + postHttp.responseText);
    
    callerContext.callerContext.callBack(callerContext.callerContext);    
}

function cartMiniListInfoZero()
{        
    __cartMiniListInfo.productCount = 0;
    __cartMiniListInfo.price = 0;
    __cartMiniListInfo.priceClub = 0;
    __cartMiniListInfo.priceRetail = 0;
    __cartMiniListInfo.weightOunces = 0;

    while(__cartMiniListInfo.products.length)
        __cartMiniListInfo.products.pop();
}

function cartMiniListInfoFill(xmlDoc)
{
    __cartMiniListInfo.productCount = xmlSelectNodes(xmlDoc, "/cart/productcount")[0].nodeValue;
    __cartMiniListInfo.price = xmlSelectNodes(xmlDoc, "/cart/price")[0].nodeValue;
    __cartMiniListInfo.priceClub = xmlSelectNodes(xmlDoc, "/cart/priceclub")[0].nodeValue;
    __cartMiniListInfo.priceRetail = xmlSelectNodes(xmlDoc, "/cart/priceretail")[0].nodeValue;        
    __cartMiniListInfo.weightOunces = xmlSelectNodes(xmlDoc, "/cart/weightounces")[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)
        {
            __cartMiniListInfo.products[size] = new Array();
            var childNodes = products[c].childNodes;
            for(var i = 0; i < childNodes.length; i++)
            {
                if(childNodes[i].firstChild)
                    __cartMiniListInfo.products[size][childNodes[i].tagName] = childNodes[i].firstChild.nodeValue;
            }
            size++;
        }
    }
}

function cartMiniListInfoGet(callerContext)
{   
    __cartMiniListInfo.callBack = cartMiniListInfoComplete;
    __cartMiniListInfo.callerContext = callerContext;
    var d = new Date();
    asyncPostUrl("/WSCartInfo.asmx/RequestCartInfo?__j__=" + d.getTime(), "", __cartMiniListInfo);
}
