﻿/*topnvai*/
function denglu_onclick() {
    var strUserName = document.getElementById("topNaviId_txtUserName").value;
    if (strUserName == "") {
        alert("请输入用户名!");
        document.getElementById("topNaviId_txtUserName").focus();
        return false;
    }
    var strUserPwd = document.getElementById("topNaviId_txtUserPwd").value;
    if (strUserPwd == "") {
        alert("请输入用户密码!");
        document.getElementById("topNaviId_txtUserPwd").focus();
        return false;
    }
    var strvcode = document.getElementById("topNaviId_ValidCodeId").value;
    if (strvcode == "") {
        alert("请输入验证码!");
        document.getElementById("topNaviId_ValidCodeId").focus();
        return false;
    }
    if (strUserPwd.length != 32) {
        strUserPwd = hex_md5(strUserPwd);
        document.getElementById("topNaviId_txtUserPwd").value = strUserPwd;
    }
    if (document.getElementById("topNaviId_save_pwd").checked) {
        setCookie("User_name", strUserName);
        setCookie("User_pwd", strUserPwd);
    } else {
        cookie_name = getCookie("User_name");
        if (cookie_name != null && cookie_name != "") {
            deleteCookie("User_name");
        }
        cookie_pwd = getCookie("User_pwd");
        if (cookie_pwd != null && cookie_pwd != "") {
            deleteCookie("User_pwd");
        }
    }
    var result = FeiDuMagazine.BLL.AjaxLogin.Login(strUserName, strUserPwd, false, strvcode, "").value;
    var crurl = window.location.href;
    if (result == "登录成功") {

        //document.getElementById("topNaviId_BtnLoginId").click();

        var isNofresh = FeiDuMagazine.BLL.AjaxLogin.IsNoFresh(crurl).value;
        if (isNofresh == "true") {

            closeWin();
            var innerhtml = "<li><b>欢迎</b></li>" +
			                "<li>" + strUserName + "</li>" +
			                "<li><a href=\"/space/index.aspx\" class=\"loginon_a\">我的主页</a></li>" +
			                "<li><a href=\"/space/MyBookstand.aspx\" class=\"loginon_a\">我的书架</a></li>" +
			                "<li class=\"quit\"><a href=\"#\" onclick=\"outLogin()\">[退出]</a\></li>"
            document.getElementById("invleftul").innerHTML = innerhtml;
        } else {

            document.getElementById("topNaviId_BtnLoginId").click();
        }


    } else {
        alert(result);
        return false;
    }
    if (window.event) //IE
    {
        window.event.returnValue = false;   //event.returnValue=false 效果相同.
    }
    else //Firefox
    {
        e.preventDefault();
    }
    //document.getElementById("topNaviId_BtnLoginId").click();
    return false;
}
function outLogin() {
    document.getElementById("topNaviId_LinkButton1").click();
}

function href() {
    var randomnum = Math.random();
    var getimagecode = document.getElementById("Image1");
    getimagecode.src = "/imgvil.aspx?r=" + randomnum;
}

document.onkeydown = function(evt) {
    var evt = window.event ? window.event : evt;
    if (evt.keyCode == 13) {
        var wind1 = document.getElementById("wind1");
        if (wind1.style.visibility == "visible") {
            denglu_onclick();
        } else {
            var myAlert = document.getElementById("UserID_alertbody");
            if (myAlert != null) {
                if (myAlert.style.display == "block") {
                    denglu_onclick1();
                }
            } else {
                var rgAlert = document.getElementById("alert");
                if (rgAlert != null) {
                    if (rgAlert.style.display == "block") {
                        denglu_onclick1();
                    }
                } else {
                    var el = window.event ? evt.srcElement : evt.target;
                    var vid = document.getElementById("headq").id;
                    if (el.id == vid) {
                        BtnSearchData('head')
                    }
                }
            }

        }
    }
}

