
// --------------------------------------------treeview class-------------------------
var grarray = new Array;

function Treeview(htmlContainerDivElement,destinationList,dirimagens)
{			
	this._containerDivElementID=htmlContainerDivElement.id;
	this.Init(htmlContainerDivElement,destinationList,dirimagens);
}

function GetIndice(lista,id)
{
	var index=-1;
	for(var i=0;i< lista.length; i++)
	{
		if(lista[i][4] == id)
		{
			index = i;
			break;
		}
	}
	return index;
}

Treeview.prototype.Init = function(htmlContainerDivElement, destinationList,dirimagens)
{	
	var children =-1;
	var xparent = -1;
	var lastid = -1;
	
	for(var i=0;i< destinationList.length; i++)
	{
		if(destinationList[i][2] == 0)
		{
			grarray[i] = new Array;
			grarray[i]['caption'] = destinationList[i][1];
			if(destinationList[i][3] == 0)
				grarray[i]['isChecked'] = 0;
			else
				grarray[i]['isChecked'] = 2;
			grarray[i]['isOpen'] = false;
			grarray[i]['id'] = destinationList[i][4];
		}
		else
		{
			if(destinationList[i][2] != lastid)
				xparent = GetIndice(destinationList,destinationList[i][2]);
			if(xparent != -1 && (lastid == -1 || lastid != destinationList[i][2]))
			{
				grarray[xparent]['children'] = new Array;
				children = -1;
			}
			lastid =destinationList[i][2];
			children = children +1;
			grarray[xparent]['children'][children] = new Array;
			grarray[xparent]['children'][children]['caption'] = destinationList[i][1];
			if(destinationList[i][3] == 0)
				grarray[xparent]['children'][children]['isChecked'] = 0;
			else
				grarray[xparent]['children'][children]['isChecked'] = 2;
			
			grarray[xparent]['children'][children]['id'] = destinationList[i][4];
		}
	}

}
