//<![CDATA[

/*
		KOMPONENTA TAccessories
		
		- autor				: Tomáš Poles
		- created			: 2004-10-05
		- last update		: 2007-06-19
		- version			: 1.0.7
		- platform			: client browser (IE, Mozilla)
		
		1.0.7
		* opraveno počítání množství v readonly režimu pro povinnou a speciální kategorii

		1.0.6
		+ podpora enabled/disabled položky

		1.0.5
		* opraveno chápání about:blank pro https tzv. ošetření https pro prázdný frame

		1.0.4
		* opraveno zobrazování poznámky

		1.0.3
		* opraveno zjištění zadávacího módu pro množství (chybné porovnání kategorie)

		1.0.2
		* úprava zpracování množství dle kategorií
		+ varovná hláška o nekorektním množství

		1.0.1
		+ přidány zvlášť styly pro buňky s hodnotama při typu zobrazení "combo"
		
*/

// - globální seznam objektů
document.accessories = new Array();

// - konstanty
// - ... typ větve
var ACC_NODE_CATEGORY = 1;
var ACC_NODE_ITEM = 2;

// - ... typ kategorie
var ACC_CATG_REQUIRED = 1;				//povinný výběr
var ACC_CATG_OPTIONAL_1 = 2;			//volitelný výběr - 1 možnost
var ACC_CATG_OPTIONAL_MORE = 3;			//volitelný výběr - více možností
var ACC_CATG_SPECIAL = 4;				//zvláštní provedení
var ACC_CATG_NOTE = 5;					//poznámka

//- ... způsob zobrazení kategorie
var ACC_SHOW_AS_TREE = 1;
var ACC_SHOW_AS_COMBO = 2;


