var tabDefName = "默认";  //默认tab名 XDeskTab 
var icon0left = 332;  //第一个icon的x边距 
var icon0left1 = 25;  //左对齐时 
var iconWidth = 32;
var iconTop = 24;
var splitWidth = 7;
var tabWidth = 20;
var tabHeight = 55;

var thisCount;
var changIndex=-1;
var changImgIndex=-1;
var isleft = 1;
var mouseonchange = 0; 
var isdown=-1;         //图标移动 
var btnMoveIndex=-1;   //分类按钮移动
var moveX=-1;
var mouseOn=false;
 
var speed = 5;  //弹出的速度 

var imgs =new Array();
var btns =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 = "0.默认.msctheme";
var themeList = ""; 
 
//将当前页面icon都显示出来 
function showIcons(aPageIndex)
{
  
  if(aPageIndex<1) aPageIndex = 1;
  LockRefresh;
     if ( changImgIndex !=-1)
     { imgs[changImgIndex].bgColor=""; }
  imgHover.Visible = false;
  hint.caption = '';
  if( curTheme.toLowerCase().indexOf("默认.msctheme")==-1  ) 
    txtCap.caption = curTheme.split(".")[1];
  else
    txtCap.caption = tabDefName;  
  
  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;
  }
iPageCount=Math.ceil(curCount/SinglePageCount); 
  maxpage = Math.ceil(curCount/SinglePageCount);
  if( aPageIndex > maxpage )
    aPageIndex = maxpage;    
  iPageIndex = aPageIndex;
  var baseIndex= (aPageIndex-1) * SinglePageCount;
  txtPage.caption = iPageIndex + "/" + maxpage;  
      
  var index;
   
   if (curCount<=SinglePageCount) 
  thisCount=curCount
  else  
  {if (iPageIndex==maxpage) 
  thisCount= Math.ceil(curCount % SinglePageCount)
  else
   thisCount=SinglePageCount; 
   } 
   if ( thisCount==0)   thisCount=SinglePageCount; 

   isleft = parseInt( GetSetting("isleft")  );

  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;
      imgs[index].Top=iconTop;
      
      if ( isleft == 1)
       imgs[index].Left = ( widgetWidth - (iconWidth + splitWidth) * thisCount) / 2 - splitWidth * 1.5 + index *(iconWidth + splitWidth);
     
    }
    catch(exception){}    
  }

 

  WriteIni("iPageIndex",iPageIndex);
  
  
  UnLockRefresh;

}



function widgetOnInit()
{ 
 LockRefresh;
  

  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;
  btns[0] = button0;
  btns[1] = button1;
  btns[2] = button2;
  btns[3] = button3;
  btns[4] = button4;
  btns[5] = button5;
  btns[6] = button6;
  for(var i=0;i<9;i++)
  {
       imgs[i].OnClick = "imgsOnClick";
       imgs[i].OnMouseDown = "img0OnMouseDown";
       imgs[i].OnMouseEnter = "img0OnMouseEnter";  
       imgs[i].OnMouseMove=  "img0OnMouseMove";
       imgs[i].OnMouseUp=  "img0OnMouseUp";
    }
  for(var i=0;i<7;i++)
  {
    btns[i].OnClick = "btnsOnClick";
     btns[i].OnMouseMove ="";
    //btns[i].OnMouseLeave ="button0OnMouseLeave";
    btns[i].OnMouseDown ="button0OnMouseDown";
    btns[i].OnMouseUp ="button0OnMouseUp";
     btns[i].OnMouseEnter="button0OnMouseEnter";
     
   } 
  loadskin();
  
 
  //载入curCount  icon数量 
  if( isNaN(  parseInt(  ReadIni("IconCount")  )  ) ) 
    curCount=0
  else
    curCount = parseInt(ReadIni("IconCount"));
    
  curTheme = ReadIni("curTheme")
  if(curTheme=="") curTheme = '0.默认.mscTheme';   
 

  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); 
  
   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]);
  
    if (i<7) 
    {
    btns[i].caption= fname.split(".")[1];
      btns[i].enabled=true;
      
  if (parseInt(GetSetting("showTab"))==1)
  {btns[i].Visible=false;
  }
  else
  { 
  btns[i].Visible=true;
  }
  }
  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
    btns[i].Visible=false;
    btns[i].enabled=false;
  }
  }
  
  if( isNaN(  parseInt(  ReadIni("widgettop")  )  ) ) 
    widget.Top =    Math.ceil(  ReadIni("widgettop")  );
  if( isNaN(  Math.ceil(  ReadIni("widgetleft")  )  ) )  
    widget.Left =    parseInt(  ReadIni("widgetleft")  );
    

 UnLockRefresh;
}