window.onerror = function() {
    return true; //不显示脚本错误信息
}

function getfreshimg() {
    var randomnum = Math.random();
    var freshimg = document.getElementById("fresh");
    freshimg.src = "/MagaFreshSn.aspx?r=" + randomnum;
}
// 这一就是进行定时执行,也就是隔19分钟执行一次.

var timer = new Timer("getfreshimg();", 1000 * 60 * 19, 5, false);
timer.Start();

/*cookie*/

// utility function to retrieve an expiration date in proper

// format; pass three integer parameters for the number of days, hours,

// and minutes from now you want the cookie to expire (or negative

// values for a past date); all three parameters are required,

// so use zeros where appropriate

function getExpDate(days, hours, minutes) {

    var expDate = new Date();

    if (typeof days == "number" && typeof hours == "number" &&

        typeof hours == "number") {

        expDate.setDate(expDate.getDate() + parseInt(days));

        expDate.setHours(expDate.getHours() + parseInt(hours));

        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));

        return expDate.toGMTString();

    }

}



// utility function called by getCookie( )

function getCookieVal(offset) {

    var endstr = document.cookie.indexOf(";", offset);

    if (endstr == -1) {

        endstr = document.cookie.length;

    }
    return unescape(document.cookie.substring(offset, endstr));

}


// primary function to retrieve cookie by name

function getCookie(name) {//获取Cookie
    name = escape(name);

    var arg = name + "=";

    var alen = arg.length;

    var clen = document.cookie.length;

    var i = 0;

    while (i < clen) {

        var j = i + alen;

        if (document.cookie.substring(i, j) == arg) {

            return unescape(getCookieVal(j));

        }

        i = document.cookie.indexOf(" ", i) + 1;

        if (i == 0) break;

    }

    return "";

}



// store cookie value with optional details as needed

function setCookie(name, value, expires, path, domain, secure) {
    name = escape(name);
    value = escape(value);
    document.cookie = name + "=" + escape(value) +

        ((expires) ? "; expires=" + expires : "") +

        ((path) ? "; path=" + path : "") +

        ((domain) ? "; domain=" + domain : "") +

        ((secure) ? "; secure" : "");
    //        alert(document.cookie);

}



// remove the cookie by setting ancient expiration date

function deleteCookie(name, path, domain) {

    if (getCookie(name)) {

        document.cookie = name + "=" +

            ((path) ? "; path=" + path : "") +

            ((domain) ? "; domain=" + domain : "") +

            "; expires=Thu, 01-Jan-70 00:00:01 GMT";

    }

}

//该函数用于返回某个Cookie的值
//cookieValue为整个Cookie文件的内容
//cookieName为要获得值的Cookie名
function returnCookieValue(cookieValue, cookieName) {
    //设置返回值var returnCookieValue = "";
    //查找Cookie名在整个Cookie文件内容中的位置
    var cookieNameIndex = cookieValue.indexOf(cookieName + "=");

    //如果在Cookie文件内容中找到Cookie名，则进一步查找该Cookie的值
    if (cookieNameIndex != -1) {

        //查找Cookie值在Cookie文件内容中的位置。
        //该位置为Cookie名的位置加上Cookie名的长度，再加上"="号的长度，即1
        var cookieValueBeginIndex = cookieNameIndex + cookieName.length + 1;

        //查找Cookie值在Cookie文件内容中的位置。
        //该位置为从Cookie名的位置开始到第一个";"为止
        var cookieVlaueEndIndex = cookieValue.indexOf("&", cookieValueBeginIndex);

        //如果从Cookie名的位置开始到整个Cookie文件内容的最后都没有找到";"，那么Cookie值的结束位置就是整个Cookie内容的最后
        if (cookieVlaueEndIndex == -1) {
            cookieVlaueEndIndex = cookieValue.length;
        }

        //通过Cookie值的开始位置和结束位置获得Cookie值
        CookieValue = cookieValue.substring(cookieValueBeginIndex, cookieVlaueEndIndex);

    } else {
        CookieValue = ""
    }

    //返回Cookie值
    return CookieValue;
}



