/**
 * @author Alex van Niel
 * 
 * Node class version 1.0.2
 * 
 */
function clsNode(p_sName,p_oData,p_nId){

	if(p_nId === null || isNaN(p_nId)){
		var oDate = new Date();
		this.m_nId = oDate.getTime() + Math.round(1000*Math.random());
	} else {
		this.m_nId = p_nId;
	}

	this.m_sName = p_sName;
	this.m_oData = p_oData;
	this.m_aChildren = new Array();
	this.m_nLength = this.m_aChildren.length;
	this.m_nCurrentChildIndex = null;
}

clsNode.prototype.hasChildren = function(p_bBuffered){
	if(p_bBuffered){
		return (this.m_nLength);
	} else {
		return (this.m_aChildren.length);
	}
}

clsNode.prototype.firstChild = function(){
	this.m_nCurrentChildIndex = 0;
	return this.m_aChildren[0];
}

clsNode.prototype.lastChild = function(){
	this.m_nCurrentChildIndex = this.m_aChildren.length - 1;
	return this.m_aChildren[(this.m_aChildren.length-1)];
}

clsNode.prototype.nextChild = function(){
	this.m_nCurrentChildIndex++;
	return this.m_aChildren[this.m_nCurrentChildIndex];
}

clsNode.prototype.currentChild = function(){
	return this.m_aChildren[this.m_nCurrentChildIndex];
}

clsNode.prototype.getChild = function(p_nIndex){
	return this.m_aChildren[p_nIndex];
}

clsNode.prototype.getNodeId = function(){
	return this.m_nId;
}

clsNode.prototype.getNodeName = function(){
	return this.m_sName;
}

clsNode.prototype.getNodeData = function(){
	return this.m_oData;
}

clsNode.prototype.setNodeId = function(p_nId){
	var bResult = false;

	if(p_nId !== null && !isNaN(p_nId)){
		this.m_nId = p_nId;
		bResult = true;
	}
	return bResult;
}

clsNode.prototype.setNodeName = function(p_sName){
	this.m_sName = p_sName;
}

clsNode.prototype.setNodeData = function(p_oData){
	this.m_oData = p_oData;
}

clsNode.prototype.setNodeType = function(p_sType){
	this.m_sType = p_sType;
}

clsNode.prototype.appendChild = function(p_oChild){
	this.m_aChildren[this.m_aChildren.length] = p_oChild;
	this.m_nLength = this.m_aChildren.length;
	this.m_nCurrentChildIndex = this.m_nLength - 1;
}

clsNode.prototype.removeChild = function(p_oChild){
	var nLength = this.m_aChildren.length;
	var bFound = false;
	var nIndex = null;

	if(typeof(p_oChild) == "object"){
		for(var nI = 0;(nI < nLength) && !bFound; nI++){
			if(this.m_aChildren[nI].m_nId == p_oChild.m_nId){
				nIndex = nI;
				bFound = true;
			}
		}
	} else {
		if(p_oChild < nLength){
			nIndex = p_oChild;
		}
	}

	if(nIndex != null){
		this.m_aChildren.splice(nIndex,1);
		this.m_nLength = this.m_aChildren.length;
		this.m_nCurrentChildIndex = this.m_nLength - 1;
	}
}

