var isFlyouting=false;  //是否正在弹出详细界面 
var isMiniState = false; //是否是最小化状态 
var rss;       //解析rss xml的dom对象 
var rssurl = "http://news.baidu.com/n?cmd=4&class=internet&tn=rss";
var defaulturl = "http://news.baidu.com/n?cmd=4&class=internet&tn=rss";  
var xmlfile = 'lastRss.xml';             
var rsslistfile = "UserSave\\Rsslist.ini";

var iPageIndex=1;  
var SinglePageCount=5; //但也rss条目数量 
var iPageCount;

//将rss条目显示出来 
function showRssItems(aPageIndex)
{
  //Print(aPageIndex );
  if(rss==null)
  {
    Print( "读取RSS失败" );
    return;
  } 
  
  try
  {
    var elist = rss.getElementsByTagName('item');
    if(elist.length < 1)
      return;
  }
  catch(e)
  {
    return;
  }
  
  LockRefresh;
  
  clearRssText() ;
  
  iPageIndex =aPageIndex;
  pagetext.fontStr = "clWhite/-17/Arial/13/0000";
  var baseIndex= (aPageIndex-1) * SinglePageCount;
  pagetext.caption = (baseIndex + 1) + "-" + (baseIndex + SinglePageCount);  
  
  var rssctl = new Array(5);
  var rssAuthctl = new Array(5);
  var rssDtctl = new Array(5);
  rssctl[0] = rss1;
  rssctl[1] = rss2;
  rssctl[2] = rss3;
  rssctl[3] = rss4;
  rssctl[4] = rss5;
  
  rssAuthctl[0] = rssAuth1;
  rssAuthctl[1] = rssAuth2;
  rssAuthctl[2] = rssAuth3;
  rssAuthctl[3] = rssAuth4;
  rssAuthctl[4] = rssAuth5;
  
  rssDtctl[0] = rssDt1;
  rssDtctl[1] = rssDt2;
  rssDtctl[2] = rssDt3;
  rssDtctl[3] = rssDt4;
  rssDtctl[4] = rssDt5;
  
  var index;
  for(var i=baseIndex;i<baseIndex+SinglePageCount;i++)
  {
    index = i % SinglePageCount;
    try 
    {
      rssctl[index].caption = elist[i].selectSingleNode('title').text;
      rssctl[index].tooltip = elist[i].selectSingleNode('title').text;
    }
    catch(exception){}    

    try 
    {
      rssAuthctl[index].caption = elist[i].selectSingleNode('author').text;
      //rssAuthctl[index].tooltip = elist[i].selectSingleNode('author').text;
    }
    catch(exception)
    {
      rssAuthctl[index].caption = '';
    }
    
    try
    {
      rssDtctl[index].caption = GetTimeDiff(elist[i].selectSingleNode('pubDate').text);
      //rssDtctl[index].tooltip = GetTimeDiff(elist[i].selectSingleNode('pubDate').text);
    }
    catch(exception)
    {
      rssAuthctl[index].caption = '';
    }
  
    rssctl[index].tag = i;
  }
  

  UnLockRefresh;

//  Print( elist.length  );  

}


//刷新RSS信息 
function RefreshRSS()
{
  LockRefresh;
  pagetext.fontStr = "clWhite/-15/黑体/11/1000";
  pagetext.caption = '刷新...'
  UnLockRefresh;

  var rsItem = GetSettingExt("rssurl","itemValue");
  if(rsItem=="")
    xmlfile = 'lastRss.xml'
  else 
    xmlfile = rsItem + '.xml' ;

  //StartGetUrlXML( rssurl );
  DownLoadFileAsync( rssurl , xmlfile ,"onDownFile" ); 

  //StartGetUrlHtmlString( rssurl );
}

function  onDownFile(fileName,errorCode)
{
  LockRefresh; 
  pagetext.fontStr = "clWhite/-17/Arial/13/0000";
  pagetext.caption = "--";
  UnLockRefresh;
  
  if(errorCode<1)
  {
    //down failed
    copyFile( widgetPath + "lastRSS.xml" , fileName );
    pagetext.caption = "--";
  }
  else
  {
    copyFile( fileName , widgetPath + "lastRSS.xml");
  }


  rss.load(fileName);
  showRssItems(1);
}