/*xnews*/
function Show_dk(dkid_num, dknum) {
    for (var i = 0; i < 6; i++) { document.getElementById("dkcontent_" + dkid_num + i).style.display = "none"; }
    for (var i = 0; i < 6; i++) { document.getElementById("dkmenu_" + dkid_num + i).className = "dkoff"; }
    document.getElementById("dkmenu_" + dkid_num + dknum).className = "dk";
    document.getElementById("dkcontent_" + dkid_num + dknum).style.display = "block";
}
  var ie5up = (document.getElementById && document.all);
  var ns6up = (!document.all && document.getElementById);
  var active = 0;  
  var x, y, coordsX, coordsY;
  function start(windowName){ 
  // 设置开关变量active，保存当前坐标
  	dragWind = document.getElementById(windowName);
  	y = coordsY-parseInt(dragWind.style.top);
  	x = coordsX-parseInt(dragWind.style.left);
  	active=1;
  }
 
  function closeWin(){
  	dragWind.style.visibility= "hidden";

  }
  function openWin(windowName){
    cookie_name = getCookie("User_name");
    cookie_pwd = getCookie("User_pwd");
    if (cookie_name != null && cookie_name != "" && cookie_pwd != null && cookie_pwd != "") {
        document.getElementById("topNaviId_txtUserName").value = cookie_name;
        document.getElementById("topNaviId_txtUserPwd").value = cookie_pwd;
        document.getElementById("topNaviId_save_pwd").checked = true;
    }
  	dragWind = document.getElementById(windowName);  	
  	dragWind.style.visibility = "visible";
  	imgs = document.getElementById("wind1").getElementsByTagName("IMG");
  	for(var i=0; i<imgs.length;i++){
  	  imgs[i].style.cursor = (ie5up)?"hand":"pointer";
  	  imgs[i].ondragstart = new Function("return false");
  	}
  }
document.onmousemove = drag;
document.onmouseup=new Function("active=0"); 
// 重新设置开关变量active
//document.onselectstart = new Function("return false");  // 针对IE
//-->

/*time*/
var Timer_State = {
    Start: 1,
    Stop: 2,
    Pause: 3
};

//expression 计时器要执行的脚本字符串
//interval 执行间隔 单位毫秒
//nMaxExeCount 执行次数 为 Number.POSITIVE_INFINITY 时不断执行
//bFirstExe 为true时先执行表达式然后再进行下一次计时，为false时先执行下一次的计时再执行表达式

