/*******************************************************
*	Method: 	showhide
*	
*	Purpose: 	Hides one div and displays the other.
*
********************************************************/
function showhide(show,hide1)
{
	//Set one div to be visible
	show=eval(show);
	
	show.style.display='inline';
	
	//Create an array to hide all other divs
	divHidden=new Array();
	divHidden[0]=hide1;		
	
	hide1=eval(divHidden[0]);
	hide1.style.display='none';
}

/*******************************************************
*	Method: 	MouseOverButton
*	
*	Purpose: 	Changes the image displayed in the 
*			button space upon moving the mouse over the
*			button space to make the button appear to
*			be highlighted.
*
********************************************************/
function MouseOverButton(leftImg,button,rightImg)
{
	ImgL = document.getElementById(leftImg);
	ImgR = document.getElementById(rightImg);
	
	if (button.style.backgroundImage == "url(../publicaccess/Images/Button/Up/Middle_pix.gif)")
	{
		ImgL.src = "../publicaccess/Images/Button/Over/Left.gif";
		button.style.backgroundImage = "url(../publicaccess/Images/Button/Over/Middle_pix.gif)";
		ImgR.src = "../publicaccess/Images/Button/Over/Right.gif";
	}
	else
	{
		ImgL.src = "../publicaccess/Images/Button/Up/Left.gif";
		button.style.backgroundImage = "url(../publicaccess/Images/Button/Up/Middle_pix.gif)";
		ImgR.src = "../publicaccess/Images/Button/Up/Right.gif";
	}
}

/*******************************************************
*	Method: 	on_load
*	
*	Purpose: 	Performs the functions necessary upon loading
*			the form.
*
********************************************************/
function on_load()
{
	getQueries();
}

/*******************************************************
*	Method: 	getQueries
*	
*	Purpose: 	Retrieves the Custom Queries that the user
*			may perform from OnBase.
*
********************************************************/
function getQueries()
{
	var soaURL = "../publicaccess/PublicAccessProvider.ashx";
	var requestor = new AjaxRequestor(soaURL, "action=getQueries", getQueries_callBack);
}

/*******************************************************
*	Method: 	getKeywords
*	
*	Purpose: 	Retrieves the Keywords that are used in the 
*			selected Custom Query.
*
********************************************************/
function getKeywords()
{
	var queryID = "";
	
	if (document.getElementById("queryList") != null)
	{
		var indexNum = document.getElementById("queryList").selectedIndex;
		queryID = document.getElementById("queryList").options[indexNum].value;
	}
	else
	{
		queryID = document.getElementById("singleQuery").childNodes[0].id;
	}
	
	var soaURL = "../publicaccess/PublicAccessProvider.ashx";
	var requestor = new AjaxRequestor(soaURL, "action=getKeywords&queryID=" + queryID, getKeywords_callBack)
}

/*******************************************************
*	Method: 	getQueries_callBack
*	
*	Purpose: 	Creates the Custom Query selection control
*			from the list of Custom Queries returned from
*			OnBase.
*
********************************************************/
function getQueries_callBack()
{
	var response = this.req.responseText;
	var responseRegEx = new RegExp("<ERROR>", ["i"]);
	var SelectQuery = document.getElementById("selectSearch");
	
	if (response.search(responseRegEx) == -1)
	{
		if (document.getElementById("singleQuery") == null)
		{
			SelectQuery.innerText = "Select Search Type";
			fillDropdown(this.req.responseText);
			document.getElementById("queryList").selectedIndex = 0;
			getKeywords();
		}
		else
		{
			document.getElementById("selectSearch").innerHTML = "";
			setSingleQuery(this.req.responseText);
			getKeywords();
		}
	}
	else
	{
		var errorMsg = "<h3>Authentication failed.  Please check the configuration settings.</h3>";
		document.write(errorMsg);
	}
}