//获取RSS的xml 
function StartGetUrlXML(url)
{
  rss.onreadystatechange = function() 
  {
    //Print( rss.readyState );
    //判断请求返回的状态
    if (rss.readyState == 4)
    { 
      var err = rss.parseError; 
      if (err.errorCode != 0) 
      {
        //showTrayHint( "Vista RSS小工具" , "连接服务器出错: " + err.reason );
        pagetext.fontStr = "clWhite/-17/Arial/13/0000";
        pagetext.caption = "";  
        //clearRssText() ;
      } 
      else 
      { 
         //alert(rss.xml) 
         showRssItems(iPageIndex);
      } 
    }
     
  }
   
  //rss.resolveExternals = false; 
  rss.load(url);
   

}

/******************************************************************************* 
Object CreateXMLParser(void) 
创建尽可能高版本的XMLDOM解析器 
********************************************************************************/ 
function CreateXMLParser() 
{ 
  try{ 
    return new ActiveXObject('MSXML2.DOMDocument.4.0'); 
  }catch(e){ 
  try{ 
    return new ActiveXObject('MSXML2.DOMDocument.3.0'); 
  }catch(e){ 
    try{ 
      return new ActiveXObject('MSXML2.DOMDocument.2.6'); 
  }catch(e){ 
  try{ 
    return new ActiveXObject('MSXML2.DOMDocument'); 
  }catch(e){ 
    try{ 
      return new ActiveXObject('Microsoft.XMLDOM'); 
  }catch(e){ 
  return null; 
  } 
  } 
  } 
  } 
  } 
} 



function widgetOnDock()
{
  HideFlyout();
   
  LockRefresh;
  
  btAdd.left = 315;
  btAdd.top = 155;
  
  //flyoutBgRight.Src = "images\/flyoutBgRightDocked.png" ;
  rssBg.Src = "images\/rssBackBlue_docked.png" ; 
  rssBg.top = 8; 
  
  btRefresh.Left = 423;
  btRefresh.top = 162;
  

  hotbg.Left = 311;
  hotbg.Height = 29;
  hotbg.Width = 124;
  hotbg.Src = "images\/rss_headline_glow_docked.png" ; 


  line.Src = "images\/line_dock.png" ; 
  line.left = 312;
  line.top = 12;

  widgetWidth = 444;
  
  if(!isFlyouting)
    widgetHeight = 180
  else
    widgetHeight = 240;

  
  
  navBg.left = 333;
  navBg.top = 153;

  btUp.left = 336;
  btUp.top = 155;

  btDown.left = 392;
  btDown.top = 155;
  
  pagetext.left = 338;
  pagetext.top = 155;
  
  //rss条目文字字体///////////////////
  rss1.fontSize = 13;
  rss2.fontSize = 13;
  rss3.fontSize = 13;
  rss4.fontSize = 13;
  rss5.fontSize = 13;
     
  rssAuth1.fontSize = 10;
  rssAuth2.fontSize = 10;
  rssAuth3.fontSize = 10;
  rssAuth4.fontSize = 10;
  rssAuth5.fontSize = 10;

  rssDt1.fontSize = 10;
  rssDt2.fontSize = 10;
  rssDt3.fontSize = 10;
  rssDt4.fontSize = 10;
  rssDt5.fontSize = 10;
  
  //rss条目文字坐标///////////////////
  rss1.Left = 312;
  rss2.Left = 312;
  rss3.Left = 312;
  rss4.Left = 312;
  rss5.Left = 312;
  rssAuth1.left = 312;
  rssAuth2.left = 312;
  rssAuth3.left = 312;
  rssAuth4.left = 312;
  rssAuth5.left = 312;
  rssDt1.Left = 371;
  rssDt2.Left = 371;
  rssDt3.Left = 371;
  rssDt4.Left = 371;
  rssDt5.Left = 371;

  rss1.top = 13;
  rss2.top = 40;
  rss3.top = 67;
  rss4.top = 94;
  rss5.top = 121;
  rssAuth1.top = 28;
  rssAuth2.top = 55;
  rssAuth3.top = 82;
  rssAuth4.top = 109;
  rssAuth5.top = 136;
  rssDt1.top = 27
  rssDt2.top = 54;
  rssDt3.top = 81;
  rssDt4.top = 108;
  rssDt5.top = 135;
    
  //rss条目文字宽高///////////////////
  rss1.Width = 121;
  rss2.Width = 121;
  rss3.Width = 121;
  rss4.Width = 121;
  rss5.Width = 121;
  rssAuth1.Width = 70;
  rssAuth2.Width = 70;
  rssAuth3.Width = 70;
  rssAuth4.Width = 70;
  rssAuth5.Width = 70;
  rssDt1.Width = 60;
  rssDt2.Width = 60;
  rssDt3.Width = 60;
  rssDt4.Width = 60;
  rssDt5.Width = 60;

  rss1.Height = 15;
  rss2.Height = 15;
  rss3.Height = 15;
  rss4.Height = 15;
  rss5.Height = 15;
  rssAuth1.Height = 12;
  rssAuth2.Height = 12;
  rssAuth3.Height = 12;
  rssAuth4.Height = 12;
  rssAuth5.Height = 12;
  rssDt1.Height = 12;
  rssDt2.Height = 12;
  rssDt3.Height = 12;
  rssDt4.Height = 12;
  rssDt5.Height = 12;


  
  UnLockRefresh;

}

