var loginuid;
var loginuname;

function sAlert(){
//	var eSrc=(document.all)?window.event.srcElement:arguments[1];
	var shield = document.createElement("div");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = document.body.scrollHeight+"px";
	shield.style.background = "#333";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;
	var alertFram = document.createElement("div");
	alertFram.id="alertFram";
	alertFram.style.position = "absolute";
	alertFram.style.left = "50%";
	alertFram.style.top = "50%";
	alertFram.style.marginLeft = "-205px" ;
	alertFram.style.marginTop = -75+document.documentElement.scrollTop+"px";
	alertFram.style.width = "410px";
	alertFram.style.height = "260px";
	alertFram.style.background = "#333";
	alertFram.style.zIndex = "10001";
	
	
	strHtml = '<div class="Login_wrap">\n';
	strHtml = strHtml +'<div class="Login_content">\n';
	strHtml = strHtml +'<a href="#" title="关闭"><img src="http://www.8jnet.com/images/8jnet_p_cha.gif" alt="关闭" title="关闭" id="do_OK" onclick="doOk()" class="login_close_img" /></a>\n';
	strHtml = strHtml +'<h2><span class="below"><a href="http://login.8jee.com/reg.jsp" title="快速注册">快速注册?</a></span>用户登录</h2>\n';
	strHtml = strHtml +'<table height="200" width="78%" border="0" align="center" cellpadding="2" cellspacing="2">\n';
	strHtml = strHtml +'<form id="form1" name="login" method="post" action="http://login.8jee.com/login.jsp" onsubmit="return checkForm();" target="_self">\n';
	strHtml = strHtml +'<tr><td width="21%" align="right">帐号：</td>\n';
	
	
	strHtml = strHtml +'<td colspan="2"><input name="username" type="text" onfocus="this.className=\'login_input Hot_input\'" onblur="this.className=\'login_input\'" class="login_input" />';
	strHtml = strHtml +'<input name=\"savecookic\" type=\"hidden\" value=\"yes\"/></td>\n';
	strHtml = strHtml +'</tr><tr><td align="right">密码：</td>\n';
	strHtml = strHtml +'<td colspan="2"><input name="password" type="password" onfocus="this.className=\'login_input Hot_input\'" onblur="this.className=\'login_input\'" class="login_input" /><input name="url" type="hidden" value="" /></td>\n';
	strHtml = strHtml +'</tr><tr><td height="40">&nbsp;</td><td width="35%"><input name="submit" type="submit" class="C_sub_input" value="登 录" onclick="return tosubmit(this);" /></td>\n';
	strHtml = strHtml +'<td width="44%"><input name="submit2" type="button" id="do_OK" onclick="doOk()" class="C_sub_input2" value="取 消" /></td>\n';
	strHtml = strHtml +'</tr><tr><td height="21">&nbsp;</td><td colspan="2" class="below"><a href="http://login.8jee.com/getpasswd.jsp" target="_blank">找回密码？</a></td>\n';
	strHtml = strHtml +'</tr><tr><td height="21" colspan="3" class="Orange" align="center">请输入八界网通行证用户名和密码登录</td>\n';
	strHtml = strHtml +'</tr></table></form></div></div>\n';
	alertFram.innerHTML = strHtml;
	document.body.appendChild(alertFram);
	document.body.appendChild(shield);
	this.setOpacity = function(obj,opacity){
		if(opacity>=1)opacity=opacity/100;
		try{ obj.style.opacity=opacity; }catch(e){}
		try{ 
			if(obj.filters.length>0&&obj.filters("alpha")){
				obj.filters("alpha").opacity=opacity*100;
			}else{
				obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
			}
		}catch(e){}
	}
	var c = 0;
	this.doAlpha = function(){
		if (++c > 20){clearInterval(ad);return 0;}
		setOpacity(shield,c);
	}
	var ad = setInterval("doAlpha()",1);
	this.doOk = function(){
		//alertFram.style.display = "none";
		//shield.style.display = "none";
		document.body.removeChild(alertFram);
		document.body.removeChild(shield);
//		eSrc.focus();
		document.body.onselectstart = function(){return true;}
		document.body.oncontextmenu = function(){return true;}
	}
	document.getElementById("do_OK").focus();
//	eSrc.blur();
	document.body.onselectstart = function(){return false;}
	document.body.oncontextmenu = function(){return false;}
}
function tosubmit() {
	document.login.url.value=this.location.href;
}// JavaScript Document

