function ViewRow(){
	this.container = null;
	this.items = new Array();
	this.styles = new Array();
	this.key = -1;
	this.nestedCategories;
	this.expandable = false;
	this.expanded = true;
	this.containingRow = null;
	this.toggleFlag = false;
	this.rows = new Array();
}

ViewRow.prototype.buildCategory = ViewTable.prototype.buildCategory;

ViewRow.prototype.buildNestedRows = ViewTable.prototype.buildNestedRows;

ViewRow.prototype.appendRow = ViewTable.prototype.appendRow;

ViewRow.prototype.collapseAll = ViewTable.prototype.collapseAll;

ViewRow.prototype.init = function(cRow, tag, data){
	var self = this;
	this.containingRow = cRow;
	this.container = tag;
	this.items = data.slice(0, data.length);
	this.container.innerHTML = getTableRow(this.items, this.key);
	this.container.onclick = function(){self.toggle();};
	
	function getTableRow(data, key){
		var cells = "";
		if(key == -1){
			cells = "<table class='jsViewTable'><tr><td>&nbsp;</td>";
			for(var i=0;i<data.length;i++){
				if(i < self.nestedCategories){
					cells += "<td>&nbsp;</td>";
				}else{
					cells += "<td>" + data[i] + "</td>";
				}
			}
			cells += "</tr></table>";
		}else{
			cells = "<table class='jsViewTable'><tr><td>+</td>";
			for(var i=0;i<data.length;i++){
				if(i == key || i >= self.nestedCategories){
					cells += "<td>" + data[i] + "</td>";
				}else{
					cells += "<td>&nbsp;</td>";
				}
			}
			cells += "</tr></table>";
		}
		return cells;
	}
};

ViewRow.prototype.expand = function(){
	var i;
	if(this.expandable == true){
		for(i=0;i < this.rows.length; i++){
			this.rows[i].show();
		}
		this.expanded = true;
		this.container.getElementsByTagName("td")[0].innerHTML = "-";
	}
};

ViewRow.prototype.collapse = function(){
	var i;
	if(this.expandable == true){
		for(i=0;i < this.rows.length; i++){
			this.rows[i].hide();
		}
		this.expanded = false;
		this.container.getElementsByTagName("td")[0].innerHTML = "+";
	}
};

ViewRow.prototype.toggle = function(){
	if(this.toggleFlag){
		this.clearToggleFlag();
	}else{
		if(this.expanded){
			this.collapse();
		}else{
			this.expand();
		}
		this.setToggleFlag();
	}
};

ViewRow.prototype.clearToggleFlag = function(){
	this.toggleFlag = false;
};

ViewRow.prototype.setToggleFlag = function(){
	
	setContainingRowToggleFlag(this.containingRow);
	
	function setContainingRowToggleFlag(row){
		if(row.clearToggleFlag){
			row.toggleFlag = true;
			setContainingRowToggleFlag(row.containingRow);
		}
	}
};

ViewRow.prototype.show = function(){
	this.container.style.display = "block";
};

ViewRow.prototype.hide = function(){
	this.container.style.display = "none";
};