function widgetOnUnDock()
{
  HideFlyout();
  
 
  LockRefresh;
  
  btAdd.left = 325;
  btAdd.top = 194;
  
  //flyoutBgRight.Src = "images\/flyoutBgRight.png" ; 
  rssBg.Src = "images\/rssBackBlue_Undocked.png" ;
  rssBg.top = 1; 

  btRefresh.Left = 570;
  btRefresh.top = 199;

  hotbg.Left = 321;
  hotbg.Height = 34;
  hotbg.Width = 264;
  hotbg.Src = "images\/rss_headline_glow_floating.png" ; 



  line.Src = "images\/line.png" ; 
  line.left = 322;
  line.top = 13;

  widgetWidth = 608;
  widgetHeight = 240;

  
  
  navBg.left = 415;
  navBg.top = 190;

  btUp.left = 418;
  btUp.top = 192;

  btDown.left = 475;
  btDown.top = 192;
  
  pagetext.left = 420;
  pagetext.top = 192;

  //rss条目文字字体///////////////////
  rss1.fontSize = 15;
  rss2.fontSize = 15;
  rss3.fontSize = 15;
  rss4.fontSize = 15;
  rss5.fontSize = 15;

  rssAuth1.fontSize = 11;
  rssAuth2.fontSize = 11;
  rssAuth3.fontSize = 11;
  rssAuth4.fontSize = 11;
  rssAuth5.fontSize = 11;

  rssDt1.fontSize = 11;
  rssDt2.fontSize = 11;
  rssDt3.fontSize = 11;
  rssDt4.fontSize = 11;
  rssDt5.fontSize = 11;

  //rss条目文字坐标///////////////////
  rss1.Left = 323;
  rss2.Left = 323;
  rss3.Left = 323;
  rss4.Left = 323;
  rss5.Left = 323;
  rssAuth1.left = 323;
  rssAuth2.left = 323;
  rssAuth3.left = 323;
  rssAuth4.left = 323;
  rssAuth5.left = 323;
  rssDt1.Left = 457;
  rssDt2.Left = 457;
  rssDt3.Left = 457;
  rssDt4.Left = 457;
  rssDt5.Left = 457;

  rss1.top = 17;
  rss2.top = 52;
  rss3.top = 85;
  rss4.top = 120;
  rss5.top = 155;
  rssAuth1.top = 35;
  rssAuth2.top = 70;
  rssAuth3.top = 101;
  rssAuth4.top = 138;
  rssAuth5.top = 172;
  rssDt1.top = 35;
  rssDt2.top = 70;
  rssDt3.top = 101;
  rssDt4.top = 138;
  rssDt5.top = 172;

  //rss条目文字宽高///////////////////
  rss1.Width = 260;
  rss2.Width = 260;
  rss3.Width = 260;
  rss4.Width = 260;
  rss5.Width = 260;
  rssAuth1.Width = 140;
  rssAuth2.Width = 140;
  rssAuth3.Width = 140;
  rssAuth4.Width = 140;
  rssAuth5.Width = 140;
  rssDt1.Width = 125;
  rssDt2.Width = 125;
  rssDt3.Width = 125;
  rssDt4.Width = 125;
  rssDt5.Width = 125;  
     
  rss1.Height = 17;
  rss2.Height = 17;
  rss3.Height = 17;
  rss4.Height = 17;
  rss5.Height = 17;
  rssAuth1.Height = 14;
  rssAuth2.Height = 14;
  rssAuth3.Height = 14;
  rssAuth4.Height = 14;
  rssAuth5.Height = 14;
  rssDt1.Height = 14;
  rssDt2.Height = 14;
  rssDt3.Height = 14;
  rssDt4.Height = 14;
  rssDt5.Height = 14;      
      


  UnLockRefresh;

}

