
function tmOnTimer()
{
  var today = (new Date()).getTime();
  var exam_day = (new Date( GetSetting("month")+"-"+GetSetting("day")+"-"+GetSetting("year")+ " " + GetSetting("time") ) ).getTime();
  var time = (exam_day - today);

  if(time > 0)
  {
  	var days = (time - (time % 86400000)) / 86400000;
  	time = time - (days * 86400000);
  	var hours = (time - (time % 3600000)) / 3600000;
  	time = time - (hours * 3600000);
  	var mins = (time - (time % 60000)) / 60000;
  	time = time - (mins * 60000);
  	var secs = (time - (time % 1000)) / 1000;
  	
  	if(days < 10)
  		days = "0" + days;
  	if(hours < 10)
  		hours = "0" + hours;
  	if(mins < 10)
  		mins = "0" + mins;
  	if(secs < 10)
  		secs = "0" + secs;
        Print( days + "day  " + hours + "hour  " + mins+ "min  " + secs + "sec");
        
        if(GetSetting( "sec" )=="1")
          leaveTm.caption = days + "天" + hours + "时" + mins +"分" + secs + "秒"
        else
          leaveTm.caption = days + "天" + hours + "时" + mins +"分";
          
  }
  else
  {
    tm.enabled=false;
    LockRefresh; 
    title.caption = "请设置倒计时时间";
    leaveTm.caption = "";
    UnLockRefresh;
    Refresh;		
  }
  
}

function OnAllSettingsSaved()
{
  widgetOnInit(); 
  tmOnTimer();
}

function widgetOnInit()
{
  LockRefresh; 
  title.caption = GetSetting( "title" );
  leaveTm.caption = "";
  
  if(GetSetting( "sec" )=="1")
    tm.interval = 1000
  else
    tm.interval = 1000 * 60; 
  tm.enabled = true;
    
  bg.src = GetSetting("bg"); 

  UnLockRefresh;
  tmOnTimer();
}

function widgetOnDock()
{
  scale = 90;
}

function widgetOnUnDock()
{
    scale = 100;
}