
var compareTray=null;if(document.getElementById){compareTray=document.getElementById("tray");}
var TRAY_DELAY_MS=3000;var trayLength;var trayOpen=false;var phoneCounter=0;var usedUrl="/res/fnc/pics/small_phone_icon_red_1b.gif";var unusedUrl="/res/fnc/pics/small_phone_icon_gray_1b.gif";var fncXmlFileUrlPrefix="/fncxml/parameter/";var fncXmlRequestFailed=false;var fncParameterXmlFound=false;var fncDataXmlFileUrl="";function initializeTrayPics(){var values=getCookieValues(trayCookieName);var productTempArray=parseProducts(values);updateTrayStatusPics(productTempArray.length);}
function clearTray(){clearComparisonButtons();eraseCookie(trayCookieName);if(getCookieValues("comparisonSelectionsCookie")!=null){createCookie("comparisonSelectionsCookie","",-1);}
var div=document.getElementById("trayProductList_1");div.innerHTML="";updateTraySize(0);initializeTrayPics();checkTrayHeight();}
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){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)
{showCompareTray();setTimeout("hideCompareTray()",TRAY_DELAY_MS);}else
{setTimeout("hideCompareTray()",TRAY_DELAY_MS);}
if(isIE)
{setTimeout("timeOutTray()",500);}}else{var div=document.getElementById("trayProductList_1");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){showCompareTray();setTimeout("hideCompareTray()",TRAY_DELAY_MS);}else{setTimeout("hideCompareTray()",TRAY_DELAY_MS);}
updateTrayStatusPics(phoneCount);checkTrayHeight();}
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)
{document.getElementById("trayIsFullNotification").style.display="none";document.getElementById("trayCounterNotification").style.display="block";}else
{if(document.all)
{document.all["trayIsFullNotification"].style.display="none";document.all["trayCounterNotification"].style.display="block";}}}}else{if(document.getElementById)
{document.getElementById("trayCounterNotification").style.display="none";}else
{if(document.all)
{document.all["trayCounterNotification"].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;if(trayCookie==null){createCookie(trayCookieName,productId,1);if(!trayOpen){showCompareTray();setTimeout("hideCompareTray()",TRAY_DELAY_MS);}else{addTrayProduct(productId);setTimeout("hideCompareTray()",TRAY_DELAY_MS);}
updateTraySize(1);phoneCount=1;}else{var productArray=parseProducts(trayCookie);var addProduct=true;phoneCount=productArray.length;if(productArray.length<comparableItemsMax){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){showCompareTray();setTimeout("hideCompareTray()",TRAY_DELAY_MS);}else{addTrayProduct(productId,a);updateTraySize(trayLength+1);}
phoneCount++;}}}
updateTrayStatusPics(phoneCount);checkTrayHeight();}
function updateTrayStatusPics(count){var e=document.getElementById("traycount_images");if(!e){return;}
var images=e.getElementsByTagName("img");var trayIconUrl="";for(var i=0;i<images.length;i++)
{trayIconUrl=(i<count?usedUrl:unusedUrl);if(document.fnc_languageDirectionRTL)
{images[(images.length-1)-i].setAttribute("src",trayIconUrl);}else
{images[i].setAttribute("src",trayIconUrl);}}}
function showCompareTray(){adjustTrayPosition();if(!trayOpen){this.trayOpen=true;populateTray();compareTray.style.display="block";adjustTrayHeight();checkTrayHeight();}}
function populateTray(){log.debug("populateTray");var values=parseProducts(getCookieValues(trayCookieName));if(values!=null)
{updateTraySize(values.length);addTrayProduct(null);}
else
{updateTraySize(0);}}
function hideCompareTray(){var div=document.getElementById("trayProductList_1");div.innerHTML="";compareTray.style.display="none";this.trayOpen=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("trayProductList_1");if(invidualPhoneDiv.style.display=="none"){invidualPhoneDiv.style.display="block";}
var htmlToDiv=invidualPhoneDiv.innerHTML;var hbxName=hbxProdName.replace(/ /g,"+");htmlToDiv+="<div class=\"trhbx div_fnc\" id=\""+hbxProdName+"\"></div>";htmlToDiv+="<div id=\"trprd"+id+"\" class=\"trayphone div_fnc\">";htmlToDiv+="<img src=\""+teaserImgUrl+"\" alt=\""+name+"\" title=\""+name+"\" /><br />"+"<a onclick=\"if(isDefined('useHbx') && useHbx){_hbLink('tray+product+title+"+hbxName+"','');}\" href=\""+productPageUrl+"\">"+name+"</a><br/>"+"<div id=\"comparebtn_close\" class=\"fnc_tray_compare_button_remove div_fnc\"><a onclick=\"if(isDefined('useHbx') && useHbx){_hbLink('tray+remove+product+"+hbxName+"','');}\" href=\"javascript:removeComparinsonPhone('"+id+"');\"><span class=\"comparetext\">"+removeStr+"</span></a></div></div>";invidualPhoneDiv.innerHTML=htmlToDiv;}}
else{log.debug("Product allready 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 checkTrayHeight()
{setTimeout("adjustTrayHeight()",100);}
function adjustTrayHeight()
{var trayContentElement=null;var heightSpacerElement=null;var aDivFound=false;var bDivFound=false;var allTrayDivs=compareTray.getElementsByTagName("div");for(var x=0;x<allTrayDivs.length;x++)
{if(allTrayDivs[x].className=="traycontent div_fnc")
{trayContentElement=allTrayDivs[x];aDivFound=true;}
heightSpacerElement=document.getElementById("heightSpacer");if(heightSpacerElement!=null)
{bDivFound=true;}
if(aDivFound==true&&bDivFound==true)
{break;}}
if(aDivFound==true&&bDivFound==true)
{heightSpacerElement.style.display="none";var trayContentHeight=trayContentElement.offsetHeight;if(!(trayContentHeight%2))
{log.debug("add spacer");heightSpacerElement.style.display="block";}
else
{log.debug("hide spacer");heightSpacerElement.style.display="none";}}
else{log.error("Tray elements not found!");}}
function adjustTrayPosition()
{if(document.fnc_thisIsProductPage){var compareButton=document.getElementById("compareButton");if(compareTray===null)
{compareTray=document.getElementById("tray");}
if(document.fnc_languageDirectionRTL)
{compareButton.style.position="absolute";compareButton.style.right="0px";compareButton.style.marginRight="-40px";if(isIE)
{compareTray.style.position="absolute";compareTray.style.right="0px";compareTray.style.marginRight="-552px";}
if(isMoz)
{compareTray.style.position="absolute";compareTray.style.left="0px";compareTray.style.marginLeft="16px";}}
else
{compareButton.style.marginRight="-6px";compareTray.style.position="absolute";compareTray.style.right=" 0px";compareTray.style.marginRight="-6px";compareTray.style.marginTop="23px";}}
else
{if(isMoz)
{compareTray.style.marginTop="-2px";}}}
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;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;}
