﻿// JavaScript Document
(function() {

    //ADS命名空间
    if (!window.ads) { window['ads'] = {} }

    //检查js是否能正确运行
    function runCheck(other) {
        if (other === false
	   || !Array.prototype.push
	   || !Object.hasOwnProperty
	   || !document.createElement
	   || !document.getElementsByTagName
	   ) {
            return false;
        }
        return true;
    }
    window['ads']['runCheck'] = runCheck;

    //根据ID获取元素，可同时获取多个
    function $() {
        var elements = new Array();

        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
            if (typeof arguments[i] == 'string') {
                element = document.getElementById(element);
            }
            if (arguments.length == 1) {
                return element;
            }
            elements.push(element);
        }
        return elements;
    }
    window['ads']['$'] = $;

    //根据Class获取元素
    function $c(className, tag, parent) {
        parent = parent || document;
        tag = tag || '*';
        if (!(parent = $(parent))) { return false; }

        //查找匹配标签
        var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);

        var elements = new Array();

        //正则表达式，判断className是否正确
        className = className.replace(/\-/g, "\\-");
        var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");

        var element;
        for (var i = 0; i < allTags.length; i++) {
            element = allTags[i];
            if (regex.test(element.className)) {
                elements.push(element);
            }
        }
        if (elements.length == 1) return elements[0];
        return elements;
    }
    window['ads']['$c'] = $c;

    //根据html标签获取元素
    function $t(tag, parent) {
        parent = parent || document;
        tag = tag || '*';
        if (!(parent = $(parent))) { return false; }

        //查找匹配标签
        var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);

        var elements = new Array();

        if (allTags.length == 1) { return allTags[0] };

        for (var i = 0; i < allTags.length; i++) {
            elements.push(allTags[i]);
        }
        return elements;
    }
    window['ads']['$t'] = $t;

    function getBrowserSize() {
        var de = document.documentElement;

        return {
            'width': (
            window.innerWidth
            || (de && de.clientWidth)
            || document.body.clientWidth),
            'height': (
            window.innerHeight
            || (de && de.clientHeight)
            || document.body.clientHeight)
        }
    };
    window['ads']['getBrowserSize'] = getBrowserSize;

    //添加、移除事件
    function addEvent(node, type, listener) {
        if (!runCheck()) { return false; }
        if (!(node = $(node))) { return false; }

        //W3C添加事件方法
        if (node.addEventListener) {
            node.addEventListener(type, listener, false);
            return true;
        }
        //MSIE添加事件方法
        else if (node.attachEvent) {
            node['e' + type + listener] = listener;
            node[type + listener] = function() {
                node['e' + type + listener](window.event);
            }
            node.attachEvent('on' + type, node[type + listener]);
            return true;
        }
        return false;
    }
    window['ads']['addEvent'] = addEvent;

    function removeEvent(node, type, listener) {
        if (!runCheck()) { return false; }
        if (!(node = $(node))) { return false; }

        //W3C添加事件方法
        if (node.removeEventListener) {
            node.removeEventListener(type, listener, false);
            return true;
        }
        //MSIE添加事件方法
        else if (node.detachEvent) {
            node.detachEvent('on' + type, node[type + listener]);
            node[type + listener] = null;
            return true;
        }
        return false;
    }
    window['ads']['removeEvent'] = removeEvent;

    //取消默认动作
    function preventDefault(eventObject) {
        eventObject = eventObject || getEventObject(eventObject);
        if (eventObject.preventDefault) {
            eventObject.preventDefault();
        }
        else {
            eventObject.returnValue = false;
        }
    }
    window['ads']['preventDefault'] = preventDefault;

    //更改函数执行环境
    function bindFunction(obj, func) {
        return function() {
            func.apply(obj, arguments);
        };
    }
    window['ads']['bindFunc'] = bindFunction;


})();



