home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2011 October / PCgo_1011_CD.iso / interface / js / search.js < prev    next >
Encoding:
JavaScript  |  2011-08-16  |  36.3 KB  |  1,215 lines

  1. // ********************************************************************************************************************
  2. // Search Functions
  3. // ********************************************************************************************************************
  4.  
  5. var globalHightLightColor = "";
  6. var globalHightLightColorCell1 = '';
  7. var globalHightLightColorCell2 = '';
  8. var globalHightLightColorCell3 = '';
  9.  
  10. function issueItem() {
  11.   var year;
  12.   var nos = new Array();
  13. }
  14.  
  15. function nodeResultItem() {
  16.   var year = '';
  17.   var nr = '';
  18.   var category = '';
  19.   var title = '';
  20.   var description = '';
  21.   var link = '';
  22. }
  23.  
  24. var smallLetters = 'abcdefghijklmnopqrstuvwxyz';
  25. var bigLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  26. var xmlDocLocal = null;
  27. var xmlDocGlobal = null;
  28. var availableCategories = new Array();
  29. var availableIssues = new Array();
  30. var sorting = 1;
  31. var globalResultNodes = null;
  32. var localResultNodes = null;
  33.  
  34. function sortByTitleDESC (a, b) {
  35.   var valueA = a.title.toLowerCase();
  36.   var valueB = b.title.toLowerCase();
  37.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  38. }
  39.  
  40. function sortByTitleASC (a, b) {
  41.   var valueA = a.title.toLowerCase();
  42.   var valueB = b.title.toLowerCase();
  43.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  44. }
  45.  
  46. function sortByCategoryDESC (a, b) {
  47.   var valueA = a.category.toLowerCase();
  48.   var valueB = b.category.toLowerCase();
  49.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  50. }
  51.  
  52. function sortByCategoryASC (a, b) {
  53.   var valueA = a.category.toLowerCase();
  54.   var valueB = b.category.toLowerCase();
  55.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  56. }
  57.  
  58. function sortByDescriptionDESC (a, b) {
  59.   var valueA = a.description.toLowerCase();
  60.   var valueB = b.description.toLowerCase();
  61.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  62. }
  63.  
  64. function sortByDescriptionASC (a, b) {
  65.   var valueA = a.description.toLowerCase();
  66.   var valueB = b.description.toLowerCase();
  67.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  68. }
  69.  
  70. function sortByIssueDESC (a, b) {
  71.   var yearA = parseInt(a.year);
  72.   var yearB = parseInt(b.year);
  73.   var nrA = parseInt(a.nr);
  74.   var nrB = parseInt(b.nr);
  75.   if (yearA == yearB) {
  76.     return ((nrA > nrB) ? 1 : ((nrA < nrB) ? -1 : 0));
  77.   }
  78.   else {
  79.     return ((yearA > yearB) ? 1 : ((yearA < yearB) ? -1 : 0));
  80.   }
  81. }
  82.  
  83. function sortByIssueASC (a, b) {
  84.   var yearA = parseInt(a.year);
  85.   var yearB = parseInt(b.year);
  86.   var nrA = parseInt(a.nr);
  87.   var nrB = parseInt(b.nr);
  88.   if (yearA == yearB) {
  89.     return ((nrA < nrB) ? 1 : ((nrA > nrB) ? -1 : 0));
  90.   }
  91.   else {
  92.     return ((yearA < yearB) ? 1 : ((yearA > yearB) ? -1 : 0));
  93.   }
  94. }
  95.  
  96. function doSort(nodesArray) {
  97.     switch (sorting) {
  98.       case 1:
  99.         nodesArray.sort(sortByTitleDESC);
  100.         break;
  101.       case 2:
  102.         nodesArray.sort(sortByTitleASC);
  103.         break;
  104.       case 3:
  105.         nodesArray.sort(sortByCategoryDESC);
  106.         break;
  107.       case 4:
  108.         nodesArray.sort(sortByCategoryASC);
  109.         break;
  110.       case 5:
  111.         nodesArray.sort(sortByDescriptionDESC);
  112.         break;
  113.       case 6:
  114.         nodesArray.sort(sortByDescriptionASC);
  115.         break;
  116.       case 7:
  117.         nodesArray.sort(sortByIssueDESC);
  118.         break;
  119.       case 8:
  120.         nodesArray.sort(sortByIssueASC);
  121.         break;
  122.     }
  123. }
  124.  
  125. function setSorting(value, type) {
  126.     if (sorting == value) {
  127.       sorting = value+1;
  128.     }
  129.     else {
  130.       if (sorting == value+1) {
  131.         sorting = value;
  132.       }
  133.       else {
  134.         sorting = value;
  135.       }
  136.     }
  137.  
  138.     if (type == 1) {
  139.         doSort(localResultNodes);
  140.         var html = getResultHTML(localResultNodes, 1);
  141.         var searchContent = document.getElementById('searchContentLocal');
  142.         if (searchContent != null) {
  143.           searchContent.innerHTML = html;
  144.           //resizeIFrame();
  145.           redrawResultsTable();
  146.         }
  147.     }
  148.     else {
  149.         doSort(globalResultNodes);
  150.         var html = getResultHTML(globalResultNodes, type);
  151.         var searchContent = document.getElementById('searchContentGlobal');
  152.         if (searchContent != null) {
  153.           searchContent.innerHTML = html;
  154.           //resizeIFrame();
  155.           redrawResultsTable();
  156.         }
  157.     }
  158. }
  159.  
  160. function existsInResults(arrResults, node) {
  161.   var rN = null;
  162.   for (var i=0; i<arrResults.length; i++) {
  163.     rN = arrResults[i];
  164.     if (rN.year == node.year && rN.nr == node.nr && rN.category == node.category && rN.title == node.title && rN.description == node.description && rN.link == node.link) {
  165.       return true;
  166.     }
  167.   }
  168.   return false;
  169. }
  170.  
  171. function getResultArray(resultNodes) {
  172.   var issueNode, resultNode;
  173.   var result = new Array();
  174.  
  175.   for (var i=0; i<resultNodes.length; i++) {
  176.     resultNode = resultNodes[i];
  177.  
  178.     if (resultNode.nodeName != 's') {
  179.       resultNode = resultNode.parentNode;
  180.     }
  181.     issueNode = resultNode.parentNode;
  182.     var itemNode = new nodeResultItem();
  183.     itemNode.year = issueNode.getAttribute('year');
  184.     itemNode.nr = issueNode.getAttribute('nr');
  185.     itemNode.category = resultNode.getAttribute('c');
  186.     if (resultNode.getElementsByTagName('t')[0].hasChildNodes) {
  187.        itemNode.title = resultNode.getElementsByTagName('t')[0].firstChild.nodeValue;
  188.     }
  189.     else {
  190.          itemNode.title = '';
  191.     }
  192.     if (resultNode.getElementsByTagName('k')[0].hasChildNodes) {
  193.        itemNode.description = resultNode.getElementsByTagName('k')[0].firstChild.nodeValue;
  194.     }
  195.     else {
  196.          itemNode.description = '';
  197.     }
  198.     if (resultNode.getElementsByTagName('a')[0].hasChildNodes) {
  199.        itemNode.link = resultNode.getElementsByTagName('a')[0].firstChild.nodeValue;
  200.     }
  201.     else {
  202.          itemNode.link = '';
  203.     }
  204.     if (!existsInResults(result, itemNode)) {
  205.       result.push(itemNode);
  206.     }
  207.   }
  208.   return result;
  209. }
  210.  
  211. function getResultHTML(resultItems, type) {
  212.   var resultNode, issueNode, category, title, description, link, year, nr, issueText, aStart, aEnd;
  213.   var color;
  214.   var textColor;
  215.   var imgTitle = '';
  216.   var imgCategory = '';
  217.   var imgDescription = '';
  218.   var imgIssue = '';
  219.     
  220.     /* anpassen !!! */
  221.     var actYear = 2011;
  222.     var actNo = 10;
  223.  
  224.   switch (sorting) {
  225.     case 1:
  226.       imgTitle = '<img src="images/arrowDown.gif" width="7" height="6" />';
  227.       break;
  228.     case 2:
  229.       imgTitle = '<img src="images/arrowUp.gif" width="7" height="6" />';
  230.       break;
  231.     case 3:
  232.       imgCategory = '<img src="images/arrowDown.gif" width="7" height="6" />';
  233.       break;
  234.     case 4:
  235.       imgCategory = '<img src="images/arrowUp.gif" width="7" height="6" />';
  236.       break;
  237.     case 5:
  238.       imgDescription = '<img src="images/arrowDown.gif" width="7" height="6" />';
  239.       break;
  240.     case 6:
  241.       imgDescription = '<img src="images/arrowUp.gif" width="7" height="6" />';
  242.       break;
  243.     case 7:
  244.       imgIssue = '<img src="images/arrowDown.gif" width="7" height="6" />';
  245.       break;
  246.     case 8:
  247.       imgIssue = '<img src="images/arrowUp.gif" width="7" height="6" />';
  248.       break;
  249.   }
  250.  
  251.   doSort(resultItems);
  252.  
  253.   var result = '<div>';
  254. //  var result = "";
  255.  
  256.   if( resultItems.length > 0 ) {
  257.       result += '<table border="0" cellspacing="0" cellpadding="0" class="searchResultsTableHeader" width="960">';
  258.       result += '<tr id="searchHeader">';
  259.  
  260.       result += '<td id="firstSearchColumn" style="width: 140px; padding: 0 0 0 10px;"><a href="javascript: void(0);" onclick="setSorting(1, ' + type + ');">Titel</a>' + imgTitle + '</td>';
  261.       result += '<td id="secondSearchColumn" style="width: 550px; padding: 0 0 0 10px; border-left: solid 1px #00285d; border-right: solid 1px #00285d;"><a href="javascript: void(0);" onclick="setSorting(5, ' + type + ');">Beschreibung</a>' + imgDescription + '</td>';
  262.       result += '<td id="thirdSearchColumn" style="width: 80px; padding: 0 0 0 10px;"><a href="javascript: void(0);" onclick="setSorting(7, ' + type + ');">Ausgabe</a>' + imgIssue + '</td>';
  263.  
  264.       result += '</tr>';
  265.       result += '</table>';
  266.  
  267.       result += '<div style="height: 480px; overflow: auto;" id="searchResultsDiv"><table width="960" cellpadding="0" cellspacing="0" border="0" class="searchResultsTable" id="searchResultsTable" align="left">';
  268.  
  269.       var onClickGoTo = "";
  270.             
  271.       for (var i=0; i<resultItems.length; i++) {
  272.         resultItem = resultItems[i];
  273.  
  274.         if (parseInt(resultItem.year) == parseInt(actYear) && parseInt(resultItem.nr) == parseInt(actNo)) {
  275.           issueText = resultItem.year + ' - ' + resultItem.nr;
  276.           
  277.                  aStart = '<a href="javascript: void(0);" onclick="switch_iframe(\'' + resultItem.link + '\');">';
  278.            aEnd = '</a>';
  279.                  
  280.           onClickGoTo = "javascript:switch_iframe('" + resultItem.link + "');";
  281.         }
  282.         else {
  283.           issueText = resultItem.year + ' - ' + resultItem.nr;
  284.           aStart = '';
  285.           aEnd = '';
  286.            onClickGoTo = "";
  287.         }
  288.  
  289.         if (i%2 == 0) {
  290.           color = "transparent";
  291.           textColor = "black";
  292.         }
  293.         else {
  294.           color = "blue";
  295.           textColor = "white";
  296.         }
  297.  
  298.         result += '<tr valign="top" class="row'+ color +'">';
  299.  
  300.         //result += '<td width="130">' + aStart + resultItem.title + aEnd + '</td>';
  301.         if (sorting == 1 || sorting == 2) {
  302.                if (onClickGoTo != '')
  303.                {
  304.                          result += '<td  class="row'+ color +'Sort" style="width: 140px; padding: 5px 0 5px 10px;" onclick="' + onClickGoTo + '" onmouseover="javascript:hightLightLine( this );" onmouseout="javascript:unHightLightLine( this );">' + resultItem.title + '</td>';
  305.                         } else {
  306.                         result += '<td  class="row'+ color +'Sort" style="width: 140px; padding: 5px 0 5px 10px;">' + resultItem.title + '</td>';
  307.                         }        
  308.         }
  309.         else {
  310.                  if (onClickGoTo != '')
  311.                    {
  312.                          result += '<td style="width: 140px; padding: 5px 0 5px 10px;" onclick="' + onClickGoTo + '" onmouseover="javascript:hightLightLine( this );" onmouseout="javascript:unHightLightLine( this );">' + resultItem.title + '</td>';
  313.                           } else {
  314.                             result += '<td style="width: 140px; padding: 5px 0 5px 10px;">' + resultItem.title + '</td>';
  315.                             }
  316.             }
  317.  
  318.         var tempTxt = ' ';
  319.         if (resultItem.description.length > 0) {
  320.           var tempTxt = resultItem.description;
  321.         }
  322.          
  323.         if (sorting == 5 || sorting == 6) {         
  324.            if (onClickGoTo != '')
  325.                    {
  326.                          result += '<td class="row'+ color +'Sort" style="width: 550px; padding: 5px 0 5px 10px; border-left: solid 1px #00285d; border-right: solid 1px #00285d;" onclick="' + onClickGoTo + '" onmouseover="javascript:hightLightLine( this );" onmouseout="javascript:unHightLightLine( this );">' + tempTxt + '</td>';
  327.                          } else {
  328.                          result += '<td class="row'+ color +'Sort" style="width: 550px; padding: 5px 0 5px 10px; border-left: solid 1px #00285d; border-right: solid 1px #00285d;">' + tempTxt + '</td>';
  329.                          }
  330.         }
  331.         else {
  332.                  if (onClickGoTo != '')
  333.                    {
  334.                    result += '<td style="width: 550px; padding: 5px 0 5px 10px; border-left: solid 1px #00285d; border-right: solid 1px #00285d;" onclick="' + onClickGoTo + '" onmouseover="javascript:hightLightLine( this );" onmouseout="javascript:unHightLightLine( this );">' + tempTxt + '</td>';
  335.                    } else {
  336.                          result += '<td style="width: 550px; padding: 5px 0 5px 10px; border-left: solid 1px #00285d; border-right: solid 1px #00285d;">' + tempTxt + '</td>';
  337.                          }
  338.         }
  339.  
  340.         if (sorting == 7 || sorting == 8) {
  341.              if (onClickGoTo != '')
  342.                    {
  343.                    result += '<td class="row' + color + 'Sort" style="width: 80px; padding: 5px 0 5px 10px;" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  344.                        } else {
  345.                              result += '<td class="row' + color + 'Sort" style="width: 80px; padding: 5px 0 5px 10px;">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  346.                              }
  347.         }
  348.         else {
  349.              if (onClickGoTo != '')
  350.                    {
  351.           result += '<td style="width: 80px; padding: 5px 0 5px 10px;" onclick="' + onClickGoTo + '" onmouseover="javascript:hightLightLine( this );" onmouseout="javascript:unHightLightLine( this );">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  352.           } else {
  353.                 result += '<td style="width: 80px; padding: 5px 0 5px 10px;">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  354.                 }
  355.         }
  356.  
  357.         result += '</tr>';
  358.       }
  359.  
  360.       result += '</table>';
  361.  
  362.   } else {
  363.       result += '<br /><br /><br /><h3 class="searchResults">Keine Elemente gefunden</h3>';
  364.   }
  365.  
  366.   result += '</div>';
  367.  
  368.   return result;
  369. }
  370.  
  371. /**
  372.  * executeInnerHTMLJavaScript
  373.  *
  374.  * @param {Element} element
  375.  */
  376.  function executeInnerHTMLJavaScript( element ) {
  377.  
  378.      if( element != null ) {
  379.  
  380.          var scriptTags = element.getElementsByTagName( "script" );
  381.  
  382.          if( scriptTags != null && scriptTags.length > 0 ) {
  383.  
  384.              for( var loop = 0; loop < scriptTags.length; loop++ ) {
  385.                  eval( scriptTags[loop].text );
  386.              }
  387.          }
  388.      }
  389.  }
  390.  
  391.  function setAllTableCells(parentRow, className) {
  392.    var cells = parentRow.getElementsByTagName('td');
  393.    for (i=0; i<cells.length; i++) {
  394.     switch (i) {
  395.       case 0:
  396.         globalHightLightColor1 = cells[0].className;
  397.         break;
  398.       case 1:
  399.         globalHightLightColor2 = cells[1].className;
  400.         break;
  401.       case 2:
  402.         globalHightLightColor3 = cells[2].className;
  403.         break;
  404.     }
  405.      
  406.      cells[i].className = className;
  407.    }
  408.  }
  409.  
  410.  function restorAllTableCells(parentRow) {
  411.    var cells = parentRow.getElementsByTagName('td');
  412.    for (i=0; i<cells.length; i++) {
  413.     switch (i) {
  414.       case 0:
  415.         cells[0].className = globalHightLightColor1;
  416.         break;
  417.       case 1:
  418.         cells[1].className = globalHightLightColor2;
  419.         break;
  420.       case 2:
  421.         cells[2].className = globalHightLightColor3;
  422.         break;
  423.     }
  424.    }
  425.  }
  426.  
  427. /**
  428.  * hightLightLine
  429.  *
  430.  * @param {Node} element
  431.  */
  432.  function hightLightLine(element) {
  433.      if( element != null ) {
  434.          var parentElement = element.parentNode;
  435.  
  436.          if( parentElement != null ) {
  437.              setAllTableCells(parentElement, 'rowSortActive');
  438.              globalHightLightColor = parentElement.className;
  439.              parentElement.className = "rowActive";
  440.          }
  441.      }
  442.  }
  443.  
  444. /**
  445.  * unHightLightLine
  446.  *
  447.  * @param {Node} element
  448.  */
  449.  function unHightLightLine(element) {
  450.      if( element != null ) {
  451.          var parentElement = element.parentNode;
  452.  
  453.          if( parentElement != null ) {
  454.              restorAllTableCells(parentElement);
  455.              parentElement.className = globalHightLightColor;
  456.          }
  457.      }
  458.  }
  459.  
  460. /**
  461.  * redrawResultsTable
  462.  */
  463.  function redrawResultsTable() {   
  464.  
  465.      var element = document.getElementById( "searchResultsDiv" );
  466.  
  467.      if( element != null ) {
  468.  
  469.          var elementHeight = element.scrollHeight;
  470.  
  471.          var parentElement = element.parentNode;
  472.  
  473.          if( parentElement != null ) {
  474.  
  475.              var parentHeight = parentElement.scrollHeight;
  476.  
  477.              var firstElement = document.getElementById( "firstSearchColumn" );
  478.              var secondElement = document.getElementById( "secondSearchColumn" );
  479.              var thirdElement = document.getElementById( "thirdSearchColumn" );
  480.  
  481.              var tableElement = document.getElementById( "searchResultsTable" );
  482.  
  483.             //alert( "x: " + elementHeight + " - y: " + parentHeight );
  484.  
  485.              if( elementHeight >= parentHeight ) {
  486.  
  487.                  // scrollbar present
  488.  
  489.                  if( firstElement != null ) {
  490.                      firstElement.style.width = "139px";
  491.                  }
  492.  
  493.                  if( secondElement != null ) {
  494.                      secondElement.style.width = "549px";
  495.                  }
  496.  
  497.                  if( tableElement != null ) {
  498.                      tableElement.style.height = "";
  499.                  }
  500.  
  501.              } else {
  502.  
  503.                  // no scrollbar
  504.  
  505.                  if( firstElement != null ) {
  506.                      firstElement.style.width = "140px";
  507.                  }
  508.  
  509.                  if( secondElement != null ) {
  510.                      secondElement.style.width = "550px";
  511.                  }
  512.  
  513.                  if( tableElement != null ) {
  514.                      tableElement.style.height = "";
  515.                  }
  516.  
  517.              }
  518.          }
  519.      }     
  520.  }
  521.  
  522. function closeSearchDivs() {
  523.   switchLocalSearchDiv(false);
  524.   switchGlobalSearchDiv(false);
  525.   
  526.   var searchesBox = document.getElementById( "searchesBox" );
  527.   if( searchesBox != null ) {
  528.       searchesBox.style.display = "block";
  529.   }  
  530. }
  531.  
  532. function switchLocalSearchDiv(doShow) {
  533.   var elementSearch = document.getElementById('localsearch');
  534.   var elementIFrame = document.getElementById('iframe');
  535.   if (elementSearch != null && elementIFrame != null) {
  536.       if (doShow) {
  537.         elementSearch.style.display = 'block';
  538.         elementIFrame.style.display = 'none';
  539.       }
  540.       else {
  541.         elementSearch.style.display = 'none';
  542.         elementIFrame.style.display = 'block';
  543.       }
  544.   }
  545. }
  546.  
  547. function switchGlobalSearchDiv(doShow) {
  548.   var elementSearch = document.getElementById('globalsearch');
  549.   var elementIFrame = document.getElementById('iframe');
  550.   if (elementSearch != null && elementIFrame != null) {
  551.       if (doShow) {
  552.         elementSearch.style.display = 'block';
  553.         elementIFrame.style.display = 'none';
  554.       }
  555.       else {
  556.         elementSearch.style.display = 'none';
  557.         elementIFrame.style.display = 'block';
  558.       }
  559.  
  560.  
  561.       var resultsElement = document.getElementById('globalsearchresult');
  562.  
  563.       if( resultsElement != null ) {
  564.         resultsElement.style.display = "none";
  565.       }
  566.   }
  567. }
  568.  
  569. function importXML(filename, type) {
  570.   // 1 - local
  571.   // 2 - global
  572.   var xmlDoc = null;
  573.     if (document.implementation && document.implementation.createDocument) {
  574.         xmlDoc = document.implementation.createDocument("", "", null);
  575.     }
  576.     else if (window.ActiveXObject) {
  577.         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  578.      }
  579.     else {
  580.         alert('Your browser can\'t handle this script');
  581.         return;
  582.     }
  583.     xmlDoc.load(filename);
  584.     xmlDoc.setProperty("SelectionLanguage", "XPath");
  585.     if (type == 1) {
  586.       xmlDocLocal = xmlDoc;
  587.     }
  588.     else {
  589.       xmlDocGlobal = xmlDoc;
  590.     }
  591. }
  592.  
  593. function doLocalSearch() {
  594.   var res = '';
  595.  
  596.   var searchText = "";
  597.   var element = document.getElementById('searchinput');
  598.   if (element != null) {
  599.     searchText = element.value;
  600.     searchText = searchText.toLowerCase();
  601.   }
  602.   if (searchText != "") {
  603.     switchLocalSearchDiv(true);
  604.     switchGlobalSearchDiv(false);
  605.  
  606.     if (xmlDocLocal == null) {
  607.       importXML('localsearch.xml', 1);
  608.     }
  609.  
  610.     var xpath = "//t[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //k[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //l[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //la[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //os[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')]  | //f[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] ";
  611.  
  612.     var resultNodes = xmlDocLocal.selectNodes(xpath);
  613.     localResultNodes = getResultArray(resultNodes);
  614.     var html = getResultHTML(localResultNodes, 1);
  615.     var searchContent = document.getElementById('searchContentLocal');
  616.  
  617.     if (searchContent != null) {
  618.       searchContent.innerHTML = html;
  619.       //resizeIFrame();
  620.       redrawResultsTable();
  621.       //executeInnerHTMLJavaScript( searchContent );
  622.     }
  623.  
  624.     switchLocalSearchDiv(true);
  625.   }
  626. }
  627.  
  628. function getLanguageString() {
  629.   var res = '';
  630.   var langElement;
  631.  
  632.   langElement = document.getElementById('searchInLangDE');
  633.   if (langElement != null && langElement.checked) {
  634.     res += "./parent::*/la[contains(., 'deutsch')] and ";
  635.   }
  636.   langElement = document.getElementById('searchInLangEN');
  637.   if (langElement != null && langElement.checked) {
  638.     res += "./parent::*/la[contains(., 'englisch')] and ";
  639.   }
  640.   langElement = document.getElementById('searchInLangFR');
  641.   if (langElement != null && langElement.checked) {
  642.     res += "./parent::*/la[contains(., 'franz├â┼ôsisch')] and ";
  643.   }
  644.   langElement = document.getElementById('searchInLangES');
  645.   if (langElement != null && langElement.checked) {
  646.     res += "./parent::*/la[contains(., 'spanisch')] and ";
  647.   }
  648.   langElement = document.getElementById('searchInLangIT');
  649.   if (langElement != null && langElement.checked) {
  650.     res += "./parent::*/la[contains(., 'italienisch')] and ";
  651.   }
  652.  
  653.   res = res.substr(0, res.length-4);
  654.  
  655.   if (res != '') {
  656.     res = "((" + res + ") or ./parent::*/la[contains(., 'multilingual')])";
  657.   }
  658.   return res;
  659. }
  660.  
  661. function getOSString() {
  662.   var res = '';
  663.   var osElement;
  664.  
  665.   osElement = document.getElementById('searchInOS95');
  666.   if (osElement != null && osElement.checked) {
  667.     res += "./parent::*/os[contains(., 'Windows 95')] and ";
  668.   }
  669.   osElement = document.getElementById('searchInOS98');
  670.   if (osElement != null && osElement.checked) {
  671.     res += "./parent::*/os[contains(., 'Windows 98')] and ";
  672.   }
  673.   osElement = document.getElementById('searchInOSMe');
  674.   if (osElement != null && osElement.checked) {
  675.     res += "./parent::*/os[contains(., 'Windows Me')] and ";
  676.   }
  677.   osElement = document.getElementById('searchInOS2000');
  678.   if (osElement != null && osElement.checked) {
  679.     res += "./parent::*/os[contains(., 'Windows 2000')] and ";
  680.   }
  681.   osElement = document.getElementById('searchInOS2003');
  682.   if (osElement != null && osElement.checked) {
  683.     res += "./parent::*/os[contains(., 'Windows 2003')] and ";
  684.   }
  685.   osElement = document.getElementById('searchInOSXP');
  686.   if (osElement != null && osElement.checked) {
  687.     res += "./parent::*/os[contains(., 'Windows XP')] and ";
  688.   }
  689.   osElement = document.getElementById('searchInOSXP64');
  690.   if (osElement != null && osElement.checked) {
  691.     res += "./parent::*/os[contains(., 'Windows XP 64')] and ";
  692.   }
  693.   osElement = document.getElementById('searchInOSVista');
  694.   if (osElement != null && osElement.checked) {
  695.     res += "./parent::*/os[contains(., 'Windows Vista')] and ";
  696.   }
  697.   osElement = document.getElementById('searchInOSVista64');
  698.   if (osElement != null && osElement.checked) {
  699.     res += "./parent::*/os[contains(., 'Windows Vista 64')] and ";
  700.   }
  701.   osElement = document.getElementById('searchInOS7');
  702.   if (osElement != null && osElement.checked) {
  703.     res += "./parent::*/os[contains(., 'Windows 7')] and ";
  704.   }
  705.   osElement = document.getElementById('searchInOS764');
  706.   if (osElement != null && osElement.checked) {
  707.     res += "./parent::*/os[contains(., 'Windows 7 64')] and ";
  708.   }
  709.  
  710.   res = res.substr(0, res.length-4);
  711.  
  712.   if (res != '') {
  713.     res = "(" + res + ")";
  714.   }
  715.   return res;
  716. }
  717.  
  718. function getGlobalXPathString(searchText) {
  719.   var categoryString = '';
  720.   var res = '';
  721.  
  722.   searchText = searchText.toLowerCase();
  723.  
  724.   // Kategorien
  725.   var catElement = document.getElementById('categoryAll');
  726.   if (catElement != null && !catElement.checked) {
  727.     for (var i=0; i<availableCategories.length; i++) {
  728.       catElement = document.getElementById('category' + i);
  729.       if (catElement != null && catElement.checked) {
  730.         categoryString += "./parent::*[@c='" + availableCategories[i] + "'] or ";
  731.       }
  732.     }
  733.     if (categoryString != '') {
  734.       categoryString = categoryString.substr(0, categoryString.length-3);
  735.       categoryString = "(" + categoryString + ")";
  736.     }
  737.   }
  738.  
  739.   // Sprachen
  740.   var languageString = getLanguageString();
  741.  
  742.   // Betriebsysteme
  743.   var osString = getOSString();
  744.  
  745. //  alert(languageString);
  746.  
  747.   // Ausgaben
  748.   var issueString = '';
  749.   for (var i=0; i<availableIssues.length; i++) {
  750.     var issue = availableIssues[i];
  751.     var year = issue.year;
  752.     var nos = issue.nos;
  753.     var issueElement = document.getElementById('issueyear' + year);
  754.     if (issueElement != null) {
  755.       if (issueElement.checked) {
  756.         // ganzes Jahr
  757.         issueString += "./parent::*/parent::*[@year='" + year + "'] or ";
  758.       }
  759.       else {
  760.         for (var j=0; j<nos.length; j++) {
  761.           var nr = nos[j];
  762.           var issueSubElement = document.getElementById('issueno' + nr + year);
  763.           if (issueSubElement != null && issueSubElement.checked) {
  764.             issueString += "./parent::*/parent::*[@year='" + year + "' and @nr='" + nr + "'] or ";
  765.           }
  766.         }
  767.       }
  768.     }
  769.   }
  770.   if (issueString != '') {
  771.     issueString = issueString.substr(0, issueString.length-3); // -3 damit " or" gefilter wird
  772.     issueString = "(" + issueString + ")";
  773.   }
  774.  
  775.   // im Titel immer suchen
  776.   res += "//t[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  777.   if (categoryString != '') {
  778.     res += " and " + categoryString;
  779.   }
  780.   if (issueString != '') {
  781.     res += " and " + issueString;
  782.   }
  783.   if (languageString != '') {
  784.     res += " and " + languageString;
  785.   }
  786.   if (osString != '') {
  787.     res += " and " + osString;
  788.   }
  789.  
  790.   res += '] | ';
  791.  
  792.   if (document.getElementById('searchInShort').checked) {
  793.       res += "//k[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  794.       if (categoryString != '') {
  795.         res += " and " + categoryString;
  796.       }
  797.       if (issueString != '') {
  798.         res += " and " + issueString;
  799.       }
  800.       if (languageString != '') {
  801.         res += " and " + languageString;
  802.       }
  803.       if (osString != '') {
  804.         res += " and " + osString;
  805.       }
  806.       res += '] | ';
  807.   }
  808.  
  809.   if (document.getElementById('searchInLong').checked) {
  810.       res += "//l[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  811.       if (categoryString != '') {
  812.         res += " and " + categoryString;
  813.       }
  814.       if (issueString != '') {
  815.         res += " and " + issueString;
  816.       }
  817.       if (languageString != '') {
  818.         res += " and " + languageString;
  819.       }
  820.       if (osString != '') {
  821.         res += " and " + osString;
  822.       }
  823.       res += '] | ';
  824.   }
  825.  
  826.   if (document.getElementById('searchInFiles').checked) {
  827.       res += "//f[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  828.       if (categoryString != '') {
  829.         res += " and " + categoryString;
  830.       }
  831.       if (issueString != '') {
  832.         res += " and " + issueString;
  833.       }
  834.       if (languageString != '') {
  835.         res += " and " + languageString;
  836.       }
  837.       if (osString != '') {
  838.         res += " and " + osString;
  839.       }
  840.       res += '] | ';
  841.   }
  842.  
  843.   res = res.substr(0, res.length-2);
  844.  
  845.   return res;
  846. }
  847.  
  848. function searchGlobal_nohistory() {
  849.   var searchText = "";
  850.   var element = document.getElementById('searchglobalinput');
  851.   if (element != null) {
  852.     searchText = element.value;
  853.   }
  854.  
  855.   if (searchText != "") {
  856.     var xpath = getGlobalXPathString(searchText);
  857.     var resultNodes = xmlDocGlobal.selectNodes(xpath);
  858.     globalResultNodes = getResultArray(resultNodes);
  859.     var html = getResultHTML(globalResultNodes, 2);
  860.     var searchContent = document.getElementById('searchContentGlobal');
  861.     if (searchContent != null) {
  862.       searchContent.innerHTML = html;
  863.     }
  864.  
  865.     var resultsElement = document.getElementById('globalsearchresult');
  866.  
  867.     if( resultsElement != null ) {
  868.         resultsElement.style.display = "block";
  869.     } 
  870.  
  871.     toggleTab_nohistory(2);
  872.  
  873.     if (searchContent != null) {
  874.       //resizeIFrame();
  875.       redrawResultsTable();
  876.     }
  877.  
  878.   }
  879. }
  880.  
  881. function searchGlobal() {
  882.   var searchText = "";
  883.   var element = document.getElementById('searchglobalinput');
  884.   if (element != null) {
  885.     searchText = element.value;
  886.   }
  887.  
  888.   if (searchText != "") {
  889.     var xpath = getGlobalXPathString(searchText);
  890.     var resultNodes = xmlDocGlobal.selectNodes(xpath);
  891.     globalResultNodes = getResultArray(resultNodes);
  892.     var html = getResultHTML(globalResultNodes, 2);
  893.     var searchContent = document.getElementById('searchContentGlobal');
  894.     if (searchContent != null) {
  895.       searchContent.innerHTML = html;
  896.     }
  897.  
  898.     var resultsElement = document.getElementById('globalsearchresult');
  899.  
  900.     if( resultsElement != null ) {
  901.         resultsElement.style.display = "block";
  902.     } 
  903.  
  904.     toggleTab(2);
  905.  
  906.     if (searchContent != null) {
  907.       //resizeIFrame();
  908.       redrawResultsTable();
  909.     }
  910.  
  911.   }
  912. }
  913.  
  914. function showDiv(value, divName) {
  915.   var element = document.getElementById(divName);
  916.   if (element != null) {
  917.     if (value) {
  918.       element.style.display = 'block';
  919.     }
  920.     else {
  921.       element.style.display = 'none';
  922.     }
  923.   }
  924. }
  925.  
  926. function showPlaeseWait(value) {
  927.   showDiv(value, 'pleaseWait');
  928. }
  929.  
  930. function showCategoriesDiv(value) {
  931.   showDiv(value, 'searchCategories');
  932. }
  933.  
  934. function showIssuesDiv(value) {
  935.   showDiv(value, 'searchIssues');
  936. }
  937.  
  938. function insertCategoryIntoArray(category) {
  939.   var boolFound = false;
  940.   for (var i=0; i<availableCategories.length; i++) {
  941.     if (availableCategories[i] == category) {
  942.       boolFound = true;
  943.       break;
  944.     }
  945.   }
  946.  
  947.   if (!boolFound) {
  948.     availableCategories.push(category);
  949.   }
  950. }
  951.  
  952. function loadCategories() {
  953.   availableCategories = new Array();
  954.   var category;
  955.   var softwareNodes = xmlDocGlobal.getElementsByTagName('s');
  956.   for (var i=0; i<softwareNodes.length; i++) {
  957.     var softwareNode = softwareNodes[i];
  958.     category = softwareNode.getAttribute('l');
  959.  
  960.     if( category != null && category != "null" ) {
  961.     insertCategoryIntoArray(category);
  962.     }
  963.   }
  964.   availableCategories.sort();
  965. }
  966.  
  967. function insertIssueIntoArray(issueYear, issueNo) {
  968.   var boolFoundYear = false;
  969.   var boolFoundNo = false;
  970.   for (var i=0; i<availableIssues.length; i++) {
  971.     if (availableIssues[i].year == issueYear) {
  972.       boolFoundYear = true;
  973.       for (var j=0; j<availableIssues[i].nos.length; j++) {
  974.         if (availableIssues[i].nos[j] == issueNo) {
  975.           boolFoundNo = true;
  976.           break;
  977.         }
  978.       }
  979.       break;
  980.     }
  981.   }
  982.  
  983.   if (!boolFoundYear) {
  984.     var item = new issueItem();
  985.     item.year = issueYear;
  986.     if (item.nos == null) {
  987.       item.nos = new Array();
  988.     }
  989.     item.nos.push(issueNo);
  990.     availableIssues.push(item);
  991.   }
  992.   else {
  993.     if (!boolFoundNo) {
  994.       var item = availableIssues[i];
  995.       item.nos.push(issueNo);
  996.     }
  997.   }
  998. }
  999.  
  1000. function toggleYear(year) {
  1001.   var element = document.getElementById('year' + year);
  1002.   var elementImage = document.getElementById('plusminus' + year);
  1003.   if (element != null) {
  1004.     if (element.style.display == 'block') {
  1005.       element.style.display = 'none';
  1006.       elementImage.src = 'images/tree_plus.gif';
  1007.     }
  1008.     else {
  1009.       element.style.display = 'block';
  1010.       elementImage.src = 'images/tree_minus.gif';
  1011.     }
  1012.   }
  1013. }
  1014.  
  1015. function loadIssues() {
  1016.   availableIssues = new Array();
  1017.   var issueYear;
  1018.   var issueNo;
  1019.   var issueNodes = xmlDocGlobal.getElementsByTagName('i');
  1020.   for (var i=0; i<issueNodes.length; i++) {
  1021.     var issueNode = issueNodes[i];
  1022.     issueYear = issueNode.getAttribute('year');
  1023.     issueNo = issueNode.getAttribute('nr');
  1024.     insertIssueIntoArray(issueYear, issueNo);
  1025.   }
  1026.   availableCategories.sort();
  1027. }
  1028.  
  1029. function uncheckFirstAllCategory(element) {
  1030.   if (element.checked) {
  1031.     var catAll = document.getElementById('categoryAll');
  1032.     if (catAll != null) {
  1033.       catAll.checked = false;
  1034.     }
  1035.   }
  1036. }
  1037.  
  1038. function uncheckCategories(element) {
  1039.   if (element.checked) {
  1040.     for (var i=0; i<availableCategories.length; i++) {
  1041.         var cat = document.getElementById('category' + i);
  1042.         if (cat != null) {
  1043.           cat.checked = false;
  1044.         }
  1045.     }
  1046.   }
  1047. }
  1048.  
  1049. function setCategoriesHTML() {
  1050.   var element = document.getElementById('searchCategories');
  1051.   if (element != null) {
  1052.     var result = '<strong>Lizenzart ausw├ñhlen</strong><br /><br />';
  1053.     result += '<input type="checkbox" id="categoryAll" onclick="uncheckCategories(this);" checked/>Alle<br>';
  1054.     for (var i=0; i<availableCategories.length; i++) {
  1055.       if (availableCategories[i] != '') {
  1056.         result += '<input type="checkbox" id="category' + i + '" onclick="uncheckFirstAllCategory(this);" />' + availableCategories[i] + '<br />';
  1057.       }
  1058.     }
  1059.     element.innerHTML = result;
  1060.   }
  1061. }
  1062.  
  1063. function selectWholeYear(element) {
  1064.   if (element.checked) {
  1065.     var id = element.id;
  1066.     id = id.substr(9);
  1067.     for (var i=0; i<availableIssues.length; i++) {
  1068.       var issue = availableIssues[i];
  1069.       var year = issue.year;
  1070.       var nos = issue.nos;
  1071.       if (year == id) {
  1072.         for (var j=0; j<nos.length; j++) {
  1073.           var tmp = document.getElementById('issueno' + nos[j] + year);
  1074.           tmp.checked = true;
  1075.         }
  1076.       }
  1077.     }
  1078.   }
  1079. }
  1080.  
  1081. function deselectYear(element, year) {
  1082.   if (!element.checked) {
  1083.     var tmp = document.getElementById('issueyear' + year);
  1084.     if (tmp != null) {
  1085.       tmp.checked = false;
  1086.     }
  1087.   }
  1088. }
  1089.  
  1090. function setIssuesHTML() {
  1091.   var issueNoChecked = '';
  1092.   var element = document.getElementById('searchIssues');
  1093.  
  1094.   if (element != null) {
  1095.     var result = '<strong>Ausgaben ausw├ñhlen</strong><br /><br />';
  1096.     for (var i=0; i<availableIssues.length; i++) {
  1097.       var issue = availableIssues[i];
  1098.       var year = issue.year;
  1099.       var nos = issue.nos;
  1100.       var srcLevel1 = 'images/tree_vert_hor.gif';
  1101.       var srcLevel1Next = 'images/tree_vert.gif';
  1102.       if (i == (availableIssues.length-1)) {
  1103.         srcLevel1 = 'images/tree_vert_hor_end.gif';
  1104.         srcLevel1Next = 'images/blank.gif';
  1105.       }
  1106.  
  1107.       result += '<div class="treeview"><img src="' + srcLevel1 + '" style="border: 0;" /><a href="javascript: void(0);" onclick="toggleYear(\'' + issue.year + '\');"><img src="images/tree_minus.gif" id="plusminus' + issue.year + '" style="border: 0;"/></a>';
  1108.       result += '<div class="treeContainer"><input class="treeinput" type="checkbox" id="issueyear' + issue.year + '" onclick="selectWholeYear(this);" /><span class="treeline"> ' + year + '</span></div><div class="clearDiv"></div>';
  1109.       result += '<div id="year' + issue.year+ '" style="display: block;">';
  1110.       for (var j=0; j<nos.length; j++) {
  1111.         var srcLevel2 = 'images/tree_vert_hor.gif';
  1112.         if (j == (nos.length-1)) {
  1113.           srcLevel2 = 'images/tree_vert_hor_end.gif';
  1114.         }
  1115.         // debug(year + '-' + actYear);
  1116.         // debug(nos[j] + '-' + actNo);
  1117.         if (parseInt(year) == parseInt(actYear) && parseInt(nos[j]) == parseInt(actNo)) {
  1118.  
  1119.           issueNoChecked = 'CHECKED';
  1120.         }
  1121.         result += '<div class="treeview"><img src="' + srcLevel1Next + '"><img src="' + srcLevel2 + '"><input class="treeinput" type="checkbox" id="issueno' + nos[j] + year + '" onclick="deselectYear(this, \'' + year + '\');" ' + issueNoChecked + '/><span class="treeline"> ' + nos[j] + '</span></div><div class="clearDiv"></div>';
  1122.       }
  1123.       result += '</div>';
  1124.     }
  1125.  
  1126.     element.innerHTML = result;
  1127.   }
  1128. }
  1129.  
  1130. function doGlobalSearch_nohistory() {
  1131.   var element = document.getElementById('searchglobalinput');
  1132.  
  1133.   var searchesBox = document.getElementById( "searchesBox" );
  1134.  
  1135.   if( searchesBox != null ) {
  1136.       searchesBox.style.display = "none";
  1137.   }
  1138.  
  1139.   if (element != null) {
  1140.     element.value = '';
  1141.   }
  1142.   
  1143.   toggleTab_nohistory(1);
  1144.   var tabResult = document.getElementById('searchContentGlobal');
  1145.   tabResult.innerHTML = '';
  1146.  
  1147.   switchLocalSearchDiv(false);
  1148.   switchGlobalSearchDiv(true);
  1149.   if (xmlDocGlobal == null) {
  1150.     showPlaeseWait(true);
  1151.     importXML('globalsearch.xml', 2);
  1152.     loadCategories();
  1153.     loadIssues();
  1154.     showPlaeseWait(false);
  1155.     if (availableCategories.length > 0) {
  1156.       setCategoriesHTML();
  1157.       showCategoriesDiv(true);
  1158.     }
  1159.     else {
  1160.       showCategoriesDiv(false);
  1161.     }
  1162.     if (availableIssues.length > 0) {
  1163.       setIssuesHTML();
  1164.       showIssuesDiv(true);
  1165.     }
  1166.     else {
  1167.       showIssuesDiv(false);
  1168.     }
  1169.   }
  1170. }
  1171.  
  1172. function doGlobalSearch() {
  1173.   var element = document.getElementById('searchglobalinput');
  1174.  
  1175.   var searchesBox = document.getElementById( "searchesBox" );
  1176.  
  1177.   if( searchesBox != null ) {
  1178.       searchesBox.style.display = "none";
  1179.   }
  1180.  
  1181.   if (element != null) {
  1182.     element.value = '';
  1183.   }
  1184.  
  1185.   toggleTab(1);
  1186.     
  1187.   var tabResult = document.getElementById('searchContentGlobal');
  1188.   tabResult.innerHTML = '';
  1189.  
  1190.   switchLocalSearchDiv(false);
  1191.   switchGlobalSearchDiv(true);
  1192.   if (xmlDocGlobal == null) {
  1193.     showPlaeseWait(true);
  1194.     importXML('globalsearch.xml', 2);
  1195.     loadCategories();
  1196.     loadIssues();
  1197.     showPlaeseWait(false);
  1198.     if (availableCategories.length > 0) {
  1199.       setCategoriesHTML();
  1200.       showCategoriesDiv(true);
  1201.     }
  1202.     else {
  1203.       showCategoriesDiv(false);
  1204.     }
  1205.     if (availableIssues.length > 0) {
  1206.       setIssuesHTML();
  1207.       showIssuesDiv(true);
  1208.     }
  1209.     else {
  1210.       showIssuesDiv(false);
  1211.     }
  1212.   }
  1213.   
  1214. }
  1215.