  
  
  //disables a given field from a given selection box value
  function disableFieldFromSelection(selectId,disableOnValue,fieldId,clearFieldOnDisable){
  
  	var selectObj = document.getElementById(selectId);
  	var fieldObj = document.getElementById(fieldId);
	var tmpValue = '';
	
  	if(selectObj.selectedIndex!=-1){
		tmpValue = selectObj.options[selectObj.selectedIndex].value;
		if(tmpValue == disableOnValue){
			fieldObj.className = "disabled";
			fieldObj.value = "";
		}else{
			fieldObj.className = "enabled";
		}
	}else{
		fieldObj.className = "enabled";
	}
  
  
  }
  
  //used to retrieve non inline styles (browser set values)
  function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (document.defaultView)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		var y = eval('x.currentStyle.' + styleProp);
	return y;
  }

  
  // used to keep track of the mouse location
  function mouseTracker(e) {
	e = e || window.Event || window.event;
	window.pageX = e.pageX || e.clientX;
	window.pageY = e.pageY || e.clientY;
  }
  
  //used to locate the x cordinate of a given HTML element
  function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
  }

  //used to locate the y cordinate of a given HTML element
  function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
  }

	function getMouseX(){
	
		if (window.pageXOffset > -1) {
			return window.pageXOffset+window.pageX;
		} else if (document.body) {
			return window.document.body.scrollLeft+window.pageX; 
		}
	
		return 0;
	}

	function getMouseY(){
		if (window.pageYOffset > -1) {
			return window.pageYOffset+window.pageY;
		} else if (document.body) {
			return window.document.body.scrollTop+window.pageY;
		}
		
		return 0;
	}
	
    //used to retun an x cordinate that would show the current object within the current browser window
  	function getNewX(xcord,myWidth){
		var newX = 0;
		var diff = 0;
		if(document.all){
			if(document.body){
				if((xcord+myWidth) > (document.body.clientWidth + document.body.scrollLeft)){
					diff = (xcord+myWidth) - (document.body.clientWidth+document.body.scrollLeft);
					newX = xcord-(diff + 5) ;
				}else{
					newX=xcord;
				}
			}else{
				newX=xcord;
			}       
		}else{
			if((xcord+myWidth) > (window.innerWidth + window.pageXOffset)){
				diff = (xcord + myWidth) - (window.innerWidth + window.pageXOffset);
				newX = xcord - (diff + 20);
			}else{
				newX=xcord;
			}
		}
	
		if(newX<5) newX = 5;
		return newX;
  	}

	//used to retun a y cordinate that would show the current object within the current browser window
	function getNewY(ycord,myHeight){
		var newY = 0
		if(document.all){
			if(document.body){
				if((ycord+myHeight+5) > (document.body.clientHeight+document.body.scrollTop)){
					diff = (ycord+myHeight) - (document.body.clientHeight+document.body.scrollTop)
					newY = ycord-(diff + 5);
				}else{
					newY=ycord;
				}
			}else{
				newY=ycord;
			}       
		}else{
	
			if((ycord+myHeight+15) > (window.innerHeight+window.pageYOffset)){
				diff = (ycord+myHeight) - (window.innerHeight+window.pageYOffset)
				newY = ycord-(diff + 20);
			}else{
				newY=ycord;
			}
		}
		
		if(newY<5) newY = 5;
		return newY;
	}

  //Used in conjunction with the CustomSelectionBuilder().java
  function showList(fieldId,listId,show,x,y,widthFieldName,heightFieldName){
    
    var fieldTop;
    var fieldLeft;
    var width = 0;
    var height = 0;
    
    //alert('showList');
  	    
    if(!x) x = 0;
    if(!y) y = 0;
    
	if(widthFieldName  && String(widthFieldName).length > 0){
		width = parseInt(document.getElementById(widthFieldName).value);
	}
	if(heightFieldName && String(heightFieldName).length > 0){
	 	height = parseInt(document.getElementById(heightFieldName).value);
	}
	
  	if(show){
  		fieldTop = findPosY(document.getElementById(fieldId));
  		fieldLeft = findPosX(document.getElementById(fieldId));
  		if(width > 0){
  			document.getElementById(listId+'Parent').style.top = getNewY(fieldTop+20,height) + 5 + y + "px";
	  	    document.getElementById(listId+'Parent').style.left = getNewX(fieldLeft,width) + x + "px";
	  		document.getElementById(listId).style.visibility = "visible";
  		}else{
	  	    document.getElementById(listId+'Parent').style.top = fieldTop + 25 + y + "px";
	  	    document.getElementById(listId+'Parent').style.left = fieldLeft + x + "px";
	  		document.getElementById(listId).style.visibility = "visible";
  		}
  		
  	}else{
  		document.getElementById(listId).style.visibility = "hidden";
  	}
  	
  	var statistics  ='FieldId:' + fieldId + '\n';
  	    statistics +='ListId:' + listId + '\n';
  	    statistics +='myWidth:' + width + '\n';
  	    statistics +='myHeight:' + height + '\n';
  	    statistics +='myTop:' + document.getElementById(listId+'Parent').style.top + '\n';
  	    statistics +='myLeft:' + document.getElementById(listId+'Parent').style.left + '\n';
  	    statistics +='XTuning:' + x + '\n';
  	    statistics +='YTuning:' + y + '\n';
  	    statistics +='myVisibility:' + document.getElementById(listId).style.visibility + '\n';
  	    
  	   // alert(statistics);
  	
  }

  //sets a field with a given selection Objects selected value
  function setFieldValue(selectId,fieldId){
  	
  	var selectObj = document.getElementById(selectId);
	var tmpValue = '';
	
	if(selectObj.selectedIndex!=-1){
		tmpValue = selectObj.options[selectObj.selectedIndex].value;
	}else{
		if(selectObj.options[0]){;
			tmpValue = selectObj.options[0].value;
		}
	}

	document.getElementById(fieldId).value = tmpValue;
	
  }