function subNav(navID, maxNavName, minNavName) {
    this.navID = navID;
    this.maxNavName = maxNavName;
    this.minNavName = minNavName;
    this.setMenu();
};
subNav.prototype = {
    maxNav: null,
    minNav: null,
    init: function() {
        this.maxNav = ads.$c(this.maxNavName, '*', this.navID);
        this.minNav = ads.$c(this.minNavName, '*', this.navID);
        for (var i = 0; i < this.minNav.length; i++) {
            this.minNav[i].style.display = 'none';
        }
    },
    regListener: function(maxMenu, minMenu) {
        ads.addEvent(maxMenu, 'mouseover', function() { minMenu.style.display = 'block'; })
        ads.addEvent(maxMenu, 'mouseout', function() { minMenu.style.display = 'none'; })
        ads.addEvent(minMenu, 'mouseover', function() { maxMenu.getElementsByTagName('a')[0].style.backgroundColor = "BDCBD4"; })
        ads.addEvent(minMenu, 'mouseout', function() { minMenu.style.display = 'none'; maxMenu.getElementsByTagName('a')[0].style.backgroundColor = ""; })
    },
    setMenu: function() {
        this.init();
        for (var i = 0; i < this.maxNav.length; i++) {
            this.regListener(this.maxNav[i], this.minNav[i]);
        }
    }
}
ads.addEvent(window, "load", function() {
    var nav = new subNav("mainnav", "maxMenu", "minMenu");
})




function $(TID) {
    return document.getElementById(TID);
}

function ShowSubMenu(show_id, hide_ids) {
    if (hide_ids != "") {
        for (var i = 0; i < hide_ids.split(",").length; i++) {
            try {
                $(hide_ids.split(",")[i]).style.display = 'none';
            } catch (e) { }
        }
    }

    try {
        $(show_id).style.display = '';
    }
    catch (e) { }
}


function Search_Click() {
    var str = document.getElementById("SearchStr").value;
    if (str == "搜索站内资讯") {
        alert("搜索站内资讯不能为空"); return;
    }
    location.href = "/aspx/SearchNews.aspx?Key=" + str;
}

function showLayer(objA, objB, cur) {
    for (var i = 0; i < objB.length; i++) {
        objB[i].style.display = "none";
    }
    if (cur) {
        objB[cur].style.display = "block";
        objB[cur].style.paddingLeft = cur * 100; +"px";
    }
    for (var i = 0; i < objA.length; i++) {
        addListent(i);
    }

    function addListent(index) {
        ads.addEvent(objA[index], "mouseover", function() {
            for (var j = 0; j < objB.length; j++) {
                objB[j].style.display = "none";
            }
            objB[index].style.display = "block";
            var leftPX = index * 100;
            objB[index].style.paddingLeft = leftPX + "px";
        })
    }
}

function showBgImage(index) {
    try {
        var obj = ads.$c("menu", "li", "mainnav")[index];
        if (obj.className == "maxMenu menu") {
            obj.className = "maxMenu menu here";
        } else if (obj.className == "menu") {
            obj.className = "menu here";
        };
    }
    catch (e) { }


}

// JScript 文件
function getCookie(sCookieName) {
    var sName = sCookieName + "=", ichSt, ichEnd;
    var sCookie = document.cookie;

    if (sCookie.length && (-1 != (ichSt = sCookie.indexOf(sName)))) {
        if (-1 == (ichEnd = sCookie.indexOf(";", ichSt + sName.length)))
            ichEnd = sCookie.length;
        return unescape(sCookie.substring(ichSt + sName.length, ichEnd));
    }

    return null;
}

function setCookie(sName, vValue) {
    var argv = setCookie.arguments, argc = setCookie.arguments.length;
    var sExpDate = (argc > 2) ? "; expires=" + argv[2].toGMTString() : "";
    var sPath = "; path=/"; // (argc > 3) ? "; path="+argv[3] : "";
    var sDomain = (argc > 4) ? "; domain=" + argv[4] : "";
    var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
    document.cookie = sName + "=" + escape(vValue, 0) + sExpDate + sPath + sDomain + sSecure + ";";
}

function deleteCookie(sName) {
    document.cookie = sName + "=" + getCookie(sName) + "; expires=" + (new Date()).toGMTString() + ";";
}

//------------------------------------

function setProductInqurie(pid, ask) {
    var oldCookie = getCookie("InquireList") == null ? "" : getCookie("InquireList");
    if (pid.replace(" ", "") != "" && oldCookie.indexOf(pid + ",") < 0) {
        setCookie("InquireList", oldCookie + pid + ",");
    }
    if (ask == true) {
        if (window.confirm("Inquiry for the product was submitted successfully. Shift to the page of products inquired ?")) {
            location.href = "/aspx/InquiryBasket.aspx";
        }
    }
}

