if(typeof Auth == 'undefined')
{
function AuthClass(){}
AuthClass.prototype.user =function()
{
    var _user={'utype':'','uid':'','username':''}
    _user.utype = GetCookie("izl_login_type");
    _user.uid = GetCookie("izl_login_uid"); 
    _user.name = GetCookie("izl_login_username");
    return _user;
}
AuthClass.prototype.utype =function()
{
    var _user = this.user();
    return _user.utype;
}
AuthClass.prototype.uid =function()
{
    var _user = this.user();
    return _user.uid;
}
AuthClass.prototype.username =function()
{
    var _user = this.user();
    return _user.name;
}
AuthClass.prototype.isLogin =function()
{
    var _user = this.user();
    return (_user.uid && _user.name);
}
Auth = new  AuthClass();

}
function EncodeUtf8(s1)
{
    var s = escape(s1);
    var sa = s.split("%");
    var retV ="";
    if(sa[0] != "")
    {
        retV = sa[0];
    }
    for(var i = 1; i < sa.length; i ++)
    {
        if(sa[i].substring(0,1) == "u")
        {
            retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5)));

        }
        else retV += "%" + sa[i];
    }
    return retV;
}
function Str2Hex(s)
{
    var c = "";
    var n;
    var ss = "0123456789ABCDEF";
    var digS = "";
    for(var i = 0; i < s.length; i ++)
    {
        c = s.charAt(i);
        n = ss.indexOf(c);
        digS += Dec2Dig(eval(n));

    }
    //return value;
    return digS;
}
function Dec2Dig(n1)
{
    var s = "";
    var n2 = 0;
    for(var i = 0; i < 4; i++)
    {
        n2 = Math.pow(2,3 - i);
        if(n1 >= n2)
        {
            s += '1';
            n1 = n1 - n2;
        }
        else
            s += '0';

    }
    return s;

}
function Dig2Dec(s)
{
    var retV = 0;
    if(s.length == 4)
    {
        for(var i = 0; i < 4; i ++)
        {
            retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
        }
        return retV;
    }
    return -1;
} 
function Hex2Utf8(s)
{
    var retS = "";
    var tempS = "";
    var ss = "";
    if(s.length == 16)
    {
        tempS = "1110" + s.substring(0, 4);
        tempS += "10" +  s.substring(4, 10); 
        tempS += "10" + s.substring(10,16); 
        var sss = "0123456789ABCDEF";
        for(var i = 0; i < 3; i ++)
        {
            retS += "%";
            ss = tempS.substring(i * 8, (eval(i)+1)*8);



            retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
            retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
        }
        return retS;
    }
    return "";
}
function transform(s) 
{ 
    var hex=''    
        var i,j,t 

        j=0 
        for (i=0; i<s.length; i++) 
        { 
            t = hexfromdec( s.charCodeAt(i) ); 
            if (t=='25') 
            { 
                t=''; 
            } 
            hex += '%' + t; 
        } 
    return hex; 
} 

function hexfromdec(num) { 
    if (num > 65535) { return ("err!") } 
    first = Math.round(num/4096 - .5); 
    temp1 = num - first * 4096; 
    second = Math.round(temp1/256 -.5); 
    temp2 = temp1 - second * 256; 
    third = Math.round(temp2/16 - .5); 
    fourth = temp2 - third * 16; 
    return (""+getletter(third)+getletter(fourth)); 
} 

