home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Picture It! Photo Premium Version 9 / PI_CD1.ISO / pip / pi9 / 1033 / pi.chm / digcd_script.js < prev    next >
Encoding:
JavaScript  |  2003-06-07  |  17.0 KB  |  701 lines

  1. /**********************************************************************
  2.     Javascript functions for HTML Help for Picture It! Publishing
  3.     Author: Chris Sanders (csand)
  4.     Microsoft Corporation, All Rights Reserved, 1999-2002
  5.  
  6.     Note: These functions are designed for PROC topics which have
  7.     subtopic_choice radio buttons.
  8.     
  9.     Note: These functions are for IE4+ browsers.
  10.     
  11.     Note: Cannot use less-than or greater-than symbols
  12.     in the javascript or the MSXML2.5 parser will crash.
  13.     (this may not be true for MSXML3.0, but I have not checked)
  14. **********************************************************************/
  15.  
  16. // Global variables
  17. var g_strSubtopicChoiceContext = ""
  18. var g_strCurrentContext = ""
  19. var g_arrContextElements = new Array('INSTRUCTIONS','MORE_INFO','LINK','MOVIE_LINK') // the classNames of the elements that may have context
  20. var g_strCurrentIdeaNum = ""
  21. var g_arrIdeaArrow = new Array('arrowrightblue.gif','arrowdownred.gif')
  22.  
  23.  
  24. //************************************************************
  25. //  Functions for PROC pages
  26. //************************************************************
  27.  
  28. function onPageLoad( strTemplate )
  29. {
  30.     if (strTemplate == 'PROC')
  31.     {
  32.         hideContextContent() //start with all context content is hidden
  33.  
  34.         if ( existsSubtopicChoiceForm() )
  35.         {
  36.             resetSubtopicChoiceForm()
  37.         }
  38.         
  39.         showContextContent() //always show content appropriate for the context
  40.     }
  41. }
  42. function setCurrentContext()
  43. {
  44.     g_strCurrentContext = getSubtopicChoiceContext()
  45. }
  46. function getCurrentContext()
  47. {
  48.     setCurrentContext()
  49.     return g_strCurrentContext
  50. }
  51.  
  52. function setSubtopicChoiceContext( strContext )
  53. {
  54.     g_strSubtopicChoiceContext = strContext
  55. }
  56. function getSubtopicChoiceContext()
  57. {
  58.     return g_strSubtopicChoiceContext
  59. }
  60. function existsSubtopicChoiceForm()
  61. {
  62.     return document.SubtopicChoiceForm
  63. }
  64. function hasTheContext( strElementContext, strCurrentContext )
  65. {
  66.     // Does this element have the current context
  67.  
  68.     var arrElementContext = strElementContext.split(",")
  69.     
  70.     for (var i = 0; i < arrElementContext.length; i++)
  71.     {
  72.         if ( arrElementContext[i] == strCurrentContext )
  73.         {
  74.             return true
  75.         }
  76.     }
  77.     return false
  78. }
  79. function getElementContext( oElement )
  80. {
  81.     //The context is contained in the id attribute
  82.     var strContext = ( oElement.id ) ? oElement.id : ""
  83.     return strContext
  84. }
  85. function clickedSubtopicChoice( strContext )
  86. {
  87.     setSubtopicChoiceContext( strContext ) // remember the context
  88.     hideContextContent()  // first, hide all context content
  89.     showContextContent()  // then, show all context content dependent on the new context
  90. }
  91. function resetSubtopicChoiceForm()
  92. {
  93.     //set the subtopic_choice context to nothing
  94.      setSubtopicChoiceContext( "" )
  95.      
  96.      if ( existsSubtopicChoiceForm() )
  97.      {
  98.          //uncheck all subtopic_choice radio elements
  99.          var oRadioGroup = document.SubtopicChoiceForm.SUBTOPIC_CHOICE
  100.          for (var i = 0; i < oRadioGroup.length; i++)
  101.          {
  102.              oRadioGroup[i].checked = false
  103.          }
  104.      }
  105. }
  106.  
  107. function isContextElement(oElement)
  108. {
  109.     // Is oElement an element that has context
  110.     for (var i=0; i < g_arrContextElements.length; i++)
  111.     {
  112.         if ( oElement.className == g_arrContextElements[i] )
  113.         {
  114.             return true
  115.         }
  116.     }
  117.     return false
  118. }
  119. function showContextContent()
  120. {
  121.     // Display all elements appropriate for the context
  122.     var oElement
  123.     var oLinksElement
  124.     var oMovieLinksElement
  125.     
  126.     //First, make sure that the current context is up-to-date
  127.     setCurrentContext()
  128.  
  129.     //Loop through all of the elements on the page
  130.     for (var i = 0; i != document.all.length; i++)
  131.     {
  132.         oElement = document.all[i]
  133.         
  134.         if (oElement.className == 'LINKS')
  135.             oLinksElement = oElement
  136.         else if (oElement.className == 'MOVIE_LINKS')
  137.             oMovieLinksElement = oElement
  138.         
  139.         if (isContextElement(oElement))
  140.         {
  141.             if (hasTheContext(getElementContext(oElement),g_strCurrentContext))
  142.             {
  143.                 if (oElement.className == 'LINK')
  144.                 {
  145.                     oLinksElement.style.display = '' // display the related LINKS container
  146.                 }
  147.                 else if (oElement.className == 'MOVIE_LINK')
  148.                 {
  149.                     oMovieLinksElement.style.display = '' // display the related MOVIE_LINKS container
  150.                 }
  151.                 oElement.style.display = '' // display the element
  152.             }
  153.             else
  154.             {
  155.                 oElement.style.display = 'none' // hide the element
  156.             }
  157.         }
  158.     }
  159. }
  160. function hideContextContent()
  161. {
  162.     // Hide all elements that have context
  163.     var oElement
  164.     
  165.     //First, make sure that the current context is up-to-date
  166.     setCurrentContext()
  167.     
  168.     //Loop through all of the elements on the page
  169.     for (var i = 0; i != document.all.length; i++)
  170.     {
  171.         oElement = document.all[i]
  172.         
  173.         if ( (isContextElement(oElement)) || (oElement.className == 'LINKS') || (oElement.className == 'MOVIE_LINKS') )
  174.         {
  175.             oElement.style.display = 'none' // hide the element
  176.         }
  177.     }
  178. }
  179.  
  180. //************************************************************
  181. //  Functions for other pages
  182. //************************************************************
  183.  
  184. function toggleNext(oElement, strClassName)
  185. {
  186.     if (strClassName == 'GLOSSARY_DEF')
  187.     {
  188.         toggleGlossary(oElement)
  189.     }
  190.     else
  191.     {
  192.         //find the strClassName element associated with oElement
  193.         //(it should be the next strClassName element in the source index hierarchy)
  194.         //and toggle it
  195.         for (var i = oElement.sourceIndex; i != document.all.length; i++)
  196.         {
  197.             oElement = document.all[i]
  198.             
  199.             if (oElement.tagName == "img")
  200.             {
  201.                 toggleArrow(oElement.sourceIndex)
  202.             }
  203.             if (oElement.className == strClassName)
  204.             {
  205.                 toggleSI(oElement.sourceIndex)
  206.                 break
  207.             }
  208.         }
  209.     }
  210. }
  211. function toggleSI(intSI) {
  212.     //toggle the element at this source index
  213.     
  214.     if (document.all[intSI].style.display == 'none')
  215.     {
  216.         document.all[intSI].style.display = ''
  217.     }
  218.     else
  219.     {
  220.         document.all[intSI].style.display = 'none'
  221.     }
  222. }
  223. function toggleArrow(intSI) {
  224.     //toggle the img element at this source index
  225.     
  226.     var strCurrentImg, intCursor
  227.     strCurrentImg = document.all[intSI].src
  228.     intCursor = strCurrentImg.lastIndexOf('/')
  229.     
  230.     if (intCursor != -1)
  231.     {
  232.         strCurrentImg = strCurrentImg.substr(intCursor+1)
  233.     }
  234.     
  235.     if (strCurrentImg == g_arrIdeaArrow[0])
  236.     {
  237.         document.all[intSI].src = g_arrIdeaArrow[1]
  238.     }
  239.     else if (strCurrentImg == g_arrIdeaArrow[1])
  240.     {
  241.         document.all[intSI].src = g_arrIdeaArrow[0]
  242.     }
  243. }
  244. function toggleIdea(oElement)
  245. {
  246.     // oElement is the IDEA_CATEGORY SPAN element that contains first an <IMG> element and then Text
  247.     // First, hide any open IDEAS DIV element
  248.     // Second, the IMG for the clicked IDEA_CATEGORY must be changed to the clicked state
  249.     // Third, the corresponding IDEAS DIV must be shown
  250.     
  251.     var intSI
  252.     var oElem
  253.     
  254.     // close any open IDEAS
  255.     if (g_strCurrentIdeaNum != "")
  256.     {
  257.         // there is an IDEA_CATEGORY currently selected
  258.         intSI = document.all[getCurrentIcatID()].sourceIndex + 1  // the source index of the associated IMG element
  259.         toggleArrow(intSI)  // toggle the IMG to the unselected state
  260.         oElem = eval( "document.all." + getCurrentIdeasID() )
  261.         oElem.style.display = 'none'  // close the associated IDEA
  262.     }
  263.     
  264.     // open new IDEAS as appropriate
  265.     if (g_strCurrentIdeaNum != getIdeaNumber(oElement.id))
  266.     {
  267.         // a new IDEA_CATEGORY was selected
  268.         setCurrentIdea(oElement.id)  // remember this new idea number
  269.         intSI = oElement.sourceIndex + 1  // the source index of the associated IMG element
  270.         toggleArrow(intSI)  // toggle the image to the selected state
  271.         oElem = eval( "document.all." + getCurrentIdeasID() )
  272.         oElem.style.display = ''  // open the associated IDEAS
  273.     }
  274.     else
  275.     {
  276.         // the open IDEA_CATEGORY was reselected
  277.         g_strCurrentIdeaNum = "" // remember that there are no ideas currently selected
  278.     }
  279. }
  280. function getCurrentIdeasID()
  281. {
  282.     return ('ideas_' + g_strCurrentIdeaNum)
  283. }
  284. function getCurrentIcatID()
  285. {
  286.     return ('icat_' + g_strCurrentIdeaNum)
  287. }
  288. function getIdeaNumber(strID)
  289. {
  290.     return strID.substring( strID.indexOf('_')+1, strID.length )
  291. }
  292. function setCurrentIdea(strID)
  293. {
  294.     g_strCurrentIdeaNum = getIdeaNumber(strID)
  295. }
  296. function doLearnMore(strHREF)
  297. {
  298.     // jump to the help topic page indicated by the HREF
  299.     if (strHREF != '')
  300.     {
  301.         window.location = strHREF;
  302.     }
  303.  
  304. }
  305. function openMovieWindow(fn)
  306. {
  307.     var X, Y, sl, a, ra, link, filename;
  308.     var subDir = "movies/";
  309.     
  310.     filename = fn;
  311.     ra = /:/;
  312.     a = location.href.search(ra);
  313.     if (a == 2)
  314.         X = 14;
  315.     else
  316.         X = 7;
  317.     sl = "\\";
  318.     Y = location.href.lastIndexOf(sl) + 1;
  319.  
  320.     do {
  321.         link = 'file:///' + location.href.substring(X, Y) + subDir + filename;
  322.         // open the window, and get the value returned when the window closes
  323.         filename = window.showModalDialog(link,'',"dialogWidth:600px;dialogHeight:535px;center=yes;status=no;scroll=no;help=no");
  324.     } while (filename.indexOf('.htm') != -1)
  325.     
  326.     // if link from the flash movie back to the tutorial topic in the chm
  327.     if ( filename.indexOf('TUTO') != -1 )
  328.     {
  329.         // show the tutorial topic
  330.         window.location = filename + ".htm";
  331.     }
  332. }
  333. function openLocalFile(fn)
  334. {
  335.     var X, Y, sl, a, ra, link, oWindow;
  336.     
  337.     ra = /:/;
  338.     a = location.href.search(ra);
  339.     if (a == 2)
  340.         X = 14;
  341.     else
  342.         X = 7;
  343.     sl = "\\";
  344.     Y = location.href.lastIndexOf(sl) + 1;
  345.  
  346.     link = 'file:///' + location.href.substring(X, Y) + fn;
  347.     oWindow = window.open(link,'LocalWin','width=500,height=500,resizable');
  348.     
  349. }
  350.  
  351. //************************************************************
  352. //  Glossary Popup
  353. //************************************************************
  354.  
  355. function toggleGlossary(oElement)
  356. {
  357.     //IE4+ browsers only
  358.  
  359.     var strGlossaryPopupDIV = "<div id='popupWindow' style='visibility:hidden; position:absolute; " +
  360.         "top:0px; left:0px; background-color:#FFFFFF; " + 
  361.         "border:solid 1 #325580'></div>";
  362.  
  363.     if (!(document.all.popupWindow))
  364.     {
  365.         //insert the popup div in the doc body
  366.         document.body.insertAdjacentHTML('beforeEnd', strGlossaryPopupDIV);
  367.     }
  368.     
  369.     if (document.all.popupWindow.style.visibility == 'hidden')
  370.     {
  371.         //let's make it visible with the proper content and in the proper position
  372.         showGlossary(oElement)
  373.         
  374.         //allow click in doc body to hide the glossary
  375.         document.body.onmousedown = hideGlossary
  376.     }
  377.     else
  378.     {
  379.         //it is visible so this must be a call to hide it
  380.         hideGlossary()
  381.     }
  382. }
  383. function hideGlossary()
  384. {
  385.     document.all.popupWindow.style.visibility = 'hidden';
  386.     document.body.onclick = doNothing
  387. }
  388. function doNothing()
  389. {}
  390. function showGlossary(oElement)
  391. {
  392.     //IE4+ browsers only
  393.     
  394.     var oPopup = document.all.popupWindow;
  395.  
  396.     oPopup.style.height = 0;
  397.     oPopup.style.width = 200;
  398.      oPopup.style.padding = 4;
  399.     oPopup.style.fontsize = 10;
  400.     oPopup.innerHTML = '\t'+ getGlossaryText(oElement);
  401.  
  402.     oPopup.style.backgroundColor="#FFFF99";
  403.  
  404.     positionGlossaryPopup(oElement);
  405.  
  406.     oPopup.style.visibility = "visible";
  407.     
  408. }
  409. function positionGlossaryPopup(oElement)
  410. {
  411.     //IE4+ browsers only
  412.     
  413.     var popupWindow = document.all.popupWindow
  414.     
  415.     var pageBottom = document.body.scrollTop + document.body.clientHeight;
  416.     var popHeight = popupWindow.offsetHeight;
  417.  
  418.     var ieX;
  419.     var ieY;
  420.  
  421.     if (oElement.offsetParent.tagName.toLowerCase() == 'body')
  422.     {
  423.         ieX = oElement.offsetLeft;
  424.         ieY = ((oElement.offsetTop) + (oElement.offsetHeight) + 1);
  425.     }
  426.     else if (oElement.offsetParent.offsetParent.tagName.toLowerCase() == 'body')
  427.     {
  428.         ieX = ((oElement.offsetLeft) + (oElement.offsetParent.offsetLeft));
  429.         ieY = ((oElement.offsetHeight) + (oElement.offsetTop) + (oElement.offsetParent.offsetTop) + (1));
  430.     }
  431.     else if (oElement.offsetParent.offsetParent.offsetParent.tagName.toLowerCase() == 'body')
  432.     {
  433.         ieX = ((oElement.offsetLeft) + (oElement.offsetParent.offsetLeft) + (oElement.offsetParent.offsetParent.offsetLeft));
  434.         ieY = ((oElement.offsetHeight) + (oElement.offsetTop) + (oElement.offsetParent.offsetTop) + (oElement.offsetParent.offsetParent.offsetTop) + (1));
  435.     }
  436.     else
  437.     {
  438.         ieX = window.event.clientX;
  439.         ieY = window.event.clientY + document.body.scrollTop;
  440.     }
  441.  
  442.      var rightlimit = ieX + popupWindow.offsetWidth;
  443.     if (rightlimit >= document.body.clientWidth)
  444.     {
  445.         ieX -= (rightlimit - document.body.clientWidth);
  446.     }
  447.     
  448.     try{
  449.         popupWindow.style.height = popHeight - 2 * (parseInt(popupWindow.style.borderWidth));
  450.     }
  451.     catch (e) {}
  452.     
  453.     if (popHeight + ieY >= pageBottom)
  454.     {
  455.         if (popHeight <= pageBottom)
  456.         {
  457.             ieY = pageBottom - popHeight;
  458.         }
  459.         else
  460.         {
  461.             ieY = 0;
  462.         }
  463.     }
  464.     popupWindow.style.left = ieX;
  465.     popupWindow.style.top = ieY;
  466.     
  467. }
  468. function getGlossaryText(oClickedElement)
  469. {
  470.     //IE4+ browsers only
  471.     
  472.     //find the strClassName element associated with oElement
  473.     //(it should be the next strClassName element in the source index hierarchy)
  474.     //and get its content
  475.     
  476.     var oElement
  477.     var strText
  478.     var strHTML
  479.     
  480.     strHTML = "<b>" + oClickedElement.innerText + "</b>"
  481.     strHTML += "<p>"
  482.     
  483.     for (var i = oClickedElement.sourceIndex; i != document.all.length; i++)
  484.     {
  485.         oElement = document.all[i]
  486.             
  487.         if (oElement.className == 'GLOSSARY_DEF')
  488.         {
  489.             strText = oElement.innerText
  490.             break
  491.         }
  492.     }
  493.     
  494.     //capitalize the first alphabetic char
  495.     var strFirstChar
  496.     for (var i = 0; i != strText.length; i++)
  497.     {
  498.         var strFirstChar = strText.substr(i,1)
  499.         if (strFirstChar != " ")
  500.         {
  501.             var strRest = strText.substr(i+1)
  502.             strText = strFirstChar.toUpperCase() + strRest
  503.             break
  504.         }
  505.     }
  506.     
  507.     strHTML += strText + "</p>"
  508.  
  509.     return strHTML
  510. }
  511. //************************************************************
  512.  
  513. /**********************************************************************
  514.     Generic Cross Browser Code
  515. **********************************************************************/
  516.  
  517. var isIE4 = true;
  518. var isNav4 = false;
  519. var isNav6 = false;
  520.  
  521. function blur( oElement )
  522. {
  523.     oElement.blur()
  524. }
  525.  
  526. function existsForm( name )
  527. {
  528.     if ( typeof document.forms[name] == "object" )
  529.         return true
  530.     else
  531.         return false
  532. }
  533. function getElementById( strId )
  534. {
  535.     if (isNav6)
  536.     {
  537.         return document.getElementById( strId );
  538.     }
  539.     else if (isIE4)
  540.     {
  541.         return document.all[strId]
  542.     }
  543.     else
  544.     {
  545.         return null
  546.     }
  547. }
  548.  
  549. function getStyleBySelector( selector )
  550. {
  551.     if (!isNav6)
  552.     {
  553.         return null;
  554.     }
  555.     var sheetList = document.styleSheets;
  556.     var ruleList;
  557.     var i, j;
  558.  
  559.     /* look through stylesheets in reverse order that
  560.        they appear in the document */
  561.     for (i=sheetList.length-1; i >= 0; i--)
  562.     {
  563.         ruleList = sheetList[i].cssRules;
  564.         for (j=0; j<ruleList.length; j++)
  565.         {
  566.             if (ruleList[j].type == CSSRule.STYLE_RULE && ruleList[j].selectorText == selector)
  567.             {
  568.                 return ruleList[j].style;
  569.             }   
  570.         }
  571.     }
  572.     return null;
  573. }
  574. function getStylePropertyById( strId, strProperty )
  575. {
  576.     if (isNav6)
  577.     {
  578.         var styleObject = document.getElementById( strId );
  579.         if (styleObject != null)
  580.         {
  581.             styleObject = styleObject.style;
  582.             if (styleObject[strProperty])
  583.             {
  584.                 return styleObject[ strProperty ];
  585.             }
  586.         }
  587.         styleObject = getStyleBySelector( "#" + strId );
  588.         return (styleObject != null) ?
  589.             styleObject[strProperty] :
  590.             null;
  591.     }
  592.     else if (isIE4)
  593.     {
  594.         return document.all[strId].style[strProperty];
  595.     }
  596.     else
  597.     {
  598.         return ""
  599.     }
  600. }
  601.  
  602. function setStylePropertyById( strId, strProperty, strValue )
  603. {
  604.     if (isNav6)
  605.     {
  606.         var styleObject = document.getElementById( strId );
  607.         if (styleObject != null)
  608.         {
  609.             styleObject = styleObject.style;
  610.             styleObject[ strProperty ] = strValue;
  611.         }
  612.     }
  613.     else if (isIE4)
  614.     {
  615.          document.all[strId].style[strProperty] = strValue;
  616.     }
  617.     else
  618.     {}    //so Nav4 won't return error
  619. }
  620.  
  621. function setStylePropertyByElement( oElement, strProperty, strValue )
  622. {
  623.     if (isNav6)
  624.     {
  625.         var styleObject = oElement;
  626.         if (styleObject != null)
  627.         {
  628.             styleObject = styleObject.style;
  629.             styleObject[ strProperty ] = strValue;
  630.         }
  631.     }
  632.     else if (isIE4)
  633.     {
  634.          oElement.style[strProperty] = strValue;
  635.     }
  636.     else
  637.     {}    //so Nav4 won't return error
  638. }
  639.  
  640. function toggleElementDisplay( element, strStyle )
  641. {
  642.     var strID
  643.     
  644.     //get the element id
  645.     if (typeof element == "object")
  646.     {
  647.         strID = element.id    
  648.     }
  649.     else if (typeof element == "string")
  650.     {
  651.         strID = element
  652.     }
  653.     
  654.     if ((strID != "") && (strID != null))
  655.     {
  656.         if (isIE4 || isNav6)
  657.         {
  658.             if ( getStylePropertyById( strID,'display')=='none' )
  659.             {
  660.                 setStylePropertyById( strID, 'display', strStyle ) //show the element
  661.             }
  662.             else
  663.             {
  664.                 setStylePropertyById( strID, 'display', 'none' ) //hide the element
  665.             }
  666.         }
  667.     }
  668. }
  669.  
  670. function toggleImg( element, strImg1, strImg2 )
  671. {
  672.     var oElement;
  673.     
  674.     //get the element id
  675.     if (typeof element == "object")
  676.     {
  677.         oElement = element;
  678.     }
  679.     else if (typeof element == "string")
  680.     {
  681.         oElement = getElementById( element );
  682.     }
  683.     
  684.     if (oElement != null)
  685.     {
  686.         var strSrc = oElement.src;
  687.         if ( strSrc.indexOf(strImg1) > -1 )
  688.         {
  689.             oElement.src = strImg2;
  690.         }
  691.         else
  692.         {
  693.             oElement.src = strImg1;
  694.         }
  695.     }
  696. }
  697.  
  698. /**********************************************************************
  699.     End Generic Cross-Browser Code
  700. **********************************************************************/
  701.