	
	// --- ic_order_item_browser_node ---
	
	function ic_order_item_browser_node(parent, color, no, item_description, unit_price, cut_price, baleni, unit, image_path) {
	
		this.parent = parent;
		
		this.color = color;
		this.no = no;
		this.item_description = item_description;
		this.unit_price = unit_price;
		this.cut_price = cut_price;
		this.baleni = baleni;
		this.unit = unit;
		this.image_path = image_path;
		
		this.container = null;
		
		this.construct();
	}
	
	ic_order_item_browser_node.prototype.construct = function() {
		var self = this;
		this.container = document.createElement("DIV");
		this.container.className = "ic_node";
		
		var inner = "<table cellspacing=\"0\"><tr>";
		inner += "<td class=\"color\">";
		if (this.color != "") inner += "<img src=\"" + this.color + "\"/>";
		inner += "</td>";
		inner += "<td class=\"no\">" + this.no + "</td>";
		inner += "<td class=\"item_description\">" + this.item_description + "</td>";
		//inner += "<td class=\"unit_price\">" + this.unit_price + "</td>";
		//inner += "<td class=\"cut_price\">" + this.cut_price + "</td>";
		inner += "</tr></table>";
		
		this.container.innerHTML = inner;
		
		this.container.onmousedown = function() {
			self.parent.activate(self);
			self.parent.activate_set();
		}
		
		this.container.onmouseup = function() {
			self.parent.select();
		}
		
		this.parent.nodes_container.appendChild(this.container);
	}
	
	ic_order_item_browser_node.prototype.destroy = function() {
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}
	
	ic_order_item_browser_node.prototype.refresh = function() {
		if (this.parent.active == this) {
			this.container.className = "ic_node ic_node_active";
			this.parent.image_load(this);
		
		} else {
			this.container.className = "ic_node";
		}
	}

	// --- ic_order_item_browser ---
	
	function ic_order_item_browser(parent) {
		this.nodes = new Array();
		
		this.parent = parent;
		this.container = null;
		this.content = null;
		this.nodes_container = null;
		this.image_container = null;
		this.clean = null;
		this.image = null;
		this.input = null;
		this.type_time = null;
		
		this.assigned = null;
		this.active = null;
		this.imageref = null;
		this.shadows = null;
		
		this.construct();
	}
	
	ic_order_item_browser.prototype.construct = function() {
		
		var self = this;
		this.container = document.createElement("DIV");
		this.container.className = "ic_browser";
		
		this.content = document.createElement("DIV");
		this.content.className = "ic_browser_content";
		
		this.nodes_container = document.createElement("DIV");
		this.nodes_container.className = "ic_node_container";
		
		this.image_container = document.createElement("DIV");
		this.image_container.className = "ic_node_image";
		this.image_container.style.display = "none";
		
		this.image = document.createElement("IMG");
		this.image_container.appendChild(this.image);
		
		this.clean = document.createElement("DIV");
		this.clean.className = "ic_clean_node";
		
		this.container.appendChild(this.content);
		this.content.appendChild(this.nodes_container);
		this.content.appendChild(this.image_container);
		this.content.appendChild(this.clean);
		
		document.body.appendChild(this.container);
	}
	
	ic_order_item_browser.prototype.shadows_build = function() {
		var mc = this.shadow_container();
		var mx = this.shadow_width();
		var my = this.shadow_height();
		
		var f, areas = new Array();
		// linky
		areas[0] = new Array(0, -15, mx, 0, "top_line");
		areas[1] = new Array(mx, 13, mx + 28, my - 14, "right_line");
		areas[2] = new Array(0, my, mx, my + 12, "bottom_line");
		areas[3] = new Array(-12, 15, 0, my - 11, "left_line");
		
		// rohy
		areas[4] = new Array(-12, -15, 0, 15, "left_top_corner");
		areas[5] = new Array(mx, -15, mx + 28, 14, "right_top_corner");
		areas[6] = new Array(mx, my - 16, mx + 28, my + 12, "right_bottom_corner");
		areas[7] = new Array(-12, my - 11, 0, my + 12, "left_bottom_corner");
		
		// pointer
		areas[8] = new Array(0, -14, 41, 0, "top_pointer");
		
		if (this.shadows == null) {
			this.shadows = new Array();
			
			for (f = 0; f < areas.length; f++) {
				this.shadows[f] = document.createElement("DIV");
				this.shadows[f].style.position = "absolute";
				this.shadows[f].style.left = areas[f][0] + "px";
				this.shadows[f].style.top = areas[f][1] + "px";
				this.shadows[f].style.width = (areas[f][2] - areas[f][0]) + "px";
				this.shadows[f].style.height = (areas[f][3] - areas[f][1]) + "px";
				this.shadows[f].style.background = "url('/gfx/ic/" + areas[f][4] + ".png')";
				
				mc.appendChild(this.shadows[f]);
			}
		} else {
			for (f = 0; f < areas.length; f++) {
				this.shadows[f].style.left = areas[f][0] + "px";
				this.shadows[f].style.top = areas[f][1] + "px";
				this.shadows[f].style.width = (areas[f][2] - areas[f][0]) + "px";
				this.shadows[f].style.height = (areas[f][3] - areas[f][1]) + "px";
			}
		}
	}
	
	ic_order_item_browser.prototype.shadows_destroy = function() {
		if (this.shadows != null) {
			var f;
			for (f = 0; f < this.shadows.length; f++) {
				context.structure_destroy(this.shadows[f]);
				this.shadows[f] = null;
			}
			this.shadows = null;
		}
	}
	
	ic_order_item_browser.prototype.image_unload = function() {
		if (this.imageref != null) {
			this.imageref = null;
			
			if (this.type_time != null) clearTimeout(this.type_time);
			
			this.image_container.style.display = "none";
			this.image.onload = null;
			this.image.src = "";
		}
	}
	
	ic_order_item_browser.prototype.image_load = function(ref) {
		this.image_unload();
	
		if (this.imageref == null) {
			this.imageref = ref;
			
			var self = this;
			this.image.onload = function() {
				self.image_container.style.display = "block";
			}
			
			this.image.src = "/pifc.php?src=" + this.imageref.image_path + "&prev=middle";
		}
	}
	
	ic_order_item_browser.prototype.activate = function(new_node) {
		var bef_node = this.active;
		this.active = new_node;
		
		if (bef_node != null) bef_node.refresh();
		new_node.refresh();
	}
	
	ic_order_item_browser.prototype.activate_set = function() {
		if (this.active != null)
			this.input.value = this.active.no;
	}
	
	ic_order_item_browser.prototype.typed = function(trgEvent) {
		if (trgEvent == null) this.typed_query();
		else {
			switch (trgEvent.keyCode) {
				case 27 :
					this.close();
					break;
					
				case 38 : // nahoru
					if (this.active != null) {
						var new_node = this.get_node(this.active, -1);
						
						if (new_node != null) this.activate(new_node);
						else this.active.refresh();
					}
					break;
				
				case 40 : // dolu
					if (this.active != null) {
						var new_node = this.get_node(this.active, 1);
						
						if (new_node != null) this.activate(new_node);
						else this.active.refresh();
					}
					break;
					
				case 9 :
				case 13 : // select
					if (this.active != null) {
						this.activate_set();
						this.select();
					}
					break;
					
				default :
					if (this.type_time != null) clearTimeout(this.type_time);
					this.type_time = setTimeout("oi_col.browser.typed_done()", 250);
					break;
			}
		}
	}
	
	ic_order_item_browser.prototype.typed_done = function() {
		this.type_time = null;
		this.typed(null);
	}
	
	ic_order_item_browser.prototype.typed_query = function() {
		query_struct = new structure_class();
		query_struct.map("head/major", "typed");
		query_struct.map("head/pattern", this.input.value);
		
		var self = this;
		context.request("typed", null, function(data, request) {
			if (self != null && self.assigned != null) self.evt_typed(data, request);
		}, query_struct);
	}
	
	ic_order_item_browser.prototype.evt_typed = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
		
			var head = res[0];
			var body = res[1];
			
			// nacteni
			var f, elm = body.getElementsByTagName("node");
			this.flush();
			for (f = 0; f < elm.length; f++) {
				this.add(
					context.sub_element_value(elm[f], "pattern_image"),
					context.sub_element_value(elm[f], "no"),
					//context.sub_element_value(elm[f], "web_group_name") + " - " + context.sub_element_value(elm[f], "item_description"),
					context.sub_element_value(elm[f], "item_description"),
					context.sub_element_value(elm[f], "unit_price"),
					context.sub_element_value(elm[f], "cut_price"),
					context.sub_element_value(elm[f], "baleni"),
					context.sub_element_value(elm[f], "unit"),
					context.sub_element_value(elm[f], "image_path")
				);
			}
			
			// nalez active itemu
			if (this.nodes.length > 0) {
				var founded = false;
				f = 0;
				
				while (!founded && f < this.nodes.length) {
					if (this.nodes[f].no == this.input.value) founded = true;
					else f++;
				}
				
				this.activate(founded ? this.nodes[f] : this.nodes[0]);
				
			} else {
				this.nodes_container.innerHTML = "<span>Nebyly nalezeny žádné produkty.</span>";
			}
			
			this.shadows_build();
		}
	}
	
	ic_order_item_browser.prototype.select = function() {
		this.assigned.code.value = this.input.value;
		this.assigned.baleni = this.active.baleni;
		this.assigned.unit.value = this.active.unit;
		this.assigned.unit_text.innerHTML = this.active.unit;
		this.assigned.determine_state();
		this.assigned.visible_state();
		this.assigned.values_recount_whole();
		this.assigned.code.focus();
		this.close();
	}
	
	ic_order_item_browser.prototype.get_node = function(ref, inc) {
		var founded = false;
		var pos = 0;
		
		while (!founded && pos < this.nodes.length)
			if (this.nodes[pos] == ref) founded = true;
			else pos++;
			
		if (founded) {
			pos += inc;
			if (pos >= 0 && pos < this.nodes.length) return this.nodes[pos];
		}
		
		return null;
	}
	
	ic_order_item_browser.prototype.open = function(item) {
		this.close();
	
		if (this.assigned == null) {
		
			var self = this;
			this.assigned = item;
			
			this.input = item.code;
			this.input.onkeydown = function(trgEvent) {
				e = trgEvent == null ? event : trgEvent;
				
				switch (e.keyCode) {
					case 13 :
					case 9 :
						var ba = self.assigned;
						
						if (e.keyCode == 13) cancelEvent(e, true);
						self.typed(e);
						if (ba != null) ba.evt_keydown(e, this, true);
						break;
				}
			}
			this.input.onkeyup = function(trgEvent) {
				self.typed(trgEvent == null ? event : trgEvent);
			}
			
			this.container.style.left = context.get_elementX(item.code) + "px";
			this.container.style.top = (context.get_elementY(item.code) + context.get_elementHeight(item.code) + 5) + "px";
			this.container.style.display = "block";
			
			this.shadows_build();
			this.input.focus();
			
			this.typed(null);
		}
	}
	
	ic_order_item_browser.prototype.close = function() {
		if (this.assigned != null) {
			this.input.onkeyup = null;
			this.flush();
			this.assigned = null;
			
			this.container.style.display = "none";
			
			this.shadows_destroy();
		}
	}
	
	ic_order_item_browser.prototype.add = function(color, no, item_description, unit_price, cut_price, baleni, unit, image_path) {
		var ref = new ic_order_item_browser_node(this, color, no, item_description, unit_price, cut_price, baleni, unit, image_path);
		this.nodes[this.nodes.length] = ref;
	}
	
	ic_order_item_browser.prototype.flush = function() {
		this.active = null;
		this.image_unload();
		
		var f;
		for (f = this.nodes.length - 1; f >= 0; f--) {
			this.nodes[f].destroy();
			this.nodes[f] = null;
		}
		
		this.nodes_container.innerHTML = "";
		this.nodes = new Array();
	}
	
	ic_order_item_browser.prototype.shadow_container = function() { return this.content; }
	
	ic_order_item_browser.prototype.shadow_width = function() { return context.get_elementWidth(this.content) - 1; }
	ic_order_item_browser.prototype.shadow_height = function() { return context.get_elementHeight(this.content) - 1; }

	// --- ic_order_item_class ---
	
	function ic_order_item_class(parent, container, uid, code, size_x, size_sep, size_y, size, num, unit, note, remove, baleni, flags) {
	
		this.parent = parent;
	
		this.container = container;
		this.uid = uid;
		
		this.code = code;
		this.size_x = size_x;
		this.size_sep = size_sep;
		this.size_y = size_y;
		this.size = size;
		this.num = num;
		this.unit = unit;
		this.unit_text = null;
		this.note = note;
		this.remove = remove;
		this.baleni = baleni;
		this.flags = flags;
		
		this.state = "default";
		this.index = null;
		
	}
	
	ic_order_item_class.prototype.construct = function() {
		var self = this;
		
		var loop = this.unit.parentNode.childNodes[0];
		while (this.unit_text == null && loop != null) {
			if (loop.nodeType == 1 && loop.nodeName.toUpperCase() == "SPAN") this.unit_text = loop;
			else loop = loop.nextSibling;
		}
		
		this.code.onfocus = function() {
			self.parent.browser.open(self);
		}
		this.code.onblur = function() {
			self.parent.browser.close();
		}
		this.code.onchange = function() {
			self.parent.save();
		}
		addEvent(this.code, "keydown", function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); });
		
		this.determine_state();
		this.visible_state();
		this.values_recount_whole();
		
		this.size_x.onchange = function() {
			self.determine_state("cut");
			self.visible_state();
			self.values_recount("cut_size_x");
			self.parent.save();
		}
		this.size_x.onkeydown = function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); }
		this.size_y.onchange = function() {
			self.determine_state("cut");
			self.visible_state();
			self.values_recount("cut_size_y");
			self.parent.save();
		}
		this.size_y.onkeydown = function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); }
		this.size.onchange = function() {
			self.determine_state("cut");
			self.visible_state();
			self.values_recount("cut_size");
			self.parent.save();
		}
		this.size.onkeydown = function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); }
		
		this.num.onchange = function() {
			self.determine_state("free");
			self.visible_state();
			self.values_recount("free_num");
			self.parent.save();
		}
		this.num.onkeydown = function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); }
		/*
		this.unit.onchange = function() {
			self.determine_state("free");
			self.visible_state();
			self.values_recount("free_unit");
		}
		*/
		this.note.onkeydown = function(trgEvent) { return self.evt_keydown(trgEvent == null ? event : trgEvent, this); }
		this.note.onchange = function() {
			self.parent.save();
		}
		
		this.remove.onclick = function() {
			self.parent.remove_line(self.uid);
		}
	}
	
	ic_order_item_class.prototype.evt_keydown = function(trgEvent, ref, forced) {
		this.parent.wholesale_term_touch();
			
		if (trgEvent.keyCode == 13) {
			var ob = new Array();
			ob[0] = this.code;
			ob[1] = this.size_x;
			ob[2] = this.size_y;
			ob[3] = this.size;
			ob[4] = this.num;
			ob[5] = this.note;
			
			var founded = false;
			var pos = 0;
			
			while (!founded && pos < ob.length)
				if (ob[pos] === ref) founded = true;
				else pos++;
			
			if (founded && (pos != 0 || forced)) {
				cancelEvent(trgEvent, true);
				
				pos++;
				while (pos < ob.length && ob[pos].disabled) pos++;
				
				if (pos == ob.length) {
					if (this.index + 1 < this.parent.items.length) {
						this.parent.items[this.index + 1].code.focus();
					}
				} else {
					ob[pos].focus();
				}
			}
			
		}
	}
	
	ic_order_item_class.prototype.destroy = function() {
		context.structure_destroy(this.container);
		context.object_destroy(this);
	}
	
	ic_order_item_class.prototype.save_compose = function(parent) {
		if (this.is_free() || this.is_cut()) {
			var node = parent.add_child("node");
			
			node.add_child("code", this.code.value);
			node.add_child("note", this.note.value);
			
			if (this.is_free()) {
				node.add_child("type", "free");
				node.add_child("num", this.num.value);
				
			} else {
				node.add_child("type", "cut");
				node.add_child("size_x", this.size_x.value);
				node.add_child("size_y", this.size_y.value);
				node.add_child("size", this.size.value);
			}
			
			return true;
		}
		return false;
	}
	
	ic_order_item_class.prototype.dis = function(ref) {
		ref.parentNode.style.backgroundColor = "#D6D6D6";
		ref.style.backgroundColor = "#D6D6D6";
		ref.style.color = "#4C4C4C";
		ref.style.fontWeight = "bold";
		ref.disabled = true;
	}
	
	ic_order_item_class.prototype.enb = function(ref) {
		ref.parentNode.style.backgroundColor = "";
		ref.style.backgroundColor = "";
		ref.style.color = "black";
		ref.style.fontWeight = "normal";
		ref.disabled = false;
	}
	
	ic_order_item_class.prototype.hig = function(ref) {
		ref.parentNode.style.backgroundColor = "#dfeefc";
		ref.style.backgroundColor = "#dfeefc";
		ref.style.fontWeight = "bold";
	}
	
	ic_order_item_class.prototype.uhi = function(ref) {
		ref.parentNode.style.backgroundColor = "";
		ref.style.backgroundColor = "";
		ref.style.fontWeight = "normal";
	}
	
	ic_order_item_class.prototype.is_cut = function() { return this.size_x.value != "" || this.size_y.value != "" || this.size.value != ""; }
	//ic_order_item_class.prototype.is_free = function() { return this.num.value != "" || this.unit.options[this.unit.selectedIndex].value != ""; }
	ic_order_item_class.prototype.is_free = function() { return this.num.value != ""; }
	ic_order_item_class.prototype.determine_state = function(pre_state) {
		this.state = "default";
		
		if (this.baleni == 0) {
			if (this.is_free()) this.state = "free";
			else if (this.is_cut()) this.state = "cut";
			
		} else {
			switch (pre_state) {
				case "cut" :
					if (this.is_cut()) this.state = "cut";
					else if (this.is_free()) this.state = "free";
					break;
					
				case "free" :
				default :
					if (this.is_free()) this.state = "free";
					else if (this.is_cut()) this.state = "cut";
					break;
			}
		}
	}
	
	ic_order_item_class.prototype.visible_state = function() {
		switch (this.state) {
			case "free" :
				this.dis(this.size_x);
				this.dis(this.size_y);
				this.dis(this.size);
				
				this.size_x.value = "";
				this.size_y.value = "";
				this.size.value = "";
				
				this.enb(this.num);
				this.enb(this.unit);
				break;
				
			case "cut" :
				this.dis(this.num);
				this.dis(this.unit);
				
				this.num.value = "";
				//this.unit.selectedIndex = 0;
				
				this.enb(this.size_x);
				this.enb(this.size_y);
				this.enb(this.size);
				break;
				
			default :
				this.enb(this.num);
				this.enb(this.unit);
				this.enb(this.size_x);
				this.enb(this.size_y);
				this.enb(this.size);
				break;
		}
	}
		
	ic_order_item_class.prototype.get_num = function(input) {
		var res = parseFloat(input);
		return isNaN(res) ? 0 : res;
	}
	
	ic_order_item_class.prototype.set_num = function(input) {
		var string = "" + input;
		return string.replace(".", ",");
	}
	
	ic_order_item_class.prototype.values_recount_whole = function() {
		switch (this.state) {
			case "cut" :
				this.values_recount("cut_size_x");
				this.values_recount("cut_size_y");
				this.values_recount("cut_size");
				break;
				
			case "free" :
				this.values_recount("free_unit");
				break;
		}
	}
	
	ic_order_item_class.prototype.values_recount = function(sub_state) {
		var baleni = this.get_num(this.baleni);
		var baleni_max = 3;
	
		switch (this.state) {
			case "cut" :
				switch (sub_state) {
					case "cut_size_x" :
						if (this.size_x.value != "") {
							var val = this.get_num(this.size_x.value);
							if (val > baleni * 100) val = baleni * 100;
							if (val > baleni_max * 100) val = baleni_max * 100;
							this.size_x.value = this.set_num(val);
							
							this.values_recount("cut_size");
						}
						break;
						
					case "cut_size_y" :
						if (this.size_y.value != "") {
							var val = this.get_num(this.size_y.value);
							if (val > baleni * 100) val = baleni * 100;
							if (val > baleni_max * 100) val = baleni_max * 100;
							this.size_y.value = this.set_num(val);
							
							this.values_recount("cut_size");
						}
						break;
						
					case "cut_size" :
						if (this.size.value != "") {
							var val = Math.round(this.get_num(this.size.value));
							if (val < 1) val = 1;
							else if (val >= 100) val = 99;
							this.size.value = this.set_num(val);
						}
						break;
				}
				
				if (this.size_x.value != "" && this.size_x.value != 0 && this.size_y.value != "" && this.size_y.value != 0 && this.size.value != "") {
					this.hig(this.size_x);
					this.hig(this.size_y);
					this.hig(this.size)
				} else {
					this.uhi(this.size_x);
					this.uhi(this.size_y);
					this.uhi(this.size);
				}
				break;
			
			case "free" :
				switch (sub_state) {
					case "free_num" :
						//switch (this.unit.options[this.unit.selectedIndex].value) {
						switch (this.unit.value.toLowerCase()) {
							case "ks" :
								var val = Math.round(this.get_num(this.num.value));
								if (val < 1) val = 1;
								else if (val >= 100) val = 99;
								this.num.value = this.set_num(val);
								break;
								
							case "m" :
								var val = this.get_num(this.num.value);
								if (val < 1) val = 1;
								var rest = val % baleni;
								if (rest != 0) val += -rest + baleni;
								
								this.num.value = this.set_num(val);
								break;
						}
						break;
						
					case "free_unit" :
						this.values_recount("free_num");
						break;
				}
				
				//if (this.num.value != "" && this.unit.selectedIndex != 0) {
				if (this.num.value != "") {
					this.hig(this.num);
					this.hig(this.unit);
				} else {
					this.uhi(this.num);
					this.uhi(this.unit);
				}
				break;
		}
	}

	// --- ic_order_item_collector_class ---
	
	function ic_order_item_collector_class(uids) {
		
		this.uids = uids;
		this.items = new Array();
		this.browser = null;
		
		this.order_table = null;
		this.order_table_button = null;
		this.wholesale_term = null;
		
		this.construct(uids);
		
	}
	
	ic_order_item_collector_class.prototype.construct = function() {
		var f, root;
		
		this.browser = new ic_order_item_browser(parent);
		
		for (f = 0; f < this.uids.length; f++) {
			if ((root = document.getElementById("tr" + this.uids[f] + "no")) != null)
				this.build_one(this.uids[f], root);
		}
		
		for (f = 0; f < this.items.length; f++)
			this.items[f].construct();
		
		this.order_table = document.getElementById("order_table");
		this.order_table_button = document.getElementById("order_table_button");
		this.wholesale_term = document.getElementById("wholesale_term");
		
		if (this.order_table_button != null) {
			var self = this;
			
			var nButt = context.createElement("INPUT");
			nButt.type = "button";
			nButt.className = this.order_table_button.className;
			nButt.value = this.order_table_button.value;
			
			this.order_table_button.parentNode.insertBefore(nButt, this.order_table_button);
			context.structure_destroy(this.order_table_button);
			this.order_table_button = nButt;
			
			this.order_table_button.onclick = function() {
				self.add_line();
			}
		}
		if (this.wholesale_term != null) {
			this.wholesale_term.style.visibility = "hidden";
		}
	}
	
	ic_order_item_collector_class.prototype.wholesale_term_touch = function() {
		if (this.wholesale_term != null && this.wholesale_term.style.visibility != "visible") {
			this.wholesale_term.style.visibility = "visible";
			this.wholesale_term.style.position = "relative";
			this.wholesale_term.style.top = (context.get_elementY(this.wholesale_term) * -1 + 215) + "px";
		}
	}
	
	ic_order_item_collector_class.prototype.low_element = function(node, limit) {
		var pos = 0;
		var cnt = 0;
		var element = null;
		
		while (element == null && pos < node.childNodes.length) {
			if (node.childNodes[pos].nodeType == 1) {
				cnt++;
				if (limit == null || cnt == limit) element = node.childNodes[pos];
			}
			
			pos++;
		}
		
		return element;
	}
	
	ic_order_item_collector_class.prototype.save = function() {
		query_struct = new structure_class();
		query_struct.map("head/major", "basket_save");
		
		var f, body, any = false;
		if ((body = query_struct.map("body")) != null) {
			for (f = 0; f < this.items.length; f++)
				if (this.items[f].save_compose(body)) any = true;
			
			if (any) {
				var self = this;
				context.request("basket_save", null, function(data, request) {
					if (self != null) self.evt_save(data, request);
				}, query_struct);
			}
		}
	}
	
	ic_order_item_collector_class.prototype.evt_save = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
		}
	}
	
	ic_order_item_collector_class.prototype.build_one = function(uid, root) {
		var f, current, stack = new Array();
		var tds = new Array();
		
		stack[0] = root;
		
		while (stack.length > 0) {
			current = stack.pop();
			
			if (current.tagName.toUpperCase() == "TD")
				tds[tds.length] = current;
			
			if (current.childNodes.length > 0) {
				for (f = current.childNodes.length - 1; f >= 0; f--) {
					if (current.childNodes[f].nodeType == 1)
						stack[stack.length] = current.childNodes[f];
				}
			}
		}
		
		if (tds.length == 9) {
			var eee = this.low_element(tds[0]);
		
			var ref = new ic_order_item_class(
				this,
				root, 
				uid,
				this.low_element(tds[0]), // code
				this.low_element(tds[1]), // size_x
				tds[2], // size_sep
				this.low_element(tds[3]), // size_y
				this.low_element(tds[4]), // size
				this.low_element(tds[5]), // num
				this.low_element(tds[6]), // unit
				this.low_element(tds[7]), // note
				
				this.low_element(tds[8]), // remove
				this.low_element(tds[8], 2).value, // baleni
				this.low_element(tds[8], 3).value // flags
			);
			
			ref.index = this.items.length;
			this.items[this.items.length] = ref;
			return ref;
		}
		
		return null;
	}
	
	ic_order_item_collector_class.prototype.remove_line = function(uid) {
		query_struct = new structure_class();
		query_struct.map("head/major", "basket_rem");
		query_struct.map("head/flag", 0); // ramovaci_materialy
		query_struct.map("head/uid", uid);
		
		var self = this;
		context.request("basket_add", null, function(data, request) {
			if (self != null) self.evt_remove_line(data, request);
		}, query_struct);
	}
	
	ic_order_item_collector_class.prototype.add_line = function() {
		query_struct = new structure_class();
		query_struct.map("head/major", "basket_add");
		query_struct.map("head/flag", 0); // ramovaci_materialy
		
		var self = this;
		context.request("basket_add", null, function(data, request) {
			if (self != null) self.evt_add_line(data, request);
		}, query_struct);
	}
	
	ic_order_item_collector_class.prototype.evt_remove_line = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
			var uid, elm = body.getElementsByTagName("basket_remove_uid");
			if (elm.length > 0) {
				uid = context.element_value(elm[0]);
				
				var founded = false;
				var pos = 0;
				
				while (!founded && pos < this.items.length)
					if (this.items[pos].uid == uid) founded = true;
					else pos++;
					
				if (founded) {
					var to_delete = this.items[pos];
					
					for (pos; pos < this.items.length - 1; pos++)
						this.items[pos] = this.items[pos + 1];
					this.items.pop();
					
					to_delete.destroy();
				}
			}
			
			this.save();
		}
	}
	
	ic_order_item_collector_class.prototype.evt_add_line = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
		
			var head = res[0];
			var body = res[1];
			
			var uid, elm = body.getElementsByTagName("item");
			if (elm.length > 0) {
			
				var tbody = null;
				var pos = 0;
				
				while (tbody == null && pos < this.order_table.childNodes.length)
					if (this.order_table.childNodes[pos].nodeType == 1 && this.order_table.childNodes[pos].tagName.toUpperCase() == "TBODY") tbody = this.order_table.childNodes[pos];
					else pos++;
				
				if (tbody != null) {
					var o, ntd, ntr = document.createElement("TR");
					ntr.id = "tr" + context.sub_element_value(elm[0], "uid") + "no";
					
					ntd = document.createElement("TD");
					ntd.className = "code leaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_no") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "sizex pleaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_size_x") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "sizesep pleaf";
					ntd.innerHTML = "x";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "sizey pleaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_size_y") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "size leaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_size") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "num pleaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_num") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "unit leaf";
					
					o  = "<input type=\"hidden\" name=\"" + context.sub_element_value(elm[0], "name_unit") + "\" value=\"\"/>";
					o += "<span>&nbsp;</span>";
					
					ntd.innerHTML = o;
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "note pleaf";
					ntd.innerHTML = "<input type=\"text\" name=\"" + context.sub_element_value(elm[0], "name_note") + "\" value=\"\"/>";
					ntr.appendChild(ntd);
					
					ntd = document.createElement("TD");
					ntd.className = "remove";
					
					o  = "<input type=\"button\" onclick=\"document.location.href = '/cs/objednavka/p/basket_remove/" + context.sub_element_value(elm[0], "uid") + "'\"/>";
					o += "<input type=\"hidden\" value=\"\"/>";
					o += "<input type=\"hidden\" value=\"\"/>";
					
					ntd.innerHTML = o;
					ntr.appendChild(ntd);
					
					tbody.appendChild(ntr);
					var ref = this.build_one(context.sub_element_value(elm[0], "uid"), ntr);
					if (ref != null) ref.construct();
				}
			}
			
		}
	}
	