function getletter(num) { 
    if (num < 10) { 
        return num; 
    } 
    else { 
        if (num == 10) { return "A" } 
        if (num == 11) { return "B" } 
        if (num == 12) { return "C" } 
        if (num == 13) { return "D" } 
        if (num == 14) { return "E" } 
        if (num == 15) { return "F" } 
    } 
}
function GetCookie(name) 
{ 
    var mycookie = document.cookie;
    var start1 = mycookie.indexOf(name + "="); 
    if (start1== -1) 
        return false;
    else 
    { 
        start=mycookie.indexOf("=",start1)+1;  
        var end = mycookie.indexOf(";",start); 
        if (end==-1) 
        { 
            end=mycookie.length;
        } 
        var value=unescape(mycookie.substring(start,end)); 
        return value;
    } 
}
function init_login_status()
{
    var login_type		= Auth.utype();
    var login_username  = decodeURI(EncodeUtf8(Auth.username()));
    var login_uid       = Auth.uid();
    var doc = arguments[0];
    if(!doc)doc = window.document;
    var log_html='';
    if(!Auth.isLogin())
    {
        doc.login_uid = 0;
        doc.login_username = null;

        log_html +='<p><a href="http://www.izhiliao.com/uc/login.php" title="">登录</a> | <a href="http://www.izhiliao.com/uc/reg.php" title="">注册</a></p>';
    }
    else
    {
        doc.login_uid = login_uid;
        doc.login_username = login_username;
        
		log_html +='<p>欢迎您， '+ login_username +' <a href="http://www.izhiliao.com/uc/logout.php" title="">退出</a></p>';
    }
    doc.getElementById('m_operate').innerHTML=log_html;

}
function page_loginst()
{
    var login_type		= Auth.utype();
    var login_username  = decodeURI(EncodeUtf8(Auth.username()));
    var str = "";
    if(!Auth.isLogin())
    {
        str += "<div id=\"loginarea\">";
		str += "<h2><img src=\"/static/img/h2_loginarea.jpg\" width=\"235\" height=\"32\" alt=\"登录\" /></h2>";
		str += "<div class=\"bd\"><form method=\"post\" action=\"http://www.izhiliao.com/uc/dologin.php\">";
		str += "<table cellspacing=\"0\"><tr><th>帐号</th>";
		str += "<td><input type=\"text\" class=\"input_text\" name=\"uname\" id=\"uname\" tabindex=\"1\"/></td>";
		str += "</tr><tr><th>密码</th>";
		str += "<td><input type=\"password\" class=\"input_pw\" name=\"pwd\" id=\"pwd\" tabindex=\"2\"/></td>";
		str += "</tr><tr><th>验证码</th>";
		str += "<td><input type=\"text\" class=\"input_text short\" name=\"yzm\" id=\"yzm\" tabindex=\"3\"/> <img src=\"http://www.izhiliao.com/yzm.php\" id=\"identifypic\" onclick=\"document.getElementById('identifypic').src='/yzm.php?t='+Math.random()\"/></td>";
		str += "</tr><tr class=\"submitarea\"><th>&nbsp;</th>";
		str += "<td><input type=\"submit\" class=\"input_submit\" value=\"登录\" /></td>";
		str += "</tr></table></form>";
		str += "<p class=\"reg\"><a href=\"http://www.izhiliao.com/uc/reg.php\" title=\"\">新用户注册</a></p>";
		str += "</div></div>";
    }
    else
    {
		str += "<div id=\"uccenter\">";
		str += "<h2><img src=\"/static/img/h2_uccenter.jpg\" width=\"235\" height=\"32\" alt=\"管理中心\" /></h2>";
		str += "<div class=\"bd\"><div>欢迎您，" + login_username + "</div><ul>";
		str += "<li class=\"sms\"><a href=\"http://www.izhiliao.com/uc/ucdata.php?et=4\" title=\"\">短信记录</a></li>";
		str += "<li class=\"tel\"><a href=\"http://www.izhiliao.com/uc/ucdata.php?et=1\" title=\"\">通话记录</a></li></ul>";
		str += "<div><a href=\"http://www.izhiliao.com/uc/modinfo.php\" title=\"\">资料修改</a> <a href=\"http://www.izhiliao.com/uc/modpsw.php\" title=\"\">修改密码</a></div>";
		str += "<div><a href=\"http://www.izhiliao.com/uc/ucdata.php\" title=\"\" class=\"btn_enteruc\">进入我的管理中心</a></div>";
		str += "</div></div>";
    }
    document.write(str); 
}
