﻿loadlogin();
var newMsgCount = "";

function alertLogin() {
    if ($("txtTopUsername"))
        $("txtTopUsername").focus();
}

function CloseLoginWin() {
    ObjClick($('btnCloseLogin'));
}

function topSearch() {
    var sex = $("selSex").options[$("selSex").selectedIndex].value;
    var age1 = $("selTopAge1").options[$("selTopAge1").selectedIndex].value//年龄1
    var age2 = $("selTopAge2").options[$("selTopAge2").selectedIndex].value//年龄2
    var lprovince = $("selTopProvince").options[$("selTopProvince").selectedIndex].value; //所在地省
    var haspp = ($("chkTopHavePic").checked ? 1 : 0); //有无照片

    var z = "";
    var shunxu = 0;
    var para = "&sex=" + sex;
    z+=","+(sex=="0"?"男":"女");
    if (lprovince != "0") {
        para += "&lprovince=" + lprovince;                          //所在地省
        z += "," + $("selTopProvince").options[$("selTopProvince").selectedIndex].text;
    }
    if (age1 != "0") {
        para += "&age1=" + age1;                                         //年龄1
        z += "," + age1 + "岁";
    }
    if (age2 != "0") {
        para += "&age2=" + age2;                                         //年龄2
        if (age1 != "0")
            z += "-" + age2 + "岁";
        else
            z += ",至" + age2 + "岁";

    }
    if ($("chkTopHavePic").checked) {
        para += "&haspp=" + haspp;                     //有无照片
        z += "," + ((haspp == "0") ? "无照片" : "有照片");
    }
    if (shunxu == "0") {
        para += "&shunxu=" + shunxu;                             //默认排序
    }
    if (z != "") z = z.substr(1);
    para += "&z=" + escape(z);
    window.location.href = ("/searchinfo.aspx?page=1" + para);
}

function addFri(id) {

    var e = (window.event || arguments.callee.caller.arguments[0]);
    var srcElement = (e.target || e.srcElement);
    srcElement.disabled = true;
    var url = "/handler/Validate.ashx?type=addfri&id=" + id;
    var XMLHttpRequest = createXMLHttpRequest();
    ajax2(XMLHttpRequest, url, function() { addFriCallBack(XMLHttpRequest, srcElement) });
}

function addFriCallBack(XMLHttpRequest, srcElement) {
    if (XMLHttpRequest.readyState == 4 && (XMLHttpRequest.status == 200 || window.location.href.indexOf("http") == -1)) {
        srcElement.disabled = false;
        var res = XMLHttpRequest.responseText;
        switch (res) {
            case "0": //登录
                alert("对不起，您尚未登录！");
                alertLogin();
                break;
            case "1":
                alert("该会员不存在或已被删除!");
                break;
            case "2":
                alert("操作失败");
                break;
            case "3":
                alert("添加成功");
                break;
            case "4":
                alert("不能添加自己");
                break;
        }
    }
}

function topShowNav(id) {
    $("topPService").style.display = (id == "topPService") ? "" : "none";
    $("topPForum").style.display = (id == "topPForum") ? "" : "none";
    $("topPMarri").style.display = (id == "topPMarri") ? "" : "none";
    $("topPMy").style.display = (id == "topPMy") ? "" : "none";

}
function topHideNav(obj, theEvent) {
    return;
    if (theEvent) {
        if (IsIE()) {
            if (obj.contains(event.toElement)) return;
        }
        else {
            if (obj.contains(theEvent.relatedTarget))
                return;
        }
    }
    topShowNav();
}

function setNavCurClass() {
    var url = window.location.href.toLowerCase();
    if (url.indexOf("/my/") != -1) {
        $("navMy").className = "n2 active2";
    }
    else if (url.indexOf(".aspx") == -1) {
        $("navIndex").className = "n1 active1";
    }
    else {
        $("navIndex").className = (url.indexOf(getAhref($("navIndex"))) == -1) ? "n1" : "n1 active1";
        $("navSearch").className = (url.indexOf(getAhref($("navSearch"))) == -1) ? "n3" : "n3 active3";
        $("navParty").className = (url.indexOf(getAhref($("navParty"))) == -1) ? "n4" : "n4 active4";
        $("navForum").className = (url.indexOf(getAhref($("navForum"))) == -1) ? "n5" : "n5 active5";
        $("navMember").className = (url.indexOf(getAhref($("navMember"))) == -1) ? "n6" : "n6 active6";
        $("topPService").className = (url.indexOf(getAhref($("topPService"))) == -1) ? "n7" : "n7 active7";
        $("navLove").className = (url.indexOf(getAhref($("navLove"))) == -1) ? "n8" : "n8 active8";
    }
}
function getAhref(obj) {
    if (obj.getAttribute("href")) return obj.getAttribute("href").toLowerCase();
    return "&^%$#@";
}

function topini() {
    if (typeof (HTMLElement) != "undefined") {
        HTMLElement.prototype.contains = function(obj) {
            while (obj != null && typeof (obj.tagName) != "undefind") {
                if (obj == this) return true;
                obj = obj.parentNode;
            }
            return false;
        };
    }
    $("navIndex").onmouseover = function(e) { topShowNav(''); }
    $("navMy").onmouseover = function(e) { topShowNav('topPMy'); }
    $("navSearch").onmouseover = function(e) { topShowNav(''); }
    $("navParty").onmouseover = function(e) { topShowNav(''); }
    $("navForum").onmouseover = function(e) { topShowNav('topPForum'); }
    $("navMember").onmouseover = function(e) { topShowNav('topPMarri'); }
    $("topPService").onmouseover = function(e) { topShowNav(''); }
    $("navLove").onmouseover = function(e) { topShowNav(''); }
    setNavCurClass();
}

topini();
