/*
* 中商网标准JS
* 2009/01/07 
*/
//搜索条
function SearchTextSetUp(flag, SearchTextSet, txtId) {
    if (document.getElementById(txtId)) {
        var obj = document.getElementById(txtId);
        if (flag && obj.value.length == 0) {
            obj.value = SearchTextSet;
            obj.style.color = "gray";
        }
        else if (!flag && obj.value == SearchTextSet) {
            obj.value = "";
            obj.style.color = "black";
        }
    }
}

//横向滚动(无按键)
function newScrollHorz(divId, firstTdId, secondTdId, scrollSpeed, colWidth, totalLength, scrollType, stopInteval) {
    var stopscroll = false;
    var div = document.getElementById(divId);
    if (div) {
        div.onmouseover = function() {
            stopscroll = true;
        }
        div.onmouseout = function() {
            stopscroll = false;
        }
        var first = document.getElementById(firstTdId);
        if (first) {
            var second = document.getElementById(secondTdId);
            if (second) {
                second.innerHTML = first.innerHTML

                var reset = true;
                var preLeft = 0;
                var total = 0;
                var currentLeft = 0;
                var stoptime = 0;

                //调用
                init_srolltext();

                function init_srolltext() {
                    div.scrollLeft = 0;
                    setInterval(scrollLeft, scrollSpeed);
                }

                //滚动函数定义
                function scrollLeft() {
                    if (stopscroll) return;
                    currentLeft += scrollType;
                    if (scrollType == 1 && currentLeft > colWidth) {
                        stoptime += 1;
                        currentLeft -= 1;
                        if (stoptime > stopInteval) {
                            currentLeft = 0;
                            stoptime = 0;
                        }
                        if (reset && (div.scrollLeft % colWidth > 0)) {
                            div.scrollLeft = 0;
                            reset = false;
                        }
                    } else {
                        preLeft = div.scrollLeft;
                        div.scrollLeft += 1;
                        total += scrollType;
                        if (preLeft == div.scrollLeft) {
                            div.scrollLeft = 0;
                            div.scrollLeft += 1;
                        }
                    }
                    if (total >= totalLength) {
                        div.scrollLeft = 0;
                        total = 0;
                    }
                }
            }
        }
    }
}

//横向滚动(无按键、从左向右)
function newScrollHorzRight(divId, firstTdId, secondTdId, scrollSpeed, colWidth, totalLength, scrollType, stopInteval) {
    var stopscroll = false;
    var div = document.getElementById(divId);
    if (div) {
        div.onmouseover = function() {
            stopscroll = true;
        }
        div.onmouseout = function() {
            stopscroll = false;
        }
        var first = document.getElementById(firstTdId);
        if (first) {
            var second = document.getElementById(secondTdId);
            if (second) {
                second.innerHTML = first.innerHTML
                
                var reset = true;
                var preLeft = 0;
                var total = 0;
                var currentLeft = 0;
                var stoptime = 0;
                var divWidth = totalLength;

                //调用
                init_srolltext();

                function init_srolltext() {
                    div.scrollLeft = divWidth;
                    setInterval(scrollRight, scrollSpeed);
                }

                //滚动函数定义
                function scrollRight() {
                    if (stopscroll) return;
                    currentLeft += scrollType;
                    if (scrollType == 1 && currentLeft > colWidth) {
                        stoptime += 1;
                        currentLeft -= 1;
                        if (stoptime > stopInteval) {
                            currentLeft = 0;
                            stoptime = 0;
                        }
                        if (reset && ((divWidth-div.scrollLeft) % colWidth > 0)) {
                            div.scrollLeft = divWidth;
                            reset = false;
                        }
                    } else {
                        preLeft = div.scrollLeft;
                        div.scrollLeft -= 1;
                        total += scrollType;
                        if (preLeft == div.scrollLeft) {
                            div.scrollLeft = divWidth;
                            div.scrollLeft -= 1;
                        }
                    }
                    if (total >= totalLength) {
                        div.scrollLeft = divWidth;
                        total = 0;
                    }
                }
            }
        }
    }
}
        
//纵向滚动(无按键)
function newScrollVert(outerDivId, innerDivId, rowHeight, totalLength, scrollSpeed, scrollType, stopInteval) {
    //初始化
    var stopscroll = false;
    var reset = true;
    var scrollElem = document.getElementById(outerDivId);
    if (scrollElem) {
        scrollElem.style.overflow = "hidden";
        var marqueesHeight = scrollElem.style.height;
        var preTop = 0;
        var total = 0;
        var currentTop = 0;
        var stoptime = 0;
        var leftElem = document.getElementById(innerDivId);
        if (leftElem) {
            scrollElem.appendChild(leftElem.cloneNode(true));

            scrollElem.onmouseover = function() {
                stopscroll = true;
            }
            scrollElem.onmouseout = function() {
                stopscroll = false;
            }

            //调用
            init_srolltext();

            //滚动函数定义
            function scrollUp() {
                if (stopscroll) return;
                currentTop += scrollType;
                if (scrollType == 1 && currentTop > rowHeight) {
                    stoptime += 1;
                    currentTop -= 1;
                    if (stoptime > stopInteval) {
                        currentTop = 0;
                        stoptime = 0;
                    }
                    if (reset && (scrollElem.scrollTop % rowHeight > 0)) {
                        scrollElem.scrollTop = 0;
                        reset = false;
                    }
                } else {
                    preTop = scrollElem.scrollTop;
                    scrollElem.scrollTop += 1;
                    total += scrollType;
                    if (preTop == scrollElem.scrollTop) {
                        scrollElem.scrollTop = 0;
                        scrollElem.scrollTop += 1;
                    }
                }
                if (total >= totalLength) {
                    scrollElem.scrollTop = 0;
                    total = 0;
                }
            }

            function init_srolltext() {
                scrollElem.scrollTop = 0;
                setInterval(scrollUp, scrollSpeed);
            }
        }
    }
}