//---------------------------------------------------------------------------------------------------
//  HLAVNÍ OBJEKT: TAccessory
//---------------------------------------------------------------------------------------------------
function TAccessory(AElement)
{
	//properties
	//... public
	this.index = -1;
	this.name = null;
	this.element = AElement;
	this.namespace = "";
	this.elements = new Array();
	this.script = null;
	this.currency = "";
	this.useHellers = true;
	this.useLinks = true;
	//... ... zobrazení
	this.showInTree = null;
	this.showInCombo = null;
	this.classes = new Array();
	//... ... zprávy/texty
	this.messages = new Array();
	//... ... root
	this.root = null;
	this.defaultAmount = null;
	this.userAmount = null;
	this.priceWithoutVAT = null;
	this.priceWithVAT = null;
	this.vatPercent = null;
	this.userData = null;
	//... ... items
	this.nodes = new Array();
	//... private
	this._front = new Array();
	this._loading = false;
	this._main_name = "";
	this._root_name = "";
	this._frame_name = "";
	this._node_prefix = "";

	//inicializace
	this.init = function()
	{
		//... properties
		this.index = document.accessories.length;
		this.namespace = IsNull(this.element.scopeName, "");
		this.name = this.element.getAttribute("name");
		this.script = this.element.getAttribute("script");
		this.currency = IsNull(this.element.getAttribute("currency"), "");
		this.useHellers = !IsValueInArray(this.element.getAttribute("useHellers") + "", ["false", "0", "no"]);
		this.useLinks = !IsValueInArray(this.element.getAttribute("useLinks") + "", ["false", "0", "no"]);
		this.element.removeAttribute("name");
		//... ... zobrazení
		this.showInTree = IsNull(this.element.getAttribute("showInTree"), "amount|product|priceWithoutVat|vatPercent|priceWithVat|image");
		this.showInCombo = IsNull(this.element.getAttribute("showInCombo"), "image|product|priceWithoutVat|vatPercent|priceWithVat");
		//... ... ... CSS třídy (tree příp. combo)
		this.classes["main"] = IsNull(this.element.getAttribute("classMain"), "");
		this.classes["node"] = IsNull(this.element.getAttribute("classNode"), "");
		this.classes["item"] = IsNull(this.element.getAttribute("classItem"), "");
		this.classes["itemDisabled"] = IsNull(this.element.getAttribute("classItemDisabled"), "");
		this.classes["categoryMain"] = IsNull(this.element.getAttribute("classCategoryMain"), "");
		this.classes["categoryHeader"] = IsNull(this.element.getAttribute("classCategoryHeader"), "");
		this.classes["categoryCombo"] = IsNull(this.element.getAttribute("classCategoryCombo"), "");
		this.classes["categoryNote"] = IsNull(this.element.getAttribute("classCategoryNote"), "");
		//... ... ... ... hlavička (td)
		this.classes["columnCheck"] = IsNull(this.element.getAttribute("classColumnCheck"), "");
		this.classes["columnAmount"] = IsNull(this.element.getAttribute("classColumnAmount"), "");
		this.classes["columnProduct"] = IsNull(this.element.getAttribute("classColumnProduct"), "");
		this.classes["columnPriceWithoutVat"] = IsNull(this.element.getAttribute("classColumnPriceWithoutVat"), "");
		this.classes["columnPriceWithVat"] = IsNull(this.element.getAttribute("classColumnPriceWithVat"), "");
		this.classes["columnPriceVat"] = IsNull(this.element.getAttribute("classColumnPriceVat"), "");
		this.classes["columnVatPercent"] = IsNull(this.element.getAttribute("classColumnVatPercent"), "");
		this.classes["columnImage"] = IsNull(this.element.getAttribute("classColumnImage"), "");
		//... ... ... ... hodnoty (td - tree)
		this.classes["valueCheck"] = IsNull(this.element.getAttribute("classValueCheck"), "");
		this.classes["valueAmount"] = IsNull(this.element.getAttribute("classValueAmount"), "");
		this.classes["valueProduct"] = IsNull(this.element.getAttribute("classValueProduct"), "");
		this.classes["valuePriceWithoutVat"] = IsNull(this.element.getAttribute("classValuePriceWithoutVat"), "");
		this.classes["valuePriceWithVat"] = IsNull(this.element.getAttribute("classValuePriceWithVat"), "");
		this.classes["valuePriceVat"] = IsNull(this.element.getAttribute("classValuePriceVat"), "");
		this.classes["valueVatPercent"] = IsNull(this.element.getAttribute("classValueVatPercent"), "");
		this.classes["valueImage"] = IsNull(this.element.getAttribute("classValueImage"), "");
		//... ... ... ... hodnoty (span - combo)
		this.classes["valueComboAmount"] = IsNull(this.element.getAttribute("classValueComboAmount"), "");
		this.classes["valueComboProduct"] = IsNull(this.element.getAttribute("classValueComboProduct"), "");
		this.classes["valueComboPriceWithoutVat"] = IsNull(this.element.getAttribute("classValueComboPriceWithoutVat"), "");
		this.classes["valueComboPriceWithVat"] = IsNull(this.element.getAttribute("classValueComboPriceWithVat"), "");
		this.classes["valueComboPriceVat"] = IsNull(this.element.getAttribute("classValueComboPriceVat"), "");
		this.classes["valueComboVatPercent"] = IsNull(this.element.getAttribute("classValueComboVatPercent"), "");
		this.classes["valueComboImage"] = IsNull(this.element.getAttribute("classValueComboImage"), "");
		//... ... ... ... specifické (a, input, img)
		this.classes["inputCheck"] = IsNull(this.element.getAttribute("classInputCheck"), "");
		this.classes["inputAmount"] = IsNull(this.element.getAttribute("classInputAmount"), "");
		this.classes["inputAmountReadonly"] = IsNull(this.element.getAttribute("classInputAmountReadonly"), "");
		this.classes["linkProduct"] = IsNull(this.element.getAttribute("classLinkProduct"), "");
		this.classes["product"] = IsNull(this.element.getAttribute("classProduct"), "");
		this.classes["image"] = IsNull(this.element.getAttribute("classImage"), "");
		//... ... ... CSS třídy (jen combo)
		this.classes["comboMain"] = IsNull(this.element.getAttribute("comboClassMain"), "");
		this.classes["comboValue"] = IsNull(this.element.getAttribute("comboClassValue"), "");
		this.classes["comboEdit"] = IsNull(this.element.getAttribute("comboClassEdit"), "");
		this.classes["comboEditFocused"] = IsNull(this.element.getAttribute("comboClassEditFocused"), "");
		this.classes["comboButton"] = IsNull(this.element.getAttribute("comboClassButton"), "");
		this.classes["comboList"] = IsNull(this.element.getAttribute("comboClassList"), "");
		this.classes["comboItemDefault"] = IsNull(this.element.getAttribute("comboItemClassDefault"), "");
		this.classes["comboItemSelected"] = IsNull(this.element.getAttribute("comboItemClassSelected"), "");
		this.classes["comboItemHover"] = IsNull(this.element.getAttribute("comboItemClassHover"), "");
		this.classes["comboItemDisabled"] = IsNull(this.element.getAttribute("comboItemClassDisabled"), "");
		//... ... root (přílušenství k)
		this.root = this.element.getAttribute("root");
		this.defaultAmount = IsNull(this.element.getAttribute("defaultAmount"), 1);
		this.userAmount = this.element.getAttribute("userAmount");
		this.priceWithoutVAT = this.element.getAttribute("priceWithoutVAT");
		this.priceWithVAT = this.element.getAttribute("priceWithVAT");
		this.vatPercent = this.element.getAttribute("vatPercent");
		this.userData = this.element.getAttribute("userData");
		//... ... elements
		this.elements["amount"] = GetTag(this.element.getAttribute("elementAmount"));
		this.elements["priceWithoutVAT"] = GetTag(this.element.getAttribute("elementPriceWithoutVAT"));
		this.elements["priceWithVAT"] = GetTag(this.element.getAttribute("elementPriceWithVAT"));
		this.elements["priceVAT"] = GetTag(this.element.getAttribute("elementPriceVAT"));
		//... ... ... přiřazení událostí
		if (this.elements["amount"] != null) {
			this.elements["amount"].onkeyup = new Function('return document.accessories[' + this.index + ']._handle_amount_keyup();');
		}
		//... ... messages
		this.messages["retrieving"] = IsNull(this.element.getAttribute("msgRetrieving"), "Probíhá načítání dat ...");
		this.messages["processing"] = IsNull(this.element.getAttribute("msgProcessing"), "Probíhá zpracování dat ...");
		this.messages["waiting"] = IsNull(this.element.getAttribute("msgWaiting"), "Čekejte prosím, probíhá načítání/zpracování ...");
		this.messages["amountError"] = IsNull(this.element.getAttribute("msgAmountError"), "Musí být zadáno korektní množství!");
		this.messages["columnAmount"] = IsNull(this.element.getAttribute("msgColumnAmount"), "Mn.");
		this.messages["columnProduct"] = IsNull(this.element.getAttribute("msgColumnProduct"), "Popis");
		this.messages["columnVatPercent"] = IsNull(this.element.getAttribute("msgColumnVatPercent"), "DPH [%]");
		this.messages["columnPriceWithoutVat"] = IsNull(this.element.getAttribute("msgColumnPriceWithoutVat"), "Cena bez DPH");
		this.messages["columnPriceWithVat"] = IsNull(this.element.getAttribute("msgColumnPriceWithVat"), "Cena s DPH");
		this.messages["columnPriceVat"] = IsNull(this.element.getAttribute("msgColumnPriceVat"), "DPH");
		this.messages["columnImage"] = IsNull(this.element.getAttribute("msgColumnImage"), "");
		//... ... názvy prvků
		//this._main_name = "accessory_" + (IsNull(this.name, "") != "" ? this.name : this.index);
		// * musí být dle indexu z důvodu rozpoznávání komponent dle těchto názvů
		// * v globálních událostech ( v názvu accessory se může vyskytovat cokoliv)
		this._main_name = "accessory_" + this.index;
		this._root_name = this._main_name + "_root";
		this._frame_name = this._main_name + "_frame";
		this._node_prefix = this._main_name + "_node_";
		//... vložení do seznamu (dle jména)
		if (this.name != null) {
			document.accessories[this.name] = this;
		}
		//... korekce a výpočet
		this.correct();
		this.calculate();
		//... vykreslení
		this.paint();
		//... načtení
		this.addToLoader(this);
		window.setInterval("document.accessories[" + this.index + "].loader()", 100);
	}
	
	//test a příprava dat k odeslání na server
	this.checkSubmit = function()
	{
		var in_front = (this._loading || this._front.length > 0);
		var input = GetTag(this.name);
		if (input != null) {
			input.value = (!in_front ? this.getXML() : "");
			if (in_front) alert(this.messages["waiting"]);
		}
		return (!in_front && input != null);
	}
	
	//korekce dat na vstupu pro větev
	this.correct = function(ANode)
	{
		var node = (ANode == null ? this : ANode);
		var is_root = (node.parent ? false : true);
		var data = (is_root ? this : node.data);
		var catg = (node.type == ACC_NODE_CATEGORY ? data.type : (!is_root ? node.parent.data.type : null));
		// - category
		if (node.type == ACC_NODE_CATEGORY) {
			node.allowExpand = true;
			node.expanded = true;
			node.selected = true;
			data.percent = null;
			data.priceWithoutVAT = 0;
			data.priceWithVAT = 0;
			data.vatPercent = 0;
			data.priceIsAvailable = true;
			data.defaultAmount = 1;
		// - root, item		
		} else {
			//... výběr a rozbalování větví
			var parent = (node.parent ? node.parent : node);
			var showAs = (data.showAs ? data.showAs : (parent.data ? parent.data.showAs : ACC_SHOW_AS_TREE));
			if (showAs == ACC_SHOW_AS_COMBO) node.allowExpand = false;
			if (!node.allowExpand) node.expanded = false;
			if (!node.enabled) {
				node.expanded = false;
				node.selected = false;
			}
			//... temp
			var tmp_percent = parseFloat(FloatToJS(data.percent));
			var tmp_priceWithoutVAT = parseFloat(FloatToJS(data.priceWithoutVAT));
			var tmp_priceWithVAT = parseFloat(FloatToJS(data.priceWithVAT));
			var tmp_vatPercent = parseFloat(FloatToJS(data.vatPercent));
			var tmp_defaultAmount = parseFloat(FloatToJS(data.defaultAmount));
			var tmp_userAmount = parseFloat(FloatToJS(data.userAmount));
			//... korekce
			//... ... výpočet ceny s daní
			if (isNaN(tmp_priceWithVAT) && !isNaN(tmp_priceWithoutVAT)) {
				if (isNaN(tmp_vatPercent)) tmp_vatPercent = 0;
				else if (tmp_vatPercent < 1) tmp_vatPercent *= 100;
				tmp_priceWithVAT = Math.ceil(((1 + (tmp_vatPercent / 100)) * tmp_priceWithoutVAT) * 10) / 10;
			}
			//... ... výpočet ceny bez daně
			if (isNaN(tmp_priceWithoutVAT) && !isNaN(tmp_priceWithVAT)) {
				if (isNaN(tmp_vatPercent)) tmp_vatPercent = 0;
				else if (tmp_vatPercent < 1) tmp_vatPercent *= 100;
				tmp_priceWithoutVAT = Math.ceil(tmp_priceWithVAT / ((1 + (tmp_vatPercent / 100))) * 10) / 10;
			}
			//... ... výpočet % daně
			if (isNaN(tmp_vatPercent) && !isNaN(tmp_priceWithVAT) && !isNaN(tmp_priceWithoutVAT)) {
				tmp_vatPercent = Math.round(((tmp_priceWithVAT / tmp_priceWithoutVAT) - 1) * 100);
			}
			//... přiřazení
			data.percent = (!isNaN(tmp_percent) ? tmp_percent : null);
			data.priceWithoutVAT = (!isNaN(tmp_priceWithoutVAT) ? tmp_priceWithoutVAT : null);
			data.priceWithVAT = (!isNaN(tmp_priceWithVAT) ? tmp_priceWithVAT : null);
			data.vatPercent = (!isNaN(tmp_vatPercent) ? tmp_vatPercent : null);
			data.defaultAmount = (!isNaN(tmp_defaultAmount) ? tmp_defaultAmount : 1);
			data.userAmount = (!isNaN(tmp_userAmount) ? tmp_userAmount : null);
			data.priceIsAvailable = (data.priceWithoutVAT != null && data.priceWithVAT != null);
			//... ... doplňující kontrola
			if (data.priceIsAvailable) data.percent = null;
			if (catg == ACC_CATG_REQUIRED || catg == ACC_CATG_SPECIAL) {
				data.userAmount = null;
				//if (data.defaultAmount <= 0) data.userAmount = 1;
			}
			//... ... výpočet jednotkové ceny pro procenta
			if (data.percent != null && !is_root) {
				var parent = node.parent.parent;
				if (parent.data) parent = parent.data;
				data.vatPercent = parent.vatPercent;
				if (parent.priceIsAvailable) {
					data.priceWithoutVAT = Math.ceil(((data.percent / 100) * parent.priceWithoutVAT) * 10) / 10;
					data.priceWithVAT = Math.ceil(((1 + (data.vatPercent / 100)) * data.priceWithoutVAT) * 10) / 10;
					data.priceIsAvailable = true;
				}
			}
		}
	}

	//výpočet množství/cen
	this.calculate = function(ANode)
	{
		this.calculateAmount(ANode);
		this.calculatePrice(ANode);
	}

	//výpočet množství pro větev
	this.calculateAmount = function(ANode)
	{
		var node = (ANode == null ? this : ANode);
		var parent = (node.parent ? node.parent : null);
		var data = (node.data ? node.data : node);
		var data_up = (parent != null ? (parent.data ? parent.data : parent) : null);
		//... výpočet
		if (data_up != null) {
			var amount_up = IsNull(data_up.userAmount, IsNull(data_up.calculatedAmount, data_up.defaultAmount));
			// ... ... -1, 0
			if (data.defaultAmount <= 0) {
				data.calculatedAmount = amount_up;
			// ... ... +1
			} else {
				data.calculatedAmount = Math.ceil(data.defaultAmount * amount_up);
			}
		}
		//... přepočet podvětví
		for (var i = 0; i < node.nodes.length; i ++) {
			node.nodes[i].calculateAmount();
		}
	}

	//výpočet ceny pro větev
	this.calculatePrice = function(ANode)
	{
		var node = (ANode == null ? this : ANode);
		var data = (node.data ? node.data : node);
		var amount = IsNull(data.userAmount, IsNull(data.calculatedAmount, data.defaultAmount));
		//... výpočet
		//... ... pouze položka
		data.selfCalculatedPriceWithoutVAT = data.priceWithoutVAT == null ? null : Math.ceil(data.priceWithoutVAT * amount * 10) / 10;
		data.selfCalculatedPriceWithVAT = data.priceWithVAT = null ? null : Math.ceil(data.priceWithVAT * amount * 10) / 10;
		if (data.selfCalculatedPriceWithVAT == null || data.selfCalculatedPriceWithoutVAT == null) {
		    data.selfCalculatedPriceVAT = null;
		}
		else {
		    data.selfCalculatedPriceVAT = Math.round((data.selfCalculatedPriceWithVAT - data.selfCalculatedPriceWithoutVAT) * 10) / 10;
		}
		//... ... vč. podvětví
		data.calculatedPriceWithoutVAT = data.selfCalculatedPriceWithoutVAT;
		data.calculatedPriceWithVAT = data.selfCalculatedPriceWithVAT;
		data.calculatedPriceVAT = data.selfCalculatedPriceVAT;
		for (var i = 0; i < node.nodes.length; i ++) {
			var child = node.nodes[i];
			child.calculatePrice();
			if (child.selected) {
				data.calculatedPriceWithoutVAT += child.data.calculatedPriceWithoutVAT;
				data.calculatedPriceWithVAT += child.data.calculatedPriceWithVAT;
				data.calculatedPriceVAT += child.data.calculatedPriceVAT;
			}
		}
	}

	//vykreslení - skelet komponenty
	this.paint = function()
	{
		//... události
		var evt_frame = 'onload="return document.accessories[' + this.index + ']._handle_frame_load(this)" ';
		//... styly
		var class_main = (this.classes["main"] != "" ? 'class="' + this.classes["main"] + '"' : '');
		var class_node = (this.classes["node"] != "" ? 'class="' + this.classes["node"] + '"' : '');
		//... sestavení HTML
		var sHTML = "";
		sHTML += '<div id="' + this._main_name + '" name="' + this._main_name + '" ' + class_main + '> \r\n';
		sHTML += '	<div id="' + this._root_name + '" name="' + this._root_name + '" ' + class_node + '> \r\n';
		sHTML += 			this.getHTML();
		sHTML += '	</div> \r\n';
		// - ... ošetření https pro prázdný frame
		var src_frame = this.getUrl();
		if (src_frame != null && src_frame.toLowerCase().indexOf("https://") == 0) src_frame = 'src="' + src_frame + '"'; else src_frame = '';
		sHTML += '	<iframe id="' + this._frame_name + '" name="' + this._frame_name + '" ' + evt_frame + ' scrolling="no" frameborder="0" hspace="0" vspace="0" width="0" height="0" ' + src_frame + '></iframe> \r\n';
		//sHTML += '	<iframe id="' + this._frame_name + '" name="' + this._frame_name + '" ' + evt_frame + ' scrolling="yes" frameborder="0" hspace="0" vspace="0" width="300" height="300" ' + src_frame + '></iframe> \r\n';
		if (IsNull(this.name, "") != "") {
			sHTML += '	<input type="hidden" id="' + this.name + '" name="' + this.name + '" value=""/> \r\n';
		}
		sHTML += '</div> \r\n';
		//... vložení
		this.element.innerHTML = sHTML;
		//... doplňující vykreslení
		this.paintNodes();
		this.paintAmount();
		this.paintPrices();
	}

	//vykreslení - položky
	this.paintNodes = function(AParent)
	{
		var parent = (AParent == null ? this : AParent);
		var tag = parent.getElement();
		if (tag != null) {
			var sHTML = parent.getHTML();
			tag.innerHTML = sHTML;
			//... inicializace ComboBoxů
			if (sHTML.indexOf("comboBox") >= 0) {
				InitComboBoxes();
				for (var i = 0; i < document.comboBoxes.length; i ++) {
					document.comboBoxes[i].onChange = 'document.accessories[' + this.index + ']._handle_combo_change';
				}
			}
		}
	}
	
	//vykreslení - pouze ceny
	this.paintPrices = function(ANode)
	{
		var node = (ANode != null ? ANode : this);
		var data = (node.data ? node.data : node);
		//... cena bez daně
		if (data.calculatedPriceWithoutVAT != null) {
			var tag = node.getElement("priceWithoutVAT");
			if (tag != null) {
				tag.innerHTML = Money(data.calculatedPriceWithoutVAT, this.useHellers) + (IsNull(this.currency, "") != "" ? " " + this.currency : "");
			}
		}
		//... cena s daní
		if (data.calculatedPriceWithVAT != null) {
			var tag = node.getElement("priceWithVAT");
			if (tag != null) {
				tag.innerHTML = Money(data.calculatedPriceWithVAT, this.useHellers) + (IsNull(this.currency, "") != "" ? " " + this.currency : "");
			}
		}
		//... daň - cena
		if (data.calculatedPriceVAT != null) {
			var tag = node.getElement("priceVAT");
			if (tag != null) {
				tag.innerHTML = Money(data.calculatedPriceVAT, this.useHellers) + (IsNull(this.currency, "") != "" ? " " + this.currency : "");
			}
		}
		//... daň - procento
		if (data.vatPercent != null) {
			var tag = node.getElement("vatPercent");
			if (tag != null) {
				tag.innerHTML = data.vatPercent + "%";
			}
		}		
		//... podvětve
		for (var i = 0; i < node.nodes.length; i ++) {
			node.nodes[i].paintPrices();
		}
	}
	
	//vykreslení - pouze množství
	this.paintAmount = function(AWithSelf, ANode)
	{
		var node = (ANode != null ? ANode : this);
		var parent = (node.parent ? node.parent : node);
		var data = (node.data ? node.data : node);
		var catg = (node.type == ACC_NODE_ITEM ? parent.data.type : null);
		var amountMode = (node.amountEntryMode ? node.amountEntryMode() : -1);
		var amount = (amountMode == 3 ? IsNull(data.userAmount, "") : IsNull(data.userAmount, IsNull(data.calculatedAmount, data.defaultAmount)));
		if (IsNull(AWithSelf, true) == true) {
			var tag = node.getElement("amount");
			if (tag != null) {
				if ((tag.tagName + "").toUpperCase() == "INPUT") {
					tag.value = amount;
				} else tag.innerHTML = amount;
			}
		}
		//... podvětve
		for (var i = 0; i < node.nodes.length; i ++) {
			node.nodes[i].paintAmount();
		}
	}
	
	//sestavení html
	this.getHTML = function(AParent)
	{

		//... pomocná fce na sestavení html pro položku typu "item	"
		function itemHTML(AAccessory)
		{
			for (var j = 0; j < columns.length; j ++) {
				var col = columns[j].trim().toLowerCase();
				var tag_id = '';
				var buf = '';
				var key = '';
				// - sloupec: "množství"
				if (col == "amount") {
					key = "valueAmount";
					var amountMode = node.amountEntryMode();
					var evt_amount = 'onkeyup="return document.accessories[' + AAccessory.index + ']._handle_amount_keyup(\'' + node._node_name + '\')" ';
					var class_amount = (AAccessory.classes["inputAmount" + (amountMode == 1 ? "Readonly" : "")] != "" ? 'class="' + AAccessory.classes["inputAmount" + (amountMode == 1 ? "Readonly" : "")] + '"' : '');
					var amount = (amountMode == 3 ? IsNull(data.userAmount, "") : IsNull(data.userAmount, IsNull(data.calculatedAmount, data.defaultAmount)));
					buf += '<input type="text" id="' + node._amount_name + '" name="' + node._amount_name + '" ' + (amountMode == 1 || !node.enabled ? 'readonly' : '') + ' maxlength="5" size="3" value="' + amount + '" ' + class_amount + ' ' + evt_amount + '/>';
				// - sloupec: "název a popis produktu"
				} else if (col == "product") {
					key = "valueProduct";
					// ... název (možnost linku)
					if (IsNull(data.name, "") != "") {
						if (AAccessory.useLinks && IsNull(data.link, "") != "") {
							var class_link = (AAccessory.classes["linkProduct"] != "" ? 'class="' + AAccessory.classes["linkProduct"] + '"' : '');
							buf += '<a href="' + data.link + '" ' + class_link + '>' + data.name + '</a> \r\n';
						} else {
							var class_product = (AAccessory.classes["product"] != "" ? 'class="' + AAccessory.classes["product"] + '"' : '');
							buf += '<span ' + class_product + '>' + data.name + '</span>';
						}
					}
					// ... popis
					if (IsNull(data.desc, "") != "") {
						if (IsNull(data.name, "") != "") buf += '<br/>';
						buf += data.desc + '\r\n';
					}
				// - sloupec: "cena bez daně"
				} else if (col == "pricewithoutvat") {
					key = "valuePriceWithoutVat";
					tag_id = 'id="' + node._priceWithoutVAT_name + '" name="' + node._priceWithoutVAT_name + '"';
					if (data.calculatedPriceWithoutVAT != null) {
						buf += Money(data.calculatedPriceWithoutVAT, AAccessory.useHellers) + (IsNull(AAccessory.currency, "") != "" ? " " + AAccessory.currency : "");
					}
					else {
					    buf += '<img src="design/stasto/images/icons/phone.gif" />';
					}
				// - sloupec: "cena s daní"
				} else if (col == "pricewithvat") {
					key = "valuePriceWithVat";
					tag_id = 'id="' + node._priceWithVAT_name + '" name="' + node._priceWithVAT_name + '"';
					if (data.calculatedPriceWithVAT != null) {
						buf += Money(data.calculatedPriceWithVAT, AAccessory.useHellers) + (IsNull(AAccessory.currency, "") != "" ? " " + AAccessory.currency : "");
					}
					else {
					    buf += '<img src="design/stasto/images/icons/phone.gif" />';
					}					
				// - sloupec: "daň - cena"
				} else if (col == "pricevat") {
					key = "valuePriceVat";
					tag_id = 'id="' + node._priceVAT_name + '" name="' + node._priceVAT_name + '"';
					if (data.calculatedPriceVAT != null) {
						buf += Money(data.calculatedPriceVAT, AAccessory.useHellers) + (IsNull(AAccessory.currency, "") != "" ? " " + AAccessory.currency : "");
					}
					else {
					    buf += '<img src="design/stasto/images/icons/phone.gif" />';
					}					
				// - sloupec: "daň - procento"
				} else if (col == "vatpercent") {
					key = "valueVatPercent";
					tag_id = 'id="' + node._vatPercent_name + '" name="' + node._vatPercent_name + '"';
					if (data.vatPercent != null) {
						buf += data.vatPercent + "%";
					}
					else {
					    buf += '<img src="design/stasto/images/icons/phone.gif" />';
					}					
				// - sloupec: "obrázek"
				} else if (col == "image") {
					key = "valueImage";
					if (IsNull(data.image, "") != "") {
						var class_img = (AAccessory.classes["image"] != "" ? 'class="' + AAccessory.classes["image"] + '"' : '');
						buf += '<img src="' + data.image + '" ' + class_img + '/> \r\n';
					} else {
						buf += '&nbsp;\r\n';
					}
				}
				// - sestavení
				if (showAs == ACC_SHOW_AS_TREE) {
					var class_value = (AAccessory.classes[key] != "" ? 'class="' + AAccessory.classes[key] + '"' : '');
					sHTML += '		<td ' + tag_id + ' ' + class_value + '>' + buf + '</td> \r\n';
				} else if (showAs == ACC_SHOW_AS_COMBO) {
					key = key.replace("value", "valueCombo");
					var class_value = (AAccessory.classes[key] != "" ? 'class="' + AAccessory.classes[key] + '"' : '');
					sHTML += '<span ' + tag_id + ' ' + class_value + '>' + buf + '</span>';
				}
			}
		}
		
		var parent = (AParent == null ? this : AParent);
		var sHTML = '';
		//... jednotlivé větve (category / item)
		for (var i = 0; i < parent.nodes.length; i ++) {
			var node = parent.nodes[i];
			var data = node.data;
			var catg = (node.type == ACC_NODE_CATEGORY ? data.type : parent.data.type);
			var id_name = 'id="' + node._node_name + '" name="' + node._node_name + '"';
			var showAs = (node.data.showAs ? node.data.showAs : (parent.data ? parent.data.showAs : ACC_SHOW_AS_TREE));
			var columns = (showAs == ACC_SHOW_AS_COMBO ? this.showInCombo : this.showInTree).split("|");
			// * category
			if (node.type == ACC_NODE_CATEGORY) {
				if (node.nodes.length == 0) {
					continue;
				}
				// - styly
				var class_main = (this.classes["categoryMain"] != "" ? 'class="' + this.classes["categoryMain"] + '"' : '');
				var class_header = (this.classes["categoryHeader"] != "" ? 'class="' + this.classes["categoryHeader"] + '"' : '');
				var class_combo = (this.classes["categoryCombo"] != "" ? 'class="' + this.classes["categoryCombo"] + '"' : '');
				var class_note = (this.classes["categoryNote"] != "" ? 'class="' + this.classes["categoryNote"] + '"' : '');
				var class_check = (this.classes["columnCheck"] != "" ? 'class="' + this.classes["columnCheck"] + '"' : '');
				sHTML += '<table cellspacing="0" ' + class_main + '> \r\n';
				// - pokud se nejedná o poznámku zobraz hlavičku
				if (catg != ACC_CATG_NOTE) {
					sHTML += '	<tr> \r\n';
					sHTML += '		<td colspan="20" ' + class_header + '>' + data.name + (IsNull(data.desc, "") != "" ? " (" + data.desc + ")" : "") + '</td> \r\n';
					sHTML += '	</tr> \r\n';
					// - ... pohled: tree
					if (showAs == ACC_SHOW_AS_TREE) {
						sHTML += '	<tr> \r\n';
						sHTML += '		<td ' + class_check + '></td> \r\n';
						for (var j = 0; j < columns.length; j ++) {
							var col = columns[j].trim().toLowerCase();
							var key = "";
							if (col == "amount") key = "columnAmount";
							else if (col == "product") key = "columnProduct";
							else if (col == "vatpercent") key = "columnVatPercent";
							else if (col == "pricewithoutvat") key = "columnPriceWithoutVat";
							else if (col == "pricewithvat") key = "columnPriceWithVat";
							else if (col == "pricevat") key = "columnPriceVat";
							else if (col == "image") key = "columnImage";
							var class_col = (this.classes[key] != "" ? 'class="' + this.classes[key] + '"' : '');
							sHTML += '		<td ' + class_col + '>' + this.messages[key] + '</td> \r\n';
						}
						sHTML += '	</tr> \r\n';
						sHTML += 		node.getHTML();
					// - ... pohled: combo
					} else if (showAs == ACC_SHOW_AS_COMBO) {
						var comboBox = this.handleNamespace("comboBox");
						var classes = '';
						classes += 'classMain="' + this.classes["comboMain"] + '" ';
						classes += 'classValue="' + this.classes["comboValue"] + '" ';
						classes += 'classEdit="' + this.classes["comboEdit"] + '" ';
						classes += 'classEditFocused="' + this.classes["comboEditFocused"] + '" ';
						classes += 'classButton="' + this.classes["comboButton"] + '" ';
						classes += 'classList="' + this.classes["comboList"] + '" ';
						sHTML += '	<tr> \r\n';
						sHTML += '		<td colspan="20" ' + class_combo + '> \r\n';
						sHTML += '			<' + comboBox + ' name="' + node._node_name + '" ' + classes + '> \r\n';
						sHTML += 					node.getHTML();
						sHTML += '			</' + comboBox + '> \r\n';
						sHTML += '		</td> \r\n';
						sHTML += '	</tr> \r\n';
					}
				// - poznámka
				} else {
					sHTML += '	<tr> \r\n';
					sHTML += '		<td colspan="20" ' + class_header + '>' + node.data.name + '</td> \r\n';
					sHTML += '	</tr> \r\n';
					for (var j = 0; j < node.nodes.length; j ++) {
						var d = node.nodes[j].data;
						sHTML += '	<tr> \r\n';
						sHTML += '		<td colspan="20" ' + class_note + '>' + IsNull(IsNull(d.name, d.desc), "") + '</td> \r\n';
						sHTML += '	</tr> \r\n';
					}
				}
				sHTML += '</table> \r\n';
			// * item
			} else if (node.type == ACC_NODE_ITEM) {
				// - ... styly
				var class_check1 = (this.classes["valueCheck"] != "" ? 'class="' + this.classes["valueCheck"] + '"' : '');
				var class_check2 = (this.classes["inputCheck"] != "" ? 'class="' + this.classes["inputCheck"] + '"' : '');
				var class_node = (this.classes["node"] != "" ? 'class="' + this.classes["node"] + '"' : '');
				var class_item = (this.classes["item" + (!node.enabled ? "Disabled" : "")] != "" ? 'class="' + this.classes["item" + (!node.enabled ? "Disabled" : "")] + '"' : '');
				// - ... pohled: tree
				if (showAs == ACC_SHOW_AS_TREE) {
					sHTML += '	<tr ' + class_item + '> \r\n';
					sHTML += '		<td ' + class_check1 + '> \r\n';
					if (node.enabled && data.priceIsAvailable) {
						var evt_check = 'onclick="return document.accessories[' + this.index + ']._handle_check_click(\'' + node._node_name + '\')" ';
						var type = (catg == ACC_CATG_REQUIRED ? 'radio' : 'checkbox');
						sHTML += '			<input type="' + type + '" id="' + node._check_name + '" name="' + node._check_name + '" ' + (node.selected ? 'checked' : '') + ' ' + class_check2 + ' ' + evt_check + '/> \r\n';
					}
					sHTML += '		</td> \r\n';
					itemHTML(this);
					sHTML += '	</tr> \r\n';
					if (node.allowExpand) {
						sHTML += '	<tr> \r\n';
						sHTML += '		<td></td> \r\n';
						sHTML += '		<td colspan="19" ' + id_name + ' ' + class_node + '> \r\n';
						if (node.expanded) sHTML += node.getHTML();
						sHTML += '		</td> \r\n';
						sHTML += '	</tr> \r\n';
					}
				// - ... pohled: combo
				} else if (showAs == ACC_SHOW_AS_COMBO) {
					var comboItem = this.handleNamespace("item");
					var classes = '';
					classes += 'classDefault="' + this.classes["comboItemDefault"] + '" ';
					classes += 'classSelected="' + this.classes["comboItemSelected"] + '" ';
					classes += 'classHover="' + this.classes["comboItemHover"] + '" ';
					classes += 'classDisabled="' + this.classes["comboItemDisabled"] + '" ';
					sHTML += '			<' + comboItem + ' enabled="' + (node.enabled ? '1' : '0') + '" value="' + node._node_name + '" ' + (node.selected ? 'selected' : '') + ' ' + classes + '>';
					itemHTML(this);
					sHTML += 			 '</' + comboItem + '> \r\n';
				}
			}
		}
		return sHTML;
	}
	
	//sestavení xml (pro odeslání na server)
	this.getXML = function(ANode, AIndent)
	{
		var node = (ANode != null ? ANode : this);
		var data = (node.data ? node.data : node);
		var is_root = (node.parent ? false : true);
		var tn = (node.parent ? "item" : "root");
		var indent = IsNull(AIndent, 0);
		var indent_buf = Replicate("\t", indent);
		//... sestavení
		var xml = '';
		//... ... pouze u položky/rootu
		if (node.type != ACC_NODE_CATEGORY) {
			if (is_root) {
				xml += '<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> \r\n';
			}
			var attr = '';
			attr += 'id="' + (is_root ? data.root : data.id) + '" ';
			attr += 'amount="' + IsNull(data.userAmount, IsNull(data.calculatedAmount, data.defaultAmount)) + '" ';
			attr += 'priceWithoutVat="' + IsNull(data.selfCalculatedPriceWithoutVAT, data.priceWithoutVAT) + '" ';
			attr += 'priceWithVat="' + IsNull(data.selfCalculatedPriceWithVAT, data.priceWithVAT) + '" ';
			attr += 'priceVat="' + IsNull(data.selfCalculatedPriceVAT, data.priceVAT) + '" ';
			attr += 'vatPercent="' + data.vatPercent + '"';
			if (IsNull(data.userData, "") != "") attr += ' userData="' + data.userData + '"';
			xml += indent_buf + '<' + tn + ' ' + attr + '> \r\n';
			indent ++;
		}
		//... ... položky
		for (var i = 0; i < node.nodes.length; i ++) {
			var child = node.nodes[i];
			if (child.selected) xml += child.getXML(indent);
		}
		//... ... pouze u položky/rootu
		if (node.type != ACC_NODE_CATEGORY) {
			xml += indent_buf + '</' + tn + '> \r\n';
		}
		return xml;
	}

	//zjištění elementu
	this.getElement = function(AType)
	{
		if (IsNull(AType, "") != "") {
			return this.elements[AType];
		} else {
			return GetTag(this._root_name);
		}
	}

	//zjištění zdroje dat
	this.getUrl = function()
	{
		var buf = IsNull(this.script, "");
		buf = AddToUrl(buf, "root", IsNull(this.root, ""));
		buf = AddToUrl(buf, "rootData", IsNull(this.userData, ""));
		return buf;
	}
	
	//úprava názvu uživatelského tagu dle namespace u komponenty
	this.handleNamespace = function(ATagName)
	{
		return (IsNull(this.namespace, "") != "" ? this.namespace + ":" + ATagName : ATagName);
	}
	
	//vyhledání větve - dle jména
	this.findNodeByName = function(ANodeName, AParent)
	{
		if (IsNull(ANodeName, "") == "") return null;
		var ret = null;
		var parent = (AParent != null ? AParent : this);
		//... přímé větve
		for (var i = 0; i < parent.nodes.length; i ++) {
			if (parent.nodes[i]._node_name == ANodeName) {
				ret = parent.nodes[i];
				break;
			}
		}
		//... vícevnořené větve
		if (ret == null) {
			for (var i = 0; i < parent.nodes.length; i ++) {
				ret = this.findNodeByName(ANodeName, parent.nodes[i]);
				if (ret != null) break;
			}
		}
		return ret;
	}
	
	//správa pro načítání větví	
	//... přidání
	this.addToLoader = function(AObject)
	{
		this._front[this._front.length] = AObject;
	}
	
	//... spuštění
	this.loader = function()
	{
		if (this._loading) return false;
		if (this._front.length > 0) {
			var node = this._front[0];
			var tag = node.getElement();
			var frame = window.frames[this._frame_name];
			tag.innerHTML = this.messages["retrieving"];
			frame.document.location = node.getUrl();
			this._loading = true;
			return true;
		}
		return false;
	}
	
	//... zpracování načteného obsahu
	this.processContent = function(ANode, ADocument)
	{
		var accessory = ADocument.getElementsByTagName("accessory")[0];
		if (accessory != null) {
			var categories = accessory.getElementsByTagName("category");
			for (var i = 0; i < categories.length; i ++) {
				ANode.nodes[ANode.nodes.length] = new TAccessoryNode(ANode, categories[i]);
			}
			this.calculate();
			this.paintPrices();
			ANode.paintNodes();
		}
	}

	//zachycení událostí prvků
	//... IFRAME - OnLoad
	this._handle_frame_load = function(AElement)
	{
		if (!this._loading) return false;
		var node = this._front[0];
		var tag = node.getElement();
		var frame = window.frames[this._frame_name];
		tag.innerHTML = this.messages["processing"];
		this.processContent(node, frame.document);
		RemoveFromArray(this._front, 0);
		this._loading = false;
		return true;
	}
	
	//... CHECKBOX/RADIO - OnClick
	this._handle_check_click = function(ANodeName)
	{
		var node = (IsNull(ANodeName, "") == "" ? this : this.findNodeByName(ANodeName));
		var element = (node != null ? node.getElement("check") : null);
		node.select(element.checked);
	}

	//... AMOUNT - OnKeyUp
	this._handle_amount_keyup = function(ANodeName)
	{
		var node = (IsNull(ANodeName, "") == "" ? this : this.findNodeByName(ANodeName));
		var element = (node != null ? node.getElement("amount") : null);
		if (node == null || element == null) return;
		var data = (node.data ? node.data : node);
		data.userAmount = element.value;
		node.correct();
		if (node.select) {
			node.select(data.userAmount != null);
		}
		this.calculate();
		this.paintPrices();
		node.paintAmount(false);
	}

	//... COMBO - OnChange
	this._handle_combo_change = function(ACombo)
	{
		if (ACombo.selected == null) return;
		var node = this.findNodeByName(ACombo.selected.value);
		if (node != null) node.select(true, false, false, true);
	}

	//inicializace
	this.init();
}

