	
	// --- ic_producer_item ---
		
	function ic_producer_item(parent, container) {
		this.parent = parent;
		this.container = container;
		
		this.fields = new Array();
		this.options = new Array();
	}
	
	ic_producer_item.prototype.construct = function() {
		var self = this, f;
		
		if (this.container == null && this.parent.tbody != null) {
			// vytvoreni radku a bunek
			this.container = document.createElement("TR");
			
			var tmp = null;
			for (f = 0; f < this.fields.length; f++) {
				tmp = document.createElement("TD");
				tmp.className = this.parent.items[0].fields[f].parentNode.className;
				tmp.appendChild(this.fields[f]);
				
				this.container.appendChild(tmp);
			}
			
			this.parent.tbody.appendChild(this.container);
		}
		
		for (f = 0; f < this.fields.length; f++) {
			if (f == 0) {
				this.fields[f].onchange = function() { 
					self.set_by_label(1, this.options[this.selectedIndex].value);
					self.evt_change(this); 
				}
			} else {
				this.fields[f].onchange = function() { self.evt_change(this); }
			}
			this.options[f] = new Array();
		}
		
		this.set_by_label(1, this.fields[0].selectedIndex == null ? "" : this.fields[0].options[this.fields[0].selectedIndex].value, true);
	}
	
	ic_producer_item.prototype.get_value = function() {
		if (this.fields[0].selectedIndex != false || this.fields[1].selectedIndex != false || (this.fields.length > 2 && this.fields[2].value != "")) {
			var f, out = new Array();
			for (f = 0; f < this.fields.length; f++) {
				if (f <= 1) out[out.length] = this.fields[f].options[this.fields[f].selectedIndex].value;
				else out[out.length] = this.fields[f].value;
			}
			return out;
		}
		
		return false;
	}
	
	ic_producer_item.prototype.set_by_label = function(index, key, no_reset) {
		var f, d = this.fields[index], len = this.options[index].length;
		var rem = new Array();
		
		for (f = 0; f < d.options.length; f++) {
			if (d.options[f].value != "" && d.options[f].label != key) {
				rem[rem.length] = f;
				this.options[index][this.options[index].length] = d.options[f];
			}
		}
		
		for (f = rem.length - 1; f >= 0; f--) d.remove(rem[f]);
		rem = new Array();
		
		for (f = 0; f < len; f++) {
			if (this.options[index][f].label == key) {
				d.options.add(this.options[index][f]);
				rem[rem.length] = f;
			}
		}
		
		for (f = rem.length - 1; f >= 0; f--) {
			var sf, pos = rem[f];
			for (sf = pos; sf < this.options[index].length - 1; sf++)
				this.options[index][sf] = this.options[index][sf + 1];
			this.options[index].pop();
		}
		
		if (!no_reset) d.selectedIndex = 0;
	}
	
	ic_producer_item.prototype.destroy = function() {
		var f;
		for (f = 0; f < this.fields; f++) {
			context.structure_destroy(this.fields[f]);
			this.fields[f] = null;
		}
		
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}	
	
	ic_producer_item.prototype.evt_change = function(ref) {
		var empty = true;
		var pos = 0;
		
		while (empty && pos < this.fields.length) {
			switch (this.fields[pos].tagName.toUpperCase()) {
				case "SELECT" :
					if (this.fields[pos].selectedIndex != null && this.fields[pos].options[this.fields[pos].selectedIndex].value != "") empty = false;
					else pos++;
					break;
					
				case "INPUT" :
					if (this.fields[pos].value != "") empty = false;
					else pos++;
					break;
			}
		}
		
		this.parent.evt_change(ref);
		if (empty) this.parent.rem_item(this);
	}
	
	ic_producer_item.prototype.copy = function(ref) {
		var f, sf, d, n, op;
		for (f = 0; f < ref.fields.length; f++) {
			d = ref.fields[f];
			
			if (d.tagName.toUpperCase() == "SELECT") {
				n = document.createElement("SELECT");
				n.name = d.name;
				
				for (sf = 0; sf < d.options.length; sf++) {
					op = document.createElement("OPTION");
					op.value = d.options[sf].value;
					op.text = d.options[sf].text;
					op.label = d.options[sf].label;
					
					n.options.add(op);
				}
				
				for (sf = 0; sf < ref.options[f].length; sf++) {
					op = document.createElement("OPTION");
					op.value = ref.options[f][sf].value;
					op.text = ref.options[f][sf].text;
					op.label = ref.options[f][sf].label;
					
					n.options.add(op);
				}
				
				this.fields[this.fields.length] = n;
			
			} else {
				n = document.createElement("INPUT");
				n.type = d.type;
				n.name = d.name;
				
				this.fields[this.fields.length] = n;
			}
		}
	}
	
	ic_producer_item.prototype.get_values_info = function() {
		var f, out = "";
		for (f = 0; f < this.fields[f].length; f++) {
			switch (f) {
				case 0 :
				case 1 :
					if (this.fields[f].selectedIndex != 0)
						out += (out == "" ? "" : ", ") + this.fields[f].options[this.fields[f].selectedIndex].text;
					break;
				
				default :
					out += (out == "" ? "" : ", ") + this.fields[f].value;
					break;
			}
		}
		
		return out;
	}
	
	// --- ic_producer_class ---
	
	function ic_producer(base) {
	
		this.inheritFrom = shadow_block_class;
		this.inheritFrom();
	
		this.reg_ident = null;
		this.base = base;
		this.tbody = null;
		this.change_event = null;
		this.items = new Array();
		this.add_href = null;
		
		this.evt_item_touch = null;
		
		this.construct();
	}
	
	clone_add(ic_producer.prototype, shadow_block_class.prototype); // inherit
	
	ic_producer.prototype.construct = function() {
		var self = this;
		this.reg_ident = context.ic_collector.register(this);
		
		if (this.base != null) {
			var last_item = null, f, current, stack = new Array();
			stack[0] = this.base;
			
			while (stack.length > 0) {
				current = stack.pop();
				
				switch (current.tagName.toUpperCase()) {
					case "TBODY" :
						this.tbody = current;
						break;
				
					case "TR" :
						if (last_item != null && last_item.fields.length > 0) {
							this.items[this.items.length] = last_item;
							last_item.construct();
						}
						last_item = new ic_producer_item(this, current);
						break;
						
					case "SELECT" :
					case "INPUT" :
						if (current.tagName.toUpperCase() == "SELECT" || current.type == "text") {
							if (last_item != null) {
								last_item.fields[last_item.fields.length] = current;
							}
						}
						break;
				}
				
				for (f = current.childNodes.length - 1; f >= 0; f--)
					if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
			}
			
			if (last_item != null && last_item.fields.length > 0) {
				this.items[this.items.length] = last_item;
				last_item.construct();
			}
			
			this.add_href = document.createElement("A");
			this.add_href.href = "javascript:blank()";
			this.add_href.className = "add";
			this.add_href.innerHTML = "Přidat další";
			this.add_href.onclick = function() { self.add_item(); }
			
			if (this.tbody.parentNode.nextSibling == null) this.base.parentNode.appendChild(this.add_href);
			else this.base.parentNode.insertBefore(this.add_href, this.tbody.parentNode.nextSibling);
		}
	}
	
	ic_producer.prototype.shadow_container = function() { return this.base.parentNode; }
	
	ic_producer.prototype.shadow_width = function() { return context.get_elementWidth(this.base.parentNode) - 1; }
	ic_producer.prototype.shadow_height = function() { return context.get_elementHeight(this.base.parentNode) - 1; }
	
	ic_producer.prototype.clear_items = function() {
		if (this.items.length > 0) {
			var f;
			for (f = this.items.length - 1; f >= 0; f--) {
				this.items[f].destroy();
				this.items[f] = null;
			}
			
			this.items = new Array();
			
			if (this.evt_item_touch != null)
				this.evt_item_touch(this);
				
			this.evt_change();
		}
	}
	
	ic_producer.prototype.add_item = function() {
		var item = new ic_producer_item(this, null);
		item.copy(this.items[0]);
		this.items[this.items.length] = item;
		item.construct();
		
		if (this.evt_item_touch != null)
			this.evt_item_touch(this);
	}
	
	ic_producer.prototype.rem_item = function(ref) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.items.length)
			if (this.items[pos] === ref) founded = true;
			else pos++;
			
		if (founded) {
			if (this.items.length > 1) {
				this.items[pos].destroy();
				
				var f;
				for (f = pos; f < this.items.length - 1; f++)
					this.items[f] = this.items[f + 1];
				this.items.pop();
				
				if (this.evt_item_touch != null)
					this.evt_item_touch(this);
			}
		}
	}
	
	ic_producer.prototype.cancel = function() {
		
	}
	
	ic_producer.prototype.evt_change = function(ref) {
		if (this.change_event != null)
			this.change_event(this, ref);
	}
	
	ic_producer.prototype.get_values = function() {
		var f, tmp, res = new Array();
		for (f = 0; f < this.items.length; f++)
			if ((tmp = this.items[f].get_value()) != false) res[res.length] = tmp;
		return res;
	}
	
	ic_producer.prototype.get_values_info = function() {
		var f, out = "", tmp;
		for (f = 0; f < this.items.length; f++) {
			tmp = this.items[f].get_values_info();
			if (tmp != "") out += (out == "" ? "" : ", ") + tmp;
		}
		return out;
	}
	
