//Function that allows multiple calls to functions upon loading of the web page
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
		window[fnc]();		
      };
    }
    else 
      window.onload = fnc;
  }
}

//Function to round numbers, changing the rlength variable indicates the number of decimal places to round to
function roundNumber(theNumber) 
{
  var rnum = theNumber;
  var rlength = 0;
  if (rnum > 8191 && rnum < 10485) 
  {
	rnum = rnum-5000;
	var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);		
  } 
  else 
  {
	var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  }
  return newnumber;
}

//Function that converts words in a string to the proper case
function PCase(STRING)
{
  var strReturn_Value = "";
  var iTemp = STRING.length;
  if(iTemp==0)
  {
    return"";
  }
  var UcaseNext = false;
  strReturn_Value += STRING.charAt(0).toUpperCase();
  for(var iCounter=1;iCounter < iTemp;iCounter++)
  {
    if(UcaseNext == true)
	{
	  strReturn_Value += STRING.charAt(iCounter).toUpperCase();
	}
	else
	{
	  strReturn_Value += STRING.charAt(iCounter).toLowerCase();
	}
	var iChar = STRING.charCodeAt(iCounter);
	if(iChar == 32 || iChar == 45 || iChar == 46)
	{
	  UcaseNext = true;
	}
	else
	{
	  UcaseNext = false
	}
	if(iChar == 99 || iChar == 67)
	{
	  if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
	  {
	    UcaseNext = true;
	  }
	}
  }
return strReturn_Value;
}

//Function that returns an object having .x and .y properties which are the coordinates of the named anchor, relative to the page.
function getAnchorPosition(anchorname) 
{	
  var useWindow=false;
  var coordinates=new Object();
  var x=0,y=0;
  var use_gebi=false, use_css=false, use_layers=false;
  if (document.getElementById) { use_gebi=true; }
  else if (document.all) { use_css=true; }
  else if (document.layers) { use_layers=true; }	
  if (use_gebi && document.all) 
  {
	x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
	y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
  }
  else if (use_gebi) 
  {
	var o=document.getElementById(anchorname);
	x=AnchorPosition_getPageOffsetLeft(o);
	y=AnchorPosition_getPageOffsetTop(o);
  }
  else if (use_css) 
  {
	x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
	y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
  }
  else if (use_layers) 
  {
	var found=0;
	for (var i=0; i<document.anchors.length; i++) {
	  if (document.anchors[i].name==anchorname) { found=1; break; }
	}
	if (found==0) 
	{
	  coordinates.x=0; coordinates.y=0; return coordinates;
	}
	x=document.anchors[i].x;
	y=document.anchors[i].y;
  }
  else 
  {
	coordinates.x=0; coordinates.y=0; return coordinates;
  }
  coordinates.x=x;
  coordinates.y=y;
  return coordinates;
}

// Function getting the page offset left position
function AnchorPosition_getPageOffsetLeft (el) 
{
  var ol=el.offsetLeft;
  while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
  return ol;
}

// Function getting the page offset top position
function AnchorPosition_getPageOffsetTop (el) 
{
  var ot=el.offsetTop;
  while((el=el.offsetParent) != null) { ot += el.offsetTop; }
    return ot;
}

//Function that bookmarks a web page
function BookmarkPage(title, url)
{
  if (document.all)
  window.external.AddFavorite(url, title);
  else if (window.sidebar)
  window.sidebar.addPanel(title, url, "")
}

//Function that loads the court or agency drop down when the page is initially loaded by calling the import court or agency drop down function that takes in the area (court/agency) indicated.  Before the court or agency drop down is loaded, a message is displayed informing the user that the drop down is being loaded.
function loadCourtOrAgencyDropDown(Area) 
{
  var divTag = document.createElement('div');
  divTag.setAttribute('id','CourtOrAgency');
  divTag.id = 'CourtOrAgency';
  var loadingMessage = document.createTextNode("Loading...");
  divTag.appendChild(loadingMessage);
  document.getElementById('CourtOrAgencyDisplay').appendChild(divTag);
  importCourtOrAgencyDropDown(Area)
}

