/*var edtIcoCap,
    edtIcoPath,
    edtIcoAction,
    icoListBox,
    icoImg,
    btSelPic,
    btSelAct,
    btUpLevel,
    btDownLevel,
    btAddIco,
    btClearIco,
    btDelIco;   //选项窗口用到的控件 
  */
var imgs =new Array();
var iconArray  = new Array();

var curCount = 0;
var iPageIndex = 1;
var iPageCount = 0;
var SinglePageCount=9; //单页icon数量 
var curID;
var showhint = true;                                                
var rowCount = 3;
var incRow = false;  //增加行数 
var curTheme = "default.msctheme";
var themeList = ""; 
 
//将当前页面icon都显示出来 
function showIcons(aPageIndex)
{
  if(aPageIndex<1) aPageIndex = 1;
  LockRefresh;

  if( curTheme.toLowerCase()!="default.msctheme"  ) 
    hint.caption = curTheme.substr(0,curTheme.length-9);
  else
    hint.caption = "MyShortcut2";
  imgHover.Visible = false;
  
  txthint2.Visible = false; 
  imgdrag.Visible = false;
  for (var i=0; i<9; i++)
  {
    imgs[i].Src = "";
    imgs[i].tooltip = "";
    imgs[i].cursorHandPoint = false;
    imgs[i].Visible = false;
  }  

  if(curCount < 1)
  {
    txthint2.Visible = true; 
    imgdrag.Visible = true;
    txtPage.caption = "1/1";  
    iPageIndex = 1;
    UnLockRefresh;
    return;
  }
  
  maxpage = Math.ceil(curCount/SinglePageCount);
  if( aPageIndex > maxpage )
    aPageIndex = maxpage;    
  iPageIndex = aPageIndex;
  var baseIndex= (aPageIndex-1) * SinglePageCount;
  txtPage.caption = iPageIndex + "/" + maxpage;  
        
  var index;
  for(var i=baseIndex;i<baseIndex+SinglePageCount;i++)
  {
    index = i % SinglePageCount;
    try 
    {
      if( !fileExists( iconArray[i].path ) )
        iconArray[i].path = "images\\defaultIcon.png"; 
      var ht =  iconArray[i].caption + '\r\n' + '位置：' + iconArray[i].action; 

      imgs[index].Src = iconArray[i].path;
      if(showhint)
        imgs[index].tooltip = splittooltip( ht )
      else
        imgs[index].tooltip = "";
      imgs[index].cursorHandPoint = true;
      imgs[index].Visible = true;
    }
    catch(exception){}    
  }
  
  WriteIni("iPageIndex",iPageIndex);
  
  
  UnLockRefresh;

}



function widgetOnInit()
{
  imgs[0] = img0;
  imgs[1] = img1;
  imgs[2] = img2;
  imgs[3] = img3;
  imgs[4] = img4;
  imgs[5] = img5;
  imgs[6] = img6;
  imgs[7] = img7;
  imgs[8] = img8;
  
  for(var i=0;i<9;i++)
    imgs[i].OnClick = "imgsOnClick";
  
  loadskin();
 
  //载入curCount  icon数量 
  if( isNaN(  parseInt(  ReadIni("IconCount")  )  ) ) 
    curCount=0
  else
    curCount = parseInt(ReadIni("IconCount"));
    
  curTheme = ReadIni("curTheme")
  if(curTheme=="") curTheme = 'default.mscTheme';   
  Print( curTheme );

  if(  curCount<0  ) 
    curCount=0;

  WriteIni("IconCount",curCount);
      
  for (var i = 0; i < curCount; i++)
  {
    iconArray.push(new NewIcon());
    
    iconArray[i].id = i;
    iconArray[i].caption = ReadIni( i + "caption" );
    iconArray[i].path = ReadIni( i + "path" );
    iconArray[i].action = ReadIni( i + "action" );

    WriteIni(i+"caption",iconArray[i].caption);
    WriteIni(i+"path",iconArray[i].path);
    WriteIni(i+"action",iconArray[i].action);

//    curID++;
//    lastId++;
//    totalId++;
  }
  
  if(isNan(iPageIndex))
    iPageIndex = 1;
      
  //显示所有icon  
  showIcons(iPageIndex); 
  
}


function img0OnPopupMenu(sender)
{
  var tag = sender.tag;  
  var curID= (iPageIndex-1) * SinglePageCount + tag;
  var sCaption = iconArray[curID].caption;
  var sAction = iconArray[curID].action;
  var sPath = iconArray[curID].path;    

  custPopMenu.clear;
  custPopMenu.addMenuItem('打开 "' + sCaption + '"',"imgsOnClick",tag);
  custPopMenu.addMenuItem("-","",tag);
  custPopMenu.addMenuItem('删除',"deleteIcon",tag);
  custPopMenu.addMenuItem('编辑',"editIcon",tag);
  custPopMenu.popup;
  
}

