﻿//更新时间：3-21

function addFlash(m_width, m_height, m_style, m_src, m_flashvars) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width=" + m_width + " height=" + m_height + " style=\"margin:0px;" + m_style + "\">");
    document.write("<param name='movie' value='" + m_src + "' />");
    document.write("<param name='quality' value='high' />");
    document.write("<param name='menu' value='false' />");
    document.write("<param name='wmode' value='transparent' /> ");
    document.write("<param name='flashvars' value='" + m_flashvars + "' /> ");
    document.write("</object>");
}

//收藏
function mark() {
    bookmark(window.location, document.title);
}
function bookmark(sURL, sTitle) {
    try {
        window.external.AddFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
//设为首页
function setHome(This) {
    This.style.behavior = 'url(#default#homepage)';
    This.setHomePage(window.location);
}


function flashNew(width, height, pics, titles, links) {
    //csdn:addFlash(width,height,"background:#000000","/content/pic.swf","pic_width="+width+"&pic_height="+height+"&pics="+pics+"&links="+links+"&texts="+titles+"&show_text=0&txtcolor=000000&bgcolor=666666&button_pos=4&stop_time=3000&border=0");
    if (titles.length > 6) {
        addFlash(width, height, "background:#eeeeee", "/content/pixviewer.swf",
            "borderwidth=" + width + "&borderheight=" + (height - 18) + "&pics=" + pics + "&links=" + links + "&texts="
            + titles + "&textheight=18&curhref=http://www.sina.com.cn");
    } else {
        addFlash(width, height, "background:#eeeeee", "/content/pixviewer.swf",
            "borderwidth=" + width + "&borderheight=" + height + "&pics=" + pics + "&links=" + links + "&texts="
            + titles + "&textheight=0&curhref=http://www.sina.com.cn");
    }
    //pics=&links=&texts=&borderwidth=306&borderheight=169&textheight=0&curhref=
}


//BannerShow
function BannerShow() {
    this.mID = null;
    this.timer = null;
    this.mHtml = "";
    this.Img = new Array();
    this.Title = new Array();
    this.Address = new Array();
    this.index = 0;
    //添加图片
    this.AddImage = function(img, title, address) {
        this.Img[this.Img.length] = img;
        this.Title[this.Title.length] = title;
        this.Address[this.Address.length] = address;
    }
    //开始播放
    this.playNext = function() {

        this.index++;
        if (this.index >= this.Img.length) this.index = 0;
        for (var i = 0; i < this.Img.length; i++) {
            if (i == this.index) {
                document.getElementById(this.mID + "img" + i).filters.blendTrans.apply();
                document.getElementById(this.mID + "img" + i).style.visibility = "visible";
                document.getElementById(this.mID + "img" + i).filters.blendTrans.play();
            } else {
                document.getElementById(this.mID + "img" + i).filters.blendTrans.apply();
                document.getElementById(this.mID + "img" + i).style.visibility = "hidden";
                document.getElementById(this.mID + "img" + i).filters.blendTrans.play();
            }
        }
    }
    //开始构建
    this.create = function(id, width, height, non_click) {
        this.mID = id;
        this.mHtml = "<div id='" + id + "' style='width:" + width + "px;height:" + height + "px;position:relative;overflow:hidden;'>";
        for (var i = 0; i < this.Img.length; i++) {
            this.mHtml = this.mHtml + "<a href='" + this.Address[i] + "' title='" + this.Title[i] + "' target='_blank'><img alt='" + this.Title[i] + "' id='" + id + "img" + i + "' src='" + this.Img[i] + "' style='width:100%;height:100%;position:absolute;top:0px;left:0px;margin:0px;FILTER: blendTrans(duration=1);border:0px;"
            if (i != 0) this.mHtml = this.mHtml + "visibility:hidden;"; //将第一个设为可见
            this.mHtml = this.mHtml + "' /></a>";
        }

        if (non_click == true) {
            this.mHtml = this.mHtml + "<div style='position:absolute;width:100%;height:100%;background:#FFFFFF;filter:alpha(style=0,opacity=1);'>您的浏览器版本过低</div>";
        }

        this.mHtml = this.mHtml + "</div>";
        document.write(this.mHtml);
    }
    //播放
    this.play = function() {
        if (this.timer == null) {
            var self = this;
            this.timer = setInterval(function() { self.playNext(); }, 5000);
        }
    }
    //停止
    this.stop = function() {
        clearInterval(this.timer);
        this.timer = null;
    }
    //调用构建


}

//动画切换:简单
function EasyBanner(width, height, images) {
    var tm = new Date();
    var banner = new BannerShow();
    var imgs = images.split("|");
    for (var i = 0; i < imgs.length; i++) {
        banner.AddImage(imgs[i], "", "/");
    }
    banner.create("abc" + tm.getTime(), width, height, true);
    banner.play();

}




///***********************************************************
//在线客服
function hideKF() {
    document.getElementById("kfdiv").style.display = "none";
}
function KF(qq, info) {
    var _self = this;
    //飘动    
    this.move = function() {
        var img = document.getElementById("kfdiv").style.top = 80 + document.documentElement.scrollTop; //80+document.body.scrollTop;
    }

    //输出对象
    var html = "<div id='kfdiv' style='top:80px;cursor:hand;position:absolute;width:100px;height:200px;right:3px; z-inde:99;background:url(\"/content/user_kf.gif\") no-repeat;' >\r\n";
    html += ("<a href='tencent://message?uin=" + qq + "' style='display:block;height:120px;border:0px solid red;'>&nbsp;</a><div style='cursor:hand;position:absolute;width:90px;height:70px;border:0px solid red;left:5px;top:115px;overflow:hidden;'>" + info + "</div>");
    html += ("<img title='点击此处关闭' src='/content/close.gif' onclick='hideKF()' style='color:blue;position:absolute;bottom:1px;left:2px;' />");
    html += ("</div>\r\n");
    document.write(html);
    //设置事件
    window.attachEvent("onscroll", _self.move);
    window.attachEvent("onresize", _self.move);
    //window.onscroll += function() { _self.move(); }
    //window.onresize += function() { _self.move(); }
    //改变背景
    this.SetBackground = function(img) {
        document.getElementById("kfdiv").style.background = "url(" + img + ") no-repeat";
    }
    //改变前影色
    this.SetForeColor = function(color) {
        document.getElementById("kfdiv").style.color = color;
    }
    //设置样式
    this.SetBackgroundIndex = function(idx) {
        switch (idx) {
            case 0:
                this.SetBackground("/content/hichina_kf.gif");
                break;
            case 1:
                this.SetBackground("/content/user_kf.gif");
                break;
            default:
                break;
        }

    }

}





//===================禁止选择网页内容，屏蔽右键==========
//调用方式：<script>DeSelect();</script>
function DeSelect() {
    this.__szft_empty = function() {
        document.selection.empty();
    }
    this.__szft_return_false = function() {
        return false;
    }
    this.__EventsBind = function() {
        try {
            document.body.oncontextmenu = this.__szft_return_false;
            document.body.ondragstart = this.__szft_return_false;
            document.body.onselectstart = this.__szft_return_false;
            document.body.onselect = this.__szft_empty;
            document.body.oncopy = this.__szft_empty;
            document.body.onbeforecopy = this.__szft_return_false;
            document.body.onmouseup = this.__szft_empty;
        }
        catch (e) {
            //屏蔽失败
        }
    }
    this.__EventsBind();
}


//获取META信息
function GetMETA(metaname) {
    var metas = document.getElementsByTagName('META');
    for (var i = 0; i < metas.length; i++) {
        if (metas[i].getAttribute('NAME').toUpperCase() == metaname.toUpperCase())
            return metas[i].getAttribute('CONTENT');
    }
    return "";
}


//String扩展
String.prototype.format = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,
        function(m, i) {
            return args[i];
        });
}

