﻿var isclose=true;
var firstPost=true;
			function $(o)
			{
				return document.getElementById(o);
			}

			function login()
			{
				if ($('UserName1').value=="")
				{
					alert("请输入用户名");
					$('UserName1').focus();
					return;
				}
				if ($('Password1').value=="")
				{
					alert("请输入密码");
					$('Password1').focus();
					return;
				}
				if ($('checkcode').value=="")
				{
					alert("请输入验证码");
					$('checkcode').focus();
					return;
				}
				if(!IsNum($('UserName1').value))
				{
					$('LoginType1').value = 0;
				}
				else
				{
					$('LoginType1').value = 1;
				}
        var obj_fra;
        if(!window.ActiveXObject)
        	obj_fra=document.getElementById("login_fr").contentDocument;
        else
        {
        	obj_fra=frames["login_fr"].document;
        }
				obj_fra.getElementById('UserName1').value=$('UserName1').value;
				obj_fra.getElementById('Password1').value=$('Password1').value;				
				obj_fra.getElementById('LoginType1').value=$('LoginType1').value;	
				obj_fra.getElementById('checkcode').value=$('checkcode').value;		
				frames["login_fr"].login();
			}
var isok = function(obj)
{
		firstPost = true;
	var ret = obj.responseText;
	var retstr=eval('(' + ret + ')') ;
	switch (retstr.ret)
	{
		case 1:
				isclose=false;
				var r = new Request();
				var URL=r.QueryString["url"];
				if(URL!="" && URL!=null)
				{
					top.document.location.href=unescape(URL);	
				}
				else
				{
					//top.document.location.href=top.document.location.href;
					//showLoginStatus();
					top.document.location.href=top.document.location.href;
				}
				break;
		case -801:
			  alert('验证码错误');
			 	$('check_img').src='http://pass.sanguo001.com/ValidateNumber.aspx?r='+Math.random();
			  $('checkcode').focus();
			  break;
		default:
			alert("用户名或密码错误！");
			$('check_img').src='http://pass.sanguo001.com/ValidateNumber.aspx?r='+Math.random();
			break;
	}

}
function IsNum(str) 
{  
			return /^\d+$/.test(str);//为真
}
function showLoginStatus()
{   
	var objLogin_In = document.getElementById("Login_In");
	var objLogin_Out = document.getElementById("Login_Out");
	if((GetCookie("5show_user_id") !=null) && (GetCookie("5show_user_id") !="-1") && (GetCookie("5show_user_id") !=""))
	{   
		objLogin_In.style.display = "";
		objLogin_Out.style.display = "none";
		if(GetCookie_client("5show_nick_name_client")!="")
		{
			document.getElementById("AA_In").innerHTML ='<div class="k">'+GetCookie_client("5show_nick_name_client")+"，欢迎回来！"+'</div>';
		}
		else
			document.getElementById("AA_In").innerHTML = '<div class="k">'+GetCookie("5show_user_name")+"，欢迎回来！"+'</div>';
		if($('index_js_1')!=null)
		{
				$('index_js_1').href='http://pass.sanguo001.com/m.aspx?cn=payselect';
				$('index_js_2').href='http://pass.sanguo001.com/m.aspx?cn=PassportInfo';		
		}
	}
	else
	{   
		objLogin_In.style.display = "none";
		objLogin_Out.style.display = "";
		if($('index_js_1')!=null)
		{
				$('index_js_1').href='javascript:alert("请先登录！")';
				$('index_js_2').href='javascript:alert("请先登录！")';		
				$('index_js_1').target="_self";
				$('index_js_2').target="_self";	
		}		
	}

}
function DecodeCookie(str)
{
　var strArr;
　var strRtn="";

　strArr=str.split("a");

　for (var i=strArr.length-1;i>=0;i--) 
　strRtn+=String.fromCharCode(eval(strArr[i]));

　return strRtn;
}