//编辑图标属性 
function editIcon(sender)
{
  var tag = sender.tag;
  var curID= (iPageIndex-1) * SinglePageCount + tag;

  var sCaption = iconArray[curID].caption;
  var sAction = iconArray[curID].action;
  var sPath = iconArray[curID].path;
  
  
  try
  {
    frm = TForm.create(widget);
    frm.width = 400;
    frm.height = 230;
    frm.Position = poScreenCenter;
    frm.caption = '编辑快捷方式';
    frm.font.name='宋体';
    frm.font.size=9;
    frm.ShowHint=true;
    frm.BorderStyle=bsDialog;
    
    
    lblCaption=TLabel.create(widget);
    lblCaption.parent=frm;
    lblCaption.left=16; 
    lblCaption.top=16;
    lblCaption.caption='快捷名称：';
    
    edtCaption=TEdit.create(widget);
    edtCaption.parent=frm;
    edtCaption.left=76; 
    edtCaption.top=12;
    edtCaption.width=180;
    edtCaption.text=sCaption;
    
    lblAction=TLabel.create(widget);
    lblAction.parent=frm;
    lblAction.Caption='打开动作：';
    lblAction.left=16; 
    lblAction.top=48;
    
    cbbAction=TComboBox.create(widget);
    cbbAction.parent=frm;
    cbbAction.left=16; cbbAction.top=64;
    cbbAction.width = 340;
    cbbAction.text = sAction;
cbbAction.Items.text='我的电脑\r\n我的文档\r\n网上邻居\r\n控制面板\r\nIE浏览器\r\n拨号上网\r\n回收站\r\n关机\r\n注销\r\n重启\r\n休眠/待机\r\n切换系统用户\r\n锁定系统\r\nCMD命令行\r\n运行对话框\r\n查找文件对话框\r\n最小化所有窗口\r\n任务管理器'; 
    cbbAction.OnSelectEx = "cbbActionSelected";
    
    btnSelFile = TButton.create(widget);
    btnSelFile.caption = '...';
    btnSelFile.left = 360;  btnSelFile.top = 62;
    btnSelFile.width = 24;  btnSelFile.height = 24;
    btnSelFile.parent = frm;
    btnSelFile.OnClickEx = 'btnSelFileClick';
    btnSelFile.hint = '选择打开动作';

    lblPath = TLabel.create(widget);
    lblPath.parent = frm;
    lblPath.Caption = '快捷图标：';
    lblPath.left = 16; lblPath.top = 96;
    
    edtPath = TEdit.create(widget);
    edtPath.parent = frm;
    edtPath.left = 16; edtPath.top = 112;
    edtPath.width = 340;
    edtPath.text = sPath;
    
    btnSelPic = TButton.create(widget);
    btnSelPic.caption = '...';
    btnSelPic.left = 360;  btnSelPic.top = 110;
    btnSelPic.width = 24;  btnSelPic.height = 24;
    btnSelPic.parent = frm;
    btnSelPic.OnClickEx = 'btnSelPicClick';
    btnSelPic.hint = '选择快捷方式的显示图标';

    btnCancel = TButton.create(widget);
    btnCancel.caption = '取  消';
    btnCancel.left = 300;
    btnCancel.top = 160;
    btnCancel.parent = frm;
    btnCancel.ModalResult = 2;
    btnCancel.cancel = true;
    
    btnOK = TButton.create(widget);
    btnOK.caption = '确  定';
    btnOK.left = 210;
    btnOK.top = 160;
    btnOK.parent = frm;
    btnOK.ModalResult = 1;
    //btnOK.OnClickEx = 'btnOkClick';
    if(frm.ShowModal==1)
    {
      sAction = cbbAction.text;
      if(sAction=="我的电脑")
        sAction = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
      else if(sAction=="我的文档")
        sAction = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
      else if(sAction=="网上邻居")
        sAction = "::{208D2C60-3AEA-1069-A2D7-08002B30309D}"
      else if(sAction=="控制面板")
        sAction = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"
      else if(sAction=="IE浏览器")
        sAction = "explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}"
      else if(sAction=="拨号上网")
        sAction = systemPath+"Rasphone.exe"
      else if(sAction=="回收站")
        sAction = "::{645FF040-5081-101B-9F08-00AA002F954E}"
        
      else if(sAction=="关机")
        sAction = "shutdown" 
      else if(sAction=="重启")
        sAction = "restart" 
      else if(sAction=="注销")
        sAction = "logoff" 
      else if(sAction=="休眠/待机")
        sAction = "standBy" 
      else if(sAction=="切换系统用户")
        sAction = "switchuser" 
      else if(sAction=="锁定系统")
        sAction = "lock" 

      else if(sAction=="CMD命令行")
        sAction = "cmd" 
      else if(sAction=="运行对话框")
        sAction = "runDlg"
        
      else if(sAction=="查找文件对话框")
        sAction = "FindFiles" 
      else if(sAction=="最小化所有窗口")
        sAction = "MinimizeAll" 
        
      else if(sAction=="任务管理器")
        sAction = "TaskMgr" 
      
       ; 
      
      iconArray[curID].caption = edtCaption.text;
      iconArray[curID].path = edtPath.text;
      iconArray[curID].action = sAction;
      
      WriteIni(curID+"caption",iconArray[curID].caption);
      WriteIni(curID+"path",iconArray[curID].path);
      WriteIni(curID+"action",iconArray[curID].action);
      
      //刷新图标 
      showIcons(iPageIndex);
      
      refreshMgrIconList(); 

    }
    
    frm.free;
    
  }
  catch(e)
  {
  
  }
}

function cbbActionSelected(sender)
{
  edtCaption.text = cbbAction.text;
}

function btnSelFileClick(sender)
{
  var fn;
  try
  {
    fn = openFileDialog;
    if(fn!="")
      cbbAction.text = fn; 
  }catch(e)
  {
  }
}


function btnSelPicClick(sender)
{
  var fn;
  try
  {
    fn = openPicDialog;
    if(!fileExists( fn ))
      return;
    if( fn.substr(0,widgetPath.length).toLowerCase() == widgetPath.toLowerCase()  )
      fn = fn.substr(widgetPath.length);  
    edtPath.text = fn; 
  }catch(e)
  {
  }
}

function deleteIcon(sender)
{
  var tag = sender.tag;
  var curID= (iPageIndex-1) * SinglePageCount + tag;
  if(!widget.confirm('确认删除快捷方式图标 "'+ iconArray[curID].caption +'" ？\n链接动作: ' + iconArray[curID].action))
    return;
      
  //清空Ini中最后一个的内容
  WriteIni((iconArray.length - 1) +"caption","");
  WriteIni((iconArray.length - 1) +"path","");
  WriteIni((iconArray.length - 1) +"action","");    
  
  //从数组中删除curID的内容 
  iconArray.splice(curID, 1);
  //将新数组所有内容逐一保存 
  for (var i = 0; i < iconArray.length; i++)
  {
    WriteIni(i+"caption",iconArray[i].caption);
    WriteIni(i+"path",iconArray[i].path);
    WriteIni(i+"action",iconArray[i].action);    
  }
  //确保iPageIndex在范围内
  curCount = iconArray.length; 
  if(iPageIndex > Math.ceil(curCount/SinglePageCount))
    iPageIndex--;  
  
  //记录总图标数量 
  WriteIni("IconCount", curCount);
  
  //刷新图标
  showIcons(iPageIndex); 
   
  refreshMgrIconList(); 

}
                       
function deleteIDIcon(id)
{
  curID = id;
      
  //清空Ini中最后一个的内容
  WriteIni((iconArray.length - 1) +"caption","");
  WriteIni((iconArray.length - 1) +"path","");
  WriteIni((iconArray.length - 1) +"action","");    
  
  //从数组中删除curID的内容 
  iconArray.splice(curID, 1);
  //将新数组所有内容逐一保存 
  for (var i = 0; i < iconArray.length; i++)
  {
    WriteIni(i+"caption",iconArray[i].caption);
    WriteIni(i+"path",iconArray[i].path);
    WriteIni(i+"action",iconArray[i].action);    
  }
  //确保iPageIndex在范围内
  curCount = iconArray.length; 
  if(iPageIndex > Math.ceil(curCount/SinglePageCount))
    iPageIndex--;  
  
  //记录总图标数量 
  WriteIni("IconCount", curCount);
  
  //刷新图标
  showIcons(iPageIndex); 

}


