﻿// JScript 文件
<!--
var objDiv;

///**隐藏信息方法**/
function msgHide(){
    if(!isNullORUndefined(objDiv))
    {
        objDiv.style.visibility="hidden";
        objDiv.style.display="none";
    }
}

///**信息显示方法**/
function msgShow(part1){
    objDiv=part1;
    objDiv.style.visibility = "visible";
    objDiv.style.display="";
    try{
        objDiv.style.display=undefined;
    }
    catch(err){
    }
}

function startPlay(){
    var divTimeMusic
    if(true==IsIE())
        divTimeMusic = document.getElementById("divTimeMusic1");
    else
        divTimeMusic = document.getElementById("divTimeMusic2");
    msgShow(divTimeMusic);
}

function IsIE(){
    //如果浏览器为IE
    if (window.navigator.userAgent.indexOf("MSIE")>=1)
        return true;
    else
        return false;
}

//------控制何时播放报时------
var executive=false;
var ifmTimeMusic;
var crrTime=new Date();
setInterval('showAlert()',1000);
//setTimeout('showAlert()',10000);
function showAlert(){
    ifmTimeMusic=document.getElementById("ifmTimeMusic");
    if(isNullORUndefined(ifmTimeMusic)==true) return;
    //debugger;
    var pageTime=getCookie("pageTime");
    var dttPage=new Date(pageTime);
    crrTime=new Date();
    if(true==executive){
        runTimeMusic();
    }
    else{
        var intDiff=dttPage.dateDiff("s",crrTime);
        if(intDiff>32){
            runTimeMusic();
        }
    }
}

//确定是否进行报时
function runTimeMusic(){
    //debugger;
    if(0==crrTime.getMinutes() || 5==crrTime.getMinutes() || 55==crrTime.getMinutes())
    {
        var playTime=getCookie("playTime");
        var dttPlay=new Date(playTime);
        if(isNullORUndefined(playTime)==false && compoundDate(crrTime).trim()==playTime.trim()) return;
        //debugger;
        setCookie("playTime",compoundDate(crrTime));
        ifmTimeMusic.src="/TimeMusic/index.aspx?hour="+crrTime.getHours()+"&minute="+crrTime.getMinutes();
    }
    executive=true;
    setCookie("pageTime",crrTime);
}

function isNullORUndefined(checkValue){
if(typeof(checkValue)=="undefined" || checkValue=='undefined' || checkValue==null) return true;
return false;
}

function compoundDate(dttValue){
return dttValue.getFullYear()+"-"+(dttValue.getMonth()+1)+"-"+dttValue.getDate()+" "+dttValue.getHours()+":"+dttValue.getMinutes();
}

//设置和获取Cookie
function getCookie(cookieName){
var topCookieString= window.document.cookie;
var start = topCookieString.indexOf(cookieName + '=');
if (start == -1) return null; // 找不到
start += cookieName.length + 1;
var end = topCookieString.indexOf(';', start);
if (end == -1) return unescape(topCookieString.substring(start));
return unescape(topCookieString.substring(start, end));
}

function setCookie(cookieName,cookieValue){
window.document.cookie=cookieName + '=' + escape(cookieValue);
}

//获取查询字符串
function QueryString(key){
var query=location.search;
var reg = new RegExp(key + "=(.*?)(#|&|$)");
var arr = query.match(reg);
return (arr!=null)?arr[1]:"";
}

//***系统对象函数***
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}

Date.prototype.dateAdd = function(interval,number){
var d = this;
var k={'y':'FullYear', 'q':'Month', 'm':'Month', 'w':'Date', 'd':'Date', 'h':'Hours', 'n':'Minutes', 's':'Seconds', 'ms':'MilliSeconds'};
var n={'q':3, 'w':7};
eval('d.set'+k[interval]+'(d.get'+k[interval]+'()+'+((n[interval]||1)*number)+')');
return d;
}

Date.prototype.dateDiff = function(interval,objDate2){
var d=this, i={}, t=d.getTime(), t2=objDate2.getTime();
i['y']=objDate2.getFullYear()-d.getFullYear();
i['q']=i['y']*4+Math.floor(objDate2.getMonth()/4)-Math.floor(d.getMonth()/4);
i['m']=i['y']*12+objDate2.getMonth()-d.getMonth();
i['ms']=objDate2.getTime()-d.getTime();
i['w']=Math.floor((t2+345600000)/(604800000))-Math.floor((t+345600000)/(604800000));
i['d']=Math.floor(t2/86400000)-Math.floor(t/86400000);
i['h']=Math.floor(t2/3600000)-Math.floor(t/3600000);
i['n']=Math.floor(t2/60000)-Math.floor(t/60000);
i['s']=Math.floor(t2/1000)-Math.floor(t/1000);
return i[interval];
}
//-->