
var bVisible=false;var bProcessingMessageVisible=false;var iProcessingDots=3;var bAddListToCart=false;var bMiniCartBubble=true;var ProcessingMessageReturned=false;var ProcessingMessageHTML="";var ProcessingMessagePlain=false;function getElementById(id){if(document.getElementById)
return document.getElementById(id);if(document.all)
return document.all[id];}
function getPageCoords(elementId){var coords={x:0,y:0}
var element;element=getElementById(elementId);while(element){coords.x+=element.offsetLeft;coords.y+=element.offsetTop;element=element.offsetParent;}
return coords;}
function displayMiniCart(url){if(bVisible)
return;txtMiniCart="MiniCart";eMiniCart=getElementById(txtMiniCart);if(!eMiniCart)
eMiniCart=addMiniCartDiv(txtMiniCart,url);if(!eMiniCart)
return;postMiniCartHTML(url);}
function addListToCart(FormName,url,sProcessingURL){url+="&ButtonAddListToCart.x=1";addItemsToCart(FormName,url,sProcessingURL);}
function addItemsToCart(FormName,url,sProcessingURL){var i,sItemCode,eAddToCart,elem2,elemList;var aItemCodes=new Array();var aItemQuantities=new Array();var aUOM=new Array();var aHTMLFormRowNumber=new Array();var sHTMLFormRow;oCartBox=getElementById("CartBox");sMiniCartDisplay=oCartBox.getAttribute("MiniCartDisplay");if(sMiniCartDisplay!="TRUE")
bMiniCartBubble=false;if(bMiniCartBubble)
scroll(0,0);displayProcessingMessage(sProcessingURL);oForm=document.forms[FormName];if((FormName=="frmItemSearchResults")||(FormName=="frmPastPurchaseList")||(FormName=="frmPastPurchaseDetail")||(FormName=="frmMyAccountResultArea")||(FormName=="frmGoTogethers")||(FormName=="frmSubstitutes")){if(FormName=="frmPastPurchaseDetail")
iItemsToSearch=1;else
iItemsToSearch=getElementById("txtISRLines").value;for(i=0;i<=(iItemsToSearch-1);i++){if(oForm.elements["txtQuantity"+i]&&trimAll(oForm.elements["txtQuantity"+i].value)!=''){aItemCodes.push(oForm.elements["txtItemID"+i].value);aItemQuantities.push(oForm.elements["txtQuantity"+i].value);if(oForm.elements["selUOM"+i]&&trimAll(oForm.elements["selUOM"+i].value)!='')
aUOM.push(oForm.elements["selUOM"+i].value);}}}
else if(FormName=="frmMyAccountResultAreaOQD"){iItemsToSearch=getElementById("txtISRLines").value;for(i=0;i<=(iItemsToSearch-1);i++){if(oForm.elements["AJAXtxtQuantity"+i]&&trimAll(oForm.elements["AJAXtxtQuantity"+i].value)!=''){aItemCodes.push(oForm.elements["AJAXtxtItemID"+i].value);aItemQuantities.push(oForm.elements["AJAXtxtQuantity"+i].value);if(oForm.elements["selUOM"+i]&&trimAll(oForm.elements["selUOM"+i].value)!='')
aUOM.push(oForm.elements["selUOM"+i].value);}}}
else if(FormName=="Item_Detail_Content"){if(oForm.elements["txtQuantity0"]&&trimAll(oForm.elements["txtQuantity0"].value)!=''){aItemCodes.push(oForm.elements["ItemCode"].value);aItemQuantities.push(oForm.elements["txtQuantity0"].value);}}
else if(FormName.indexOf("Quick_Order")>-1){iItemsToSearch=getElementById("txtQOPLines").value;for(i=0;i<=(iItemsToSearch-1);i++){if(oForm.elements["txtQuantity"+i]&&trimAll(oForm.elements["txtQuantity"+i].value)!=''){aItemCodes.push(oForm.elements["txtItemID"+i].value);aItemQuantities.push(oForm.elements["txtQuantity"+i].value);}}}
else if(url.indexOf("ButtonAddListToCart")>-1){var sATCUID="";lid=getElementById("lid").value;oAllElements=document.getElementsByTagName("*");if(oAllElements==null)
oAllElements=document.all;for(j=0;j<=oAllElements.length-1;j++){oElem=oAllElements[j];sElementName=oElem.getAttribute("name");sElementValue=oElem.getAttribute("value");if(sElementName&&sElementValue){if(sElementName.indexOf("HTMLFormRowNumber")>-1){aHTMLFormRowNumber.push("&"+sElementName+"="+sElementValue);oElem2=getElementById("txtShoppingListQuantity"+sElementValue);if(oElem2)
aItemQuantities.push("&"+oElem2.name+"="+oElem2.value);oElem2=getElementById("selUOM"+sElementValue);if(oElem2)
aUOM.push("&"+oElem2.name+"="+oElem2.value);}}}}
else if(FormName.indexOf("My_Account_Shopping_List_Detail_Content")>-1){var sATCUID="";lid=getElementById("lid").value;oATCUID=document.getElementsByName("atcuid");for(i=0;i<=oATCUID.length-1;i++){if(oATCUID[i].checked){sATCUID+=oATCUID[i].value+",";oAllElements=document.getElementsByTagName("*");if(oAllElements==null)
oAllElements=document.all;for(j=0;j<=oAllElements.length-1;j++){oElem=oAllElements[j];sElementName=oElem.getAttribute("name");sElementValue=oElem.getAttribute("value");if(sElementName&&sElementValue){if((sElementName.indexOf("HTMLFormRowNumber")>-1)&&(sElementValue==oATCUID[i].value)){aHTMLFormRowNumber.push("&"+sElementName+"="+sElementValue);}}}
oElem=getElementById("txtShoppingListQuantity"+oATCUID[i].value);if(oElem)
aItemQuantities.push("&"+oElem.name+"="+oElem.value);oElem=getElementById("selUOM"+oATCUID[i].value);if(oElem)
aUOM.push("&"+oElem.name+"="+oElem.value);}}
if((sATCUID)&&(sATCUID.length>0)&&(sATCUID.charAt(sATCUID.length-1)==","))
sATCUID=sATCUID.substring(0,sATCUID.length-1);}
txtMiniCart="MiniCart";eMiniCart=getElementById(txtMiniCart);if(!eMiniCart)
eMiniCart=addMiniCartDiv(txtMiniCart,url);if(!eMiniCart)
return;if(FormName.indexOf("My_Account_Shopping_List_Detail_Content")>-1)
postMiniCartHTMLFromShoppingList(url,"addItemsToCartFromShoppingList",lid,sATCUID,aHTMLFormRowNumber,aItemQuantities,aUOM);else
postMiniCartHTML(url,"addItemsToCart",aItemCodes,aItemQuantities,aUOM);}
function displayProcessingMessage(sProcessingURL)
{if(bProcessingMessageVisible)
return;iProcessingDots=0;eCartBox=getElementById("CartBox");if((eCartBox&&bMiniCartBubble)||(!sProcessingURL)){ProcessingMessagePlain=true;ProcessingMessageReturned=true;ProcessingMessageHTML="<HTML><BODY><TABLE ID='MiniShoppingCartView_MainTable' WIDTH='150'><TR ID='MiniShoppingCartView_HeaderRow'><TD><TABLE WIDTH='100%'><TR><TD ALIGN='center'>Processing<DIV ID=ProcessingMessageDots>.</DIV></TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>";}
if(!ProcessingMessageReturned){getProcessingMessageHTML(sProcessingURL);return;}
divProcessingMessage=document.createElement("div");divProcessingMessage.id='DivProcessingMessage';divProcessingMessage.name='DivProcessingMessage';divProcessingMessage.style.visibility='hidden';divProcessingMessage.className="MiniCart";divProcessingMessage.style.position="absolute";divProcessingMessage.style.zIndex="110";if(ProcessingMessagePlain){divProcessingMessage.style.width="150";divProcessingMessage.style.height="20";}
divProcessingMessage.innerHTML=ProcessingMessageHTML;windowWidth=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;windowHeight=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;eCartBox=getElementById("CartBox");if(eCartBox&&bMiniCartBubble){coordsCartBox=getPageCoords(eCartBox.id);if((parseInt(windowWidth)/2)<coordsCartBox.x+(parseInt(eCartBox.offsetWidth)/2)){divProcessingMessage.style.right=parseInt(windowWidth)-(coordsCartBox.x+parseInt(eCartBox.offsetWidth));}}
else{bMiniCartBubble=false;divProcessingMessage.className="ProcessingMessage";eCartBox=document.createElement("div");eCartBox.id="CartBox";eCartBox.name="CartBox";eCartBox.className="MiniCart";eCartBox.style.overflow="auto";eCartBox.style.position="absolute";eCartBox.style.zIndex="110";eCartBox.style.visibility="visible";var sWidth=0;if(divProcessingMessage.innerHTML.indexOf("MiniShoppingCartView_MainTable")>-1){sContent=divProcessingMessage.innerHTML.split("MiniShoppingCartView_MainTable")[1];if(sContent.indexOf("width=")>-1)
sWidth=sContent.substring((sContent.indexOf("width=")+6),sContent.indexOf(">")).split(" ")[0];}
eCartBox.style.top=f_scrollTop()+(windowHeight/3);eCartBox.style.left=(windowWidth/2)-75;eCartBox.style.width="0";eCartBox.style.height="0";document.body.appendChild(eCartBox);divProcessingMessage.style.top=eCartBox.style.top;divProcessingMessage.style.left=eCartBox.style.left;}
eCartBox.parentNode.appendChild(divProcessingMessage);viewProcessingMessage();}
function f_scrollTop(){return f_filterResults(window.pageYOffset?window.pageYOffset:0,document.documentElement?document.documentElement.scrollTop:0,document.body?document.body.scrollTop:0);}
function f_filterResults(n_win,n_docel,n_body){var n_result=n_win?n_win:0;if(n_docel&&(!n_result||(n_result>n_docel)))
n_result=n_docel;return n_body&&(!n_result||(n_result>n_body))?n_body:n_result;}
function addMiniCartDiv(txtMiniCart,url)
{var divMiniCart,eCartBox,windowWidth;var bMouseOut=false;eCartBox=getElementById("CartBox");if(eCartBox==null)
return null;if(eCartBox.onmouseout)
bMouseOut=true;divMiniCart=document.createElement("div");divMiniCart.id=txtMiniCart;divMiniCart.name=txtMiniCart;divMiniCart.className=txtMiniCart;if(bMiniCartBubble)
divMiniCart.style.overflow="auto";divMiniCart.style.position="absolute";divMiniCart.style.zIndex="110";divMiniCart.style.visibility="hidden";if(bMouseOut)
divMiniCart.onmouseout=hideMiniCart;divMiniCart.onblur=hideMiniCart;divMiniCart.onclick=processOnClick;coordsCartBox=getPageCoords(eCartBox.id);windowWidth=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;if((parseInt(windowWidth)/2)<coordsCartBox.x+(parseInt(eCartBox.offsetWidth)/2)){divMiniCart.style.right=parseInt(windowWidth)-(coordsCartBox.x+parseInt(eCartBox.offsetWidth));}
eCartBox.parentNode.appendChild(divMiniCart);return divMiniCart;}
function getMiniCartHTML(url){url+="&random="+Math.random();if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.open('GET',url,true);xmlHttpRequest.send(null);}
else if(window.ActiveXObject){xmlHttpRequest=new ActiveXObject('Microsoft.XMLHTTP');if(xmlHttpRequest){xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.open('GET',url,true);xmlHttpRequest.send();}}}
function getProcessingMessageHTML(sProcessingMessageURL){if(window.XMLHttpRequest){xmlHttpRequest2=new XMLHttpRequest();xmlHttpRequest2.onreadystatechange=DisplayProcessingMessage;xmlHttpRequest2.open('GET',sProcessingMessageURL,true);xmlHttpRequest2.send(null);}
else if(window.ActiveXObject){xmlHttpRequest2=new ActiveXObject('Microsoft.XMLHTTP');if(xmlHttpRequest){xmlHttpRequest2.onreadystatechange=DisplayProcessingMessage;xmlHttpRequest2.open('GET',sProcessingMessageURL,true);xmlHttpRequest2.send();}}}
function DisplayProcessingMessage(){if(xmlHttpRequest2!=null){if(xmlHttpRequest2.readyState==4){ProcessingMessageReturned=true;ProcessingMessageHTML=xmlHttpRequest2.responseText;displayProcessingMessage("Success");}}}
function postMiniCartHTML(url,action,aItemCodes,aItemQuantities,aUOM){var i,params;url+="&random="+Math.random()
if(action)
url+="&action="+action;if(bMiniCartBubble)
url+="&UsingMiniCartBubble=True";else
url+="&UsingMiniCartBubble=False";if(aItemCodes){params="AJAXTotalItemsToAdd="+aItemCodes.length;for(i=0;i<aItemCodes.length;i++){params+="&AJAXItemCode"+i+"="+aItemCodes[i];}
for(i=0;i<aItemQuantities.length;i++){params+="&AJAXItemQuantity"+i+"="+aItemQuantities[i];}
for(i=0;i<aUOM.length;i++){params+="&selUOM"+i+"="+aUOM[i];}}
if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();xmlHttpRequest.open('POST',url,true);xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlHttpRequest.send(params);}
else if(window.ActiveXObject){xmlHttpRequest=new ActiveXObject('Microsoft.XMLHTTP');if(xmlHttpRequest){xmlHttpRequest.open('POST',url,true);xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlHttpRequest.send(params);}}}
function postMiniCartHTMLFromShoppingList(url,action,lid,sATCUID,aHTMLFormRowNumber,aItemQuantities,aUOM){var i,params="";if(url.indexOf("ButtonAddListToCart")==-1)
url+="&ButtonAddCheckedToCart.x=1";url+="&random="+Math.random()+"&MiniCart=True";if(action)
url+="&action="+action;if(lid)
url+="&lid="+lid;if(sATCUID)
url+="&atcuid="+sATCUID;if(bMiniCartBubble)
url+="&UsingMiniCartBubble=True";else
url+="&UsingMiniCartBubble=False";if(aHTMLFormRowNumber){for(i=0;i<aHTMLFormRowNumber.length;i++){params+=aHTMLFormRowNumber[i];}
for(i=0;i<aItemQuantities.length;i++){params+=aItemQuantities[i];}
for(i=0;i<aUOM.length;i++){params+=aUOM[i];}}
if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();xmlHttpRequest.open('POST',url,true);xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlHttpRequest.send(params);}
else if(window.ActiveXObject){xmlHttpRequest=new ActiveXObject('Microsoft.XMLHTTP');if(xmlHttpRequest){xmlHttpRequest.open('POST',url,true);xmlHttpRequest.onreadystatechange=processReqChange;xmlHttpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlHttpRequest.send(params);}}}
function processReqChange(){var iAJAXId,oddResults,oFirst,tmpDD,oInputBox;if(xmlHttpRequest!=null){if(xmlHttpRequest.readyState==4){if(xmlHttpRequest.status==200){eMiniCart=getElementById("MiniCart");if(!eMiniCart)
return;eMiniCart.innerHTML=xmlHttpRequest.responseText;eItemCount=getElementById("ItemCount");if(eItemCount){sCountType=eItemCount.getAttribute("CountType");if(sCountType=="item")
sInnerText=eMiniCart.innerHTML.substring((eMiniCart.innerHTML.indexOf("CartItemCount")+20),(eMiniCart.innerHTML.indexOf("NameCartItemCount")-18));else if(sCountType=="line")
sInnerText=eMiniCart.innerHTML.substring((eMiniCart.innerHTML.indexOf("CartLineCount")+20),(eMiniCart.innerHTML.indexOf("NameCartLineCount")-18));if((sInnerText.length>0)&&(IsNumeric(sInnerText)))
eItemCount.innerText=sInnerText;}
windowWidth=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;windowHeight=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;if(bMiniCartBubble){coordsMiniCart=getPageCoords(eMiniCart.id);AvailableHeight=windowHeight-coordsMiniCart.y;if(AvailableHeight<parseInt(eMiniCart.offsetHeight))
eMiniCart.style.height=(AvailableHeight-50)+"px";}
else{var sWidth=0;if(eMiniCart.innerHTML.indexOf("MiniShoppingCartView_MainTable")>-1){sContent=eMiniCart.innerHTML.split("MiniShoppingCartView_MainTable")[1];if(sContent.indexOf("width=")>-1)
sWidth=sContent.substring((sContent.indexOf("width=")+6),sContent.indexOf(">")).split(" ")[0];}
eMiniCart.style.top=f_scrollTop()+(windowHeight/3);eMiniCart.style.left=(windowWidth/2)-75;}
if(bProcessingMessageVisible)
hideProcessingMessage();if(!bVisible)
viewMiniCart();}}}}
function hideProcessingMessage(){if(!bProcessingMessageVisible)
return;eProcessingMessage=getElementById("DivProcessingMessage");if(!eProcessingMessage)
return;eProcessingMessage.style.visibility='hidden';bProcessingMessageVisible=false;}
function processOnClick(){var eMiniCart,eCartBox,oEvent,iClientX,iClientY,coords;if(!bVisible)
return;eMiniCartClose=getElementById("MiniShoppingCartView_close");if(eMiniCartClose){oEvent=window.event;if(document.documentElement&&document.documentElement.scrollTop)
root=document.documentElement;else if(document.body)
root=document.body;iClientX=oEvent.clientX+root.scrollLeft;iClientY=oEvent.clientY+root.scrollTop;coordsMiniCartClose=getPageCoords(eMiniCartClose.id);if((iClientX>=coordsMiniCartClose.x)&&(iClientX<=(coordsMiniCartClose.x+parseInt(eMiniCartClose.offsetWidth)))){if((iClientY>=coordsMiniCartClose.y)&&(iClientY<=(coordsMiniCartClose.y+parseInt(eMiniCartClose.offsetHeight)))){bVisible=false;fadeOutMiniCart("MiniCart");return;}}}}
function hideMiniCart(){var eMiniCart,eCartBox,oEvent,iClientX,iClientY,coords;if(!bVisible)
return;eMiniCart=getElementById("MiniCart");if(!eMiniCart)
return;eCartBox=getElementById("CartBox");if(!eCartBox)
return null;oEvent=window.event;if(document.documentElement&&document.documentElement.scrollTop)
root=document.documentElement;else if(document.body)
root=document.body;iClientX=oEvent.clientX+root.scrollLeft;iClientY=oEvent.clientY+root.scrollTop;coordsCartBox=getPageCoords(eCartBox.id);coordsMiniCart=getPageCoords(eMiniCart.id);CartBoxHeight=coordsMiniCart.y-coordsCartBox.y;if((iClientX<coordsCartBox.x)&&(iClientY<coordsMiniCart.y)){bVisible=false;fadeOutMiniCart("MiniCart");return;}
if((iClientX>=coordsMiniCart.x)&&(iClientX<=(coordsMiniCart.x+parseInt(eMiniCart.offsetWidth)))){if((iClientY>=(coordsCartBox.y))&&(iClientY<=(coordsCartBox.y+CartBoxHeight+parseInt(eMiniCart.offsetHeight))))
return;}
bVisible=false;fadeOutMiniCart("MiniCart");}
function setOpacity(elemName,value){getElementById(elemName).style.opacity=value/10;getElementById(elemName).style.filter='alpha(opacity='+value*10+')';}
function fadeInMiniCart(elemName){for(var i=0;i<=100;i++)
setTimeout('setOpacity("'+elemName+'",'+(i/10)+')',3*i);}
function fadeOutMiniCart(elemName){for(var i=0;i<=100;i++){setTimeout('setOpacity("'+elemName+'",'+(10-i/10)+')',3*i);}
setTimeout('closeElem("'+elemName+'")',300);}
function closeElem(elemName){getElementById(elemName).style.visibility='hidden';}
function viewMiniCart(){bVisible=true;setOpacity("MiniCart",0);getElementById("MiniCart").style.visibility='visible';getElementById("MiniCart").focus();fadeInMiniCart("MiniCart");}
function viewProcessingMessage(){bProcessingMessageVisible=true;setOpacity("DivProcessingMessage",0);getElementById("DivProcessingMessage").style.visibility='visible';fadeInMiniCart("DivProcessingMessage");displayProcessingDots();}
function tkanimate(){var i;var dots;dots=".";for(i=0;i<iProcessingDotCount;i++){if(iProcessingDotCount>=10){dots=".";iProcessingDotCount=0;}
else{dots+=".";}}
oProcessingDots.firstChild.nodeValue=dots;iProcessingDotCount++;setTimeout("tkanimate()",500);}
function displayProcessingDots(){oProcessingDots=getElementById("ProcessingMessageDots");iProcessingDotCount=0;tkanimate();}