home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Freeware
/
Programare
/
paranoia
/
ParanoiaSetup.exe
/
Gui
/
Search.js
< prev
next >
Wrap
Text File
|
2005-04-02
|
9KB
|
376 lines
var g_GlobalAttributes = "";
var g_Interval;
function OnloadSearch()
{
CommonOnload();
LoadFileTypes();
ExecuteCommand("SetSearchResultsHeaderTemplate|SEPERATOR|<table width='100%' border='0' cellpadding='2px' cellspacing='0'>");
var lsSearchResultsTemplate = "<tr> \
<td align='left' colspan='4' bgcolor='#F1F1F1'><span onmouseout=hidemeta() onmouseover=showmeta(<ResultID>) class='CommandLink' onclick=downloadfile(<ResultID>)><ResultName></span> </td>\
</tr>\
<tr >\
<td align='left' >Size: <ResultSize></td>\
<td align='left'>Avg Speed: <AverageSpeed></td>\
<td align='left'>Host Count: <HostCount></td>\
<td align='left'>SHA1: <SHA1></td>\
</tr>";
var lsCmd = "SetSearchResultsTemplate" + "|SEPERATOR|" + lsSearchResultsTemplate;
ExecuteCommand(lsCmd);
ExecuteCommand("SetSearchResultsFooterTemplate|SEPERATOR|</table>");
/* Set a 1 sec interval to check if we are connected to the network */
g_Interval = window.setInterval("IsConnected()",1000);
}
/*
* function: LoadFileTypes
* Description: Loads the file types and adds them to the combo box.
* LoadFileTypesFunction will be called with an array of File Types
*/
function LoadFileTypes()
{
ExecuteCommand("LoadFileTypes|SEPERATOR|LoadFileTypesFunction");
}
/*
* Function: LoadFileTypesFunction
* Description: This function is called by the program (as set with LoadFileTypes) with the array
* of File Types (Names + IDs)
*/
function LoadFileTypesFunction(ar)
{
var a = new VBArray(ar);
var b = a.toArray();
delete a;
for (i=0; i<b.length; i++)
{
/* b contains the Meta Name and the Meta ID
* using the following format: MetaName|SEPERATOR|MetaID
* we need to split it.
*/
res = b[i].split("|SEPERATOR|");
try
{
var oOption = document.createElement("OPTION");
oOption.text = res[0];
oOption.value= res[1];
FileTypeList.add(oOption);
}
catch(e)
{
}
}
}
/*
* function: ShowMetaAttributes
* Description: Loads the META attributes according to the ID of the File Types list.
* MetaAttributesFunction will be called with an array of META attributes
*/
function ShowMetaAttributes()
{
var Cmd = "GetMetaAttributes|SEPERATOR|" + FileTypeList.value + "|SEPERATOR|MetaAttributesFunction";
ExecuteCommand(Cmd);
}
/*
* Function: MetaAttributesFunction
* Description: This function is called by the program (as set with GetMetaAttributes) with the array
* of META Attributes (Names + IDs)
*/
function MetaAttributesFunction(ar)
{
var a = new VBArray(ar);
var b = a.toArray();
delete a;
g_GlobalAttributes = "";
if(FileTypeList.selectedIndex==0)
{
AttributesID.innerHTML = "";
AttributeTitleID.innerHTML = "";
return;
}
var lsTempHTML = "";
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>";
AttributeTitleID.innerHTML = lsTitle;
/* I am creating a dynamic list of attributes that will change for each
* META ID. lsTempHTML holds the inputs for each META ID. Once lsTempHTML is
* ready - it goes into AttributesID.innerHTML.
*/
for (i=0; i<b.length; i++)
{
/* b contains the Attribute Name and the Attribute ID
* using the following format: AttributeName|SEPERATOR|AttributeID
* we need to split it.
*/
res = b[i].split("|SEPERATOR|");
try
{
lsTempHTML += res[0];
lsTempHTML += ":<BR>";
lsTempHTML += "<input style=\"width:22ex;border: 1px solid Black;\" type=text name=\"";
lsTempHTML += res[0];
lsTempHTML += "\" >"
lsTempHTML += "<br><br>";
/* Now this is a bit tricky: I'm building a string with the attributes name and values
* so I can use eval() later when I submit the search. The format for the attributes and
* values is Attribute:value.
*/
var lsTmp = "\"" + res[0] + ":\" + " + res[0] + ".value ";
if(i+1<b.length)
lsTmp += " + \"|SEPERATOR|\" + ";
g_GlobalAttributes += lsTmp;
}
catch(e)
{
}
AttributesID.innerHTML = lsTempHTML;
}
}
/*
* Function: StartSearch
* Description: Search the network using the search terms and META data
*/
function StartSearch()
{
var lsSearchString = SearchPhraseInput.value;
if(lsSearchString.length == 0)
return;
var lsMetaID = FileTypeList.value;
var lsAttributes = eval(g_GlobalAttributes);
/* Clearing old data before the new search*/
SearchResultsID.innerHTML = " ";
PagingID.style.display = 'none';
ResultDetailsID.style.display = 'none';
SearchedNodesID.innerHTML = "";
var Cmd = "StartMETASearch|SEPERATOR|" + lsSearchString + "|SEPERATOR|" + lsMetaID + "|SEPERATOR|" + lsAttributes + "|SEPERATOR|SearchResultsID";
ExecuteCommand(Cmd);
StartButton.disabled = true;
}
/*
* Function: StopSearch
* Description: Stops the current Search
*/
function StopSearch()
{
ExecuteCommand("StopSearch");
StartButton.disabled = false;
}
/*
* Function: showmeta
* Description: Show the META data in a floating textbox
*/
function showmeta(ResultID)
{
var lsCmd = "GetMetaData|SEPERATOR|" + ResultID + "|SEPERATOR|MetaID";
ExecuteCommand(lsCmd);
if(MetaID.innerHTML.length>0)
{
var intTop = event.clientY + document.body.scrollTop+10;
var intLeft = event.clientX + document.body.scrollLeft+10;
MetaTextBox.style.pixelTop = intTop;
MetaTextBox.style.pixelLeft = intLeft;
var lsText = "<B>Additional Information:</B><br>" + MetaID.innerHTML
MetaTextBox.innerHTML = lsText;
MetaTextBox.style.display = 'inline';
}
}
/*
* Function: hidemeta
* Description: Hide the META data textbox
*/
function hidemeta(text)
{
MetaTextBox.style.display = 'none';
}
/*
* function: OnUpdate
* Description: Fired by the application when an update to the search results occurrs
*/
function OnUpdate()
{
ExecuteCommand("GetProgress|SEPERATOR|ProgressID");
if(parseInt(ProgressID.innerHTML)>0)
{
var lsText = ProgressID.innerHTML + " G2 Nodes Searched, Gnutella Unknown";
SearchedNodesID.innerHTML = lsText;
}
ExecuteCommand("IsPaged|SEPERATOR|IsPagedID");
if(IsPagedID.innerHTML == "1")
PagingID.style.display = 'inline';
else
PagingID.style.display = 'none';
ExecuteCommand("GetStartingResultNumber|SEPERATOR|FirstResultNumberID");
ExecuteCommand("GetEndingResultNumber|SEPERATOR|EndingResultNumberID");
ExecuteCommand("GetTotalResultNumber|SEPERATOR|TotalResultNumberID");
ResultDetailsID.style.display = 'inline';
}
/*
* function: checkKey
* Description: checks if the user press enter on the search box
*/
function checkKey()
{
if(window.event.keyCode==13)
{
StopSearch();
StartSearch();
}
}
/*
* function: GoToFirstPage
* Description: Shows the first page of the list
*/
function GoToFirstPage()
{
ExecuteCommand("GoToFirstPage");
}
/*
* function: GoToNextPage
* Description: Shows the next page of the list
*/
function GoToNextPage()
{
ExecuteCommand("GoToNextPage");
}
/*
* function: GoToPrevPage
* Description: Shows the previous page of the list
*/
function GoToPrevPage()
{
ExecuteCommand("GoToPrevPage");
}
/*
* function: GoToLastPage
* Description: Shows the last page of the list
*/
function GoToLastPage()
{
ExecuteCommand("GoToLastPage");
}
/*
* function: SortByName
* Description: Sorts the list by the file name and updates the GUI
*/
function SortByName()
{
ExecuteCommand("SortByName");
}
/*
* function: SortBySize
* Description: Sorts the list by the file size and updates the GUI
*/
function SortBySize()
{
ExecuteCommand("SortBySize");
}
/*
* function: SortByType
* Description: Sorts the list by the type size and updates the GUI
*/
function SortByHostCount()
{
ExecuteCommand("SortByHostCount");
}
/*
* function: SortBySearched
* Description: Sorts the list by the number of time file was searched and updates the GUI
*/
function SortBySpeed()
{
ExecuteCommand("SortBySpeed");
}
/*
* function: downloadfile
* Description: download a specific file by its FileID
*/
function downloadfile(FileID)
{
var lsCmd = "DownloadFile|SEPERATOR|" + FileID;
ExecuteCommand(lsCmd);
}
/*
* function: IsConnected
* Description: Checks if connected to one of the networks and enables/disables the search
* button accordingly.
*/
function IsConnected()
{
/*
* Calling the IsConnected function for connection status of both G1 and G2:
* 0 - Connecting
* 1 - Connected
* 2 - Disconnected
* Set the result in an Object with the ID = IsConnectedID
*/
ExecuteCommand("IsConnected|SEPERATOR|IsConnectedID");
if(document.all.IsConnectedID.innerHTML == "1")
{
StartButton.disabled = false;
window.clearInterval(g_Interval);
}
}