var	inmateSearchTypeLeft			= 30
var	inmateSearchTypeTop				= 40
var	inmateSearchTypeBorder			= 1
var	inmateSearchTypeBorderColor		= '#D6D6EB'
var	inmateSearchDataLeft			= 30
var	inmateSearchDataTop				= 125
var	inmateSearchDataBorder			= 1
var	inmateSearchDataBorderColor		= '#D6D6EB'
var inmateSearchButtonLeft			= 210
var inmateSearchButtonTop			= 210
var	inmateSearchResultsLeft			= 15
var	inmateSearchResultsTop			= 285
var	inmateSearchResultsHeight		= 300
var	inmateSearchResultsWidth		= 900
var	inmateSearchResultsBorder		= 1
var	inmateSearchResultsBorderColor	= '#D6D6EB'
var inmateSearchAllPersons 			= 0 	
var inmateSearchTypeCode 			= 'name'	//'name'  'arrestid'  'identifier'  'ssn'
var inmateSearchDetailCode 			= 'high' //'high'  'low'
var inmateSearchResultsRows 		= 10
var strNoRecordMessage				= 'No Records Found Matching Your Search Criteria'
var searchHeader
var SearchNow
var strXSLPath

var currentRow
var thisTable

var oSignupWindow = null;
function openSignup()
{
	//oSignupWindow = window.open('WiggleForm.aspx','97.9 Wiggle Contest','toolbar=no,left=300,top=200,menu=no,status=no,scrollbars=no,resizable=no'); //,screen.availWidth,screen.availHeight
	oSignupWindow = window.open("WiggleForm.aspx", "", "toolbar=no,left=200,top=200,menu=no,status=0,scrollbars=no,resizable=no");
	oSignupWindow.resizeTo(550,650);
	oSignupWindow.focus();
}

var oTextSignupWindow = null;
function openTextSignup()
{
	
	oTextSignupWindow = window.open("http://www.citystreamlive.com/TextForm.aspx", "", "toolbar=no,left=200,top=200,menu=no,status=0,scrollbars=no,resizable=no");
	oTextSignupWindow.resizeTo(550,650);
	oTextSignupWindow.focus();
}



function keyDown()
	{
		
	if(event.keyCode == 40)
		{
			if (currentRow == thisTable.length - 1)
				currentRow = 0
			else
				currentRow++
				
			thisTable[currentRow].className = "PanelItem9"
			if (currentRow == 0)
				{
					thisTable[thisTable.length - 1].className = thisTable[thisTable.length - 1].oldClass
				}
			else
					thisTable[currentRow - 1].className = thisTable[currentRow - 1].oldClass
			
		}

	if(event.keyCode == 38)
		{
			if (currentRow == 0)
				currentRow = thisTable.length - 1
			else
				currentRow--
				
			thisTable[currentRow].className = "PanelItem9"
			
			if (currentRow == thisTable.length - 1)
				{
					thisTable[0].className = thisTable[0].oldClass
				}
			else
					thisTable[currentRow + 1].className = thisTable[currentRow + 1].oldClass
			
		}


	}	


