﻿

    //展览会开始时间
    var beginTime = new Date(StartTime); 
        
    //展览会结束时间
    var endTime  = new Date(EndTime);
        
    //是否已经开始
    var isBegin =0;
    
    getTime();    
    
    function getTime() 
    {

        var now = new Date();

        if(now < beginTime && isBegin == 0 )
            document.all.timer_Title.innerText = "距展览会开幕 还有";
        else
        {  
            if(now < endTime)
            {
                document.all.timer_Title.innerText = "距展览会结束时间 还有"; 
                if(isBegin == 0)
                    beginTime = endTime;
                isBegin = 1;
            }
            else
            {
                document.all.timer_Title.innerText = "展览会已经结束了";
//                document.images.day1.style.display = "none";
                document.images.day2.style.display = "none";
                document.images.day3.style.display = "none";
                document.images.day4.style.display = "none";
                document.images.hour1.style.display = "none";
//                document.images.hour2.style.display = "none";
                document.images.min1.style.display = "none";
//                document.images.min2.style.display = "none";
                document.images.sec1.style.display = "none";
//                document.images.sec2.style.display = "none";
                return;
            }
        }
        
        days = (beginTime - now) / 1000 / 60 / 60 / 24;
        daysRound = Math.floor(days);
        hours = (beginTime - now) / 1000 / 60 / 60 - (24 * daysRound);
        hoursRound = Math.floor(hours);
        minutes = (beginTime - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
        minutesRound = Math.floor(minutes);
        seconds = (beginTime - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
        secondsRound = Math.round(seconds);
        //秒    
        if (secondsRound <= 9) 
        {
            document.images.sec1.style.display = "none";
            document.images.sec2.src = imgPath + "/s_" +secondsRound +".gif";
        }
        else 
        {
            document.images.sec1.style.display = "inline";
            document.images.sec1.src = imgPath + "/s_" +Math.floor(secondsRound/10) +".gif";
            document.images.sec2.src = imgPath + "/s_" +(secondsRound%10) +".gif";

        }
        //分钟
        if (minutesRound <= 9) 
        {
            document.images.min1.style.display = "none";
            document.images.min2.src = imgPath + "/s_" +minutesRound +".gif";
        }
        else 
        {
            document.images.min1.style.display = "inline";
            document.images.min1.src = imgPath + "/s_" +Math.floor(minutesRound/10) +".gif";
            document.images.min2.src = imgPath + "/s_" +(minutesRound%10) +".gif";
        }
        //小时
        if (hoursRound <= 9) 
        {
            document.images.hour1.style.display = "none";
            document.images.hour2.src = imgPath + "/s_" +hoursRound +".gif";
        }
        else 
        {
            document.images.hour1.style.display = "inline";
            document.images.hour1.src = imgPath + "/s_" +Math.floor(hoursRound/10) +".gif";
            document.images.hour2.src = imgPath + "/s_" +(hoursRound%10) +".gif";
        }
        //天
        if (daysRound <= 9) 
        {
            document.images.day1.style.display = "none";
            document.images.day2.style.display = "none";
            document.images.day3.style.display = "none";
            document.images.day4.src = imgPath + "/b_"+daysRound+ ".gif";
        }
        else if (daysRound <= 99) 
        {
            document.images.day1.style.display = "none";
            document.images.day2.style.display = "none";
            document.images.day3.src = imgPath + "/b_"+Math.floor((daysRound/10)%10)+ ".gif";
            document.images.day4.src = imgPath + "/b_"+Math.floor(daysRound%10)+ ".gif"; 
        }
        else if (daysRound <= 999) 
        {
            document.images.day1.style.display = "none";
            document.images.day2.src = imgPath + "/b_"+Math.floor((daysRound/100)%10)+ ".gif";
            document.images.day3.src = imgPath + "/b_"+Math.floor((daysRound/10)%10)+ ".gif";
            document.images.day4.src = imgPath + "/b_"+Math.floor(daysRound%10)+ ".gif";
        }
        else if (daysRound <= 9999)
        {
            document.images.day1.src = imgPath + "/b_"+Math.floor(daysRound/1000)+ ".gif";
            document.images.day2.src = imgPath + "/b_"+Math.floor((daysRound/100)%10)+ ".gif";
            document.images.day3.src = imgPath + "/b_"+Math.floor((daysRound/10)%10)+ ".gif";
            document.images.day4.src = imgPath + "/b_"+Math.floor(daysRound%10)+ ".gif";
        }
        else
        {
            return;
        }
        newtime = window.setTimeout("getTime();", 1000);
    }
