﻿String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.format = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,
        function(m, i) {
            return args[i];
        });
}
//模拟下拉菜单
function showDownList(objElement, minHeight) {
    var height = parseInt(objElement.style.height);
    var maxHeight = objElement.scrollHeight;
    if (maxHeight <= minHeight) return;
    var step = Math.floor(maxHeight / 20);

    if (height == minHeight) {
        var i = 2;
        var ddlTimer = setInterval(function() {
            while (step * i < minHeight) {
                i++;
            }
            setStyle(objElement, "height", (step * i) + "px");
            i++;
            if (i >= 20) {
                clearInterval(ddlTimer);
                setStyle(objElement, "height", maxHeight + "px");
            }
        }, 30);
    }
    else {
        var i = 20;
        var ddlTimer = setInterval(function() {
            setStyle(objElement, "height", (step * i) + "px");
            i--;
            if (i == 2 || step * i <= minHeight) {
                clearInterval(ddlTimer);
                objElement.style.height = minHeight + "px";
            }
        }, 30);
    }
}
//全选
function selectAll(checked, ParentNode) {
    var chkList = ParentNode?ParentNode.getElementsByTagName("input"):document.getElementsByTagName("input");
    for (var i = 0; i < chkList.length; i++) {
        if (chkList[i].type.toLowerCase() == "checkbox") {
            chkList[i].checked = checked;
        }
    }
}
//获取元素
function $(id) {
    return document.getElementById(id);
}
//设置元素样式
function setStyle(objELement, styleName, value) {
    objELement.style[styleName] = value;
}
//设置元素样式二
function setStyleByID(id, styleName, value) {
    $(id).style[styleName] = value;
}
//加载自动缩放图片
function loadImage(o, maxWidth, maxHeight) {
    var width = parseInt(o.width);
    var height = parseInt(o.height);
    if (maxWidth / width > maxHeight / height) {
        if (height > maxHeight) o.style.height = maxHeight + "px";
    }
    else {
        if (width > maxWidth) o.style.width = maxWidth + "px";
    }
}
//替换url
function replaceUrl(name, value, url) {
    if (url == null) {
        url = location.href;
    }
    if (url.match(/\?[^\s]+/g)==null) {
        url = "{0}?{1}={2}".format(location.pathname, name, value);
    }
    else {
        if (url.indexOf(name + "=") > 0) {
            var reg = new RegExp("{0}=[^&]*".format(name), "g");
            url = url.replace(reg, "{0}={1}".format(name,value));
        }
        else {
            url += "&{0}={1}".format(name, value);
        }
    }
    return url;
}
//获取url参数
function getUrlPara(name,url) {
    if (url == null) {
        url = location.href;
    }
    if (url.indexOf("?") == -1) return "";
    var search = url.substring(url.indexOf("?") + 1);
    var paras = search.split("&");
    for (var i = 0; i < paras.length; i++) {
        if (paras[i].split("=")[0] == name) {
            try {
                return paras[i].split("=")[1];
            }
            catch (err) {return "";}
        }
    }
    return "";
}
//获取或设置滚动条位置
function $scroll(roll) {
    if (roll) {
        window.scrollTo(roll.left, roll.top);
    }
    else if (document.documentElement && document.documentElement.scrollTop) 
    {
        return {
            top:document.documentElement.scrollTop,
           left:document.documentElement.scrollLeft
        }
    } 
    else if (document.body) 
    {
        return { 
            top:document.body.scrollTop,
           left:document.body.scrollLeft
        }
    }
}
//获取窗口大小
function $winSize() {
    var w = 0, h = 0;

    if (typeof (window.innerWidth) == 'number') {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientWidth) {
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    return { width: w, height: h };
}

//获取鼠标位置
function $position(e) {
    if (e.pageX || e.pageY) {
        return { x: e.pageX, y: e.pageY };
    }
    return {
        x: e.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: e.clientY + document.body.scrollTop - document.body.clientTop
    }
}
//阻止事件冒泡函数
function stopBubble(e) {
    if (e && e.stopPropagation)
        e.stopPropagation()
    else
        window.event.cancelBubble = true
}
//阻止浏览器的默认行为
function stopDefault(e) {
    if (e && e.preventDefault)
        e.preventDefault();
    else
        window.event.returnValue = false;
    return false;
}
//同步容器高度
function syncHeight(box1, box2,inner, i) {
    var h1 = $(box1).scrollHeight;
    var h2 = $(box2).scrollHeight;

    var maxHeight = Math.max(h1, h2);
    $(box1).style.height = maxHeight + "px";
    $(box2).style.height = maxHeight + "px";

    if (i != null) maxHeight = maxHeight - i;
    $(inner).style.height = maxHeight + "px";

}

var BannerAD = function() {
    this.Images = new Array();
    this.Src = new Array();
    this.Url = new Array();
    this.PCode = new Array();
    this.CName = new Array();
    this.Data = new Array();

    var index = 1;
    var index2 = 0;

    function setTransition(Element) {
        if (document.all) {
            Element.filters.revealTrans.Transition = Math.floor(Math.random() * 23);
            Element.filters.revealTrans.apply();
        }
    }

    function playTransition(Element) {
        if (document.all)
            Element.filters.revealTrans.play()
    }

    this.play = function(type) {
        if (this.Src.length < 2) return;
        var _images = this.Images;
        var _src = this.Src;
        var timer = setInterval(function() {
            for (var i = 0; i < _images.length; i++) {
                setTransition(_images[i]);
                _images[i].src = _src[index];
                playTransition(_images[i]);

                index++;
                if (index >= _src.length) index = 0;
            }
        }, 5000);
    }

    this.play2 = function() {
        var _images = this.Images;
        var _src = this.Src;
        var _url = this.Url;
        var _pcode = this.PCode;
        var _cname = this.CName;

        var timer = setInterval(function() {
            for (var i = 0; i < _images.length; i++) {
                setTransition(_images[i]);
                _images[i].src = _src[index];
                var pcode = $("index_product_pcode" + i);
                var cname = $("index_product_cname" + i);

                pcode.innerHTML = _pcode[index];
                cname.innerHTML = _cname[index];

                pcode.href = _url[index];
                _images[i].parentNode.href = _url[index];

                playTransition(_images[i]);

                index++;
                if (index >= _src.length) index = 0;
            }
        }, 5000);
    }

    this.play3 = function() {
        if (this.Src.length < 2) return;
        var _images = this.Images;
        var _pcode = this.PCode;
        var _src = this.Src;
        var _url = this.Url;
        var _code = [$("index_product_pcode0"), $("index_product_pcode1"), $("index_product_pcode2")];

        for (var i = 0; i < 3; i++) {
            _images[i].src = _src[i][0];
            _images[i].parentNode.href = _url[i][0];

            _code[i].innerHTML = _pcode[i][0];
            _code[i].href = _url[i][0];
        }

        var timer = setInterval(function() {
            for (var i = 0; i < _images.length; i++) {
                index2 = index % _src[i].length;

                setTransition(_images[i]);

                _images[i].src = _src[i][index2];
                _images[i].parentNode.href = _url[i][index2];

                _code[i].innerHTML = _pcode[i][index2];
                _code[i].href = _url[i][index2];

                playTransition(_images[i]);
            }
            index++;
        }, 5000);
    }
}

function aa() {
    var aa = new Array();
    
}
