function loadA(){
	try{
		var tp = tvu();
	    if(!tp) return;
	    tp.SetTVGuideUrl(getA());
	}catch(err){		
	}
}

function onPlayCallback(s,ec){
	if(ec == 3){
		onPlayCallbackA();
	} else if(ec == 4) {
		onPlayCallbackB();
	}	else if(ec == 8) {
		onPlayCallbackC(s);
	}	else if(ec == 9) {
		onPlayCallbackD();
	}
	/*if(ec == 3){
		showObj("PlayCallback");
		document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:460px;'>To watch this channel, you must sign in and subscribe it. Do you want to sign in now?</div><div style='margin:20px auto; width:200px;'><div style='float:left;background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; line-height:27px; height:27px;'><a href='javascript:openLogin()' style='text-decoration:none;color:#ffffff;'>OK</a></div><div style='background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; height:27px;float:right; line-height:27px;'><a href='javascript:closeObj(\"PlayCallback\")' style='text-decoration:none;color:#ffffff;'>Cancel</a></div></div>"
	} else if(ec == 4) {
		showObj("PlayCallback");
		document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:460px;'>This channel is only available to subscribers. Are you interested in becoming a subscriber?</div><div style='margin:20px auto; width:200px;'><div style='float:left;background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; line-height:27px; height:27px;text-align:center;'><a target='_blank' href='http://pages.tvunetworks.com/viewers/ptos.jsp?c=" +s+"&aff="+loginAffiliate+"' onclick='closeObj(\"PlayCallback\")' style='text-decoration:none;color:#ffffff;'>OK</a></div><div style='background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; height:27px;float:right; line-height:27px;'><a href='javascript:closeObj(\"PlayCallback\")' style='text-decoration:none;color:#ffffff;'>Cancel</a></div><div>"
	}	*/
}
function onPlayCallbackA(){
	openLogin();
}
function onPlayCallbackB(){
	showObj("PlayCallback");
		document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:460px;'>This channel is only available to subscribers. Are you interested in becoming a subscriber?</div><div style='margin:20px auto; width:200px;'><div style='float:left;background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; line-height:27px; height:27px;text-align:center;'><a target='_blank' href='http://pages.tvunetworks.com/viewers/ptos.jsp?c=" +s+"&aff="+loginAffiliate+"' onclick='closeObj(\"PlayCallback\")' style='text-decoration:none;color:#ffffff;'>OK</a></div><div style='background:url(http://pages.tvunetworks.com/images/broadcast/button_bg.png); width:80px; height:27px;float:right; line-height:27px;'><a href='javascript:closeObj(\"PlayCallback\")' style='text-decoration:none;color:#ffffff;'>Cancel</a></div><div>"
}

var setTvGuideFlag = true;
function onPlayCallbackC(s){
	setTvGuideFlag=false;
	reloadSc("assc","http://pages.tvunetworks.com/accounts/accountStatusSmallAxl.jsp?tg="+s);
}
function onPlayCallbackD(){
	setTvGuideFlag=false;
	reloadSc("assc","http://pages.tvunetworks.com/accounts/accountStatusSmallAxl.jsp?tg=o");
}
function closeObj(id){
	if(!document.getElementById(id))return;
	if(document.getElementById(id).style.display!="none"){
		document.getElementById(id).style.display="none";
	}
}
function showObj(id){
	if(!document.getElementById(id))return;
	if(document.getElementById(id).style.display=="none"){
		document.getElementById(id).style.display="block";
	}
}
function openLogin(){
	if(BrowserDetect.OS=="Mac"){
	   tvu().Dohide=true;
	}
	document.getElementById("loginFrame").src="http://pages.tvunetworks.com/accounts/viewLoginP.do?referer=s.html&aff="+loginAffiliate;
	document.getElementById("login_w").style.display = "inline";
	document.getElementById("login_w_b").style.display = "inline";
	closeObj("PlayCallback")
}
function logout(){
	document.getElementById("loginFrame").src="http://pages.tvunetworks.com/accounts/logoutP.do?referer=s.html";
}

function closeLoginW(){
	document.getElementById("login_w").style.display = "none";
	document.getElementById("login_w_b").style.display = "none";
	document.getElementById("loginFrame").src="about:blank";
}

var ii=1;
function refreshAccountStatus(){
	reloadSc("assc","http://pages.tvunetworks.com/accounts/accountStatusSmallAx.jsp?aff="+loginAffiliate +"&"+ii);
	ii++;
}

function resetAStatus(){
	try{
	  var tp = tvu();
	  if(!tp) return;
	  tp.SetTVGuideUrl(getA());	
	}catch(e){
	}
	
	var at = accountStatusTableBuild();
	document.getElementById("accountStatus").innerHTML =at ;
}

function reloadSc(emId,url){
	var el = document.getElementById(emId);
	var p=el.parentNode;
	//delete
	if(el != null && el != 'undefine'){
		var p=el.parentNode;
		p.removeChild(el);
	}
	var newSc=document.createElement('script');
	newSc.setAttribute('src',url);   
	newSc.id=emId; 
	newSc.DEFER="defer";
	var done = false;
	newSc.onload= newSc.onreadystatechange = function(){
		if ( !done && (!this.readyState || 
				this.readyState == "loaded" || this.readyState == "complete")){
			done=true;
			resetAStatus();
		}
	};
	p.appendChild(newSc);
}