function img0OnPopupMenu(sender)
{  if (mouseOn!=-1)
  img0OnMouseLeave(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.addMenuItem('交换位置',"changeIcon",tag);
  custPopMenu.addMenuItem('创建快捷方式',"createLink",tag);

  
  
  custPopMenu.popup;
  
}
 function createLink(sender)
{  
  
 var fso = new ActiveXObject("Scripting.FileSystemObject");   
  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  { 
                  var shell = new ActiveXObject("WScript.Shell");      
             var tagFolder = shell.regread("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\desktop");
               
               //  if(!fso.FolderExists(tagFolder )) { fso.CreateFolder(tagFolder);}
                 if(!fso.FileExists(tagFolder + "//"+sCaption+".lnk"))
                 {                
                     var link = shell.CreateShortcut(tagFolder + "//"+sCaption+".lnk");  
                     link.Description = "打开程序"+sCaption+"的快捷方式";           
                      
                      link.TargetPath = sAction;
                      link.WorkingDirectory = sAction.substr(0,sAction.lastIndexOf("\\")+1);  
                     link.WindowStyle = 3;
                              
                     link.Save();                      
                 }  }catch(e)
  {
                alert("暂不支持创建此程序的快捷方式");
  }
                 
 }
function changeIcon(sender)
{     
      changImgIndex = sender.tag;
      changIndex =(iPageIndex-1) * SinglePageCount + sender.tag;            
      imgs[ sender.tag ].bgColor="0,0,0";
   
}

//编辑图标属性 
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;
  var index= (iPageIndex-1) * SinglePageCount + tag;
 
     LockRefresh;  
   if (mouseOn==-1)
   {
   sender.Left = sender.Left - splitWidth;
   sender.Width = iconWidth + splitWidth*2;
   sender.Height = iconWidth + splitWidth*2;   
     mouseOn=tag;
    }
  imgHover.left = sender.Left-2;
  imgHover.top = sender.Top-2;
  
  

  hint.caption = iconArray[index].caption;
   hint.left = sender.Left + parseInt( (iconWidth+splitWidth*2 -hint.width)/2 );

  imgHover.Visible = true; 
  UnLockRefresh; 

  

 
  if (nMenu5.Checked==-1)
  {
  if (isdown!=-1)
    {

    if (isdown==100) return;
  var sCaption = iconArray[isdown].caption;
  var sAction = iconArray[isdown].action;
  var sPath = iconArray[isdown].path;
    iconArray[isdown].caption= iconArray[index].caption;
    iconArray[isdown].action= iconArray[index].action;
    iconArray[isdown].path= iconArray[index].path;
    iconArray[index].caption= sCaption;
    iconArray[index].action=sAction;
    iconArray[index].path= sPath;
    showIcons(iPageIndex);
    if (isleft==2)
    {
    
     if (tag==0)
     imgs[0].Left=icon0Left
     else
    imgs[tag-1].Left=imgs[tag-1].Left+splitWidth;  
     }
    return;
    }
   } 



 
     
}


function img0OnMouseLeave(sender)
{
  if(!sender.Visible) return;
  imgHover.Visible = false; 
    
   if (mouseOn!=-1)
  { sender.Left=sender.Left+splitWidth;
     sender.Width=iconWidth;
  sender.Height=iconWidth;
  mouseOn=-1;
  }
}

