var gddress = window.location.href;
gddress = gddress.replace("http://","").split("/")[0];
var oldurladdress = window.location.href;
oldurladdress = oldurladdress.split("?eol")[0];
if(oldurladdress.split(".html")[1]!=null){
	oldurladdress="http://"+gddress+"/schoolhtm/schoolTemple/school"+schoolid+".htm"
}


//全局变量
var debug = true;
//用户模型
var code = "0";
var regcode="6";//默认未知
var al1= "您还没有登录！请使用EOL通行证登录后，完成此操作。";


function getSchoolId(){
	var oldhref= window.location.href;	
	if   (oldhref.indexOf("schoolTemple/")>=0)   
    {   
         var aCrumb = (oldhref.split("schoolTemple/"))[1].split(".");
         return aCrumb[0]; 
    }
	else
	{
	    if( typeof(schoolid)!='undefined' && schoolid!=null)
	    {
	      
	       return "school"+schoolid;
	    }
	    return "";
	}
	
}



function windowopen(){
	window.open ('/nologin.htm', 'newwindow', 'height=80, width=200, top=200,left=100, toolbar=0, menubar=no, scrollbars=no, resizable=0,location=no, status=no');
}

function noLogin(){
	alert("您还没有登录！请使用'EOL通行证登录'后，完成此操作。");
}


//注意内部数据以$开始
function CookieUser(){
	this.$cookie = new Cookie(document,"gkcx_eol_cn_user",null,"/",".eol.cn",false);
	this.$userid="";
	this.$username="";
	this.$password="";
	this.$manage=-1;
	this.$html2link=0;
	this.$roomId="";
	this.$nickname="";
	this.$lastTime="";
	this.$area=6;
	if(this.$cookie.load()){
		this.$userid=this.$cookie.userid;
		this.$username=this.$cookie.username;
		this.$manage=this.$cookie.manage;
		this.$roomId=this.$cookie.roomId;
		this.$html2link=this.$cookie.html2link; 
		this.$nickname=getCookieNickname("gkcx_eol_cn_user");
		this.$lastTime=this.$cookie.lastTime;
		this.$area=this.$cookie.area;
		
	}

	/*
	this.$userMenu='<form id="ssologinForm"  name="ssologinForm" method="post" action="http://reg.eol.cn/interface/sublogin.php">\
							EOL通行证：<input style="height:18px;font-size:11px;" size="10" name="email" id="username" type="text" value="Email地址" onfocus="this.select()" onblur="if (value ==\'\'){value=\'Email地址\'}" onclick="if(value==\'Email地址\'){value=\'\'}" onmouseover="this.focus()"/>\
							密码：<input style="height:18px;font-size:11px;" size="7" name="passwd" id="password" type="password" /><input  name="subcode" id="subcode" type="hidden" value="1002"/><input type="hidden" name="from" value="http://gkcx.eol.cn/htm/schoollogin/login'+getSchoolId()+'.jsf" /><input type="hidden" name="type" value="1" />\
						<input type="hidden" name="_acegi_security_remember_me" value="true" />\
						<input name="button2" type="submit" class="x_button" id="button2" value="登录" style="height:20px;" align="middle" />\
							<a href="http://reg.eol.cn/register.php?url=http://gkcx.eol.cn/" class="green">注册</a>\
					</form>';
	*/
	
	this.$userMenu='<form id="ssologinForm"  name="ssologinForm" method="post" action="http://reg.eol.cn/interface/sublogin.php">\
					<div id="gkcx_top_login">\
					  <strong class="z_blue01_12b">EOL通行证：</strong>\
					  <input type="text" class="input_120" style="font-size:11px" value="Email地址" name="email" id="username" type="text" value="Email地址" onfocus="this.select()" onblur="if (value ==\'\'){value=\'Email地址\'}" onclick="if(value==\'Email地址\'){value=\'\'}" onmouseover="this.focus()"/>\
				        &nbsp;&nbsp;&nbsp;&nbsp;<strong class="z_blue01_12b"> 密码：</strong>\
						<input type="password" name="passwd" id="password" class="input_65" />\
						<input  name="subcode" id="subcode" type="hidden" value="1002"/>\
						<input type="hidden" name="from" value="http://"+gddress+"/htm/schoollogin/login'+getSchoolId()+'.jsf" />\
						<input type="hidden" name="type" value="1" />\
						<input type="hidden" name="_acegi_security_remember_me" value="true" />\
						&nbsp;&nbsp;<input name="Submit" type="image" value="提交" src="/images/g_button_login.jpg" align="top" />\
						&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://reg.eol.cn/register.php?url=http://"+gddress+"/">注册</a></div>\
					</form>';
					
					
	this.$orderSchoolButton = '<a href="javascript:void(0)" onclick="windowopen()">\
					        		<font color="red">关注高校</font>\
					           </a>';
					
}