String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}
//String扩展:替换全部
String.prototype.replaceAll = function(s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}


//水印API===================================================================================================
function ApplyMask(ImgObj, width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text) {
    var masktext = "www.zyc1.com";
    if (mask_text != null) masktext = mask_text;

    var commonstyle = "position:absolute;width:100%;height:100%;left:0px;top:0px;font-family:Tahome;font-weight:bold;font-size:" + font_size + ";";
    var img = ImgObj;  //document.getElementById(imgid);
    img.style.width = "100%";
    img.style.height = "100%";
    img.style.border = "0px";

    var obj = document.createElement("span");
    obj.setAttribute("style", "width:" + width + ";height:" + height + ";border:0px solid Gray;display:inline-block;position:relative;overflow:hidden;line-height:" + line_height
                        + ";text-align:center;color:" + text_color + ";font-family:" + font_family + ";margin:0px;padding:0px;");
    img.parentNode.insertBefore(obj, img);
    obj.insertBefore(img, null);
    obj.innerHTML += "<span style='" + commonstyle + "filter:alpha(style=0,opacity=1);z-index:88;background:#FFFFFF;'></span>";
    obj.innerHTML += "<span style='filter:DropShadow(Color=#555555,OffX=1,OffY=1,Positive=1) alpha(style=0,opacity=" + font_opacity + ");  z-index:99;" + commonstyle + "'>" + masktext + "</span>";

}
//将ID为ＸＸ的图片加上水印
function ApplyByID(imgid, width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text) {
    ApplyMask(document.getElementById(imgid), width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text);
}
//将某DIV下的所有图片加上水印
function UseMasks(DivObj, width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text) {
    var cld = DivObj.childNodes;
    for (var i = 0; i < cld.length; i++) {
        try {
            if (cld[i].tagName.toLowerCase() == "img") {
                ApplyMask(cld[i], width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text);
            } else {
                UseMasks(cld[i], width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text);
            }
        }
        catch (e) { }
    }
}
//将某DIV下的所有图片加上水印
function use_mask_for_all_child_objects(DivName, width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text) {
    UseMasks(document.getElementById(DivName), width, height, line_height, text_color, font_size, font_family, font_opacity, mask_text)
}