function checkTextDataForENGLISH(strValue) {
	var regTextEnglish = /^[a-zA-Z0-9]*$/;
	return regTextEnglish.test(strValue);
}

function checkForm() {
	var uname = document.all.username.value.trim();
	var passwd = document.all.password.value.trim();
	if(uname == "" || passwd=="") {
		alert('请输入用户名和密码');
		return false;
	}
	if (!checkTextDataForENGLISH(uname)){
	    alert("尊敬得用户，由于八界网改版成功，所有会员用户名将只容许英文、数字组合,请您用上几秒钟修改你得用户信息!");  
		this.location.href='http://login.8jnet.com/reg_gai.jsp';
		return false;
	 }
}
////////////////////////////////////////////////////////////////////////////
function getCookie(namex)
{
	var cookieHeader = namex + "=";
	var cookies = document.cookie;
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}

function setCookie(sName,lmid,lmname,iTime) {
	var date = new Date();
	date.setTime(date.getTime()+iTime*1000);
	document.cookie = escape(sName) + "=" + escape(lmid+";"+lmname) + ";expires=" + date.toGMTString();
}

function readCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (escape(sName) == aCrumb[0])
		return unescape(aCrumb[1]);
	}
	return "";
}

function delCookie(sName){
	var date = new Date();
	document.cookie = escape(sName)+"=;expires="+date.toGMTString();
}

function checklogin() {
	var site = getCookie("site");
	var urs = getCookie("urs");
	
	var Head_logon = document.getElementById("loginno");
	var Head_logon_succeed = document.getElementById("loginok");
	
	if ( site!="" && urs!="" ){
		var tmpstr = site.split("|");
		if(tmpstr.length==2) {
		    loginuid = tmpstr[1];
		    loginuname = tmpstr[0];
		    try {
		    	var con = "<p id=\"loginuname\">欢迎 <b>"+tmpstr[0]+"</b></p>"+
						"<p><a href=\"javascript:logout2()\" target=\"_self\">退出</a> | <a href=\"#\#\#\" target=\"_self\" onclick=\"showtools();\" title=\"快速入口\">我的八界<img src=\"http://www.8jnet.com/images/manage_tools.gif\" align=\"absmiddle\" alt=\"快速入口\" /></a></p>"+
						"<div class=\"Tools_menu_nav\" id=\"tools\" style=\"display: none;\">"+
							"<ul class=\"menu_nav\">"+
								"<li><a href=\"http://"+tmpstr[0]+".blog.8jnet.com/manage.jsp\" target=\"_self\">管理中心</a></li>"+
								"<li><a href=\"http://"+tmpstr[0]+".blog.8jnet.com\" target=\"_self\">我的掘客</a></li>"+
								"<li><a href=\"http://photo.8jnet.com/myalbum.jsp\" target=\"_self\">我的相册</a></li>"+
								"<li><a href=\"http://"+tmpstr[0]+".blog.8jnet.com/artcpublish.jsp\" target=\"_self\">美味分享</a></li>"+
								"<!-- <li><a href=\"http://tv.8jnet.com/tv_user.asp\">我的视频</a></li> -->"+
								"<li><a href=\"http://recipes.8jnet.com/addfood.jsp\" target=\"_self\">添加菜谱</a></li>"+
								"<li><a href=\"http://shop.8jnet.com/addshop.jsp\" target=\"_self\">添加商家</a></li>"+
							"</ul>"+
						"</div>"
		        document.getElementById("loginok").innerHTML = con;
		    }
		    catch(e)
		    {}
		    Head_logon.style.display="none";
		    Head_logon_succeed.style.display="";
		} else {
			Head_logon.style.display="";
			Head_logon_succeed.style.display="none";
		}	    
	} else {
		Head_logon.style.display="";
		Head_logon_succeed.style.display="none";
	}
}

function showtools(){
	var display = document.getElementById('tools').style.display;
	document.getElementById('tools').style.display=display=="none"?"":"none";
}

function changloaction(url) {
	window.location=url;
}
