/*
 * Copyright (C) 2008-2010 APN, LLC. All rights reserved
 */
var ATBLogger=window.opener.ATB.Logger;var webListener=window.opener.ATB.Widgets.widgetWebProgressListener;function ATB_onLoadPopup(g){var b=document.getElementById("asktb-popup-iframe");var d=window.arguments[0];var c=window.arguments[1];var h=window.arguments[2];var f=window.arguments[3];var i=window.arguments[4];var a=window.arguments[5];webListener.containerWindow=g;b.addProgressListener(webListener,Components.interfaces.nsIWebProgress.NOTIFY_STATE_ALL);b.contentDocument.body.innerHTML="<div style='font-family: sans-serif;'>Loading...</div>";try{var j=window.opener.ATB.Cache;if(j&&d&&j.get(d)&&j.getValue(d)!=""){ATBLogger.debug("ATBPopupHTMLWindow: Widget exists in cache - pulling from cache and showing widget...");b.contentDocument.body.innerHTML=j.getValue(d)}else{ATBLogger.info("ATBPopupHTMLWindow: Widget does NOT exist in cache - forwarding to the live url: ",c);b.setAttribute("src",c)}window.setTimeout(ATB_removeNoscriptTags,2000);if(f=="widget"){document.getElementById("asktb-popup-footerBox").setAttribute("style","display:none;");document.getElementById("asktb-popup-headerBox").setAttribute("style","display:none;")}if(i=="no"){b.setAttribute("style","overflow:hidden;")}if(a=="no"){document.getElementById("asktb-popup-footerBox").setAttribute("style","display:none;")}if(document.getElementById("asktb-popup-title")!=null&&f=="popup"){document.getElementById("asktb-popup-title").setAttribute("value",window.arguments[2]);b.setAttribute("height",(window.innerHeight-45))}else{b.setAttribute("height",window.innerHeight)}b.setAttribute("width",window.innerWidth);window.setTimeout(ATB_removeNoscriptTags,2000)}catch(e){ATBLogger.error("ATBPopupHTMLWindow: Error loading widget popup: ",e);b.contentDocument.body.innerHTML="<div style='font-family: Arial, Sans Serif; font-size: 12px; padding: 12px;'>Widget unavailable.<br/>Please try again later.</div>"}if(f=="popup"){window.setTimeout(function(){window.resizeBy(8,8)},1)}else{window.setTimeout(function(){window.resizeBy(-6,-5)},1)}window.focus();return}function ATB_onUnloadPopup(){document.getElementById("asktb-popup-iframe").removeProgressListener(webListener)}function ATB_removeNoscriptTags(){var a=document.getElementById("asktb-popup-iframe");var b=a.contentDocument.getElementsByTagName("noscript");for(n=0;n<b.length;n++){b[n].parentNode.removeChild(b[n])}b=a.contentDocument.getElementsByTagName("NOSCRIPT");for(n=0;n<b.length;n++){b[n].parentNode.removeChild(b[n])}b=a.contentDocument.getElementsByTagName("NoScript");for(n=0;n<b.length;n++){b[n].parentNode.removeChild(b[n])}b=a.contentDocument.getElementsByTagName("Noscript");for(n=0;n<b.length;n++){b[n].parentNode.removeChild(b[n])}return}function ATB_userCloseWindow(){ATBLogger.debug("User closing the popup window :",window.name);if(window.opener&&window.opener.ATB.Widgets){try{delete window.opener.ATB.Widgets.getAllPopupWindows()[window.name]}catch(a){ATBLogger.debug("Could not delete the window:",window.name,"from the popupWindows map, Error:",a)}}window.close()}function handleLinkClick(l){var d=l.target.hasAttribute("href")?l.target:l.target.parentNode;if(d.hasAttribute("href")){try{ATBLogger.debug("ATBPopupHTMLWindow: Checking to see if the link click is a toolbar command..");var k=/http:\/\/.*?\.ask\.com\/customize\/command.*/;var b=d.getAttribute("href");if(k.test(b)){ATBLogger.debug("ATBPopupHTMLWindow: Toolbar command encountered. Url: ",b);var j=b.split("?")[1];var c=j.split("&");var a={};for(var g=0;g<c.length;g++){var m=c[g].split("=");a[m[0].toLowerCase()]=m[1]}var e=a.cmd;var f=unescape(a.url);ATBLogger.debug("ATBPopupHTMLWindow: Original Url: ",f);if(e=="redir"){window.close();ATBLogger.debug("ATBPopupHTMLWindow: Redirecting to Original Url...");window.opener.content.document.location=f}}}catch(h){ATBLogger.error("ATBPopupHTMLWindow: OnClick: Error handling toolbar command url: ",h)}}}function ATB_handleResize(a){var e=window.arguments[2];document.getElementById("asktb-popup-title").setAttribute("value",window.arguments[2]);var d=(document.getElementById("asktb-popup-title").boxObject.width+50-window.innerWidth);var c=0;if(d>0){c=Math.floor(d/7)}if(c){for(var b=0;b<c;b++){e=e.replace(/.$/,"")}document.getElementById("asktb-popup-title").setAttribute("value",e)}return};