function ShowFlyout()
{
  if(isFlyouting)
    return;
    
  isFlyouting = true;
     
  LockRefresh;
  
  if(dockedOnSidebar||isMiniState)
    flyoutBgRight.Src = "images\/flyoutBgRightDocked.png" 
  else
    flyoutBgRight.Src = "images\/flyoutBgRight.png" ;

  flyoutBgLeft.Visible = true;
  flyoutBgRight.Visible = true;
  rssLink.Visible = true;

  widgetHeight = 240;

  UnLockRefresh;

  
}

function HideFlyout()
{
  if(!isFlyouting)
    return;
    
  isFlyouting = false;
  
  HtmlPanelVisible = false;   
  UnLockRefresh;
  
  flyoutBgLeft.Visible = false;
  flyoutBgRight.Visible = false;
  rssLink.Visible = false;
  
  if(dockedOnSidebar||isMiniState)
    widgetHeight = 180
  else
    widgetHeight = 240;



  UnLockRefresh;
  
}


function widgetOnDBClick()
{
  HideFlyout();
}

function widgetOnClose()
{
  rss = null;
}

function nMenu1OnClick()
{
  RefreshRSS();  
}

function clearRssText() 
{

  rss1.caption = "";
  rss2.caption = "";
  rss3.caption = "";
  rss4.caption = "";
  rss5.caption = "";

  rss1.tooltip = "";
  rss2.tooltip = "";
  rss3.tooltip = "";
  rss4.tooltip = "";
  rss5.tooltip = "";
  
  rssAuth1.caption = "";
  rssAuth2.caption = "";
  rssAuth3.caption = "";
  rssAuth4.caption = "";
  rssAuth5.caption = "";
  
  rssDt1.caption = "";
  rssDt2.caption = "";
  rssDt3.caption = "";
  rssDt4.caption = "";
  rssDt5.caption = "";

  rssDt1.tooltip = "";  
  rssDt2.tooltip = "";  
  rssDt3.tooltip = "";  
  rssDt4.tooltip = "";  
  rssDt5.tooltip = "";  

  rss1.tag = -1;
  rss2.tag = -1;
  rss3.tag = -1;
  rss4.tag = -1;
  rss5.tag = -1;
  

}

function widgetOnInit()
{
  rss = CreateXMLParser() ;//new ActiveXObject("Msxml2.DOMDocument"); 
  isMiniState  = parseInt( ReadIni("isMiniState") );
  if(isNan(isMiniState)) isMiniState = false;

  iPageIndex = 1;
  var url = GetSetting( "rssurl" );
  if(url!="")
    rssurl = url;
    
  xmlfile = ReadIni('rssurlitemValue') + '.xml' ;
  if(xmlfile=='.xml')
    xmlfile = 'lastRss.xml'; 

  try
  {
    if(fileExists( widgetPath + xmlfile ))
      rss.load( widgetPath + xmlfile )
    else
      rss.load( widgetPath + "lastRSS.xml");
  }
  catch(e)
  {
  }
  
  showRssItems(iPageIndex);  
    
    
}