CookieUser.prototype.store = function(){
	//this.$cookie.userid = "";//this.$userid;
	this.$cookie.username = "";//this.$username;	
	this.$cookie.nickname =	"";//this.$nickname;
	this.$cookie.manage = -1;//this.$manage;
	this.$cookie.roomId = "";//this.$roomId;
	this.$cookie.html2link = 0;//this.$html2link;
	this.$cookie.lastTime = "";
	this.$cookie.area = 6;
	this.$cookie.store();

}








//logout参数设定
var oldhref= window.location.href;
var furl = "http://reg.eol.cn/interface/sublogout.php?from="+oldurladdress;//"http://reg.eol.cn/interface/sublogout.php?from=http://"+gddress+"/userpages/logout.jsf?rurl="+oldhref;


//显示用户登录后的菜单
CookieUser.prototype.showLoginMenu=function(){
	var menu="";
	//if(this.$manage=='1' && getSsoStatus()){
	if(this.$manage=='1'){
		this.$userMenu='欢迎你，'
						+'<font style="color:red">'+ this.$nickname +'</font>'
						+' | <a href="http://i.eol.cn/" class="blue">个人中心</a>'
						+' | <a href="'+furl+'" class="blue" style="font-size:12px;">退出</a>';
	
		this.$orderSchoolButton = '<a href="http://i.eol.cn/school_order.php?action=add&takeid=gkcx&takevalue='+schoolcode+'">\
					        		<font color="red">关注高校</font>\
					        	   </a>';
	}else if(this.$manage=='0'){
		this.$userMenu='冻结用户!'
						+ this.$nickname
						+'<a href="http://reg.eol.cn/interface/sublogout.php?from=http://gkcx.eol.cn/userpages/logout.jsf" class="blue" style="font-size:12px;">退出登录</a>';
	}
	$('userMenu1').innerHTML = this.$userMenu;
	
}

var user = new CookieUser();
//alert("manage: "+user.$manage+" ,   html2link: "+user.$html2link);



function getCookieNickname(cookie_name)
{
   
    var aCookie = document.cookie.split("; ");
    for (var i=0; i<aCookie.length; i++)
    {
       
        var aCrumb = aCookie[i].split("=");
        if (cookie_name == aCrumb[0])
        {
            var gcc = aCrumb[1].split(":");
            var nickname = (gcc[2].split("&"))[0];
            if(nickname.indexOf("%40")>=0){
            	nickname = nickname.replace("%40","@");
            }
            if(nickname.indexOf("+")>=0){
            	nickname = nickname.replace("+"," ");
            }
			return decodeURI(nickname);
        }
    }
    return "gkcx cookie not found!";
}


function getCookie(cookie_name)
{
   
    var aCookie = document.cookie.split("; ");
    for (var i=0; i<aCookie.length; i++)
    {
       
        var aCrumb = aCookie[i].split("=");
        if (cookie_name == aCrumb[0])
        {	
        	return aCrumb[1];
        }
    }
    // a cookie with the requested name does not exist
    //return null;
    return "not found";
}

function getSsoStatus(){
	if (getCookie('REG1002')=='Y')
		return true;
	else 
		return false;
}


function deleteCookie2(name,path,domain){
 document.cookie = name + "=" +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}






function getLoginBackUrlo(){
	var oldhref= window.location.href;
		return oldhref.substring(0,8+oldhref.substring(8,oldhref.length).indexOf('/')) +'/j_acegi_eolsso_security_check?rurl='+encodeURIComponent(oldhref);//?rurl='+encodeURIComponent(window.location.href));

}


function getLoginBackUrl(){
	var oldhref= window.location.href;
		return oldhref.substring(0,8+oldhref.substring(8,oldhref.length).indexOf('/')) +'/schoolhtm/schoollogin/login'+getSchoolId()+'.jsf';
	
}

//alert("reg1002:"+getCookie('REG1002')+", reg1001:"+getCookie('REG1001')+", manager:"+user.$manage);

function getEolUserName(){
	return getCookie("eol_name");
}


/*
// 调用函数
if (getSsoStatus() && user.$manage==-1) {//登录用户
	user.$html2link = 1;
	window.location.href='http://reg.eol.cn/interface/sublink.php?type=2&from='+getLoginBackUrlo();
	deleteCookie2('REG1002','/','.eol.cn');	
}else if(getSsoStatus() && user.$manage!=-1 && getCookie('REG1001')=="N"){//切换用户
	user.$html2link = 1;
	window.location.href='http://reg.eol.cn/interface/sublink.php?type=2&from='+getLoginBackUrlo();
	deleteCookie2('REG1002','/','.eol.cn');
}else if(getSsoStatus() && user.$manage!=-1 && getCookie('REG1001')!="N"){
	window.location.href='http://reg.eol.cn/interface/sublink.php?type=2&from='+getLoginBackUrl();
	deleteCookie2('REG1002','/','.eol.cn');
}else if(getCookie('REG1001')=="not found" && user.$manage!=-1){//退出用户
	window.location.href=furl;
}
*/