function bgOnMouseMove()
{
  LockRefresh;
  if(imgHover.Visible)
    imgHover.Visible = false;
  hint.caption = '';  
  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()
{
   if (nMenu5.Checked==-1)
  {    isdown=100;    }
}

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++)
      {
        sender.tag = i;
        addIconMenuClick(sender);
      } 
      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;
  

  if (nMenu5.Checked==-1)
   {  
   if (isdown!=-1 && isdown!=100  )
   {   
if ( isleft == 1)
{
    
    if  (isdown==0 || isdown % SinglePageCount==0)
    imgs[0].Left = ( widgetWidth - (iconWidth + splitWidth) * thisCount) / 2 - splitWidth * 1.5 - splitWidth;
   else
   imgs[isdown % SinglePageCount].Left=imgs[isdown % SinglePageCount-1].Left + iconWidth + splitWidth -splitWidth;
 
 }
  else if ( isleft > 1 )
  {  
   if  (isdown==0 || isdown % SinglePageCount==0)
    imgs[0].Left= icon0left 
   else
   imgs[isdown % SinglePageCount].Left=imgs[isdown % SinglePageCount-1].Left - iconWidth - splitWidth ;
 
  } 
  else
 {
 
   if  (isdown==0 || isdown % SinglePageCount==0)
    imgs[0].Left= icon0left1 -splitWidth
   else
   imgs[isdown % SinglePageCount].Left=imgs[isdown % SinglePageCount-1].Left + iconWidth + splitWidth -splitWidth;
 
 } 
 
 
   
   imgs[isdown % SinglePageCount].Top=iconTop;
   hint.Top = iconTop + iconWidth + 2;  
   
    if (mouseY - widget.Top > 80)
   {
 
   if (isdown==0) 
   {
    createLink(imgs[0]);
    if (nMenu6.Checked==-1)
    deleteIcon(imgs[0]); 
  
     } else  
     {
   createLink(imgs[isdown % SinglePageCount]);
  if (nMenu6.Checked==-1)
     deleteIcon(imgs[isdown % SinglePageCount]); 
      }
  }
 
   
   
  isdown=-1;
  }
  return;
   }
     
 
  if ( changIndex != -1 )
  {   
  var sCaption = iconArray[changIndex].caption;
  var sAction = iconArray[changIndex].action;
  var sPath = iconArray[changIndex].path;
    iconArray[changIndex].caption= iconArray[index].caption;
    iconArray[changIndex].action= iconArray[index].action;
    iconArray[changIndex].path= iconArray[index].path;
    iconArray[index].caption= sCaption;
    iconArray[index].action=sAction;
    iconArray[index].path= sPath;
    showIcons(iPageIndex);
  
   imgs[changImgIndex].bgColor="";
   changIndex = -1; 
   changImgIndex = -1;
  return;
  }
  if (mouseOn!=-1)
  img0OnMouseLeave(sender);
  var act = iconArray[index].action;



  if(act=="")
  {
    showTrayHint("我的桌面图标2", "动作为空。 请先给此图标指定打开动作，比如打开某个文件或文件夹" );
    editIcon(tag);
    return;
  }                                  
  else if(act=="shutdown")
  {                                   
    if(! widget.confirm2( "确认要关机？" ))
      return; 
    runEx("shutdown","-s -t 03");
  }
  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");
    return;
  }  
  else 
      run( act  );
   
}

