﻿var lib = {};

lib.$ = function(e){
    var o = document.getElementById(e);
    if(o) return o;
    o = document.getElementsByName(e);
    if(o.tagName == undefined) return null;
    return o;
}

lib.euid = {};
lib.euid.toString = function(){
    var euid = "";
    for(var i=0;i<32;i++){
        euid += Math.floor(Math.random() * 16.0).toString(16);
    }
    return euid;
}

lib.ajax = function(url,method,content,async){
  var rper = false;
  var hper = this;
  try{
    rper = new XMLHttpRequest;
  }catch(e){
    try{
      rper = new ActiveXObject("MSXML2.XMLHTTP");
    }catch(e2){
      try{
        rper = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(e3){
        rper = false;
      }
    }
  }
  if(!rper) return false;
  this.method = method || "GET";
  this.url = url || "";
  this.async = async || true;
  this.content = content || "";
  this.collect = function(rxer){return;}
  this.connect = function(){
    if(!this.method||!this.url||!this.async) return false;
    rper.open(this.method,this.url,this.async);
    if(this.method=="POST") rper.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    rper.onreadystatechange = function(){
      if(rper.readyState==4){
        if(rper.status==200){
          hper.collect(rper);
        }
      }
    }
    if(this.method=="POST") rper.send(this.content);
    else rper.send(null);
  }
}

lib.event = function(o,e,r){
    if(arguments.length==1){
        lib.event(window,"load",arguments[0]);
    }else{
        if(window.attachEvent){
            if(typeof(o)=="string") o = lib.$(o);
            try{if(o!=null){
                if(typeof(r)=="string"){
                    o.attachEvent("on"+e,function(){eval(r)});
                }else if(typeof(r)=="function"){
                    o.attachEvent("on"+e,r);
                }
            }}catch(err){}
        }else{
            if(typeof(o)=="string") o = lib.$(o);
            try{if(o!=null){
                if(typeof(r)=="string"){
                    o.addEventListener(e,function(){eval(r)},false);
                }else if(typeof(r)=="function"){
                    o.addEventListener(e,r,false);
                }
            }}catch(err){}
        }
    }
}

lib.image = function(ele,ini,txt){
    // lib.image(e,[c,w,h,ih,a,t],[[i],[u],[t]]);
    //var dini = ini.slice(0,0);
    //var eini = ini.slice(0);
    //    dini.push("files/image.swf");
    //ini = dini.concat(eini);
    var code  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        code += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
        code += 'width="'+ ini[2] +'" height="'+ (ini[3] + ini[4]) +'">';
        code += '<param name="movie" value="' + ini[0] + '">';
        //code += '<param name="wmode" value="transparent">';
        code += '<param name="wmode" value="opaque">';
        code += '<param name="quality" value="high"><param name="bgcolor" value="' + ini[1] + '">';
        code += '<param name="menu" value="false"><param name=wmode value="opaque">';
        code += '<param name="FlashVars" value="pics=' + txt[0].join("|");
        code += '&links=' + txt[1].join("|") + '&texts=' + txt[2].join("|");
        code += '&borderwidth=' + ini[2] + '&borderheight=' + ini[3];
        code += '&textheight=' + ini[4] + '&text_align=' + ini[5] + '&interval_time=' + ini[6] + '">';
        code += '<embed src="' + ini[0] + '" wmode="opaque" FlashVars="pics=' + txt[0].join("|");
        code += '&links=' + txt[1].join("|") + '&texts=' + txt[2].join("|") + '&borderwidth=' + ini[2];
        code += '&borderheight=' + ini[3] + '&textheight=' + ini[4] + '&text_align=' + ini[5];
        code += '&interval_time=' + ini[6] + '" menu="false" bgcolor="' + ini[1] + '" quality="high" ';
        code += 'width="' + ini[2] + '" height="' + (ini[3] + ini[4]) + '" allowScriptAccess="sameDomain" ';
        code += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        code += '</object>';
        //<param name="wmode" value="transparent">
    if(lib.$(ele)!=null) lib.$(ele).innerHTML = code;
}

lib.media = function(ele,url,width,height,count,model,only){
    if(lib.$(ele)!=null){
        if(!width) width = "100%";
        if(!height) height = "100%";
        if(!count) count = 1;
        if(!model) model = "full";
        if(!only) only = "MPlayer";
        url = url.replace(/ /g,"%20").replace(/�/g,"·");
        var mh  = '<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="' + only + '" name="' + only + '" width="' + width + '" height="' + height + '">';
            mh += '<param name="URL" value="' + url + '"><param name="rate" value="1"><param name="balance" value="0">';
            mh += '<param name="currentPosition" value="0"><param name="defaultFrame" value><param name="playCount" value="' + count + '">';
            mh += '<param name="autoStart" value="-1"><param name="currentMarker" value="0"><param name="invokeURLs" value="-1">';
            mh += '<param name="baseURL" value><param name="volume" value="50"><param name="mute" value="0">';
            mh += '<param name="uiMode" value="' + model + '"><param name="stretchToFit" value="0"><param name="windowlessVideo" value="0">';
            mh += '<param name="enabled" value="-1"><param name="enableContextMenu" value="1"><param name="fullScreen" value="0">';
            mh += '<param name="SAMIStyle" value><param name="SAMILang" value><param name="SAMIFilename" value>';
            mh += '<param name="captioningID" value><param name="enableErrorDialogs" value="0"></object>';
        //var ss = '<iframe id="MediaFramel" name="MediaFramel" marginwidth="0" marginheight="0" height="310" width="320" scrolling="no" border="0" frameborder="0"></iframe>';
        lib.$(ele).innerHTML = mh;
        //lib.$(ele).innerHTML = ss;
        //MediaFramel.document.write('<html><body style="border:0px;">' + mh + '</body><html>');
        if(model=="none"){
            lib.$(only).onmouseover = function(){
                lib.$(only).uiMode = "full";
            }
            lib.$(only).onmouseout = function(){
                lib.$(only).uiMode = "none";
            }
        }
    }
}

lib.flash = function(ele,url,width,height,query){
    if(!width) width = "100%";
    if(!height) height = "100%";
    var code  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        code += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
        code += 'width="'+ width +'" height="'+ height +'">';
        code += '<param name="movie" value="' + url + '">';
        code += '<param name="quality" value="high">';
        code += '<param name="menu" value="false"><param name=wmode value="opaque">';
        if(query!=null){
            code += '<param name="FlashVars" value="' + query + '">';
        }
        code += '<embed src="' + url + '" wmode="opaque" quality="high" ';
        if(query!=null){
            code += 'FlashVars="' + query + '" ';
        }
        code += 'width="' + width + '" height="' + width + '" allowScriptAccess="sameDomain" ';
        code += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        code += '</object>';
    if(lib.$(ele)!=null) lib.$(ele).innerHTML = code;
}

lib.MediaPanel = function(url){
    //lib.media(ele,url,width,height,count,model,only);
    if(lib.$("MediaPanel")!=null) lib.media("MediaPanel",url,320,310);
}

lib.MediaFramel = function(url){
    if(lib.$("MediaFramel")!=null) lib.$("MediaFramel").src = url;
}

lib.track = function(url,full){
    var e = {};
    if(full==null||full==false){
        e.w = 682;
        e.h = window.screen.availHeight - 160;
    }else{
        e.w = window.screen.availWidth - 10;
        e.h = window.screen.availHeight - 160;
    }
    e.s = "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,";
    window.open(url,null,e.s + "width=" + e.w + ",height=" + e.h);
}

lib.__track = function(url,full){
    var d = lib.$("divFrame");
    if(d!=null){
        if(full==null||full==false){
            d.style.width = 682;
            d.style.height = document.body.clientHeight - 80;
            d.style.left = (document.body.clientWidth - d.clientWidth) / 2;
            var o = (document.body.clientHeight - d.clientHeight) / 2;
            o += document.body.scrollTop;
            d.style.top = o;
        }else{
            d.style.width = document.body.clientWidth;
            d.style.height = document.body.clientHeight;
            d.style.left = (document.body.clientWidth - d.clientWidth) / 2;
            var o = (document.body.clientHeight - d.clientHeight) / 2;
            o += document.body.scrollTop;
            d.style.top = o;
        }
        d.style.visibility = "visible";
        d.src = url;
        if(lib.$("MediaFramel")!=null) lib.$("MediaFramel").style.visibility = "hidden"; //visible
    }
}

lib._track = function(url,full){
    //location.href("content.html");
    var e = lib.$("divBlack");
    if(e!=null){
        e.style.top = "0px";
        e.style.left = "0px";
        document.body.scroll = "no";
        e.style.width = document.body.clientWidth;
        if(document.body.clientHeight>document.body.scrollHeight){
            e.style.height = document.body.clientHeight;
        }else{
            e.style.height = document.body.scrollHeight;
        }
        var d = lib.$("divFrame");
        if(d!=null){
            if(full==null||full==false){
                d.style.width = 682;
                d.style.height = document.body.clientHeight - 80;
                d.style.left = (document.body.clientWidth - d.clientWidth) / 2;
                var o = (document.body.clientHeight - d.clientHeight) / 2;
                o += document.body.scrollTop;
                d.style.top = o;
            }else{
                d.style.width = document.body.clientWidth;
                d.style.height = document.body.clientHeight;
                d.style.left = (document.body.clientWidth - d.clientWidth) / 2;
                var o = (document.body.clientHeight - d.clientHeight) / 2;
                o += document.body.scrollTop;
                d.style.top = o;
            }
            e.style.visibility = "visible";
            d.style.visibility = "visible";
            d.src = url;
            if(lib.$("MediaFramel")!=null) lib.$("MediaFramel").style.visibility = "hidden"; //visible
        }else{
            document.body.scroll = "auto";
        }
    }
}

lib.close = function(e){
    if(e==true){
        parent.lib.close(false);
    }else{
        window.opener = null;
        window.close();
    }
}

lib._close = function(e){
    if(e==true){
        parent.lib.close(false);
    }else{
        //var e = lib.$("divBlack");
        var d = lib.$("divFrame");
        d.style.width = 0;
        d.style.height = 0;
        //e.style.width = 0;
        d.style.height = 0;
        if(d!=null) d.style.visibility = "hidden";
        //if(e!=null) e.style.visibility = "hidden";
        //document.body.scroll = "auto";
        d.src = "about:blank";
        if(lib.$("MediaFramel")!=null) lib.$("MediaFramel").style.visibility = "visible"; //hidden
    }
}

lib.PrintTrack = function(){
    if(lib.$("PrintTrack")!=null){
        //var s = "";
        //for(var i=0;i<27;i++){
            //s += '<div class="HalfPanel"><div class="temp"><a href="javascript:lib.track();"></a></div></div>';
        //    s += '<div class="HalfPanel"><div class="temp"><a href="channel.html" target="_blank">某某某局' + (i+1) + '</a></div></div>';
        //}
        //lib.$("PrintTrack").innerHTML = s;
        var o = lib.$("PrintTrack").childNodes;
        for(var i=0;i<o.length;i++){
            if((i+1)%3==0) o[i].style.width = o[i].clientWidth + 1;
        }
    }
}

var _ilike_yes = 5;
var _ilike_not = 5;

lib.CheckPanel = function(o,e){
    var d = lib.$("CheckPanel");
    if(d==null) return;
    d.style.visibility = "visible";
    d.style.top = lib.$("ClickPanel").getBoundingClientRect().top + document.body.scrollTop - 2;
    d.style.left = (document.body.offsetWidth - d.offsetWidth) / 2;
    lib.$("ClickEvent").onclick = function(){
        var s = lib.$("CheckInput");
        s = s.value;
        if(s.length==0){
            alert("参数错误,请输入验证答案!");
        }else{
            lib.like(o,e,s);
        }
        d.style.visibility = "hidden";
        return false;
    }
}

lib.like = function(o,e,chk){
    var url = "";
    if(o==true){
        url = "comment.aspx?format=like&id=" + e + "&chk=" + chk + "&euid=" + lib.euid;
    }else{
        url = "comment.aspx?format=hate&id=" + e + "&chk=" + chk + "&euid=" + lib.euid;
    }
    var ajax = new lib.ajax(url);
        ajax.collect = function(r){
            var echo = parseInt(r.responseText);
            if(echo.toString()=="NaN") echo = 0;
            if(echo==1){
                alert("参数错误,没有指定您要投票的信息!");
            }else if(echo==2){
                alert("操作失败,您已经对指定信息投过票了!");
            }else if(echo==3){
                alert("操作失败,指定信息不存在或已经被删除!");
            }else if(echo==4){
                alert("完成操作,谢谢您的投票!"); return; //不更新票数了
                var i1 = 1; var i2 = 1;
                if(lib.$("ilike_yes").count==null){
                    i1 = 1;
                    lib.$("ilike_yes").count = i1;
                }else{
                    var i1 = parseInt(lib.$("ilike_yes").count);
                    if(i1.toString()=="NaN") i1 = 1;
                    lib.$("ilike_yes").count = i1;
                }
                if(lib.$("ilike_not").count==null){
                    i2 = 1;
                    lib.$("ilike_not").count = i2;
                }else{
                    var i2 = parseInt(lib.$("ilike_not").count);
                    if(i2.toString()=="NaN") i2 = 1;
                    lib.$("ilike_not").count = i2;
                }
                if(o==true){
                    i1 += 1;
                    lib.$("ilike_yes").count = i1;
                    lib.$("ilike_yes").title = "已有" + i1 + "朵鲜花,点击送鲜花!";
                }else{
                    i2 += 1;
                    lib.$("ilike_not").count = i2;
                    lib.$("ilike_not").title = "被扔" + i2 + "个鸡蛋,点击扔鸡蛋!";
                }
                var i3 = i1 + i2;
                i3 = (i1 / i3) * 100;
                if(i3>50){
                    lib.$("dlike_yes").className = "dlike_iao";
                }else if(i3<50){
                    lib.$("dlike_yes").className = "dlike_kus";
                }else{
                    lib.$("dlike_yes").className = "";
                }
                lib.$("dlike_yes").style.width = i3 + "%";
            }else if(echo==5){
                alert("参数错误,请输入正确的验证答案!");
            }else{
                alert("操作失败,执行过程中发生未知错误!");
            }
        }
        ajax.connect();
}

lib.checklike = function(a,b){
    var i1 = parseInt(a);
    if(i1.toString()=="NaN") i1 = 1;
    var i2 = parseInt(b);
    if(i2.toString()=="NaN") i2 = 1;
    var i3 = i1 + i2;
    i3 = (i1 / i3) * 100;
    lib.$("ilike_yes").count = i1;
    lib.$("ilike_yes").title = "已有" + i1 + "朵鲜花,点击送鲜花!";
    lib.$("ilike_not").count = i2;
    lib.$("ilike_not").title = "被扔" + i2 + "个鸡蛋,点击扔鸡蛋!";
    lib.$("dlike_not").title = "这是总数百分比,点击进入年度排行榜!";
    if(i3>50){
        lib.$("dlike_yes").className = "dlike_iao";
    }else if(i3<50){
        lib.$("dlike_yes").className = "dlike_kus";
    }else{
        lib.$("dlike_yes").className = "";
    }
    lib.$("dlike_yes").style.width = i3 + "%";
}

lib.ilike = function(o){
    if(o==true){
        _ilike_yes += 1;
        //lib.$("ilike_yes").innerText = _ilike_yes;
        lib.$("ilike_yes").title = "已有" + _ilike_yes + "朵鲜花,点击送鲜花!";
    }else{
        _ilike_not += 1;
        //lib.$("ilike_not").innerText = _ilike_not;
        lib.$("ilike_not").title = "被扔" + _ilike_not + "个鸡蛋,点击扔鸡蛋!";
    }
    var e = _ilike_yes + _ilike_not;
    e = (_ilike_yes / e) * 100;
    if(e>50){
        lib.$("dlike_yes").className = "dlike_iao";
    }else if(e<50){
        lib.$("dlike_yes").className = "dlike_kus";
    }else{
        lib.$("dlike_yes").className = "";
    }
    lib.$("dlike_yes").style.width = e + "%";
}

lib.ClickChannel = function(e){
    var o = lib.$("StarChannel" + e);
    if(o!=null) o.className = "ClickChannel";
}

lib.CheckChannel = function(a,b,c){
    if(a=="$[Content.Channel.Parent]$"||a=="0"){
        if(b=="$[Channel.Parent]$"||b=="0"){
            if(c!="$[Channel.Id]$") lib.ClickChannel(c);
        }else{
            lib.ClickChannel(b.split(",")[1]);
        }
    }else{
        lib.ClickChannel(a.split(",")[1]);
    }
}

lib.checktrack = function(){
    var s = document.getElementsByTagName("a");
    for(var i=0;i<s.length;i++){
        if(s[i].link!=null){
            if(s[i].open!=null){
                if(s[i].open.length>7){
                    if(s[i].open.substring(0,7)=="http://"){
                    }else{
                        if(s[i].text!=null) s[i].link += "&caption=" + escape(s[i].text);
                        s[i].href = "javascript:lib.track('" + s[i].link + "')";
                        s[i].target = "_self";
                    }
                }else{
                    if(s[i].text!=null) s[i].link += "&caption=" + escape(s[i].text);
                    s[i].href = "javascript:lib.track('" + s[i].link + "')";
                    s[i].target = "_self";
                }
            }else{
                if(s[i].text!=null) s[i].link += "&caption=" + escape(s[i].text)
                s[i].href = "javascript:lib.track('" + s[i].link + "')";
                s[i].target = "_self";
            }
        }else{
            if(s[i].text!=null) s[i].href += "&caption=" + escape(s[i].text);
        }
    }
}

lib.meteorological = function(e){
    if(e.length>2){
        var chars = "&nbsp;<a href='http://weather.tq121.com.cn/detail.php?city=%C8%F0%B0%B2' target='_blank'>";
            chars += "瑞安天气</a>&nbsp;" + e[2] + "&nbsp;" + e[0] + "&nbsp;温度" + e[1];
        lib.$("meteorological").innerHTML = chars;
    }else{
        lib.$("meteorological").innerHTML = "<font color='red'>&nbsp;远程服务器连接失败.无法加载天气信息!</font>";
    }
}

lib.logical = function(){
    if(lib.$("meteorological")!=null){
        var ajax = new lib.ajax("weather.aspx?" + lib.euid);
        ajax.collect = function(r){
            try{eval(r.responseText)}catch(e){}
        }
        ajax.connect();
    }
}

lib.library = function(){
    var s = lib.$("txtlibrary").value;
    if(s.length==0){
        alert("参数错误,请填写搜索关键字!");
    }else{
        var url = "?class=1&style=library&keyword=" + escape(s);
        lib.track(url);
    }
}

lib.linklibrary = function(o){
    parent.location.href(o);
}

lib.checklibrary = function(){
    var s = document.getElementsByTagName("a");
    for(var i=0;i<s.length;i++){
        var e = s[i];
        if(e.model!=null){
            if(e.model=="简介单页"||e.model=="视频专题"){
                e.href = "javascript:lib.linklibrary('" + e.track + "')";
            }
        }
    }
}

lib.event(function(){
    //setTimeout("lib.logical()",1000);
    try{lib.PrintTrack();}catch(e){};
    try{lib.checktrack();}catch(e){};
});










