	var tableWidget_tableCounter = 0;
	var tableWidget_arraySort = new Array();
	var tableWidget_okToSort = true;
	var activeColumn = new Array();
	var arrowImagePath = "http://itwiw.com/images/";	// Path to arrow images
	var sortCol=-1;
	var sortDir="";
	var sortDB=false;
	var sortURLBase="";
	var nohand="";

// alternating means the rows' cellcounts differ (multicell row followed by desc row)
  var alternateCells=false;
  var lastHighlightedRow1=null;
  var lastHighlightedRow2=null;
	var highlight=true;

	function addEndCol(obj)
	{
		if(document.all)return;
		var rows = obj.getElementsByTagName('TR');
		for(var no=0;no<rows.length;no++){
			var cell = rows[no].insertCell(-1);
			cell.innerHTML = '&nbsp;';
			cell.style.width = '13px';
			cell.width = '13';

		}	
		
	}
	
	function highlightTableHeader()
	{
		this.className='tableWigdet_headerCellOver';
		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='tableWidget_headerCell';		
	}
	
	function mousedownTableHeader()
	{
		this.className='tableWigdet_headerCellDown';
		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()
	{
		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')indexThis++;		
		}

		var images = this.getElementsByTagName('IMG');
		
		if(this.getAttribute('direction') || this.direction){
			direction = this.getAttribute('direction');
			if(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{
		  if((this.innerHTML.substring(0,1)=="%")||
		    (this.innerHTML.substring(0,3)=="Uto")||
		    (this.innerHTML.substring(0,3)=="Stá")||
		    (this.innerHTML.substring(0,3)=="Kez")||
		    (this.innerHTML.substring(0,3)=="Kül")){
			  direction = 'descending';
			  this.setAttribute('direction','descending');
			  this.direction = 'descending';
			}else{
			  direction = 'ascending';
			  this.setAttribute('direction','ascending');
			  this.direction = 'ascending';
			}
		}
		
		// ha az összes rekord több lapon van, akkor db-ben kell orderby-ozni, nem csak a kliensen rendezni
		if(sortDB){
		  if(sortURLBase.length!=0)
		    document.location=sortURLBase+"&sortCol="+indexThis+"&sortColName="+this.innerHTML.substring(0,3)+"&sortDir="+direction;
		  else{document.skills.sortCol.value=indexThis;document.skills.sortColName.value=this.innerHTML.substring(0,3);document.skills.sortDir.value=direction;document.skills.pagenum.value=1;doSearch();}  
		  return;
		}
		
		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];
		
// bugfix for colspan if no record
if(tableObj.rows.length>1)if(indexThis>=tableObj.rows[1].cells.length)return false;

		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[0].style.display='none';
			images[1].style.display='inline';
			images[1].style.visibility = 'hidden';
			if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');			
		}

		activeColumn[widgetIndex] = this;
		
		var cellArray = new Array();
		var cellObjArray = new Array();

// addition to handle desc rows
    alternateCells=false;
    if(tableObj.rows.length>2)if(tableObj.rows[1].cells.length!=tableObj.rows[2].cells.length)alternateCells=true;
    if(alternateCells){
		  var cellObjArray2 = new Array();
  		for(var no=1;no<((tableObj.rows.length+1)/2);no++){
  			var content= tableObj.rows[no*2-1].cells[indexThis].innerHTML+'';
	 		  cellArray.push(content);
			  cellObjArray.push(tableObj.rows[no*2-1].cells[indexThis]);
			  cellObjArray2.push(tableObj.rows[no*2].cells[0]);
		  }
    }else{
  		for(var no=1;no<tableObj.rows.length;no++){
			  var content= tableObj.rows[no].cells[indexThis].innerHTML+'';
			  cellArray.push(content);
			  cellObjArray.push(tableObj.rows[no].cells[indexThis]);
		  }
    }

		if(sortMethod=='N'){
			cellArray = cellArray.sort(sortNumeric);
		}else{
			cellArray = cellArray.sort(sortString);
		}
		
		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('allreadySorted')){
						cellObjArray[no2].setAttribute('allreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);				
						if(tableObj.rows.length>2)if(tableObj.rows[1].cells.length!=tableObj.rows[2].cells.length)tBody.appendChild(cellObjArray2[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('allreadySorted')){
						cellObjArray[no2].setAttribute('allreadySorted','1');	
						tBody.appendChild(cellObjArray[no2].parentNode);				
						if(tableObj.rows.length>2)if(tableObj.rows[1].cells.length!=tableObj.rows[2].cells.length)tBody.appendChild(cellObjArray2[no2].parentNode);
					}
				}			
			}				
		}
		
		for(var no2=0;no2<cellObjArray.length;no2++){
			cellObjArray[no2].removeAttribute('allreadySorted');		
		}

		tableWidget_okToSort = true;
		
		
	}
	
	function initTableWidget(objId,width,height,sortArray)
	{
		width = width + '';
		height = height + '';
		var obj = document.getElementById(objId);
		tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
		if(width.indexOf('%')>=0){
			obj.style.width = width;
			obj.parentNode.style.width = width;
		}else{
			obj.style.width = width + 'px';
			obj.parentNode.style.width = width + 'px';
		}

		if(height.indexOf('%')>=0){
			obj.style.height = height;		
			obj.parentNode.style.height = height;			
			
		}else{
			obj.style.height = height + 'px';		
			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');
		for(var no=0;no<cells.length;no++){
			cells[no].className = 'tableWidget_headerCell';
			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;		
				cells[no].onclick = sortTable;	

				var img = document.createElement('IMG');
				img.src = arrowImagePath + 's_arrow_up.gif';
				cells[no].innerHTML+='&nbsp;';
				cells[no].appendChild(img);
				img.style.visibility = 'hidden';
				
				var img = document.createElement('IMG');
				img.src = arrowImagePath + 's_arrow_down.gif';
				cells[no].appendChild(img);	
				img.style.display = 'none';

			}else{
				cells[no].style.cursor = 'default';	
			}
			if(no==sortCol){
				direction = sortDir;
				cells[no].setAttribute('direction',sortDir);
				cells[no].direction = sortDir;	
		    
		    var images = cells[no].getElementsByTagName('IMG');
		    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 tBody = obj.getElementsByTagName('TBODY')[0];
		if(document.all && 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.indexOf('Opera')>=0){
				obj.parentNode.style.overflow = 'auto';
			}
		}
		
// addition to handle desc rows
    var isDescCell=0;
    alternateCells=0;
    if(obj.rows.length>2)if(obj.rows[1].cells.length!=obj.rows[2].cells.length)alternateCells=true;

		for(var no=1;no<obj.rows.length;no++){
         for(var no2=0;no2<obj.rows[no].cells.length;no2++){
           if(alternateCells){
             if(obj.rows[no].cells[no2].rowSpan>1)obj.rows[no].cells[no2].className = 'tableWidget_descCell';
             else if(isDescCell)obj.rows[no].cells[no2].className = 'tableWidget_descCell';
             else obj.rows[no].cells[no2].className = 'tableWidget_normCell';
           }else obj.rows[no].cells[no2].className = 'tableWidget_singleCell';
         }

         if(obj.rows[no].cells[0].innerHTML.length>0){
  			   if(highlight)obj.rows[no].onmouseover = highlightDataRow;
			     if(highlight)obj.rows[no].onmouseout = deHighlightDataRow;
			     for(var no2=0;no2<sortArray.length;no2++){	/* Right align numeric cells */
				    if(sortArray[no2] && sortArray[no2]=='N')if(obj.rows[no].cells.length>no2)obj.rows[no].cells[no2].style.textAlign='right';
           }
			   }
         if(alternateCells)isDescCell=1-isDescCell;
		}
		for(var no2=0;no2<sortArray.length;no2++){	/* Right align numeric cells */
			if(sortArray[no2] && sortArray[no2]=='N')if(obj.rows[0].cells.length>no2)obj.rows[0].cells[no2].style.textAlign='right';
		}		
		
		if(objId!='list00')tableWidget_tableCounter++;
	}
	
	function selectDataRow()
	{
		if(navigator.userAgent.indexOf('Opera')>=0)return;
		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 highlightDataRow()
	{
		if(navigator.userAgent.indexOf('Opera')>=0)return;
    this.className='tableWidget_dataRollOver'+nohand;

// color connected row as well
    alternateCells=false;
    if(this.nextSibling)if(this.nextSibling.cells)if(this.cells.length!=this.nextSibling.cells.length)alternateCells=true;
    if(this.previousSibling)if(this.previousSibling.cells)if(this.cells.length!=this.previousSibling.cells.length)alternateCells=true;

    colorNext=false;colorPrev=false;
    if(alternateCells){
      if(this.nextSibling){
        if(this.cells.length>this.nextSibling.cells.length)colorNext=true;else colorPrev=true;
      }else colorPrev=true;
    }

    // Dehighlighting
    if((this!=lastHighlightedRow1)&&(this!=lastHighlightedRow2)&&(lastHighlightedRow1!=null)){
      lastHighlightedRow1.className=null;
      if(lastHighlightedRow2!=null)if(alternateCells)lastHighlightedRow2.className=null;
    }

    // Highlighting
    lastHighlightedRow1=this;
    if(colorNext){this.nextSibling.className='tableWidget_dataRollOver'+nohand;lastHighlightedRow2=this.nextSibling;}
    if(colorPrev){this.previousSibling.className='tableWidget_dataRollOver'+nohand;lastHighlightedRow2=this.previousSibling;}

		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.indexOf('Opera')>=0)return;
    
    if(lastHighlightedRow1!=null)lastHighlightedRow1.className=null;
    if(lastHighlightedRow2!=null)if(alternateCells)lastHighlightedRow2.className=null;
	}


