﻿//更新时间：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);
}

 

//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) {
        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>";
        }
        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);
    banner.play();

}


 
//===================禁止选择网页内容，屏蔽右键==========
//调用方式：<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;
}



//图片播放Baseuri, 
function SlidePlayer(Width, Height) {
    this.objID = "ss" + ((new Date()).getTime() * 1000);
    this.width = Width == null ? "" : "width:{0}px;".format(Width);
    this.height = Height == null ? "" : ("height:{0}px;").format(Height);
    this.textWidth = Width == null ? "" : "width:{0}px;".format(Width - 40);
    this.imgs = new Array();
    this.urls = new Array();
    this.titles = new Array();
    this.pos = 0;
    var _this = this;
    //添加图片
    this.push = function (img, gouri, title) {
        this.imgs.push(img);
        this.urls.push(gouri);
        this.titles.push(title);
        return this;
    }
    //设置文字
    this.setText = function () {
        var titleid = "{0}title".format(_this.objID);
        var title = this.titles[this.pos] == null ? "未命名图片新闻" : this.titles[this.pos];
        document.getElementById(_this.objID).title = title;
        document.getElementById(_this.objID).alt = title;
        document.getElementById(titleid).innerText = "【{0}/{1}】{2}".format(_this.pos + 1, _this.imgs.length, title);
    }

    this.Next = function () {
        //切换开始
        _this.pos++;
        if (_this.pos >= _this.imgs.length) _this.pos = 0;
        document.getElementById(_this.objID).src = _this.imgs[_this.pos];
        _this.setText();
        //切换结束 
        return _this;
    };
    this.Prev = function () {
        //切换开始
        _this.pos--;
        if (_this.pos < 0) _this.pos = _this.imgs.length - 1;
        document.getElementById(_this.objID).src = _this.imgs[_this.pos];
        _this.setText();
        //切换结束 
        return _this;
    };

    //开始播放
    this.start = function () {
        var htmlstr = "<center style='{4}'><div style='position:relative;overflow:hidden;{2}{3}'><img id='{0}' src='{1}' \
              style='cursor:hand;border:0px;width:100%;height:100%;' />\
             <span  style=\"position:absolute;left:0px;bottom:0px;display:block;background:#000000; \
             width:100%;height:20px;line-height:20px;color:#FFFFFF;filter:alpha(style=0,opacity=64);\"></span> \
             <span style='position:absolute;right:0px;bottom:0px;display:block; z-index:88; width:100%; height:20px;\
             line-height:20px;color:#FFFFFF; text-align:center;  '>\
            <a  id='{0}prev' style='display:block;cursor:hand;width:20px;height:20px;text-align:center;float:left;font-family:marlett;text-decoration:none;color:#FFFFFF;'>3</a>\
            <a  id='{0}next' style='display:block;cursor:hand;width:20px;height:20px;text-align:center;float:right;font-family:marlett;text-decoration:none;color:#FFFFFF;'>4</a>\
            <span  id='{0}title' style=' position:relative;overflow:hidden;height:20px;width:{5};display:block;'></span>\
            </span>\
             </div></center> ";

        //输出
        document.write(htmlstr.format(this.objID, this.imgs[0], this.width, this.height, "font-size:9pt;font-family:tahoma;", this.textWidth));
        this.setText();
        document.getElementById(this.objID).onclick = function () { //alert(_this.urls[_this.pos] == null ? "未指定地址" : _this.urls[_this.pos]);
            if (_this.urls[_this.pos] != null) window.open(_this.urls[_this.pos]); //this.Next; 
        }
        setInterval(_this.Next, 3000);
        //绑定
        var cmdNext = document.getElementById(this.objID + "next");
        cmdNext.onclick = this.Next;
        var cmdPrev = document.getElementById(this.objID + "prev");
        cmdPrev.onclick = this.Prev;


        return this;
    }



}







    /*水平滚动*/
    function HScroller(sourceID, divWidth, speed, deubg_mode) {
        this._divWidth = 50; 											//即将创建的容器高度
        this._sourceID = sourceID; 										//源ID
        this._offWidth = document.getElementById(sourceID).scrollWidth; 	//内容的高度 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 != divWidth) this._divWidth = divWidth;
        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 + "'><table cellspacing=0 cellpadding=0 border=0><tr><td>" + this._sourceContent  +"</td><td>"+ this._sourceContent + "</td></tr></table></div>";
			document.getElementById(this._content_div).style.position = "absolute";
            document.getElementById(this._content_div).style.left = "0px";
            document.getElementById(sourceID).style.width = "" + this._divWidth + "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 left = parseInt(document.getElementById(_self._content_div).style.left);
                var nLeft = left - 1;
                var ln = 0 - _self._offWidth; 
                if (nLeft < ln) nLeft = 0;
                document.getElementById(_self._content_div).style.left = nLeft;
                if (_self._deubg_mode != undefined) document.title = "left:" + nLeft + "　contentWidth:" + _self._offWidth;
            }, this._speed);
            //滚动控制：结束

        }

        //开始
        this.go();
    }


    ///垂直滚动
    function VScroller(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 PhotoPlayer() {
        //变量
        this._id = "" + (new Date()).getTime() * 1000;
        this._img = new Array();
        this._index = -1;
        var _self = this;
        //开始显示
        this.show = function() {
            var html = "<div id='{0}' style='background:#FFFFFF;min-height:400px;width:100%;'><center><img id='img{0}' style='width:90%;margin:5px;' /><div id='button{0}'></div></center></div>".format(this._id);
            document.write(html);
            this._next();
        }
        //显示全部
        this.showAll = function() {
            for (var i = 0; i < this._img.length; i++) {
                document.write("<img src='{0}' class='imgitem' />".format(this._img[i]));
            }
        }

        //添加图片
        this.push = function(uri) {
            var imgs = uri.split("|");
            for (var i = 0; i < imgs.length; i++)
                this._img.push(imgs[i]);
        }
        //下一张
        this._next = function() {
            this._index++;
            _self._goto(this._index);
        }
        //跳至某张
        this._goto = function(index) {
            _self._index = index;
            document.getElementById("img" + _self._id).src = _self._img[_self._index];
            _self._show_button();
        }
        //显示按钮
        this._show_button = function() {
            var htmls = "";
            for (var i = 0; i < _self._img.length; i++) {
                htmls += ("<a href='{0}' id='buttonitem{2}_{1}' onclick='javascript:document.getElementById(\"img{2}\").src=this.href;return false;'> [{1}] </a>".format(_self._img[i], i + 1, _self._id));
            }
            document.getElementById("button{0}".format(_self._id)).innerHTML = htmls;
        }

    }





    //留言表单提交检查
    function checkGbForm() {
        var uid = document.getElementById("txtUID").value;
        var title = document.getElementById("txtTitle").value;
        var content = document.getElementById("txtContent").value;
        if ((uid.length == 0) | (title.length == 0) | (content.length == 0)) {
           
            alert("表单中的任何一项都必须填写!");
            return false;
        }

        var exp = /(<.+?>)/igm;
        if (exp.test(content)) {
            document.getElementById("txtContent").value = content.replace(exp, "");
            alert("检测到非法字符!");
            return false;
        }
        else {
            document.getElementById("cmdPostMessage").setAttribute("disabled", "disabled");
            document.getElementById("cmdPostMessage").value = "正在提交...";
            //提交
            $.post("/Feedback.ashx", { "title": title, "uid": uid, "content": content }, function (e) {
                alert(e);
                if (e.indexOf("[OK]") >= 0) {
                    document.getElementById("cmdPostMessage").value = "恭喜，提交成功！";
                } else {
                    document.getElementById("cmdPostMessage").removeAttribute("disabled");
                    document.getElementById("cmdPostMessage").value = "立即提交";
                }
            }, "text");
        }

        return false;
    }
