	function jsListButtonLink(lc,ll,targ)
	{
		if (lc != null && ll != null)
		{
			rowNum = eval("document.all['" + ll + "'].ACTIVEREQUEST");
			rowNum = (rowNum != null)? rowNum : 1;
			try{
				loc = eval("document.all['" + ll + "'].rows[rowNum].cells[" + lc + "].innerText");
				if (targ != null && targ != '')
					eval(targ + ".location.href=loc");
					else
					self.location.href=loc;
			}
			catch(exception){
			alert("NO ROW SELECTED EXCEPTION:\n"+exception.description);
			}
		}
	}
	
	var rowData,
		sortedColumn,
		sortedDirection,
		startRow,
		sortAnywhere,
		endRow,
		lastRow,
		element;
	function jsListTableInit(lmnt)
	{
	element = lmnt;
	rowData = new Array();
	sortedColumn = null;
	sortedDirection = null;
	startRow	= element.getAttribute("STARTROW",0);
	sortAnywhere	= element.getAttribute("SORTANYWHERE",0);
	endRow		= element.getAttribute("ENDROW",0);
	lastRow = 0;
	
	//figure out where to start sorting
	if (startRow == null)
	{
	  startRow = 0;
	}
	//figure out where to end sorting	
	if (endRow != null)
		lastRow = element.rows.length - endRow;
	else
		lastRow = element.rows.length;
		
	jsListTableArray();
	}
	
	//main function
	function jsListTableSort()
	{
	row 		= element.rows;
	column 		= event.srcElement.cellIndex;
   
     //Get the Sortable value of the clicked on cell
	//if the src Element is out of bounds
	if(event.srcElement.parentElement.rowIndex == null)
	{
	  return false;
	}
	try{
		isSortable = row[event.srcElement.parentElement.rowIndex].cells[column].getAttribute("SORTABLE");
		if(isSortable == "No")
		{
		  return false;
		}
	}
	catch(exception){}
	
	/* Sort by clicking on any row of the table [true|false] default is true */
	if (sortAnywhere)
	{
		if(event.srcElement.parentElement.rowIndex >= startRow)
		{
		  return false;
		}
	}
	//if a different colum is being sorted
	if (column != sortedColumn)
	{
		//if the array is upside down, flip it over
		if (sortedDirection == 'a')
		{
			//turn the data back over
			rowData.reverse();
			sortedDirection = 'd';
			//redraw the table so that they match
			ReDrawTable();
		}
		//GetSort Column
		GetSortColumn(column);
		//Sort the Array
		HeapSort(rowData,rowData.length-1);
		//Set the Sorted Column and Direction
		sortedColumn = column;
		sortedDirection = 'd';
	}
	//otherwise just flip the array and set the variables
	else
	{
		//flip the sorted array
		rowData.reverse();
	
		//if the colum is sorted in descending order
		if (sortedDirection == 'd')
			sortedDirection = 'a';
		else
			sortedDirection = 'd';
	}
	
    //Draw the New Table
	ReDrawTable();
}

function convertData(cell)
{
	tempCell=cell;
    //pull out the leading dollarsign if it's there
    tempCell=tempCell.replace("$","");
	//if the first part of the cell is a float
	if(parseFloat(tempCell))
	{
	   //Check to see if it's a mm/dd/yy or mm/dd/yyyy value
	   if(tempCell.indexOf("/") != -1)
	   {
			//parse off the month
			parsedCell = tempCell.split("/");
			if(parsedCell[2].length == 2)
			{
				if(parsedCell[2]<99)
					intDate='19'+parsedCell[2];
				else
					intDate = '20'+parsedCell[2];
			}
			else
				intDate = parsedCell[2];
			if(parsedCell[0].length==2)
				intDate=intDate+parsedCell[0];
			else
				intDate=intDate+'0'+parsedCell[0];
			if(parsedCell[1].length==2)
				intDate=intDate+parsedCell[1];
			else
				intDate=intDate+'0'+parsedCell[1];
			//Set the value to be passed out
			cell=parseInt(intDate);
		}
		//if the last character is also a number
		else if(parseInt(cell.substr(cell.length-1,cell.length))||(cell.substr(cell.length-1,cell.length)==0))
		{
			while(tempCell.indexOf(",") != -1)
			{
				tempCell = tempCell.replace(",","");
			}
			tempCell = parseFloat(tempCell);
			cell=tempCell
		}
	}
	//if the value is zero
	else if((tempCell.substr(0,1) == 0) && (tempCell.substr(tempCell.length-1,tempCell.length)==0))
	{
		cell = 0;
	}
	return cell;
}

