function grid()
{
	this.anzahl = 0;
	this.columns = new Array();
	this.origcolumns = new Array();
	this.store = new cache;
	this.sortorder = "";
	this.container="";
	this.createByCSV = function(el,csv)
	{
		var grc = "";
		this.container=el;
		var y = 0;
		var inhalt = new Array();
		csv=csv.split(core.isIE?"<BR>":"<br>");
		for(var z = 0;z<csv.length-1;z++)
		{
			inhalt[y] = {};
			line=csv[z].split("|");
			for(var a = 0;a<line.length;a++)
			{
				if( y == 0 )
				{
					this.columns.push( line[a] );
					this.origcolumns.push( line[a] );
				}
				else
				{
					inhalt[( y-1 )][this.columns[a]] = line[a];
				}
			}
			y++;
		}
		this.anzahl++;
		this.store.save('content',inhalt);
		this.dolayout();
	};
	this.dolayout=function()
	{
		var grc="";
		var id = false;

		var del = this.container.getAttribute('delete');
		var add = this.container.getAttribute('add');
		var edit = this.container.getAttribute('edit');
		var info = this.container.getAttribute('info');
		var stat = this.container.getAttribute('stat');
		var subdel = this.container.getAttribute('subdelete');
		var subedit = this.container.getAttribute('subedit');	
		var subinfo = this.container.getAttribute('subinfo');	
		var bestat = this.container.getAttribute('bestat');	
		if( add ) add = '&' + add; else add = '';
		inhalte=this.store.load('content');
		//core.var_dump(inhalte);
		for(var z = 0;z<inhalte.length;z++)
		{
			if(!inhalte[z])
				continue;
				
			var grd = "";
			for(var a = 0;a<this.columns.length;a++)
			{
				if( !id && inhalte[z][this.columns[a]] != undefined ){ id = (inhalte[z]['Id']?inhalte[z]['Id']:inhalte[z][this.columns[a]]); }
				if(this.columns[a]==this.origcolumns[a])
				{
					if(inhalte[z][this.columns[a]] == undefined)
						continue
					grd = grd + '<td>' + inhalte[z][this.columns[a]] + '</td>';
				}
			}
			if(!id)
			{
				continue;
			}
			grc = grc+'<tr class="line_' + ( z%2 ) + '" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)">'+grd;
			if(edit && !subedit)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&edit='+id+add,false)+'\' onMouseOver="showhelp(\'edit'+id+'\');" onMouseOut="closehelp(\'edit'+id+'\');"><img src="'+core.design+'icon/edit.png"></a><div class="help" id="edit'+id+'">Bearbeiten</div></td>';
			}
			if(del && !subdel)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&del='+id+add,true)+'\' onMouseOver="showhelp(\'delete'+id+'\');" onMouseOut="closehelp(\'delete'+id+'\');"><img src="'+core.design+'icon/delete.png"></a><div class="help" id="delete'+id+'">Entfernen</div></td>';
			}
			if(info && !subinfo)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&info='+id+add,false)+'\' onMouseOver="showhelp(\'info'+id+'\');" onMouseOut="closehelp(\'info'+id+'\');"><img src="'+core.design+'icon/info.png"></a><div class="help" id="info'+id+'">Informationen</div></td>';
			}
			if(bestat)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&bestat='+id+add,false)+'\' onMouseOver="showhelp(\'bestat'+id+'\');" onMouseOut="closehelp(\'bestat'+id+'\');"><img src="'+core.design+'icon/bestat.png"></a><div class="help" id="bestat'+id+'">Bestaetigen</div></td>';
			}
			if(stat)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&stat='+id+add,false)+'\' onMouseOver="showhelp(\'stat'+id+'\');" onMouseOut="closehelp(\'stat'+id+'\');"><img src="'+core.design+'icon/stat.png"></a><div class="help" id="stat'+id+'">Statistik</div></td>';
			}
			if(subedit)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&edit='+edit+'&subedit='+id+add,false)+'\' onMouseOver="showhelp(\'edit'+id+'\');" onMouseOut="closehelp(\'edit'+id+'\');"><img src="'+core.design+'icon/edit.png"></a><div class="help" id="edit'+id+'">Bearbeiten</div></td>';
			}
			if(subdel)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&edit='+edit+'&subdel='+id+add,true)+'\' onMouseOver="showhelp(\'delete'+id+'\');" onMouseOut="closehelp(\'delete'+id+'\');"><img src="'+core.design+'icon/delete.png"></a><div class="help" id="delete'+id+'">Entfernen</div></td>';
			}
			if(subinfo)
			{
				grc = grc + '<td><a onclick=\''+core.createlink(false,false,'&edit='+edit+'&subinfo='+id+add,false)+'\' onMouseOver="showhelp(\'info'+id+'\');" onMouseOut="closehelp(\'info'+id+'\');"><img src="'+core.design+'icon/info.png"></a><div class="help" id="info'+id+'">Informationen</div></td>';
			}
			grc = grc + "</tr>";
			id = false;
		}
		this.container.innerHTML='<table width="100%">' + this.createheader() + grc + '</table>';
		document.getElementById('mask').style.display='none';
	};
	this.createheader=function()
	{
		var header="";
		for( var x = 0; x < this.origcolumns.length; x++)
		{
			if(this.origcolumns[x]==this.columns[x])
			{
				header = header + '<th align="left"><img src="'+core.design+'icon/down.png" style="cursor:pointer;" onclick="core.listener.event(this,\'click\',\'grid\',\'' + (this.anzahl-1) + '\');"> ' + this.origcolumns[x] + '</th>';
			}
		}
		return header;
	};
	this.clickevent=function(el)
	{
		if(el.parentNode.nodeName=='TH')
		{
			this.openColumnChooser(el);
		}
		if(el.nodeName=='INPUT')
		{
			for(x=0;x<this.columns.length;x++)
			{
				if(el.checked && el.name==this.origcolumns[x]) 
				{
					this.columns[x]=this.origcolumns[x];
				}
				if(!el.checked && el.name==this.origcolumns[x]) 
				{
					this.columns[x]="";
				}
			}
			this.dolayout();
		}
	};
	this.closecolumnchooser=function()
	{
		document.getElementById('mask').style.display='none';
		var el = document.getElementById('columnchooser');
		if(!el)
			return false;
		el.parentNode.removeChild(el);
		return true;
	};
	this.openColumnChooser=function(el)
	{
		var chooser=document.createElement('div');
		chooser.setAttribute('id','columnchooser');
		if( core.isIE )
			var content='<table border="0" width="100%">'+
			'<tr>'+
				'<td class="choosebg" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)" onclick="core.app.grids[' + (this.anzahl-1) + '].sortdesc(this,\''+el.parentNode.innerText.replace(' ','')+'\');core.listener.remove(this.parentNode);">absteigend Sortieren</td>'+
			'</tr>'+
			'<tr>'+
				'<td class="choosebg" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)" onclick="core.app.grids[' + (this.anzahl-1) + '].sortasc(this,\''+el.parentNode.innerText.replace(' ','')+'\');core.listener.remove(this.parentNode);">aufsteigend Sortieren</td>'+
			'</tr>';
		else
			var content='<table border="0" width="100%">'+
			'<tr>'+
				'<td class="choosebg" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)" onclick="core.app.grids[' + (this.anzahl-1) + '].sortdesc(this,\''+el.parentNode.textContent.replace(' ','')+'\');core.listener.remove(this.parentNode);">absteigend Sortieren</td>'+
			'</tr>'+
			'<tr>'+
				'<td class="choosebg" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)" onclick="core.app.grids[' + (this.anzahl-1) + '].sortasc(this,\''+el.parentNode.textContent.replace(' ','')+'\');core.listener.remove(this.parentNode);">aufsteigend Sortieren</td>'+
			'</tr>';
		for(var x = 0; x<this.origcolumns.length;x++)
		{
				content=content+'<tr>'+
					'<td class="choosebg" onmouseover="core.effects.changebg(this)" onmouseout="core.effects.changebg(this)"><input type="checkbox" name="'
						+this.origcolumns[x]
						+'" '
						+(this.origcolumns[x]==this.columns[x]?"checked":"")
						+' onclick="core.listener.event(this,\'click\',\'grid\',\'' + (this.anzahl-1) + '\');core.listener.remove(this.parentNode.parentNode);"> '
						+this.origcolumns[x]+'</td>'+
				'</tr>';
		}
		chooser.innerHTML=content+'</table>';
		chooser.className='absolutebox';
		el.parentNode.appendChild(chooser);
		document.getElementById('mask').style.display='block';
	};
	this.sortdesc=function(el,column)
	{
		inhalte=this.store.load('content');
		newinhalt=new Array();
		sort=new Array();
		for(var x=0;x<inhalte.length-1;x++)
		{
			sort.push(inhalte[x][column]);
		}
		sort.sort().reverse();
		
		for(var x=0;x<=sort.length;x++)
		{
			for(var z=0;z<inhalte.length;z++)
			{
				if(inhalte[z][column]==sort[x])
				{
					newinhalt[x]=inhalte[z];
				}
			}
		}
		
		this.store.save('content',newinhalt);
		this.dolayout();
	};
	this.sortasc=function(el,column)
	{
		inhalte=this.store.load('content');
		newinhalt=new Array();
		sort=new Array();
		for(var x=0;x<inhalte.length-1;x++)
		{
			sort.push(inhalte[x][column]);
		}
		sort.sort();
		
		for(var x=0;x<=sort.length;x++)
		{
			for(var z=0;z<inhalte.length;z++)
			{
				if(inhalte[z][column]==sort[x])
				{
					newinhalt[x]=inhalte[z];
				}
			}
		}
		
		this.store.save('content',newinhalt);
		this.dolayout();
	};
}