function img0OnMouseEnter(sender)
{
  if(!sender.Visible) return;
  if(!sender.cursorHandPoint) return;
  var tag = sender.tag;
  LockRefresh;
  imgHover.left = imgs[tag].Left-2;
  imgHover.top = imgs[tag].Top-2;

  var index= (iPageIndex-1) * SinglePageCount + tag;
  hint.caption = iconArray[index].caption;

  imgHover.Visible = true; 
  UnLockRefresh;
     
}


function img0OnMouseLeave(sender)
{
  if(!sender.Visible) return;
  imgHover.Visible = false; 
}

function bgOnMouseMove()
{
  LockRefresh;
  if((imgHover.Visible)||(hint.caption!="MyShortcut2"))
  { 
    if( curTheme.toLowerCase()!="default.msctheme"  ) 
      hint.caption = curTheme.substr(0,curTheme.length-9);
    else
      hint.caption = "MyShortcut2";
    imgHover.Visible = false;
  }   
  imgRow.alpha = 50;
  btAdd.alpha = 80;
  UnLockRefresh;
}

function NewIcon()
{
  this.id = "";
  this.caption = "";
  this.path = "";
  this.action = "";
}

function addIcon(cap,act,iconPath)
{
  var fn = act;
  
  iconArray.push(new NewIcon());
  curCount = iconArray.length;
  var index = iconArray.length-1;

  var ext = getFileExt(fn);
  if(cap=="")
    cap = getFileName(fn);

  if(iconPath=="")
    iconPath = getFileIcon(fn);

  if(ext.toLowerCase()=="lnk")
  {
    fn = getLinkFileName( fn );
    cap = cap.substr(0,cap.length-4);
  }
      
  iconArray[index].id = index;
  iconArray[index].caption = cap;
  iconArray[index].path = iconPath;
  iconArray[index].action = fn;
  
  //保存icon信息  
  WriteIni("IconCount",curCount);
  WriteIni(index+"caption",iconArray[index].caption);
  WriteIni(index+"path",iconArray[index].path);
  WriteIni(index+"action",iconArray[index].action);

}

function widgetOnDropFile(fileNameList)
{
  var files = fileNameList.split("|");
  for(var i=0;i<files.length;i++ )
  { 
    var fn = files[i];
    addIcon("",fn,"");
  }
  
  //显示到最后一页 
  showIcons( Math.ceil(curCount/SinglePageCount) );
  imgHover.Visible = false; 
  
  refreshMgrIconList(); 
  
}

function btNextOnClick()
{
  var index = iPageIndex+1;
  var count = Math.ceil(curCount/SinglePageCount);
  if(index>count)
    index = 1;
  showIcons(index);
  
}

function btPrevOnClick()
{
  var index = iPageIndex-1;
  if(index<1)  index = Math.ceil(curCount/SinglePageCount);
  showIcons(index);  
}


//获取文件名
function   getFileName(sfile)   
{
  if(sfile==null)
    return "";
  if( (sfile.length<=3)||( sfile.substr(1,10).toLowerCase()==":\\recycled" ) )
    return sfile;   
    
  var   reg=/([^\\]+)$/.exec(sfile);   
  return   RegExp.$1;   
}
    
//获取扩展名 
function  getFileExt(sfile)   
{   
  var   reg=/([^\.]+)$/.exec(sfile);   
  return  RegExp.$1;   
}   

function getFileIcon(fn)
{
   var afile;
   var cap = getFileName(fn);
   try{ var fname = (cap.split("."))[0]; } catch(e){ fname = cap }
   var ext = getFileExt(fn).toLowerCase();

   if( isDir( fn ) )
   {
      if( (fn.length<=3)&&( fn.substr(1,2)==":\\" ) )
        afile = "images\\soft\\disk.png"
      else if( fn.substr(1,10).toLowerCase()==":\\recycled" )
        afile = "images\\soft\\recycled.png"
      else
        afile = "images\\soft\\folder.png";
    } 
    else
    {
      switch (ext)
      {
        case "exe": case"lnk":
          afile = "images\\soft\\" + fname + ".png";
       
          if(fname=="wordicon") 
            afile = "images\\soft\\winword.png";

          if(!fileExists( widgetPath + afile ) )
          {
            getFileIconToPng( fn , widgetPath + "images\\soft\\" + fname + ".png" );
            afile = "images\\soft\\" + fname + ".png";
          }

          if(!fileExists( widgetPath + afile ) )
            afile = "images\\soft\\exe.png";
          break;
            
        //网页网址类    
        case "htm": case "html":  
          afile = "images\\soft\\htm.png";
          break;
          
        //图片类  
        case "gif": case "jpg": case "jpeg":  case "tiff":  case "png":
        case "bmp": case "ico": case "pict":    
          afile = "images\\soft\\pic.png";
          break;
          
        //脚本类  
        case "js": case "vbs": case "asp":  case "aspx":  case "php":  case "jsp":
          afile = "images\\soft\\script.png";
          break;
          
        //电影类  
        case "rmvb": case "rm": case "wmv":  case "avi":  case "mpg":  case "asf":
        case "swf":  case "swf":  case "3gp": 
          afile = "images\\soft\\movie.png";
          break;
          
         
        default:
          afile = "images\\soft\\" + ext + ".png";
      }
       
    }


    if(!fileExists( widgetPath + afile ) )
    {
      getFileIconToPng( fn , widgetPath + "images\\soft\\" + fname + ".png" );
      afile = "images\\soft\\" + fname + ".png";
    }
      


    if(!fileExists( widgetPath + afile ) )
      afile = "images\\defaultIcon.png";
    return afile;
}


function Run2(objPath) 
{
    try 
    {
        var objShell = new ActiveXObject('wscript.shell');
        objShell.Run(objPath);
        objShell = null;
        return true;
    }
    catch (e)
    {
      return false;
    }
}

function img0OnMouseDown()
{
  //预留 
}

function btAddOnMouseDown(sender)
{
  sender.alpha = 20;
  
}