//function to pull the data from the table to the array
function jsListTableArray()
{
    FArow = element.rows;

	//if your sorting 1 or fewer rows then just get out
	if	((lastRow - startRow) <= 1)
	{
		return (false);
	}
	
    //Keep track of your place in the current Row
    FAcurRow = 1;
	//loop over the table putting all the data we're interested in into an array
	for	( i = startRow; i < lastRow; i++ )
	{	
	    rowData[FAcurRow] = new Array;
	    rowData[FAcurRow][0] = 0;
		for	( n = 0; n <FArow[i].cells.length; n++ )
			rowData[FAcurRow][n+1] = element.rows[i].cells[n].innerHTML;
		FAcurRow ++;
	}
}

//function to get the colum value to sort on
function GetSortColumn(GSCcolumn)
{
    GSCcurRow = 1;
	for	( i = startRow; i < lastRow; i++ )
	{
	  rowData[GSCcurRow][0] = convertData(element.rows[i].cells[GSCcolumn].innerText);
	  GSCcurRow++;
	}
}

//function to rebuild the table with the sorted data, starting at StartRow and going to end of sorted data
function ReDrawTable()
{	
	//if it's an asceding sorted array then start at zero and end one early
	if(sortedDirection == 'a')
		RDTcurRow = 0;
	else
		RDTcurRow = 1;
	for(RDTi=startRow; RDTi<lastRow; RDTi++)
	{
		for ( RDTe = 1; RDTe <= row[RDTi].cells.length; RDTe++ )
			row[RDTi].cells[RDTe-1].innerHTML = rowData[RDTcurRow][RDTe];
		RDTcurRow++;
	}
}

//Function to parse the array into a heap (tree)
function Heapify(dataArray,i,HeapSize)
{
  //Figure the left child
  left=2*i;
  //figure the right child
  right=2*i+1;
  
  //if the Left Child is still in the heap and greater than the root
  if ((left <= HeapSize) && (dataArray[left][0] > dataArray[i][0]))
      //The left child is the largest
      largest = left;
  else
      //otherwise the root is the largest
      largest = i;

  //if the right child is still in the heap and is greater than the current largest
  if ((right <= HeapSize) && (dataArray[right][0] > dataArray[largest][0]))
      //then the right child is the largest
      largest = right;

  //if the root is not the largest then you have to swap
  if (largest != i) {
    //Swap the root with the largest child
    temp = dataArray[i];
	dataArray[i] = dataArray[largest];
	dataArray[largest] = temp;
	//Heap Sort from the largest Child
    Heapify(dataArray,largest,HeapSize);
  }
}

//Call the Heap Sort
function HeapSort(dataArray, n)
{
     HeapSize = n;
     //Do the first wrap through of the Heap Sort 
     for (i= parseInt(HeapSize/2); i >= 1; i--)
	 {   //Call the Heap function for each root node
         Heapify(dataArray,i,HeapSize);
	 }

	 //Come back up the tree putting the roots in their order
     for (i=n; i>=1; i--) {
	      //Swap the Root to the top
		  temp = dataArray[i];
		  dataArray[i] = dataArray[1];
		  dataArray[1] = temp;
          HeapSize--;
          Heapify(dataArray,1,HeapSize);
     }
}

	
function jsActivateRowClick(restoreBgColor,restoreTxtColor,clickRow,sRow,hColor,tColor,activeRow)
	{
	try
		{
		var RowIdx 	= event.srcElement.parentElement.rowIndex;
		if (RowIdx > sRow)
			{
			clickRow[RowIdx].style.color= tColor;
			clickRow[RowIdx].style.backgroundColor= hColor;
			activeRow = RowIdx;
			DeActivateRowClick(restoreBgColor,restoreTxtColor,clickRow,sRow,hColor,tColor,activeRow);
			return activeRow;
			}
		}
		catch(exception){}
	}
	