/*******************************************************
*	Method: 	setSingleQuery
*	
*	Purpose: 	Creates the Query control using a single 
*			Custom Query.
*
********************************************************/
function setSingleQuery(responseText)
{
	var singleQueryDiv = document.getElementById("singleQuery");
	var singleQueryInfo = singleQueryDiv.childNodes.item(0);
	/*
	Check to see if we are using IE
	*/
	if (window.ActiveXObject)
	{
		/*
		Create xmldoc and load responseText
		*/	
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.loadXML(responseText);
		var nodeList = xmlDoc.selectNodes("CustomQueriesCollection/CustomQuery");
		var length = nodeList.length;
		var queryFound = false;
		/*
		Loop through the custom queries in the xml
		*/

		for (var i=0; i < length; i++)
		{
		
			var xmlNode = nodeList[i];
			/*
			Loop through the query list to find the correct query to show 
			*/
			if (xmlNode.selectSingleNode("QueryID").text == singleQueryInfo.id)
			{
				singleQueryInfo.innerText = xmlNode.selectSingleNode("QueryName").text;
				queryFound = true;
				break;
			}	
		}
		if (queryFound == false)
		{
			document.write("<h3>Invalid query id</h3>");
		}
	}
	/*
	If this is Firefox/Seamonkey/Safari
	*/
	else if(document.implementation && document.implementation.createDocument)
	{
		/*
		Create a parser, add response text and then create node list
		*/										
		var parser = new DOMParser();
		var doc = parser.parseFromString(responseText,"application/xml");
		doc.async = false;
		var x = doc.documentElement;
		var nodeList = x.childNodes;
		nodeList = x.childNodes;
		var length = nodeList.length;
		var queryFound = false;
		/*
		Loop through the query list to find the correct query to show 
		*/
		for (var i=0; i < length; i++)
		{
			var xmlNode = nodeList[i];
			var subNodeList = xmlNode.childNodes;
			/*
			For each custom query, create an option object and add the
			query name as the option text and query id as the option value
			and then add the option to the select list
			*/
			if (subNodeList[0].childNodes[0].nodeValue == singleQueryInfo.id)
			{
				queryFound = true;
				singleQueryInfo.innerHTML = subNodeList[1].childNodes[0].nodeValue;
				break;
			}		
		}
		if (queryFound == false)
		{
			document.write("<h3>Invalid query id</h3>");
		}
	}
	else
	{
		alert("Browser failed to create object");
	}
}

/*******************************************************
*	Method: 	fillDropdown
*	
*	Purpose: 	Fills the Custom Query selection control with
*			the Custom Queries returned by OnBase.
*
********************************************************/
function fillDropdown(responseText)
{
	var dropDown = document.getElementById("queryList");
	/*
	Check to see if we are using IE
	*/
	if (window.ActiveXObject)
	{
		/*
		Create xmldoc and load responseText
		*/	
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.loadXML(responseText);
		var nodeList = xmlDoc.selectNodes("CustomQueriesCollection/CustomQuery");
		var length = nodeList.length;
		/*
		Loop through the custom queries in the xml
		*/	
		for (var i=0; i < length; i++)
		{
		
			xmlNode = nodeList[i];
			/*
			For each custom query, create an option object and add the
			query name as the option text and query id as the option value
			and then add the option to the select list
			*/	
			var newOption = document.createElement("OPTION");
			newOption.text = xmlNode.selectSingleNode("QueryName").text;
			newOption.value =  xmlNode.selectSingleNode("QueryID").text;
			dropDown.add(newOption);
		}
	}
	/*
	If this is Firefox/Seamonkey/Safari
	*/
	else if(document.implementation && document.implementation.createDocument)
	{
		/*
		Create a parser, add response text and then create node list
		*/										
		var parser = new DOMParser();
		var doc = parser.parseFromString(responseText,"application/xml");
		doc.async = false;
		var x = doc.documentElement;
		var nodeList = x.childNodes;
		nodeList = x.childNodes;
		var length = nodeList.length;
		/*
		Loop through the list to get query information
		*/
		for (var i=0; i < length; i++)
		{
			xmlNode = nodeList[i];
			subNodeList = xmlNode.childNodes;
			/*
			For each custom query, create an option object and add the
			query name as the option text and query id as the option value
			and then add the option to the select list
			*/	
			var newOption = document.createElement("option");
			newOption.text = subNodeList[1].childNodes[0].nodeValue;
			newOption.value =  subNodeList[0].childNodes[0].nodeValue;

			dropDown.options[i] = newOption;
			
		}
	}
	else
	{
		alert("Browser failed to create object");
	}
}