function displayInmateSearch()
{	





	var search_current = getCookie("search_current")
	if (search_current != 0) {not_released.checked = "on"}

	
	if (inmateSearchAllPersons == 1 || inmateSearchAllPersons == 2 || inmateSearchAllPersons == 3)
	{
		lblIdentifier.style.visibility = 'hidden'
		rdoIdentifier.style.visibility = 'hidden'
		lblBooking.style.visibility = 'hidden'
		rdoBooking.style.visibility = 'hidden'
		lblCurrent.style.visibility = 'hidden'
		chkCurrent.style.visibility = 'hidden'
		lblInternalId.style.visibility = 'hidden'
		rdoInternalId.style.visibility = 'hidden'
		lblDOB.style.visibility = 'hidden'
		rdoDOB.style.visibility = 'hidden'
		spnInmateSearchType.style.height = 30
	} 
	else
	{
		lblIdentifier.style.visibility = 'visible'
		rdoIdentifier.style.visibility = 'visible'
		lblBooking.style.visibility = 'visible'
		rdoBooking.style.visibility = 'visible'
		lblCurrent.style.visibility = 'visible'
		chkCurrent.style.visibility = 'visible'
		lblInternalId.style.visibility = 'visible'
		rdoInternalId.style.visibility = 'visible'
		lblDOB.style.visibility = 'visible'
		rdoDOB.style.visibility = 'visible'
		spnInmateSearchType.style.height = 80
	}
	
	if (inmateSearchAllPersons == 3)
	{
		lblOpenWarrants.style.top = 25
		lblOpenWarrants.style.visibility = 'visible'
		chkCurrent.style.top = 22
		chkCurrent.style.visibility = 'visible'
		spnInmateSearchType.style.height = 50


	}

	spnInmateSearchType.style.top				= inmateSearchTypeTop
	spnInmateSearchType.style.left				= inmateSearchTypeLeft
	spnInmateSearchType.style.borderWidth		= inmateSearchTypeBorder
	spnInmateSearchType.style.borderColor		= inmateSearchTypeBorderColor
	spnBookingNoSearch.style.top				= inmateSearchDataTop
	spnBookingNoSearch.style.left				= inmateSearchDataLeft
	spnBookingNoSearch.style.borderWidth		= inmateSearchDataBorder
	spnBookingNoSearch.style.borderColor		= inmateSearchDataBorderColor
	spnIdentifierSearch.style.top				= inmateSearchDataTop
	spnIdentifierSearch.style.left				= inmateSearchDataLeft
	spnIdentifierSearch.style.borderWidth		= inmateSearchDataBorder
	spnIdentifierSearch.style.borderColor		= inmateSearchDataBorderColor
	spnNameSearch.style.top						= inmateSearchDataTop
	spnNameSearch.style.left					= inmateSearchDataLeft
	spnNameSearch.style.borderWidth				= inmateSearchDataBorder
	spnNameSearch.style.borderColor				= inmateSearchDataBorderColor
	spnSSNSearch.style.top						= inmateSearchDataTop
	spnSSNSearch.style.left						= inmateSearchDataLeft
	spnSSNSearch.style.borderWidth				= inmateSearchDataBorder
	spnSSNSearch.style.borderColor				= inmateSearchDataBorderColor

	spnDOBSearch.style.top						= inmateSearchDataTop
	spnDOBSearch.style.left						= inmateSearchDataLeft
	spnDOBSearch.style.borderWidth				= inmateSearchDataBorder
	spnDOBSearch.style.borderColor				= inmateSearchDataBorderColor
	
	spnInternalId.style.top						= inmateSearchDataTop
	spnInternalId.style.left					= inmateSearchDataLeft
	spnInternalId.style.borderWidth				= inmateSearchDataBorder
	spnInternalId.style.borderColor				= inmateSearchDataBorderColor
	
	inmateSearchButton.style.top				= inmateSearchButtonTop
	inmateSearchButton.style.left				= inmateSearchButtonLeft
	inmateSearchResultsList.style.top			= inmateSearchResultsTop
	inmateSearchResultsList.style.left			= inmateSearchResultsLeft
	inmateSearchResultsList.style.height		= inmateSearchResultsHeight
	inmateSearchResultsList.style.width			= inmateSearchResultsWidth
	inmateSearchResultsList.style.borderWidth	= inmateSearchResultsBorder
	inmateSearchResultsList.style.borderColor	= inmateSearchResultsBorderColor
		
	spnInmateSearchType.style.visibility = 'visible';
	inmateSearchButton.style.visibility = 'visible';
	inmateSearchName_onclick();
	document.all.rdoName.checked = true;
	LastName.focus()
	InmateSearchObject = RSGetASPObject("/RemoteScripts/Global_RemoteScript.asp");		//set up remote scripting
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Search Inmate - Load Info into Span via Remote Scripting
////////////////////////////////////////////////////////////////////////////////////////////////////////

function getInmateSearchList()
{
	
	inmateSearchResultsList.style.visibility = "hidden"
	inmateSearchResultsList.innerHTML = imgSearching.innerHTML;

	//Choose XSL Stylesheet
	strXSLPath = "/style/showPersonSearchResults.xsl"			
		if ((inmateSearchAllPersons == 1)||(inmateSearchAllPersons == 2)||(inmateSearchAllPersons == 3)) 
		{
			if (inmateSearchDetailCode == "low") 
			{
				strXSLPath = "/style/showPersonSearchResultsAllCondensed.xsl"
			}
			else
			{
				strXSLPath = "/style/showPersonSearchResultsAll.xsl"
			}
		}		
		else
		{
			if (inmateSearchDetailCode == "low") 
			{
				strXSLPath = "/style/showPersonSearchResultsCondensed.xsl"
			}
			else
			{
				
				strXSLPath = "/style/showPersonSearchResults.xsl"
			}
		}
	
	var searchValue
	if (inmateSearchTypeCode == 'name')
	{
		searchValue = LastName.value + "," + FirstName.value
	}
	
	if (inmateSearchTypeCode == 'arrestid')
	{
		searchValue = ArrestID.value
	}
	
	if (inmateSearchTypeCode == 'identifier')
	{
		searchValue = Identifier.value
	}
	
	if (inmateSearchTypeCode == 'ssn')
	{
		searchValue = SSN.value
	}

	if (inmateSearchTypeCode == 'InternalId')
	{
		searchValue = InternalId.value
	}

	if (inmateSearchTypeCode == 'dob')
	{
		searchValue = DOB.value
	}
		
	if ( inmateSearchTypeCode == 'WrntNo')
	{
		searchValue = WrntNo.value
	}
	
	SearchNow = 1

	if ((searchValue == "")||(searchValue ==  ","))
	{
		var PersonDesc
		PersonDesc = "Inmates"
		if (inmateSearchAllPersons == 1 || inmateSearchAllPersons == 2 || inmateSearchAllPersons == 3)
		{
			PersonDesc = "Persons"
		}	
		
		SearchNow = confirm("Search All " + PersonDesc + "?")
	}
	

	if (SearchNow == 1)
	{
		inmateSearchResultsList.style.visibility = 'visible';
		var co = InmateSearchObject.personSearch(not_released.checked, inmateSearchTypeCode, searchValue, inmateSearchDetailCode, inmateSearchAllPersons, inmateSearchResultsRows, strXSLPath)
		processSearchResults(co);
		inmateSearch_onclick_addYourFunctions()	
		
		
	}
	

	return true;
	
}

function processSearchResults(co)
{
	if (co.status != 0)
	{
		alert('Unable to Retrieve Records');
		return;
	}
	inmateSearchResultsList.innerHTML = co.return_value

	thisTable = inmateSearchResultsList.all.tags("tr")
		for(i=0;i<thisTable.length;i++)
			{
				thisTable[i].oldClass = thisTable[i].className
				//thisTable[i].thisID = i
			}
	currentRow = (thisTable.length - 1)
	
	if (inmateSearchResultsList.all.tags("tr").length < 4)
		{
			alert(strNoRecordMessage)
		}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Search results Paging
////////////////////////////////////////////////////////////////////////////////////////////////////////
function searchPage(strData)
{
	var searchElement
	var searchPageNo
	var searchID
	var searchRows
	var searchFirstRow
	var searchLastRow
	var searchAliases
		
	searchElement = strData.split('|')
	searchPageNo = searchElement[0]
	searchID = searchElement[1]
	searchRows = searchElement[2]
	searchFirstRow = searchElement[3]
	searchLastRow = searchElement[4]
	searchAliases = searchElement[5]
		
	var co = InmateSearchObject.personSearchPage(searchPageNo, searchID, searchRows, searchFirstRow, searchLastRow, searchAliases, strXSLPath, processSearchResults)
}



////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Name Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchName_onclick()
{
	hideAllSearchCriteria();
	spnNameSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'name'
	setSearchTypeCookie(inmateSearchTypeCode)
	
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Warrant No Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchWrntNo_onclick( )
{
	hideAllSearchCriteria();
	//CAI 05/04/05 trying to solve issues documented in 4.3.3 QA defect #56
	//cant use reposition. it will be more work to add a new span, so we'll try dynamic positioning
	//depending on which page is the host for the <SPAN>
	//Charles Gbadebo 6/15/05 commented out the following if statement and replaced it with the statement after it
	
	/*
	if( document.location.pathname != "/dms/facility/Warrant/warrant.asp")
	{
		spnWrntNoSearch.style.top = 40;
		spnWrntNoSearch.style.left = 295;
	}
	*/	
	if( document.location.pathname == "dms/inmate/inmate_search.asp")
	{
		spnWrntNoSearch.style.top = 40;
		spnWrntNoSearch.style.left = 295;
	}
	
	document.all.spnWrntNoSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'WrntNo'
	setSearchTypeCookie(inmateSearchTypeCode)
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////	
// InternalId Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchInternalId_onclick()
{
	hideAllSearchCriteria();
	spnInternalId.style.visibility = 'visible';
	inmateSearchTypeCode = 'InternalId'
	setSearchTypeCookie(inmateSearchTypeCode)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// BookingNo Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchBookingNo_onclick()
{
	hideAllSearchCriteria();
	document.all.spnBookingNoSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'arrestid'
	setSearchTypeCookie(inmateSearchTypeCode)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// rdoIdentifier Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchIdentifier_onclick()
{
	hideAllSearchCriteria();
	document.all.spnIdentifierSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'identifier'
	setSearchTypeCookie(inmateSearchTypeCode)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// SSN Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchSSN_onclick()
{
	hideAllSearchCriteria();
	document.all.spnSSNSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'ssn'
	setSearchTypeCookie(inmateSearchTypeCode)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// DOB Radio click event
////////////////////////////////////////////////////////////////////////////////////////////////////////

function inmateSearchDOB_onclick()
{
	hideAllSearchCriteria();
	document.all.spnDOBSearch.style.visibility = 'visible';
	inmateSearchTypeCode = 'dob'
	setSearchTypeCookie(inmateSearchTypeCode)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Hide all criteria Fieldsets
////////////////////////////////////////////////////////////////////////////////////////////////////////

function hideAllSearchCriteria()
{
	document.all.spnInternalId.style.visibility = 'hidden';
	document.all.spnBookingNoSearch.style.visibility = 'hidden';
	document.all.spnIdentifierSearch.style.visibility = 'hidden';
	document.all.spnNameSearch.style.visibility = 'hidden';
	document.all.spnSSNSearch.style.visibility = 'hidden';
	document.all.spnDOBSearch.style.visibility = 'hidden';
	document.all.spnWrntNoSearch.style.visibility = 'hidden';
}

////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Hide all !!
////////////////////////////////////////////////////////////////////////////////////////////////////////

function searchHideAll()
{
	hideAllSearchCriteria();
	document.all.spnInmateSearchType.style.visibility = 'hidden';
	document.all.inmateSearchButton.style.visibility = 'hidden';
	document.all.inmateSearchResultsList.style.visibility = 'hidden';

	lblIdentifier.style.visibility = 'hidden'
	rdoIdentifier.style.visibility = 'hidden'
	lblBooking.style.visibility = 'hidden'
	rdoBooking.style.visibility = 'hidden'
	lblCurrent.style.visibility = 'hidden'
	chkCurrent.style.visibility = 'hidden'
	lblInternalId.style.visibility = 'hidden'
	rdoInternalId.style.visibility = 'hidden'
	lblDOB.style.visibility = 'hidden'
	rdoDOB.style.visibility = 'hidden'

}

function setSearchCurrentCookie(value)
{
	var searchFlag
	searchFlag = 1
	if (!value) {searchFlag = 0}
	document.cookie = "search_current = " + searchFlag + ";"
}

function setSearchTypeCookie(value)
{
	document.cookie = "search_type = " + value + ";"
}

function getTheInmate(id_code,arrest_no,firstname,lastname,Alias)
{
	if (Alias == 1)
	{
		alert("Note: This person was included in these search results because of a matching alias.")
	}
	
	var co = InmateSearchObject.checkAlerts(id_code, 1)
	if (co.return_value > 0)
	{
		var sURL = "/commonDlgs/dlgAlertSummary.asp?ID_Code=" + id_code;
		var oWin = window.showModalDialog(sURL, null,"status: no;dialogWidth:325px;dialogHeight:275px")
	}	

	getInmate(id_code,arrest_no,firstname,lastname)
}

function getThePerson(id_code,ssn,firstname,lastname,Alias)
{
	if (Alias == 1)
	{
		alert("Note: This person was included in these search results because of a matching alias.")
	}

	var co = InmateSearchObject.checkAlerts(id_code, 1)
	if (co.return_value > 0)
	{
		var sURL = "/commonDlgs/dlgAlertSummary.asp?ID_Code=" + id_code;
		var oWin = window.showModalDialog(sURL, null,"status: no;dialogWidth:325px;dialogHeight:275px")
	}	

	getPerson(id_code,ssn,firstname,lastname)
}