function DeActivateRowClick(restoreBgColor,restoreTxtColor,clickRow,sRow,hColor,tColor,activeRow)
	{
	try
		{
		for (e = sRow; e < clickRow.length; e++)
			{
			if (e != activeRow)
				{
				clickRow[e].style.color = restoreTxtColor;
				clickRow[e].style.backgroundColor = restoreBgColor;
				}
			}
			}
		catch(exception){}
	}
	
	
	//RowOver code
	function jsActivate(element,orientation,rhint,chint,textHover,bgHover,roRow)
	{
	if (orientation != null)
		{
		switch(orientation.toLowerCase())
			{
			case 'row':
			ActivateRow(element,rhint,chint,textHover,bgHover,roRow);
			break;
			
			case 'col':
			ActivateColumn(element,chint,rhint,roRow,textHover,bgHover);
			break;
			
			case 'both':
			ActivateRow(element,rhint,chint,textHover,bgHover,roRow);
			ActivateColumn(element,chint,rhint,roRow,textHover,bgHover);
			break;
			
			default:
			}
		}
	}

	function jsDeActivate(element,orientation,roRow,restoreRoTxtColor,restoreRoColor)
	{
	if (orientation != null)
		{
		switch(orientation.toLowerCase())
			{
			case 'row':
			DeActivateRow(element,roRow,restoreRoTxtColor,restoreRoColor);
			break;
			
			case 'col':
			DeActivateColumn(restoreRoTxtColor,restoreRoColor);
			break;
			
			case 'both':
			DeActivateRow(element,roRow,restoreRoTxtColor,restoreRoColor);
			DeActivateColumn(restoreRoTxtColor,restoreRoColor);
			break;
			
			default:
			}
		}
	}
	
	function ActivateRow(element,rhint,chint,textHover,bgHover,roRow)
	{
	try
		{
		RowIdx 	= event.srcElement.parentElement.rowIndex;
		cellIdx = event.srcElement.cellIndex;
		srcRow	= roRow[RowIdx].cells;
		
		if (chint != null)
		colHeaderTxt = "  ^ " + element.rows[chint].cells[cellIdx].innerText;
		else
		colHeaderTxt = "";
		
		if (rhint != null)
		rowTxt = "< "+ element.rows[RowIdx].cells[rhint].innerText;
		else
		rowTxt = "";
		
		hintText =  rowTxt +  colHeaderTxt;
		for (i = 0; i < srcRow.length; i++)
			{
			if (srcRow[i].tagName != 'TH')
				{
				srcRow[i].style.color = textHover;
				srcRow[i].style.backgroundColor = bgHover;
				if (chint != null || rhint != null)
				roRow[RowIdx].cells[cellIdx].setAttribute('title',hintText,0);
				}
			}
		}
		catch(exception){}
	}
	
	function DeActivateRow(element,roRow,restoreRoTxtColor,restoreRoColor)
	{
	try
		{
		RowIdx 	= event.srcElement.parentElement.rowIndex;
		srcRow	= roRow[RowIdx].cells;
		
			for (e = 0; e < srcRow.length; e++)
				{
				if (srcRow[e].tagName != 'TH')
					{
					srcRow[e].style.color = restoreRoTxtColor;
					srcRow[e].style.backgroundColor = restoreRoColor;
					}
				}
			}
		catch(exception){}
	}
	
	function ActivateColumn(element,chint,rhint,roRow,textHover,bgHover)
	{
	cellIdx = event.srcElement.cellIndex;
	idx = event.srcElement.parentElement.rowIndex;
	
	try
		{
		if (chint != null)
		colHeaderTxt = "  ^ " + element.rows[chint].cells[cellIdx].innerText;
		else
		colHeaderTxt = "";
		
		if (rhint != null)
		rowTxt = "< "+ element.rows[idx].cells[rhint].innerText;
		else
		rowTxt = "";
		
		hintText =  rowTxt +  colHeaderTxt;
		for (c = 1; c < idx; c++)
			{
			if (roRow[c].cells[cellIdx].tagName != 'TH')
				{
				roRow[c].cells[cellIdx].style.color = textHover;
				roRow[c].cells[cellIdx].style.backgroundColor = bgHover;
				if (chint != null || rhint != null)
				roRow[c +1].cells[cellIdx].setAttribute('title',hintText,0);
				}
			}
		}
		catch(exception){}
	}
	
	function DeActivateColumn(restoreRoTxtColor,restoreRoColor)
	{
	cellIdx = event.srcElement.cellIndex;
	idx = event.srcElement.parentElement.rowIndex;
	try
		{
		for (d = 1; d < idx; d++)
			{
			if (roRow[d].cells[cellIdx].tagName != 'TH')
				{
				roRow[d].cells[cellIdx].style.color = restoreRoTxtColor;
				roRow[d].cells[cellIdx].style.backgroundColor = restoreRoColor;
				}
			}
		}
		catch(exception){}
	}
	
	function addRow()
	{
	curTable = document.all.listView;
	frm = document.WizForm;
	TableName = frm.TableName.value;
	RowAction = frm.TableAction.value;
	FieldName = "";
	DataType = "";
	FieldSize = "";
	PrimaryKey = "";
	Indexed = "";
	NotNull = "";
	Unique = "";
	if (TableName == "")return false;
	switch(RowAction)
	{
		case 'AddTable':
		FieldName = frm.FieldName.value;
		DataType = frm.DataType.value;
		FieldSize = frm.FieldSize.value;
		PrimaryKey = frm.PrimaryKey.checked;
		Indexed = frm.Indexed.checked;
		NotNull = frm.NotNull.checked;
		Unique = frm.Unique.checked;
		if (FieldName == "")return false;
		hiddenCell = '<INPUT TYPE="hidden" NAME="addColumn" VALUE="' + RowAction +'~'+ TableName +'~'+ FieldName +'~'+ DataType +'~'+ FieldSize +'~'+ PrimaryKey +'~'+ Indexed +'~'+ NotNull +'~'+ Unique + '">';
		document.WizForm.FieldName.focus();
		break;
		
		case 'RemoveTable':
		hiddenCell = '<INPUT TYPE="hidden" NAME="addColumn" VALUE="' + RowAction +'~'+ TableName + '">';
		document.WizForm.TableName.focus();
		break;
	}
	
		newRow = curTable.insertRow(curTable.rows.length);
		cell0 = newRow.insertCell(0);
		cell0.innerText = TableName;
		cell1 = newRow.insertCell(1);
		cell1.innerText = FieldName;
		cell2 = newRow.insertCell(2);
		cell2.innerText = DataType;
		cell3 = newRow.insertCell(3);
		cell3.innerText = FieldSize;
		cell4 = newRow.insertCell(4);
		cell4.innerText = PrimaryKey;
		cell5 = newRow.insertCell(5);
		cell5.innerText = Indexed;
		cell6 = newRow.insertCell(6);
		cell6.innerText = NotNull;
		cell7 = newRow.insertCell(7);
		cell7.innerText = Unique;
		cell8 = newRow.insertCell(8);
		cell8.innerHTML = hiddenCell;
		cell8.className = 'linkColumn';
		
		//Clean up
		document.all.listView.ACTIVEREQUEST = curTable.rows.length-1;
		try{
		doc.FieldName.value='';
		doc.FieldSize.value='';
		doc.PrimaryKey.checked=false;
		doc.Indexed.checked=false;
		doc.NotNull.checked=false;
		doc.Unique.checked=false;
		}
		catch(exception){}
	
	}
	
	function deleteRow()
	{
	try{
	selOption = document.all.listView.ACTIVEREQUEST;
	curTable = document.all.listView;
	selOption = (selOption < 1)? 1 : selOption;
	curTable.deleteRow(selOption);
	document.all.listView.ACTIVEREQUEST = curTable.rows.length-1;
	document.WizForm.FieldName.focus();
	}
	catch(exception){alert("No Row Selected Exception \n" + exception.description);}
	}