if(!window.Microsoft)window.Microsoft=new Object();if(!Microsoft.Msn)Microsoft.Msn=new Object();if(!Microsoft.Msn.Tv)Microsoft.Msn.Tv=new Object();if(!Microsoft.Msn.Tv.UiText)Microsoft.Msn.Tv.UiText=new Object();if(!Microsoft.Msn.Tv.UiText.MktID)Microsoft.Msn.Tv.UiText.MktID='en-US';
if(!window.Microsoft)window.Microsoft=new Object();if(!Microsoft.Msn)Microsoft.Msn=new Object();if(!Microsoft.Msn.Tv)Microsoft.Msn.Tv=new Object();Microsoft.Msn.Tv.DataFetcher={"LoadURL":function(url,isCacheable,preempt,timeoutMS,onMethodComplete,onMethodTimeout,onMethodError)
{if(isCacheable&&this.webServiceCache[url]!=null)
{onMethodComplete(this.webServiceCache[url]);return;}
this.logLastWSCall(url);if(this.scriptDiv==null)
{this.scriptDiv=document.createElement("div");this.scriptDiv.id="Microsoft.Msn.TV.ScriptDiv";document.body.appendChild(this.scriptDiv);}
var callbackid=this.m_WSCallId++;var callState=new this.CallState(callbackid,url,isCacheable,timeoutMS,"get",null,onMethodComplete,onMethodTimeout,onMethodError);this.insertCallState(callState);eval("var f1 = function(result) { Microsoft.Msn.Tv.DataFetcher.OnMethodComplete("+callbackid+",result); }");eval("var f2 = function(errId, errMsg) { Microsoft.Msn.Tv.DataFetcher.OnMethodError("+callbackid+", errId, errMsg); }");var callbackName="dataFetcherComplete"+callbackid;var errorName="dataFetcherError"+callbackid;eval("window."+callbackName+"=f1");eval("window."+errorName+"=f2");if(url.indexOf("?")>=0)
{url+="&";}
else
{url+="?";}
url+="onComplete="+callbackName+"&onError="+errorName;if(!isCacheable)
{var d=new Date();url+=("&dts="+d.valueOf());}
var scriptElem=document.createElement("script");scriptElem.src=url;scriptElem.type="text/javascript";scriptElem.language="javascript";scriptElem.charset="utf-8";callState.timeoutTimer=setTimeout("Microsoft.Msn.Tv.DataFetcher.WebServiceTimeout("+callbackid+")",callState.timeout);callState.scriptElem=scriptElem;this.scriptDiv.appendChild(scriptElem);},"logLastWSCall":function(url)
{if(!Microsoft.Msn.MediaTags)return;var ui=Microsoft.Msn.MediaTags.TvTagUI;if(ui)ui.setInformativeText("appLastWSCall",url);},"scriptDiv":null,"callStates":new Array(),"m_WSCallId":0,"webServiceCache":new Array(),"doNothing":function()
{},"insertCallState":function(cs)
{var len=this.callStates.length;for(var i=0;i<len;i++)
{if(this.callStates[i]==null)
{this.callStates[i]=cs;return;}}
this.callStates[len]=cs;return;},"getCallState":function(id)
{var len=this.callStates.length;for(var i=0;i<len;i++)
{var cs=this.callStates[i];if(cs)
{if(cs.callbackid==id)return cs;}}
return null;},"cleanupCallState":function(cs)
{var callbackName="dataFetcherComplete"+cs.callbackid;var errorName="dataFetcherError"+cs.callbackid;eval("window."+callbackName+"=this.doNothing");eval("window."+errorName+"=this.doNothing");try{this.scriptDiv.removeChild(cs.scriptElem);}catch(e){}
var len=this.callStates.length;for(var i=0;i<len;i++)
{var csx=this.callStates[i];if(csx)
{if(csx.callbackid==cs.callbackid)this.callStates[i]=null;}}},"OnMethodComplete":function(callbackid,result)
{var callState=this.getCallState(callbackid);if(callState==null)return;clearTimeout(callState.timeoutTimer);callState.timeoutCallback=null;callState.timeoutTimer=null;callState.onloadCallback(result);if(callState.isCachable)
{this.webServiceCache[callState.url]=result;}
this.cleanupCallState(callState);},"OnMethodError":function(callbackid,errId,errMsg)
{var callState=this.getCallState(callbackid);if(callState==null)return;clearTimeout(callState.timeoutTimer);callState.timeoutCallback=null;callState.timeoutTimer=null;callState.errorCallback(errId,errMsg);this.cleanupCallState(callState);},"WebServiceTimeout":function(callbackid)
{var callState=this.getCallState(callbackid);if(callState==null)return;var fn=callState.timeoutCallback;if(fn)
{this.cleanupCallState(callState);fn();}},"ClearCache":function()
{this.webServiceCache=new Array();},"CallState":function(callbackid,url,isCacheable,timeout,type,data,onloadCallback,timeoutCallback,errorCallback)
{this.callbackid=callbackid;this.url=url;this.data=data;this.isCacheable=isCacheable;this.onloadCallback=onloadCallback;this.errorCallback=errorCallback;this.timeoutCallback=timeoutCallback;this.timeout=timeout;this.type=type;}};var registerTvNamespace=function(ns)
{var rootObject=window;var namespaceParts=ns.split(".");for(var i=0;i<namespaceParts.length;i++)
{var currentPart=namespaceParts[i];if(!rootObject[currentPart])
rootObject[currentPart]=new Object();rootObject=rootObject[currentPart];}};registerTvNamespace("Microsoft.Msn.Tv.Shared");Microsoft.Msn.Tv.Shared.Utils={UiText:Microsoft.Msn.Tv.UiText,AddElement:function(parentOb,tagName,className)
{var e=document.createElement(tagName);e.className=className;return parentOb.appendChild(e);},FillDigits:function(num,count,dir)
{var s=num.toString();while(s.length<count)
{if(dir==1)
s="0"+s;else
s=s+"0";}
return s;},ArraysAreEqual:function(a,b)
{if(a==null||b==null)
return false;if(a.length!=b.length)
return false;for(var i=0;i<a.length;i++)
{if(a[i]!=b[i])
return false;}
return true;},WindowOffsetTop:function(ob)
{var y=0;if(ob.offsetTop!=null)
{y+=ob.offsetTop;while(ob.offsetParent)
{y+=ob.offsetParent.offsetTop;ob=ob.offsetParent;}}
return y;},CancelDefaultNav:function(aEvent)
{if(typeof event!='undefined')
{event.returnValue=false;}
else
{aEvent.preventDefault();}},HelpIsEnabled:function()
{return typeof LaunchHelp=="function";},EventTarget:function(e)
{var targ;if(!e)var e=window.event;if(e.target)targ=e.target;else if(e.srcElement)targ=e.srcElement;if(targ.nodeType==3)
targ=targ.parentNode;return targ;},StringFormat:function(str,arr)
{if(arr!=null)
{for(var i=0;i<arr.length;i++)
{var newS=arr[i];var oldS="{"+i+"}";var a=str.indexOf(oldS);if(a!=-1)
{var b=a+oldS.length;str=str.substring(0,a)+newS+str.substring(b,str.length)}}}
return str;},ToXMLString:function(obj,name)
{var xml="";var isArray=!!obj.sort;if(isArray)
{for(var i in obj)
xml+=this.ToXMLString(obj[i],name);}
else if(typeof(obj)=="object")
{if(name)
xml+="<"+name+">";for(var m in obj)
xml+=this.ToXMLString(obj[m],m);if(name)
xml+="</"+name+">";}
else
{xml+="<"+name+">"+this.EscapeStr(obj.toString())+"</"+name+">";}
return xml;},ToJSONString:function(obj)
{var isArray=!!obj.sort;var objstr=isArray?"[":"{";for(var i in obj)
{var val=obj[i];if(typeof val=="undefined")
{continue;}
if(Object.prototype[i])
{continue;}
if(objstr.length>1)
{objstr+=",";}
if(!isArray)
{objstr+=i+":";}
if(typeof val=="object")
{objstr+=this.ToJSONString(val);}
else
{if(typeof val=="string")
{val='"'+this.EscapeStr(val)+'"';}
objstr+=val.toString();}}
objstr+=isArray?"]":"}";return objstr.replace(/\n/g,"").replace(/\r/g,"");},EscapeStr:function(str)
{return str.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t");},StripSpaces:function(str)
{var noSpaces=new RegExp("[^\\s]*","g");return str!=null&&str.match(noSpaces)!=null?str.match(noSpaces).join(''):null;},OnlyDigits:function(str)
{var onlyDigits=new RegExp("\\d+","g");return str!=null&&str.match(onlyDigits)!=null?str.match(onlyDigits).join(''):null;},Trim:function(s)
{var str=new String(s);str=str.replace(/^\s+/g,"");str=str.replace(/\s+/g," ");return str.replace(/\s+$/g,"");},StatsEnabled:false,MaxProps:11,InitStats:function(accountName)
{if(true==this.IsStatsEnabled())
{this.InitScode(accountName);}
return;},IsStatsEnabled:function()
{return typeof tvs_s!='undefined'?true:false;},GetTrackingAccount:function()
{return this.IsStatsEnabled()==true?tvs_s_account:"";},LogStats:function(pageName,arrProps,accountName)
{if(false==this.IsStatsEnabled())
{return;}
if(typeof this.UiText=='undefined')
{this.UiText=Microsoft.Msn.Tv.UiText;}
if(typeof accountName!='undefined'&&accountName!=null)
{this.InitScode(accountName);}
this.StatsResetLogProps();tvs_s.account=accountName;tvs_s.pageName=pageName;for(var i=1;i<arrProps.length;i++)
{if(typeof arrProps[i]!='undefined')
{eval("tvs_s.prop"+i+" = arrProps[i];");}}
if(this.UiText.NonCustomMktID!=null&&this.UiText.NonCustomMktID!="")
{tvs_s.prop2=this.UiText.NonCustomMktID;}
else
{tvs_s.prop2=this.UiText.MktID;}
tvs_s.prop6=document.URL;tvs_s.t();this.StatsResetLogProps();},InitScode:function(accountName)
{tvs_s=null;tvs_s_account=accountName;tvs_s=tvs_s_gi(tvs_s_account);},StatsResetLogProps:function()
{tvs_s.pagename="";for(var i=1;i<=this.MaxProps;i++)
{eval("tvs_s.prop"+i+" = ''");}}};registerTvNamespace("Microsoft.Msn.MediaTags");Microsoft.Msn.MediaTags.RemoteRecordManager=function()
{var k_TvTagMgrUrl="http://mediaservices.msn.com/TvTags/TvTagUi.ashx";var k_ExactSearchUrl="http://mediaservices.msn.com/DiscoveryWS/ExactSearch2.ashx";var k_Errors={"00":"There was an error parsing the TVTagUiManager result.","01":"The TVTagUiManager request timed out.","02":"The TVTagUiManager request returned an error.","10":"There was an error parsing the ExactSearch2 result.","11":"The ExactSearch2 request timed out.","12":"The ExactSearch2 request returned an error.","13":"Remote Record is currently disabled"};var m_this=this;var m_dataFetcher=Microsoft.Msn.Tv.DataFetcher;var m_onInitCallback;var m_onErrorCallback;var m_onChangeHeadendCallback;var m_exactSearchCallback;var m_tvTagManager;var m_baseFontSize;var m_uiText;this.init=function(onInit,onError,onChangeHeadend,baseFontSize)
{m_onInitCallback=onInit;m_onErrorCallback=onError;m_onChangeHeadendCallback=onChangeHeadend;m_baseFontSize=baseFontSize;m_UiText=Microsoft.Msn.Tv.UiText;m_dataFetcher.LoadURL(k_TvTagMgrUrl+"?mkt="+m_UiText.MktID+"&release=4.0",true,true,180000,OnGetTvTagUi,OnGetTvTagUiTimeout,OnGetTvTagUiError);}
this.dispose=function()
{if(m_tvTagManager!=null)
m_tvTagManager.DetachEvents();}
this.getAllAirings=function(title,programid,onComplete,seriesid,Hasseries)
{m_exactSearchCallback=onComplete;var url=k_ExactSearchUrl+"?source=TV";if(title!=null&&title!="")
url+="&title="+title;if(programid!=null&&programid!="")
url+="&programid="+programid;if(seriesid!=null&&seriesid!='undefined'&&seriesid!="")
url+="&seriesid="+seriesid;if(Hasseries!=null&&Hasseries!='undefined'&&Hasseries!="")
url+="&Hasseries="+Hasseries;url+="&timezoneOffset="+m_tvTagManager.TZ+"&observesDST="+m_tvTagManager.DST+"&mkt="+m_UiText.MktID;m_dataFetcher.LoadURL(url,true,true,10000,OnGetExactSearch,OnExactSearchTimeout,OnExactSearchError);}
this.getAllAiringsWithEncode=function(title,programid,onComplete,seriesid,Hasseries)
{m_this=this;m_this.getAllAirings(encodeURIComponent(title),encodeURIComponent(programid),onComplete,encodeURIComponent(seriesid),encodeURIComponent(Hasseries));}
this.doRecord=function(exactSearchOb,episodeIndex,airingIndex,recordSeries,onCloseFocusElement)
{if(true)
{var showSeriesEpisodeOpt=false;if(onCloseFocusElement!=null)
m_tvTagManager.SetPageElementForFocus(onCloseFocusElement);m_tvTagManager.ExactSearchOb=exactSearchOb;m_tvTagManager.SetNowShow(episodeIndex,airingIndex);m_tvTagManager.Record.SetPreferences(recordSeries,showSeriesEpisodeOpt);m_tvTagManager.DoRecord();}
else
{OnRemoteRecordDisabledError();}}
this.doChangeProvider=function(onCloseFocusElement)
{if(onCloseFocusElement!=null)
m_tvTagManager.SetPageElementForFocus(onCloseFocusElement);m_tvTagManager.ChooseHeadend.Show();}
this.getHeadendName=function()
{var headend=null;if(m_tvTagManager.Headend!=null)
{headend=m_tvTagManager.Headend.name;}
return headend;}
this.getHeadendZip=function()
{var zip=null;if(m_tvTagManager.Headend!=null)
{zip=m_tvTagManager.Headend.zip;}
return zip;}
this.getHeadendIsDefault=function()
{var isDefault=false;if(m_tvTagManager.Headend!=null)
{isDefault=m_tvTagManager.Headend.isDefault;}
return isDefault;}
this.getDateTimeStringWithFormat=function(utcTime,format)
{return Microsoft.Msn.Tv.Shared.DateTime.GetDateTimeStringWithFormat(utcTime,format);}
this.midnightNthDay=function(n)
{return Microsoft.Msn.Tv.Shared.DateTime.MidnightNthDay(n);}
function OnGetTvTagUi(result)
{try
{if(result!=null)
{eval(result);}
m_tvTagManager=Microsoft.Msn.MediaTags.TvTagUI;}
catch(e)
{HandleError("00");return;}
var onChangeHeadend=m_onChangeHeadendCallback;var includeLinksOnConfirmation=false;var baseFontSizePercent=m_baseFontSize;var remoteRecordVersion=3;var enableRemoteRecord=true;m_tvTagManager.Init(includeLinksOnConfirmation,baseFontSizePercent,enableRemoteRecord,remoteRecordVersion);m_tvTagManager.SetCallbackEvents(onChangeHeadend,null);m_onInitCallback();}
function OnGetTvTagUiTimeout()
{HandleError("01");}
function OnGetTvTagUiError()
{HandleError("02");}
function OnGetExactSearch(resultStr)
{try
{eval("var result = "+resultStr);if(result.headend!=null)
{if(result.headend.name!="")
{m_tvTagManager.Headend=result.headend;}
if(!Microsoft.Msn.Tv.Shared.DateTime.initialized)
{Microsoft.Msn.Tv.Shared.DateTime.Init(result.headend.timezone*60*1000,result.headend.dstTransition,result.headend.dstOffsetCurrent,result.headend.dstOffsetNext,14);}}}
catch(e)
{HandleError("10");return;}
m_exactSearchCallback(result);}
function OnExactSearchTimeout()
{HandleError("11");}
function OnExactSearchError()
{HandleError("12");}
function OnRemoteRecordDisabledError()
{HandleError("13");}
function HandleError(errorCode)
{m_onErrorCallback(errorCode,k_Errors[errorCode]);}};registerTvNamespace("Microsoft.Msn.Tv");Microsoft.Msn.Tv.SearchWrapper=function()
{var k_SearchHandler="SearchTV.ashx";var k_Errors={"10":"error in OnSearchReturn","11":"OnSearchTimeout","12":"OnSearchError"};var m_this=this;var m_dataFetcher=Microsoft.Msn.Tv.DataFetcher;var m_utils=Microsoft.Msn.Tv.Shared.Utils;var m_discoveryPath;var m_observesDST;var m_onErrorCallback;var m_onSearchCallback;var m_timezoneOffset;var m_uiText;this.init=function(wsPath,onError)
{m_discoveryPath=wsPath;m_onErrorCallback=onError;var d1=new Date(2003,1,1);var d2=new Date(2003,7,1);var stdTz=d1.getTimezoneOffset();var dstTz=d2.getTimezoneOffset();m_timezoneOffset=-stdTz;m_observesDST=stdTz!=dstTz;m_UiText=Microsoft.Msn.Tv.UiText;}
this.dispose=function()
{m_discoveryPath=null;m_observesDST=null;m_onErrorCallback=null;m_onSearchCallback=null;m_timezoneOffset=null;}
this.levelOneSearch=function(query,startIndex,endIndex,onComplete)
{query=m_utils.Trim(query);query=encodeURIComponent(query);m_onSearchCallback=onComplete;var grouping="noepisodes";Search(query,startIndex,endIndex,grouping,"");}
this.levelTwoSearch=function(title,query,field,onComplete)
{m_onSearchCallback=onComplete;var grouping="allepisodes";var newQuery="title:\""+title+"\"";if(field!="Title")
newQuery+=" "+field+":{"+query+"}";startIndex=0;endIndex=5000;Search(newQuery,startIndex,endIndex,grouping,"");}
function Search(query,startIndex,endIndex,grouping,additionalParams)
{var startTime=new Date();var endTime=new Date(2050,0,1);var now=Math.floor(startTime.getTime()/1000);var future=Math.floor(endTime.getTime()/1000);var url=m_discoveryPath+"/SearchTV.ashx";url+="?startTime="+now;url+="&endTime="+future;url+="&startIndex="+startIndex;url+="&endIndex="+endIndex;url+="&query="+encodeURIComponent(query);url+="&grouping="+grouping;url+="&timezoneOffset="+m_timezoneOffset;url+="&observesDST="+m_observesDST;url+="&mkt="+m_UiText.MktID;url+=additionalParams;m_dataFetcher.LoadURL(url,true,true,10000,OnSearchReturn,OnSearchTimeout,OnSearchError);}
function OnSearchReturn(result)
{if(result==null||typeof result!="object")
{HandleError("10");}
else
{if(Microsoft.Msn.Tv.Shared.DateTime&&!Microsoft.Msn.Tv.Shared.DateTime.initialized&&result.headend)
{Microsoft.Msn.Tv.Shared.DateTime.Init(result.headend.timezone*60*1000,result.headend.dstTransition,result.headend.dstOffsetCurrent,result.headend.dstOffsetNext,14);}
m_onSearchCallback(result);}}
function OnSearchTimeout()
{HandleError("11");}
function OnSearchError()
{HandleError("12");}
function HandleError(errorCode)
{m_onErrorCallback(errorCode,k_Errors[errorCode]);}};if (typeof(uiHandlers) == 'undefined') { uiHandlers = new Array();uiHandlers["tvservices:tv"] = {url:"http://mediaservices.msn.com/tvtags/tvtagui.ashx?version=6.1.612.27&mkt=",loaded:false,queue:[]};
if(!Microsoft.Msn.MediaTags)Microsoft.Msn.MediaTags=new Object();Microsoft.Msn.MediaTags.UiHandlers = uiHandlers; }