function widgetOnStart()       
{
   
  RefreshRSS();
  //每30分钟更新一次 
  timer0.interval = GetSetting( "refreshtm" ) * 60 * 1000;
  timer0.enabled = true;
  
  //每分钟翻页一次 
  timer1.interval = GetSetting( 'autodownpage' ) * 60 * 1000;
  if(GetSetting( 'autodownpage' )<0)
    timer1.enabled = false
  else
    timer1.enabled = true;

  
}

function getRssPageCount()
{
  try
  {
    var length = rss.getElementsByTagName('item').length;
    var count =  length / SinglePageCount;
    if(length % SinglePageCount>0)
    count = count + 1;
    return  count;
  }
  catch(e)
  {
  }
}

function btDownOnClick()
{
  var index = iPageIndex+1;
  var count = getRssPageCount();
  if(index>count)
    index = 1;
  showRssItems(index);

}

function btUpOnClick()
{
  var index = iPageIndex-1;
  if(index<1)  index = getRssPageCount();
  showRssItems(index);

}

function GetTimeDiff(str) 
{ 
  if(str == '') 
  { 
    return ''; 
  } 
  
  var pubDate = new Date(str); 
  var nowDate = new Date(); 
  var diffMilSeconds = nowDate.valueOf()-pubDate.valueOf(); 
  var days = diffMilSeconds/86400000; 
  days = parseInt(days); 
  diffMilSeconds = diffMilSeconds-(days*86400000); 
  var hours = diffMilSeconds/3600000; 
  hours = parseInt(hours); 
  diffMilSeconds = diffMilSeconds-(hours*3600000); 
  var minutes = diffMilSeconds/60000; 
  minutes = parseInt(minutes); 
  diffMilSeconds = diffMilSeconds-(minutes*60000); 
  var seconds = diffMilSeconds/1000; 
  seconds = parseInt(seconds); 
  var returnStr = "" + pubDate.toLocaleString(); 
  if(days > 0) 
  { 
    returnStr = returnStr + "" + days + "天" + hours + "小时" + minutes + "分钟前(" + returnStr + ")"; 
  } 
  else if (hours > 0) 
  { 
    returnStr = hours + "小时" + minutes + "分钟前(" + returnStr + ")"; 
  } 
  else if (minutes > 0) 
  {
    returnStr = minutes + "分钟前(" + returnStr + ")"; 
  } 
  
  return returnStr; 
}

function OnAllSettingsSaved()
{
  var url = GetSetting( "rssurl" );
  if(url!="")
    rssurl = url;
    
  xmlfile = ReadIni('rssurlitemValue') + '.xml' ;
  if(xmlfile=='.xml')
    xmlfile = 'lastRss.xml'; 
    
  RefreshRSS();  
  
  //每30分钟更新一次 
  timer0.interval = parseInt( GetSetting( "refreshtm" ) ) * 60 * 1000;
  timer0.enabled = true;
  
  //每分钟翻页一次 
  timer1.interval = parseInt( GetSetting( 'autodownpage' ) ) * 60 * 1000;
  if(GetSetting( 'autodownpage' )<0)
    timer1.enabled = false
  else
    timer1.enabled = true;
      
}


function widgetOnDeActive()
{
  hotbg.Visible = false;
  HideFlyout();
  Refresh;
}

function rssLinkOnClick()
{
   OpenLink( rssLink.tooltip );
}