//calculates the next numeric value in a selection list
function getNextNumericSelectValue(selectId){
	var selectObj = document.getElementById(selectId);
	var selections = new Array();
	var selectOpt = null;
	
	for(i=0; i<selectObj.length; i++){
	    selectOpt = selectObj.options[i];
		selections[i]=parseInt(selectOpt.text);
	}
	
	//sort
	selections.sort(function(a,b){ return a-b; });
	return selections[selections.length-1];
}

//adds an option to a selection box
function addSelectOption(selectId,selectText,selectValue,defaultSelected,selected){
    
	var selectObj = document.getElementById(selectId);
	var selectOpt = new Option(selectText,selectValue,defaultSelected,selected);
	
	selectObj.options[selectObj.length] = selectOpt;
}

//gets the selected 'Display Value' for a given a selection box
function getSelectedText(selectId){
	var selectObj = document.getElementById(selectId);
	var text = '';
	
	if(selectObj.selectedIndex!=-1){
		text = selectObj.options[selectObj.selectedIndex].text;
	}else{
		text = selectObj.options[0].text;
	}

	return text;
}

//gets the selected 'Display Value' for a given a selection box
function setSelectedOptionByTextValue(selectId,textValue){
	var selectObj = document.getElementById(selectId);
	var text = '';
	
	for(x=0; x<selectObj.length; x++){
		text = selectObj.options[x].text;
		if(text == textValue){
			selectObj.selectedIndex = x;
		}
	}

	return text;
}


function isOptionSelected(optionValue, dbValue)
{
  if (optionValue == dbValue)
  {
    document.write(" SELECTED");
  }
}

function isSelected(selectName, selectValue)
{
// selectBy = request.
  var selectBy = 'P';
  
  if (selectBy = 'S')
  {
	document.form.selectBy.option[1].selectedIndex;
  }
  else
  {
	document.form.selectBy.option[0].selectedIndex;
  }
}

// Swaps out Add/Inquire button on Alpha Index Page
function setAlphaIndexSwapDefaults()
{
	changeObjectVisibility('inquire', 'visible');
	stancoStyleObject = getStyleObject('inquire');
	stancoStyleObject.display = '';
	
	changeObjectVisibility('add', 'hidden');
	partyStyleObject = getStyleObject('add');
	partyStyleObject.display = 'none';
}

