﻿
        

setInterval("ShowTime();",1000);
function TimeCom( dateValue )
{
  var newCom;
  if (dateValue=="")
  {
   newCom = new Date();
  }else{
   newCom = new Date(dateValue);
  }
        this.year = newCom.getYear();
        this.month = newCom.getMonth()+1;
        this.day = newCom.getDate();
        this.hour = newCom.getHours();
        this.minute = newCom.getMinutes();
        this.second = newCom.getSeconds();
        this.msecond = newCom.getMilliseconds();
        this.week = newCom.getDay();
}
    
  function ShowTime()
  {
   var difSec=DateDiff('s',EndDate,new Date());
   var strHour=(difSec%(60*60*24)-difSec%(60*60))/(60*60);
   if(strHour<0)
   {
     strHour="00";
   }
   else if(strHour<10)
   {
    strHour="0"+strHour;
   }
   
   var strMin=(difSec%(60*60)-difSec%60)/60;
   
   if(strMin<0)
   {
     strMin="00";
   }
   else if(strMin<10)
   {
    strMin="0"+strMin;
   }
   var strSec=difSec%60;
   
   if(strSec<0)
   {
     strSec="00";
   }
   else if(strSec<10)
   {
      strSec="0"+strSec;
   }
   var strDay=(difSec-strSec-strMin*60-strHour*60*60)/(60*60*24);
   
   if(strDay<0)
   {
     strDay="00";
   }
   else if(strDay<10)
   {
      strDay="0"+strDay;
   }
   $("#divDay").html(strDay);
   $("#divHour").html(strHour);
   $("#divMin").html(strMin);
   $("#divSec").html(strSec);
  }
   
  function DateDiff(interval,date1,date2)
    {
        var TimeCom1 = new TimeCom(date1);
        var TimeCom2 = new TimeCom(date2);
        var result;
        switch(String(interval).toLowerCase())
        {
            case "y":
            case "year":
            result = TimeCom1.year-TimeCom2.year;
            break;
            case "m":
            case "month":
            result = (TimeCom1.year-TimeCom2.year)*12+(TimeCom1.month-TimeCom2.month);
            break;
            case "d":
            case "day":
            result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day))/(1000*60*60*24));
            break;
            case "h":
            case "hour":
            result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour))/(1000*60*60));
            break;
            case "min":
            case "minute":
            result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute))/(1000*60));
            break;
            case "s":
            case "second":
            result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute,TimeCom1.second)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute,TimeCom2.second))/1000);
            break;
            case "ms":
            case "msecond":
            result = Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day,TimeCom1.hour,TimeCom1.minute,TimeCom1.second,TimeCom1.msecond)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day,TimeCom2.hour,TimeCom2.minute,TimeCom2.second,TimeCom1.msecond);
            break;
            case "w":
            case "week":
            result = Math.round((Date.UTC(TimeCom1.year,TimeCom1.month-1,TimeCom1.day)-Date.UTC(TimeCom2.year,TimeCom2.month-1,TimeCom2.day))/(1000*60*60*24)) % 7;
            break;
            default:
            result = "invalid";
        }
        return(result);
    }

      
                        
                        
