  var LVCS_NONE=0x0;
  var LVCS_ASC =0x1;
  var LVCS_DESC=0x2;
  var onMove=document.all
?
  function()
  {
   var x=window.event.offsetX;
   var w=this.offsetWidth;
   if(this.parent.bPressed){
	  this.parent.style.cursor='W-resize';
      x+=window.event.srcElement.offsetLeft-this.offsetLeft;
	  if(x<40)
	     return;
	  var dx=x-this.offsetWidth;
	  this.parent.width=this.parent.offsetWidth+dx;
	  this.style.width=x;
	  return;
     }
   if(x>=w-5){
	  this.parent.style.cursor='W-resize';
      this.parent.onBorder=true;
	 }
    else{
	   this.parent.style.cursor='default';
       this.parent.onBorder=false;
  	  }
  }
:
  function(e)
  {
    var x=e.layerX-this.offsetLeft,w=this.offsetWidth;
    if(x>=w-5){
	   this.parent.style.cursor='W-resize';
	   this.parent.onBorder=true;
	  }
	 else{
	   this.parent.style.cursor='default';
       this.parent.onBorder=false;
	  }
  };
  var onMouseDown=document.all
?
  function()
  {
   if(this.parent.onBorder){
	  this.setCapture(true);
	  this.parent.bPressed=true;
	 }
    else
      this.mainObj.sort(this.num);
  }
:
  function(e)
  {
   if(this.parent.onBorder){
	  this.parent.oCol=this;
	  this.parent.bPressed=true;
	  this.parent.addEventListener('mouseup',onCapMouseUp,true);
	  this.parent.addEventListener('mousemove',onCapMove,true);
	  this.parent.addEventListener('mouseout',onCapMouseOut,true);
	 }
    else
      this.mainObj.sort(this.num);
 };
  var onMouseUp=document.all
?
  function()
  {
   if(this.parent.bPressed){
	  this.releaseCapture();
	  this.parent.bPressed=false;
	  this.mainObj.syncColumns();
	 }
  }
