//oggetto apaTreeView
function aptTreeView(id, rootid, styleHRef, styleHRefSel, imgNodeOpen, imgNodeClosed, imgNodeVertOpen, imgNodeVertClosed, imgHighLight)
{
	// proprietà
	this.id = id;
	this.rootid = rootid;
	this.imgNodeOpen = imgNodeOpen;
	this.imgNodeClosed = imgNodeClosed;
	this.imgNodeVertOpen = imgNodeVertOpen;
	this.imgNodeVertClosed = imgNodeVertClosed;
	this.imgHighLight = imgHighLight;
	this.disable = false;
	this.jsid = 'apa_tv_' + id + '_';
	//riferimento all'array imagelist
	eval('this.il = apa_tv_' + id + '_il;');
	this.currsel = 0;
	this.styleHRef = styleHRef;
	this.styleHRefSel = styleHRefSel;
	this.parent = false;

	//eventi
	this.OnNodeClick = false;
	this.OnLabelClick = false;
	this.OnLabelDblClick = false;
	
	
	// espande un nodo
	this.Expand = function(node_id)
	{
		if (this.disable || apa.working) return;
		var n = node_id;
		var d, i, p;

		// risale all'indietro...
		while (1) {
			p = document.getElementById(this.jsid + 'p' + n);
			if (p.value == this.rootid) break;
			n = p.value;
			d = document.getElementById(this.jsid + 'c' + n);
			i = document.getElementById(this.jsid + 'i' + n);
			d.style.display = 'block';
			//recupera da "alt" e "name" gli indici imagelist closed e open
			if (i) i.src = this.il[(i.src == this.il[i.alt]) ? i.name: i.alt];
		}
	
		//per ultimo apre se stesso
		this._labelclick(node_id);
	}

	
	// clic sul nodo (+ o -)
	this._nodeclick = function(node_id)
	{
		if (this.disable || apa.working) return;
		// trigger evento
		if (this.OnNodeClick && !this.OnNodeClick(node_id, this.parent)) return;
		var d = document.getElementById(this.jsid + 'c' + node_id);
		var i = document.getElementById(this.jsid + 'i' + node_id);
		if (d.style.display == 'none') {
			d.style.display = 'block';
			if (i) i.src = this.il[i.name];
		} else {
			d.style.display = 'none';
			if (i) i.src = this.il[i.alt];
		}
	}

	// clic sulla categoria
	this._labelclick = function(node_id)
	{
		if (this.disable || apa.working) return;
		// trigger evento
		if (this.OnLabelClick && !this.OnLabelClick(node_id, this.parent)) return;
		var oldlab = document.getElementById(this.jsid + 'l' + this.currsel);
		var lab = document.getElementById(this.jsid + 'l' + node_id);
		if (oldlab) oldlab.className = this.styleHRef;
		if (lab) lab.className = this.styleHRefSel;
		this.currsel = node_id;
	}

	// doppio clic sulla categoria
	this._labeldblclick = function(node_id)
	{
		if (this.disable || apa.working) return;
		// trigger evento
		if (this.OnLabelDblClick && !this.OnLabelDblClick(node_id, this.parent)) return;
		this.Expand(node_id);
	}

	// sono col mouse sulla label
	this._onmouseover = function(td)
	{
		if (this.disable || apa.working) return;
		td.style.backgroundImage = 'url(' + this.il[this.imgHighLight] + ')';
		td.style.borderTop = '1px solid #DDDDDD';
		td.style.borderLeft = '1px solid #DDDDDD';
		td.style.borderBottom = '1px solid #909090';
		td.style.borderRight = '1px solid #909090';
	}
	
	// esco col mouse dalla label
	this._onmouseout = function(td)
	{
		if (this.disable || apa.working) return;
		td.style.backgroundImage = '';
		td.style.borderTop = '';
		td.style.borderLeft = '';
		td.style.borderBottom = '';
		td.style.borderRight = '';
	}
}