//Function that imports the court or agency drop down data from the xml document by receiving the area (court/agency) indicated, creating an xml document object, calling the display court or agency drop down function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the area (court/agency) indicated and the particular request (getting the court or agency drop down), so therefore, the server knows what to process.
function importCourtOrAgencyDropDown(Area)
{
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc1 = document.implementation.createDocument("", "", null);
	xmlDoc1.onload = displayCourtOrAgencyDropDown;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc1 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc1.onreadystatechange = function () {
		if (xmlDoc1.readyState == 4) displayCourtOrAgencyDropDown()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  xmlDoc1.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?Area=" + Area + "&theRequest=getCourtOrAgencyDropDown");	
}

//Function that reads through the xml document court or agency tags and pulls the information into a drop down for display on the web page
function displayCourtOrAgencyDropDown()
{
  var x = xmlDoc1.getElementsByTagName('courtoragencies');
  var selectTag = document.createElement('select');
  selectTag.setAttribute('name','CourtOrAgency');
  selectTag.name = 'CourtOrAgency';
  selectTag.setAttribute('id','CourtOrAgency');
  selectTag.id = 'CourtOrAgency';
  selectTag.setAttribute('onChange','importYearDropDown(this.value)');  
  var functionName = "dropDownChange";
  var theFunction = "selectTag.onchange = function " + functionName + "() { importYearDropDown(this.value) };";		
  selectTag.onchange = eval(theFunction);
  selectTag.setAttribute('style','width:240px');
  selectTag.style.width = '240px';
    
  for (j=0;j<x[0].childNodes.length;j++)
  {
	if (x[0].childNodes[j].nodeType != 1) continue;
	var optionTag = document.createElement('option');
	var isSelected = x[0].childNodes[j].getAttribute('selected');
	if (isSelected == 'yes')
	{
	  optionTag.setAttribute('selected','selected');
	  optionTag.selected = 'selected';
	}
	optionTag.setAttribute('value',x[0].childNodes[j].getAttribute('value'));
	optionTag.value = x[0].childNodes[j].getAttribute('value');
	var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
	optionTag.appendChild(tagValue);
	selectTag.appendChild(optionTag);					
  }	
  if (document.getElementById('CourtOrAgencyDisplay').hasChildNodes())
  {
	document.getElementById('CourtOrAgencyDisplay').removeChild(document.getElementById('CourtOrAgency'));
	document.getElementById('CourtOrAgencyDisplay').appendChild(selectTag);
  }
  else
  {
	document.getElementById('CourtOrAgencyDisplay').appendChild(selectTag);
  }				
}

//Function that loads the year drop down when the page is initially loaded by calling the import year drop down function that takes in the value of the court or agency drop down and the year drop down.  Before the year drop down is loaded, a message is displayed informing the user that the drop down is being loaded.
function loadYearDropDown(CourtOrAgency, YearJump) 
{
  var divTag = document.createElement('div');
  divTag.setAttribute('id','YearJump');
  divTag.id = 'YearJump';
  var loadingMessage = document.createTextNode("Loading...");
  divTag.appendChild(loadingMessage);
  document.getElementById('YearDisplay').appendChild(divTag);
  importYearDropDown(CourtOrAgency, YearJump);
}

//Function that imports the year drop down data from the xml document by receiving the value of the court or agency drop down and the year drop down, creating an xml document object, calling the display year drop down function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the court or agency value, the year value and the particular request (getting the year drop down), so therefore, the server knows what to process.
function importYearDropDown(CourtOrAgency, YearJump)
{
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc2 = document.implementation.createDocument("", "", null);
	xmlDoc2.onload = displayYearDropDown;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc2 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc2.onreadystatechange = function () {
		if (xmlDoc2.readyState == 4) displayYearDropDown()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  xmlDoc2.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?CourtOrAgency=" + CourtOrAgency + "&YearJump=" + YearJump + "&theRequest=getYearDropDown");	
}

//Function that reads through the xml document year tags and pulls the information into a drop down for display on the web page
function displayYearDropDown()
{
  var x = xmlDoc2.getElementsByTagName('years');
  var selectTag = document.createElement('select');
  selectTag.setAttribute('name','YearJump');
  selectTag.name = 'YearJump';
  selectTag.setAttribute('id','YearJump');
  selectTag.id = 'YearJump';
  selectTag.setAttribute('onChange','loadPrintReadyVersionLink();loadBookmarkThisPageLink()');  
  var functionName = "dropDownChange";
  var theFunction = "selectTag.onchange = function " + functionName + "() { loadPrintReadyVersionLink();loadBookmarkThisPageLink() };";		
  selectTag.onchange = eval(theFunction);
  selectTag.setAttribute('style','width:240px');
  selectTag.style.width = '240px';
  
  for (j=0;j<x[0].childNodes.length;j++)
  {
	if (x[0].childNodes[j].nodeType != 1) continue;
	var optionTag = document.createElement('option');
	var isSelected = x[0].childNodes[j].getAttribute('selected');
	if (isSelected == 'yes')
	{
	  optionTag.setAttribute('selected','selected');
	  optionTag.selected = 'selected';
	}
	optionTag.setAttribute('value',x[0].childNodes[j].getAttribute('value'));
	optionTag.value = x[0].childNodes[j].getAttribute('value');
	var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
	optionTag.appendChild(tagValue);
	selectTag.appendChild(optionTag);					
  }	
  if (document.getElementById('YearDisplay').hasChildNodes())
  {
	document.getElementById('YearDisplay').removeChild(document.getElementById('YearJump'));
	document.getElementById('YearDisplay').appendChild(selectTag);
  }
  else
  {
	document.getElementById('YearDisplay').appendChild(selectTag);
  }
  loadPrintReadyVersionLink();
  loadBookmarkThisPageLink();
}

//Function that loads the number of cases per page drop down when the page is initially loaded by calling the import number of cases per page drop down function that takes in the value of the number of cases per page drop down.  Before the number of cases per page drop down is loaded, a message is displayed informing the user that the drop down is being loaded.
function loadNumberOfCasesPerPageDropDown(NumLines) 
{
  var divTag = document.createElement('div');
  divTag.setAttribute('id','NumLines');
  divTag.id = 'NumLines';
  var loadingMessage = document.createTextNode("Loading...");
  divTag.appendChild(loadingMessage);
  document.getElementById('NumberOfCasesPerPageDisplay').appendChild(divTag);
  importNumberOfCasesPerPageDropDown(NumLines)
}

//Function that imports the number of cases per page drop down data from the xml document by receiving the value of the number of cases per page drop down, creating an xml document object, calling the display number of cases per page drop down function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the number of cases per page value and the particular request (getting the number of cases per page drop down), so therefore, the server knows what to process.
function importNumberOfCasesPerPageDropDown(NumLines)
{
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc3 = document.implementation.createDocument("", "", null);
	xmlDoc3.onload = displayNumberOfCasesPerPageDropDown;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc3 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc3.onreadystatechange = function () {
		if (xmlDoc3.readyState == 4) displayNumberOfCasesPerPageDropDown()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  xmlDoc3.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?NumLines=" + NumLines + "&theRequest=getNumberOfCasesPerPageDropDown");	
}

//Function that reads through the xml document number of cases per page tags and pulls the information into a drop down for display on the web page
function displayNumberOfCasesPerPageDropDown()
{
  var x = xmlDoc3.getElementsByTagName('numberofcasesperpages');
  var selectTag = document.createElement('select');
  selectTag.setAttribute('id','NumLines');
  selectTag.id = 'NumLines';
  selectTag.setAttribute('name','NumLines');
  selectTag.name = 'NumLines';
  selectTag.setAttribute('onChange','loadPrintReadyVersionLink();loadBookmarkThisPageLink()');  
  var functionName = "dropDownChange2";
  var theFunction = "selectTag.onchange = function " + functionName + "() { loadPrintReadyVersionLink();loadBookmarkThisPageLink() };";		
  selectTag.onchange = eval(theFunction);
  selectTag.setAttribute('style','width:240px');
  selectTag.style.width = '240px';
  
  for (j=0;j<x[0].childNodes.length;j++)
  {
	if (x[0].childNodes[j].nodeType != 1) continue;
	var optionTag = document.createElement('option');
	var isSelected = x[0].childNodes[j].getAttribute('selected');
	if (isSelected == 'yes')
	{
	  optionTag.setAttribute('selected','selected');
	  optionTag.selected = 'selected';
	}
	optionTag.setAttribute('value',x[0].childNodes[j].getAttribute('value'));
	optionTag.value = x[0].childNodes[j].getAttribute('value');
	var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
	optionTag.appendChild(tagValue);
	selectTag.appendChild(optionTag);					
  }	
  if (document.getElementById('NumberOfCasesPerPageDisplay').hasChildNodes())
  {
	document.getElementById('NumberOfCasesPerPageDisplay').removeChild(document.getElementById('NumLines'));
	document.getElementById('NumberOfCasesPerPageDisplay').appendChild(selectTag);
  }
  else
  {
	document.getElementById('NumberOfCasesPerPageDisplay').appendChild(selectTag);
  }				
}

//Function that imports the page title data from the xml document by receiving the current value of the court or agency drop down, creating an xml document object, calling the display page title function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the value of the court or agency drop down and the particular request (getting the page title), so therefore, the server knows what to process.
function importPageTitle(CourtOrAgency)
{
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc4 = document.implementation.createDocument("", "", null);
	xmlDoc4.onload = displayPageTitle;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc4 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc4.onreadystatechange = function () {
		if (xmlDoc4.readyState == 4) displayPageTitle()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  xmlDoc4.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?CourtOrAgency=" + CourtOrAgency + "&theRequest=getPageTitle");	
}

//Function that reads through the xml document page title tag and pulls the information into the web page for display
function displayPageTitle()
{
  var x = xmlDoc4.getElementsByTagName('pagetitles');
  var divTag = document.createElement('div');
  divTag.setAttribute('id','PageTitle');
  divTag.id = 'PageTitle';  
  for (j=0;j<x[0].childNodes.length;j++)
  {
	if (x[0].childNodes[j].nodeType != 1) continue;
	var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
  }  
  var h3Tag = document.createElement('h3');  
  h3Tag.appendChild(tagValue);
  divTag.appendChild(h3Tag);					
  if (document.getElementById('TitleDisplay').hasChildNodes())
  {
	document.getElementById('TitleDisplay').removeChild(document.getElementById('PageTitle'));
	document.getElementById('TitleDisplay').appendChild(divTag);
  }
  else
  {
	document.getElementById('TitleDisplay').appendChild(divTag);
  }  
}

//Function that loads the print-ready version link when the page is initially loaded by calling the display print-ready version link function
function loadPrintReadyVersionLink() 
{
  displayPrintReadyVersionLink();
}

//Calls the onload function to load the print-ready version link upon loading of the web page
addOnloadEvent(loadPrintReadyVersionLink);

//Function that displays the print ready version link to the web browser
function displayPrintReadyVersionLink()
{
  var divTag = document.createElement('div');
  divTag.setAttribute('id','PrintReady');
  divTag.id = 'PrintReady';
}

//Function that loads the bookmark this page link when the page is initially loaded by calling the display bookmark this page link function
function loadBookmarkThisPageLink() 
{
  displayBookmarkThisPageLink();
}

//Calls the onload function to load the bookmark this page link upon loading of the web page
addOnloadEvent(loadBookmarkThisPageLink);

//Function that displays the bookmark this page link to the web browser
function displayBookmarkThisPageLink()
{
  var divTag = document.createElement('div');
  divTag.setAttribute('id','Bookmark');
  divTag.id = 'Bookmark';
  var theLink = document.createElement('a');
  var theURL = "http://www.wisbar.org/AM/CustomSource/ASPCode/caseindex.asp?NoLoad=Yes&Area=" + document.getElementById('CourtOrAgency').value + "&YearJump=" + document.getElementById('YearJump').value + "&NumLines=" + document.getElementById('NumLines').value;
  var theTitle = "Wisconsin case law index";
  var theHREF = "javascript:BookmarkPage('" + theTitle + "','" + theURL + "')"; 
  theLink.setAttribute('href',theHREF);
  theLink.href = theHREF;  
  theLink.setAttribute('className','SideNav2');
  theLink.className = 'SideNav2';
  var imgTag = document.createElement('img');
  imgTag.setAttribute('src','/AM/Graphics/template/Interior/bookmark.gif');
  imgTag.src = '/AM/Graphics/template/Interior/bookmark.gif';
  imgTag.setAttribute('width','23');
  imgTag.width = '23';
  imgTag.setAttribute('height','22');
  imgTag.width = '22';
  imgTag.setAttribute('align','middle');
  imgTag.align = 'middle';
  var bookmarkThisPageText = document.createTextNode(" Bookmark this page");  
  theLink.appendChild(imgTag);
  theLink.appendChild(bookmarkThisPageText);
  divTag.appendChild(theLink);
  
}

//Function that imports the alert message data from the xml document by creating an xml document object, calling the display alert message function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the particular request (getting the alert message), so therefore, the server knows what to process.
function importAlertMessage()
{
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc5 = document.implementation.createDocument("", "", null);
	xmlDoc5.onload = displayAlertMessage;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc5 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc5.onreadystatechange = function () {
		if (xmlDoc5.readyState == 4) displayAlertMessage()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  xmlDoc5.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?theRequest=getAlertMessage");	
}

//Function that reads through the xml document alert message tag and pulls the information into the web page for display
function displayAlertMessage()
{
  var x = xmlDoc5.getElementsByTagName('alertmessages');
  var divTag = document.createElement('div');
  divTag.setAttribute('id','AlertMessage');
  divTag.id = 'AlertMessage';
  divTag.setAttribute('style','margin-left:15px');
  divTag.style.margin='15px';
  var fontTag = document.createElement('font');
  var bTag = document.createElement('b');
  fontTag.setAttribute('style','color:red');  
  fontTag.style.color = 'red';  
  for (j=0;j<x[0].childNodes.length;j++)
  {
	if (x[0].childNodes[j].nodeType != 1) continue;
	var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
  }
  bTag.appendChild(tagValue);
  fontTag.appendChild(bTag);  
  divTag.appendChild(fontTag);
  if (document.getElementById('AlertMessageDisplay').hasChildNodes())
  {
	document.getElementById('AlertMessageDisplay').removeChild(document.getElementById('AlertMessage'));
	document.getElementById('AlertMessageDisplay').appendChild(divTag);
  }
  else
  {
	document.getElementById('AlertMessageDisplay').appendChild(divTag);
  }
  if (document.getElementById('RecordDisplay').hasChildNodes()) 
  {
	document.getElementById('RecordDisplay').removeChild(document.getElementById('sortedtable'));
	document.getElementById('RecordDisplay').removeChild(document.getElementById('Pagination'));	
  }
}

//Function that validates the form to make sure the user selected a court or agency.  If the user did not select a court or agency an alert is displayed.  If the user did select a court or agency then the import database records function is called.
function validateForm()
{
  if (document.form1.CourtOrAgency.selectedIndex == 0)
  {
  	importAlertMessage();
  }
  else
  {
	importPageTitle(document.form1.CourtOrAgency.value);
  	importDatabaseRecords(document.form1.OrdMode.value, document.form1.OrdModeFiling.value, document.form1.OrdModePetitioner.value, document.form1.OrdModeDocket.value, document.form1.OrdModeEmployer.value, document.form1.OrdModeCaseName.value, document.form1.OrdModeCitation.value, document.form1.PreviousSortColumnIndex.value, document.form1.SortColumnIndex.value, document.form1.Page.value, document.form1.LastRecordToDisplay.value);		
  }
}

//Function that imports the database records from the xml document by receiving the order modes (ascending/descending), the sort column index (the default is set to 1 which is in reference to the filing date column), the page that the user is on (the default is set to 1 for the first page of cases), the last record to display on the page, the court or agency, the year and the number of cases per page to display.  The function creates an xml document object, calls the display database records function and loads the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the order modes for sorting functionality, the sort column index (used to indicate what column to sort by), the page that the user is on, the last record to be displayed on the page, the court or agency, the year, the number of cases per page and the particular request (getting the database records), so therefore, the server knows what to process
function importDatabaseRecords(OrdMode, OrdModeFiling, OrdModePetitioner, OrdModeDocket, OrdModeEmployer, OrdModeCaseName, OrdModeCitation, PreviousSortColumnIndex, SortColumnIndex, Page, LastRecordToDisplay, CourtOrAgency, YearJump, NumLines)
{
  if (document.getElementById('AlertMessageDisplay').hasChildNodes())
  {
	document.getElementById('AlertMessageDisplay').removeChild(document.getElementById('AlertMessage'));	
  }
  document.getElementById("RecordDisplay").innerHTML = "<div align='center'><h2>Searching....</h2><br><img src='/AM/Graphics/bigrotation.gif'></div>";
  if (document.implementation && document.implementation.createDocument)
  {
	xmlDoc6 = document.implementation.createDocument("", "", null);
	xmlDoc6.onload = displayDatabaseRecords;
  }
  else if (window.ActiveXObject)
  {
	xmlDoc6 = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc6.onreadystatechange = function () {
		if (xmlDoc6.readyState == 4) displayDatabaseRecords()
	};
  }
  else
  {
	alert('Your browser can\'t handle this script');
	return;
  }
  if (CourtOrAgency == null)
  {
    CourtOrAgency = document.getElementById('CourtOrAgency').value;
  }  
  if (YearJump == null)
  {
    YearJump = document.getElementById('YearJump').value;
  }
  if (NumLines == null)
  {
    NumLines = document.getElementById('NumLines').value;
  }
  xmlDoc6.load("/AM/CustomSource/ASPCode/caseindexprocess.asp?OrdMode=" + OrdMode + "&OrdModeFiling=" + OrdModeFiling + "&OrdModePetitioner=" + OrdModePetitioner + "&OrdModeDocket=" + OrdModeDocket + "&OrdModeEmployer=" + OrdModeEmployer + "&OrdModeCaseName=" + OrdModeCaseName + "&OrdModeCitation=" + OrdModeCitation + "&PreviousSortColumnIndex=" + PreviousSortColumnIndex + "&SortColumnIndex=" + SortColumnIndex + "&Page=" + Page + "&LastRecordToDisplay=" + LastRecordToDisplay + "&CourtOrAgency=" + CourtOrAgency + "&YearJump=" + YearJump + "&NumLines=" + NumLines + "&theRequest=getDatabaseRecords");  
}

//Function that reads through the xml document record tags and pulls the information into tables for displaying the Case Law Cases.  In addition to displaying the cases, the script also creates the sorting for the cases and the pagination navigation listed at the bottom of the web page
function displayDatabaseRecords() {
  var tableTag = document.createElement('table');  
  tableTag.setAttribute('id','sortedtable');  
  tableTag.id = 'sortedtable';
  tableTag.setAttribute('width','99%');
  tableTag.width = '99%';
  var tableBodyTag = document.createElement('tbody');  
  tableTag.appendChild(tableBodyTag);
	
  var rowTag = document.createElement('tr');  
  var cellTag = document.createElement('th');
  cellTag.setAttribute("style","width:20px");
  cellTag.style.width = "20px";
  var cellData = document.createTextNode("#");
  cellTag.appendChild(cellData);  
  rowTag.appendChild(cellTag);  
  
  var w = xmlDoc6.getElementsByTagName('records');
  var RecordCount = Number(w[0].getAttribute('recordcount'));
  var Page = Number(w[0].getAttribute('page'));
  var FirstRecordToDisplay = Number(w[0].getAttribute('firstrecordtodisplay'));
  var LastRecordToDisplay = Number(w[0].getAttribute('lastrecordtodisplay'));
  var theCounter = FirstRecordToDisplay;  
  var NumLines = Number(w[0].getAttribute('numlines'));
  var OrdMode = w[0].getAttribute('ordmode');
  var OrdModeFiling = w[0].getAttribute('ordmodefiling');
  var OrdModePetitioner = w[0].getAttribute('ordmodepetitioner');  
  var OrdModeDocket = w[0].getAttribute('ordmodedocket');
  var OrdModeEmployer = w[0].getAttribute('ordmodeemployer');
  var OrdModeCaseName = w[0].getAttribute('ordmodecasename');
  var OrdModeCitation = w[0].getAttribute('ordmodecitation');
  var PreviousSortColumnIndex = w[0].getAttribute('previoussortcolumnindex');
  var SortColumnIndex = w[0].getAttribute('sortcolumnindex');
  var CourtOrAgency = Number(w[0].getAttribute('courtoragency'));
  var YearJump = Number(w[0].getAttribute('yearjump'));
  
  //The script that builds the new link for the print-ready version
  var divTag = document.createElement('div');
  divTag.setAttribute('id','PrintReady');
  divTag.id = 'PrintReady';
  
  //The script that builds the new link for the bookmark this page
  var divTag = document.createElement('div');
  divTag.setAttribute('id','Bookmark');
  divTag.id = 'Bookmark';
  var theLink = document.createElement('a');
  var theURL = "http://www.wisbar.org/AM/CustomSource/ASPCode/caseindex.asp?OrdMode=" + OrdMode + "&OrdModeFiling=" + OrdModeFiling + "&OrdModePetitioner=" + OrdModePetitioner + "&OrdModeDocket=" + OrdModeDocket + "&OrdModeEmployer=" + OrdModeEmployer + "&OrdModeCaseName=" + OrdModeCaseName + "&OrdModeCitation=" + OrdModeCitation + "&PreviousSortColumnIndex=" + PreviousSortColumnIndex + "&SortColumnIndex=" + SortColumnIndex + "&Page=" + Page + "&LastRecordToDisplay=" + LastRecordToDisplay + "&Area=" + CourtOrAgency + "&YearJump=" + YearJump + "&NumLines=" + NumLines;
  if (CourtOrAgency == '1')
  {
	if (YearJump == '0')
	{
	  var theTitle = "Wisconsin Supreme Court opinions all years listing - " + NumLines + " cases per page";
	}
	else
	{
	  var theTitle = "Wisconsin Supreme Court opinions " + YearJump + " listing - " + NumLines + " cases per page";
	}  	
  }
  else if (CourtOrAgency == '2')
  {
	if (YearJump == '0')
	{
	  var theTitle = "Wisconsin Court of Appeals opinions all years listing - " + NumLines + " cases per page";
	}
	else
	{
	  var theTitle = "Wisconsin Court of Appeals opinions " + YearJump + " listing - " + NumLines + " cases per page";
	}  	
  }
  else if (CourtOrAgency == '4')
  {
	if (YearJump == '0')
	{
	  var theTitle = "Wisconsin Tax Appeals decisions all years listing - " + NumLines + " cases per page";
	}
	else
	{
	  var theTitle = "Wisconsin Tax Appeals decisions " + YearJump + " listing - " + NumLines + " cases per page";
	}  	
  }
  else if (CourtOrAgency == '5')
  {
	if (YearJump == '0')
	{
	  var theTitle = "Wisconsin WERC Grievance Awards all years listing - " + NumLines + " cases per page";
	}
	else
	{
	  var theTitle = "Wisconsin WERC Grievance Awards " + YearJump + " listing - " + NumLines + " cases per page";
	}  	
  }
  else if (CourtOrAgency == '6')
  {
	if (YearJump == '0')
	{
	  var theTitle = "Wisconsin WERC Decisions all years listing - " + NumLines + " cases per page";
	}
	else
	{
	  var theTitle = "Wisconsin WERC Decisions " + YearJump + " listing - " + NumLines + " cases per page";
	}  	
  }
  var theHREF = "javascript:BookmarkPage('" + theTitle + "','" + theURL + "')";  
  theLink.setAttribute('href',theHREF);
  theLink.href = theHREF;
  theLink.setAttribute('className','SideNav2');
  theLink.className = 'SideNav2';
  var imgTag = document.createElement('img');
  imgTag.setAttribute('src','/AM/Graphics/template/Interior/bookmark.gif');
  imgTag.src = '/AM/Graphics/template/Interior/bookmark.gif';
  imgTag.setAttribute('width','23');
  imgTag.width = '23';
  imgTag.setAttribute('height','22');
  imgTag.width = '22';
  imgTag.setAttribute('align','middle');
  imgTag.align = 'middle';
  var bookmarkThisPageText = document.createTextNode(" Bookmark this page");  
  theLink.appendChild(imgTag);
  theLink.appendChild(bookmarkThisPageText);
  divTag.appendChild(theLink);
  
  //The script that builds the header columns for the cases and the sort feature
  if (OrdMode == "DESC")
  {
    var OrdModeOpposite = "ASC";
  }
  else
  {
    var OrdModeOpposite = "DESC";
  }
  if (OrdModeFiling == "DESC")
  {
    var OrdModeFilingOpposite = "ASC";
  }
  else
  {
    var OrdModeFilingOpposite = "DESC";
  }
  if (OrdModePetitioner == "DESC")
  {
    var OrdModePetitionerOpposite = "ASC";
  }
  else
  {
    var OrdModePetitionerOpposite = "DESC";
  }  
  if (OrdModeDocket == "DESC")
  {
    var OrdModeDocketOpposite = "ASC";
  }
  else
  {
    var OrdModeDocketOpposite = "DESC";
  }
  if (OrdModeEmployer == "DESC")
  {
    var OrdModeEmployerOpposite = "ASC";
  }
  else
  {
    var OrdModeEmployerOpposite = "DESC";
  }
  if (OrdModeCaseName == "DESC")
  {
    var OrdModeCaseNameOpposite = "ASC";
  }
  else
  {
    var OrdModeCaseNameOpposite = "DESC";
  }
  if (OrdModeCitation == "DESC")
  {
    var OrdModeCitationOpposite = "ASC";
  }
  else
  {
    var OrdModeCitationOpposite = "DESC";
  }
  var PreviousSortColumnIndex = w[0].getAttribute('previoussortcolumnindex');
  var SortColumnIndex = w[0].getAttribute('sortcolumnindex');
  var theCoordinates = getAnchorPosition('anchor');
  var theAttributeValue = "javascript:scroll("+ theCoordinates.x + "," + (theCoordinates.y-130) + ")";  
  
  var cellTag = document.createElement('th');
  cellTag.setAttribute('className','small');
  cellTag.className = 'small';
  cellTag.setAttribute("style","width:50px");
  cellTag.style.width = "50px";
  var theLink = document.createElement('a');  
  theLink.setAttribute('href',theAttributeValue);
  theLink.href = theAttributeValue;
  if (PreviousSortColumnIndex != '1' && OrdModeFiling == 'DESC')
  {
    OrdModeFilingOpposite = 'DESC';
  }
  var theClickEvent = "importDatabaseRecords('" + OrdModeFilingOpposite + "', '" + OrdModeFilingOpposite + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '1', '1', '0')";
  theLink.setAttribute('onClick',theClickEvent);
  var functionName = "FilingSort";
  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
  theLink.onclick = eval(theFunction);  
  var imgTag = document.createElement('img');
  if (SortColumnIndex == '1')
  {
	if (OrdModeFiling == "DESC")
	{
	  imgTag.setAttribute('src','img/arrow_g_down.gif');
  	  imgTag.src = 'img/arrow_g_down.gif';
	  imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	  imgTag.alt = 'Current sort descending/Sort ascending?';
  	  imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	  imgTag.title = 'Current sort descending/Sort ascending?';
	}
	else
	{
	  imgTag.setAttribute('src','img/arrow_g_up.gif');
  	  imgTag.src = 'img/arrow_g_up.gif';
	  imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	  imgTag.alt = 'Current sort ascending/Sort descending?';
  	  imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	  imgTag.title = 'Current sort ascending/Sort descending?';
	}
  }
  else
  {
	if (PreviousSortColumnIndex != '1' && OrdModeFiling == 'DESC')
	{
	  imgTag.setAttribute('src','img/down_arrow.gif');
  	  imgTag.src = 'img/down_arrow.gif';
	  imgTag.setAttribute('alt','Sort descending');
  	  imgTag.alt = 'Sort descending';
  	  imgTag.setAttribute('title','Sort descending');
  	  imgTag.title = 'Sort descending';
	}
	else
	{
      if (OrdModeFiling == "DESC")
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort ascending');
  	    imgTag.alt = 'Sort ascending';
  	    imgTag.setAttribute('title','Sort ascending');
  	    imgTag.title = 'Sort ascending';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/up_arrow.gif');
  	    imgTag.src = 'img/up_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
	}
  }  
  theLink.appendChild(imgTag);
  var cellData = document.createTextNode("Filing ");
  cellTag.appendChild(cellData);
  cellTag.appendChild(theLink);
  rowTag.appendChild(cellTag);
  
  if (CourtOrAgency == 1 || CourtOrAgency == 2)
  {
    var cellTag = document.createElement('th');
    cellTag.setAttribute('className','small');
    cellTag.className = 'small';  
    var theLink = document.createElement('a');  
    theLink.setAttribute('href',theAttributeValue);
    theLink.href = theAttributeValue;  
    var theClickEvent = "importDatabaseRecords('" + OrdModeCaseNameOpposite + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseNameOpposite + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '2', '1', '0')";  
    var functionName = "CaseNameSort";
    var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
    theLink.onclick = eval(theFunction);  
    var imgTag = document.createElement('img');
    if (SortColumnIndex == '2')
    {
      if (OrdModeCaseName == "DESC")
	  {
	    imgTag.setAttribute('src','img/arrow_g_down.gif');
  	    imgTag.src = 'img/arrow_g_down.gif';
	    imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	    imgTag.alt = 'Current sort descending/Sort ascending?';
  	    imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	    imgTag.title = 'Current sort descending/Sort ascending?';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/arrow_g_up.gif');
  	    imgTag.src = 'img/arrow_g_up.gif';
	    imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	    imgTag.alt = 'Current sort ascending/Sort descending?';
  	    imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	    imgTag.title = 'Current sort ascending/Sort descending?';
	  }
    }
    else
    {
      if (OrdModeCaseName == "DESC")
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort ascending');
  	    imgTag.alt = 'Sort ascending';
  	    imgTag.setAttribute('title','Sort ascending');
  	    imgTag.title = 'Sort ascending';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/up_arrow.gif');
  	    imgTag.src = 'img/up_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
    }  
    theLink.appendChild(imgTag);
    var cellData = document.createTextNode("Case name ");
    cellTag.appendChild(cellData);
    cellTag.appendChild(theLink);
    rowTag.appendChild(cellTag);
  }  
  
  if (CourtOrAgency == 4)
  {
    var cellTag = document.createElement('th');
    cellTag.setAttribute('className','small');
    cellTag.className = 'small';  
    var theLink = document.createElement('a');  
    theLink.setAttribute('href',theAttributeValue);
    theLink.href = theAttributeValue;  
    var theClickEvent = "importDatabaseRecords('" + OrdModePetitionerOpposite + "', '" + OrdModeFiling + "', '" + OrdModePetitionerOpposite + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '3', '1', '0')";  
    var functionName = "PetitionerSort";
    var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
    theLink.onclick = eval(theFunction);  
    var imgTag = document.createElement('img');
    if (SortColumnIndex == '3')
    {
      if (OrdModePetitioner == "DESC")
	  {
	    imgTag.setAttribute('src','img/arrow_g_down.gif');
  	    imgTag.src = 'img/arrow_g_down.gif';
	    imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	    imgTag.alt = 'Current sort descending/Sort ascending?';
  	    imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	    imgTag.title = 'Current sort descending/Sort ascending?';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/arrow_g_up.gif');
  	    imgTag.src = 'img/arrow_g_up.gif';
	    imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	    imgTag.alt = 'Current sort ascending/Sort descending?';
  	    imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	    imgTag.title = 'Current sort ascending/Sort descending?';
	  }
    }
    else
    {
      if (OrdModePetitioner == "DESC")
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort ascending');
  	    imgTag.alt = 'Sort ascending';
  	    imgTag.setAttribute('title','Sort ascending');
  	    imgTag.title = 'Sort ascending';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/up_arrow.gif');
  	    imgTag.src = 'img/up_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
    }  
    theLink.appendChild(imgTag);
    var cellData = document.createTextNode("Petitioner ");
    cellTag.appendChild(cellData);
    cellTag.appendChild(theLink);
    rowTag.appendChild(cellTag);
  }  
  
  if (CourtOrAgency == 5 || CourtOrAgency == 6)
  {
    var cellTag = document.createElement('th');
    cellTag.setAttribute('className','small');
    cellTag.className = 'small';  
    var theLink = document.createElement('a');  
    theLink.setAttribute('href',theAttributeValue);
    theLink.href = theAttributeValue;  
    var theClickEvent = "importDatabaseRecords('" + OrdModeEmployerOpposite + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployerOpposite + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '4', '1', '0')";  
    var functionName = "EmployerSort";
    var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
    theLink.onclick = eval(theFunction);  
    var imgTag = document.createElement('img');
    if (SortColumnIndex == '4')
    {
      if (OrdModeEmployer == "DESC")
	  {
	    imgTag.setAttribute('src','img/arrow_g_down.gif');
  	    imgTag.src = 'img/arrow_g_down.gif';
	    imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	    imgTag.alt = 'Current sort descending/Sort ascending?';
  	    imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	    imgTag.title = 'Current sort descending/Sort ascending?';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/arrow_g_up.gif');
  	    imgTag.src = 'img/arrow_g_up.gif';
	    imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	    imgTag.alt = 'Current sort ascending/Sort descending?';
  	    imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	    imgTag.title = 'Current sort ascending/Sort descending?';
	  }
    }
    else
    {
      if (OrdModeEmployer == "DESC")
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort ascending');
  	    imgTag.alt = 'Sort ascending';
  	    imgTag.setAttribute('title','Sort ascending');
  	    imgTag.title = 'Sort ascending';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/up_arrow.gif');
  	    imgTag.src = 'img/up_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
    }  
    theLink.appendChild(imgTag);
    var cellData = document.createTextNode("Employer ");
    cellTag.appendChild(cellData);
    cellTag.appendChild(theLink);
    rowTag.appendChild(cellTag);
  }  
  
  var cellTag = document.createElement('th');  
  cellTag.setAttribute('className','small');
  cellTag.className = 'small';
  cellTag.setAttribute("style","width:77px");
  cellTag.style.width = "77px";
  var theLink = document.createElement('a');  
  theLink.setAttribute('href',theAttributeValue);
  theLink.href = theAttributeValue;
  if (PreviousSortColumnIndex != '5')
  {
    OrdModeDocketOpposite = "DESC"
  }
  var theClickEvent = "importDatabaseRecords('" + OrdModeDocketOpposite + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocketOpposite + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + SortColumnIndex + "', '5', '1', '0')";  
  var functionName = "DocketSort";
  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
  theLink.onclick = eval(theFunction);  
  var imgTag = document.createElement('img');
  if (SortColumnIndex == '5')
  {
	if (PreviousSortColumnIndex != '5')
	{
	  imgTag.setAttribute('src','img/arrow_g_down.gif');
  	  imgTag.src = 'img/arrow_g_down.gif';
	  imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	  imgTag.alt = 'Current sort descending/Sort ascending?';
  	  imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	  imgTag.title = 'Current sort descending/Sort ascending?';  
	}
	else
	{
      if (OrdModeDocket == "DESC")
	  {
	    imgTag.setAttribute('src','img/arrow_g_down.gif');
  	    imgTag.src = 'img/arrow_g_down.gif';
	    imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	    imgTag.alt = 'Current sort descending/Sort ascending?';
  	    imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	    imgTag.title = 'Current sort descending/Sort ascending?';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/arrow_g_up.gif');
  	    imgTag.src = 'img/arrow_g_up.gif';
	    imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	    imgTag.alt = 'Current sort ascending/Sort descending?';
  	    imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	    imgTag.title = 'Current sort ascending/Sort descending?';
	  }
	}
  }
  else
  {
    if (OrdModeDocket == "DESC")
	{
	  if (PreviousSortColumnIndex != '5')
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/down_arrow.gif');
  	    imgTag.src = 'img/down_arrow.gif';
	    imgTag.setAttribute('alt','Sort ascending');
  	    imgTag.alt = 'Sort ascending';
  	    imgTag.setAttribute('title','Sort ascending');
  	    imgTag.title = 'Sort ascending';
	  }
	}
	else
	{
	  imgTag.setAttribute('src','img/up_arrow.gif');
  	  imgTag.src = 'img/up_arrow.gif';
	  imgTag.setAttribute('alt','Sort descending');
  	  imgTag.alt = 'Sort descending';
  	  imgTag.setAttribute('title','Sort descending');
  	  imgTag.title = 'Sort descending';
	}
  }  
  theLink.appendChild(imgTag);
  var cellData = document.createTextNode("Docket# ");
  cellTag.appendChild(cellData);
  cellTag.appendChild(theLink);
  rowTag.appendChild(cellTag); 
  
  if (CourtOrAgency == 1 || CourtOrAgency == 2)
  {
	var cellTag = document.createElement('th');
    cellTag.setAttribute('className','small');
    cellTag.className = 'small';
	cellTag.setAttribute("style","width:77px");
    cellTag.style.width = "77px";
    var theLink = document.createElement('a');  
    theLink.setAttribute('href',theAttributeValue);
    theLink.href = theAttributeValue;
	if (PreviousSortColumnIndex != '6')
	{
      OrdModeCitationOpposite = "DESC"
	}
    var theClickEvent = "importDatabaseRecords('" + OrdModeCitationOpposite + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitationOpposite + "', '" + SortColumnIndex + "', '6', '1', '0')";  
    var functionName = "CitationSort";
    var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
    theLink.onclick = eval(theFunction);  
    var imgTag = document.createElement('img');	
	if (SortColumnIndex == '6')
    {
	  if (PreviousSortColumnIndex != '6')
	  {
		imgTag.setAttribute('src','img/arrow_g_down.gif');
  	    imgTag.src = 'img/arrow_g_down.gif';
	    imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	    imgTag.alt = 'Current sort descending/Sort ascending?';
  	    imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	    imgTag.title = 'Current sort descending/Sort ascending?';
	  }
	  else
	  {
	    if (OrdModeCitation == "DESC")
	    {
		  imgTag.setAttribute('src','img/arrow_g_down.gif');
  	      imgTag.src = 'img/arrow_g_down.gif';
	      imgTag.setAttribute('alt','Current sort descending/Sort ascending?');
  	      imgTag.alt = 'Current sort descending/Sort ascending?';
  	      imgTag.setAttribute('title','Current sort descending/Sort ascending?');
  	      imgTag.title = 'Current sort descending/Sort ascending?';
	    }
	    else
	    {
	      imgTag.setAttribute('src','img/arrow_g_up.gif');
  	      imgTag.src = 'img/arrow_g_up.gif';
	      imgTag.setAttribute('alt','Current sort ascending/Sort descending?');
  	      imgTag.alt = 'Current sort ascending/Sort descending?';
  	      imgTag.setAttribute('title','Current sort ascending/Sort descending?');
  	      imgTag.title = 'Current sort ascending/Sort descending?';
	    }
	  }
    }
    else
    {
      if (OrdModeCitation == "DESC")
	  {
		if (PreviousSortColumnIndex != '6')
	    {
		  imgTag.setAttribute('src','img/down_arrow.gif');
  	      imgTag.src = 'img/down_arrow.gif';
	      imgTag.setAttribute('alt','Sort descending');
  	      imgTag.alt = 'Sort descending';
  	      imgTag.setAttribute('title','Sort descending');
  	      imgTag.title = 'Sort descending';
		}
		else
		{
		  imgTag.setAttribute('src','img/down_arrow.gif');
  	      imgTag.src = 'img/down_arrow.gif';
	      imgTag.setAttribute('alt','Sort ascending');
  	      imgTag.alt = 'Sort ascending';
  	      imgTag.setAttribute('title','Sort ascending');
  	      imgTag.title = 'Sort ascending';
		}	    
	  }
	  else
	  {
	    imgTag.setAttribute('src','img/up_arrow.gif');
  	    imgTag.src = 'img/up_arrow.gif';
	    imgTag.setAttribute('alt','Sort descending');
  	    imgTag.alt = 'Sort descending';
  	    imgTag.setAttribute('title','Sort descending');
  	    imgTag.title = 'Sort descending';
	  }
    }  
    theLink.appendChild(imgTag);
    var cellData = document.createTextNode("Citation ");
    cellTag.appendChild(cellData);
    cellTag.appendChild(theLink);
    rowTag.appendChild(cellTag);
  }  
  
  //The script that builds the table rows of records  
  var x = xmlDoc6.getElementsByTagName('record');
  if (x.length == 0)
  {
    importAlertMessage('No results found for your search.  Please try again.');
  }
  else
  {
    tableBodyTag.appendChild(rowTag);
  }
  for (i=0;i<x.length;i++)
  {
	var rowTag = document.createElement('tr');
	if (i == 0) {
		var rowColorAlternater = 1;
	}
	if (rowColorAlternater == 1) {
		var theBGColor = 'a3c8ef';
		rowColorAlternater = 2;
	} else {
		var theBGColor = 'ffffff';
		rowColorAlternater = 1;
	}	  
	rowTag.setAttribute('bgcolor','#' + theBGColor);
  	rowTag.bgColor = '#' + theBGColor;
	var theMouseOverAction = "this.bgColor='#6a9fdd';if (document.getElementById('prevlink" + i + "') && document.getElementById('thelink" + i + "')) {document.getElementById('prevlink" + i + "').style.color=document.getElementById('thelink" + i + "').style.color;} if (document.getElementById('thelink" + i + "')) {document.getElementById('thelink" + i + "').style.color='#660000';}";
	rowTag.setAttribute('onMouseOver',theMouseOverAction);	  
	var functionName = "theMouseOverEvent";
    var theFunction = "rowTag.onmouseover = function " + functionName + "() { " + theMouseOverAction + " };";		
  	rowTag.onmouseover = eval(theFunction);
	var theMouseOutAction = "this.bgColor='#" + theBGColor + "';if (document.getElementById('thelink" + i + "')) {document.getElementById('thelink" + i + "').style.color=document.getElementById('prevlink" + i + "').style.color;}";  	
	rowTag.setAttribute('onMouseOut',theMouseOutAction);	  
	var functionName = "theMouseOutEvent";
    var theFunction = "rowTag.onmouseout = function " + functionName + "() { " + theMouseOutAction + " };";		
  	rowTag.onmouseout = eval(theFunction);
	  
	var cellTag = document.createElement('td');
	cellTag.setAttribute('className','record');
    cellTag.className = 'record';
	cellTag.setAttribute('style','padding:3px');
    cellTag.style.padding = '3px';
	var theFieldValue = document.createTextNode(theCounter);
	theCounter = theCounter + 1;
	var theLink = document.createElement('a');
	var theHREF = x[i].getAttribute('link');
	theLink.setAttribute('href',theHREF);
	theLink.href = theHREF;
	theLink.setAttribute('target','_blank');
    theLink.target = '_blank';
	theLink.appendChild(theFieldValue);
	cellTag.appendChild(theLink);
	rowTag.appendChild(cellTag);
	for (j=0;j<x[i].childNodes.length;j++)
	{
	  if (x[i].childNodes[j].nodeType != 1) continue;
		var cellTag = document.createElement('td');
		var theFieldName = x[i].childNodes[j].nodeName;
		if (theFieldName == "filingdate")
		{
		  cellTag.setAttribute('nowrap','nowrap');
  	  	  cellTag.nowrap = 'nowrap';
		  cellTag.setAttribute('style','padding:3px');
          cellTag.style.padding = '3px';
		}
		if (theFieldName == "docketnumber")
		{
		  cellTag.setAttribute('nowrap','nowrap');
  	  	  cellTag.nowrap = 'nowrap';
		  cellTag.setAttribute('style','padding:3px');
          cellTag.style.padding = '3px';
		}
		if (theFieldName == "citation")
		{
		  cellTag.setAttribute('nowrap','nowrap');
  	  	  cellTag.nowrap = 'nowrap';
		  cellTag.setAttribute('style','padding:3px');
          cellTag.style.padding = '3px';
		}
		if (theFieldName == "casename" || theFieldName == "petitioner" || theFieldName == "employer")
		{
		  cellTag.setAttribute('className','record2');
  		  cellTag.className = 'record2';
		  cellTag.setAttribute('style','padding:3px');
          cellTag.style.padding = '3px';
		  if (CourtOrAgency == 4 || CourtOrAgency == 5 || CourtOrAgency == 6)
		  {
		    var theFieldValue = document.createTextNode(PCase(x[i].childNodes[j].firstChild.nodeValue));
		  }
		  else
		  {
		    var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
		  }		  
		  var theSpan = document.createElement('span');
		  theSpan.setAttribute('id','prevlink' + i);  
  		  theSpan.id = 'prevlink' + i;
		  cellTag.appendChild(theSpan);
		}
		else
		{
		  cellTag.setAttribute('className','record');
  		  cellTag.className = 'record';
		  cellTag.setAttribute('style','padding:3px');
          cellTag.style.padding = '3px';
		  var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
		}		  
		var theLink = document.createElement('a'); 
	  	theLink.setAttribute('href',theHREF);
	  	theLink.href = theHREF;
		if (theFieldName == "casename")
		{
		  theLink.setAttribute('id','thelink' + i);  
  		  theLink.id = 'thelink' + i;
		}
		theLink.setAttribute('target','_blank');
	    theLink.target = '_blank';
	  	theLink.appendChild(theFieldValue);
	  	cellTag.appendChild(theLink);
		rowTag.appendChild(cellTag);			
	}
	tableBodyTag.appendChild(rowTag);		
  }  
  
  //The script that builds the pagination navigation
  var NumCasesPerPage = NumLines;
  var TotalRecords = RecordCount;
  var NumberOfPages = roundNumber(+TotalRecords/NumCasesPerPage);  
  
  if ((TotalRecords/NumCasesPerPage) - NumberOfPages > 0)
  {
    NumberOfPages = NumberOfPages + 1; 
  }
  
  var divTag = document.createElement('div');
  divTag.setAttribute('id','Pagination');  
  divTag.id = 'Pagination';
  divTag.setAttribute('align','center')
  divTag.align = 'center';
  
  if (NumberOfPages > 1)
  {
    var rowTag = document.createElement('tr');
	var cellTag = document.createElement('td');
	var brTag = document.createElement('br');
	cellTag.appendChild(brTag);
	rowTag.appendChild(cellTag);
	tableBodyTag.appendChild(rowTag);
	
	var theData = document.createTextNode("More results:");
	divTag.appendChild(theData);
	var brTag = document.createElement('br');
	divTag.appendChild(brTag);
	
	if (Page != 1)
	{
	  var theLink = document.createElement('a');
	  theLink.setAttribute('href',theAttributeValue);
	  theLink.href = theAttributeValue;
	  var PreviousPage = Page - 1;
	  LastRecordToDisplay = PreviousPage * NumLines;	  
	  var theClickEvent = "importDatabaseRecords('" + OrdMode + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '" + SortColumnIndex + "', '" + PreviousPage + "', '" + LastRecordToDisplay + "')";
	  theLink.setAttribute('onClick',theClickEvent);
	  var functionName = "pageClickPrevious";
  	  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
	  theLink.onclick = eval(theFunction);		
	  var theData = document.createTextNode("Previous");
	  theLink.appendChild(theData);
	  divTag.appendChild(theLink);
	  var theData = document.createTextNode(" | ");
      divTag.appendChild(theData);
	}
	
	if (Page > 10)
	{
	  var theLink = document.createElement('a');
	  theLink.setAttribute('href',theAttributeValue);
	  theLink.href = theAttributeValue;
	  if (Page % 10 > 0)
	  {
	    var StartNumber = Page - (Page % 10 - 1)
		var EndNumber = StartNumber + 9;
	  }
	  else
	  {
		var StartNumber = Page - 9
		var EndNumber = StartNumber + 9;
	  }	  
	  var PreviousPageSet = StartNumber - 10;
	  LastRecordToDisplay = PreviousPageSet * NumLines;
	  var theClickEvent = "importDatabaseRecords('" + OrdMode + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '" + SortColumnIndex + "', '" + PreviousPageSet + "', '" + LastRecordToDisplay + "')";
	  theLink.setAttribute('onClick',theClickEvent);
	  var functionName = "pageClickPreviousSet";
  	  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
	  theLink.onclick = eval(theFunction);		
	  var theData = document.createTextNode((StartNumber - 10) + "-" + (StartNumber - 1));
	  theLink.appendChild(theData);
	  divTag.appendChild(theLink);
	  var theData = document.createTextNode(" | ");
      divTag.appendChild(theData);
	  
	  if (EndNumber > NumberOfPages)
	  {
	    EndNumber = NumberOfPages;
	  }
	}	
	else
	{
	  var StartNumber = 1;
	  var EndNumber = 10;	  
	}
	if (NumberOfPages <= 10)
	{
	  EndNumber = NumberOfPages;
	}	
	for (w=StartNumber;w<=EndNumber;w++)
	{
	  if (w <= NumberOfPages)
	  {
	    if (Page == w)
	    {
		  var theData = document.createTextNode(w);
		  divTag.appendChild(theData);				
	    }
	    else
	    {
		  var theLink = document.createElement('a');
		  theLink.setAttribute('href',theAttributeValue);
		  theLink.href = theAttributeValue;		
		  LastRecordToDisplay = w * NumLines;		
		  var theClickEvent = "importDatabaseRecords('" + OrdMode + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '" + SortColumnIndex + "', '" + w + "', '" + LastRecordToDisplay + "')";
		  theLink.setAttribute('onClick',theClickEvent);
		  var functionName = "pageClick" + w;
  		  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
		  theLink.onclick = eval(theFunction);		
		  var theData = document.createTextNode(w);
		  theLink.appendChild(theData);
		  divTag.appendChild(theLink);				
	    }	  
	    if (w != EndNumber)
	    {
		  var theData = document.createTextNode(" | ");
		  divTag.appendChild(theData);		
	    }
	  }
    }
	if ((EndNumber - StartNumber == 9) && EndNumber < NumberOfPages)
	{
	  var theData = document.createTextNode(" | ");
      divTag.appendChild(theData);
	  var theLink = document.createElement('a');
	  theLink.setAttribute('href',theAttributeValue);
	  theLink.href = theAttributeValue;
	  var NextPageSet = StartNumber + 10;
	  LastRecordToDisplay = NextPageSet * NumLines;	  
	  var theClickEvent = "importDatabaseRecords('" + OrdMode + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '" + SortColumnIndex + "', '" + NextPageSet + "', '" + LastRecordToDisplay + "')";
	  theLink.setAttribute('onClick',theClickEvent);
	  var functionName = "pageClickNextSet";
  	  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
	  theLink.onclick = eval(theFunction);
	  if (w + 9 > NumberOfPages)
	  {
		var theData = document.createTextNode((w) + "-" + (NumberOfPages));
	  }
	  else
	  {
		var theData = document.createTextNode((w) + "-" + (w + 9));
	  }
	  theLink.appendChild(theData);
	  divTag.appendChild(theLink);
	}
	if (Page < NumberOfPages)
	{		
	  var theData = document.createTextNode(" | ");
      divTag.appendChild(theData);
	  var theLink = document.createElement('a');
	  theLink.setAttribute('href',theAttributeValue);
	  theLink.href = theAttributeValue;
	  var NextPage = Page + 1;
	  LastRecordToDisplay = NextPage * NumLines;
	  var theClickEvent = "importDatabaseRecords('" + OrdMode + "', '" + OrdModeFiling + "', '" + OrdModePetitioner + "', '" + OrdModeDocket + "', '" + OrdModeEmployer + "', '" + OrdModeCaseName + "', '" + OrdModeCitation + "', '" + PreviousSortColumnIndex + "', '" + SortColumnIndex + "', '" + NextPage + "', '" + LastRecordToDisplay + "')";
	  theLink.setAttribute('onClick',theClickEvent);
	  var functionName = "pageClickNext";
  	  var theFunction = "theLink.onclick = function " + functionName + "() { " + theClickEvent + "};";		
	  theLink.onclick = eval(theFunction);		
	  var theData = document.createTextNode("Next");
	  theLink.appendChild(theData);
	  divTag.appendChild(theLink);
	}	
  }
  
  //The script that controls the display of the div tags within the search page
  document.getElementById("RecordDisplay").innerHTML = "";    
  if (document.getElementById('RecordDisplay').hasChildNodes()) 
  {
	document.getElementById('RecordDisplay').removeChild(document.getElementById('sortedtable'));
	document.getElementById('RecordDisplay').removeChild(document.getElementById('Pagination'));
	document.getElementById('RecordDisplay').appendChild(tableTag);
	document.getElementById('RecordDisplay').appendChild(divTag);
  } 
  else 
  {
	document.getElementById('RecordDisplay').appendChild(tableTag);
	document.getElementById('RecordDisplay').appendChild(divTag);
  }    
}