:
 function(e)
 {
  if(this.parent.bPressed){
	 this.parent.oCol=null;
	 this.parent.bPressed=false;
	}
 };
  var onCapMove=null;
  var onCapMouseUp=null;
  var onCapMouseOut=null;
  if(!document.all){
	 onCapMove=function(e)
	 {
	  e.stopPropagation();
	  this.style.cursor='W-resize';
	  if(!this.bPressed)
		 return;
	  var x=e.layerX-this.oCol.offsetLeft;
	  if(x<40)
	     return;
	  var dx=x-this.oCol.offsetWidth;
	  this.style.width=this.offsetWidth+dx;
	  this.oCol.style.width=x;
	 };
	 onCapMouseUp=function(e)
	 {
	  e.stopPropagation();
      this.bPressed=false;
	  this.oCol=null;
	  this.removeEventListener('mousemove',onCapMove,true);
	  this.removeEventListener('mouseup',onCapMouseUp,true);
	  this.removeEventListener('mouseout',onCapMouseOut,true);
	  this.mainObj.syncColumns();
	 };
	 onCapMouseOut=function(e)
	 {
	  if(e.target!=this)
		 return;
	  e.stopPropagation();
      this.bPressed=false;
	  this.removeEventListener('mousemove',onCapMove,true);
	  this.removeEventListener('mouseup',onCapMouseUp,true);
	  this.removeEventListener('mouseout',onCapMouseOut,true);
	  this.mainObj.syncColumns();
	 };
	}
 function ListView(_parent,ip)
 {
  this.parent=_parent;
  if(this.parent.tagName.toLowerCase()=='div'){
	 this.parent.style.border='1px solid Gray';
	 this.parent.style.overflow='auto';
   }
  this.oDoc=document.all?_parent.document:_parent.ownerDocument;
  if(!ip)
     this.iconPath='icons/';
    else
	  this.iconPath=ip;
  if(this.iconPath!='' && this.iconPath.charAt(this.iconPath.length-1)!='/')
	 this.iconPath+='/';
  this.isa=new Image();
  this.isa.src=this.iconPath+'sa.gif';
  this.isd=new Image();
  this.isd.src=this.iconPath+'sd.gif';
  this.isn=new Image();
  this.isn.src=this.iconPath+'sn.gif';
  this.icw=13;
  this.ich=12;
  var t=this.oDoc.createElement('div');
  this.body=t;
  _parent.appendChild(t);
  t.id='body';
  t.style.cursor='default';
  t.style.position='absolute';
  t.style.left=0;
  t.style.color='Black';
  t.style.backgroundColor='Gray';
  t.style.font='normal normal normal 8pt Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif';
  t=this.oDoc.createElement('table');
  _parent.appendChild(t);
  t.id='hdr';
  t.tb=this.body;
  this.hdr=t;
  _parent.hdr=t;
  _parent.scY=0;
  _parent.onscroll=function()
  {
   if(this.scY!=this.scrollTop){
	  this.hdr.style.top=this.scrollTop;
	  this.scY=this.scrollTop;
	 }
  }
  _parent.onresize=function()
  {
   if(this.hdr){
	  this.hdr.style.top=this.scrollTop;
	 }
  };
  t.cellSpacing=0;
  t.mainObj=this;
  t.cellPadding=0;
  t.style.MozUserSelect='none';
  t.style.border='2px groove white';
  t.style.cursor='default';
  t.style.position='absolute';
  t.style.left=0;
  t.style.top=0;
  t.style.color='Blue';
  t.style.backgroundColor='#D4D0C8';
  t.style.font='normal normal normal 8pt Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif';
  t.onBorder=false;
  t.nCols=0
  t.bPressed=false;
  t.oCol=null;
  this.sortCol=-1;
  this.sortType=LVCS_NONE;
  this.addColumns=function(cols)
  {
   this.body.innerHTML='';
   if(this.nCols)
	  this.hdr.deleteRow(0);
   this.nCols=cols.length;
   this.hdr.style.width='0px';
   this.cols=[];
   var row=this.hdr.insertRow(-1),cell;
   for(var i=0;i<this.nCols;i++){
	   cell=row.insertCell(-1);
       cell.nowrap=true;
       cell.align='center';
	   cell.noWrap=true;
	   cell.style.borderRight='2px groove white';
	   cell.style.padding='2px 4px';
	   cell.innerHTML='<table cellspacing="0" cellpadding="0" style="font:'+this.hdr.style.font+';color:'+this.hdr.style.color+';"><tr><td nowrap>'+cols[i]+'</td><td><img width="13" height="12" src="'+this.isn.src+'" /></td></tr></table>';
	   cell.num=i;
	   this.cols[i]={};
	   cell.style.width=cell.offsetWidth;
	   this.cols[i].align='left';
	   cell.parent=this.hdr;
	   cell.mainObj=this;
	   cell.onmousemove=onMove;
	   cell.onmousedown=onMouseDown;
	   cell.onmouseup=onMouseUp;
      }
   this.hdr.style.top=0;
   this.hdr.style.width=this.hdr.offsetWidth;
   this.body.style.top=this.hdr.offsetHeight-1;
  };
  this.setColumnAlign=function(col,align)
  {
   this.cols[col].align=align;
  };
  this.setHdrColumnWidth=function(col,w)
  {
   this.hdr.rows[0].cells[col].style.width=w;
   this.cols[col].w=w;
  };
  this.fillTable=function(data,cols,rows,n)
  {
   if(this.parent.style && this.parent.style.display=='none')
	  return;
   if(rows==undefined){
	  rows=[];
	  for(var i=0;i<data.length;i++)
		  rows[i]=i;
	 }	
   if(n==undefined)
      n=rows.length;
     else if(n>rows.length)
			 n=rows.length;
   var cls=[];
   if(cols==undefined){
	  for(var i=0;i<this.nCols;i++)
      	  cls[i]=i;
	 }
	else{
	  for(var i=0;i<cols.length;i++)
		  if(cols[i])
	      	 cls[cls.length]=i;
	  }
   var a_str=[],w=[],row=this.hdr.rows[0];
   this.sortCol=-1;
   this.sortType=LVCS_NONE;
   for(var i=0;i<this.nCols;i++){
	   w[i]=row.cells[i].offsetWidth-5;
	   row.cells[i].getElementsByTagName('img')[0].src=this.isn.src;
      }
   var str='<table cellspacing="1" cellpadding="2" style="font:'+this.body.style.font+'">';
   for(var i=0;i<n;i++){
	   a_str[i]='<tr bgcolor="white">';
	   for(var j=0;j<this.nCols;j++)
		   a_str[i]+='<td nowrap width="'+w[j]+'" align="'+this.cols[j].align+'"><div style="overflow:hidden">'+(data[rows[i]][cls[j]]!=undefined?data[rows[i]][cls[j]]:'&nbsp;')+'</div></td>';
	   a_str[i]+='</tr>';
status='Creating: '+parseInt(100*(i+1)/n)+'%';
	  }
   str+=a_str.join('');
   str+='</table>';
   a_str=null;
   this.body.innerHTML=str;
   var tb=this.body.getElementsByTagName('table')[0];
   tb.style.width=this.hdr.offsetWidth-2;   
status='';
   this.hdr.style.top=this.parent.scrollTop;
  };
  this.getColumnSortImage=function(col){ return this.hdr.rows[0].cells[col].getElementsByTagName('img')[0];};
  this.syncColumns=function()
  {
   var w=[],row=this.hdr.rows[0],tb=this.body.getElementsByTagName('table')[0],
	   rows,n;
   if(!tb)
	  return;
   rows=tb.rows;
   if(!rows)
	  return;
   n=rows.length;
   if(n==0)
	  return;
   var W=this.hdr.offsetWidth-2;
   for(var i=0;i<this.nCols;i++)
	   w[i]=row.cells[i].offsetWidth-5;
   for(var i=0;i<n;i++)
	   for(var j=0;j<this.nCols;j++)
		   rows[i].cells[j].style.width=w[j];   
   tb.style.width=W;
   this.body.style.top=t.offsetHeight-1;
  }
  this.sortASC=function(a,b)
  {
   if(!isNaN(a[1]) && !isNaN(b[1])){
	  return (a[1]-b[1]);
	 }
   var rt=0;
   if(a[1]>b[1])
	  rt=1;
	 else if(a[1]<b[1])
			 rt=-1;
   return rt;
  }
  this.sortDESC=function(a,b)
  {
   if(!isNaN(a[1]) && !isNaN(b[1])){
	  return -1*(a[1]-b[1]);
	 }
   var rt=0;
   if(a[1]>b[1])
	  rt=-1;
	 else if(a[1]<b[1])
			 rt=1;
   return rt;
  }
  this.sortFct=function(sa){};
  this.sort=function(col)
  {
   if(this.sortCol==col){
	  if(this.sortType==LVCS_ASC)
	 	 this.sortType=LVCS_DESC;
		else
	   	  this.sortType=LVCS_ASC;
	 }
	else
	  this.sortType=LVCS_DESC;
   if(this.sortCol!=col && this.sortCol!=-1)
	  this.getColumnSortImage(this.sortCol).src=this.isn.src;
   this.getColumnSortImage(col).src=(this.sortType==LVCS_ASC)?this.isa.src:this.isd.src;
   this.sortCol=col;
   var cData=[],rows=this.body.getElementsByTagName('table')[0].rows;
   var nRows=rows.length,t=status;
   for(var i=0;i<nRows;i++){
	   cData[i]=[];
	   cData[i][0]=i;
	   cData[i][1]=rows[i].cells[col].getElementsByTagName('div')[0].innerHTML;
status='Preparing: '+parseInt(100*(i+1)/nRows)+'%';
	  }
   cData.sort((this.sortType==LVCS_ASC)?this.sortASC:this.sortDESC);
   this.sortFct(cData);
   var tb=this.body.getElementsByTagName('table')[0],a_str=[],w=[],row=this.hdr.rows[0];
   var str='<table cellspacing="1" cellpadding="2" style="font:'+this.body.style.font+'">';
   for(var i=0;i<this.nCols;i++)
	   w[i]=row.cells[i].offsetWidth-5;
   for(var i=0;i<nRows;i++){
	   a_str[i]='<tr bgcolor="white">';
	   row=tb.rows[cData[i][0]];
	   for(var j=0;j<this.nCols;j++)
		   a_str[i]+='<td nowrap width="'+w[j]+'" align="'+this.cols[j].align+'"><div style="overflow:hidden">'+row.cells[j].getElementsByTagName('div')[0].innerHTML+'</div></td>';
	   a_str[i]+='</tr>';
status='Sorting: '+parseInt(100*(i+1)/nRows)+'%';
	  }
   this.body.innerHTML='';
   str+=a_str.join('');
   str+='</table>';
   a_str=null;
   this.body.innerHTML=str;
   tb=this.body.getElementsByTagName('table')[0];
   tb.style.width=this.hdr.offsetWidth-2;
status=t;
  };
  this.deleteAllRows=function(){this.body.innerHTML='';this.hdr.style.top=0;};
  this.setHeaderSortOptions=function(_so)
  {
   var num=this.hdr.rows[0].cells.length;
   this.sortCol=_so[0];
   this.sortType=_so[1];
   for(var i=0;i<num;i++)
	   if(_so[0]==i)
	  	  this.hdr.rows[0].cells[i].getElementsByTagName('img')[0].src=_so[1]==LVCS_ASC?this.isa.src:this.isd.src;
		 else
		   this.hdr.rows[0].cells[i].getElementsByTagName('img')[0].src=this.isn.src;
  };
 }

