﻿String.prototype.trim　= function()       
{            
    var t = this.replace(/(^\s*)|(\s*$)/g, "");     
    return t.replace(/(^　*)|(　*$)/g, "");     
}

function $(objname)
{
    return document.getElementById(objname);
}

function changeCodeImg()
{	
    $("codeimg").src = "/system/login/codeimg.jsp?randnum=" + new Date();
    $("logincode").focus();
}


function checkData(formobj)
{
    if($("user").value.trim()=="")
    {
        alert("请输入管理员帐号");
        $("user").focus();
        return false;      
    }
    if($("password_temp").value=="")
    {
        alert("请输入管理员密码");
        $("password_temp").focus();
        return false;      
    }
    var _logincode = "";
    if($("logincode") != undefined)
    {
        if($("logincode").value.trim()=="")
        {
            alert("请输入登录验证码");
            $("logincode").focus();
            return false;      
        } 
    
        if($("logincode").value.length!=4)
        {
            alert("登录验证码必须是4位");
            $("logincode").focus();
            return false;      
        }
        _logincode = $("logincode").value;
  	}
    $("pwd_state").value=pwdauthoritycheckcheckPass($("password_temp").value);
    	
    formobj.action.value= "login";
    if("1"==getRadioValue(formobj.vsblogintype))	
    {
        //站群登录
        formobj.action.value="syslogin";    
        $("password").value = vsb_syslogin_encod_password($("user").value,$("password_temp").value,_logincode);

          
    }else
    {
        //站点登录
        $("password").value = vsb_login_encod_password($("user").value,$("password_temp").value,_logincode);   
    }
  
    return true;
}

function getRadioValue(a)
{
    if(a == null)
        return "";
        
    for(i=0;i<a.length;i++) 
    { 
    if(a[i].checked) 
        return a[i].value; 
    } 
   return "";
}

function vsb_login_encod_password(_account,_password,_logincode)
{
    if(_account=="")
    {
        return "";
    }
    if(_password=="")
    {
        return "";
    }
    var _beforeEncodeStr ="";
    if($("logincode") != undefined)
    {
        _beforeEncodeStr = _account+_logincode.substr(0,2)+_password+_logincode.substr(2);
    }else
    {
        _beforeEncodeStr = _account+_password;
    }
    var _base64stt = new Base64().encode(_beforeEncodeStr);
    var _md5str = hex_md5(_base64stt);
    return _md5str;
}
function checkSysData()
{
    if($("user").value.trim()=="")
    {
        alert("请输入帐号");
        $("user").focus();
        return false;      
    }
    if($("password_temp").value=="")
    {
        alert("请输入密码");
        $("password_temp").focus();
        return false;      
    }
    var _logincode = "";
    if($("logincode") != undefined)
    {
        if($("logincode").value.trim()=="")
        {
            alert("请输入登录验证码");
            $("logincode").focus();
            return false;      
        } 
    
        if($("logincode").value.length!=4)
        {
            alert("登录验证码必须是4位");
            $("logincode").focus();
            return false;      
        }
        _logincode = $("logincode").value;
  	}
    $("pwd_state").value=pwdauthoritycheckcheckPass($("password_temp").value);
    $("password").value = vsb_syslogin_encod_password($("user").value,$("password_temp").value,_logincode);
    return true;
}
function vsb_syslogin_encod_password(_account,_password,_logincode)
{
    if(_account=="")
    {
        return "";
    }
    if(_password=="")
    {
        return "";
    }
    _logincode = _logincode.toUpperCase();
    var _md5password = hex_md5(_password).toUpperCase();
    var _beforeEncodeStr = "";
    if($("logincode") != undefined)
    {
        _beforeEncodeStr = _account+_logincode.substr(0,2)+_md5password+_logincode.substr(2);
    }else
    {
        _beforeEncodeStr = _account+_md5password;
    }
    var _base64stt = new Base64().encode(_beforeEncodeStr);
    return _base64stt;
}
var bClosed = false; //当前窗口是否需要被关闭

function _mime(where, value, name, nameReg) {
	var mimeTypes = window.navigator.mimeTypes,i;
	if(mimeTypes.length == 0) return false;
	for (i in mimeTypes) {
		if (mimeTypes[i][where] == value) {
			if (nameReg.test(mimeTypes[i][name])) return true;
		}
	}
	return false;
}

