// AJAX Tab
// update 2006.10.18
// 增加鼠标延迟感应特性。
// update 2006.10.8
// A 标签 href 属性将保持原有HTML功能。增加urn属性为AJAX Load 路径。
// update 2006.10.11
// 修正IE5.0 undefined 未定义错误，增加脚本错误屏蔽
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
if (Browser.isFirefox) { // entend Event Mod for FireFox
    extendEventObject();
}
function extendEventObject() {
    Event.prototype.__defineGetter__("srcElement", function() {
        var node = this.target;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("fromElement", function() {
        var node;
        if (this.type == "mouseover")
            node = this.relatedTarget;
        else if (this.type == "mouseout")
            node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("toElement", function() {
        var node;
        if (this.type == "mouseout")
            node = this.relatedTarget;
        else if (this.type == "mouseover")
            node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });
}
function IsChild(cNode, pNode) {
    while (cNode != null) {
        cNode = cNode.parentNode;
        if (cNode == pNode) return true;
    }
    return false;
}

var ajccache = new Object();
var waitInterval;
var tempref;
var MouseDelayTime = 150; //鼠标感应延迟300毫秒
//function getTBprefixName(str,sta){
//	if(str.indexOf("active")!=-1 || str.indexOf("normal")!=-1) str=str.substr(6);
//		else if(str.indexOf("over")!=-1) str=str.substr(4);
//			else str="";
//	return sta+str;
//}
var topary = new Array("nor1", "nor2", "nor3", "nor4");
function startajaxtabs() {
    for (var i = 0; i < arguments.length; i++) {
        var ulobj = document.getElementById(arguments[i]);
        ulist = ulobj.getElementsByTagName("div");
        for (var j = 0; j < ulist.length; j++) {
            var thelist = ulist[j];
            if (thelist.parentNode != ulobj) continue; //只有第一层li有效 fixed 2006.9.29
            var ulistlink = thelist.getElementsByTagName("a")[0];
            var ulistlinkurl = ulistlink.getAttribute("urn");
            var ulistlinktarget = ulistlink.getAttribute("rel");
            thelist.setActive = function(bactive) {
                if (bactive) {
                    //                    alert(this.id);
                    this.status = "active";
                    if (this.id == "nor1" || this.id == "nor2" || this.id == "nor3" || this.id == "nor4") {
                        this.className = "active a_hong12";
                        for (var i = 0; i < topary.length; i++) {
                            if (this.id == topary[i]) {
                                this.getElementsByTagName("a")[0].className = "a_hong12";

                            }
                        }

                    } else if (this.id == "kuanping1" || this.id == "kuanping2" || this.id == "kuanping3") {
                        this.className = "active2 text_mid a_dhui12";
                    } else if (this.id == "lasttab") {
                        this.className = "last1";
                    } else if (this.id == "kuanping4") {
                        this.className = "active22 text_mid a_dhui12";
                    } else if (this.id == "bios1" || this.id == "bios2" || this.id == "geforce1" || this.id == "geforce2") {
                        this.className = "active text_mid a_dhui12";
                    } else if (this.id == "bios3" || this.id == "geforce3") {
                        this.className = "active1 text_mid a_dhui12";
                    } else if (this.id == "tiao1" || this.id == "tiao2") {
                        this.className = "conT2 text_mid";
                    } else if (this.id == "sta_nor1" || this.id == "sta_nor2" || this.id == "sta_nor3" || this.id == "sta_nor4" || this.id == "fad_1" || this.id == "fad_2" || this.id == "fad_3" || this.id == "fad_4" || this.id == "tour_1" || this.id == "tour_2" || this.id == "tour_3" || this.id == "tour_4") {
                        this.className = "active text_mid";
                    } else if (this.id == "sta_nor5" || this.id == "fad_5" || this.id == "tour_5" || this.id == "Div16") {
                        this.className = "active5 text_mid";
                    }
                } else {
                    this.status = "normal";
                    if (this.id == "nor1" || this.id == "nor2" || this.id == "nor3" || this.id == "nor4") {
                        this.getElementsByTagName("a")[0].className = "";
                        this.className = "normal";
                    } else if (this.id == "kuanping1" || this.id == "kuanping2" || this.id == "kuanping3") {
                        this.className = "nomail2 text_mid a_dhui12";
                    } else if (this.id == "lasttab") {
                        this.className = "last";
                    } else if (this.id == "kuanping4") {
                        this.className = "nomail22 text_mid a_dhui12";
                    } else if (this.id == "bios1" || this.id == "bios2" || this.id == "geforce1" || this.id == "geforce2") {
                        this.className = "nomail text_mid a_dhui12";
                    } else if (this.id == "bios3" || this.id == "geforce3") {
                        this.className = "nomail1 text_mid a_dhui12";
                    } else if (this.id == "tiao1") {
                        this.className = "conT1 text_mid";
                    } else if (this.id == "tiao2") {
                        this.className = "conT3 text_mid";
                    } else if (this.id == "sta_nor1" || this.id == "sta_nor2" || this.id == "sta_nor3" || this.id == "sta_nor4" || this.id == "fad_1" || this.id == "fad_2" || this.id == "fad_3" || this.id == "fad_4" || this.id == "tour_1" || this.id == "tour_2" || this.id == "tour_3" || this.id == "tour_4") {
                        this.className = "normal text_mid";
                    } else if (this.id == "sta_nor5" || this.id == "fad_5" || this.id == "tour_5"||this.id=="Div16") {
                        this.className = "normal5 text_mid";
                    }
                }
            }
            thelist.LoadTab = function() {
                this.setActive(true);
                this.parentNode.activetab.setActive(false);
                this.parentNode.activetab = this;
                var ulistlink = this.getElementsByTagName("a")[0];

                loadAJAXTab(ulistlink.getAttribute("urn"), ulistlink.getAttribute("rel"));
            }
            thelist.onmouseover = function(aEvent) {
                var myEvent = window.event ? window.event : aEvent;
                var fm = myEvent.fromElement;
                if (IsChild(fm, this) || fm == this) return; //过滤子元素event
                if (this.status == "active") return;
                tempref = this;
                clearTimeout(waitInterval);
                waitInterval = window.setTimeout("tempref.LoadTab();", MouseDelayTime);
            }

            thelist.onmouseout = function(aEvent) {
                var myEvent = window.event ? window.event : aEvent;
                var em = myEvent.toElement;
                if (IsChild(em, this) || em == this) return; //过滤子元素event
                if (this.status == "active") return;
                clearTimeout(waitInterval);
            }

            if (ulistlinkurl.indexOf("#default") != -1) {

                thelist.setActive(true);
                ulobj.activetab = thelist;
                ajccache[ulistlinkurl] = document.getElementById(ulistlinktarget).innerHTML;
            } else {
                thelist.setActive(false);
            }

        }
        if (ulobj.activetab == null) ulobj.activetab = ulist[0];
    }
}

function getXmlhttp() {
    var http_request;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!http_request) {
        window.alert("can't create XMLHttpRequest object.");
        return null;
    }
    return http_request;
}

function loadAJAXTab(url, contentid) {

    var ocontent = document.getElementById(contentid);
    if (ajccache[url] == null) {

        var xhttp = getXmlhttp();
        xhttp.onreadystatechange = function() {
            if (xhttp.readyState == 4 && (xhttp.status == 200 || window.location.href.indexOf("http") == -1)) {
                ocontent.innerHTML = xhttp.responseText;
                ajccache[url] = ocontent.innerHTML;
            }
        }
        //xhttp.open("GET",url+"?rand="+Math.random(),true);
        xhttp.open("GET", url, true);
        xhttp.send(null);
    } else {

        ocontent.innerHTML = ajccache[url];
    }
}
window.onerror = function() { return true }