function btnsOnClick(sender)
{ 
    if(!sender.Visible) return;
//  if(!sender.cursorHandPoint) return;
   Print("visible true" );
var str =  sender.Name;
  var tag = parseInt( str.substring(str.length-1,str.length));

    if (nMenu5.Checked==-1 && btnMoveIndex!=-1 )
   {  
         Print("btnMoveIndex3:"+btnMoveIndex );  
   if  (btnMoveIndex==0 )
    btns[0].Left= icon0left1
   else
   btns[btnMoveIndex].Left=btns[btnMoveIndex-1].Left + 50 ;
   
   btns[btnMoveIndex].Top=0;
 
    if (mouseY - widget.Top > 80)
        {
     Print("btnMoveIndex4:"+btnMoveIndex );   
      var sid = btnMoveIndex;
      btnMoveIndex =-1;
    if (nMenu6.Checked==-1)
    deleteTheme(btns[sid])
    else
    renameTheme(getFileName( themeList[sid])) ;
          }
 }

      
      if(tag>=themeList.length) return;
      var newTheme =  getFileName( themeList[tag] );
     if( newTheme.toLowerCase() == curTheme.toLowerCase()) return; 
      changeTheme(newTheme);
     
  

}



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()
{ 
   if (mouseOn!=-1)
      img0OnMouseLeave(imgs[mouseOn]);
    //Print( mouseOn);
if (nMenu5.Checked ==-1)
{
if (isdown!=-1 && isdown!=100 )
{
                 if ( isleft == 1)
                    {
                    
                        if  (isdown==0 || isdown % SinglePageCount==0)
                           imgs[0].Left = ( widgetWidth - (iconWidth + splitWidth) * thisCount) / 2 - splitWidth * 1.5 
                             else
                              imgs[isdown % SinglePageCount].Left=imgs[isdown % SinglePageCount-1].Left + iconWidth + splitWidth;
 
                              } else
                               {
   
                                if  (isdown==0 || isdown % SinglePageCount==0)
                                  imgs[0].Left= icon0left1
                                   else
                                    imgs[isdown % SinglePageCount].Left=imgs[isdown % SinglePageCount-1].Left + iconWidth + splitWidth;
                                     }
                                       imgs[isdown % SinglePageCount].Top=iconTop;
                                         hint.Top = iconTop + iconWidth + 2; 
                                         
  
   if (isdown==0) 
   {
    createLink(imgs[0]);
    if (nMenu6.Checked==-1)
    deleteIcon(imgs[0]); 
  
     } else  
     {
   createLink(imgs[isdown % SinglePageCount]);
  if (nMenu6.Checked==-1)
     deleteIcon(imgs[isdown % SinglePageCount]); 
      }
      
  isdown=-1;  
}

  
  
   if ( btnMoveIndex!=-1 )
   {  
    Print("btnMoveIndex: "+btnMoveIndex );
   if  (btnMoveIndex==0 )
    btns[0].Left= icon0left1
   else
   btns[btnMoveIndex].Left=btns[btnMoveIndex-1].Left + 50 ;
  
   btns[btnMoveIndex].Top=0;
 
        if (mouseY - widget.Top > 80)
        {
     Print("btnMoveIndex2: "+btnMoveIndex );    
      var sid = btnMoveIndex;
      btnMoveIndex =-1;
    if (nMenu6.Checked==-1)
    deleteTheme(btns[sid])
    else
    renameTheme(getFileName( themeList[sid])) ;
        }


   }
 
  
}
  
  LockRefresh; 
  bgOnMouseMove();
  btAdd.alpha = 80;
  UnLockRefresh;
    if (widget.top<=0)
    {
    showHideBar(false);
     }
     else if ( widget.Left<=0)
     {      //("" );
     showHideBar(false);
  
     }
}




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 = "themeBak"; 
    dg.FileName = "msctheme备份文件.themeBak" ;
    dg.Filter = "msctheme备份文件(*.themeBak)|*.themeBak";
    dg.title = "导入msctheme备份";
    dg.InitialDir = widgetPath + "Backup";
    if(!dg.Execute)
      return;
    fn = dg.FileName;
    dg.free; 
  themeList = getFileList( widgetPath+"themes" ,"msctheme",true );
  themeList = themeList.split("\r\n");
  themeList.splice(themeList.length-1, 1);

  for(var i=0;i<themeList.length;i++)
  { 
  deleteFile(  themeList[i] );
  }      
  run("winrar x -ibck  " + fn +" *.mscTheme "+ widgetPath +"themes\\"  ) ; 
   alert("导入成功！" ); 
  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]);

   if( i<7 )
    {
    btns[i].caption = fname.split(".")[1];
        if (parseInt(GetSetting("showTab"))==0)
        btns[i].Visible=true;
        btns[i].enabled=true;
    }
    var item = custPopMenu.addMenuItem( fname ,"groupMenuClick",5+i);
    if(i==0)
      item.Checked = true;

  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
  btns[i].Visible=false;
    btns[i].enabled=false;
  }
  }   

   }catch(e){alert("导入失败，导入还原需\"Winrar\"软件支持！" );}
   
   
    curTheme = getFileName(themeList[0]);
  WriteIni("curTheme",curTheme );

  ImportShortcutList( widgetPath + "Themes\\" + curTheme );
  
  
  refreshMgrIconList();
  showIcons(1);   
 
    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();
    
    
    
    
  }catch(e)
  {
  }
  

}