function rss1OnMouseDown()
{
  try
  {
    var cap = rss1.caption;
    var tag = rss1.tag;
    LockRefresh;
    
    hotbg.Top = rss1.Top;
    hotbg.Visible = true;
      
    rssLink.caption = cap;
    rssLink.tooltip = rss.getElementsByTagName('item')[tag].selectSingleNode('link').text;
    var des = '<html><body style="font-family: 微软雅黑,宋体,Arial; font-size: 10pt">';
    
    des = des +  rss.getElementsByTagName('item')[tag].selectSingleNode('description').text;

    des = des + '<br> '+   '<div align=right> <a  href="' +  rssLink.tooltip + '"  target="_blank">' +'   <strong>[阅读全文]</strong></right>  </a></div>'; 
    
    des = des + "</body></html>";
  
    UnLockRefresh;
    
    ShowFlyout();

    HtmlPanelVisible = true;
    try
    {
      HtmlPanelHtmlSrc = des;
    }
    catch(e){}  

  }
  catch(e)
  {
    UnLockRefresh;
  }  

  
}

function rss2OnMouseDown()
{
  try{
    var cap = rss2.caption;
    var tag = rss2.tag;
    LockRefresh;
  
    hotbg.Top = rss2.Top;
    hotbg.Visible = true;
    
    rssLink.caption = cap;
    rssLink.tooltip = rss.getElementsByTagName('item')[tag].selectSingleNode('link').text;
    var des = '<html><body style="font-family: 微软雅黑,宋体,Arial; font-size: 10pt">';
    
    des = des +  rss.getElementsByTagName('item')[tag].selectSingleNode('description').text;
    
    des = des + '<br> '+   '<div align=right> <a  href="' +  rssLink.tooltip + '"  target="_blank">' +'   <strong>[阅读全文]</strong></right>  </a></div>'; 
    des = des + "</body></html>";
  
    UnLockRefresh;
    
    ShowFlyout();
  
    
    HtmlPanelVisible = true;
    HtmlPanelVisible = true;
    try
    {
      HtmlPanelHtmlSrc = des;
    }
    catch(e){}  
    Refresh;
  }
  catch(e)
  {
    UnLockRefresh;

  }    
  
}

function rss3OnMouseDown()
{
  try{
    var cap = rss3.caption;
    var tag = rss3.tag;
    LockRefresh;
    hotbg.Top = rss3.Top;
    hotbg.Visible = true;
    
    rssLink.caption = cap;
    rssLink.tooltip = rss.getElementsByTagName('item')[tag].selectSingleNode('link').text;
    var des = '<html><body style="font-family: 微软雅黑,宋体,Arial; font-size: 10pt">';
    
    des = des +  rss.getElementsByTagName('item')[tag].selectSingleNode('description').text;
    
    des = des + '<br> '+   '<div align=right> <a  href="' +  rssLink.tooltip + '"  target="_blank">' +'   <strong>[阅读全文]</strong></right>  </a></div>'; 
    des = des + "</body></html>";
  
    UnLockRefresh;
    
    ShowFlyout();
    
    HtmlPanelVisible = true;
    HtmlPanelVisible = true;
    try
    {
      HtmlPanelHtmlSrc = des;
    }
    catch(e){}  
    
    Refresh;
  }
  catch(e)
  {
    UnLockRefresh;

  }    
}

function rss4OnMouseDown()
{
  try{
    var cap = rss4.caption;
    var tag = rss4.tag;
    LockRefresh;
    hotbg.Top = rss4.Top;
    hotbg.Visible = true;
    
    rssLink.caption = cap;
    rssLink.tooltip = rss.getElementsByTagName('item')[tag].selectSingleNode('link').text;
    var des = '<html><body style="font-family: 微软雅黑,宋体,Arial; font-size: 10pt">';
    
    des = des +  rss.getElementsByTagName('item')[tag].selectSingleNode('description').text;
    
    des = des + '<br> '+   '<div align=right> <a  href="' +  rssLink.tooltip + '"  target="_blank">' +'   <strong>[阅读全文]</strong></right>  </a></div>'; 
    des = des + "</body></html>";
  
    UnLockRefresh;
    
    ShowFlyout();
    
    HtmlPanelVisible = true;
    HtmlPanelVisible = true;
    try
    {
      HtmlPanelHtmlSrc = des;
    }
    catch(e){}  
    Refresh;
  }
  catch(e)
  {
    UnLockRefresh;

  }    
  
}

