
var compareTray=null;if(document.getElementById){compareTray=document.getElementById("tray");}
var TRAY_DELAY_MS=3000;var FIRST_TRAY_DELAY_MS=5500;var trayLength;var trayOpen=false;var phoneCounter=0;var fncXmlFileUrlPrefix="/fncxml/parameter/";var fncXmlRequestFailed=false;var fncParameterXmlFound=false;var fncDataXmlFileUrl="";var trayIsAlreadyHiddenNoOpenAgain=false;function initializeTrayPics(){var values=getCookieValues(trayCookieName);var productTempArray=parseProducts(values);}
function clearTray(){clearComparisonButtons();eraseCookie(trayCookieName);if(getCookieValues("comparisonSelectionsCookie")!=null){createCookie("comparisonSelectionsCookie","",-1);}
document.getElementById("ppCompareTrayLinksId").className="ppCompareTrayLinks";var div=document.getElementById("ppCompareTrayItemHolderR6");div.innerHTML="";updateTraySize(0);initializeTrayPics();}
function clearComparisonButtons(){var trayCookieValue=getCookieValues(trayCookieName);if(trayCookieValue!=null){var trayCookieArray=trayCookieValue.split(",");for(var i=0;i<trayCookieArray.length;i++){var productId=trayCookieArray[i];buttonCtrl("comparebtn"+productId,"open","false");}}}
var divId="";function removeComparinsonPhone(removeId){trayIsFullCrtl();phoneCounter--;var elemid="trprd"+removeId;var trayPhoneElement=document.getElementById(elemid);if(trayPhoneElement!==null){trayPhoneElement.style.display="none";}
var values=getCookieValues(trayCookieName);var productArray=parseProducts(values);var phoneCount=productArray.length;var productsTBS=new Array();if(productArray.length>1){for(var a=0;a<productArray.length;a++){if(removeId==productArray[a]){divId="trprd"+removeId;updateTraySize(trayLength-1);phoneCount--;buttonCtrl("comparebtn"+removeId,"open","false");}else{productsTBS.push(productArray[a]);}}
eraseCookie(trayCookieName);createCookie(trayCookieName,productsTBS,1);if(!trayOpen){ppTrayHandler();if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}else{if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}
if(isIE){setTimeout("timeOutTray()",500);}}else{document.getElementById("ppCompareTrayLinksId").className="ppCompareTrayLinks";var div=document.getElementById("ppCompareTrayItemHolderR6");div.innerHTML="";eraseCookie(trayCookieName);updateTraySize(0);phoneCount=0;}
buttonCtrl("comparebtn"+removeId,"open","false");try{if(popupOpen){buttonCtrl("comparebtn_pu"+removeId,"open","false");}}catch(err){}
if(!trayOpen){ppTrayHandler();if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}else{if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}}
function timeOutTray(){if(document.getElementById){if(document.getElementById(divId)){document.getElementById(divId).style.display="none";}}else if(document.all){if(document.all[divId]){document.all[divId].style.display="none";}}}
function updateTraySize(newLength){this.trayLength=newLength;var lengthElement="";lengthElement=document.getElementById("fnc.msg.currentTrayPhones");if(lengthElement!=null&&lengthElement!="")
{lengthElement.innerHTML="";lengthElement.innerHTML=newLength;if(newLength<=comparableItemsMax){if(document.getElementById){if(newLength>0){}else{}}else{if(document.all){}}}else{}}else{if(document.getElementById){}else{if(document.all){}}}}
function trayIsFullCrtl(){if(document.getElementById("trayIsFullNotification").style.display=="block"){document.getElementById("trayIsFullNotification").style.display="none";}}
function parseProducts(values){var productArray=new Array();if(values!=null&&values.length>0){while(values.indexOf(",")>0){var breakpoint=values.indexOf(",");productArray.push(values.substring(0,breakpoint));values=values.slice(breakpoint+1);}
productArray.push(values);}
return productArray;}
function addComparisonPhone(productId){log.debug("productId: "+productId);var trayCookie=getCookieValues(trayCookieName);var phoneCount=0;var trayIsFull=false;if(trayCookie==null){createCookie(trayCookieName,productId,1);if(!trayOpen){ppTrayHandler();if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}else{addTrayProduct(productId);if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}
updateTraySize(1);phoneCount=1;}else{var productArray=parseProducts(trayCookie);var addProduct=true;phoneCount=productArray.length;if(productArray.length<comparableItemsMax){trayIsFullCrtl();for(var a=0;a<productArray.length;a++){if(productId==productArray[a]){addProduct=false;}}
if(addProduct){var temp=trayCookie+","+productId;createCookie(trayCookieName,temp,1);if(!trayOpen){ppTrayHandler();if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",TRAY_DELAY_MS);timeOutAlreadyCalled=true;}}else{addTrayProduct(productId,a);updateTraySize(trayLength+1);}
phoneCount++;}}else{trayIsFull=true;}}
if(!trayIsFull){}else{var parentLr=document.getElementById("ppCompareTrayItemHolderR6");var alertLayer=document.getElementById("trayIsFullNotification");var leftPlc=parseInt(parentLr.offsetLeft)+8;var heightPlc=parseInt(parentLr.offsetTop)+22;var rightPlc=parseInt(parentLr.offsetRight)+8;if(document.fnc_languageDirectionRTL){alertLayer.style.right=rightPlc+"px";}else{alertLayer.style.left=leftPlc+"px";}
alertLayer.style.top=heightPlc+"px";alertLayer.style.display="block";}}
function showCompareTray(){if(!trayOpen){try{if(document.all&&document.getElementById("buyNowModule"))hideElement();}catch(Exception){}
this.trayOpen=true;populateTray();}}
function populateTray(){log.debug("populateTray");var values=parseProducts(getCookieValues(trayCookieName));if(values!=null){if(values.length>0){}
updateTraySize(values.length);addTrayProduct(null);}else{updateTraySize(0);}}
function hideCompareTray(){try{if(document.all&&document.getElementById("buyNowModule"))showRegBnElement();}catch(Exception){}
var div=document.getElementById("ppCompareTrayItemHolderR6");var alertLayer=document.getElementById("trayIsFullNotification");alertLayer.style.display="none";div.innerHTML="";trayIsAlreadyHiddenNoOpenAgain=true;document.getElementById("trayProductIdentifier").style.display="none";ppTrayHandler();this.trayOpen=false;timeOutAlreadyCalled=false;}
function addTrayProduct(value){log.debug("addTrayProduct value: "+value);if(fncXmlRequestFailed==false){if(fncParameterXmlFound==false){var url=fncXmlFileUrlPrefix+cmsSiteId+"/"+fncLocalizationId+"/parameter.xml";var req=newXMLHttpRequest();var handlerFunction;handlerFunction=getReadyStateHandlerWithFallback(req,processParameterXml,processXmlFallback,value);req.onreadystatechange=handlerFunction;req.open("GET",url,true);req.send(null);}else{addTrayProductUsingXmlFile(value);}}else{addTrayProductUsingServlet(value);}}
function addTrayProductUsingServlet(value){log.debug("addTrayProductUsingServlet - value: "+value);if(value!=null){fetchProductUsingServlet(value);}else{var values=parseProducts(getCookieValues(trayCookieName));for(var i=0;i<values.length;i++){fetchProductUsingServlet(values[i]);}}}
function addTrayProductUsingXmlFile(value){log.debug("addTrayProductUsingXmlFile - value: "+value);if(value!=null){fetchProductUsingXmlFile(value);}else{var values=parseProducts(getCookieValues(trayCookieName));for(var i=0;i<values.length;i++){fetchProductUsingXmlFile(values[i]);}}}
function fetchProductUsingServlet(value){log.debug("fetchProductUsingServlet - value: "+value);if(value!=null){var req=newXMLHttpRequest();var handlerFunction;handlerFunction=getReadyStateHandler(req,updateTrayProduct);var url="/fncAjax.do/tray";var requestString="?id="+value;url=url+requestString;req.onreadystatechange=handlerFunction;req.open("GET",url,true);req.send(null);}}
function writeTrayProduct(id,name,teaserImgUrl,productPageUrl,hbxProdName){var elemid="trprd"+id;var trayPhoneElement=document.getElementById(elemid);if(trayPhoneElement==null){if((id!=""&&id!="null"&&id!=null)&&(name!=""&&name!="null"&&name!=null)&&(teaserImgUrl!=""&&teaserImgUrl!="null"&&teaserImgUrl!=null)&&(productPageUrl!=""&&productPageUrl!="null"&&productPageUrl!=null)){phoneCounter++;var invidualPhoneDiv=document.getElementById("ppCompareTrayItemHolderR6");if(invidualPhoneDiv.style.display=="none"){invidualPhoneDiv.style.display="block";}
var htmlToDiv=invidualPhoneDiv.innerHTML;var hbxName=hbxProdName.replace(/ /g,"+");htmlToDiv+="<div class=\"ppTrhbx\" id=\""+hbxProdName+"\"></div>";htmlToDiv+="<div id=\"trprd"+id+"\" class=\"ppCompareTraySingleItem\">";htmlToDiv+=" <img onmouseout=\"closeProductIdentifier();\" onmouseover=\"showProductIdentifier(this, event);\" src=\""+teaserImgUrl+"\" class=\"ppCompareTrayPhoneImg\" alt=\""+name+"\" title=\""+name+"\" /><br />";htmlToDiv+="  <a onclick=\"if(isDefined('useHbx') && useHbx){_hbLink('tray+remove+product+"+hbxName+"','');}\" href=\"javascript:removeComparinsonPhone('"+id+"');\">"+removeStr+"</a>";htmlToDiv+="</div>";invidualPhoneDiv.innerHTML=htmlToDiv;}}
else{log.debug("Product already exists!");}}
function updateTrayProduct(resultsXML){log.debug("updateTrayProduct");var results=resultsXML.getElementsByTagName("results")[0];var product=results.getElementsByTagName("item")[0];var id=product.getAttribute("id");var name=product.getElementsByTagName("name")[0].firstChild.nodeValue;var teaserImgUrl=product.getElementsByTagName("trayImageUrl")[0].firstChild.nodeValue;var productPageUrl=product.getElementsByTagName("productPageUrl")[0].firstChild.nodeValue;var hbxProdName=product.getElementsByTagName("hbxName")[0].firstChild.nodeValue;writeTrayProduct(id,name,teaserImgUrl,productPageUrl,hbxProdName);}
function updateTrayProductXml(resultsXML,value){log.debug("updateTrayProductXml - value: "+value);if(resultsXML!=null)
{var allProducts=resultsXML.getElementsByTagName("product");var foundFromXml=false;for(var i=0;i<allProducts.length;i++)
{var id=allProducts[i].getAttribute("id");if(value==id)
{var name=allProducts[i].getElementsByTagName("productName")[0].firstChild.nodeValue;var teaserImgUrl=allProducts[i].getElementsByTagName("productImageUrl")[0].firstChild.nodeValue;var productPageUrl=allProducts[i].getElementsByTagName("productPageUrl")[0].firstChild.nodeValue;var hbxProdName=allProducts[i].getElementsByTagName("hbxName")[0].firstChild.nodeValue;writeTrayProduct(id,name,teaserImgUrl,productPageUrl,hbxProdName);foundFromXml=true;break;}}
if(value!=null&&!foundFromXml){foundFromXml=true;addTrayProductUsingServlet(value);}}else{fncXmlRequestFailed=true;addTrayProductUsingServlet(value);}}
function processParameterXml(resultsXML,value){fncDataXmlFileUrl="";if(resultsXML!=null)
{fncParameterXmlFound=true;var results=resultsXML.getElementsByTagName('parameters').item(0);fncDataXmlFileUrl=getXmlValueOf(results,'phone_dropdown_url');addTrayProductUsingXmlFile(value);}
else
{fncXmlRequestFailed=true;addTrayProductUsingServlet(value);}}
function fetchProductUsingXmlFile(value)
{log.debug("fetchProductUsingXmlFile - value: "+value);if(value!=null){var req=newXMLHttpRequest();var handlerFunction=getReadyStateHandlerWithFallback(req,updateTrayProductXml,processXmlFallback,value);req.onreadystatechange=handlerFunction;req.open("GET",fncDataXmlFileUrl,true);req.send(null);}}
function processXmlFallback(value){log.debug("processXmlFallback - value: "+value+" fncXmlRequestFailed: "+fncXmlRequestFailed);addTrayProductUsingServlet(value);fncXmlRequestFailed=true;}
var timeOutAlreadyCalled=false;function ppTrayHandler(){if(document.getElementById){var parElement=document.getElementById("ppproductNavi");var trayElement=document.getElementById("tray");var placementValue;if(parseInt(parElement.offsetTop)==0){placementValue=27;}else{placementValue=parseInt(parElement.offsetTop)+27;}
if(isIE&&userAgent.indexOf("MSIE 6")>-1){placementValue=parseInt(placementValue)-4;}
trayElement.style.top=placementValue+"px";if(trayElement.style.display==""){trayElement.style.display="none";}
if(trayElement.style.display=="none"&&!trayIsAlreadyHiddenNoOpenAgain){trayElement.style.display="block";document.getElementById("ppCompareTrayLink").className="compareLinkActive";}else{trayElement.style.display="none";document.getElementById("ppCompareTrayLink").className="compareLink";try{if(document.all&&document.getElementById("buyNowModule"))showRegBnElement();}catch(Exception){}}
if(!timeOutAlreadyCalled){setTimeout("hideCompareTray()",FIRST_TRAY_DELAY_MS);timeOutAlreadyCalled=true;}
showCompareTray();trayIsAlreadyHiddenNoOpenAgain=false;}}
var storageObject="";function showProductIdentifier(activeObj,event){var doChange=false;if(storageObject==""){storageObject=activeObj;doChange=true;}
if(storageObject.getAttribute("alt")!=activeObj.getAttribute("alt")){storageObject=activeObj;doChange=true;}
if(doChange){if(document.getElementById("trayProductIdentifier")){var parElement=activeObj.parentNode;var currentName=activeObj.getAttribute("alt");var offsetLeftValue=parseInt(parElement.offsetLeft);var parTop="";var parLeft="";var isRTL=false;var bodyE=document.getElementsByTagName("body");if(bodyE[0].getAttribute("dir")=="rtl"){isRTL=true;}
if(isRTL&&userAgent.indexOf("MSIE 7.0")>-1||userAgent.indexOf("MSIE 6.0")>-1){parTop=parseInt(parElement.offsetTop)+22;parLeft=parseInt(parElement.offsetLeft)+2;}else{parTop=parseInt(activeObj.offsetTop)-22;parLeft=parseInt(activeObj.offsetLeft)-2;}
document.getElementById("trayProductIdentifier").innerHTML=currentName;document.getElementById("trayProductIdentifier").style.top=parTop+"px";document.getElementById("trayProductIdentifier").style.left=parLeft+"px";document.getElementById("trayProductIdentifier").style.display="block";}}}
function closeProductIdentifier(){document.getElementById("trayProductIdentifier").style.display="none";storageObject="";}