function selectAll() {
    var cbs = document.getElementsByName("CheckBox_Prod");
    var check_ids = "";
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].checked == true) {
            check_ids += cbs[i].value + ",";
            setProductInqurie(cbs[i].value, false);
        }
    }
    if (check_ids != "") {
        if (window.confirm("Inquiry for the product was submitted successfully. Shift to the page of products inquired ?")) {
            location.href = "/aspx/InquiryBasket.aspx";
        }
    }
    else {
        alert("Pls select products");
    }
    //
    //event.returnValue = false;
    return false;
}

function pcSearch() {
    var maxtype = $("ProdClassSearch1_drtype");
    var _id = maxtype.options[maxtype.selectedIndex].value;
    //
    var key = document.getElementById("ProdClassSearch1_KeyText1").value;
    if (key == "" && _id == "")
    { return; }
    location.href = ("/aspx/Search.aspx?TypeID=" + _id + "&key=" + key);

}
function clickThisImg(Name) {

    $("Img").src = "/UserFiles/Image/" + Name;
}

function chgH3_Style(id) {
    try {
        $(id).className = "here";
    } catch (e) { }
}

function chgH4_Style(id) {
    try {
        $(id).className = "here";
    } catch (e) { }
}


function SetHeadfocus(index) {

    var lists = $("nav_box11").getElementsByTagName("ul");
    switch (index) {
        case 0: lists[0].className = "on"; break;
        case 1: lists[1].className = "on"; break;
        case 2: lists[2].className = "on"; break;
        case 3: lists[3].className = "on"; break;
        case 4: lists[4].className = "on"; break;
        case 5: lists[5].className = "on"; break;
        case 6: lists[6].className = "on"; break;
        case 7: lists[7].className = "on"; break;
    }
}


function showContent(obj, a_id) {
    var ps = "p_Description,p_Specification,p_Picture,p_Case";
    for (var i = 0; i < ps.split(",").length; i++) {
        try {
            $(ps.split(",")[i]).style.display = "none";
        }
        catch (e) { }
    }
    obj.style.display = "block";

    //
    var as = "a_show_Description,a_show_Specification,a_show_Picture,a_show_Case,"; //background:#EBF1F8; color:#2E3192;
    for (var i = 0; i < as.split(",").length; i++) {
        try {
            $(as.split(",")[i]).style.background = "#7298CB";
            $(as.split(",")[i]).style.color = "#FFFFFF";
        }
        catch (e) { }
    }
    $(a_id).style.backgroundColor = "#EBF1F8";
    $(a_id).style.color = "#2E3192";
    try {
        window.event.returnValue = false;
    } catch (e) { }
    return false;
}
function AddClick(ID, TYPE) {
    var url = "<iframe width=0 height=0 style='display:none' src='/aspx/AddClick.aspx?TYPE=" + TYPE;
    url += "&IDentityID=";
    url += ID;
    url += "'></iframe>";
    document.write(url);
}
function AjaxGetPro_Next(ControlID, ObjectID, Type) {
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (4 == xmlhttp.readyState) {
            if (200 == xmlhttp.status) {

                var value = xmlhttp.responseText;
                document.getElementById(ControlID).innerHTML = value;
            }
            else {
                return null;
            }
        }
    }
    xmlhttp.open("post", "/aspx/Ajax.aspx", true);
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send("IdentityID=" + escape(ObjectID) + "&Type=" + escape(Type));
}
function AjaxGetRemmProd(ControlID, ObjectID) {
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (4 == xmlhttp.readyState) {
            if (200 == xmlhttp.status) {

                var value = xmlhttp.responseText;
                document.getElementById(ControlID).innerHTML = value;
            }
            else {
                return null;
            }
        }
    }
    xmlhttp.open("post", "/aspx/Ajax.aspx", true);
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send("GetREMMPROD=" + escape(ObjectID));
}


function displaySubMenu(li) {
    var subMenu = li.getElementsByTagName("ul")[0];
    subMenu.style.display = "block";
}
function hideSubMenu(li) {
    var subMenu = li.getElementsByTagName("ul")[0];
    subMenu.style.display = "none";
} 
