﻿function createObject() {
    var requestC;
    if (window.XMLHttpRequest) {
        requestC = new XMLHttpRequest();
    }
    if (!requestC) {
        requestC = new ActiveXObject('Msxml2.XMLHTTP');
        if (!requestC) {
            requestC = new ActiveXObject('Microsoft.XMLHTTP');
        }
        if (!requestC) {
            requestC = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        }
    }
    return requestC;
}
function getUrl(url) {
    var t = createObject();
    if (t) {
        t.open("GET", url, false);
        t.setRequestHeader("Cache-Control", "no-cache");
        t.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        t.send(null);
        return t.responseText;
    }
}
function GetQueryString(name) {
    name = checkStr(name);
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2].replace(/\./g, "$")); return null;
}
function GetInt(str) {
    if (str == null)
        window.location.href = '../../ErrPage/err404.html';
    if (/(^\d+$)|(^\+?\d+$)/.test(str)) {
        return str;
    }
    else {
        window.location.href = '../../ErrPage/err404.html';
    }
}

function leftinit() {
    if (!document.getElementById || !document.getElementsByTagName) { retun; }
    var arrayDiv = document.getElementById("levelmenu");
    if (!arrayDiv) { return; }
    var divObj = arrayDiv.getElementsByTagName("div");
    var length = divObj.length;
    var agreeDiv = new Array();
    for (var i = 0; i < length; i++) {
        if (divObj[i].className.indexOf("unit") >= 0) {
            agreeDiv.push(divObj[i]);
            divObj[i].onclick = function(event) {
                showCurrentMenu(agreeDiv, this, event);
            }
        }
    }
}
function showCurrentMenu(agreeDiv, currentObj, event) {
    if (!event) { event = window.event; }
    var eventObj = event.srcElement ? event.srcElement : event.target;
    //先隐藏所有ul
    var length = agreeDiv.length;
    for (var i = 0; i < length; i++) {
        if (eventObj.parentNode == agreeDiv[i] || eventObj.nodeName != "H5") { continue; }
        agreeDiv[i].className = "unit";
    }
    if (eventObj.nodeName == "H5") {
        if (eventObj.parentNode.className == "unit") {
            eventObj.parentNode.className = "unit current"
        } else {
            eventObj.parentNode.className = "unit"
        }
    }
}
function showsearch() {
    if (jQuery.formValidator.PageIsValid('1')) {
        var search = $("#txtSearch").val();
        var len = search.length;
        if (len < 4 || len > 30) {
            alert("Please enter 4-35 characters");
            return;
        }
        window.location.href = "productsearch.htm?seh=" + checkStr(search);
    }
}
function showsearch2() {
    debugger;
    var search = document.getElementById("txtSearch").value;
        var len = search.length;
        if (len < 4 || len > 30) {
            alert("Please enter 4-35 characters");
            return;
        }
       top.window.location = "productsearch.aspx?seh=" + checkStr(search);
}

function checkStr(inputStr) {
   if (typeof(inputStr) != "string") { return inputStr; } //判断是否是字符串类型
   var tmpValue = inputStr;
   while (tmpValue.indexOf(';') > -1) {tmpValue = tmpValue.replace(';',''); }
   while (tmpValue.indexOf('<') > -1) {tmpValue = tmpValue.replace('<',''); }
   while (tmpValue.indexOf('>') > -1) {tmpValue = tmpValue.replace('>',''); }
   while (tmpValue.indexOf('--') > -1) {tmpValue = tmpValue.replace('--',''); }
   while (tmpValue.indexOf(",") > -1) {tmpValue = tmpValue.replace(",",""); }
   while (tmpValue.indexOf("'") > -1) {tmpValue = tmpValue.replace("'",""); }
   while (tmpValue.indexOf("?") > -1) { tmpValue = tmpValue.replace("?", ""); }
   return tmpValue;}
function OpenWin(url, iW, iH, scol) {
    var oW = iW ? iW : 800;
    var oH = iH ? iH : 570;
    var wW = window.screen.availWidth;
    var wH = window.screen.availHeight;
    var left = (wW - oW) / 2;
    var top = (wH - oH) / 2;
    var sF = "dependent=yes,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,location=no,";
    sF += "scrollbars=" + (scol ? scol : "no") + ",";
    sF += "width=" + oW + ",";
    sF += "height=" + oH + ",";
    sF += "top=" + top + ",";
    sF += "left=" + left;
    window.open(url, "_blank", sF, false);
}

function MM_reloadPage(init) { //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        } 
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function setUrl()
{
   var url=document.location.href; 
   url=url.toLocaleLowerCase();
   var urllocation=url;
   if(navigator.userAgent.indexOf("Firefox")>0){
     if(url.indexOf(".htm")>0)
     urllocation=url.replace('product','productbrowser').replace('.htm','.aspx');}
   else
     {
     if(url.indexOf(".aspx")>0)
       urllocation=url.replace('productbrowser','product').replace('.aspx','.htm');
     }
    if(url!=urllocation)
    window.location.href=urllocation;
} 