//---------------------------------------------------------------------------------------------------
//  OBJEKT VĚTVE: TAccessoryNode
//---------------------------------------------------------------------------------------------------
function TAccessoryNode(AParent, AElement)
{
	//properties
	//... public
	this.index = -1;
	this.type = null;	
	this.accessory = null;
	this.parent = AParent;
	this.element = AElement;
	//... ... nastavení
	this.allowExpand = true;
	this.expanded = false;
	this.selected = false;
	this.enabled = true;
	//... ... data
	this.data = null;
	//... ... items
	this.nodes = new Array();
	//... private
	this._node_name = "";
	this._check_name = "";
	this._amount_name = "";
	this._priceWithoutVAT_name = "";
	this._priceWithVAT_name = "";
	this._priceVAT_name = "";
	this._vatPercent_name = "";
	

	//inicializace
	this.init = function()
	{
		this.index = this.parent.nodes.length;
		this.type = ((this.element.tagName + "").toUpperCase() == "CATEGORY" ? ACC_NODE_CATEGORY : ACC_NODE_ITEM);
		this.accessory = (this.parent.parent ? this.parent.accessory : this.parent);
		//... názvy prvků
		this._node_name = this.accessory._node_prefix + this.index + "_" + RandomHEX(30);
		this._check_name = this._node_name + "_check";
		this._amount_name = this._node_name + "_amount";
		this._priceWithoutVAT_name = this._node_name + "_priceWithoutVAT";
		this._priceWithVAT_name = this._node_name + "_priceWithVAT";
		this._priceVAT_name = this._node_name + "_priceVAT";
		this._vatPercent_name = this._node_name + "_vatPercent";
		//... nastavení
		this.allowExpand = !IsValueInArray((this.element.getAttribute("allowExpand") + ""), ["false", "0", "no"]);
		this.enabled = !IsValueInArray((this.element.getAttribute("enabled") + ""), ["false", "0", "no"]);
		//... data
		this.data = new Object();
		this.data.id = IsNull(this.element.getAttribute("id"), "");
		this.data.name = IsNull(this.element.getAttribute("name"), "");
		this.data.desc = IsNull(this.element.getAttribute("desc"), "");
		this.data.userData = this.element.getAttribute("userData");
		//... ... category
		if (this.type == ACC_NODE_CATEGORY) {
			this.data.type = parseInt(IsNull(this.element.getAttribute("type"), ACC_CATG_OPTIONAL_MORE));
			this.data.showAs = ((this.element.getAttribute("showAs") + "").toLowerCase() == "combo" ? ACC_SHOW_AS_COMBO : ACC_SHOW_AS_TREE);
			//... korekce
			this.correct();
			this.calculate();
			//... ... ... obsažené položky
			var items = this.element.getElementsByTagName("item");
			for (var i = 0; i < items.length; i ++) {
				this.nodes[this.nodes.length] = new TAccessoryNode(this, items[i]);
			}
			//... ... ... výběr položky
			for (var i = 0; i < this.nodes.length; i ++) {
				var node = this.nodes[i];
				if (!node.enabled) continue;
				var selected = IsValueInArray((node.element.getAttribute("selected") + ""), ["true", "1", "yes"]);
				if (selected) node.select(true); 
			}
			this.checkSelected();
		//... ... item
		} else if (this.type == ACC_NODE_ITEM) {
			this.data.image = IsNull(this.element.getAttribute("image"), "");
			this.data.link = IsNull(this.element.getAttribute("link"), "");
			this.data.percent = this.element.getAttribute("percent");
			this.data.priceWithoutVAT = this.element.getAttribute("priceWithoutVAT");
			this.data.priceWithVAT = this.element.getAttribute("priceWithVAT");
			this.data.vatPercent = this.element.getAttribute("vatPercent");
			this.data.defaultAmount = IsNull(this.element.getAttribute("defaultAmount"), 1);
			this.data.userAmount = this.element.getAttribute("userAmount");
			//... korekce
			this.correct();
		}
		//... přepočet
		this.calculate();
	}
	
	//korekce vstupních dat
	this.correct = function()
	{
		this.accessory.correct(this);
	}
	
	//výpočet množství/cen
	this.calculate = function(ANode)
	{
		this.accessory.calculate(this);
	}

	//výpočet množství pro větev
	this.calculateAmount = function()
	{
		this.accessory.calculateAmount(this);
	}

	//výpočet ceny pro větev
	this.calculatePrice = function()
	{
		this.accessory.calculatePrice(this);
	}

	//vykreslení - položky
	this.paintNodes = function()
	{
		//... vždy se vykreslují items vč. category
		if (this.type == ACC_NODE_ITEM) {	
			this.accessory.paintNodes(this);
		} else if (this.type == ACC_NODE_ITEM) {	
			this.accessory.paintNodes(this.parent);
		}
	}
	
	//vykreslení - pouze ceny
	this.paintPrices = function()
	{
		this.accessory.paintPrices(this);
	}

	//vykreslení - pouze množství
	this.paintAmount = function(AWithSelf)
	{
		this.accessory.paintAmount(AWithSelf, this);
	}
	
	//počet vybraných "item" v "category"
	this.selectedCount = function()
	{
		if (this.type != ACC_NODE_CATEGORY) return 0;
		var ret = 0;
		for (var i = 0; i < this.nodes.length; i ++) {
			if (this.nodes[i].selected) ret ++;
		}
		return ret;
	}

	//kontrola + příp. výběr položky dle typu kategorie
	this.checkSelected = function()
	{
		var item = (this.type == ACC_NODE_ITEM ? this : null);
		var category = (this.type == ACC_NODE_ITEM ? this.parent : this);
		var type = category.data.type;
		var vybrano = category.selectedCount();
		//... povinný výběr
		if (type == ACC_CATG_REQUIRED) {
			if (vybrano == 0) {
				for (var i = 0; i < category.nodes.length; i ++) {
					if (!category.nodes[i].enabled) continue;
					category.nodes[i].select(true, true, false);
					break;
				}
			} else if (vybrano > 1) {
				for (var i = 0; i < category.nodes.length; i ++) {
					var node = category.nodes[i];
					if (node != item && node.enabled) node.select(false, true, true);
				}
			}
		//... volitelný výběr - 1 možnost
		} else if (type == ACC_CATG_OPTIONAL_1) {
			if (vybrano > 1) {
				for (var i = 0; i < category.nodes.length; i ++) {
					var node = category.nodes[i];
					if (node != item && node.enabled) node.select(false, true, true);
				}
			}
		}
	}

	//výběr větve
	this.select = function(AState, ANoCheck, ANoCalc, ANoCombo)
	{
		if (this.type != ACC_NODE_ITEM) return false;
		if (!this.enabled) return false;
		var state = IsNull(AState, true);
		if ((state && this.selected) || (!state && !this.selected)) return false;
		var tag = this.getElement("check");
		// - kontrola vstupu uživatele
		if (state && !this.accessory._loading) {
			var amountMode = this.amountEntryMode();
			var amount = this.inputAmount();
			if (amountMode > 1 && (amount == null || amount <= 0)) {
				if (tag != null) tag.checked = false;
				alert(this.accessory.messages["amountError"]);
				return;
			}
		}
		//... změna stavu
		if (tag != null && tag.checked != state) tag.checked = state;
		this.selected = state;
		//... kontrola "selected"
		if (!IsNull(ANoCheck, false)) {
			this.checkSelected();
		}
		//... rozbalení/zabalení/combo
		var category = (this.type == ACC_NODE_ITEM ? this.parent : this);
		//... ... combo
		if (category.data.showAs == ACC_SHOW_AS_COMBO) {
			if (!IsNull(ANoCombo, false) && this.selected) {
				var combo = document.comboBoxes[category._node_name];
				if (combo != null) {
					var idx = combo.indexOf(this._node_name);
					if (idx >= 0) combo.items[idx].select();
				}
			}
		//... ... rozbalení/zabalení
		} else {
			if (this.selected) this.expand();
			else this.collapse();
		}
		//... přepočet
		if (!IsNull(ANoCalc, false)) {
			if (!this.selected) this.data.userAmount = null;
			this.accessory.calculate();
			this.accessory.paintPrices();
			if (!this.selected) this.paintAmount();
		}
	}

	//otevření větve
	this.expand = function()
	{
		if (this.type != ACC_NODE_ITEM) return false;
		if (!this.allowExpand || this.expanded) return false;
		this.expanded = true;
		if (this.nodes.length > 0) {
			this.paintNodes();
		} else {
			this.accessory.addToLoader(this);
		}
	}

	//zavření větve
	this.collapse = function()
	{
		if (this.type != ACC_NODE_ITEM) return false;
		if (!this.expanded) return false;
		this.expanded = false;
		var tag = this.getElement();
		if (tag != null) tag.innerHTML = "";
	}
	
	//zjistí zda má položka zadavatelné množství
	// - vrací:  0 - u této položky není množství podporováno
	//			 1 - pouze se zobrazuje (není možné upravit)
	//			 2 - je možné upravovat a hodnota je předvyplněna
	//			 3 - je možné upravovat a hodnota není předem známa (vynucené zadání uživatelem)
	this.amountEntryMode = function()
	{
		if (this.type != ACC_NODE_ITEM) return 0;
		var catg = this.parent.data.type;
		var da = this.data.defaultAmount;
		var ro = (da != null && ((da == 0) || (catg == ACC_CATG_REQUIRED || catg == ACC_CATG_SPECIAL)));
		if (ro) return 1;
		if (da < 0 && (catg == ACC_CATG_OPTIONAL_1 || catg == ACC_CATG_OPTIONAL_MORE)) return 3;
		return 2;
	}

	//zjistí množství zadané ve vstupním prvku	
	this.inputAmount = function()
	{
		var tag = this.getElement("amount");
		if (tag == null)  return null;
		var amount = parseFloat(((tag.tagName + "").toUpperCase() == "INPUT" ? tag.value : tag.innerHTML));
		if (isNaN(amount) || amount <= 0) amount = null;
		return amount;
	}

	//sestavení html
	this.getHTML = function()
	{
		return this.accessory.getHTML(this);
	}

	//sestavení xml (pro odeslání na server)
	this.getXML = function(AIndent)
	{
		return this.accessory.getXML(this, AIndent);
	}

	//zjištění elementu
	this.getElement = function(AType)
	{
		var t = IsNull(AType, "node");
		var n = eval("this._" + t + "_name");
		return GetTag(n);
	}

	//zjištění zdroje dat
	this.getUrl = function()
	{
		var param_name = (this.type == ACC_NODE_CATEGORY ? "category" : "item");
		var buf = this.accessory.getUrl();
		buf = AddToUrl(buf, param_name, this.data.id);
		buf = AddToUrl(buf, param_name + "Data", IsNull(this.data.userData, ""));
		return buf;
	}

	//inicializace
	this.init();
}

//---------------------------------------------------------------------------------------------------
//  INICIALIZAČNÍ FUNKCE
//---------------------------------------------------------------------------------------------------
function InitAccessories()
{
	//načtení všech komponent TAccessory
	//var temp = document.getElementsByTagName("accessory");
	var temp = GetElements("accessory");
	for (var i = 0; i < temp.length; i ++) {
		document.accessories[document.accessories.length] = new TAccessory(temp[i]);
	}
}

//]]>