//图片纵向滚动
function scrollVert(timeout, speed, interval, height, max, de, marque1, marque2, btn1, btn2) {
    marque2.innerHTML = marque1.innerHTML;
    var tmpHeight, ware_height;
    var MyMar1, MyMar2;
    function Marquee_ctrl() {
        tmpHeight = de.scrollTop;
        ware_height = height;
        MyMar1 = setInterval(Marquee, interval);
    }
    var flag = true;
    function Marquee() {
        flag = false;
        if (Math.abs(de.scrollTop - tmpHeight) >= ware_height) {
            clearInterval(MyMar1);
            flag = true;
            return;
        }
        if (de.scrollTop >= marque1.scrollHeight) {
            ware_height = ware_height - de.scrollTop + tmpHeight;
            de.scrollTop = 0;
            tmpHeight = 0;
        } else {
            de.scrollTop = de.scrollTop + height * interval / speed;
        }
    }
    var MyMar = setInterval(Marquee_ctrl, timeout)
    de.onmouseover = function() { clearInterval(MyMar) }
    de.onmouseout = function() { MyMar = setInterval(Marquee_ctrl, timeout) }
    function Marquee1() {
        flag = false
        if (Math.abs(de.scrollTop - tmpHeight) >= max) {
            clearInterval(MyMar2);
            flag = true
            return;
        }
        if (de.scrollTop >= marque1.scrollHeight) {
            de.scrollTop = 0;
        } else {
            de.scrollTop = de.scrollTop + max;
        }
    }
    function Marquee2() {
        flag = false;
        if (Math.abs(de.scrollTop - tmpHeight) >= max) {
            clearInterval(MyMar2);
            flag = true;
            return;
        }
        if (de.scrollTop <= 0) {
            de.scrollTop = marque1.scrollHeight;
        } else {
            de.scrollTop = de.scrollTop - max;
        }
    }
    btn1.onclick = function() {
        if (flag) {
            clearInterval(MyMar);
            tmpHeight = de.scrollTop;
            MyMar2 = setInterval(Marquee1, interval)
            MyMar = setInterval(Marquee_ctrl, timeout);
        }
    }

    btn2.onclick = function() {
        if (flag) {
            clearInterval(MyMar);
            tmpHeight = de.scrollTop;
            MyMar2 = setInterval(Marquee2, interval)
            MyMar = setInterval(Marquee_ctrl, timeout);
        }
    }
}

//图片横向滚动
function scrollHorz(timeout, speed, interval, width, max, de, marque1, marque2, btn1, btn2) {
    marque2.innerHTML = marque1.innerHTML;
    var tmpWidth, ware_width;
    var MyMar1, MyMar2;
    function Marquee_ctrl() {
        tmpWidth = de.scrollLeft;
        ware_width = width;
        MyMar1 = setInterval(Marquee, interval);
    }
    function Marquee() {
        if (Math.abs(de.scrollLeft - tmpWidth) >= ware_width) {
            clearInterval(MyMar1);
            return;
        }
        if (de.scrollLeft >= marque1.scrollWidth) {
            ware_width = ware_width - de.scrollLeft + tmpWidth;
            de.scrollLeft = 0;
            tmpWidth = 0;
        } else {
            de.scrollLeft = de.scrollLeft + width * interval / speed;
        }
    }
    var MyMar = setInterval(Marquee_ctrl, timeout)
    de.onmouseover = function() { clearInterval(MyMar) }
    de.onmouseout = function() { MyMar = setInterval(Marquee_ctrl, timeout) }
    var width3;
    var move = 0;
    var scroll_button_on_off = true;
    function Marquee1() {
        if (Math.abs(de.scrollLeft - tmpWidth) >= width3) {
            clearInterval(MyMar2);
            scroll_button_on_off = true;
            return;
        }
        if (de.scrollLeft >= marque1.scrollWidth) {
            de.scrollLeft = 0;
        } else {
            de.scrollLeft = de.scrollLeft + max;
        }
    }
    function Marquee2() {
        if (Math.abs(de.scrollLeft - tmpWidth) >= width3) {
            clearInterval(MyMar2);
            scroll_button_on_off = true;
            return;
        }
        if (de.scrollLeft <= 0) {
            de.scrollLeft = marque1.scrollWidth;
        } else {
            de.scrollLeft = de.scrollLeft - max;
        }
    }
    btn1.onclick = function() {
        if (scroll_button_on_off) {
            scroll_button_on_off = false;
            clearInterval(MyMar);
            tmpWidth = de.scrollLeft;
            width3 = max;
            MyMar2 = setInterval(Marquee1, interval)
            MyMar = setInterval(Marquee_ctrl, timeout);
        }
    }

    btn2.onclick = function() {
        if (scroll_button_on_off) {
            scroll_button_on_off = false;
            clearInterval(MyMar);
            tmpWidth = de.scrollLeft;
            width3 = max;
            MyMar2 = setInterval(Marquee2, interval)
            MyMar = setInterval(Marquee_ctrl, timeout);
        }
    }
}