function btExportIcoListOnClick(sender)
{
    //导出备份 
    //var fd = openFolderDialog;
    //if(fd=="") return;
    //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]);
   //copyFile(themeList[i],fd+"themes\\"+fname );
   //} 
   
   try
  {
    var dg = TSaveDialog.Create(widget);
    dg.DefaultExt = "themeBak"; 
    dg.FileName = "快捷方式备份_"+  formatDateTimeStr() + ".themeBak" ;
    dg.Filter = "msctheme备份文件|*.themeBak";
    dg.title = "导出msctheme备份";
    dg.InitialDir = widgetPath + "Backup";

    
    if(!dg.Execute)
      return;
    fn = dg.FileName;
    dg.free;
    if(fileExists( fn ))
      if(! widget.confirm("文件名已经存在，是否覆盖？") )
        return;   
          
          run("winrar a -ep1 -ibck " + fn +" "+ widgetPath +"themes\\*.mscTheme"  ) ; 
          alert("导出备份成功！" );
   }catch(e)
  {  alert("导出失败，导出备份需\"Winrar\"软件支持！" );
  }
   return;
 
  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(); 
 //将新数组所有内容逐一清除 
  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);
  
     
  curCount = parseInt( ReadIniEx(fn,"root","IconCount") );
  iPageCount=Math.ceil(curCount/SinglePageCount); 
  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") );
  SinglePageCount = 9; 
  iPageIndex = parseInt( ReadIni("iPageIndex")  );
  isleft = parseInt( GetSetting("isleft")  );
 // bgFrame.Src = "Default.png" ; //images\\bgFrame" + rowCount + ".png";
  bg.src ="bg_pic\\"+ getSetting("bg") + "d.png";
  button0.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
   button1.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
    button2.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
     button3.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
      button4.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
       button5.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
        button6.comb3in1ImgSrc ="btn_pic\\"+ getSetting("btn_bg") + ".png";
  widgetHeight = bg.Height + 5;
  widgetWidth = bg.Width;


  
   mouseonchange =  parseInt(GetSetting("mouseonchange"));
  
    if  ( mouseonchange == 1 )
      {
   btNext.OnMouseEnter="btNextOnClick";
   btPrev.OnMouseEnter="btPrevOnClick";
      }
     else
      {
      btNext.OnMouseEnter="nil";
      btPrev.OnMouseEnter="nil";
      }
      
   
  for(var i=0;i<9;i++)
  { 
  imgs[i].Visible = true;   
   

   if (isleft>1)
   {
                  if(i==0)
                  {
                 imgs[i].Left = icon0left;
                      }
                    else
                     {
                    imgs[i].left = imgs[i-1].Left - iconWidth - splitWidth  ;
                    }
     }
     else   if (isleft < 1 )
     {
                if(i==0)
                {
                imgs[i].Left = icon0left1;
             
                }
                else 
                 {
                  imgs[i].left = imgs[i-1].Left + iconWidth + splitWidth  ;
                  } 
     }
    
    
    imgs[i].top = iconTop;
    imgs[i].Width = iconWidth;
    imgs[i].Height = iconWidth;     
    
    if ( i<7 )
    { 
    if (parseInt( GetSetting( "showTab") )==1)
    btns[i].Visible=false
     else
     btns[i].Visible=true; 
    }
   
    
  }

    if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
    btns[i].Visible=false;
    btns[i].enabled=false;
  }
  }


}



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( txtCap.caption.toLowerCase()=="默认"  ) item.enabled = false;
  var item = custPopMenu.addMenuItemChild(pnt,"删除当前分类","groupMenuClick",2);
  if( txtCap.caption.toLowerCase()=="默认" ) 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]);
 
   if( i<7 )
    {
    btns[i].caption = fname.split(".")[1];
  if (parseInt(GetSetting("showTab"))==0)
    btns[i].Visible=true;
      btns[i].enabled=true;
    }
    var item = custPopMenu.addMenuItem( fname ,"groupMenuClick",5+i);
    if(fname.toLowerCase() == curTheme.toLowerCase() )
      item.Checked = true;
  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
  btns[i].Visible=false;
     btns[i].enabled=false;
  }
  }
  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(2,curTheme.length-11).toLowerCase() ;
      var str = widget.prompt("重命名当前分类", cap );
      if(str=="<undefined>") return;
      if(str.toLowerCase()==cap) return;
      if( fileExists( widgetPath + "themes\\" + curTheme.substr(0,2)+  str + ".mscTheme" ) )
      {
        widget.alert('分类名"'+str+'"已经存在，请重新输入.') ;
        return;
      }
      
      copyFile( fn, widgetPath + "themes\\" +curTheme.substr(0,2)+ str + ".mscTheme"  );
      if( fn.toLowerCase()!= (widgetPath + "themes\\"+curTheme.substr(0,2)+ str + ".mscTheme").toLowerCase() )
        deleteFile( fn );
      curTheme = curTheme.substr(0,2)+ str + ".mscTheme" ; 
      WriteIni("curTheme",curTheme );
            
      if( curTheme.toLowerCase().indexOf("默认.msctheme")==-1  )  
        txtCap.caption = curTheme.split(".")[1];
      else
        txtCap.caption = tabDefName;              
       
    /////////////////////////////////////   
  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]);
    
   if( i<7 )
    {
    btns[i].caption = fname.split(".")[1];
    if (parseInt(GetSetting("showTab"))==0)
    btns[i].Visible=true;
     btns[i].enabled=true;
   }
  
  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
  btns[i].Visible=false;
    btns[i].enabled=false;
  }
  }
  //////////////////////////////////  
            
      break;
    case 2 :
      if( txtCap.caption.toLowerCase()=="默认" )
      {
        if(! widget.confirm2('默认分类只能清空不能删除，确认清空？') )
          return;        
        clearAllIcons();    
        refreshMgrIconList();  
        return;
      }

      if(! widget.confirm2('确认删除当前分类"'+ curTheme +'"？') )
        return;        
      var oldtheme = widgetPath + "themes\\"+ curTheme ;
      changeTheme(getFileName( themeList[0]));                                              
      deleteFile( oldtheme );
   /////////////////////////// 
  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]);
 
   if( i<7 )
    {
    btns[i].caption = fname.split(".")[1];
    if (parseInt(GetSetting("showTab"))==0)
    btns[i].Visible=true;
      btns[i].enabled=true;
    }
  
  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
  btns[i].Visible=false;
    btns[i].enabled=false;
  }
  }
  /////////////////////////////////
      break;
    case 3 :
      nMenu4OnClick();
      break;
    case 4 :
      break;
      
      
    default:
      if(tag<5) return;
      var id = tag-5;
      

      
      if(id>=themeList.length) return;
      var newTheme =  getFileName( themeList[id] );
      
   
      
      if( newTheme.toLowerCase() == curTheme.toLowerCase()  ) 
        return;
      changeTheme(newTheme);
   
  }

}

