var g_userName;var g_machinePassword;var g_privateKey;var g_address;var g_status;var g_url;var g_standalone=false;var g_TimeoutDelay=1;var g_AvatarPath="http://app.buddytv.com:81/buddytv/avatars/";function getXmlNodeInnerText(node){if(null==node){return"";}if(typeof node.textContent!="undefined"){return node.textContent;}else{if(typeof node.innerText!="undefined"){return node.innerText;}else{if(typeof node.text!="undefined"){return node.text;}else{switch(node.nodeType){case 3:case 4:return node.nodeValue;break;case 1:case 11:var innerText="";for(var i=0;i<node.childNodes.length;i++){innerText+=getInnerText(node.childNodes[i]);}return innerText;break;default:return"";}}}}}var pendingFunctions=new Array();var pendingApplets=new Array();function WaitForLoad(func,applet){BusyCursor();var index=pendingFunctions.length;pendingFunctions[index]=func;pendingApplets[index]=applet;WaitForLoadCallback(index);}function loadCompleted(applet){if(null==applet){alert("null applet in loadCompleted!!!");return false;}if(null!=document.getElementById(applet)){try{if(document.getElementById(applet).isActive()){return true;}}catch(e){return false;}try{if(document.getElementById(applet).readyState==4){return true;}}catch(e){}}return false;}function WaitForLoadCallback(index){var applet=pendingApplets[index];if(loadCompleted(applet)){DefaultCursor();setTimeout(pendingFunctions[index],0);return;}else{var callbackProc="WaitForLoadCallback('"+index+"')";setTimeout(callbackProc,1000);}}function getCookie(name){var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if(begin==-1){begin=dc.indexOf(prefix);if(begin!=0){return"";}}else{begin+=2;}var end=document.cookie.indexOf(";",begin);if(end==-1){end=dc.length;}return unescape(dc.substring(begin+prefix.length,end));}function initializeApplet(name){parseUrl();if(null==g_privateKey||""==g_privateKey||null==g_machinePassword||""==g_machinePassword||null==g_userName||""==g_userName){g_privateKey=getCookie("BuddyTVPrivateKey");g_machinePassword=getCookie("BuddyTVMachinePassword");g_userName=getCookie("BuddyTVUserName");}if(null==g_privateKey||""==g_privateKey||null==g_machinePassword||""==g_machinePassword||null==g_userName||""==g_userName){var url="http://www.buddytv.com/BuddyTVWebSignup.aspx?sourceURL="+encodeURIComponent(document.URL);navigateToUrl(url);return false;}WaitForLoad("StartApplet('"+name+"')",name);return true;}function StartApplet(name){document.getElementById(name).SetMetaData(g_privateKey,g_machinePassword,g_userName);OnDataPoller(name);}function CreateXMLDocument(data){var xml;if(window.ActiveXObject){xml=new ActiveXObject("MSXML2.DOMDocument");xml.loadXML(data);}else{InitXmlFunctions();var parser=new DOMParser();xml=parser.parseFromString(data,"text/xml");}return xml;}var xmlFunctionsDefined=false;function InitXmlFunctions(){if(xmlFunctionsDefined){return;}xmlFunctionsDefined=true;if(document.implementation.hasFeature("XPath","3.0")){XMLDocument.prototype.selectSingleNode=function(cXPathString,xNode){if(!xNode){xNode=this;}var xItems=this.selectNodes(cXPathString,xNode);if(xItems.length>0){return xItems[0];}else{return null;}};Element.prototype.selectSingleNode=function(cXPathString){if(this.ownerDocument.selectSingleNode){return this.ownerDocument.selectSingleNode(cXPathString,this);}else{throw"For XML Elements Only";}};}if(document.implementation.hasFeature("XPath","3.0")){XMLDocument.prototype.selectNodes=function(cXPathString,xNode){if(!xNode){xNode=this;}var oNSResolver=this.createNSResolver(this.documentElement);var aItems=this.evaluate(cXPathString,xNode,oNSResolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);var aResult=[];for(var i=0;i<aItems.snapshotLength;i++){aResult[i]=aItems.snapshotItem(i);}return aResult;};Element.prototype.selectNodes=function(cXPathString){if(this.ownerDocument.selectNodes){return this.ownerDocument.selectNodes(cXPathString,this);}else{throw"For XML Elements Only";}};}}var g_keepPolling=true;function StopPolling(){g_keepPolling=false;}function OnDataPoller(appletName){if(!g_keepPolling){return;}if(loadCompleted(appletName)){var applet=document.getElementById(appletName);var data=null;data=applet.DataAvailable();if(null!=data&&""!=data){DefaultCursor();}while(null!=data&&""!=data&&g_keepPolling){ProcessData(data);data=applet.DataAvailable();}}setTimeout("OnDataPoller('"+appletName+"')",1000);}function ProcessData(data){var xml=CreateXMLDocument(data);var code=500;var text="Unknown Error";var payload=null;var command="Unknown";var commandId=0;if(null==xml.documentElement){OnDataAvailable(code,text,payload,command,commandId);return;}code=getXmlNodeInnerText(xml.documentElement.selectSingleNode("/xml/response/code"));text=getXmlNodeInnerText(xml.documentElement.selectSingleNode("/xml/response/text"));xmlPayload=xml.documentElement.selectSingleNode("/xml/response/payload");if(null!=xmlPayload){payload=xmlPayload;}command=getXmlNodeInnerText(xml.documentElement.selectSingleNode("/xml/response/command"));commandId=getXmlNodeInnerText(xml.documentElement.selectSingleNode("/xml/response/commandid"));if(403==code){var url="http://www.buddytv.com/BuddyTVWebSignup.aspx?sourceURL="+encodeURIComponent(document.URL);navigateToUrl(url);return;}OnDataAvailable(code,text,payload,command,commandId);}function sessionTypeToText(type){var textType;textType=(type==1?"live":"archived");return textType;}function TimeZoneFromEnum(zone){var timeZone;if(zone==1){timeZone="Eastern";}else{if(zone==2){timeZone="Central";}else{if(zone==3){timeZone="Mountain";}else{if(zone==4){timeZone="Pacific";}else{if(zone==5){timeZone="Hawaii";}else{timeZone="Unknown";}}}}}return timeZone;}function CheckForBuddyTV(){var provisioner;try{provisioner=new ActiveXObject("BuddyTvCtl.BuddyTvProvisioner");if("1.0.3.7"!=provisioner.Version){navigateToUrl("http://www.buddytv.com/upgradenew.htm");return null;}}catch(e){navigateToUrl("http://www.buddytv.com/download.htm");return null;}return provisioner;}function Trim(s){var start=0;while(s.charAt(start)==" "){start=start+1;}var end=s.length-1;while(s.charAt(end)==" "&&end>start){end=end-1;}return s.substr(start,end-start+1);}function switchCheckbox(){if(oCurFocus.checked=="true"){oCurFocus.checked="false";oCurFocus.className="checkbox_hilite";}else{oCurFocus.checked="true";oCurFocus.className="checkbox_checked_hilite";}}function BusyCursor(){try{document.body.style.cursor="wait";}catch(e){return;}}function DefaultCursor(){try{document.body.style.cursor="default";}catch(e){return;}}function EmptyTable(table){var table=document.getElementById(table);var cRows=table.rows.length;for(i=0;i<cRows;i++){table.deleteRow(0);}}function BuddyTvErrorDialog(error){BuddyTvDialog(error,"BuddyTv: Error",1,0,true);}function BuddyTvModalDialog(message,caption){if(false==g_standalone){try{var ret=window.external.MediaCenter().Dialog(message,caption,1,0,true);return ret;}catch(e){}}else{alert(message);return 0;}}function BuddyTvDialog(message,caption,buttons,timeout,modal){try{if(false==g_standalone){try{var ret=window.external.MediaCenter().Dialog(message,caption,buttons,timeout,modal);return ret;}catch(e){}}else{alert(caption+":"+message);return 0;}}catch(e){alert("Failed to display dialog:"+e.message);}}function doEscape(s){if(null==s){return"";}s=s.replace(/&/g,"&amp;");s=s.replace(/\"/g,"&quot;");s=s.replace(/>/g,"&gt;");s=s.replace(/</g,"&lt;");return s;}function doUnEscape(s){s=s.replace(/&amp;/g,"&");s=s.replace(/&quot;/g,'"');s=s.replace(/&gt;/g,">");s=s.replace(/&lt;/g,"<");return s;}function replaceToUrl(url){try{var newUrl=url+"?standalone="+g_standalone;window.location.replace(newUrl);}catch(e){alert("Failed to navigate to url "+url+" :"+e.message);}}function navigateToUrl(url){try{var newUrl=url+"?standalone="+g_standalone;window.location=newUrl;}catch(e){alert("Failed to navigate to url "+url+" :"+e.message);}}function buildUrl(page,name,privateKey,machinePassword,address,status){g_url=page+"?standalone="+g_standalone+"&userName="+encodeURIComponent(name)+"&privateKey="+encodeURIComponent(privateKey)+"&status="+encodeURIComponent(status)+"&address="+encodeURIComponent(address)+"&machinePassword="+encodeURIComponent(machinePassword);return;}function appendToUrl(name,value){g_url=g_url+"&"+name+"="+encodeURIComponent(value);}function RemoveUrlParameter(url,parameter){var start=url.indexOf("&"+parameter+"=");if(-1==start){start=url.indexOf("?"+parameter+"=");if(-1==start){return url;}}var end=url.indexOf("&",start+parameter.length+1);if(-1==end){end=url.length;}var newUrl=url.substr(0,start);if(end!=url.length){newUrl+=url.substr(end);}return newUrl;}function GetUrlParameter(parameter){var url=document.location.search;if(url.charAt(0)=="?"){url=url.substr(1);}var nameAndValue=url.split("&");for(i=0;i<nameAndValue.length;i++){var seperated=nameAndValue[i].split("=");if(seperated[0]==parameter){return decodeURIComponent(seperated[1]);}}return"";}function parseUrl(){var url=document.location.search;if(url.charAt(0)=="?"){url=url.substr(1);}var nameAndValue=url.split("&");for(i=0;i<nameAndValue.length;i++){var seperated=nameAndValue[i].split("=");switch(seperated[0]){case"userName":g_userName=decodeURIComponent(seperated[1]);break;case"privateKey":g_privateKey=decodeURIComponent(seperated[1]);break;case"machinePassword":g_machinePassword=decodeURIComponent(seperated[1]);break;case"address":g_address=decodeURIComponent(seperated[1]);break;case"status":g_status=decodeURIComponent(seperated[1]);break;case"standalone":g_standalone="true"==decodeURIComponent(seperated[1]);break;}}}function truncate(p_strValue,p_iLength,p_blnBeginning){if(p_iLength){l_iLength=p_iLength;}else{l_iLength=12;}if(p_strValue.length>l_iLength&&p_blnBeginning==true){return"..."+p_strValue.slice(0-l_iLength);}if(p_strValue.length>l_iLength){return p_strValue.slice(0,l_iLength)+"...";}else{return p_strValue;}}function IsBenignError(error){if(error==-2146697215||error==-2147014836||error==12031||error==12029){return true;}else{return false;}}var g_buddySettingsManager;function populateBuddySettings(){try{g_buddySettingsManager=new ActiveXObject("BuddyTvCtl.BuddyManager");g_buddySettingsManager.OnComplete=populateBuddySettingsComplete;g_buddySettingsManager.GetSettings(g_userName,g_password,g_address);}catch(e){if(!IsBenignError(e.number)){}}}function populateBuddySettingsComplete(obj,data,error,name){try{if(0!=error&&!IsBenignError(-2147014836)){return;}var root;var xmlDocument=new ActiveXObject("Microsoft.XMLDOM");xmlDocument.loadXML(data);if(null==xmlDocument.documentElement){return;}root=xmlDocument.documentElement.selectSingleNode("/settings");if(null==root){return;}var settings;settings=root.childNodes;var setting;while((setting=settings.nextNode())!=null){var value;if("1"==setting.firstChild.text){value="includes/checked.gif";}else{value="includes/not_checked.gif";}if(setting.nodeName.toLowerCase()=="sharephotos"){document.getElementById("imgPictures").src=value;}else{if(setting.nodeName.toLowerCase()=="sharemusic"){document.getElementById("imgMusic").src=value;}else{if(setting.nodeName.toLowerCase()=="sharemediastate"){}else{if(setting.nodeName.toLowerCase()=="sharerecordedtv"){document.getElementById("imgRecordedPrograms").src=value;}else{if(setting.nodeName.toLowerCase()=="sharevideos"){document.getElementById("imgVideos").src=value;}else{if(setting.nodeName.toLowerCase()=="allowbuddyrecord"){document.getElementById("imgBuddyRecord").src=value;}else{if(setting.nodeName.toLowerCase()=="autoacceptbuddyrecord"){}else{if(setting.nodeName.toLowerCase()=="viewmediastate"){document.getElementById("imgWatchPref").src=value;}}}}}}}}var l_strID="";switch(setting.nodeName.toLowerCase()){case"sharephotos":l_strID="ViewSharedPhotos";break;case"sharemusic":l_strID="ViewSharedMusic";break;case"sharevideos":l_strID="ViewSharedVideos";break;case"sharerecordedtv":l_strID="ViewSharedPrograms";break;}if(l_strID&&(setting.firstChild.text!="1")){document.getElementById(l_strID).disabled=true;}}}catch(e){BuddyTvErrorDialog(e.number+": "+e.message);}}function convertBytes(p_iTotal,p_iType){var l_iDividedTotal=parseInt(p_iTotal);switch(p_iType){case"GB":return(Math.round(l_iDividedTotal/10000000)/10)+" MB";break;case"MB":return(Math.round(l_iDividedTotal/10000)/10)+" MB";break;}return p_iTotal;}var g_buddyMediaStatusManager;function populateBuddyMediaStatus(){try{g_buddyMediaStatusManager=new ActiveXObject("BuddyTvCtl.BuddyManager");g_buddyMediaStatusManager.OnComplete=populateBuddyMediaStatusComplete;g_buddyMediaStatusManager.GetMediaStatus(g_name,g_password,g_address);}catch(e){if(e.number!=-2146697215&&e.number!=-2147014836&&!IsBenignError(e.number)){BuddyTvErrorDialog(e.number+": "+e.message);}}}function populateBuddyMediaStatusComplete(obj,data,error,name){try{if(0!=error&&!IsBenignError(error)){return;}if(data.length==0){return;}var xmlDocument=new ActiveXObject("Microsoft.XMLDOM");xmlDocument.loadXML(data);var root;root=xmlDocument.documentElement;var tv;try{tv=root.selectSingleNode("/xml/MediaStatus/tv/medianame").text;}catch(e){tv="";}var photo;try{photo=root.selectSingleNode("/xml/MediaStatus/photos/currentpicture").firstChild.text;}catch(e){photo="";}var cdartist;var cdmedia;try{cdartist=root.selectSingleNode("/xml/MediaStatus/cd/artistname").firstChild.text;cdmedia=root.selectSingleNode("/xml/MediaStatus/cd/medianame").firstChild.text;}catch(e){cdartist="";cdmedia="";}var pvd;try{pvd=root.selectSingleNode("/xml/MediaStatus/pvd/medianame").firstChild.text;}catch(e){pvd="";}var streaming;try{streaming=root.selectSingleNode("/xml/MediaStatus/streamingvideo/medianame").firstChild.text;}catch(e){streaming="";}var status="";if(0!=tv.length){status+='Watching "'+tv+'"';}if(0!=photo.length){if(status.length!=0){status+=" and ";}status+='Looking at "'+photo+'"';}if(0!=cdartist.length&&0!=cdmedia.length){if(status.length!=0){status+=" and ";}status+="Listening to "+cdartist+'-"'+cdmedia+'"';}if(0!=pvd.length){if(status.length!=0){status+=" and ";}status+='Watching "'+pvd+'"';}if(0!=streaming.length){if(status.length!=0){status+=" and ";}status+='Streaming "'+streaming+'"';}status=truncate(status,53);if(status.length==53){status+="...";}document.getElementById("mediaStatusValue").innerHTML=status;setTimeout(populateBuddyMediaStatus,60*1000);}catch(e){BuddyTvErrorDialog(e.number+": "+e.message);}}var g_objTextInput=null;function setTextFocus(obj){g_objTextInput=obj;}function setTextBlur(obj){g_objTextInput=null;}function doOnFocus(key){if(null!=g_objTextInput){if(g_RemotePressed){if(27!=key){return g_objTextInput.onRemoteEvent(key);}}}return false;}function displayTransportError(error){var errorText;switch(error){case 0:return;case -2147024784:errorText="There is not enough free disk space to retrieve the item";break;case -2147024832:errorText="The remote computer reset the connection.  This usually means that the remote user has logged off";break;case -2146697215:errorText="Could not resolve the address of the remote computer.  The remote computer may be unavailable";break;case -2147014836:errorText="Unable to connect to the remote computer.  The remote computer may not be online";break;case 12031:errorText="There was an error in the network transport while trying to retrieve the item.  The remote computer may not be available";break;case 12029:errorText="Unable to connect to the remote computer.  The remote computer may not be online";break;default:errorText="Failed to retrieve the item.  The remote computer was not available: "+error;break;}BuddyTvModalDialog(errorText,"Failed to retrieve item");}function getCurrentMedia(mediaType){try{var mediaStatus=new ActiveXObject("MediaTrackerCtl.MediaStatus");mediaStatus.GetStatus();var mediaName="";var mediaNetwork="";try{mediaStatus.SetMedia(mediaType);mediaName=mediaStatus.MediaName;mediaNetwork=mediaStatus.Network;}catch(e){}if(null==mediaName){mediaName="";}if(null==mediaNetwork){network="";}if(g_standalone){document.getElementById("inputNetwork").value=mediaNetwork;document.getElementById("inputProgram").value=mediaName;}else{document.getElementById("inputNetwork").ResetText();document.getElementById("inputNetwork").SetText(mediaNetwork);document.getElementById("inputProgram").ResetText();document.getElementById("inputProgram").SetText(mediaName);}}catch(e){if(e.number==-2147024894){}else{if(!IsBenignError(e.number)){}}}}function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p){d.MM_p=new Array();}var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++){if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}}function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){x.src=x.oSrc;}}function MM_findObj(n,d){var p,i,x;if(!d){d=document;}if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}if(!(x=d[n])&&d.all){x=d.all[n];}for(i=0;!x&&i<d.forms.length;i++){x=d.forms[i][n];}for(i=0;!x&&d.layers&&i<d.layers.length;i++){x=MM_findObj(n,d.layers[i].document);}if(!x&&d.getElementById){x=d.getElementById(n);}return x;}function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3){if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc){x.oSrc=x.src;}x.src=a[i+2];}}}function MM_reloadPage(init){if(init==true){with(navigator){if((appName=="Netscape")&&(parseInt(appVersion)==4)){document.MM_pgW=innerWidth;document.MM_pgH=innerHeight;onresize=MM_reloadPage;}}}else{if(innerWidth!=document.MM_pgW||innerHeight!=document.MM_pgH){location.reload();}}}MM_reloadPage(true);var origWidth,origHeight;if(document.layers){origWidth=window.innerWidth;origHeight=window.innerHeight;window.onresize=function(){if(window.innerWidth!=origWidth||window.innerHeight!=origHeight){history.go(0);}};}var origWidth,origHeight;if(document.layers){origWidth=window.innerWidth;origHeight=window.innerHeight;window.onresize=function(){if(window.innerWidth!=origWidth||window.innerHeight!=origHeight){history.go(0);}};}function getLyrRef(lyr,doc){if(document.layers){var theLyr;for(var i=0;i<doc.layers.length;i++){theLyr=doc.layers[i];if(theLyr.name==lyr){return theLyr;}else{if(theLyr.document.layers.length>0){if((theLyr=getLyrRef(lyr,theLyr.document))!=null){return theLyr;}}}}return null;}}function init(id,lyr){var lnk=getElemRefs(id);swapLayers(lnk,lyr);}function doNav(url){buildUrl(url,g_userName,g_privateKey,g_machinePassword,"","");window.location=g_url;}function createNavBar(){parseUrl();var sourceUrl=GetUrlParameter("sourceURL");if(null==g_privateKey||""==g_privateKey||null==g_machinePassword||""==g_machinePassword||null==g_userName||""==g_userName){g_privateKey=getCookie("BuddyTVPrivateKey");g_machinePassword=getCookie("BuddyTVMachinePassword");g_userName=getCookie("BuddyTVUserName");}if(null==g_privateKey||""==g_privateKey||null==g_machinePassword||""==g_machinePassword||null==g_userName||""==g_userName&&0==sourceUrl.Length){var url="http://www.buddytv.com/BuddyTVWebSignup.aspx?sourceURL="+encodeURIComponent(document.URL);navigateToUrl(url);return false;}var navPlaceholder=document.getElementById("navplaceholder");var navHtml="<table width='153' border='0' cellpadding='0' cellspacing='0' id='NavBar'><tr><td><a href='#' onclick='doNav(\"http://app.buddytv.com/buddytv/webapp/start.htm\")' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('Start','','images/Nav1start-over.gif',1)\"><img src='images/Nav1start-over.gif' alt='Start' name='Start' width='153' height='28' border='0' id='Start' /></a></td></tr><tr><td><a href='#' onclick='doNav(\"http://app.buddytv.com/buddytv/webapp/findtvj.htm\")' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('FindTVjSession','','images/Nav2find-over.gif',1)\"><img src='images/Nav2find.gif' alt='Find and Join a TVj Session' name='FindTVjSession' width='153' height='34' border='0' id='FindTVjSession' /></a></td></tr><tr><td><a href='#' onclick='doNav(\"http://app.buddytv.com/buddytv/webapp/starttvj.htm\")' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('startResume','','images/Nav3resume-over.gif',1)\"><img src='images/Nav3resume.gif' alt='Start / Resume TVj'ing' name='startResume' width='153' height='32' border='0' id='startResume' /></a></td></tr><tr><td><a href='#' onclick='doNav(\"http://app.buddytv.com/buddytv/webapp/referfriend.htm\")' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('refer','','images/Nav4refer-over.gif',1)\"><img src='images/Nav4refer.gif' alt='Refer a Friend' name='refer' width='153' height='30' border='0' id='refer' /></a></td></tr><tr><td><a href='#' onclick='doNav(\"http://app.buddytv.com/buddytv/webapp/faq.htm\")' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('Frequently Asked Questions','','images/Nav5faq-over.gif',1)\"><img src='images/Nav5faq.gif' alt='FAQ' name='FAQ' width='153' height='35' border='0' id='FAQ' /></a></td></tr><tr><td><a href='http://www.buddytv.com' target='_blank' onmouseover=\"MM_swapImage('goto','','images/Nav6goto-over.gif',1)\" onmouseout='MM_swapImgRestore()'><img src='images/Nav6goto.gif' alt='Go to BuddyTV.com' name='goto' width='153' height='34' border='0' id='goto' /></a></td></tr><tr><td><a href='http://forums.buddytv.com' target='_blank' onmouseout='MM_swapImgRestore()' onmouseover=\"MM_swapImage('Forum','','images/Nav7forum-over.gif',1)\"><img src='images/Nav7forum.gif' alt='Go to Forum' name='Forum' width='153' height='34' border='0' id='Forum' /></a></td></tr><tr><td>&nbsp;</td></tr><tr><td>Please contact <A href='mailto:support@buddytv.com'>support@buddytv.com</A> with any questions or to report any issues.</td></tr></table>";navPlaceholder.innerHTML=navHtml;}
