var silverlightPlugin=null,enhancedCookieName="EnhancedEncarta";function IsSilverlightInstalled(){return Silverlight.isInstalled("2.0.31005.0")}function SwitchToClassicMode(){RemoveEnhancedCookie();window.location.reload(false)}function SwitchToEnhancedMode(){if(!IsSilverlightInstalled())ShowInstallGatePage();else{SetEnhancedCookie();window.location.reload(false)}}function SilverlightAdClicked(){if(!IsSilverlightInstalled())ShowInstallGatePage();else ShowTurnOnGatePage()}function SilverlightSearch(){var queryTextBox=document.getElementById("search_encarta");if(queryTextBox!=null&&silverlightPlugin!=null){silverlightPlugin.Content.SearchM.Search(queryTextBox.value);var titleParts=document.title.split(" - ");document.title=queryTextBox.value;for(i=1;i<titleParts.length;i++)document.title+=" - "+titleParts[i]}}function InstantiateSilverlightSearchControl(){if(IsSilverlightInstalled())CreateSilverlightSearchControl();else{RemoveEnhancedCookie();window.location.reload(true)}}function CreateSilverlightSearchControl(){var parentElement=document.getElementById("silverlightPluginHost"),xapPath=MakeAbsoluteUrl("encnet/SearchSilverlightControl/Encarta_Search.xap");Silverlight.createObject(xapPath,parentElement,"silverlightSearchObject",{width:"772",height:"694",background:"white",version:"2.0",isWindowless:"true"},{onError:OnSilverlightPluginError,onLoad:OnSilverlightPluginLoaded},null,null)}function OnSilverlightPluginLoaded(plugin,context,xamlRoot){silverlightPlugin=plugin;SilverlightSearch()}function OnSilverlightPluginError(){}function ShowInstallGatePage(){var existingFrame=document.getElementById("installGateFrame");if(existingFrame!=null)document.body.removeChild(existingFrame);var existingLayer=document.getElementById("greyLayer");if(existingLayer!=null)document.body.removeChild(existingLayer);var greyLayer=CreateTransparentDiv("greyLayer");document.body.appendChild(greyLayer);var iframe=CreateCenteredIFrame("installGateFrame","encnet/Silverlight/InstallGatePage.htm",750,600);document.body.appendChild(iframe)}function InstallSilverlightButtonClicked(){SetEnhancedCookie();WaitForInstallCompletionAndReload();parent.document.location.href="http://go.microsoft.com/fwlink/?LinkID=124807"}function WaitForInstallCompletionAndReload(){try{navigator.plugins.refresh()}catch(e){}if(IsSilverlightInstalled())parent.window.location.reload(true);else setTimeout("WaitForInstallCompletionAndReload()",3000)}function ShowTurnOnGatePage(){var existingFrame=document.getElementById("turnOnGateFrame");if(existingFrame!=null)document.body.removeChild(existingFrame);var position=findPosition("silverlightAdvertisement"),iframe=CreatePositionedIFrame("turnOnGateFrame","encnet/Silverlight/TurnOnGatePage.htm",position.x+11,position.y+11,260,75);document.body.appendChild(iframe)}function TurnOnSilverlightPopupClicked(){parent.window.location.href=MakeAbsoluteUrl("encnet/refpages/search.aspx")}function NoThanksClicked(){parent.document.getElementById("installGateFrame").style.display="none";parent.document.getElementById("greyLayer").style.display="none"}function changeImage(buttonImage,imageSource){buttonImage.src=imageSource}function SetEnhancedCookie(){var date=new Date;date.setTime(date.getTime()+36500*24*60*60*1000);var expires="; expires="+date.toGMTString();document.cookie=enhancedCookieName+"=enabled"+expires+"; path=/"}function RemoveEnhancedCookie(){var date=new Date;date.setTime(date.getTime()-1*24*60*60*1000);var expires="; expires="+date.toGMTString();document.cookie=enhancedCookieName+"=enabled"+expires+"; path=/"}function MakeAbsoluteUrl(relativeSrc){return "http://"+location.host+"/"+relativeSrc}function CreateCenteredIFrame(id,relativeSource,width,height){var windowWidth=document.all?document.body.clientWidth:window.innerWidth,windowHeight=document.all?document.body.clientHeight:window.innerHeight,layerLeft=(windowWidth-width)/2,layerTop=(windowHeight-height)/2;return CreatePositionedIFrame(id,relativeSource,layerLeft,layerTop,width,height)}function CreatePositionedIFrame(id,relativeSource,left,top,width,height){var layer=document.createElement("iframe");layer.id=id;layer.src=MakeAbsoluteUrl(relativeSource);layer.style.position="absolute";layer.style.left=left;layer.style.top=top;layer.style.width=width+"px";layer.style.height=height+10+"px";layer.style.overflow="hidden";layer.style.zIndex="100001";layer.style.backgroundColor="Transparent";layer.allowTransparency="true";layer.style.border="0px";layer.frameBorder="no";return layer}function CreateTransparentDiv(id){var height=document.all?document.body.clientHeight:window.innerHeight;if(document.body.scrollHeight)height=document.body.scrollHeight;else if(document.documentElement.offsetHeight)height=document.documentElement.offsetHeight;var width=document.all?document.body.clientWidth:window.innerWidth;if(document.body.scrollWidth)width=document.body.scrollWidth;else if(document.documentElement.offsetWidth)width=document.documentElement.offsetWidth;var layer=document.createElement("div");layer.id=id;layer.style.position="absolute";layer.style.left=0;layer.style.top=0;layer.style.width=width+"px";layer.style.height=height+"px";layer.style.zIndex="100000";layer.style.backgroundImage="url('"+MakeAbsoluteUrl("encnet/Silverlight/grey.png")+"')";layer.style.backgroundRepeat="repeat";return layer}function findPosition(elementId){var x=y=0,element=document.getElementById(elementId);if(element!=null)if(element.offsetParent)do{x+=element.offsetLeft;y+=element.offsetTop}while(element=element.offsetParent);return {x:x,y:y}}