function changeTheme(newTheme)
{   
   if ( changImgIndex!=-1)
   {imgs[changImgIndex].bgColor="";
    changImgIndex = -1;
    changIndex = -1; 
  
   }
  if( !fileExists( widgetPath + "themes\\"+ curTheme ) )
    curTheme = "0.默认.mscTheme";
                 
  ExportShortcutList(widgetPath + "Themes\\" + curTheme);
 
  curTheme = newTheme; 
  WriteIni("curTheme",curTheme );

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


function creatNewTheme()
{       
  var str = widget.prompt("新建分类","分类"+themeList.length);
  if(str=="<undefined>") return;
  
  var fn = widgetPath + "Themes\\"+themeList.length+"." + str + ".msctheme";
  for (var i=0 ; i< themeList.length; i++)
  {
    if (btns[i].caption== str)
     { alert( '分类 '+ str +'己经存在。');
      return; 
     }
   
  } 
  
  ExportShortcutList(widgetPath + "Themes\\" + curTheme);
  curTheme =themeList.length+"." + str + ".msctheme"; 
  Print("new        "+curTheme );
  WriteIni("curTheme",curTheme );
  WriteIniEx(fn,"root","flag","myshortcut2theme" );
  curCount = 0;
  WriteIniEx(fn,"root","IconCount",curCount);
  clearAllIcons();    
  refreshMgrIconList(); 
  
  themeList = getFileList( widgetPath+"themes" ,"msctheme",true );
  themeList = themeList.split("\r\n");
  themeList.splice(themeList.length-1, 1);
  if( themeList.length-1 < 7)
  { btns[themeList.length-1].caption=str;
    btns[themeList.length-1].Visible=true;
    btns[themeList.length-1].enabled=true;
   
   btnMoveIndex=-1;}
    Print("btnMoveIndex5:"+btnMoveIndex ); 

}
function renameTheme(sender)
{

 var fn = widgetPath + "themes\\"+  sender ;                                              
      var cap = getFileName(fn).substr(2,curTheme.length-11).toLowerCase() ;
      if (cap=="默认") 
      {
      widget.alert('默认分类允许重命名.') ;
      return;} 
      var str = widget.prompt("重命名分类", cap );
      if(str=="<undefined>") return;
      if(str.toLowerCase()==cap) return;

       for (var i=0 ; i< themeList.length; i++)
  {
    if (btns[i].caption== str)
     { alert( '分类 '+ str +'己经存在。');
      return; 
     }
   
  } 
      copyFile( fn, widgetPath + "themes\\" +curTheme.substr(0,2)+ str + ".mscTheme"  );
      if( fn.toLowerCase()!= (widgetPath + "themes\\"+curTheme.substr(0,2)+ str + ".mscTheme").toLowerCase() )
        deleteFile( fn );
      curTheme = curTheme.substr(0,2)+ str + ".mscTheme" ; 
     
      WriteIni("curTheme",curTheme );
            
      if( curTheme.toLowerCase().indexOf("默认.msctheme")==-1  )  
        txtCap.caption = curTheme.split(".")[1];
      else
        txtCap.caption = tabDefName;              
       
    /////////////////////////////////////   
  themeList = getFileList( widgetPath+"themes" ,"msctheme",true );
  themeList = themeList.split("\r\n");
  themeList.splice(themeList.length-1, 1);  
   btns[parseInt(curTheme.substr(0,1))].caption=str;



}

function deleteTheme(sender)
{
  var str =  sender.Name;
  var tag = parseInt( str.substring(str.length-1,str.length)); 
  
     if( sender.caption.toLowerCase()=="默认"  )
      {
        if(! widget.confirm2('默认分类只能清空不能删除，是否清空？') )
          return;        
        clearAllIcons();    
        refreshMgrIconList();  
        return;
      }

    //  if(! widget.confirm2('确认删除当前分类"'+ sender.caption +'"？') )
   //     return;        
   
    if (tag == themeList.length-1)
     {
     changeTheme( getFileName(themeList[ themeList.length-2]) );
     }
     else{
    for(var i=tag;i<themeList.length-1;i++)
   {
     btnsOnClick(btns[i+1]);
     XchangeTheme(i+1,i);

   } 
  }  
 

 
   
       deleteFile(themeList[themeList.length-1]);                                           
       btns[themeList.length-1].Visible=false;  
      btns[themeList.length-1].enabled=false; 
      btns[themeList.length-1].caption="";
  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]);
  
   if( i<7 )
    {
    btns[i].caption = fname.split(".")[1];
    if (parseInt(GetSetting("showTab"))==0)
    btns[i].Visible=true;
     btns[i].enabled=true;
     }
  
  }
  if (themeList.length<7)
  {
  for(var i=themeList.length;i<7;i++)
  {
  btns[i].Visible=false;
   btns[i].enabled=false;
  }
  }
  /////////////////////////////////
}

