	var tableWidget_tableCounter = 0;
	var tableWidget_arraySort = new Array();
	var tableWidget_okToSort = true;
	var activeColumn = new Array();
	var arrowImagePath = "images/icons/";	// Path to arrow images
	
	function addEndCol(obj)
	{
		if(document.all)return;
		
		var rows = obj.getElementsByTagName('TR');
		for(var no=0;no<rows.length;no++){
			var row = rows[no];
			var cell;
			if (row.getElementsByTagName('TH').length > 0) {
				var elementTH = document.createElement('th'); 
				cell = row.appendChild(elementTH);
			} else {
				cell = rows[no].insertCell(-1);
			}
			cell.innerHTML = '&nbsp;';
			cell.style.width = '13px';
			cell.width = '13px';
		}	
	}
	
	function highlightTableHeader()
	{
		this.className='tableWidgetHeaderCellOver';
		if(document.all){	// I.E fix for "jumping" headings
			var divObj = this.parentNode.parentNode.parentNode.parentNode;
			this.parentNode.style.top = divObj.scrollTop + 'px';

		}
			
	}
	
	function deHighlightTableHeader()
	{
		this.className='tableWidgetHeaderCell';		
	}
	
	function mousedownTableHeader()
	{
		this.className='tableWidgetHeaderCellDown';
		if(document.all){	// I.E fix for "jumping" headings
			var divObj = this.parentNode.parentNode.parentNode.parentNode;
			this.parentNode.style.top = divObj.scrollTop + 'px';
		}		
	}
	
	function sortNumeric(a,b){
		
		a = a.replace(/,/,'.');
		b = b.replace(/,/,'.');
		a = a.replace(/[^\d\.\/]/g,'');
		b = b.replace(/[^\d\.\/]/g,'');
		if(a.indexOf('/')>=0)a = eval(a);
		if(b.indexOf('/')>=0)b = eval(b);
		return a/1 - b/1;
	}
	

	function sortString(a, b) {

	  if ( a.toUpperCase() < b.toUpperCase() ) return -1;
	  if ( a.toUpperCase() > b.toUpperCase() ) return 1;
	  return 0;
	}
	
	function cancelTableWidgetEvent()
	{
		return false;
	}
	
	function sortTable() {
		sortTableLocal(this);
	}
	
	function sortTableOld()
	{
		if(!tableWidget_okToSort)return;
		tableWidget_okToSort = false;
		/* Getting index of current column */
		var obj = this;
		var indexThis = 0;
		while(obj.previousSibling){
			obj = obj.previousSibling;
			if(obj.tagName == 'TD' || obj.tagName == 'TH') {
				indexThis++;
			}
			if (obj.childNodes.length)  {
				var imgs =obj.getElementsByTagName('IMG');
				if (imgs[0]) imgs[0].style.display='none';
				if (imgs[1]) imgs[1].style.display='none';
			}
		}
		
		while(obj.nextSibling){
			obj = obj.nextSibling;
			if (obj.childNodes.length)  {
				var imgs =obj.getElementsByTagName('IMG');
				if (imgs[0]) imgs[0].style.display='none';
				if (imgs[1]) imgs[1].style.display='none';
			}
		}
		var images = this.getElementsByTagName('IMG');
		
		if(this.getAttribute('direction') || this.direction){
			direction = this.getAttribute('direction');
			if(navigator.userAgent != null && navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
			if(direction=='ascending'){
				direction = 'descending';
				this.setAttribute('direction','descending');
				this.direction = 'descending';	
			}else{
				direction = 'ascending';
				this.setAttribute('direction','ascending');		
				this.direction = 'ascending';		
			}
		}else{
			direction = 'ascending';
			this.setAttribute('direction','ascending');
			this.direction = 'ascending';
			//direction = 'descending';
			//this.setAttribute('direction','descending');
			//this.direction = 'descending';
		}
		
		if(direction=='descending'){
			images[0].style.display='inline';
			images[0].style.visibility='visible';
			images[1].style.display='none';
		}else{
			images[1].style.display='inline';
			images[1].style.visibility='visible';
			images[0].style.display='none';		
		}

		var tableObj1 =this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
		var	tableObj = tableObj1.getElementsByTagName('TABLE')[1];
		var tBody = tableObj.getElementsByTagName('TBODY')[0];
		
		var widgetIndex = tableObj.id.replace(/[^\d]/g,'');
		var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
		if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
			var images = activeColumn[widgetIndex].getElementsByTagName('IMG');
			//images[1].style.display='none';
			//images[0].style.display='inline';
			//images[0].style.visibility = 'visible';
			if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');			
		}

		activeColumn[widgetIndex] = this;
		
		var cellArray = new Array();
		var cellObjArray = new Array();
		var temp = new Array();
		var temp1 = new Array();
		var temp2 = new Array();
		var rows;
		var rowStItem = 1;
		if (navigator.userAgent.indexOf('MSIE 8') >= 0)  {
			rowStItem = 0;
			rows = tableObj.tBodies[0].getElementsByTagName('TR');
		}
		else {
			rowStItem = 1;
			rows = tableObj.rows;
		}
		for(var no=rowStItem;no<rows.length;no++){
						
			temp[no] = rows[no].cells[indexThis].innerHTML+'';
									
			if(temp[no].charAt(0)=="<" && temp[no].charAt(1)=="A") {
			
				temp1[no] = temp[no].substring(temp[no].indexOf(">")+1,temp[no].indexOf("/")-1)+":"+no;
				temp2[no] = temp[no].substring(0,temp[no].indexOf(">")+1)+no; }

			else if (temp[no].charAt(0)=="<" && temp[no].charAt(1)=="I") {
				
				temp1[no] = temp[no]; } 

			else {	temp1[no] = temp[no]; } 

			//document.write(temp1[no]);

			var content= rows[no].cells[indexThis].innerHTML+'';
			//document.write(temp1[no]+"BBBBBBBBBBBBBBB"+content+"HHH"+"<br>");
			cellArray.push(temp1[no]);
			cellObjArray.push(rows[no].cells[indexThis]);
			
		}
		
		//document.write(cellArray+ "<br>");
				
		if(sortMethod=='N'){
			cellArray = cellArray.sort(sortNumeric);
		}

		else {
			cellArray = cellArray.sort(sortString);
		}
		
		//document.write(cellArray+"<br>");
/* ---------------------------------------------------------------
		if(indexThis==0) {

		for(no1=0; no1<cellArray.length; no1++) { 
		
			var strl = "<A href=\"product.asp?theKey=1\" target=\"\">";
						
			cellArray[no1] = strl+cellArray[no1]+ "</A>";} } 
			
		//document.write(cellArray); 
//----------------------------------------------------------------*/
 
		
		var cellArraytemp = new Array();
				
		if(indexThis==0) {

		for(no1=0; no1<cellArray.length; no1++) { 
		
			for(nox=1; nox<temp2.length; nox++) {
			
				if(temp2[nox].substring(temp2[nox].indexOf(">")+1)==cellArray[no1].substring(cellArray[no1].indexOf(":")+1)) {
		
					var strl = temp2[nox].substring(0,temp2[nox].indexOf(">")+1);
					
					cellArraytemp[no1] = strl + cellArray[no1].substring(0,cellArray[no1].indexOf(":"))+"</A>"; }}}
					 
					//document.write(cellArraytemp[no1]+ "<br>"); }}}}
											
					//cellArray[no1] = strl+cellArray[no1]+ "</A>";} } */

		cellArray = cellArraytemp; }
		
		else {cellArray = cellArray;}

		if(direction=='descending'){
			for(var no=cellArray.length;no>=0;no--){
				for(var no2=0;no2<cellObjArray.length;no2++){   
					if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('alreadySorted')){
						cellObjArray[no2].setAttribute('alreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);			
					}				
				}			
			}
		}

		else {
			for(var no=0;no<cellArray.length;no++){
				for(var no2=0;no2<cellObjArray.length;no2++){		
					if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('alreadySorted')){
						cellObjArray[no2].setAttribute('alreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);				
					}				
				}			
			}				
		}
		
		for(var no2=0;no2<cellObjArray.length;no2++){
			cellObjArray[no2].removeAttribute('alreadySorted');		
		}

		tableWidget_okToSort = true;
	}
	/* Note: http://www.matts411.com/post/super_tables.
	 * Super Tables v0.30 - MIT Style License --- 
	 * Copyright (c) 2008 Matt Murphy, www.matts411.com --- Contributors: Joe Gallo 
	 */

	function initTableWidget(objId,width,height,sortArray,oldSorter)
	{
		width = width + '';
		height = height + '';
		tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
		this.cssSkin = "tableWidget";
		this.headerRows = parseInt("1");
		this.colWidths = [];
				
		/* Create the framework dom */
		this.sBase = document.createElement("DIV");
		this.sHeader = this.sBase.cloneNode(false);
		this.sHeaderInner = this.sBase.cloneNode(false);
		this.sData = this.sBase.cloneNode(false);
		this.sColGroup = document.createElement("COLGROUP");
				
		this.sDataTable = document.getElementById(objId);
		this.sDataTable.style.margin = "0px"; /* Otherwise looks bad */
		// need to offset widths to prevent scrollbar overlap in IE
		this.sDataTable.id = 'tableWidget' + tableWidget_tableCounter;
		addEndCol(this.sDataTable);
		if (this.cssSkin !== "") {
			this.sDataTable.className += " " + this.cssSkin;
		}
		this.sParent = this.sDataTable.parentNode;
		this.sParentHeight = this.sParent.offsetHeight;
		this.sParentWidth = this.sParent.offsetWidth;
		
		/* Attach the required classNames */
		this.sBase.className = "widgetTableDiv";
		this.sHeader.className = "tableHeader";
		this.sHeaderInner.className = "tableHeaderCell";
		this.sData.className = "tableData";
			
		/* Clone parts of the data table for the new header table */
		var alpha, beta, clean, cleanRow, i, j, k, m, n, p, hRow;
		this.sHeaderTable = this.sDataTable.cloneNode(false);
		if (this.sDataTable.tHead) {
			alpha = this.sDataTable.tHead;
			this.sHeaderTable.appendChild(alpha.cloneNode(false));
			beta = this.sHeaderTable.tHead;
			}else {
			alpha = this.sDataTable.tBodies[0];
			this.sHeaderTable.appendChild(alpha.cloneNode(false));
			beta = this.sHeaderTable.tBodies[0];
		}
		alpha = alpha.rows;
		beta.appendChild(alpha[0].cloneNode(true));
		hRow = beta.rows[0];
		for (j=0; j<hRow.cells.length;j++)  {
			hRow.cells[j].className = 'tableWidgetHeaderCell';
			hRow.cells[j].onselectstart = cancelTableWidgetEvent;
			if(j == hRow.cells.length - 1){
				hRow.cells[j].style.borderRight = '0px';	
			}
			if(sortArray[j]){
				hRow.cells[j].onmouseover = highlightTableHeader;
				hRow.cells[j].onmouseout = deHighlightTableHeader;
				hRow.cells[j].onmousedown = mousedownTableHeader;
				hRow.cells[j].onmouseup = highlightTableHeader;
				if (oldSorter) {
					hRow.cells[j].onclick = sortTableOld;
				} else {
					hRow.cells[j].onclick = sortTable;	
				}
				var img = document.createElement('IMG');
				img.src = arrowImagePath + 'arrowDown.gif';
				hRow.cells[j].appendChild(img);	
				
				if (sortArray[j] == "SD" || sortArray[j] == "ND") {
					img.style.visibility = 'visible';
					hRow.cells[j].setAttribute('direction','descending');
				} else if (sortArray[j] == "S" || sortArray[j] == "N") {
					hRow.cells[j].setAttribute('direction','ascending');
					img.style.display = 'none';
				} else {
					img.style.display = 'none';
				}
				var img = document.createElement('IMG');
				img.src = arrowImagePath + 'arrowUp.gif';
				hRow.cells[j].appendChild(img);	
				if (sortArray[j] == "SD" || sortArray[j] == "ND") {
					img.style.display = 'none';
				}  else if (sortArray[j] == "S" || sortArray[j] == "N") {
					img.style.visibility = 'visible';
				} else {
					img.style.display = 'none';
				}
			}else{
				hRow.cells[j].style.cursor = 'default';	
			}	
		}
		this.sHeaderInner.appendChild(this.sHeaderTable);
				
		alpha = this.sDataTable.tBodies[0].getElementsByTagName('TR');
		if (alpha.length ==0) {
			alpha = this.sDataTable.tHead.getElementsByTagName('TR');
		}
		for (i=0, j=alpha.length; i<j; i++) {
			clean = true;
			for (k=0, m=alpha[i].cells.length; k<m; k++) {
				if (alpha[i].cells[k].colSpan !== 1 || alpha[i].cells[k].rowSpan !== 1) {
					i += alpha[i].cells[k].rowSpan - 1;
					clean = false;
					break;
				}
			}
			if (clean === true) break; /* A row with no cells of colSpan > 1 || rowSpan > 1 has been found */
		}
		cleanRow = (clean === true) ? i : 0; /* Use this row index to calculate the column widths */
		for (i=0, j=alpha[cleanRow].cells.length; i<j; i++) {
			if (i === this.colWidths.length || this.colWidths[i] === -1) {
				if (navigator.userAgent.indexOf('MSIE 6') >= 0 || navigator.userAgent.indexOf('MSIE 7') >= 0) {
					if (alpha[cleanRow].cells[i].offsetWidth < 16) {
						this.colWidths[i] = 0;
					}
					else {					
						this.colWidths[i] = alpha[cleanRow].cells[i].offsetWidth - 16;
					}
				} else {
					this.colWidths[i] = alpha[cleanRow].cells[i].offsetWidth;
				}
			}
		}

		for (i=0, j=this.colWidths.length; i<j; i++) {
			this.sColGroup.appendChild(document.createElement("COL"));
			this.sColGroup.lastChild.setAttribute("width", this.colWidths[i]);
		}
		this.sDataTable.insertBefore(this.sColGroup.cloneNode(true), this.sDataTable.firstChild);
		this.sHeaderTable.insertBefore(this.sColGroup.cloneNode(true), this.sHeaderTable.firstChild);

		for(var no=1;no<this.sDataTable.rows.length;no++){
			this.sDataTable.rows[no].onmouseover = highlightDataRow;
			this.sDataTable.rows[no].onmouseout = deHighlightDataRow;
			for(var no2=0;no2<sortArray.length;no2++){	
				if(sortArray[no2] && sortArray[no2]=='N')this.sDataTable.rows[no].cells[no2].style.textAlign='center';
			}
		}
		for(var no2=0;no2<sortArray.length;no2++){	
			if(sortArray[no2] && sortArray[no2]=='N')this.sDataTable.rows[0].cells[no2].style.textAlign='center';
		}	
		
		/* Throw everything into sBase */
		this.sHeader.appendChild(this.sHeaderInner);
		this.sBase.appendChild(this.sHeader);
		this.sBase.appendChild(this.sData);
		this.sParent.insertBefore(this.sBase, this.sDataTable);
		this.sData.appendChild(this.sDataTable);
				
		/* Align the tables */
		var sDataStyles, sDataTableStyles;
		this.sHeaderHeight = this.sDataTable.tBodies[0].getElementsByTagName('TR')[(this.sDataTable.tHead) ? 0 : this.headerRows].offsetTop;
		sDataTableStyles = "margin-top: " + (this.sHeaderHeight * -1) + "px;";
		sDataStyles = "margin-top: " + this.sHeaderHeight + "px;";
		sDataStyles += "height: " + (height - this.sHeaderHeight - 30) + "px;";

		if (navigator.userAgent.indexOf('MSIE 6') >= 0 ) {
			sDataStyles += "width: " + (this.sParentWidth - 80) + 'px';
		}else if (navigator.userAgent.indexOf('MSIE 7') >= 0) {
			sDataStyles += "width: " + (this.sParentWidth - 60) + 'px';
		}else {
			sDataStyles += "width: " + this.sParentWidth + "px;";
		}	
		tableWidget_tableCounter++;
		this.sData.style.cssText = sDataStyles;
		this.sDataTable.style.cssText = sDataTableStyles;	

	}
	
	function highlightDataRow()
	{
		if(navigator.userAgent != null && navigator.userAgent.indexOf('Opera')>=0)return;
		this.className='tableWidget_dataRollOver';
		if(document.all){	// I.E fix for "jumping" headings
			var divObj = this.parentNode.parentNode.parentNode;
			var tHead = divObj.getElementsByTagName('TR')[0];
			tHead.style.top = divObj.scrollTop + 'px';
			
		}	
	}
	
	function deHighlightDataRow()
	{
		if(navigator.userAgent != null && navigator.userAgent.indexOf('Opera')>=0)return;
		this.className=null;
		if(document.all){	// I.E fix for "jumping" headings
			var divObj = this.parentNode.parentNode.parentNode;
			var tHead = divObj.getElementsByTagName('TR')[0];
			tHead.style.top = divObj.scrollTop + 'px';
		}			
	}