home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 June / CHIP_CD_2004-06.iso / bonus / buhgal / files / M12USWEB.exe / RCDATA / CABINET / money.cab / msmoney.chm / jsonstart.js < prev    next >
Text File  |  2003-06-18  |  10KB  |  392 lines

  1. /*
  2.  
  3. Microsoft Money
  4. Copyright (c) 2001 Microsoft Corporation
  5. All rights reserved
  6.  
  7. File     : jsOnstart.js
  8. Modified : Dec 19 2001
  9. *********************************************************************/
  10.  
  11. var mhTpc = new Object();
  12. var mhThmbnl;
  13.  
  14. //********************************************************************
  15. function DataObject(
  16.     fValidate,
  17.     fResolve,
  18.     fPreserve,
  19.     bolAsync,
  20.     pListener)
  21. {
  22.     this.XMLDOM                    = new ActiveXObject("Microsoft.XMLDOM");
  23.     this.XMLDOM.validateOnParse    = fValidate;
  24.     this.XMLDOM.resolveExternals   = fResolve;
  25.     this.XMLDOM.preserveWhiteSpace = fPreserve;
  26.     this.XMLDOM.async              = bolAsync;
  27.     if(null != pListener) this.XMLDOM.onreadystatechange = pListener;
  28.     this.loadData = function()
  29.     {
  30.         this.XMLDOM.load(this.dataSource);
  31.     }
  32. }
  33. //********************************************************************
  34. function Main()
  35. {
  36.     mhTpc["MoneyData"]  = new DataObject(false,false,false,true,null);
  37.     mhTpc["Locale"]     = new DataObject(false,false,false,true,FetchProductSku);
  38.     mhTpc["ProductSku"] = new DataObject(false,false,false,true,FetchIncludes);
  39.     mhTpc["StyleRules"] = new Array("enabled","disabled");
  40.     
  41.     var szSku     = "hhsku.xml";
  42.     var szRsrc    = "msmoney.xml";
  43.     var szPrefs   = "hhprefs.xml";
  44.     var szDfltSku = "hhstd";
  45.     var szLocale  = "hhusa";
  46.     
  47.     mhTpc["MoneyData"].dataSource    = GetFilePath(szRsrc);
  48.     mhTpc["Locale"].dataSource       = GetFilePath(szPrefs);
  49.     mhTpc["Locale"].defaultValue     = szLocale;
  50.     mhTpc["ProductSku"].defaultValue = szDfltSku;
  51.     mhTpc["ProductSku"].dataSource   = GetFilePath(szSku);
  52.     mhTpc["ProductSku"].legalValues  = new Array("std","dlx","biz","stddlx","dlxbiz","core");
  53.     mhTpc["Includes"]                = new Array();
  54.     
  55.     mhTpc["MoneyData"].loadData();
  56. }
  57. //********************************************************************
  58. function FetchProductSku()
  59. {
  60.     if(4 == mhTpc["Locale"].XMLDOM.readyState)
  61.     {
  62.         mhTpc["Locale"].value = (0 == mhTpc["Locale"].XMLDOM.parseError)
  63.             ?
  64.             mhTpc["Locale"].XMLDOM.documentElement.selectSingleNode("country").text.toLowerCase()
  65.             :
  66.             mhTpc["Locale"].defaultValue
  67.             ;
  68.         mhTpc["ProductSku"].loadData();
  69.     }
  70. }
  71. //********************************************************************
  72. function FetchIncludes()
  73. {
  74.     if(4 == mhTpc["ProductSku"].XMLDOM.readyState)
  75.     {
  76.         mhTpc["ProductSku"].value = FetchTopicSku();
  77.         var iStyle = SelectStyleSheet(); // dependent on product SKU
  78.         mhTpc["StyleRules"].styleType = mhTpc["StyleRules"][iStyle];
  79.         
  80.         if(LoadIncludes())
  81.         {
  82.             var cbCnt = 0;
  83.             mhTpc["Includes"].stackSize = mhTpc["Includes"].length;
  84.             for(;cbCnt < mhTpc["Includes"].stackSize;)
  85.             {
  86.                 mhTpc["Includes"][cbCnt].loadData();
  87.                 cbCnt++
  88.             }
  89.         }
  90.         else
  91.         {
  92.             FinishTransformations();
  93.         }
  94.     }
  95. }
  96. //********************************************************************
  97. function FetchTopicSku()
  98. {
  99.     var szRtrn = mhTpc["ProductSku"].defaultValue;
  100.     if(0 == mhTpc["ProductSku"].XMLDOM.parseError)
  101.     {
  102.         try
  103.         {
  104.             szRtrn = mhTpc["ProductSku"].XMLDOM.documentElement.selectSingleNode("type").text.toLowerCase();
  105.         }
  106.         catch(e)
  107.         {
  108.             szRtrn = mhTpc["ProductSku"].defaultValue;
  109.         }
  110.     }
  111.     return szRtrn;
  112. }
  113. //********************************************************************
  114. function SelectStyleSheet()
  115. {
  116.     if("object" == typeof document.XMLDocument)
  117.     {
  118.         var bRtrn;
  119.         var szDsply;
  120.         var rxSku     = new RegExp();
  121.         var cbCnt     = 0;
  122.         var kbIsEnbld = 0;
  123.         var kbIsDsbld = 1;
  124.         var hStyle    = document.createStyleSheet("csOnstart.css");
  125.         var szSku     = document.XMLDocument.documentElement.getAttribute("sku").toLowerCase();
  126.         
  127.         switch(mhTpc["ProductSku"].value)
  128.         {
  129.             case "hhstd" :
  130.             rxSku = /^(?:std(dlx)?)$/
  131.             break;
  132.                 
  133.             case "hhdlx" :
  134.             rxSku = /^(?:(std)?(dlx)(biz)?)$/
  135.             break;
  136.                 
  137.             case "hhbiz" :
  138.             rxSku = /^(?:(dlx)?biz)$/
  139.             break;
  140.         }
  141.         if("core" == szSku)
  142.         {
  143.             bRtrn = kbIsEnbld;
  144.         }
  145.         else
  146.         { 
  147.             bRtrn = (rxSku.test(szSku))
  148.                 ?
  149.                 kbIsEnbld
  150.                 :
  151.                 kbIsDsbld
  152.                 ;
  153.         }
  154.         for(;cbCnt < mhTpc["ProductSku"].legalValues.length;)
  155.         {
  156.             szDsply = (rxSku.test(mhTpc["ProductSku"].legalValues[cbCnt]))
  157.                 ?
  158.                 "inline" 
  159.                 :
  160.                 "none"
  161.                 ;
  162.             hStyle.addRule(".Frgmnt__" + mhTpc["ProductSku"].legalValues[cbCnt],
  163.                 "display:" + szDsply);
  164.             cbCnt++;
  165.         }
  166.         hStyle.rules[1].style.color = (kbIsEnbld == bRtrn) ? "#000000" : "#93948e";
  167.         
  168.         return bRtrn;
  169.     }
  170. }
  171. //********************************************************************
  172. function LoadIncludes()
  173. {
  174.     var fRtrn = false;
  175.     if("object" == typeof document.XMLDocument)
  176.     {
  177.         mhTpc["Clone"] = document.XMLDocument.cloneNode(true);
  178.         var iLkup;
  179.         var hIncld;
  180.         var szHref;
  181.         var bInPrcss   = 0;
  182.         var szTkn      = "#xpointer(";
  183.         var rghInclude = mhTpc["Clone"].selectNodes("//include");
  184.         if(rghInclude.length > 0)
  185.         {
  186.             hIncld = rghInclude.nextNode();
  187.             while(hIncld)
  188.             {
  189.                 szHref = hIncld.getAttribute("href");
  190.                 if(szHref)
  191.                 {
  192.                     mhTpc["Includes"][bInPrcss] = new DataObject(false,false,false,true,HandleIncludes);
  193.                     mhTpc["Includes"][bInPrcss].designTimeNode = hIncld;
  194.                     iLkup = szHref.lastIndexOf(szTkn);
  195.                     mhTpc["Includes"][bInPrcss].queryPath = (iLkup > 0)
  196.                         ?
  197.                         szHref.substr(iLkup + szTkn.length,szHref.length - iLkup - szTkn.length - 1)
  198.                         :
  199.                         null
  200.                         ;
  201.                     if(iLkup > 0) 
  202.                     {
  203.                         szHref = szHref.substr(0,iLkup);
  204.                     }
  205.                     mhTpc["Includes"][bInPrcss].dataSource = szHref;
  206.                     bInPrcss++;
  207.                 }    
  208.                 hIncld = rghInclude.nextNode();
  209.             }
  210.             fRtrn = (mhTpc["Includes"].length > 0);
  211.         }
  212.     }
  213.     return fRtrn;
  214. }
  215. //********************************************************************
  216. function HandleIncludes()
  217. {
  218.     var cbCnt = 0;
  219.     var cbRdy = 0;
  220.     for(;cbCnt < mhTpc["Includes"].length;)
  221.     {
  222.         if((mhTpc["Includes"][cbCnt] != null)
  223.             && (mhTpc["Includes"][cbCnt].XMLDOM.readyState == 4))
  224.         {
  225.             if(mhTpc["Includes"][cbCnt].XMLDOM.parseError != 0)
  226.             {
  227.                 mhTpc["Includes"].stackSize -= 1;
  228.                 mhTpc["Includes"][cbCnt] = null;
  229.             }
  230.             else if(mhTpc["Includes"][cbCnt].XMLDOM.url != "")
  231.             {
  232.                 cbRdy++;
  233.             }
  234.         }
  235.         cbCnt++;
  236.     }
  237.     if(cbRdy == mhTpc["Includes"].stackSize)
  238.     {
  239.         cbCnt = 0;
  240.         for(;cbCnt < mhTpc["Includes"].length;)
  241.         {
  242.             if((null != mhTpc["Includes"][cbCnt]) 
  243.                 && (0 == mhTpc["Includes"][cbCnt].XMLDOM.parseError))
  244.             {
  245.                 TransformIncludes(cbCnt);
  246.             }
  247.             else
  248.             {
  249.                 //alert("This help topic is still partially\nunder construction, and may have\nproblems displaying properly.");
  250.             }
  251.             cbCnt++;                                                                                  
  252.         }
  253.         FinishTransformations();    
  254.     }
  255. }
  256. //********************************************************************
  257. function TransformIncludes(iLkup)
  258. {
  259.     var hNw;
  260.     var hDom   = mhTpc["Includes"][iLkup].XMLDOM;
  261.     var szQry  = mhTpc["Includes"][iLkup].queryPath;
  262.     var hIncld = mhTpc["Includes"][iLkup].designTimeNode;
  263.     var bErr   = hDom.parseError;
  264.     if(0 == bErr)
  265.     {
  266.         hNw = hDom.createDocumentFragment();
  267.         if(szQry != null)
  268.         {
  269.             var rghQry = hDom.selectNodes(szQry);
  270.             var hNxt   = rghQry.nextNode();
  271.             while(hNxt)
  272.             {
  273.                 hNxt.setAttribute("href",GetFileName(hDom.url));
  274.                 if(hNxt.text.length < 1)
  275.                 {
  276.                     hNxt.setAttribute("type","uarvw");
  277.                 }
  278.                 hNw.appendChild(hNxt);
  279.                 hNxt = rghQry.nextNode();
  280.             }
  281.         }
  282.     }
  283.     hIncld.parentNode.replaceChild(hNw,hIncld);
  284. }
  285. //********************************************************************
  286. function FinishTransformations()
  287. {
  288.     try
  289.     {
  290.         mhTpc["Clone"].documentElement.selectSingleNode("content").setAttribute("styleType",mhTpc["StyleRules"].styleType);
  291.     
  292.         if(mhTpc["Locale"].value == "hhcdn")
  293.         {
  294.             mhTpc["Clone"].documentElement.selectSingleNode("content").setAttribute("preference","cdn");
  295.         }
  296.         if(mhTpc["Clone"].documentElement.selectNodes("//thumbnail").length > 0)
  297.         {
  298.             mhThmbnl = window.createPopup();
  299.         }
  300.         document.body.innerHTML = mhTpc["Clone"].transformNode(Transformation);
  301.         ReadUpdateList();
  302.         ResetHeaderHtml();
  303.         window.onresize = function()
  304.         {
  305.             ResetHeaderHtml();
  306.         }
  307.     }
  308.     catch(e)
  309.     {
  310.         document.body.innerHTML = "Unable to load topic.  <A HREF='#' onclick='location.reload()'>Click here</A> to try again.";
  311.     }
  312.     document.body.oncontextmenu = function()
  313.     {
  314.         return false;
  315.     }
  316. }
  317. //********************************************************************
  318. function ReadUpdateList()
  319. {
  320.     if((4 == mhTpc["MoneyData"].XMLDOM.readyState) 
  321.         && (0 == mhTpc["MoneyData"].XMLDOM.parseError))
  322.     {
  323.         try
  324.         {
  325.             var lTnum = document.XMLDocument.documentElement.getAttribute("tNum");
  326.             var hTrgt = document.all.MSMNYUPDATE;
  327.             var hUpdt = mhTpc["MoneyData"].XMLDOM.documentElement.selectNodes("update[@id='" + lTnum + "']");
  328.             if(hUpdt.length && hTrgt)
  329.             {
  330.                 hTrgt.innerHTML = hUpdt.item(0).text;
  331.                 hTrgt.style.display = "block";    
  332.             }
  333.         }
  334.         catch(e)
  335.         {
  336.             return;
  337.         }
  338.     }
  339. }
  340. //********************************************************************
  341. function ResetHeaderHtml()
  342. {
  343.     if(HeaderExpandText)
  344.     {
  345.         HeaderExpandText.style.display = (document.body.clientWidth >= 200) ? "none" : "block";
  346.     }
  347.     if(HeaderContractText)
  348.     {
  349.         HeaderContractText.style.display = (document.body.clientWidth < 200) ? "none" : "block";
  350.     }
  351. }
  352. //********************************************************************
  353. function GetFilePath(szName)
  354. {
  355.     var szPath;
  356.     var bRgt;
  357.     var bLft;
  358.     var szLctn = location.href;
  359.     bRgt = szLctn.lastIndexOf("\\") + 1;
  360.     bLft = (2 == szLctn.search(/:/)) 
  361.         ? 
  362.         14 
  363.         : 
  364.         7
  365.         ;
  366.     szPath = (0 == bRgt) 
  367.         ? 
  368.         szName 
  369.         : 
  370.         unescape("file:///" + szLctn.substring(bLft, bRgt) + szName)
  371.         ;
  372.     return szPath;
  373. }
  374. //********************************************************************
  375. function GetFileName(szPath)
  376. {
  377.     var rgszPrts = (4 == szPath.search(/:/)) 
  378.         ?
  379.         szPath.split("\\")
  380.         :
  381.         szPath.split("/")
  382.         ;
  383.     return rgszPrts[rgszPrts.length - 1];
  384. }
  385. //********************************************************************
  386. window.onload = function()
  387. {
  388.     mhTpc["Locale"].loadData();
  389. }
  390. Main();
  391.  
  392.