﻿function catalogInfoInstance()
{this.callBack=null;this.callerContext=null;this.categoryID=0;this.parentCategoryId=-1;this.totalCount=0;this.categories=new Array();this.products=new Array();}
var __catalogInfo=new catalogInfoInstance();function catalogInfoComplete(postHttp,success,callerContext)
{catalogInfoZero();if(success)
catalogInfoFill(postHttp.responseXML);else
alert(postHttp.statusText+" "+postHttp.responseText);callerContext.callerContext.callBack(callerContext.callerContext);}
function catalogInfoZero()
{while(__catalogInfo.categories.length)
__catalogInfo.categories.pop();while(__catalogInfo.products.length)
__catalogInfo.products.pop();}
function catalogInfoFill(xmlDoc)
{__catalogInfo.parentCategoryId=xmlSelectNodes(xmlDoc,"/cache/parentcategoryid")[0].nodeValue;__catalogInfo.totalCount=xmlSelectNodes(xmlDoc,"/cache/totalcount")[0].nodeValue;var categories=xmlSelectNodes(xmlDoc,"/cache/categories");var size=0;var c=0;for(c=0;c<categories.length;c++)
{if(categories[c].tagName=="category"&&categories[c].childNodes)
{__catalogInfo.categories[size]=new Array();var childNodes=categories[c].childNodes;for(var i=0;i<childNodes.length;i++)
{if(childNodes[i].firstChild)
__catalogInfo.categories[size][childNodes[i].tagName]=childNodes[i].firstChild.nodeValue;}
size++;}}
var products=xmlSelectNodes(xmlDoc,"/cache/products");size=0;for(c=0;c<products.length;c++)
{if(products[c].tagName=="product"&&products[c].childNodes)
{__catalogInfo.products[size]=new Array();var childNodes=products[c].childNodes;for(var i=0;i<childNodes.length;i++)
{if(childNodes[i].firstChild)
__catalogInfo.products[size][childNodes[i].tagName]=childNodes[i].firstChild.nodeValue;}
size++;}}}
function catalogInfoGet(serviceUrl,context,startFrom,returnLimit,sortBy,sortDirection,callerContext)
{__catalogInfo.callBack=catalogInfoComplete;__catalogInfo.callerContext=callerContext;var data="context="+((context.length==0)?".":context)+"&"+"startFrom="+startFrom+"&"+"returnLimit="+returnLimit+"&"+"sortBy="+sortBy+"&"+"sortDirection="+sortDirection;var d=new Date();asyncPostUrl("/"+serviceUrl+"/RequestCatalogInfo?__j__="+d.getTime(),data,__catalogInfo);}