/*******************************************************
*	Method: 	getKeywords_callBack
*	
*	Purpose: 	Handles the call back from the Web Service
*			request to retrieve Keywords.
*
********************************************************/
function getKeywords_callBack()
{
	var strKeywords = this.req.reponseText;
	createKeywords(this.req.responseText);
}

/*******************************************************
*	Method: 	createKeywords
*	
*	Purpose: 	Creates the Keyword controls from the list of
*			Keywords returned from OnBase.
*
********************************************************/
function createKeywords(responseText)
{
	var dropDown = document.getElementById("queryList");
	var keywordPanel = document.getElementById("keywordPanel");
	/*
	Check to see if IE
	*/	
	if (window.ActiveXObject)
	{
		/*
		Create xmlDoc object and load in responseText
		*/
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.loadXML(responseText);
		var nodeList = xmlDoc.selectNodes("Collection/KeywordGroup/KeywordTypeCollection/KeywordType");
		var length = nodeList.length;
		var keywordHtml = "<table width=100% border=0 class=bglight>";
		/*
		Loop through the kewyord xml
		*/	
		for (var i=0; i < length; i++)
		{
			xmlNode = nodeList[i];
			/*
			For each node, add html to add text with the kewyord's name
			and then an input box below using the keyword's id as the input
			box's id
			*/
			keywordHtml += "<tr><td>";
			keywordHtml += xmlNode.selectSingleNode("Name").text;
			if (xmlNode.selectSingleNode("Name").text == "Jurisdiction")
			{
				keywordHtml += "<br><select style='width:150px' id=";
				keywordHtml += xmlNode.selectSingleNode("ID").text;
				keywordHtml += " name=Jurisdiction_List_1 class=default>";
				
				//Populate the drop down based on the Query selected
				keywordHtml += "<option id=Jurisdiction_1 value='NULL'>All</option>";
				keywordHtml += "<option id=Jurisdiction_2 value='ANN ARBOR CITY'>Ann Arbor City</option>";
				keywordHtml += "<option id=Jurisdiction_3 value='ANN ARBOR TOWNSHIP'>Ann Arbor Township</option>";
				keywordHtml += "<option id=Jurisdiction_4 value='AUGUSTA TOWNSHIP'>Augusta Township</option>";
				keywordHtml += "<option id=Jurisdiction_5 value='BRIDGEWATER TOWNSHIP'>Bridgewater Township</option>";
				keywordHtml += "<option id=Jurisdiction_6 value='CHELSEA CITY'>Chelsea City</option>";
				keywordHtml += "<option id=Jurisdiction_7 value='DEXTER TOWNSHIP'>Dexter Township</option>";
				keywordHtml += "<option id=Jurisdiction_8 value='DEXTER VILLAGE'>Dexter Village</option>";
				keywordHtml += "<option id=Jurisdiction_9 value='FREEDOM TOWNSHIP'>Freedom Township</option>";
				keywordHtml += "<option id=Jurisdiction_10 value='LIMA TOWNSHIP'>Lima Township</option>";
				keywordHtml += "<option id=Jurisdiction_11 value='LODI TOWNSHIP'>Lodi Township</option>";
				keywordHtml += "<option id=Jurisdiction_12 value='LYNDON TOWNSHIP'>Lyndon Township</option>";
				keywordHtml += "<option id=Jurisdiction_13 value='MANCHESTER TOWNSHIP'>Manchester Township</option>";
				keywordHtml += "<option id=Jurisdiction_14 value='MANCHESTER VILLAGE'>Manchester Village</option>";
				keywordHtml += "<option id=Jurisdiction_15 value='MILAN CITY'>Milan City</option>";
				keywordHtml += "<option id=Jurisdiction_16 value='NORTHFIELD TOWNSHIP'>Northfield Township</option>";
				keywordHtml += "<option id=Jurisdiction_17 value='PITTSFIELD TOWNSHIP'>Pittsfield Township</option>";
				keywordHtml += "<option id=Jurisdiction_18 value='SALEM TOWNSHIP'>Salem Township</option>";
				keywordHtml += "<option id=Jurisdiction_19 value='SALEM VILLAGE'>Salem Village</option>";
				keywordHtml += "<option id=Jurisdiction_20 value='SALINE CITY'>Saline City</option>";
				keywordHtml += "<option id=Jurisdiction_21 value='SALINE TOWNSHIP'>Saline Township</option>";
				keywordHtml += "<option id=Jurisdiction_22 value='SCIO TOWNSHIP'>Scio Township</option>";
				keywordHtml += "<option id=Jurisdiction_23 value='SHARON TOWNSHIP'>Sharon Township</option>";
				keywordHtml += "<option id=Jurisdiction_24 value='SUPERIOR TOWNSHIP'>Superior Township</option>";
				keywordHtml += "<option id=Jurisdiction_25 value='SYLVAN TOWNSHIP'>Sylvan Township</option>";
				keywordHtml += "<option id=Jurisdiction_26 value='WEBSTER TOWNSHIP'>Webster Township</option>";
				keywordHtml += "<option id=Jurisdiction_27 value='YORK TOWNSHIP'>York Township</option>";
				keywordHtml += "<option id=Jurisdiction_28 value='YPSILANTI CITY'>Ypsilanti City</option>";
				keywordHtml += "<option id=Jurisdiction_29 value='YPSILANTI TOWNSHIP'>Ypsilanti Township</option>";
				
				keywordHtml += "</select>";
			}
			else
			{
				keywordHtml += "<br><input size=26 id=";
				keywordHtml += xmlNode.selectSingleNode("ID").text;
				keywordHtml += " class=default"
				switch(xmlNode.selectSingleNode("Name").text)
				{
					case "Case Number":
						keywordHtml += " maxlength=15";
						break;
					case "Contractor Name":
						keywordHtml += " maxlength=50";
						break;
					case "Owner Last Name":
						keywordHtml += " maxlength=35";
						break;
					case "Parcel ID":
						keywordHtml += " maxlength=20";
						break;
					case "Street  Name":
						keywordHtml += " maxlength=40";
						break;
					case "Street  #":
						keywordHtml += " maxlength=15";
						break;
				}
				keywordHtml += ">";
			}
			keywordHtml += "</td></tr>";
		}
		keywordHtml += "</table>";
		keywordPanel.innerHTML = keywordHtml;
	}
	else if(document.implementation && document.implementation.createDocument)
	{
		/*
		Create the parser and load up the xml
		*/
		var parser = new DOMParser();
		var doc = parser.parseFromString(responseText,"application/xml");
		var nodeList = doc.getElementsByTagName("KeywordTypeCollection")[0].childNodes;
		var length = nodeList.length;
		var keywordHtml = "<table width=100% border=0 class=bglight>";
		/*
		Loop through the xml
		*/
		for (var i=0; i < length; i++)
		{
			/*
			Get the individual keyword node
			*/
			var xmlNode = nodeList[i];
			var nodeLength = xmlNode.childNodes.length;
			var keywordName = "";
			var keywordID = "";
			/*
			Loop through the keyword node to get the id and name
			*/
			for (var x=0; x < nodeLength; x++)
			{
				if (xmlNode.childNodes[x].nodeName == "Name")
				{
					keywordName = xmlNode.childNodes[x].childNodes[0].nodeValue;
				}
				if (xmlNode.childNodes[x].nodeName == "ID")
				{
					keywordID = xmlNode.childNodes[x].childNodes[0].nodeValue;
				}

			}
			
			/*
			For each node, add html to add text with the kewyord's name
			and then an input box below using the keyword's id as the input
			box's id
			*/
			keywordHtml += "<tr><td>";
			keywordHtml += keywordName;
			if (xmlNode.selectSingleNode("Name").text == "Jurisdiction")
			{
				keywordHtml += "<br><select style='width:150px' id=";
				keywordHtml += xmlNode.selectSingleNode("ID").text;
				keywordHtml += " name=Jurisdiction_List_1 class=default>";
				
				//Populate the drop down
				keywordHtml += "<option id=Jurisdiction_1 value='NULL'>All</option>";
				keywordHtml += "<option id=Jurisdiction_2 value='ANN ARBOR CITY'>Ann Arbor City</option>";
				keywordHtml += "<option id=Jurisdiction_3 value='ANN ARBOR TOWNSHIP'>Ann Arbor Township</option>";
				keywordHtml += "<option id=Jurisdiction_4 value='AUGUSTA TOWNSHIP'>Augusta Township</option>";
				keywordHtml += "<option id=Jurisdiction_5 value='BRIDGEWATER TOWNSHIP'>Bridgewater Township</option>";
				keywordHtml += "<option id=Jurisdiction_6 value='CHELSEA CITY'>Chelsea City</option>";
				keywordHtml += "<option id=Jurisdiction_7 value='DEXTER TOWNSHIP'>Dexter Township</option>";
				keywordHtml += "<option id=Jurisdiction_8 value='DEXTER VILLAGE'>Dexter Village</option>";
				keywordHtml += "<option id=Jurisdiction_9 value='FREEDOM TOWNSHIP'>Freedom Township</option>";
				keywordHtml += "<option id=Jurisdiction_10 value='LIMA TOWNSHIP'>Lima Township</option>";
				keywordHtml += "<option id=Jurisdiction_11 value='LODI TOWNSHIP'>Lodi Township</option>";
				keywordHtml += "<option id=Jurisdiction_12 value='LYNDON TOWNSHIP'>Lyndon Township</option>";
				keywordHtml += "<option id=Jurisdiction_13 value='MANCHESTER TOWNSHIP'>Manchester Township</option>";
				keywordHtml += "<option id=Jurisdiction_14 value='MANCHESTER VILLAGE'>Manchester Village</option>";
				keywordHtml += "<option id=Jurisdiction_15 value='MILAN CITY'>Milan City</option>";
				keywordHtml += "<option id=Jurisdiction_16 value='NORTHFIELD TOWNSHIP'>Northfield Township</option>";
				keywordHtml += "<option id=Jurisdiction_17 value='PITTSFIELD TOWNSHIP'>Pittsfield Township</option>";
				keywordHtml += "<option id=Jurisdiction_18 value='SALEM TOWNSHIP'>Salem Township</option>";
				keywordHtml += "<option id=Jurisdiction_19 value='SALEM VILLAGE'>Salem Village</option>";
				keywordHtml += "<option id=Jurisdiction_20 value='SALINE CITY'>Saline City</option>";
				keywordHtml += "<option id=Jurisdiction_21 value='SALINE TOWNSHIP'>Saline Township</option>";
				keywordHtml += "<option id=Jurisdiction_22 value='SCIO TOWNSHIP'>Scio Township</option>";
				keywordHtml += "<option id=Jurisdiction_23 value='SHARON TOWNSHIP'>Sharon Township</option>";
				keywordHtml += "<option id=Jurisdiction_24 value='SUPERIOR TOWNSHIP'>Superior Township</option>";
				keywordHtml += "<option id=Jurisdiction_25 value='SYLVAN TOWNSHIP'>Sylvan Township</option>";
				keywordHtml += "<option id=Jurisdiction_26 value='WEBSTER TOWNSHIP'>Webster Township</option>";
				keywordHtml += "<option id=Jurisdiction_27 value='YORK TOWNSHIP'>York Township</option>";
				keywordHtml += "<option id=Jurisdiction_28 value='YPSILANTI CITY'>Ypsilanti City</option>";
				keywordHtml += "<option id=Jurisdiction_29 value='YPSILANTI TOWNSHIP'>Ypsilanti Township</option>";
				
				keywordHtml += "</select>";
			}
			else
			{
				keywordHtml += "<br><input size=26 id=";
				keywordHtml += keywordID;
				keywordHtml += " class=default";			
				switch(xmlNode.selectSingleNode("Name").text)
				{
					case "Case Number":
						keywordHtml += " maxlength=15";
						break;
					case "Contractor Name":
						keywordHtml += " maxlength=50";
						break;
					case "Owner Last Name":
						keywordHtml += " maxlength=35";
						break;
					case "Parcel ID":
						keywordHtml += " maxlength=20";
						break;
					case "Street Name":
						keywordHtml += " maxlength=40";
						break;
					case "Street #":
						keywordHtml += " maxlength=15";
						break;
				}
			}
			keywordHtml += "></td></tr>";			
		}
	}
	
	keywordHtml += "</table>";
	keywordPanel.innerHTML = keywordHtml;
}

