home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / paranoia / ParanoiaSetup.exe / Gui / Search.js < prev    next >
Text File  |  2005-04-02  |  9KB  |  376 lines

  1. var g_GlobalAttributes = "";
  2. var g_Interval;
  3. function OnloadSearch()
  4. {
  5.     CommonOnload();
  6.     LoadFileTypes();
  7.     
  8.     ExecuteCommand("SetSearchResultsHeaderTemplate|SEPERATOR|<table width='100%'  border='0' cellpadding='2px' cellspacing='0'>");
  9.     var lsSearchResultsTemplate = "<tr> \
  10.                                 <td align='left' colspan='4' bgcolor='#F1F1F1'><span  onmouseout=hidemeta() onmouseover=showmeta(<ResultID>) class='CommandLink' onclick=downloadfile(<ResultID>)><ResultName></span>  </td>\
  11.                             </tr>\
  12.                             <tr >\
  13.                                 <td align='left' >Size: <ResultSize></td>\
  14.                                 <td align='left'>Avg Speed: <AverageSpeed></td>\
  15.                                 <td align='left'>Host Count: <HostCount></td>\
  16.                                 <td align='left'>SHA1: <SHA1></td>\
  17.                             </tr>";
  18.     var lsCmd = "SetSearchResultsTemplate" + "|SEPERATOR|" + lsSearchResultsTemplate;
  19.     ExecuteCommand(lsCmd);
  20.  
  21.     ExecuteCommand("SetSearchResultsFooterTemplate|SEPERATOR|</table>");
  22.     
  23.     /* Set a 1 sec interval to check if we are connected to the network */
  24.     g_Interval = window.setInterval("IsConnected()",1000);
  25. }
  26.  
  27. /*
  28.  * function: LoadFileTypes
  29.  * Description: Loads the file types and adds them to the combo box.
  30.  * LoadFileTypesFunction will be called with an array of File Types
  31.  */
  32. function LoadFileTypes()
  33. {
  34.     ExecuteCommand("LoadFileTypes|SEPERATOR|LoadFileTypesFunction");
  35. }
  36.  
  37. /*
  38.  * Function: LoadFileTypesFunction
  39.  * Description: This function is called by the program (as set with LoadFileTypes) with the array 
  40.  * of File Types (Names + IDs)
  41.  */
  42. function LoadFileTypesFunction(ar)
  43. {
  44.     var a = new VBArray(ar);
  45.     var b = a.toArray();
  46.     delete a;
  47.  
  48.     for (i=0; i<b.length; i++) 
  49.     {
  50.         /* b contains the Meta Name and the Meta ID 
  51.          * using the following format: MetaName|SEPERATOR|MetaID
  52.          * we need to split it.
  53.          */
  54.         res = b[i].split("|SEPERATOR|");    
  55.         
  56.         try 
  57.         {
  58.             
  59.             var oOption = document.createElement("OPTION");
  60.             oOption.text = res[0];
  61.             oOption.value= res[1];
  62.             FileTypeList.add(oOption);
  63.            }
  64.         catch(e)
  65.         {        
  66.         }
  67.  
  68.  
  69.         
  70.     }
  71. }
  72.  
  73. /*
  74.  * function: ShowMetaAttributes
  75.  * Description: Loads the META attributes according to the ID of the File Types list.
  76.  * MetaAttributesFunction will be called with an array of META attributes
  77.  */
  78. function ShowMetaAttributes()
  79. {
  80.     var Cmd = "GetMetaAttributes|SEPERATOR|" + FileTypeList.value + "|SEPERATOR|MetaAttributesFunction";
  81.     ExecuteCommand(Cmd);
  82. }
  83.  
  84.  
  85. /*
  86.  * Function: MetaAttributesFunction
  87.  * Description: This function is called by the program (as set with GetMetaAttributes) with the array 
  88.  * of META Attributes (Names + IDs)
  89.  */
  90. function MetaAttributesFunction(ar)
  91. {
  92.     
  93.     var a = new VBArray(ar);
  94.     var b = a.toArray();
  95.     delete a;
  96.     
  97.     g_GlobalAttributes = "";
  98.  
  99.     if(FileTypeList.selectedIndex==0)
  100.     {
  101.         AttributesID.innerHTML = "";
  102.         AttributeTitleID.innerHTML = "";
  103.         return;
  104.     }
  105.     
  106.     var lsTempHTML = "";
  107.     var lsTitle = "<span style='background: #CCCCCC; width:100%; padding: 4px; border-left: 1px solid #999999; border-right: 1px solid #999999; border-top: 1px solid #999999;'> " + FileTypeList.options[FileTypeList.selectedIndex].text + "</span><br>";
  108.     AttributeTitleID.innerHTML = lsTitle;
  109.     /* I am creating a dynamic list of attributes that will change for each 
  110.      * META ID. lsTempHTML holds the inputs for each META ID. Once lsTempHTML is
  111.      * ready - it goes into AttributesID.innerHTML.
  112.      */
  113.     for (i=0; i<b.length; i++) 
  114.     {
  115.         /* b contains the Attribute Name and the Attribute ID 
  116.          * using the following format: AttributeName|SEPERATOR|AttributeID
  117.          * we need to split it.
  118.          */
  119.         res = b[i].split("|SEPERATOR|");    
  120.         
  121.         try 
  122.         {
  123.             lsTempHTML += res[0];
  124.             lsTempHTML += ":<BR>";
  125.  
  126.             
  127.             lsTempHTML += "<input style=\"width:22ex;border: 1px solid Black;\" type=text name=\"";
  128.             lsTempHTML += res[0];
  129.             lsTempHTML += "\" >"
  130.             
  131.             lsTempHTML += "<br><br>";
  132.             
  133.             /* Now this is a bit tricky: I'm building a string with the attributes name and values
  134.              * so I can use eval() later when I submit the search. The format for the attributes and
  135.              * values is Attribute:value.
  136.              */
  137.              var lsTmp = "\"" + res[0] + ":\" + " + res[0] + ".value ";
  138.              if(i+1<b.length)
  139.                  lsTmp += " + \"|SEPERATOR|\" + ";
  140.                  
  141.              g_GlobalAttributes += lsTmp;
  142.              
  143.             
  144.            }
  145.         catch(e)
  146.         {        
  147.         }
  148.         
  149.         AttributesID.innerHTML = lsTempHTML;
  150.     }
  151. }
  152.  
  153. /*
  154.  * Function: StartSearch
  155.  * Description: Search the network using the search terms and META data
  156.  */
  157. function StartSearch()
  158. {
  159.     
  160.     var lsSearchString = SearchPhraseInput.value;
  161.     if(lsSearchString.length == 0)
  162.         return;
  163.         
  164.     var lsMetaID = FileTypeList.value;
  165.     var lsAttributes = eval(g_GlobalAttributes);
  166.  
  167.     /* Clearing old data before the new search*/
  168.     SearchResultsID.innerHTML = " ";
  169.     PagingID.style.display = 'none';
  170.     ResultDetailsID.style.display = 'none';
  171.     SearchedNodesID.innerHTML = "";
  172.     
  173.     var Cmd = "StartMETASearch|SEPERATOR|" + lsSearchString + "|SEPERATOR|" + lsMetaID + "|SEPERATOR|" + lsAttributes + "|SEPERATOR|SearchResultsID";
  174.     ExecuteCommand(Cmd);
  175.     StartButton.disabled = true;
  176.     
  177.     
  178. }
  179.  
  180. /*
  181.  * Function: StopSearch
  182.  * Description: Stops the current Search
  183.  */
  184. function StopSearch()
  185. {
  186.     ExecuteCommand("StopSearch");
  187.     StartButton.disabled = false;
  188. }
  189.  
  190. /*
  191.  * Function: showmeta
  192.  * Description: Show the META data in a floating textbox
  193.  */
  194. function showmeta(ResultID)
  195. {
  196.     var lsCmd = "GetMetaData|SEPERATOR|" + ResultID + "|SEPERATOR|MetaID";
  197.     ExecuteCommand(lsCmd);
  198.  
  199.     if(MetaID.innerHTML.length>0)
  200.     {
  201.         
  202.         var intTop = event.clientY + document.body.scrollTop+10;
  203.         var intLeft = event.clientX + document.body.scrollLeft+10;
  204.         
  205.         MetaTextBox.style.pixelTop = intTop;
  206.         MetaTextBox.style.pixelLeft = intLeft;        
  207.         
  208.         var lsText = "<B>Additional Information:</B><br>" + MetaID.innerHTML
  209.         MetaTextBox.innerHTML = lsText;
  210.  
  211.         MetaTextBox.style.display = 'inline';
  212.     }
  213.  
  214. }
  215.  
  216. /*
  217.  * Function: hidemeta
  218.  * Description: Hide the META data textbox
  219.  */
  220. function hidemeta(text)
  221. {
  222.     MetaTextBox.style.display = 'none';
  223.  
  224. }
  225.  
  226. /*
  227.  * function: OnUpdate
  228.  * Description: Fired by the application when an update to the search results occurrs
  229.  */
  230. function OnUpdate()
  231. {
  232.     ExecuteCommand("GetProgress|SEPERATOR|ProgressID");
  233.     
  234.     if(parseInt(ProgressID.innerHTML)>0)
  235.     {
  236.         var lsText = ProgressID.innerHTML + " G2 Nodes Searched, Gnutella Unknown";
  237.         SearchedNodesID.innerHTML = lsText;
  238.     }
  239.     
  240.     ExecuteCommand("IsPaged|SEPERATOR|IsPagedID");
  241.     if(IsPagedID.innerHTML == "1")
  242.         PagingID.style.display = 'inline';
  243.     else
  244.         PagingID.style.display = 'none';
  245.         
  246.     ExecuteCommand("GetStartingResultNumber|SEPERATOR|FirstResultNumberID");
  247.     ExecuteCommand("GetEndingResultNumber|SEPERATOR|EndingResultNumberID");
  248.     ExecuteCommand("GetTotalResultNumber|SEPERATOR|TotalResultNumberID");
  249.     
  250.     
  251.     
  252.     ResultDetailsID.style.display = 'inline';
  253. }
  254.  
  255. /*
  256.  * function: checkKey
  257.  * Description: checks if the user press enter on the search box
  258.  */
  259. function checkKey()
  260. {
  261.     if(window.event.keyCode==13)
  262.     {
  263.         StopSearch();
  264.         StartSearch();
  265.     }
  266.     
  267. }
  268.  
  269. /*
  270.  * function: GoToFirstPage
  271.  * Description: Shows the first page of the list
  272.  */
  273. function GoToFirstPage()
  274. {
  275.     ExecuteCommand("GoToFirstPage");
  276. }
  277.  
  278. /*
  279.  * function: GoToNextPage
  280.  * Description: Shows the next page of the list
  281.  */
  282. function GoToNextPage()
  283. {
  284.     ExecuteCommand("GoToNextPage");
  285. }
  286.  
  287. /*
  288.  * function: GoToPrevPage
  289.  * Description: Shows the previous page of the list
  290.  */
  291. function GoToPrevPage()
  292. {
  293.     ExecuteCommand("GoToPrevPage");
  294. }
  295.  
  296.  
  297. /*
  298.  * function: GoToLastPage
  299.  * Description: Shows the last page of the list
  300.  */
  301. function GoToLastPage()
  302. {
  303.     ExecuteCommand("GoToLastPage");
  304. }
  305.  
  306.  
  307. /*
  308.  * function: SortByName
  309.  * Description: Sorts the list by the file name and updates the GUI
  310.  */
  311. function SortByName()
  312. {
  313.     ExecuteCommand("SortByName");
  314. }
  315.  
  316. /*
  317.  * function: SortBySize
  318.  * Description: Sorts the list by the file size and updates the GUI
  319.  */
  320. function SortBySize()
  321. {
  322.     ExecuteCommand("SortBySize");
  323. }
  324.  
  325. /*
  326.  * function: SortByType
  327.  * Description: Sorts the list by the type size and updates the GUI
  328.  */
  329. function SortByHostCount()
  330. {
  331.     ExecuteCommand("SortByHostCount");
  332. }
  333.  
  334. /*
  335.  * function: SortBySearched
  336.  * Description: Sorts the list by the number of time file was searched and updates the GUI
  337.  */
  338. function SortBySpeed()
  339. {
  340.     ExecuteCommand("SortBySpeed");
  341. }
  342.  
  343. /*
  344.  * function: downloadfile
  345.  * Description: download a specific file by its FileID
  346.  */
  347. function downloadfile(FileID)
  348. {
  349.     var lsCmd = "DownloadFile|SEPERATOR|" + FileID;
  350.     ExecuteCommand(lsCmd);
  351. }
  352.  
  353. /*
  354.  * function: IsConnected
  355.  * Description: Checks if connected to one of the networks and enables/disables the search
  356.  * button accordingly.
  357.  */
  358. function IsConnected()
  359. {
  360.     /*
  361.      * Calling the IsConnected function for connection status of both G1 and G2:
  362.      * 0 - Connecting
  363.      * 1 - Connected
  364.      * 2 - Disconnected
  365.      * Set the result in an Object with the ID = IsConnectedID
  366.      */
  367.     ExecuteCommand("IsConnected|SEPERATOR|IsConnectedID");
  368.  
  369.     if(document.all.IsConnectedID.innerHTML == "1")
  370.     {
  371.         StartButton.disabled = false;
  372.         window.clearInterval(g_Interval);
  373.     }
  374.     
  375.      
  376. }