﻿// JScript File
var XMLHTTPUrl = "http://ajax.cyzone.cn/ValiLogin.aspx?";
var xmlhttp;

var LogoutUrl = "http://ajax.cyzone.cn/AutoLogout.aspx";
function calLogout() {

    window.location.replace("http://blog.cyzone.cn/Logout.aspx");
}
function checkUserName() {
    var elName = $('#txtUserName').get(0);
    var elPassword = $('#txtPassword').get(0);
    if (elName.value == '') {
        alert('请输入用户名!');
        return false;
    }
    if (elPassword.value == '') {
        alert('请输入密码!');
        return false;
    }
    var url = XMLHTTPUrl + "name=" + elName.value + "&password=" + elPassword.value;

    $.getScript(url, function() {

        var response = s.note;
        if (response != "error") {
            window.location.href = window.location.href; return;
            var elCookie = $('#divLogin').get(0);
            elCookie.innerHTML = response;
            var elBtn = $('#divBtn').get(0);
            elCookie.style.display = "";
            elBtn.style.display = "none";
        }
        else {
            alert('用户名密码错误!');
            window.location.href = "http://passport.cyzone.cn/login.aspx";
            return false;
        }

    });


    return true;
};

function state_Change_login() {
    if (xmlhttp.readyState == 4) {// 4 = "loaded"
        if (xmlhttp.status == 200) {
            var response = xmlhttp.responseText;
            if (response == "error") {
                alert('用户名密码错误!');
                window.location.href = "http://passport.cyzone.cn/login.aspx";
                return false;
            }
            else {
                window.location.href = window.location.href;return;
                var elCookie = $get('divLogin');
                elCookie.innerHTML = response;
                var elBtn = $('#divBtn').get(0);
                elCookie.style.display = "";
                elBtn.style.display = "none";
            }
        }
    }
}

function login() {
    $(document).ready(function() {
        if (document.cookie.indexOf(".ASPXAUTH") > -1) {
            $.getScript("http://ajax.cyzone.cn/ValiLogin.aspx?name=cyzonetech&password=as111", function() {
                if (s.note != "error") {
                    var response = s.note;
                    if (response != "error") {
                        var elCookie = $('#divLogin').get(0);
                        elCookie.innerHTML = response;
                        var elBtn = $('#divBtn').get(0);
                        elCookie.style.display = "";
                        elBtn.style.display = "none";
                    }
                }
            });
        }
        else {
            var email = getCookie("loginuser");
            if (email) {
                $("#txtUserName").val(email);
            }
        }
    });
}

function state_Change_login2() {

    if (xmlhttp.readyState == 4) {// 4 = "loaded"
        if (xmlhttp.status == 200) {
            var response = xmlhttp.responseText;
            if (response != "error") {
                window.location.href = window.location.href; return;
                var elCookie = $('#divLogin').get(0);
                elCookie.innerHTML = response;
                var elBtn = $('#divBtn').get(0);
                elCookie.style.display = "";
                elBtn.style.display = "none";
            }
        }
    }
}

function Logout() {
  //  calLogout();
    window.location.replace("http://blog.cyzone.cn/Logout.aspx");

}
function Searchclick() {
    var key = $('#SearchKey').get(0).value;
   // var type = $('#SearchType').get(0).value;
    location.replace('http://www.cyzone.cn/Search.aspx?key=' + escape(key) + '&op=user'); //+ '&type=' + escape(type));
}
function keycheck(event) {
    var oevent = event ? event : window.event;
    var obj = event.target ? event.target : event.srcElement;
    if (oevent.keyCode == 13) {
        if (obj.name == "txtPassword")
            checkUserName();
        else
            Searchclick();
    }
}

//
//Init menu
//
var _iim = false;
var _cm = 1;
var _tr;
var _tm = "t_m";
var _ts = "t_s";
var _ss = "ss";
var _sn = "sn";
var _sd = "sd";
var _li = "li";
var _ul = "ul";
var _m1 = "t_menu1";
var _m2 = "t_menu2";

function menuInit(id) {
    _cm = id;
    if (!document.getElementById(_m2))
        document.getElementById("t_menu").style.height = "32px";

    var sfEls = document.getElementById(_m1).getElementsByTagName(_li);
    var id;
    for (var i = 0; i < sfEls.length; i++) {
        id = sfEls[i].id.replace(_tm, "");
        if (id == _cm) {
            document.getElementById(_tm + id).className = _ss;
            //document.getElementById(_ts + id).style.display = "inline-block";
        } else
        { document.getElementById(_tm + id).className = _sn; }
        sfEls[i].onmouseover = function() {
            _iim = true;
            clearTimeout(_tr);

            var sf1Els = document.getElementById(_m1).getElementsByTagName(_li);
            for (var s1 = 0; s1 < sf1Els.length; s1++) {
                sf1Els[s1].className = _sn;
            }
            document.getElementById(_tm + _cm).className = _sd;
            this.className = _ss;

        }

        sfEls[i].onmouseout = function() {
            _iim = false;
            _tr = setTimeout("menuReset()", 2000);
        }
    }

}
function menuReset() {
    if (!_iim) {
        var sf1Els = document.getElementById(_m1).getElementsByTagName(_li);
        for (var s1 = 0; s1 < sf1Els.length; s1++) {
            sf1Els[s1].className = _sn;
        }
        document.getElementById(_tm + _cm).className = _ss;

    }
    clearTimeout(_tr);
}

function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
        else return ""
    }
} 