/*******************************************************
*	Method: 	AjaxRequestor
*	
*	Purpose: 	Makes web requests using AJAX.
*
********************************************************/
function AjaxRequestor(url, params, callback)
{
	this.req = null;
	this.callback = callback;
	this.load(url, params);
}AjaxRequestor.prototype.load = function(url, params)
{
	var requestor = this;
	if (window.ActiveXObject)
	{
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest)
	{
		this.req = new XMLHttpRequest();
	}
	else
	{
		alert("Browser failed to create object");
	}
	this.req.onreadystatechange =  function()
	{
		requestor.onreadystatechange.call(requestor);
	}
	this.req.open("POST", url, true);
	this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.req.send(params);
}
AjaxRequestor.prototype.onreadystatechange = function()
{
	if(this.req.readyState == 4)
	{
		this.callback.call(this);
	}
}

/*******************************************************
*	Method: 	ClearKeywords
*	
*	Purpose: 	Clears values in the Keyword fields.
*
********************************************************/
function ClearKeywords()
{
	var inputArray = document.getElementsByTagName("input");
	var arrayLen = inputArray.length;
	var jurisdictionList = document.getElementsByTagName("select");
	var jurisdiction;
	var listLen = jurisdictionList.length;
	var i;
	
	// Clear all of the input fields
	for(i=0; i < arrayLen; i++)
	{
		if (inputArray[i].value != "" && inputArray[i].type != "hidden" && inputArray[i].type != "button")
		{
			inputArray[i].value = "";
		}
	}
	
	// Select the first item in the Jurisdiction select control
	for(i=0; i < listLen; i++)
	{
		if (jurisdictionList[i].name == "Jurisdiction_List_1")
		{
			jurisdiction = jurisdictionList[i];	
			jurisdiction.options[0].selected = true;
		}
	}
	
}

