﻿var jq = {
    $: function(id)
    {
        var obj = document.getElementById(id);
        if (!obj) return false;

        obj.observe = function(evname, bserver) { if (obj.attachEvent) this.attachEvent("on" + evname, bserver); else this.addEventListener(evname, bserver, false); };
        obj.dobserve = function(evname, bserver) { if (obj.attachEvent) this.detachEvent("on" + evname, bserver); else this.removeEventListener(evname, bserver, false); };

        obj.isShow = function() { return obj.style.display == "block"; };
        obj.isHide = function() { return obj.style.display == "none"; };
        obj.show = function() { obj.style.display = "block"; };
        obj.hide = function() { obj.style.display = "none"; };

        return obj;
    },

    isIE: navigator.appVersion.indexOf("MSIE") != -1 ? true : false,

    //{url, w, h, objid, bg, win}
    flash: function(paras)
    {
        var wm = "Transparent";
        if (paras.isWin)
            wm = "Window";

        var flashStr = '\<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"\
                            width="' + paras.w + '" height="' + paras.h + '" id="FLVPlayer">\
                            <param name="movie" value="' + paras.url + '" />\
                            <param name="wmode" value="' + wm + '" />\
                            <param name="salign" value="lt" />\
                            <param name="quality" value="high" />\
                            <param name="scale" value="noscale" />\
                            <embed src="' + paras.url + '" quality="high" wmode="' + wm + '" scale="noscale" menu="false" width="' + paras.w + '" height="' + paras.h + '" name="FLVPlayer" salign="LT" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
                        </object>';

        if (paras.flv)
            var flashStr = '\
                    <object type="application/x-shockwave-flash" data="/images/tplayer.swf" width="' + paras.w + '" height="' + paras.h + '" id="vcastr3">\
			        <param name="movie" value="/images/tplayer.swf"/>\
			        <param name="wmode" value="'+wm+'" />\
			        <param name="allowFullScreen" value="true" />\
			        <param name="FlashVars" value="xml=\
				        <vcastr>\
					        <channel>\
						        <item>\
							        <source>' + paras.flv + '</source>\
							        <duration></duration>\
							        <title></title>\
						        </item>\
					        </channel>\
					        <config>\
					        </config>\
					        <plugIns>\
					        </plugIns>\
				        </vcastr>"/>\
		            </object>';

        if (paras.objID)
            jq.$(paras.objID).innerHTML = flashStr;
        else
            document.write(flashStr);
    },
    
    // 发送json请求
    sendJson: function(url, onend, onbefore)
    {
        var getJson = function(xmlHttp, onend)
        {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var json = eval("(" + xmlHttp.responseText + ")");
                onend(json);
            }

            xmlHttp = null;
        };

        var xmlHttp;
        if (window.ActiveXObject)
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest)
            xmlHttp = new XMLHttpRequest();

        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = function() { getJson(xmlHttp, onend); }
        xmlHttp.send(null);

        if (onbefore != null)
            onbefore(); //处理预发消息
    }
};