function rss5OnMouseDown()
{
  try{
    var cap = rss5.caption;
    var tag = rss5.tag;
    LockRefresh;
    hotbg.Top = rss5.Top;
    hotbg.Visible = true;
    
    rssLink.caption = cap;
    rssLink.tooltip = rss.getElementsByTagName('item')[tag].selectSingleNode('link').text;
    var des = '<html><body style="font-family: 微软雅黑,宋体,Arial; font-size: 10pt">';
    
    des = des +  rss.getElementsByTagName('item')[tag].selectSingleNode('description').text;
    
    des = des + '<br> '+   '<div align=right> <a  href="' +  rssLink.tooltip + '"  target="_blank">' +'   <strong>[阅读全文]</strong></right>  </a></div>'; 
    des = des + "</body></html>";
  
    UnLockRefresh;
    
    ShowFlyout();
    
    HtmlPanelVisible = true;
    HtmlPanelVisible = true;
    try
    {
      HtmlPanelHtmlSrc = des;
    }
    catch(e){}  
    
    Refresh;
  }
  catch(e)
  {
    UnLockRefresh;

  }    
}

function checkDock()
{
  if(dockedOnSidebar)
  {
     widgetOnDock();
  }
  else
  {
    if(!isMiniState)
      widgetOnUnDock()
    else
      widgetOnDock();
  }  
}

function nMenu3OnClick()
{
  isMiniState = !isMiniState;
  checkDock();
  WriteIni("isMiniState",isMiniState);  
}

function widgetOnPopupMenu()
{
  nMenu3.Visible = !dockedOnSidebar;
  if(!dockedOnSidebar)
  {
    if(isMiniState)
      nMenu3.caption = "切换到详细模式"
    else 
      nMenu3.caption = "切换到迷你模式";
  }
  
  //////////////////// 
  nMenu2.clear;
  var pnt = nMenu2;  
  custPopMenu.addMenuItemChild(pnt,"新增...","rssMenuClick",0);
  custPopMenu.addMenuItemChild(pnt,"编辑...","rssMenuClick",1);
  custPopMenu.addMenuItemChild(pnt,"删除","rssMenuClick",2);

  custPopMenu.addMenuItemChild(pnt,"-","",-999);
  
  var sl = (ReadIniSec( xdeskshowPath +  rsslistfile)).split("||"); ;
  var tp = getSettingExt("rssurl","typeValue");
  var it = getSettingExt("rssurl","itemValue");
  for(var i=0;i<sl.length;i++)
  {
    var pnt2 = custPopMenu.addMenuItemChild(pnt,sl[i],"",-999);
    pnt2.tagStr = sl[i];
    if(tp==sl[i]) 
      pnt2.Checked = true;
    
    var item = ( ReadIniSecItem( xdeskshowPath +  rsslistfile , sl[i] ) ).split("||");
    for(var k=0;k<item.length;k++)
    {
      var rs = custPopMenu.addMenuItemChild(pnt2,item[k],"rssMenuClick",5);
      rs.tagStr = sl[i]+"--->"+item[k];
      if( (tp==sl[i]) &&(it==item[k]) )
        rs.Checked = true;
    }
                
  }
}