function addIconMenuClick(sender)
{           
  var tag = sender.tag;
  switch (tag)
  {
    case 0:
      var fl = openFileDialog;
      if(fl=="") return;
      addIcon("",fl,"");

      break; 
    case 1:
      var fd = openFolderDialog;
      if(fd=="") return;
      addIcon("",fd,"");
    
      break; 
    case 2:
      addIcon("我的电脑","::{20D04FE0-3AEA-1069-A2D8-08002B30309D}","images\\soft\\computer.png");
      break; 
    case 3:
      addIcon("我的文档","::{450D8FBA-AD25-11D0-98A8-0800361B1103}","images\\soft\\Documents.png");
      break; 
    case 4:
      addIcon("网上邻居","::{208D2C60-3AEA-1069-A2D7-08002B30309D}","images\\soft\\network.png");
      break; 
    case 5:
      addIcon("控制面板","::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}","images\\soft\\controlpanel.png");
      break; 
    case 6:
      addIcon("IE浏览器", "explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}","images\\soft\\IExplore.png");
      break; 
    case 7:
      addIcon("拨号上网", systemPath+"Rasphone.exe",  "images\\soft\\Rasphone.png");
      break; 
    case 8:
      addIcon("回收站","::{645FF040-5081-101B-9F08-00AA002F954E}","images\\soft\\Recycled.png");
      break; 
    case 9: addIcon("CMD","cmd","images\\soft\\cmd.png");  break; 
    case 10: addIcon("运行","rundlg","images\\soft\\run.png"); break; 
    case 11: addIcon("查找文件","findfiles","images\\soft\\findfiles.png");  break; 
    case 12:  addIcon("最小化","MinimizeAll","images\\soft\\MinimizeAll.png"); break; 
    case 13:  addIcon("任务管理器","TaskMgr","images\\soft\\TaskMgr.png"); break; 
    
    case 14:  addIcon("关机","shutdown","images\\soft\\shutdown.png"); break; 
    case 15:  addIcon("重启","restart","images\\soft\\restart.png"); break; 
    case 16:  addIcon("注销","logoff","images\\soft\\logoff.png"); break; 
    case 17:  addIcon("休眠/待机","standby","images\\soft\\standby.png"); break; 
    case 18:  addIcon("切换系统用户","switchuser","images\\soft\\switchuser.png"); break; 
    case 19:  addIcon("锁定系统","lock","images\\soft\\lock.png"); break; 
    
    case 20:  addIcon("Word","winword","images\\soft\\word.png"); break; 
    case 21:  addIcon("Excel","excel","images\\soft\\excel.png"); break; 
    case 22:  addIcon("Outlook","outlook","images\\soft\\outlook.png"); break; 
    case 23:  addIcon("Access","msaccess","images\\soft\\access.png"); break; 
    case 24:  addIcon("PowerPoint","powerpnt","images\\soft\\powerpoint.png"); break; 

    case -2:
      for(var i=2;i<=24;i++)
         addIconMenuClick(i);
      break;
    case -5:
      for(var i=2;i<=8;i++)
      {
        sender.tag = i;
        addIconMenuClick(sender);
      }
      break;
    case -6:
      for(var i=9;i<=13;i++)
      {
        sender.tag = i;
        addIconMenuClick(sender);
      }
      break;
    case -7:
      for(var i=13;i<=19;i++)
      {
        sender.tag = i;
        addIconMenuClick(sender);
      }
      break;
    case -8:
      for(var i=20;i<=24;i++)
      {
        sender.tag = i;
        addIconMenuClick(sender);
      }
      break;
    default:
  }

  //刷新图标
  showIcons(Math.ceil(curCount/SinglePageCount));   

  refreshMgrIconList(); 
      
}

function imgsOnClick(sender)
{
  var tag = sender.tag;
  var index= (iPageIndex-1) * SinglePageCount + tag;
  var act = iconArray[index].action;

  Print( act );

  if(act=="")
  {
    showTrayHint("我的桌面图标2", "动作为空。 请先给此图标指定打开动作，比如打开某个文件或文件夹" );
    editIcon(tag);
    return;
  }                                  
  else if(act=="shutdown")
  {                                   
    if(! widget.confirm2( "确认要关机？" ))
      return; 
    runEx("shutdown","-p");
  }
  else if(act=="restart")
  {                                   
    if(! widget.confirm2( "确认要重启？" ))
      return; 
    runEx("shutdown","-r -f -t 03");
  }
  else if(act=="logoff")
  {                                   
    if(! widget.confirm2( "确认要注销？" ))
      return; 
    runEx("shutdown","-l");
  }
  else if(act=="standby")
  {                                   
    if(! widget.confirm2( "确认要休眠/待机？" ))
      return; 
    runEx("rundll32.exe","powrprof.dll,SetSuspendState");
  }    
  else if((act=="switchuser")||(act=="lock"))
  {                                   
    runEx("rundll32.exe","user32.dll,LockWorkStation");
  }  
  else 
    run( act  );
}



function clearAllIcons()
{
  //将新数组所有内容逐一清除 
  for (var i = 0; i < iconArray.length; i++)
  {
    WriteIni(i +"caption","");
    WriteIni(i +"path","");
    WriteIni(i +"action","");    
  }

  iconArray.splice(0, iconArray.length); 
  iPageIndex = 1;  
  
  //记录总图标数量 
  curCount = 0;
  WriteIni("IconCount", curCount);
  
  //刷新图标
  showIcons(1); 
}



function widgetOnLeave()
{
  LockRefresh; 
  bgOnMouseMove();
  btAdd.alpha = 80;
  imgRow.alpha = 50;
  UnLockRefresh;
}

function widgetOnDBClick()
{   
  imgRowOnClick(imgRow);
}


function splittooltip(str)
{
  function strSplit(text,c,sc) 
  {
    if(typeof text=="string") 
    {
    	var tl = text.length;
    	var results = [];
    	var i = Math.floor(tl/parseInt(c))
    	for(var j=0;j<=i;j++) 
          {
    		results.push(text.substring(j*c,(j+1)*c))
    	}
    	return results.join(sc)
    }
  }
  return strSplit(str,50,"\n")
}