/*******************************************************
*	Method: 	Search
*	
*	Purpose: 	Performs the selected Custom Query using the
*			values specified by the user.
*
********************************************************/
function Search()	
{
	/*
	Grab the query id and all of the keyword input boxes 
	*/
	/*Check for multiple or single queries*/
	if (document.getElementById("queryList") != null)
	{
		var indexNum = document.getElementById("queryList").selectedIndex;
		var queryID = document.getElementById("queryList").options[indexNum].value;
	}
	else
	{
		var singleQueryDiv = document.getElementById("singleQuery");
		var singleQueryInfo = singleQueryDiv.childNodes.item(0);
		var queryID = singleQueryInfo.id;
	}
	
	var inputArray = document.getElementsByTagName("input");
	var jurisdictionList = document.getElementsByTagName("select");
	var jurisdiction;
	var arrayLen = inputArray.length;
	var listLen = jurisdictionList.length;
	var keyCount = 0;
	var wildCount = 0;
	var keywordList = "&keys=";
	
	/*
	Loop through the keyword input boxes.  If there is a value, increment the
	keycount variable and add the keyword name and the value to keywordList
	*/
	for(i=0; i < arrayLen; i++)
	{
		if (inputArray[i].value != "" && inputArray[i].type != "hidden" && inputArray[i].type != "button")
		{
			keyCount++;
			keywordList += inputArray[i].id + "_" + inputArray[i].value + "|";
		}
	}
	
	/*
	Loop through the keyword input boxes.  If the value is *, increment the wildcount variable
	*/
	for(i=0; i < arrayLen; i++)
	{
		if (inputArray[i].value.indexOf("*") >= 0 && inputArray[i].type != "hidden" && inputArray[i].type != "button")
		{
			if (inputArray[i].value.replace(/\*/g, "") == "")
			{
				wildCount++;
			}
		}
	}
	
	if (keyCount > 0)
	{
		if (wildCount != keyCount)
		{
			var tblResults = document.getElementById("tblResults");
			
			// Clear the results table
			while (tblResults.firstChild)
			{
				tblResults.removeChild(tblResults.firstChild);
			}
			
			// Add a new row to the results table
			var row = tblResults.insertRow(-1);
			cell  = row.appendChild(document.createElement('td'));
			cell.innerHTML = "Performing Search...";
			
			//Retrieve the value selected in the Jurisdiction
			for(i=0; i < listLen; i++)
			{
				if (jurisdictionList[i].name == "Jurisdiction_List_1")
				{
					jurisdiction = jurisdictionList[i];
					if (jurisdiction.options[jurisdiction.selectedIndex].value != "NULL")
					{
						keyCount++;
						keywordList += jurisdiction.id + "_" + jurisdiction.options[jurisdiction.selectedIndex].value + "|";
					}
				}
			}
			
			var soaURL = "../publicaccess/PublicAccessProvider.ashx";
			
			var params = "action=getDocHitList&queryID=" + queryID + "&keyCount=" + keyCount + keywordList;
			
			var requestor = new AjaxRequestor(soaURL, params, getDocHitList_callBack);	
		}
		else
		{
			alert("You cannot perform a wild card only search.");
		}
	}
	else
	{
		alert("You must enter a value for at least one keyword.");
	}
}