function swapAlphaIndexButton(buttonSwapValue)
{
  var inquireStyleObject = getStyleObject('inquire');
  var addStyleObject = getStyleObject('add');

  if (buttonSwapValue == 'inquire')
  {
      changeObjectVisibility('inquire', 'visible');
	  inquireStyleObject.display = '';
	  
      changeObjectVisibility('add', 'hidden');
	  addStyleObject.display = 'none';
  }
  else{
    if (buttonSwapValue == 'add')
    {
      changeObjectVisibility('add', 'visible');
	  addStyleObject.display = '';
	  
      changeObjectVisibility('inquire', 'hidden');
	  inquireStyleObject.display = 'none';
    }
	else
	{
      changeObjectVisibility('inquire', 'hidden');
	  inquireStyleObject.display = 'none';

      changeObjectVisibility('add', 'hidden');
	  addStyleObject.display = 'none';
	}
  }
}

function swapQueryOption()
{
  var datacountStyleObject = getStyleObject('dataCount');
  var emptycolumnStyleObject = getStyleObject('emptyColumns');
//  var warrantStyleObject = getStyleObject('WarrantSearch');
  
  var queryOption = document.selectTables.queryType.value;

  if (queryOption == 'emptyColumns')
  {
      changeObjectVisibility('emptyColumns', 'visible');
	  emptycolumnStyleObject.display = '';

      changeObjectVisibility('dataCount', 'hidden');
	  datacountStyleObject.display = 'none';
  }
  else{
    if (queryOption == 'dataCount')
    {
      changeObjectVisibility('dataCount', 'visible');
	  datacountStyleObject.display = '';

      changeObjectVisibility('emptyColumns', 'hidden');
	  emptycolumnStyleObject.display = 'none';
    }
	else
	{
      changeObjectVisibility('emptyColumns', 'hidden');
	  emptycolumnStyleObject.display = 'none';

      changeObjectVisibility('dataCount', 'hidden');
	  datacountStyleObject.display = 'none';
	}
  }
}

function swapOffenderRegistrantSectionBGColor(sectionValue){
  if (sectionValue == 'arson'){
    document.offenderRegistrant.arsonBG.style.bgColor = '#004000';
    document.offenderRegistrant.narcoticBG.style.bgColor = '#ccccbb';
    document.offenderRegistrant.sexBG.style.bgColor = '#ccccbb';
  }

  if (sectionValue == 'narcotic'){
    document.offenderRegistrant.arsonBG.style.bgColor = '#ccccbb';
    document.offenderRegistrant.narcoticBG.style.bgColor = '#004000';
    document.offenderRegistrant.sexBG.style.bgColor = '#ccccbb';
  }

  if (sectionValue == 'sex'){
    document.offenderRegistrant.arsonBG.style.bgColor = '#ccccbb';
    document.offenderRegistrant.narcoticBG.style.bgColor = '#ccccbb';
    document.offenderRegistrant.sexBG.style.bgColor = '#004000';
  }
}

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function hide()
{
	changeObjectVisibility('hideFooter', 'hidden');
	footerStyleObject = getStyleObject('hideFooter');
	footerStyleObject.display = 'none';

	changeObjectVisibility('hideHeader', 'hidden');
	headerStyleObject = getStyleObject('hideHeader');
	headerStyleObject.display = 'none';
}

function disableField(fieldId, disable){  	
  if(disable){
  	document.getElementById(fieldId).value = '';
  	document.getElementById(fieldId).className = 'disabled';
  }else{
  	document.getElementById(fieldId).className = 'enabled';
  }

  document.getElementById(fieldId).disabled = disable;
  return;
}

function validateDate(fieldId){
	var fullDate = new String(document.getElementById(fieldId).value);
    var splitChar = "/";
    if(fullDate.indexOf("-") >=0) splitChar ="-";
    if(fullDate.indexOf(".") >=0) splitChar =".";
    
    var dateValues = fullDate.split(splitChar);
    var month="";
    var day="";
    var year="";
    
    for(x=0; x<dateValues.length; x++){
    	if(x==0) month = dateValues[x];
    	if(x==1) day = dateValues[x];
    	if(x==2) year = dateValues[x];
    }
    
    validated = isDate(year,month,day);
    if(validated) document.getElementById(fieldId).value = month + "/" + day + "/" + year;
	return validated;
}