function IconsMgr_scriptFuncName(panel)
{

//////////////////////////////////////////////////////// 
  lbIconCount = TLabel.Create(widget);
  lbIconCount.parent = panel;
  lbIconCount.rc = rect(20,2,200,14);
  lbIconCount.caption = "快捷方式列表 [共 "+ iconArray.length +" 个]:";

  icoListBox = TListBox.Create(widget);
  // 一定要将parent设为 panel 才可显示出来
  icoListBox.parent = panel;    
  icoListBox.rc = Rect(20,18,340,130);
  for(var i=0;i<iconArray.length;i++)
    icoListBox.items.add(iconArray[i].caption);
  if(icoListBox.items.count>0)  icoListBox.itemIndex = 0;
  icoListBox.OnClickEx = "icoListBoxOnClickEx";
  
//////////////////////////////////////////////////////// 
  bev = TBevel.Create(widget);
  bev.parent = panel;
  bev.rc = Rect(20,155,36,36);
  
  icoImg = TImage.Create(widget);
  icoImg.parent = panel;
  icoImg.rc = Rect(22,157,32,32);
  icoImg.stretch = true;
  
//////////////////////////////////////////////////////// 
  var lb = TLabel.Create(widget);
  lb.parent = panel;
  lb.rc = rect(65,160,50,14);
  lb.caption = "名    称:";
  
  edtIcoCap = TEdit.Create(widget);
  edtIcoCap.parent = panel;
  edtIcoCap.rc = Rect(125,155,198,21);

  btSaveIco = TButton.create(widget);
  btSaveIco.parent = panel;
  btSaveIco.caption = '保存';
  btSaveIco.rc = Rect(325,154,35,21);
  btSaveIco.OnClickEx = 'btSaveIcoOnClick';  
//////////////////////////////////////////////////////// 
  var lb = TLabel.Create(widget);
  lb.parent = panel;
  lb.rc = rect(65,185,50,14);
  lb.caption = "图标路径:";

  edtIcoPath = TEdit.Create(widget);
  edtIcoPath.parent = panel;
  edtIcoPath.rc = Rect(125,182,198,21);
  
  btSelPic = TButton.create(widget);
  btSelPic.parent = panel;
  btSelPic.caption = '浏览';
  btSelPic.rc = Rect(325,181,35,21);
  btSelPic.OnClickEx = 'btSelPicClick';
  
//////////////////////////////////////////////////////// 
  var lb = TLabel.Create(widget);
  lb.parent = panel;
  lb.rc = rect(65,211,50,14);
  lb.caption = "动    作:";

  edtIcoAction = TEdit.Create(widget);
  edtIcoAction.parent = panel;
  edtIcoAction.rc = Rect(125,208,198,21);
  
  btSelAct = TButton.create(widget);
  btSelAct.parent = panel;
  btSelAct.caption = '浏览';
  btSelAct.rc = Rect(325,207,35,21);
  btSelAct.OnClickEx = 'btSelActClick';
 
//////////////////////////////////////////////////////// 
  btAddIco = TButton.Create(widget);
  btAddIco.parent = panel;
  btAddIco.caption = "添加";
  btAddIco.OnClickEx = "btAddIcoOnClick";
  btAddIco.rc = Rect(20,250,40,21);
  
  btDelIco = TButton.Create(widget);
  btDelIco.parent = panel;
  btDelIco.caption = "删除";
  btDelIco.OnClickEx = "btDelIcoOnClick";
  btDelIco.rc = Rect(61,250,40,21);
  
  btClearIco = TButton.Create(widget);
  btClearIco.parent = panel;
  btClearIco.caption = "清空";
  btClearIco.OnClickEx = "btClearIcoOnClick";
  btClearIco.rc = Rect(102,250,40,21);
  
  btExportIcoList = TButton.Create(widget);
  btExportIcoList.parent = panel;
  btExportIcoList.caption = "导出";
  btExportIcoList.OnClickEx = "btExportIcoListOnClick";
  btExportIcoList.rc = Rect(143,250,40,21);

  btimportIcoList = TButton.Create(widget);
  btimportIcoList.parent = panel;
  btimportIcoList.caption = "导入";
  btimportIcoList.OnClickEx = "btImportIcoListOnClick";
  btimportIcoList.rc = Rect(184,250,40,21);
  
  
//////////////////////////////////////////////////////// 
  btUpLevel = TButton.Create(widget);
  btUpLevel.parent = panel;
  btUpLevel.caption = "上移";
  btUpLevel.OnClickEx = "btUpLevelOnClick";
  btUpLevel.rc = Rect(278,250,40,21);
  
  btDownLevel = TButton.Create(widget);
  btDownLevel.parent = panel;
  btDownLevel.caption = "下移";
  btDownLevel.OnClickEx = "btDownLevelOnClick";
  btDownLevel.rc = Rect(320,250,40,21);
  
  
//////////////////////////////////////////////////////// 

  icoListBoxOnClickEx(icoListBox); 
  
}

function btImportIcoListOnClick(sender)
{                               
  if(curCount>0)
    if(! widget.confirm("导入操作会清除现有全部快捷方式，是否继续？") )
      return;

  //导入
  var fn;
  try
  {
    var dg = TOpenDialog.Create(widget);
    dg.DefaultExt = "msctheme"; 
    dg.FileName = "快捷方式备份文件.msctheme" ;
    dg.Filter = "快捷方式列表备份文件(*.msctheme)|*.msctheme";
    dg.title = "导入快捷方式列表备份";
    dg.InitialDir = widgetPath + "Backup";
    if(!dg.Execute)
      return;
    fn = dg.FileName;
    dg.free; 

    if( ReadIniEx(fn,"root","flag")!="myshortcut2theme" )
    {
      alert("备份文件格式非法,请到鱼鱼论坛寻求帮助 http://bbs.cfishsoft.com");
      return;
    }
    
    try{  
      icoListBox.clear;
      edtIcoCap.text = "";
      edtIcoPath.text = "";
      edtIcoAction.text = "";      
    }catch(e){}

    ImportShortcutList(fn);
    
    refreshMgrIconList();
    
    showIcons(1); 
    
    
  }catch(e)
  {
  }
  

}

function btExportIcoListOnClick(sender)
{
  //导出备份 
  var fn;
  try
  {
    var dg = TSaveDialog.Create(widget);
    dg.DefaultExt = "msctheme"; 
    dg.FileName = "快捷方式备份_"+  formatDateTimeStr() + ".msctheme" ;
    dg.Filter = "快捷方式列表备份文件|*.msctheme";
    dg.title = "导出快捷方式列表备份";
    dg.InitialDir = widgetPath + "Backup";
    if(!dg.Execute)
      return;
    fn = dg.FileName;
    dg.free;
    if(fileExists( fn ))
      if(! widget.confirm("文件名已经存在，是否覆盖？") )
        return;
    
    ExportShortcutList(fn)
  }catch(e)
  {
  }
  

}