//多图flash1
function getShowImageFlash1(config, focus_width, swf_height, files, links, texts) {
    links = escape(links);
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + focus_width + '" height="' + swf_height + '">');
    document.write('<param name="movie" value="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片1.swf" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name=wmode value="opaque" />');
    document.write('<param name="FlashVars" value="config=' + config + '&bcastr_flie=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '" />');
    document.write('<embed src="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片1.swf" wmode="opaque" FlashVars="config=' + config + '&bcastr_flie=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '& menu="false" quality="high" width="' + focus_width + '" height="' + swf_height + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

//多图flash2
function getShowImageFlash2(focus_width, swf_height, pics, links, texts, focus_height, text_height) {
    links = escape(links);
    focus_width = parseInt(focus_width);
    swf_height = parseInt(swf_height);
    focus_height = parseInt(focus_height);
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + focus_width + '" height="' + swf_height + '">');
    document.write('<param name="allowscriptaccess" value="samedomain"><param name="movie" value="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片2.swf"><param name="quality" value="high"><param name="bgcolor" value="#ffffff">');
    document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
    document.write('<param name="flashvars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '">');
    document.write('<embed src="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片2.swf" wmode="opaque" flashvars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '" menu="false" bgcolor="#ffffff" quality="high" width="' + focus_width + '" height="' + focus_height + '" allowscriptaccess="samedomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

//多图flash3
function getShowImageFlash3(focus_width, swf_height, pics, links, texts, focus_height, text_height) {
    links = escape(links);
    focus_width = parseInt(focus_width);
    swf_height = parseInt(swf_height);
    focus_height = parseInt(focus_height);
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + focus_width + '" height="' + swf_height + '">');
    document.write('<param name="allowscriptaccess" value="samedomain"><param name="movie" value="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片3.swf"><param name="quality" value="high"><param name="bgcolor" value="#ffffff">');
    document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
    document.write('<param name="flashvars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '">');
    document.write('<embed src="http://img1.chinaec.net//12/1100001212//编辑器上传文件/Flash图片3.swf" wmode="opaque" flashvars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '" menu="false" bgcolor="#ffffff" quality="high" width="' + focus_width + '" height="' + focus_height + '" allowscriptaccess="samedomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

//撑开宽度
function ResetWidth() {
    if (!frameElement)
        return;
    if (frameElement.scrolling == "no") {
        if (document.body.offsetWidth < document.body.scrollWidth)
            frameElement.style.pixelWidth = document.body.scrollWidth;
    }
}

//撑开高度
function ResetHeight() {
    try {
        if (!frameElement)
            return;
        if (frameElement.scrolling == "no") {
            if (document.body.offsetHeight < document.body.scrollHeight)
                frameElement.style.height = document.body.scrollHeight;
        }
    } catch (e) { }
}

//不断撑开高度
function AutoResetHeight() {
    setInterval(ResetHeight, 100);
}

//跟随置顶
function ShowReturnTop(contentWidth, contentHeight, pageRetruenTop) {
    //定位功能代码 
    var myReturnTop = window.onresize = window.onscroll = function() {  //注册窗体滚动及尺寸变化事件
        var scrollX = document.body.scrollLeft;        //横向滚动宽度
        var scrollY = document.body.scrollTop;       //纵向滚动高度
        var windowWidth = document.body.clientWidth;          //窗口宽度
        var windowHeight = document.body.clientHeight;      //窗口高度
        if (windowWidth <= contentWidth) return;           //当宽度小于此相素时不做改变
        var x = Math.ceil(windowWidth / 2) - 1 + contentWidth / 2;     //定位div的横坐标
        var y = contentHeight + scrollY;   //定位div的纵坐标
        pageRetruenTop.style.display = 'block';
        pageRetruenTop.style.left = x + 'px';
        pageRetruenTop.style.top = y + 'px';
    };
    myReturnTop();
    //注册div点击事件 
    pageRetruenTop.onclick = function() {
        document.body.scrollTop = '0px';
    };
}


//图片等比例缩放
function DrawImage(ImgD, FitWidth, FitHeight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= FitWidth / FitHeight) {
            if (image.width > FitWidth) {
                ImgD.width = FitWidth;
                ImgD.height = (image.height * FitWidth) / image.width;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > FitHeight) {
                ImgD.height = FitHeight;
                ImgD.width = (image.width * FitHeight) / image.height;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
} 