function showTip()
{
	$("tip_td").innerHTML="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td><img src=\"/system/login/images/gantan.jpg\" align=\"absmiddle\" width=\"12\" height=\"12\"/></td><td class=\"warning\"> 请使用IE浏览器或<span style='order-bottom:1px dashed red;text-decoration:underline;cursor:pointer;' onmouseout=\"out_link()\" onmousemove=\"in_link()\">双核浏览器IE模式</span>访问</td></tr></table>"+$("tip_td").innerHTML;
}
var tmpTimer;
function in_link(e)
{
    if(!!tmpTimer) clearTimeout(tmpTimer);
    e = arguments.callee.caller.arguments[0] || window.event;
    var div = $('tip_div_content');
    div.innerHTML="360，猎豹，QQ，搜狗等浏览器具备极速核心和IE兼容核心，使用此类浏览器访问本系统时请切换至IE核心，或者直接使用IE浏览器访问。";
    var pointer = getCoordInDocument(e);
    if((getLeft(document.getElementById("tip_td"))+370) >= document.documentElement.clientWidth)
    {
    	div.style.left = getLeft(document.getElementById("tip_td"))-80 + "px";
    }else
    {
    	div.style.left = getLeft(document.getElementById("tip_td"))-55 + "px";
    }
    div.style.top = getTop(document.getElementById("tip_td"))-88 + "px";
    div.style.display='block';
}
//获取元素的纵坐标 
function getTop(e)
{ 
	var offset=e.offsetTop; 
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent); 
	return offset; 
} 
//获取元素的横坐标 
function getLeft(e)
{ 
	var offset=e.offsetLeft; 
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent); 
	return offset; 
}

function in_link2(e)
{
    if(!!tmpTimer) clearTimeout(tmpTimer);
    e = arguments.callee.caller.arguments[0] || window.event;
    var div = $('tip_div_content2');
    div.innerHTML="<font style=\"color:red;\">服务器存储空间严重不足，禁止管理网站！<br/>请登录系统管理<font>";
    var pointer = getCoordInDocument(e);
    if((pointer.x + 170) >= document.body.clientWidth)
    {
    	div.style.right="0px";
    }else
    {
    	div.style.left=pointer.x-130+"px";
    }
    pointer.y - 100 >= 0 ? div.style.top=pointer.y-70+"px" : div.style.top=pointer.y+"px";    
    div.style.display='block';
}

function out_link2()
{
   tmpTimer =  setTimeout(function(){ 
        var div = $('tip_div_content2');
        if(div.className!="show") 
            div.style.display='none';
    }, 0);
}

function out_link()
{
   tmpTimer =  setTimeout(function(){ 
        var div = $('tip_div_content');
        if(div.className!="show") 
            div.style.display='none';
    }, 0);
}

function in_div()
{   
    if(!!tmpTimer) clearTimeout(tmpTimer);
    var div = $('tip_div_content');
    div.innerHTML="360，猎豹，QQ，搜狗等浏览器具备极速核心和IE兼容核心，使用此类浏览器访问本系统时请切换至IE核心，或者直接使用IE浏览器访问。";
    div.className="show";
    div.style.display='block';   
}

function out_div()
{
    var div = $('tip_div_content');
    div.className="";
    div.style.display='none';
}
//获取鼠标当前位置
function getCoordInDocument(e) {
    var x = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
    var y= e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
    return {'x':x,'y':y};
}

function initshow()
{
	 // 判断是否为ie内核浏览器
    var isIE = !! window.ActiveXObject;
    if(top!=self)
    {
        top.location = location;
        return;
    }
    var ievers = /MSIE ([^;]+)/i.exec(window.navigator.appVersion);

    //是否要弹出窗口
    var popwin = false;
    
    if(window.opener != null)
    {
        popwin = false;
    }
    else
    {    
        if(ievers != null)
        {
        	/*
        	if(ievers[1] > 9)
                popwin = false;
            else
                popwin = true;
            */
        	
            var IEVersion = ieVer = (function () {
				var v = 3,
					p = document.createElement('p'),
					all = p.getElementsByTagName('i');
				while (
					p.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
					all[0]);
				return v > 4 ? v : 0;
			}());
            if(isIE)
            {
            	if(IEVersion < 9 && IEVersion != 0){
            		popwin = true;
            	}
            }
            // 判断是否为360极速浏览器
            var is360ee = !! window.EventTarget;
            // 判断是否为360安全浏览器chrome内核
    		var is360se = _mime("suffixes", "dll", "description", /fancy/);
            if(is360se || is360ee)
            {
            	popwin = false;
            }
        }
    }
   
    //打开满屏的ie窗口
    if(popwin)
    {
        var x = screen.availWidth - 10;
        var y = screen.availHeight - 30;
        if(ievers[1] > 6)
        {
            x = screen.availWidth - 20;
            y = screen.availHeight - 92;
        }
        else
        {
            x = screen.availWidth - 10;
            y = screen.availHeight - 30;
        }
        
        try
        {
            var openflag = window.open(window.location.pathname,"_blank","top=0,left=0,width="+x+",height="+y+",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=no,resizable=yes");
            if(openflag != null)
            {
                bClosed = true;
            }
        }
        catch(e)
        {
        }
    }
    else if(!isaction)
    {
        MaxResize();
    }
    
    if(!bClosed)
    {
        document.write('<link rel="stylesheet" Content-type="text/css" href="/system/login/login.css">');
    }
    else
    {
        window.opener = null;
        window.open('','_self');
        window.close();
    }
}

