﻿//----------------------------------------------------------------------------------------------------------
//-------------------------------edit by cai 2009.12.29
//-------------------------------
//----------------------------------------------------------------------------------------------------------

//ajax登陆部分
var userName = "";
function LoadCheck() {
    var x = new AjaxRequest('XML', 'status');
    x.para = [];
    x.async = false;
    x.post('logincheck', '/ajax.aspx', function(s) {
        var xml = x.createXmlDom(s);
        var status = xml.getElementsByTagName("status")[0].firstChild.data;
        if (status == 'ok') {
            userName = xml.getElementsByTagName("username")[0].firstChild.data;
            ChangeState(true);
        }
        else {
            ChangeState(false);
        }
    });
}

function ChangeState(flag) {
    var logindiv = document.getElementById("logindiv");
    var logoutdiv = document.getElementById("logoutdiv");
    if (flag == true) {
        logindiv.style.display = "none";
        logoutdiv.style.display = "";
        document.getElementById("spanUserName").innerHTML = userName + " 您好，欢迎光临惟有爱";
    }
    else {
        logindiv.style.display = "";
        logoutdiv.style.display = "none";
    }
}

function Logout() {
    var x = new AjaxRequest('XML', '');
    x.post('userlogout', '/ajax.aspx',
    function(s) {
        var xml = x.createXmlDom(s);
        var status = xml.getElementsByTagName("status")[0].firstChild.data;
        if (status == "ok") {
            if (xml.getElementsByTagName("API_Enable")[0].firstChild.data == "1") {
                var LogOutString = xml.getElementsByTagName("LogOutString")[0].firstChild.data;
                Loginin(LogOutString);
            }
            window.location.reload();
        }
    });
}


//Tag 选择框
function selectTag(showContent, selfObj) {
    var tag = document.getElementById("tags").getElementsByTagName("li");
    var taglength = tag.length;
    for (var i = 0; i < taglength; i++) {
        tag[i].className = "";
    }
    selfObj.className = "tabOn";
    for (var j = 0; j < taglength; j++) {
        document.getElementById("tagCont" + j).style.display = "none";
    }
    document.getElementById(showContent).style.display = "block";
}

//问题分类菜单JS
function rolinTab(obj, iShow) {
    var list = $(obj).getElementsByTagName("LI");
    var state = { show: false, hidden: false, showObj: false };

    for (var i = 0; i < list.length; i++) {
        var tmp = new rolinItem(list[i], state);
        if (i == iShow) tmp.pShow();
    }
}
function rolinItem(obj, state) {
    var speed = 0.4666;
    var range = 1;
    var interval;
    var tarH;
    var tar = this;
    var head = getFirstChild(obj);
    var content = getNextChild(head);
    var isOpen = false;
    this.pHidden = function() {
        if (isOpen) hidden();
    }
    this.pShow = show;
    var baseH = content.offsetHeight;
    content.style.display = "none";
    var isOpen = false;
    head.onmouseover = function() {
        //alert("here");
        if (!isOpen) {
            this.style.background = "url(/Skin/service/images/s_inc.png) -231px -242px no-repeat";
        }
    }
    head.onmouseout = mouseout;
    head.onclick = function() {
        this.style.background = "url(/Skin/service/images/s_inc.png) -231px -280px no-repeat";
        if (!state.show && !state.hidden) {
            if (!isOpen) {
                head.onmouseout = null;
                show();
            } else {
                hidden();
            }
        }
    }
    function mouseout() {
        //alert("there");
        this.style.background = "url(/Skin/service/images/s_inc.png) -231px -242px no-repeat"
    }
    function show() {
        head.style.borderBottom = "1px solid #DADADA";
        state.show = true;
        if (state.openObj && state.openObj != tar) {
            state.openObj.pHidden();
        }
        content.style.height = "0px";
        content.style.display = "block";
        content.style.overflow = "hidden";
        state.openObj = tar;
        tarH = baseH;

        interval = setInterval(move, 10);
    }
    function showS() {
        isOpen = true;
        state.show = false;
    }
    function hidden() {
        state.hidden = true;
        tarH = 0;
        interval = setInterval(move, 10);
    }
    function hiddenS() {
        head.style.borderBottom = "none";
        head.onmouseout = mouseout;
        head.onmouseout();
        content.style.display = "none";
        isOpen = false;
        state.hidden = false;
    }

    function move() {
        var dist = (tarH - content.style.height.pxToNum()) * speed;
        if (Math.abs(dist) < 1) dist = dist > 0 ? 1 : -1;
        content.style.height = (content.style.height.pxToNum() + dist) + "px";
        if (Math.abs(content.style.height.pxToNum() - tarH) <= range) {
            clearInterval(interval);
            content.style.height = tarH + "px";
            if (tarH != 0) {
                showS()
            } else {
                hiddenS();
            }
        }
    }

}
var $ = function($) { return document.getElementById($) };
String.prototype.pxToNum = function() { return Number(this.replace("px", "")) }
function getFirstChild(obj) {
    var result = obj.firstChild;
    while (!result.tagName) {
        result = result.nextSibling;
    }
    return result;
}
function getNextChild(obj) {
    var result = obj.nextSibling;
    while (!result.tagName) {
        result = result.nextSibling;
    }
    return result;
}

