﻿function catalogViewInstance(){this.callBack=null;this.context="0";this.prevContext="0";this.startFrom=0;this.returnLimit=16;this.sortBy="NAME";this.sortDirection="ASCENDING";this.serviceUrl="";this.flag=-1;this.images=new imageQueueInstance();}
var __catalogView=new catalogViewInstance();function catalogViewClear(){var ctrlView=document.getElementById("ctrlview");while(ctrlView.firstChild)
ctrlView.removeChild(ctrlView.firstChild);}
function catalogViewDraw(){catalogViewClear();imageQueueZero(__catalogView.images);var ctrlView=document.getElementById("ctrlview");if(__catalogInfo.parentCategoryId!=-1)
{var center=document.createElement("center");var a=document.createElement("a");a.href="javascript:__catalogView.startFrom=0;catalogViewLoad("+__catalogInfo.parentCategoryId+","+__catalogView.flag+");";var img=new Image();img.src="/images/backbutton.gif";img.border=0;a.appendChild(img);center.appendChild(a);center.appendChild(document.createElement("br"));center.appendChild(document.createElement("br"));ctrlView.appendChild(center);}
var table=document.createElement("table");table.className="products";var tBody=document.createElement("tbody");var tr=document.createElement("tr");var tc=1;var i=0;var len=__catalogInfo.categories.length;for(i=0;i<len;i++)
{var td=document.createElement("td");{var a=document.createElement("a");a.href=browserNextStaticUrl();var img=new Image();img.id="cpic"+i;img.border=0;img.onclick=catalogCatalogViewLoadCallback(__catalogInfo.categories[i]);a.appendChild(img);a.appendChild(document.createElement("br"));td.appendChild(a);}
{var a=document.createElement("a");a.href="javascript:catalogViewLoad("+__catalogInfo.categories[i]["id"]+","+__catalogView.flag+");";var aText=document.createTextNode(__catalogInfo.categories[i]["desc"]);a.appendChild(aText);td.appendChild(a);}
tr.appendChild(td);if(tc++==4)
{tBody.appendChild(tr);tr=document.createElement("tr");tc=1;}}
tBody.appendChild(tr);len=__catalogInfo.products.length;for(i=0;i<len;i++)
{var td=document.createElement("td");{var a=document.createElement("a");a.href="/Product.aspx?t=1&i="+__catalogInfo.products[i]["id"];var img=new Image();img.id="ppic"+i;img.border=0;if(__catalogInfo.products[i]["largeicon"]!=undefined)
{var imgvar=new Image();imgvar.id="PreloadedImg"+i;imgvar.src=__catalogInfo.products[i]["largeicon"];}
a.appendChild(img);a.appendChild(document.createElement("br"));td.appendChild(a);}
{var a=document.createElement("a");a.href="/Product.aspx?t=1&i="+__catalogInfo.products[i]["id"];var aText=document.createTextNode(__catalogInfo.products[i]["name"]);a.appendChild(aText);a.appendChild(document.createElement("br"));td.appendChild(a);}
var span=document.createElement("span");span.className="msclabel";span.appendChild(document.createTextNode("$"+__catalogInfo.products[i]["price"]+" / "));td.appendChild(span);var span=document.createElement("span");span.className="mscclublabel";span.appendChild(document.createTextNode("$"+__catalogInfo.products[i]["cprice"]));td.appendChild(span);if(__catalogInfo.products[i]["IsOnPromotion"]=="True")
{td.appendChild(document.createElement("br"));var span=document.createElement("span");span.className="msconspecial";span.appendChild(document.createTextNode("On Special"));td.appendChild(span);}
tr.appendChild(td);if(tc++==4)
{tBody.appendChild(tr);tr=document.createElement("tr");tc=1;}
imageQueueAdd(__catalogView.images,"ppic"+i,__catalogInfo.products[i]["largeicon"],GETROOTURL()+((__catalogInfo.products[i]["img"])?__catalogInfo.products[i]["img"]:"/images/noiproduct.gif"));}
if(len==0)
{var td=document.createElement("td");td.style.textAlign="left";td.innerHTML="<br/>Sorry, we couldn't find what you were looking for. This doesn't mean we don't have it!<br /> <br />To find the product you're looking for, try the following.<br /><br />1. If you were searching by passion, necessity, theme or brand, try searching by keyword instead.<br /><br /> 2. Try a different keyword. For example, instead of 'dogs', try 'dog', or try 'kids' instead of 'children'.<br /><br />3. Use the 'AND' and 'OR' feature. For example, if you want to find a design collection that includes beagles, try typing 'dog AND beagle', which will find only products that have keywords of both dog and beagle. If you get no results, try 'dog OR beagle', which will find results with the keyword dog or beagle.<br /><br />4. Contact us! You can send us an e-mail at search@annthegran.com, and let one of our product experts find it for you.<br/><br/>";tr.appendChild(td);}
tBody.appendChild(tr);table.appendChild(tBody);ctrlView.appendChild(table);table=document.createElement("table");table.className="productbuttons";tBody=document.createElement("tbody");tr=document.createElement("tr");var td=document.createElement("td");td.style.width="10%";var input=document.createElement("input");input.type="button";input.name="butPrev";input.value="<<";input.onclick=function(){catalogViewStartFromSet(__catalogView.startFrom-__catalogView.returnLimit);return true;};input.style.width="50px";if(__catalogView.startFrom==0)
input.disabled=true;else
input.disabled=false;td.appendChild(input);tr.appendChild(td);td=document.createElement("td");td.style.width="80%";center=document.createElement("center");td.appendChild(center);len=parseInt(__catalogInfo.totalCount/__catalogView.returnLimit);if(parseInt(__catalogInfo.totalCount%__catalogView.returnLimit)!=0)
len++;for(i=0;i<len;i++)
{var txt=document.createTextNode(i+1);if(parseInt(__catalogView.startFrom/__catalogView.returnLimit)==i)
{center.appendChild(txt);}
else
{var a=document.createElement("a");a.href="javascript:catalogViewStartFromSet("+(i*__catalogView.returnLimit)+");";a.appendChild(txt);center.appendChild(a);}
center.appendChild(document.createTextNode(" "));}
tr.appendChild(td);td=document.createElement("td");td.style.width="10%";input=document.createElement("input");input.type="button";input.name="butNext";input.value=">>";input.onclick=function(){catalogViewStartFromSet(__catalogView.startFrom+__catalogView.returnLimit);return true;};input.style.width="50px";if(parseInt(__catalogView.startFrom/__catalogView.returnLimit)>=len)
input.disabled=true;else
input.disabled=false;if(parseInt(__catalogInfo.totalCount-__catalogView.startFrom)<=__catalogView.returnLimit)
input.disabled=true;td.appendChild(input);tr.appendChild(td);tBody.appendChild(tr);table.appendChild(tBody);ctrlView.appendChild(table);imageQueueExecute(__catalogView.images,1,0);}
function catalogProductViewCreateCallback(product){return function(){productViewCreate(product["id"],PRODUCTVIEWCALLERSHOP());window.location="/Product.aspx?t=1&i="+__productView.catalogId;return true;}}
function catalogCatalogViewLoadCallback(category){return function(){catalogViewLoad(category["id"],__catalogView.flag);return true;}}
function catalogViewDrawLoading(){catalogViewClear();var ctrlView=document.getElementById("ctrlview");var center=document.createElement("center");var table=document.createElement("table");var tBody=document.createElement("tbody");table.width="100%";table.cellPadding=0;table.cellSpacing=0;var tr=document.createElement("tr");var td=document.createElement("td");td.style.width="100%";td.style.height="200px";td.style.textAlign="center";td.style.verticalAlign="middle";td.className="loading";var img=new Image();img.src="/images/loading.gif";td.appendChild(img);td.appendChild(document.createElement("br"));td.appendChild(document.createTextNode("Loading..."));tr.appendChild(td);tBody.appendChild(tr);table.appendChild(tBody);center.appendChild(table);ctrlView.appendChild(center);}
function catalogViewInit(callerContext){if(__preSelectInfo.categoryId==-1)
catalogViewDraw();else
catalogViewLoad(__preSelectInfo.categoryId,__catalogView.flag);}
function catalogViewLoad(context,flag){__catalogView.flag=flag;__catalogView.context=context;__catalogView.callBack=catalogViewInit;catalogViewDrawLoading();if(__catalogView.prevContext!=context)
{__catalogView.prevContext=context;__catalogView.startFrom=0;}
if(flag==2)
catalogInfoGet(__catalogView.serviceUrl,context,__catalogView.startFrom,__catalogView.returnLimit,"PRICE","ASCENDING",__catalogView);else if(flag==3)
catalogInfoGet(__catalogView.serviceUrl,context,__catalogView.startFrom,__catalogView.returnLimit,"PRICE","DESCENDING",__catalogView);else if(flag==0)
catalogInfoGet(__catalogView.serviceUrl,context,__catalogView.startFrom,__catalogView.returnLimit,"NAME","ASCENDING",__catalogView);else if(flag==1)
catalogInfoGet(__catalogView.serviceUrl,context,__catalogView.startFrom,__catalogView.returnLimit,"NAME","DESCENDING",__catalogView);else if(flag==-1)
catalogInfoGet(__catalogView.serviceUrl,context,__catalogView.startFrom,__catalogView.returnLimit,__catalogView.sortBy,__catalogView.sortDirection,__catalogView);}
function catalogViewStartFromSet(startFrom){__catalogView.startFrom=startFrom;catalogViewLoad(__catalogView.context,__catalogView.flag);}
function catalogViewServiceUrlSet(serviceUrl){__catalogView.serviceUrl=serviceUrl;}