function DoubleTable(id, name)
{
	this.data = new Array ();
	this.id = id;
	this.name = name;
	this.obj = document.getElementById (this.id);
			
	this.ShowRows = function(comboId)
	{
		$value = '';
		//Zde treba setridit polozky this.data podle col1[val]
		for (var key in this.data)
		{  
			if (key == "toJSONString") continue;
			row = this.data[key];
			if (Object.isFunction(row)) continue;
			if (row['fixed'] != 1) {oper = this.PrepareOperation (key);}
				else {oper = '';}
			this.AddRow (oper, row['col1']['val'], row['col2']['val']);			  		                    		                  
		}
		//if (this.data.length == 0)
	}
	
	this.PrepareOperation = function(key)
	{
		oper = '';
		//oper += "<a class='hand' onclick=\"doubleTables['"+this.id+"'].DeleteRow("+key+")\"><img alt='Odstranit' class='dt-ico' src='style/ico/edit16.png' /></a> ";
		oper += "<a class='hand' onclick=\"doubleTables['"+this.id+"'].DeleteRow("+key+")\"><img alt='Odstranit' class='dt-ico' src='style/ico/cut16.png' /></a> ";
		return oper;	
	}
	
	this.ImportRow = function(key1, value1, key2, value2, fixed)
	{
		ar1 = new Array();
		ar1['key'] = key1;
		ar1['val'] = value1;
		
		ar2 = new Array();
		ar2['key'] = key2;
		ar2['val'] = value2;		
		
		ar = new Array ();
		ar['col1'] = ar1;
		ar['col2'] = ar2;
		ar['fixed'] = fixed;
		
		this.data[this.data.length] = ar;	
	}	
	
	this.Export = function ()
	{
		var exp = '';
		for (var key in this.data)
		{
			if (key == "toJSONString") continue;
			if (Object.isFunction(this.data[key])) continue;
			if (exp != '') exp+= '&';			
			exp += this.ExportRow(key);
		}
		return exp;	
	}
		
	this.ExportRow = function (which)
	{
		return (this.name + "[]=" + this.data[which]['col1']['key'] + '|' + this.data[which]['col2']['key'] + '|' + this.data[which]['fixed']);	
	}
	
	this.FindKeys = function(key1, key2)
	{
		for (var key in this.data)
		{  			
			if (key == "toJSONString") continue;
			if (Object.isFunction(this.data[key])) continue;
			if ((this.data[key]['col1']['key'] == key1) && (this.data[key]['col2']['key'] == key2)) return 1;
		}
		return 0; 
	}
	
	this.AddItem = function(key1, value1, key2, value2)
	{
		if (this.FindKeys (key1, key2) == 1) {return 0;}	
		
		ar1 = new Array();
		ar1['key'] = key1;
		ar1['val'] = value1;
		
		ar2 = new Array();
		ar2['key'] = key2;
		ar2['val'] = value2;		
		
		ar = new Array ();
		ar['col1'] = ar1;
		ar['col2'] = ar2;
		ar['fixed'] = false;		
		
		this.data[this.data.length] = ar;	

		//this.ClearRows();
		//this.ShowRows();
		
		this.AddRow (this.PrepareOperation (this.data.length - 1), value1, value2);
		return 1;	
	}
	
	this.AddRow = function(cell, cell1, cell2)
	{
		var tBody = this.obj.getElementsByTagName('tbody')[0];
		var newTR = document.createElement('tr');
		var newTD1 = document.createElement('td');
		var newTD2 = document.createElement('td');
		var newTD3 = document.createElement('td');
		newTD1.innerHTML = cell;
		newTD1.clasName = "ajaxtableleft";
		newTD2.innerHTML = cell1;
		newTD3.innerHTML = cell2;
		newTR.appendChild (newTD1);
		newTR.appendChild (newTD2);
		newTR.appendChild (newTD3);
		tBody.appendChild (newTR);
	}

	this.DeleteRow = function (which)
	{
		this.data.splice (which, 1); 

		this.ClearRows();
		this.ShowRows();						
	}
	
	this.ClearRows = function ()
	{
		var tBody = this.obj.getElementsByTagName('tbody')[0];

		var pocet = tBody.rows.length;
		for (i = 1; i < pocet; i++)		
		{
			tBody.deleteRow (1);
		}		
	}	
	
	this.ShowRows();
} 	
	