/*******************************************************
*	Method: 	getDocHitList_callBack
*	
*	Purpose: 	Processes the Document Hit List response 
*			from the Web Service.
*
********************************************************/
function getDocHitList_callBack()
{
	BuildHitList(this.req.responseText);
}

/*******************************************************
*	Method: 	BuildHitList
*	
*	Purpose: 	Builds the Document Hit List from the list of
*			documents returned from OnBase.
*
********************************************************/
function BuildHitList(results)
{
	var tblResults = document.getElementById("tblResults");
	var maxResults = 50; // The maximum results that will be displayed to the users
	
	while (tblResults.firstChild)
	{
		tblResults.removeChild(tblResults.firstChild);
	}
	/*
	If this is IE
	*/
	if (window.ActiveXObject)
	{
		/*
		If there are no results, show the No Documents string
		*/
		if (results == "")
		{
			var row = tblResults.insertRow(-1);
			cell  = row.appendChild(document.createElement('td'));
			cell.innerHTML = "No documents found";
		}
		/*
		Otherwise loop through what we have
		*/
		else
		{
			/*
			Load up the results as an xml doc
			*/
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = false;
			xmlDoc.loadXML(results);
			var nodeList = xmlDoc.selectNodes("DocumentCollection/Document");
			var length = nodeList.length;
			
			var row = tblResults.insertRow(-1);
			cell  = row.appendChild(document.createElement('td'));
			cell.innerHTML = "ADDRESS - TOWNSHIP - OWNER LAST NAME - PERMIT # - PARCEL ID";
			cell.style.backgroundColor = "#a2bcea";
			
			for (var i=0; i < maxResults; i++)
			{
				if (i < length)
				{
					/*
					Create xml node from node in node list and insert a row object
					into the table
					*/
					xmlNode = nodeList[i];
					row = tblResults.insertRow(-1);
					/*
					Create a cell object and add to the row.  Set cell id as the 
					document id, the cell text as the document name, the onclick
					function to GetDoc and the cursor style to pointer.
					*/
					cell  = row.appendChild(document.createElement('td'));
					cell.id = xmlNode.selectSingleNode("ID").text;
					cell.innerHTML = xmlNode.selectSingleNode("Name").text;
					cell.onclick = function(){GetDoc(this)};
					cell.style.cursor = "pointer";
					/*
					If the alternating row color property is true then set the
					background color of the row to white if it is and even number
					*/
					if ("true" == "true" && i%2 == 0)
					{
						cell.style.backgroundColor = "#FFFFFF";
					}
				}
			}
			
			// Check how many documents were retrieved and inform the user what will be displayed
			if (length > maxResults)
			{
				// Display a message indicating that some documents were not displayed
				alert ("The number of documents retrieved was too large to display.  " +
					"The first 50 documents have been displayed.  Enter more specific " +
					"search criteria to limit the results returned.");
			}
		}
	 }
	 /*
	 If this is Firefox/Seamonkey/Safari
	 */
	 else if(document.implementation && document.implementation.createDocument)
	 {
		/*
		Check the results and if empty display the no documents message.
		*/
		if (results == "" || results == null)
		{
			var row = tblResults.insertRow(-1);
			cell  = row.appendChild(document.createElement('td'));
			cell.innerHTML = "No documents found";	
		}

		/*
		If there is something, create everything you need and start going 
		through the results
		*/
		else
		{
			var parser = new DOMParser();
			var doc = parser.parseFromString(results,"application/xml");
			doc.async = false;
			var x = doc.documentElement;
			var nodeList = x.childNodes;
			var length = nodeList.length;

			for (var i=0; i < maxResults; i++)
			{
				if (i < length)
				{
					/*
					Create xml node from node in node list and insert a row object
					into the table
					*/
					xmlNode = nodeList[i];
					var row = tblResults.insertRow(-1);
					/*
					Create a cell object and add to the row.  Set cell id as the 
					document id, the cell text as the document name, the onclick
					function to GetDoc and the cursor style to pointer.
					*/
					cell  = row.appendChild(document.createElement('td'));
					cell.id = doc.getElementsByTagName("ID")[i].childNodes[0].nodeValue;
					cell.innerHTML = doc.getElementsByTagName("Name")[i].childNodes[0].nodeValue;
					cell.onclick = function(){GetDoc(this)};
					cell.style.cursor = "pointer";
					/*
					If the alternating row color property is true then set the
					background color of the row to white if it is and even number
					*/
					if ("true" == "true" && i%2 == 0)
					{
						cell.bgColor = "#FFFFFF";
					}
				}
			}
			
			// Check how many documents were retrieved and inform the user what will be displayed
			if (length > maxResults)
			{
				// Display a message indicating that some documents were not displayed
				alert ("The number of documents retrieved was too large to display.  " +
					"The first 50 documents have been displayed.  Enter more specific " +
					"search criteria to limit the results returned.");
			}
		}
	}	
}

/*******************************************************
*	Method: 	GetDoc
*	
*	Purpose: 	Retrieves the selected document and displays
*			it in the ViewDocument page.
*
********************************************************/
function GetDoc(cell)
{
	var url = "../publicaccess" + "/ViewDocument.aspx?docID=" + cell.id;
	var myWindow = window.open(url,"_blank","height=600,width=800,status=no,toolbar=no,menubar=no,resizable=yes");
}

/*******************************************************
*	Method: 	load_viewer
*	
*	Purpose: 	Method called upon loading the ViewDocument 
*			page.
*
********************************************************/
function load_viewer()
{	
	if (document.title = "Error")
	{
		var myWindow = window.open("../publicaccess/Error.htm", "_self");
	}
}