﻿var langType;
if(!langType){
	langType="en"
}
function loadA(){
	var tp = tvu();
	if(!tp) return;
	try{
		//if(BrowserDetect.OS!="Mac"){
	       tp.SetTVGuideUrl(getA());	//not support mac
	   // }
	}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();
	}	
}
function onPlayCallbackA(){
	openLogin();
	/*
	showObj("PlayCallback");
	if(langType=="en"){
		document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:410px;'>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()' class='auplay_btn'>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\")' class='auplay_btn'>Cancel</a></div></div>"
	 }else if(langType=="zh") {
		document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:410px; '>您必须登录并且订阅才能观看这个频道。<br> 您现在需要登录吗?</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:25px; height:25px;'><a href='javascript:openLogin()' class='auplay_btn'>确定</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\")' class='auplay_btn'>取消</a></div></div>"
	 }
	 */
}
function onPlayCallbackB(){
	showObj("PlayCallback");
	if(langType=="en"){
	   document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:410px;'>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/tvutos.jsp?c=" +c+"' onclick='closeObj(\"PlayCallback\")' class='auplay_btn'>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\")' class='auplay_btn'>Cancel</a></div><div>"
	 }else if(langType=="zh") {
		 document.getElementById("PlayCallback").innerHTML="<div style='margin:13px auto; width:410px;'>您需要订阅才能观看这个频道。<br> 您有兴趣订阅吗?</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:25px; height:25px;text-align:center;'><a target='_blank' href='http://pages.tvunetworks.com/viewers/tvutos.jsp?c=" +c+"' onclick='closeObj(\"PlayCallback\")' class='auplay_btn'>确定</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\")' class='auplay_btn'>取消</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 openLogin(){
	if(BrowserDetect.OS=="Mac"){
	   tvu().Dohide=true;
	}
	document.getElementById("loginFrame").src="http://pages.tvunetworks.com/accounts/viewLoginl.do?referer=s.html";
	document.getElementById("login_w").style.display = "block";
	document.getElementById("login_w_b").style.display = "block";
	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";
	if(BrowserDetect.OS=="Mac"){
	   tvu().Dohide=false;
	}
}

var ii=1;

function refreshAccountStatus(){
	ii++;
	reloadSc("assc","http://pages.tvunetworks.com/accounts/accountStatusSmallAxl.jsp?"+ii);
}

function resetAStatus(){
	var tp = tvu();
	//if(BrowserDetect.OS!="Mac"){
	if(setTvGuideFlag){
	    tp.SetTVGuideUrl(getA());	//not support mac
	}else{
		setTvGuideFlag = true;
	}
	//}
	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);

}

