	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++;
		}
			
			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;
			
			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 tableObj = this.parentNode.parentNode.parentNode;
		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();
		
		for(var no=1;no<tableObj.rows.length;no++){
						
			temp[no] = tableObj.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= tableObj.rows[no].cells[indexThis].innerHTML+'';
			//document.write(temp1[no]+"BBBBBBBBBBBBBBB"+content+"HHH"+"<br>");
			cellArray.push(temp1[no]);
			cellObjArray.push(tableObj.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;
	}
	
	function initTableWidget(objId,width,height,sortArray,oldSorter)
	{
		width = width + '';
		height = height + '';
		var obj = document.getElementById(objId);
        
        if(navigator.userAgent.indexOf('MSIE')>=0){
            obj.parentNode.style.overflowY = 'scroll';
        }
        
		tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
		if(width.indexOf('%')>=0){
			obj.style.width = width;
			obj.parentNode.style.width = width;
		}else{
            obj.parentNode.style.width = width + 'px';            
            
            // need to offset widths to prevent scrollbar overlap in IE
            if (navigator.userAgent.indexOf('MSIE') >= 0) {
                obj.style.width = (width - 16) + 'px';
            } else {
			obj.style.width = width + 'px';
            }	
		}
		
		if(height.indexOf('%')>=0){	
			obj.parentNode.style.height = height;			
			
		}else{
			obj.parentNode.style.height = height + 'px';
		}
		obj.id = 'tableWidget' + tableWidget_tableCounter;
		addEndCol(obj);
		
		obj.cellSpacing = 0;
		obj.cellPadding = 0;
		obj.className='tableWidget';
		var tHead = obj.getElementsByTagName('THEAD')[0];
		var cells = tHead.getElementsByTagName('TD');
		if (cells.length == 0) {
			cells = tHead.getElementsByTagName('TH');
		}
		for(var no=0;no<cells.length;no++){
			cells[no].className = 'tableWidgetHeaderCell';
			cells[no].onselectstart = cancelTableWidgetEvent;
			if(no==cells.length-1){
				cells[no].style.borderRight = '0px';	
			}
									
			if(sortArray[no]){
				cells[no].onmouseover = highlightTableHeader;
				cells[no].onmouseout =  deHighlightTableHeader;
				cells[no].onmousedown = mousedownTableHeader;		
				cells[no].onmouseup = highlightTableHeader;
				
				if (oldSorter) {
					cells[no].onclick = sortTableOld;
				} else {
					cells[no].onclick = sortTable;	
				}
				
				var img = document.createElement('IMG');
				img.src = arrowImagePath + 'arrowDown.gif';
				cells[no].appendChild(img);	
				
				if (sortArray[no] == "SD" || sortArray[no] == "ND") {
					img.style.visibility = 'visible';
					cells[no].setAttribute('direction','descending');
				} else if (sortArray[no] == "S" || sortArray[no] == "N") {
					cells[no].setAttribute('direction','ascending');
					img.style.display = 'none';
				} else {
					img.style.display = 'none';
				}
				
				var img = document.createElement('IMG');
				img.src = arrowImagePath + 'arrowUp.gif';
				cells[no].appendChild(img);	
				if (sortArray[no] == "SD" || sortArray[no] == "ND") {
					img.style.display = 'none';
				}  else if (sortArray[no] == "S" || sortArray[no] == "N") {
					img.style.visibility = 'visible';
				} else {
					img.style.display = 'none';
				}
				
				
			}else{
				cells[no].style.cursor = 'default';	
			}
			
		}		
				
		var tBody = obj.getElementsByTagName('TBODY')[0];
		if(document.all && (navigator.userAgent == null || navigator.userAgent.indexOf('Opera')<0)) {
			tBody.className='scrollingContent';
			tBody.style.display='block';			
		}else{
			tBody.className='scrollingContent';
			tBody.style.height = (obj.parentNode.clientHeight-tHead.offsetHeight) + 'px';
			if (navigator.userAgent != null && navigator.userAgent.indexOf('Opera') >= 0) {
				obj.parentNode.style.overflow = 'auto';
			}
		}
		
		for(var no=1;no<obj.rows.length;no++){
			obj.rows[no].onmouseover = highlightDataRow;
			obj.rows[no].onmouseout = deHighlightDataRow;
			for(var no2=0;no2<sortArray.length;no2++){	
				if(sortArray[no2] && sortArray[no2]=='N')obj.rows[no].cells[no2].style.textAlign='center';
			}
		}
		for(var no2=0;no2<sortArray.length;no2++){	
			if(sortArray[no2] && sortArray[no2]=='N')obj.rows[0].cells[no2].style.textAlign='center';
		}		
		
		tableWidget_tableCounter++;
					
		 if (navigator.userAgent.indexOf('MSIE') >= 0) {
		 	if (oldSorter) {
				obj.rows[0].cells[1].setAttribute("direction", "descending");
				obj.rows[0].cells[1].click();
			}
	    }

	}
	
	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';
		}			
	}