function rssMenuClick(sender)
{
  var tag = sender.tag; 
  switch (tag)
  {
    case 0:
      //新增 
      var sl = edtIniItem( xdeskshowPath +  rsslistfile ,"新建RSS项","RSS分类","RSS名称","RSS地址","","","");


      if( sl=="" ) return;
      Print( sl );
      sl = sl.split("\r\n");
      var rsSec = sl[0];
      var rsItem = sl[1];
      var rsUrl = sl[2]; 

      if((rsSec=="")||(rsItem=="")||(rsUrl=="")) return;

      rssurl = rsUrl;

      SetSetting( "rssurl",rssurl );
      SetSettingExt("rssurl","typeValue",rsSec);
      SetSettingExt("rssurl","itemValue",rsItem);
      
      SaveSetting( "rssurl" );
        
      xmlfile = rsItem + '.xml' ;
      RefreshRSS();  
      
      break;
    case 1:
      //编辑
      var sl = edtIniItem( xdeskshowPath +  rsslistfile ,"编辑RSS项","RSS分类","RSS名称","RSS地址", GetSettingExt("rssurl","typeValue") ,GetSettingExt("rssurl","itemValue"), GetSetting("rssurl") ); 
      if( sl=="" ) return;
      Print( sl );
      sl = sl.split("\r\n");
      var rsSec = sl[0];
      var rsItem = sl[1];
      var rsUrl = sl[2]; 

      if((rsSec=="")||(rsItem=="")||(rsUrl=="")) return;

      rssurl = rsUrl;

      SetSetting( "rssurl",rssurl );
      SetSettingExt("rssurl","typeValue",rsSec);
      SetSettingExt("rssurl","itemValue",rsItem);
      
      SaveSetting( "rssurl" );
        
      xmlfile = rsItem + '.xml' ;
      RefreshRSS();  


      break;
    case 2:
      //删除
      if( !widget.confirm('确认要删除RSS"'+ GetSettingExt("rssurl","itemValue") +'" ?') ) return;    
      WriteIniEx( xdeskshowPath +  rsslistfile ,  GetSettingExt("rssurl","typeValue") ,GetSettingExt("rssurl","itemValue"),"" );
      
      rssurl = defaulturl;
      var rsSec = ""; 
      var rsItem = ""; 

      SetSetting( "rssurl",rssurl );
      SetSettingExt("rssurl","typeValue",rsSec);
      SetSettingExt("rssurl","itemValue",rsItem);
      
      SaveSetting( "rssurl" );
      
      xmlfile = 'lastRss.xml'; 
        
      RefreshRSS();        
      
      
      break;

    case 5:
      //rss地址
      var sl = (sender.tagStr).split("--->");
      if(sl.length!=2) return
      
      var rsSec = sl[0];
      var rsItem = sl[1];
      
      if((rsSec=="")||(rsItem=="")) return;
      
      var rsUrl = ReadIniEx( xdeskshowPath +  rsslistfile , rsSec , rsItem );
      if(rsUrl=="") return;
      
      if( rsUrl.substr(0,4).toLowerCase() != "http" ) return ;
      
      print( rsUrl );
      rssurl = rsUrl;
      
      SetSetting( "rssurl",rssurl );
      SetSettingExt("rssurl","typeValue",rsSec);
      SetSettingExt("rssurl","itemValue",rsItem);
      
      SaveSetting( "rssurl" );
      
        
      xmlfile = rsItem + '.xml' ;
      RefreshRSS();  
      
      
      
      break;

    default:

    
      
  }



}

function btAddOnClick(sender)
{
  custPopMenu.clear;
  custPopMenu.addMenuItem("新增...","rssMenuClick",0);
  custPopMenu.addMenuItem("编辑...","rssMenuClick",1);
  custPopMenu.addMenuItem("删除","rssMenuClick",2);

  custPopMenu.addMenuItem("-","",-999);
  
  var sl = (ReadIniSec( xdeskshowPath +  rsslistfile)).split("||"); ;
  var tp = getSettingExt("rssurl","typeValue");
  var it = getSettingExt("rssurl","itemValue");
  for(var i=0;i<sl.length;i++)
  {
    var pnt2 = custPopMenu.addMenuItem(sl[i],"",-999);
    pnt2.tagStr = sl[i];
    if(tp==sl[i]) 
      pnt2.Checked = true;
    
    var item = ( ReadIniSecItem( xdeskshowPath +  rsslistfile , sl[i] ) ).split("||");
    for(var k=0;k<item.length;k++)
    {
      var rs = custPopMenu.addMenuItemChild(pnt2,item[k],"rssMenuClick",5);
      rs.tagStr = sl[i]+"--->"+item[k];
      if( (tp==sl[i]) &&(it==item[k]) )
        rs.Checked = true;
    }
                
  } 
  custPopMenu.popup; 
}