//--------------------------------------------------------
//Class Node
function Node (parent,userObject)
	{
	this.parent=parent;
	this.index=null;
	this.userObject=userObject;
	this.collapsed = true;
	this.expanded = false;
	
	this.childNodes=new Array();
	}

Node.prototype.addNode = function (node){
	this.childNodes[this.childNodes.length] = node;
}

Node.prototype.getNode = function (criteria,optParam) {
	if (this.userObject && this.userObject.equals(criteria,optParam))
		return this;
	if (this.childNodes.length == 0)
		return false;
	else {
		for (var i=0;i<this.childNodes.length;i++) {
			var node = this.childNodes[i].getNode(criteria,optParam);
			if (node != false)
				return node;
		}
		return false;
	}	
}

Node.prototype.collapse = function(children) {
	this.expanded = false;
	if (children) {
		for (var i=0;i<this.childNodes.lenght;i++)
			this.childNodes[i].collapse(children);
	}
}

Node.prototype.expand = function(children) {
	this.expanded = true;
	if (children) {
		for (var i=0;i<this.childNodes.length;i++)
			this.childNodes[i].expand(children);
	}
}

Node.prototype.callOnUserObject = function (funcID,param) {
	this.userObject.exec(funcID,param);
	if (param["callOnChildren"]) {
		param["childCall"] = true;
		for (var i=0;i<this.childNodes.length;i++)
			this.childNodes[i].callOnUserObject(funcID,param);
	}
}

	
//--------------------------------------------------------
//Class Tree
function Tree (root) {
	this.root = root;
}

Tree.prototype.getNode = function(criteria,optParam) {
	if (this.root == null)
		return false;
	else
		return this.root.getNode(criteria,optParam);
}


//------------------------------------------------------
//Class Category
function Category(name,ukatnr,posnr,script,ordernr,type,allowed,password)
	{
	this.name=name;
	this.ukatnr=ukatnr;
	this.posnr = posnr;
	this.script=script;
	this.ordernr=new String(ordernr);
	this.type=type;
	this.allowed=allowed;
	this.password=password;
	this.oldOrdernr=null;
	this.modified = false;
	this.changes = 0;
	}

Category.prototype.equals = function (compare,optParam) {
	if (optParam)
		return this[optParam] == compare;
	else
		return (this.ordernr==compare);
}

Category.prototype.changeOrdernr = function (param)
	{
	var newOrdernr = new String(param.ordernr);
	if (!this.modified)
		this.oldOrdernr=this.ordernr;
	if (newOrdernr.length < this.ordernr.length)
		this.ordernr=newOrdernr+this.ordernr.substring(newOrdernr.length,this.ordernr.length);
	else
		this.ordernr=newOrdernr;
	this.modified = true;
	}

Category.prototype.rename = function (param) {
	var newName = param.name;
	this.name = newName;
}

Category.prototype.changePwd = function (param) {
	this.password = param.password;
	this.modified = true;
}

Category.prototype.exec = function (id,param) {
	eval("this."+id+"(param);");
}