function btUpLevelOnClick(sender)
{
  curID = icoListBox.itemIndex;
  if((curID<=0)||(curID>=icoListBox.items.count) )
    return;
    
  var ca = iconArray[ curID ].caption; 
  var pa = iconArray[ curID ].path; 
  var ac = iconArray[ curID ].action; 
    
  iconArray[ curID ].caption = iconArray[ curID-1 ].caption; 
  iconArray[ curID ].path = iconArray[ curID-1 ].path; 
  iconArray[ curID ].action = iconArray[ curID-1 ].action; 
  writecurIDIcon(curID);
    
  iconArray[ curID-1 ].caption = ca; 
  iconArray[ curID-1 ].path = pa; 
  iconArray[ curID-1 ].action = ac;
  writecurIDIcon(curID-1);
   
  icoListBox.Items.Move(curID,curID-1);
  icoListBox.ItemIndex=curID-1;
  
  showIcons(iPageIndex); 
    
}

function btDownLevelOnClick(sender)
{
  curID = icoListBox.itemIndex;
  if((curID<0)||(curID>=icoListBox.items.count-1) )
    return;
    
  var ca = iconArray[ curID ].caption; 
  var pa = iconArray[ curID ].path; 
  var ac = iconArray[ curID ].action; 
    
  iconArray[ curID ].caption = iconArray[ curID+1 ].caption; 
  iconArray[ curID ].path = iconArray[ curID+1 ].path; 
  iconArray[ curID ].action = iconArray[ curID+1 ].action; 
  writecurIDIcon(curID);
    
  iconArray[ curID+1 ].caption = ca; 
  iconArray[ curID+1 ].path = pa; 
  iconArray[ curID+1 ].action = ac;
  writecurIDIcon(curID+1);
   
  icoListBox.Items.Move(curID,curID+1);
  icoListBox.ItemIndex=curID+1;
  
  showIcons(iPageIndex);     
    
}


function icoListBoxOnClickEx(sender)
{
  curID = icoListBox.itemIndex;
  if((curID<0)||(curID>=icoListBox.items.count) )
    return;
    
  try
  {
    var fn = widgetPath + iconArray[curID].path;
    if( !fileExists( fn  ) )
      fn = iconArray[curID].path;
    if( !fileExists( fn  ) )
      fn = widgetPath + "images\\defaulticon.png" ;
    icoImg.picture.loadfromfile( fn );
  }catch(e){}
  
  edtIcoCap.text = iconArray[ sender.itemIndex ].caption; 
  edtIcoPath.text = iconArray[ sender.itemIndex ].path; 
  edtIcoAction.text = iconArray[ sender.itemIndex ].action; 

}

function btSelPicClick(sender)
{
  var fn;
  try
  {
    var dg = TopenPictureDialog.Create(widget);
    dg.FileName = edtIcoPath.text;
    dg.Filter='图片文件|*.png;*.jpg;*.bmp;*.ico';
    dg.InitialDir = widgetPath + "images\\soft";
    if(!dg.Execute)
      return;
    fn = dg.FileName;
    dg.free;
    if(!fileExists( fn ))
      return;
    if( fn.substr(0,widgetPath.length).toLowerCase() == widgetPath.toLowerCase()  )
      fn = fn.substr(widgetPath.length);  
    edtIcoPath.text = fn; 
  }catch(e)
  {
  }
}

function btSelActClick(sender)
{
  var fn;
  try
  {
    fn = openFileDialog;
    if(fn!="")
      edtIcoAction.text = fn; 
  }catch(e)
  {
  }
}

function btAddIcoOnClick(sender)
{
  addIcon("新图标","","images\\defaultIcon.png");
  curID = curCount-1;
  icoListBox.items.add("新图标");

  lbIconCount.caption = "快捷方式列表 [共 "+ iconArray.length +" 个]:";

  //刷新图标 
  showIcons(Math.ceil(curCount/SinglePageCount)); 
  icoListBox.itemIndex = curID; 
  icoListBoxOnClickEx(icoListBox); 
} 
         
function btDelIcoOnClick(sender)
{
  curID = icoListBox.itemIndex;
  if(curID<0) return;
  if(!widget.confirm('确认删除快捷方式图标 "'+ iconArray[curID].caption +'" ？\n链接动作: ' + iconArray[curID].action))
    return false;
 
  deleteIDIcon(curID);
  icoListBox.DeleteSelected;
  
  if(  curID<icoListBox.items.count )
    icoListBox.itemIndex = curID
  else if(  curID-1 < icoListBox.items.count )
    icoListBox.itemIndex = curID-1
  else if(icoListBox.items.count>0) 
    icoListBox.itemindex = 0; 
  icoListBoxOnClickEx(icoListBox);  
  lbIconCount.caption = "快捷方式列表 [共 "+ iconArray.length +" 个]:";
}         

function btClearIcoOnClick(sender)
{
  if(!widget.confirm('确认要清空所有快捷方式图标？'))
    return;
  clearAllIcons();
  icoListBox.clear;    

  edtIcoCap.text = "";
  edtIcoPath.text = "";
  edtIcoAction.text = "";
  lbIconCount.caption = "快捷方式列表 [共 "+ iconArray.length +" 个]:";

}
         
         
function btSaveIcoOnClick(sender)
{
  curID = icoListBox.itemIndex;
  if((curID<0)||(curID>=icoListBox.items.count) )
    return;
  
  iconArray[curID].caption = edtIcoCap.text;
  iconArray[curID].path = edtIcoPath.text;
  iconArray[curID].action = edtIcoAction.text;

  icoListBox.clear; 
  for(var i=0;i<iconArray.length;i++)
    icoListBox.items.add(iconArray[i].caption);
  
  writecurIDIcon(curID);
  
  //刷新图标 
  showIcons(iPageIndex); 
  icoListBox.itemIndex = curID; 
  
} 

function OnAllSettingsSaved()
{
  loadskin();
  btSaveIcoOnClick(null);      
}

function writecurIDIcon(id)
{
  WriteIni(id+"caption",iconArray[id].caption);
  WriteIni(id+"path",iconArray[id].path);
  WriteIni(id+"action",iconArray[id].action);
}

function formatDateTimeStr()
{
  var dt = new Date();
  return ""+ dt.getYear() 
         + (dt.getMonth()+1)
         + dt.getDate()
         + dt.getHours()
         + dt.getMinutes()
         + dt.getSeconds();
}