function XchangeTheme(f1,f2)
{
  var fn1=themeList[f1];
  var fn2=themeList[f2];
  var fn=getFileName(fn1).substr(2,getFileName(fn1).length);
  var fPath=  fn2.substr(0,fn1.lastIndexOf("\\") );
               
       copyFile( fn1, fPath+"\\"+f2+"."+fn); 
    
       deleteFile( fn1 );
       
        curTheme =f2+"."+fn;  
  fn=getFileName(fn2).substr(2,getFileName(fn2).length);
   
          
       copyFile( fn2, fPath+"\\"+f1+"."+fn); 
 
        
       deleteFile( fn2 );
  
   
  themeList = getFileList( widgetPath+"themes" ,"msctheme",true );
  themeList = themeList.split("\r\n");
  themeList.splice(themeList.length-1, 1);
    


}

function txtCapOnClick(sender)
{
  showHideBar(widget.Left < 0);
}

function showHideBar(flag)
{
  if(flag)
  {
     
     if  (widget.Left <0 )  //左
     {
    if(widget.Left == 0) return;
    //拉出 
    //widget.Left = tabWidth - widgetWidth;
    while(true)
    {
      if(widget.Left > 0 )
      {
        widget.Left = 0; 
        break;
      }
      widget.Left = widget.Left + speed;
    } }
    else          //上 
    {
    if(widget.Top ==0) return;
    //拉出 
    //widget.Left = tabWidth - widgetWidth;
    while(true)
    {
      if(widget.Top > 0 )
      {
        widget.Top = 0; 
        break;
      }
      widget.Top = widget.Top + speed;
    } 
    
    
    } 
  }
  else
  {
     if  (widget.Top <=0 )
     {
       if(widget.Top == tabHeight - widgetHeight) return;
    //缩进 
    //widget.Left = 0;
    while(true)
    {
      if(widget.Top <= tabHeight - widgetHeight)
      {
        widget.Top = tabHeight - widgetHeight;
        break;
      }
      widget.Top =  widget.Top - speed - 3 ;
    }
     } 
     else
     {   if (widget.Left <= 0) {
         
    if(widget.Left == tabWidth - widgetWidth) return;
    //缩进 
    //widget.Left = 0;
    while(true)
    {
      if(widget.Left <= tabWidth - widgetWidth)
      {
        widget.Left = tabWidth - widgetWidth;
        break;
      }
      widget.Left =  widget.Left - speed - 3 ;
    }
    } }
  }
}

function widgetOnDeActive()
{
  LockRefresh; 
  bgOnMouseMove();
  btAdd.alpha = 80;
  UnLockRefresh;
  
  if( GetSetting("autoHide")=="1" )
    showHideBar(false);  
}



function widgetOnStart()
{
if  (parseInt( GetSetting("startHide") )==1)
  showHideBar(false);
}

function txtCapOnMouseMove(sender)
{  if (widget.Left<=0 )
    {
   showHideBar(widget.Left < 0);
   }
   
}



function widgetOnEnter()
{
   if (widget.top<0)
    {
   showHideBar(widget.top < 0);
   }
}

function widgetOnClose()
{
    WriteIni("widgettop",widget.Top);
    WriteIni("widgetleft",widget.Left);
}



function nil(sender)
{
  
}                                                





function img0OnMouseUp(sender)
{ if (nMenu5.Checked==-1)
  {
   isdown=-1;
  } 
}