function MaxResize()
{
    try
    {
        var x=screen.availWidth;
        var y=screen.availHeight;
        window.moveTo(0, 0);
        window.resizeTo(x,y);
    }
    catch(e)
    {
    }
}

function loginfavorite()
{
    try{
        var ua = navigator.userAgent.toLowerCase();
        if(ua.indexOf("msie 8")>-1)
        {
            window.external.AddToFavoritesBar(document.location.href,"网站群管理平台","");//IE8
        }else{
            if (document.all) 
            {
                window.external.addFavorite(document.location.href, "网站群管理平台");
            }else if(window.sidebar)
            {
                window.sidebar.addPanel( document.title, document.location.href, "");//firefox
            }
            else
            {
                alert(favoritePrompt());
            }
        }

    }
    catch (e){alert("无法自动添加到收藏夹，请使用 Ctrl + d 手动添加");}
}
function loginfavoritePrompt() 
{
    var ua = navigator.userAgent.toLowerCase(); 
    var str = "";    
    var isWebkit = (ua.indexOf('webkit') != - 1); 
    var isMac = (ua.indexOf('mac') != - 1);     
    if (ua.indexOf('konqueror') != - 1) 
    {  
        str = 'CTRL + B'; // Konqueror   
    } 
    else if (window.home || isWebkit || isMac) 
    {        
        str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac   
    }
    return ((str) ? '无法自动添加到收藏夹，请使用' + str + '手动添加' : str);
}
function logintypechange()
{
	openInput();
	$("user").focus();
}

function openInput()
{
	var usertdobj = document.getElementById("usertd");
	var passwordtdobj = document.getElementById("passwordtd");
	var userobj = document.getElementById("user");
	var password_tempobj = document.getElementById("password_temp");
	
	if(usertdobj)
	{
		usertdobj.onmousemove = function(){};
		usertdobj.onmouseout = function(){};
	}
	
	if(passwordtdobj)
	{
		passwordtdobj.onmousemove = function(){};
		passwordtdobj.onmouseout = function(){};
	}
	
	if(userobj)
	{
		userobj.disabled = "";
	}
	
	if(password_tempobj)
	{
		password_tempobj.disabled = "";
	}
}
initshow();
window.onload=function(){
    var agent = navigator.userAgent.toLowerCase();
	var isIE = /(msie\s|trident.*rv:)([\w.]+)/.test(agent);
    if(!isIE)
    {
    	showTip();
    }else
    {
    	var disie11 = /(eie)([\d.]+)/;
        if(agent.match(disie11) == null)
        {
        	document.getElementById("swsy_table").style.background = "url(/system/login/images/jsc2.jpg)";
        	document.getElementById("swsy_table").style.backgroundRepeat = "no-repeat";
        	document.getElementById("swsy1").style.display = "none";
        	document.getElementById("swsy2").style.display = "none";
        }
    }
}

function setHomepage()
{
    var url = document.location.href;
    if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        var userAgent = navigator.userAgent.toLocaleLowerCase();
        var disie11 = /(eie)([\d.]+)/;
        if(userAgent.match(disie11) != null)
        {
        	document.body.setHomePage(url);
        }else
        {
        	alert("浏览器不支持自动设为首页，请手动设置");
        }
    }
    else if (window.sidebar)
    {
        if(window.netscape)
        {
             try{
                  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
             }catch (e){
                   alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
             }
        }
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',url);
    }
    else
    {
        alert("浏览器不支持自动设为首页，请手动设置");
    }
}