﻿var isclose=true;
var firstPost=true;
			function $q(o)
			{
				return document.getElementById(o);
			}

			function login()
			{
				if ($q('UserName1').value=="")
				{
					alert("请输入用户名");
					$q('UserName1').focus();
					return;
				}
				if ($q('Password1').value=="")
				{
					alert("请输入密码");
					$q('Password1').focus();
					return;
				}
				if ($q('checkcode').value==""|| $q('checkcode').value=="点击获取")
				{
					alert("请输入验证码");
					$('checkcode').value="";
					$q('checkcode').focus();
					return;
				}
				if(!IsNum($q('UserName1').value))
				{
					$q('LoginType1').value = 0;
				}
				else
				{
					$q('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=$q('UserName1').value;
				obj_fra.getElementById('Password1').value=$q('Password1').value;				
				obj_fra.getElementById('LoginType1').value=$q('LoginType1').value;	
				obj_fra.getElementById('checkcode').value=$q('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('验证码错误');
			 	$q('check_img').src='http://pass.dipan.com/ValidateNumber.aspx?r='+Math.random();
			  $q('checkcode').focus();
			  break;
		default:
			alert("用户名或密码错误！");
			$q('check_img').src='http://pass.dipan.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>';
		//$q('login_top_div').className="nine";
	}
	else
	{   
		objLogin_In.style.display = "none";
		objLogin_Out.style.display = "";
		if($q('index_js_1')!=null)
		{
				for(var i=1;i<30;i++)
				{				
					if($q('index_js_'+i)!=null)
					{
							$q('index_js_'+i).href='javascript:please_login()';
							$q('index_js_'+i).target="_self";
					}
				}				
				
		}	
	}

}
function please_login()
{
	alert('请先登录。');	
	if($q('UserName1')!=null)
		$q('UserName1').focus();
}
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 showimg2()
{
	$q('check_img').style.display='';
	$q('check_img').src='http://pass.dipan.com/ValidateNumber.aspx?r='+Math.random();
}
window.onload=function()
{
	    
    	var r = new Request();
			var pid=r.QueryString["pid"];
			if(document.location.href=='http://sg.dipan.com/index.html?')
				pid=1;
			if(pid!="" && pid!=null)
			{
					var nextYear = new Date();
					nextYear.setYear(nextYear.getFullYear()+1);
					setCookie("sg_pid",pid,nextYear,"dipan.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,"dipan.com");
		 }
var uid = r.QueryString.aid;
    if (uid != "" && uid != null) {
        var nextYear = new Date;
        nextYear.setYear(nextYear.getYear() + 1);
        setCookie("sg_p_uid", uid, nextYear, "dipan.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,"dipan.com");
		 }	
		 //已经收藏
		 if(document.location.href.indexOf("?favorite")!=-1)
		 {
			var nextYear = new Date();
			nextYear.setYear(nextYear.getFullYear()+1);
			setCookie("dipan_cn_favorite","1",nextYear,"dipan.com");		
		 }

}
window.onbeforeunload=function()
{

		if(GetCookie("dipan_cn_favorite")=="" && GetCookie("dipan_cn_favorite_t")=="" && isclose && ($q('index_js_1')!=null))
		{
			var nextYear = new Date();			
			nextYear.setHours(nextYear.getHours()+24);			
			setCookie("dipan_cn_favorite_t","1",nextYear,"dipan.com");			
var title="《地盘 黑暗契约》今日新服！在线火爆！";
var url="http://qy.dipan.com/default.html?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)
{
   $q("tab_1").style.display="none";
   $q("tab_2").style.display="none";   
   $q("tab_3").style.display="none";
   $q("tab_"+id).style.display="";   	
}

function show_serverlist()
{
	if((GetCookie("5show_user_id") !=null) && (GetCookie("5show_user_id") !="-1") && (GetCookie("5show_user_id") !=""))
	{



	document.getElementById('dlg_message').style.display="";
	//document.getElementById('mask').style.display="";
	if($q('flash_div')!=null)
		$q('flash_div').style.visibility="hidden";
	//document.getElementById('mask').style.height=document.body.scrollHeight+"px";
 	//if(document.body.clientHeight>document.body.scrollHeight)
  //{
  // 			document.getElementById('mask').style.height=document.body.clientHeight+"px";
 	//}
 //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=(document.documentElement.scrollWidth-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";
	}
	show_server_list();
}

}


function close_layer()
{
		document.getElementById('dlg_message').style.display="none";
	  //document.getElementById('mask').style.display="none";	
	  if($q('flash_div')!=null)
	  	$q('flash_div').style.visibility="visible";
	  
}

function check_img_show()
{
	if(document.getElementById('check_img').src.indexOf('ValidateNumber')==-1)
	{
			showimg2();	
			document.getElementById('checkcode').value='';
			document.getElementById('check_img').style.display="";		
	}
}