/*
创建滚动文本对象:内容所在div的ID,创建高度，速度，是否启用调试信息
*/
function TextScroller(sourceID, divHEIGHT, speed, deubg_mode) {
    this._divHEIGHT = 50;                                                               //即将创建的容器高度
    this._sourceID = sourceID;                                                                  //源ID
    this._offHeight = document.getElementById(sourceID).scrollHeight;        //内容的高度 scrollHeight(内容实际高度) offsetHeight(可视区高度)
    this._sourceContent = document.getElementById(sourceID).innerHTML;
    this._content_div = "cnt" + sourceID;
    this._speed = 90;
    this._paused = false;
    this._deubg_mode = deubg_mode;

    if (undefined != divHEIGHT) this._divHEIGHT = divHEIGHT;
    if (undefined != speed) this._speed = speed;

    //创建对象
    this.go = function() {
        var _self = this;
        document.getElementById(sourceID).style.overflow = "hidden";
        document.getElementById(sourceID).style.position = "relative";
        document.getElementById(this._sourceID).innerHTML = "<div id='" + this._content_div + "'><div>" + this._sourceContent + "</div><div>" + this._sourceContent + "</div></div>";
        document.getElementById(this._content_div).style.position = "absolute";
        document.getElementById(this._content_div).style.top = "0px";
        document.getElementById(sourceID).style.height = "" + this._divHEIGHT + "px";

        document.getElementById(this._content_div).onmouseover = function() {
            _self._paused = true;
        };
        document.getElementById(this._content_div).onmouseout = function() {
            _self._paused = false;
        };


        //滚动控制：开始
        setInterval(function() {
            if (_self._paused) return;
            var top = parseInt(document.getElementById(_self._content_div).style.top);
            var nTop = top - 1;
            var ln = 0 - _self._offHeight; // (parseInt(_self._offHeight) * 2 - parseInt(_self._divHEIGHT));
            if (nTop < ln) nTop = 0;
            document.getElementById(_self._content_div).style.top = nTop;
            if (_self._deubg_mode != undefined) document.title = "top:" + nTop + "　contentHeight:" + _self._offHeight;
        }, this._speed);
        //滚动控制：结束

    }

    //开始
    this.go();
}




function SogouPatch() {
    var _self = this;
    this.close = function() { document.getElementById("sg_patch").style.display = "none"; }
    //飘动
    this.move = function() {
        var ttt = document.documentElement.scrollTop + document.documentElement.clientHeight - 220;
        document.getElementById("sg_patch").style.top = "" + ttt + "px";
    }
    //修复搜狐显示错误
    this.repair = function() {
        document.getElementById("sogouh2").style.background = "transparent";
        document.getElementById("sogouh2").style.lineHeight = "12px";
        document.getElementById("sogouh2").style.fontSize = "9pt";
        document.getElementById("sogouh2").style.paddingTop = "1px";
    }
    //输出对象 
    document.write("<div id='sg_patch' style='position:absolute;width:230px;height:250px; left:0px;display:block;'></div>");
    //移动搜狗留言框的位置
    var sogouobj = "" + document.getElementById("sogouMessage").outerHTML;
    document.getElementById("sogouMessage").outerHTML = "";
    document.getElementById("sg_patch").innerHTML = sogouobj;
    //修复搜狗的毛病
    this.repair();
    //设置事件  
    window.attachEvent("onscroll", _self.move);
    window.attachEvent("onresize", _self.move);
    document.getElementById("sogouImg").onclick = function() { alert("test"); }; // _self.close;
    //document.getElementById("sogouImg").attachEvent("onclick",_self.close); 


    _self.move();
}


//图片播放
function SlidePlayer(Baseuri, Width) {
    this.objID = "ss" + ((new Date()).getTime() * 1000);
    this.width = Width == null ? "" : "width:" + Width + "px;";
    this._baseuri = Baseuri == null ? "." : Baseuri;
    this.imgs = new Array();
    this.pos = 0;
    var _this = this;
    this.push = function(img) { this.imgs.push(img); return this; }
    this.setText = function() {
        document.getElementById("{0}title".format(_this.objID)).innerText = "【{0}/{1}】点击图片播放下一张".format(
        _this.pos + 1, _this.imgs.length);

    }
    //开始播放
    this.start = function() {
        var htmlstr = "<center style='{4}'><img id='{0}' src='{2}/{1}' style='cursor:hand;border:0px;{3}' /><br ><span id='{0}title'></span></center>";
        document.write(htmlstr.format(
            this.objID, this.imgs[0], this._baseuri, this.width, "font-size:9pt;font-family:tahoma;")
        );
        this.setText();
        document.getElementById(this.objID).onclick = function() {
            _this.pos++;
            if (_this.pos >= _this.imgs.length) _this.pos = 0;
            document.getElementById(_this.objID).src = _this._baseuri + "/" + _this.imgs[_this.pos];
            _this.setText();

        };

    } 
    
}