function GetCookie_client (cookiename) 
{
    var thebigcookie = document.cookie;
    var firstchar = thebigcookie.indexOf(cookiename);
    if (firstchar != -1) {
        firstchar += cookiename.length + 1;
        lastchar = thebigcookie.indexOf(";",firstchar);
        if(lastchar == -1) lastchar = thebigcookie.length;
        return DecodeCookie(unescape(thebigcookie.substring(firstchar, lastchar)));
    }
    return "";
}
function showimg1()
{
	$('check_img').style.display='inline';
	$('check_img').src='http://pass.sanguo001.com/ValidateNumber.aspx?r='+Math.random();
}
window.onload=function()
{
	if(typeof loadtabs != 'undefined')
{
	var menucount=loadtabs.length; var a = 0; var b = 1; do {easytabs(b, loadtabs[a]);  a++; b++;}while (b<=menucount);
	if (autochangemenu!=0){start_autochange();} 
}   
    	var r = new Request();
			var pid=r.QueryString["pid"];
			if(document.location.href=='http://www.sanguo001.com/index.html?')
				pid=1;
			if(pid!="" && pid!=null)
			{
					var nextYear = new Date();
					nextYear.setYear(nextYear.getFullYear()+1);
					setCookie("sg_pid",pid,nextYear,"sanguo001.com");
		 }
		 	var uid=r.QueryString["uid"];
			if(uid!="" && uid!=null)
			{
					var nextYear = new Date();
					nextYear.setYear(nextYear.getFullYear()+1);
					setCookie("sg_p_uid",uid,nextYear,"sanguo001.com");
		 }
			var uname=r.QueryString["uname"];
			if(uname!="" && uname!=null)
			{
					var nextYear = new Date();
					nextYear.setYear(nextYear.getFullYear()+1);
					setCookie("sg_p_uname",uname,nextYear,"sanguo001.com");
		 }	
		 //已经收藏
		 if(document.location.href.indexOf("?favorite")!=-1)
		 {
			var nextYear = new Date();
			nextYear.setYear(nextYear.getFullYear()+1);
			setCookie("dipan_cn_favorite","1",nextYear,"sanguo001.com");		
		 }

}
window.onbeforeunload=function()
{

		if(GetCookie("dipan_cn_favorite")=="" && GetCookie("dipan_cn_favorite_t")=="" && isclose && ($('index_js_1')!=null))
		{
			var nextYear = new Date();			
			nextYear.setHours(nextYear.getHours()+24);			
			setCookie("dipan_cn_favorite_t","1",nextYear,"sanguo001.com");			
var title="《武林英雄》今日新服！在线火爆！现在注册，拿888礼金券！";
var url="http://www.sanguo001.com/?favorite";
if (window.sidebar) window.sidebar.addPanel(title, url,"");
else if( window.opera  &&  window.print ){
var mbm = document.createElement('a');
mbm.setAttribute('rel','sidebar');
mbm.setAttribute('href',url);
mbm.setAttribute('title',title);
mbm.click();}
else if( document.all ) window.external.AddFavorite( url, title);			
		}


}
function changeTab(id)
{
   $("tab_1").style.display="none";
   $("tab_2").style.display="none";   
   $("tab_3").style.display="none";
   $("tab_"+id).style.display="";   	
}

function show_serverlist()
{
	if((GetCookie("5show_user_id") !=null) && (GetCookie("5show_user_id") !="-1") && (GetCookie("5show_user_id") !=""))
	{
	setrightserverlist(1);
	document.getElementById('dlg_message').style.display="";
	document.getElementById('mask').style.display="";
	if($('flash_div')!=null)
		$('flash_div').style.visibility="hidden";
  document.getElementById('mask').style.height=document.documentElement.scrollHeight+"px";
	document.getElementById('mask').style.width="100%";
	document.body.style.marginRight="0";
	document.body.style.marginLeft="0";
	document.getElementById('dlg_message').style.left=(window.screen.width-document.getElementById('dlg_message').style.width.replace('px',''))/2+"px";

	if((window.screen.height-document.getElementById('dlg_message').style.height.replace('px',''))/2-100<0)
	{
   		document.getElementById('dlg_message').style.top=0;
	}
	else
	{
   		document.getElementById('dlg_message').style.top=(window.screen.height-document.getElementById('dlg_message').style.height.replace('px',''))/2-100+document.documentElement.scrollTop+"px";
	}
}

}


function close_layer()
{
		document.getElementById('dlg_message').style.display="none";
	  document.getElementById('mask').style.display="none";	
	  if($('flash_div')!=null)
	  	$('flash_div').style.visibility="visible";
	  
}