function ImportShortcutList(fn)
{
  clearAllIcons(); 
    
  curCount = parseInt( ReadIniEx(fn,"root","IconCount") );

  if(isNaN(curCount)) curCount = 0;
  if( (curCount<0)||(curCount=="") )
    curCount = 0;
     
  WriteIni("IconCount",curCount);
  for (var i = 0; i < curCount; i++)
  {
    iconArray.push(new NewIcon());
    
    iconArray[i].id = i;
    iconArray[i].caption = ReadIniEx(fn,"root",i + "caption" );
    iconArray[i].path = ReadIniEx(fn,"root",i + "path" );
    iconArray[i].action = ReadIniEx(fn,"root", i + "action" );
    
    if( (!fileExists( widgetPath + iconArray[i].path ))&&(!fileExists(iconArray[i].path )))
      iconArray[i].path = getFileIcon(iconArray[i].action);    

    WriteIni(i+"caption",iconArray[i].caption);
    WriteIni(i+"path",iconArray[i].path);
    WriteIni(i+"action",iconArray[i].action);

  }

}

function ExportShortcutList(fn)
{
  WriteIniEx(fn,"root","flag","myshortcut2theme" );
  if(isNaN(curCount)) curCount = 0;
  WriteIniEx(fn,"root","IconCount",curCount);
  for (var i = 0; i < curCount; i++)
  {
    WriteIniEx(fn,"root",i+"caption",iconArray[i].caption);
    WriteIniEx(fn,"root",i+"path",iconArray[i].path);
    WriteIniEx(fn,"root",i+"action",iconArray[i].action);
  }

}

function refreshMgrIconList()
{
  try
    {  
      icoListBox.clear;
      for(var i=0;i<iconArray.length;i++)
        icoListBox.items.add(iconArray[i].caption);
      if(icoListBox.items.count>0)  icoListBox.itemIndex = icoListBox.items.count-1;
      lbIconCount.caption = "快捷方式列表 [共 "+ iconArray.length +" 个]:";
 
      icoListBoxOnClickEx(icoListBox); 
    }catch(e){}  
}

function nMenu4OnClick()
{
  if(!widget.confirm('确认要清空所有快捷方式图标？'))
    return;
  clearAllIcons();    
  refreshMgrIconList();   
}

function loadskin()
{
  showhint = parseInt( GetSetting("showhint") );
  if( GetSetting("custbg")=="1" )
    bgPaper.Src = GetSetting("bgfile") 
  else
    bgPaper.Src = GetSetting("bgpaper"); 
  rowCount = parseInt( GetSetting("rowCount") );
  SinglePageCount = rowCount*3; 
  bgPaper.alpha = parseInt( GetSetting("bgalpha")  );
  iPageIndex = parseInt( ReadIni("iPageIndex")  );
  
  bgFrame.Src = "images\\bgFrame" + rowCount + ".png";
  widgetHeight = bgFrame.Height;
  if(rowCount==1)
  {
    incRow = true;
    imgRow.Src = "images\\morerow.png";
    imgRow.tooltip = "展开";
    bgPaper.height = 93;
    for(var i=3;i<9;i++) 
      imgs[i].Visible = false;
    imgRow.top = 85;
    hint.top =  83;
    imgdrag.Top = 43;
    txthint2.Top = 43; 
  }
  else if(rowCount==2)
  {
    if(!incRow)
    {
      imgRow.Src = "images\\lessrow.png";
      imgRow.tooltip = "折叠";
    }
    else
    {
      imgRow.Src = "images\\morerow.png";
      imgRow.tooltip = "展开";
    }

    for(var i=3;i<6;i++) 
      imgs[i].Visible = true;
    for(var i=6;i<9;i++) 
      imgs[i].Visible = false;
    
    bgPaper.height = 131 ;
    imgRow.top = 123;
    hint.top =  121;

    imgdrag.Top = 60;
    txthint2.Top = 60;    
    
  }
  else
  {
    incRow = false;
    imgRow.Src = "images\\lessrow.png";
    imgRow.tooltip = "折叠";
    bgPaper.height = 167;
    for(var i=0;i<9;i++) 
      imgs[i].Visible = true;
    imgRow.top = 159;
    hint.top =  157;

    imgdrag.Top = 80;
    txthint2.Top = 80;
  }
 

}

function imgRowOnMouseDown(sender)
{
  sender.alpha = 30;
}

function imgRowOnMouseUp(sender)
{
  sender.alpha = 50;   
}

function imgRowOnMouseEnter(sender)
{
  sender.alpha = 100;  
}

function imgRowOnMouseLeave(sender)
{
  sender.alpha = 50;
}

function imgRowOnClick()
{
  if(rowCount==1)
  {
    incRow = true; 
    rowCount++;
  }
  else if(rowCount==2)
  {
    if(incRow)
      rowCount++
    else
      rowCount--;
  }
  else if(rowCount==3)
  {
    incRow = false;
    rowCount--;
  }
    
  SetSetting("rowCount",rowCount );
  SaveSetting("rowCount");
  
  loadskin();  
  showIcons(iPageIndex);
  
}



