var y,mm,d,dt,h,m,s;
var sss,mmm,hhh;
var skin,showsec,secSpring,timeoffset;
var vhour,vhalfhour;

function timer0OnTimer()
{
  dt = new Date();
  h = dt.getHours() + timeoffset;
  m = dt.getMinutes();
  s = dt.getSeconds();
  y = dt.getYear();
  mm = dt.getMonth()+1;
  d = dt.getDate();
  
  if(showsec==0)
  {
    if((hhh==h)&&(mmm==m))
    {
      hhh = h;
      mmm = m;
      return;
    }
  }
  
  if((sss==s)&&(mmm==m))
    return;
  sss = s;
  mmm = m;
  
  LockRefresh;
  
  if(showsec==1)
  {
    if(secSpring==0)
      imgsec.angle = s*6
    else
    {
      imgsec.angle = s*6+4;
    }
  } 
  
 
  imgmin.angle =   parseInt(s/10) +m*6;
  imgh.angle =  parseInt(m/2) + parseInt(h % 12*30) ;
  txt.tooltip = y + "年" + mm + "月" + d + "日 " + h + ":" + m + ":" + s ;
  
  UnLockRefresh;

  if((showsec==1)&&(secSpring==1))
    timer1.enabled = true;
  
  if(vhalfhour==1)  
    if( (m==30)&&(s==0) )
    {
       playVoiceTime;
       Print("半点报时");
    }

  if(vhour==1)  
    if( (m==0)&&(s==0) )
    {
       playVoiceTime;
       Print("整点报时");
    }
    
    

}   

function timer1OnTimer()
{
  timer1.enabled = false;
  imgsec.angle = s*6;
}

function widgetOnInit()
{ 
  sss = -1;
  hhh = -1;
  mmm = -1;
  
  LockRefresh;
  
  timeoffset = parseInt(GetSetting("timeoffset"));
  showsec = GetSetting("sec");
  secSpring = GetSetting("spring");
  txt.caption = GetSetting( "cname" ); 
  
  skin = GetSetting("skin");
  bg.Src = "images\\" + skin + ".png"; 
  imgmin.Src = "images\\" + skin + "_m.png"; 
  imgh.Src = "images\\" + skin + "_h.png"; 
  imgsec.Src = "images\\" + skin + "_s.png"; 
  imghl.Src = "images\\" + skin + "_highlights.png"; 
  imgdot.Src = "images\\" + skin + "_dot.png";
  
  if((skin=="diner")||(skin=="modern")   )
    txt.fontColor = "clWhite" 
  else if((skin=="flower") )
    txt.fontColor = "230,111,3" 
  else if((skin=="cronometer") )
    txt.fontColor = "clRed"
  else 
    txt.fontColor = "clBlack";
    
  imgsec.Visible = showsec;
  
  
  //语音报时设置
  vhour = GetSetting("valhour");  
  vhalfhour = GetSetting("valhalfhour");  
  
  UnLockRefresh;
  
  timer0OnTimer();
}

function OnAllSettingsSaved()
{
  widgetOnInit();
}

function widgetOnDBClick()
{
   Run("RunDLL32.exe Shell32.dll,Control_RunDLL TimeDate.cpl");
}

function Run(objPath) 
{
    try 
    {
        var objShell = new ActiveXObject('wscript.shell');
        objShell.Run(objPath);
        objShell = null;
    }
    catch (e)
    {
    alert('找不到指定文件'+objPath+'(或它的组件之一)，请确定文件或路径是否正确，并确定更改了你的IE安全级别：工具--Internet 选项 -- 安全 -- 自定义级别 -- 没有标记为安全的 ActiveX 控件进行初始化和脚本运行\n设置为“启用”或 “提示”');
    }
}

function nMenu1OnClick()
{
  playVoiceTime;
}

function nMenu5OnClick()
{
  if(GetSetting("valhalfhour")==1)
    SetSetting("valhalfhour",0)
   else    
    SetSetting("valhalfhour",1);
  vhalfhour = GetSetting("valhalfhour");
  SaveSetting("valhalfhour");
}

function nMenu4OnClick()
{
  if(GetSetting("valhour")==1)
    SetSetting("valhour",0)
   else    
    SetSetting("valhour",1);
  vhour = GetSetting("valhour");
  SaveSetting("valhour");
  
}

function widgetOnPopupMenu()
{
  if(GetSetting("valhour")==1)
    nMenu4.Checked = true
  else
    nMenu4.Checked = false;
    
  if(GetSetting("valhalfhour")==1)
    nMenu5.Checked = true
  else
    nMenu5.Checked = false;
    
}