﻿// JScript 文件
var the_timeout;
var LoginSkinFlag = 0;//skin vertical or horizontal 
var CartPanel = false;
window.attachEvent("onload",bindUser);

function bindUser()
{
//每2秒执行一次，为了防止在多页中的一页登录或登出时，保持多页登录面板的同步和一致 

the_timeout = setTimeout("bindUser();",2000);
var LoginPanel_H = "<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\" bgColor=\"#000000\"><tr>";
	LoginPanel_H += "<td width=\"19%\" class=\"14_white\" ><b><IMG height=\"38\" src=\"http://Image.top100.cn/WebImg/icon_log.gif\" width=\"190\"><\/b><\/td><td width=\"34%\" class=\"color_balck\"><font color=\"#FF9900\">当前用户:<SPAN id=\"Login1_lbCurrUser\"><\/SPAN><img style=\"border:0px;cursor:hand;\" src=\"http://image.top100.cn/webImg/icon_user.gif\"/><SPAN id=\"showUserName\" style=\"font-weight:bolder;position:relative;left:4px;\"><\/SPAN><\/font><\/td>";
	LoginPanel_H += "<td width=\"12%\" class=\"color_balck\"><img style=\"CURSOR: hand\" onClick=\"Logout()\" alt=\"\" src=\"http:\/\/www.top100.cn\/Images\/icon_logout.gif\" border=\"0\"><\/td>";
	LoginPanel_H += "<td width=\"35%\" class=\"color_balck\"><a href=\"\http://www.top100.cn/UserManage\/UserManage.aspx\" target=\"_blank\"><img id=\"Login1_ibtMana\" alt=\"\" src=\"http:\/\/www.top100.cn\/Images\/icon_mana.gif\" border=\"0\"><\/a><\/td><\/tr><\/table>";
var LoginPanel_V="<table width=\"190\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"36\" valign=\"top\" background=\"http://image.top100.cn/webimg/0823_icon_log.gif\"><table width=\"100%\" height=\"28\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"21%\">&nbsp;</td><td width=\"79%\" valign=\"bottom\"><div align=\"left\" class=\"a2\"><strong>登&nbsp;&nbsp;录</strong></div></td></tr></table></td></tr><tr><td background=\"http://image.top100.cn/webimg/0823_icon_log_bj.gif\">     <TABLE class=\"style7\" id=\"Table2\" cellSpacing=\"0\" cellPadding=\"0\" align=\"center\" border=\"0\"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD width=\"105\"><DIV align=\"center\"><SPAN id=\"Login1_lbCurrUser\"><FONT style=\"FONT-WEIGHT: normal; FONT-SIZE: x-small; COLOR: orange; FONT-FAMILY: 宋体\" color=\"#ff9933\">&nbsp;&nbsp;&nbsp;当前用户:</FONT></SPAN></DIV></TD><TD width=\"105\"><DIV><FONT style=\"FONT-WEIGHT: normal; FONT-SIZE: small; COLOR: orange; FONT-FAMILY: 宋体\"><SPAN id=\"showUserName\"></SPAN></FONT></DIV></TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD width=\"105\"><DIV align=\"center\"><IMG style=\"CURSOR: hand\" onclick=\"exit()\" alt=\"\" src=\"http://Image.top100.cn/WebImg/icon_logout.gif\" border=\"0\"></DIV></TD><TD><A href=\"/UserManage/UserManage.aspx\"><IMG id=\"Login1_ibtMana\" alt=\"\" src=\"http://Image.top100.cn/WebImg/icon_mana.gif\" border=\"0\"></A></TD></TR></TABLE>      </td></tr><tr><td height=\"14\" background=\"http://image.top100.cn/webimg/0823_icon_log_d.gif\"></td></tr></table>";
var userName=readCookie("userName");
var userID=readCookie("userID");


//当cookie中存在userName时，表明是登录状态 
if(userName!="")
{
    
    clearTimeout(the_timeout);
   
    //当用户从其它的Web应用登录时，用以下的异步方法来把此用户的登录信息写入Session
    UserLoginRelated.NotifySessionAdd(userName,NotifySessionAdd_CallBack);
   
    switch (LoginSkinFlag)
    {
      case 0: 
			document.getElementById("logined_Panel").innerHTML = LoginPanel_V;
            break;
      case 1: 
			document.getElementById("logined_Panel").innerHTML = LoginPanel_H;
            break;
    }
    document.getElementById("password").value="" ;
    if(userID!="")
	{
	document.getElementById("showUserName").innerHTML="<a target='_self' href=\"http://user.top100.cn/HomePage.aspx?userID="+userID+"\" title='进入我的首页' ><font style=\"COLOR: #bf2327\">"+userName+"</font></a>";
	}
	else
	{
	document.getElementById("showUserName").innerHTML=userName;
	}
    document.getElementById("login_Panel").style.display='none';
    document.getElementById("logined_Panel").style.display='';
  
 }
else
 {
//当从其它的Web应用退出时，也要通知Session，将它从之中删除。
    
    UserLoginRelated.NotifySessionRemove(NotifySessionRemove_CallBack);
    document.getElementById("login_Panel").style.display='';
    document.getElementById("logined_Panel").innerHTML="";
    document.getElementById("logined_Panel").style.display='none';
    var div=document.getElementById("uploadPhoto");
    if(div!=null)
    div.innerHTML="";
    
 }
}

function NotifySessionAdd_CallBack(response)
{
   
}

function NotifySessionRemove_CallBack(response)
{

}

function login()
{
if(document.getElementById("userName").value=="" ){alert(unescape('用户名不能为空!'));return;}
if(document.getElementById("password").value=="" ){alert(unescape('密码不能为空!'));return;}

UserLoginRelated.Login(document.getElementById("userName").value,document.getElementById("password").value,Login_CallBack);
}


function Login_CallBack(res)
{
   //登录出现错误时，显示提示。
   if(res.error != null){ alert(res.error);return;}
   //如果返回值为true时，则绑定登录的用户，且转到当前用户登录后能显示当前页
   if(res.value) 
     {  
        //在登录面板上绑定当前登录的用户
        bindUser();
     }
   else
     {
        alert("用户名或密码错误!");
     }   

}

function Logout()
{
  UserLoginRelated.Logout(Logout_CallBack);
}
function Logout_CallBack(res)
{  
   
   if(res.error != null)
     { 
       alert(res.error);
       return;
     } 
     //在登录面板上重新绑定当前登录的用户，实际上是不再显示此用户的信息 
     bindUser();
     //转到当前用户注销后能显示的当前页，登录和注销时的页不同，注销后显示的页不可编辑
     
     
}