function img0OnMouseMove(sender)
{    var tag = sender.tag;
  
  
 if (nMenu5.Checked==-1)
  { 
   if (isdown==-1) return;
     LockRefresh;
   if (isdown==100)
    { 
    mouseX=widget.Left+sender.Left+iconWidth/2;
    mouseY=widget.Top+sender.Top+iconWidth/2;   
    moveX = mouseX;

    } 

    isdown =  (iPageIndex-1) * SinglePageCount + tag;
    sender.Left= mouseX - widget.Left-iconWidth/2;
    sender.Top= mouseY - widget.Top -iconWidth/2;
    hint.left = sender.Left + parseInt( (iconWidth-hint.width)/2 );
    hint.Top = sender.Top + iconWidth + 2; 
   UnLockRefresh;  
   if (sender.Left  <0)
   
    {
  
   if (iPageCount>1)
      {
       
      if  (iPageIndex == 1)
      {  
      isdown=1;
      img0OnMouseEnter(imgs[0]); 
      isdown=2;
      img0OnMouseEnter(imgs[1]);
      isdown=3;
      img0OnMouseEnter(imgs[2]);
      isdown=4;
      img0OnMouseEnter(imgs[3]);
      isdown=5;
      img0OnMouseEnter(imgs[4]);
      isdown=6;
      img0OnMouseEnter(imgs[5]);
      isdown=7;
      img0OnMouseEnter(imgs[6]);
      isdown=8;
      img0OnMouseEnter(imgs[7]);  
              
      showIcons(iPageCount);
   
    
      img0OnMouseEnter(imgs[thisCount-1]); 
     } 
     else
     {
      showIcons(iPageIndex - 1);
      img0OnMouseEnter(imgs[thisCount-1]); 
     }
      }
    
    }
    else  if ( (moveX-mouseX)>iconWidth+splitWidth && isleft<2 )
       {     Print( "左或居中时，左移");                
     moveX = mouseX;
       if (tag>0)
       {
     img0OnMouseEnter(imgs[tag-1]);
       if (isdown!=0) isdown--;
        }
      }
     else if   ( (mouseX-moveX)>iconWidth+splitWidth && isleft==2 )
      {
       Print( "右对齐，右移 "+tag);                
     moveX = mouseX;
    
       if (tag>0)
       {
     imgs[tag].Left= imgs[tag-1].Left - iconWidth - splitWidth;
     img0OnMouseEnter(imgs[tag-1]);
       if (isdown!=0) isdown--;
        }
     
      }
   }
}

function widgetOnClick()
{
  isdown=-1;
}





function nMenu5OnClick()
{ 
  if (nMenu5.Checked==-1)
  { 
     nMenu5.Checked=0;
     nMenu6.enabled=0;
   }  
   else
    { 
    nMenu5.Checked=1;
    nMenu6.enabled=1;
   }
}

function nMenu6OnClick()
{
   if (nMenu6.Checked==-1)
     nMenu6.Checked=0
     else
     nMenu6.Checked=1;
}

function widgetOnDBClick()
{
  if (themeList.length==7)
  {alert( "己有七个分类，不能再增加！");}
  else
  {  creatNewTheme();
  }
}



function button0OnMouseDown(sender)
{    if(!sender.Visible) return;
  if(!sender.cursorHandPoint) return;
  
  if (nMenu5.Checked==-1)
    {   
 var str =  sender.Name;
  var tag = parseInt( str.substring(str.length-1,str.length)); 
   Print("btnMoveIndex6:"+btnMoveIndex ); 
     btnsOnClick(sender);
     btnMoveIndex=tag;
    }
}
function button0OnMouseUp(sender)
{
   if (nMenu5.Checked==-1)
  {
   btnMoveIndex=-1;
  } 
}

function button0OnMouseEnter(sender)
{    if(!sender.Visible) return;
  if(!sender.cursorHandPoint) return;
     
 if (nMenu5.Checked==-1 )
   {
  
  
    var str =  sender.Name;
   var tag = parseInt( str.substring(str.length-1,str.length)); 
 
    if(tag == btnMoveIndex ) return;
    if ( btnMoveIndex==-1) return;
    
      LockRefresh;
       
     var btnCaption = btns[tag].Caption ;
    btns[tag].Caption  = btns[btnMoveIndex].Caption ;
    btns[btnMoveIndex].Caption =btnCaption; 
    XchangeTheme(tag,btnMoveIndex);
      if ( tag > btnMoveIndex )
     {
     var btnleft = btns[tag].Left ;
     
       if ( btnMoveIndex==0)
       btns[btnMoveIndex].Left=icon0left1
       else
       btns[btnMoveIndex].Left =  btns[btnMoveIndex-1].Left + 50 ; 
     }
    else if (tag < btnMoveIndex )
    {
      var btnleft = btns[tag].Left ;
    
      btns[btnMoveIndex].Left =btnleft + 50 ; 
    }
   
    btns[btnMoveIndex].Top=0;
    UnLockRefresh;
    btnMoveIndex = tag;
    return;                         
   } 
  if( mouseonchange == 1 )
      btnsOnClick(sender);
}

function widgetOnMouseMove()
{
   if (nMenu5.Checked==-1)
    { 
   if (btnMoveIndex==-1) return;
   Print("btnMoveIndex8:"+btnMoveIndex );
     LockRefresh;
    btns[btnMoveIndex].Left = mouseX - widget.Left - 25;
    btns[btnMoveIndex].Top = mouseY - widget.Top -10;
    UnLockRefresh; 
      }
}