// REQUIRES JQUERY TO BE REFERENCED TO SITE 

function DocumentSearch(sSearchText, lFolderId)
{
	var sParam;
	var oXML;
	var oRoot;
	var aHTML = [];
	var h = -1;
	
	var divLoadPages = $('#divLoadPages');
	//divLoadPages.style.display = 'block';
	//divLoadPages.setAttribute("class", "");
	
	if (sSearchText == undefined)
	{
		sSearchText = $('#inputSearchText').val()
	}
	
	sParam = 'method=SITE_DOCUMENT_SEARCH&site=1164&hasurl=1&quicksearch=' + sSearchText;
	
	//NOTES
	//&quicksearch= - searches across title, summary, keywords and url
	//&hasurl=1 - forces to only return docs with a URL
	//folder=[folderid]
	//&includeattachmentcount=1 - return count of attachments
	//&count=1 - returns row count with the data.
	//&includemynetworkgroups=1 - includes documents in network groups - user has to be logged on.
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName('ondemand').item(0);

	if (oRoot.hasChildNodes())
	{
	
		aHTML[++h] = '<table id="tableSearchResults" class="searchResults" border="0" width="600">'
		aHTML[++h] = '<tbody>'
		aHTML[++h] = '<tr>'
		aHTML[++h] = '<td style="width: 100px;">Title</td>'
		aHTML[++h] = '<td style="width: 350px;">Summary</td>'
		aHTML[++h] = '</tr>'
		
	  	for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			
			aHTML[++h] = '<tr><td style="width: 150px;" class="searchResult">' +
							'<h2><a href="' + onDemandXMLGetData(oRow, "url") +
							'" class="searchResult" id="document-' + onDemandXMLGetData(oRow, "id") + '">' +
							onDemandXMLGetData(oRow, "title") +
							'</a></h2></td>';
							
			aHTML[++h] = '<td class="searchResult"><h3>' +
							onDemandXMLGetData(oRow, "keywords") + '</h3><p>' +
							onDemandXMLGetData(oRow, "summary") +
							'</p></td></tr>';	
		}	
		
		aHTML[++h] = '</tbody>'
		aHTML[++h] = '</table>'	
		
	}
	else
	{
		aHTML[++h] = '<table><tr><td><i>No search results.</i></td></tr></table>'
	}

	$("#divSearchResults").html(aHTML.join(''));
	
}

function homeSearch()
{
	// alert('/search/' + document.getElementById("inputSearchText").value);
	document.location.href = '/search/' + document.getElementById("inputSearchText").value
}