function btAddOnClick(sender)
{
  custPopMenu.clear;
  custPopMenu.addMenuItem("添加文件...","addIconMenuClick",0);
  custPopMenu.addMenuItem("添加文件夹...","addIconMenuClick",1);
  custPopMenu.addMenuItem("添加以下全部","addIconMenuClick",-2);
  custPopMenu.addMenuItem("-","",0);

  var pnt = custPopMenu.addMenuItem("添加系统图标类","",0); 
  custPopMenu.addMenuItemChild(pnt,"添加此类全部","addIconMenuClick",-5);
  custPopMenu.addMenuItemChild(pnt,"-","",0);
  custPopMenu.addMenuItemChild(pnt,"添加 我的电脑","addIconMenuClick",2);
  custPopMenu.addMenuItemChild(pnt,"添加 我的文档","addIconMenuClick",3);
  custPopMenu.addMenuItemChild(pnt,"添加 网上邻居","addIconMenuClick",4);
  custPopMenu.addMenuItemChild(pnt,"添加 控制面板","addIconMenuClick",5);
  custPopMenu.addMenuItemChild(pnt,"添加 IE浏览器","addIconMenuClick",6);
  custPopMenu.addMenuItemChild(pnt,"添加 拨号上网","addIconMenuClick",7);
  custPopMenu.addMenuItemChild(pnt,"添加 回收站","addIconMenuClick",8);
  
  var pnt = custPopMenu.addMenuItem("添加常用操作类","",0); 
  custPopMenu.addMenuItemChild(pnt,"添加此类全部","addIconMenuClick",-6);
  custPopMenu.addMenuItemChild(pnt,"-","",0);
  custPopMenu.addMenuItemChild(pnt,"添加 CMD命令行","addIconMenuClick",9);
  custPopMenu.addMenuItemChild(pnt,"添加 运行对话框","addIconMenuClick",10);
  custPopMenu.addMenuItemChild(pnt,"添加 查找文件对话框","addIconMenuClick",11);
  custPopMenu.addMenuItemChild(pnt,"添加 最小化所有窗口","addIconMenuClick",12);
  custPopMenu.addMenuItemChild(pnt,"添加 任务管理器","addIconMenuClick",13);

  var pnt = custPopMenu.addMenuItem("添加关机操作类","",0); 
  custPopMenu.addMenuItemChild(pnt,"添加此类全部","addIconMenuClick",-7);
  custPopMenu.addMenuItemChild(pnt,"-","",0);
  custPopMenu.addMenuItemChild(pnt,"添加 关机","addIconMenuClick",14);
  custPopMenu.addMenuItemChild(pnt,"添加 重启","addIconMenuClick",15);
  custPopMenu.addMenuItemChild(pnt,"添加 注销","addIconMenuClick",16);
  custPopMenu.addMenuItemChild(pnt,"添加 休眠/待机","addIconMenuClick",17);
  custPopMenu.addMenuItemChild(pnt,"添加 切换系统用户","addIconMenuClick",18);
  custPopMenu.addMenuItemChild(pnt,"添加 锁定系统","addIconMenuClick",19);
  
  var pnt = custPopMenu.addMenuItem("添加Office类","",0); 
  custPopMenu.addMenuItemChild(pnt,"添加此类全部","addIconMenuClick",-8);
  custPopMenu.addMenuItemChild(pnt,"-","",0);
  custPopMenu.addMenuItemChild(pnt,"添加 Word","addIconMenuClick",20);
  custPopMenu.addMenuItemChild(pnt,"添加 Excel","addIconMenuClick",21);
  custPopMenu.addMenuItemChild(pnt,"添加 Outlook","addIconMenuClick",22);
  custPopMenu.addMenuItemChild(pnt,"添加 Access","addIconMenuClick",23);
  custPopMenu.addMenuItemChild(pnt,"添加 PowerPoint","addIconMenuClick",24);
  
  custPopMenu.popup;  
}

function btThemeOnClick(sender)
{
  custPopMenu.clear;
  custPopMenu.addMenuItem("新建分类...","groupMenuClick",0);
  var pnt = custPopMenu.addMenuItem("管理当前分类","",0);
  var item = custPopMenu.addMenuItemChild(pnt,"重命名当前分类","groupMenuClick",1);
  if( curTheme.toLowerCase()=="default.msctheme"  ) item.enabled = false;
  var item = custPopMenu.addMenuItemChild(pnt,"删除当前分类","groupMenuClick",2);
  if( curTheme.toLowerCase()=="default.msctheme"  ) item.enabled = false;
  custPopMenu.addMenuItemChild(pnt,"清空当前分类","groupMenuClick",3);
  custPopMenu.addMenuItem("-","",0);

  themeList = getFileList( widgetPath+"themes" ,"msctheme",true );
  themeList = themeList.split("\r\n");
  themeList.splice(themeList.length-1, 1);
  
  var fname = "";
  for(var i=0;i<themeList.length;i++)
  {
    fname = getFileName(themeList[i]);
    var item = custPopMenu.addMenuItem( fname ,"groupMenuClick",5+i);
    if(fname.toLowerCase() == curTheme.toLowerCase() )
      item.Checked = true;
  }
  
  custPopMenu.popup;    
}

function groupMenuClick(sender)
{
  var tag = sender.tag; 
  switch(tag)
  {
    case 0:  creatNewTheme();
      break;
    case 1 :
      var fn = widgetPath + "themes\\"+ curTheme ;                                              
      var cap = curTheme.substr(0,curTheme.length-9).toLowerCase() ;
      var str = widget.prompt("重命名当前分类", cap );
      if(str=="<undefined>") return;
      if(str.toLowerCase()==cap) return;
      if( fileExists( widgetPath + "themes\\"+ str + ".mscTheme" ) )
      {
        widget.alert('分类名"'+str+'"已经存在，请重新输入.') ;
        return;
      }
      
      copyFile( fn, widgetPath + "themes\\"+ str + ".mscTheme"  );
      if( fn.toLowerCase()!= (widgetPath + "themes\\"+ str + ".mscTheme").toLowerCase() )
        deleteFile( fn );
      curTheme = str + ".mscTheme" ; 
      WriteIni("curTheme",curTheme );
            
      break;
    case 2 :
      if( curTheme.toLowerCase()=="default.msctheme"  )
      {
        if(! widget.confirm2('default默认分类只能清空不能删除，确认清空？') )
          return;        
        clearAllIcons();    
        refreshMgrIconList();  
        return;
      }

      if(! widget.confirm2('确认删除当前分类"'+ curTheme +'"？') )
        return;        
      var oldtheme = widgetPath + "themes\\"+ curTheme ;
      changeTheme( "default.mscTheme" );                                              
      deleteFile( oldtheme );
    
    
      break;
    case 3 :
      nMenu4OnClick();
      break;
    case 4 :
      break;
      
      
    default:
      if(tag<5) return;
      var id = tag-5;
      
      Print( id + "   " + themeList.length );
      
      if(id>=themeList.length) return;
      var newTheme =  getFileName( themeList[id] );
      
      Print( newTheme );
      
      if( newTheme.toLowerCase() == curTheme.toLowerCase()  ) 
        return;
      changeTheme(newTheme);
      
  }

}

function changeTheme(newTheme)
{     
  if( !fileExists( widgetPath + "themes\\"+ curTheme ) )
    curTheme = "default.mscTheme";
  
  ExportShortcutList(widgetPath + "Themes\\" + curTheme);

  curTheme = newTheme; 
  WriteIni("curTheme",curTheme );

  ImportShortcutList( widgetPath + "Themes\\" + curTheme );
  Print( curTheme );
  
  refreshMgrIconList();
  showIcons(1);   
}


function creatNewTheme()
{       
  var str = widget.prompt("新建分类","新分类1");
  if(str=="<undefined>") return;
  
  var fn = widgetPath + "Themes\\" + str + ".msctheme";
  if( fileExists( fn ) )
  {
    if(! widget.confirm2('分类名"'+str+'"已经存在，是否覆盖?') )
      return;
    deleteFile( fn );
  } 
  ExportShortcutList(widgetPath + "Themes\\" + curTheme);
  curTheme = str + ".msctheme"; 
  WriteIni("curTheme",curTheme );

  WriteIniEx(fn,"root","flag","myshortcut2theme" );
  curCount = 0;
  WriteIniEx(fn,"root","IconCount",curCount);
  
  clearAllIcons();    
  refreshMgrIconList();   
  

}