function Timer(expression, interval, nMaxExeCount, bFirstExe) {


    if (Timer._Initialized == undefined) {

        //开始
        Timer.prototype.Start = function() {

            if (this.State == Timer_State.Start) return;
            this.State = Timer_State.Start;
            this.doStart();
        }

        Timer.prototype.doStart = function() {
            this.CreateExpressionTimer();
        }

        Timer.prototype.CreateExpressionTimer = function() {

            var exp = this.BuildExpression(this.Expression);
            this._Timer = setTimeout(exp, this.Interval);
        }

        //表达式执行完毕
        Timer.prototype.ExecuteComplete = function() {

            this.ExeCount++;

            if (this.MaxExeCount != Number.POSITIVE_INFINITY && this.ExeCount >= this.MaxExeCount) {
                this.Stop();
                return;
            }

            if (this.State == Timer_State.Start) this.CreateExpressionTimer();
        }

        //停止
        Timer.prototype.Stop = function() {

            if (this.State == Timer_State.Stop) return;
            this.State = Timer_State.Stop;
            this.doStop();

        }

        Timer.prototype.doStop = function() {

            this.ClearCheckPause();
            if (this._Timer == null) return;
            clearTimeout(this._Timer);
            this._Timer = null;
        }

        //暂停
        Timer.prototype.Pause = function(fCheckPause, checkInterval) {

            if (fCheckPause == null || typeof (fCheckPause) != "function") {
                throw "参数类型异常";
            }

            if (this.State == Timer_State.Stop) return;
            this.ClearCheckPause();

            this.State = Timer_State.Pause;
            this.CheckPauseHandler = fCheckPause;
            if (checkInterval == null) checkInterval = 500; 
            
            this.CheckInterval = checkInterval;

            this.doStop();

            this.doPause();
        }

        Timer.prototype.doPause = function() {

            this._CheckPauseTimer = setTimeout("Timer.CheckPause(" + this.Id + ");", this.CheckInterval);
        }

        Timer.prototype.CheckPause = function() {

            if (this.CheckPauseHandler == null) return;

            if (this.CheckPauseHandler()) {
                this.Resume();
            }
            else {
                this.doPause();
            }
        }

        Timer.prototype.ClearCheckPause = function() {
            if (this._CheckPauseTimer == null) return;
            clearTimeout(this._CheckPauseTimer);
            this._CheckPauseTimer = null;
            this.CheckPauseHandler = null;
        }

        //恢复
        Timer.prototype.Resume = function() {

            this.ClearCheckPause();
            if (this.State == Timer_State.Stop) return;
            
            this.Start();
        }

        Timer.prototype.BuildExpression = function(expression) {
            var str = "Timer.ExecuteComplete(" + this.Id + ");";
            var _expression = this.FirstExe ? (expression + ";" + str) : (str + expression);

            return _expression;
        }

        //释放资源
        Timer.prototype.Dispose = function() {

            this.Stop();
            this.Expression = null;
            this.CheckPauseHandler = null;
            Timer.Timers.Remove(this);
        }
    }


    if (interval == null || expression == null) {
        throw "缺少参数";
    }

    if (typeof (expression) != "string") {
        throw "参数类型不正确";
    }
    if (nMaxExeCount == null) nMaxExeCount = Number.POSITIVE_INFINITY;
    if (bFirstExe == null) bFirstExe = false;

    this.MaxExeCount = nMaxExeCount;
    this.ExeCount = 0;
    this.FirstExe = bFirstExe;
    this.Interval = interval;
    this.State = Timer_State.Stop;
    this._Timer = null;
    this.CheckInterval = 500;
    this.CheckPauseHandler = null;
    this._CheckPauseTimer = null;
    this.Id = Timer.GetNewId();
    this.Expression = expression;
    Timer.Timers.push(this);
}

//根据值取得索引
Array.prototype.IndexOf = function(oValue) {
    var count = this.length, value;


    for (var i = 0; i < count; i++) {
        if (this[i] == oValue) {
            return i;
        }
    }

    return -1;
}
//根据索引移除
Array.prototype.RemoveByIndex = function(iStartIndex, iDeleteCount) {
    if (iDeleteCount == null) iDeleteCount = 1;

    this.splice(iStartIndex, iDeleteCount);

    return this.length;
}

//移除项
Array.prototype.Remove = function(oValue) {
    var index = this.IndexOf(oValue);

    return this.RemoveByIndex(index);
}

Timer.Timers = new Array();

Timer.LastId = 0;
Timer.GetNewId = function() {

    ++Timer.LastId;

    return Timer.LastId;
}


Timer.GetTimerById = function(id) {

    var count = Timer.Timers.length;

    for (var i = 0; i < count; i++) {
        var timer = Timer.Timers[i];

        if (timer.Id == id) {
            return timer;
        }
    }

    return null;
}

Timer.ExecuteComplete = function(id) {

    var timer = Timer.GetTimerById(id);
    if (timer != null) timer.ExecuteComplete();
}

Timer.CheckPause = function(id) {

    var timer = Timer.GetTimerById(id);

    if (timer != null) timer.CheckPause();
}
