Xeon.Core.namespace('Calculator');

Calculator.SimilarDepositsRenderer = function(placeHolderId, tableId) {
	this.tableElement = document.getElementById(tableId);
	this.tBobyElement = null;
	this.placeHolder = document.getElementById(placeHolderId);
	
	for(var i = 0; i < this.tableElement.childNodes.length; i++) {
		if (this.tableElement.childNodes[i].nodeName == 'TBODY') {
			this.tBobyElement = this.tableElement.childNodes[i];
			break;
		}
	}
	
	this.addRow = function(id, cells, callback)
	{
		var oRow = document.createElement('tr');		

		var oCell = document.createElement('td');
		oCell.appendChild(document.createTextNode(cells[0]));		
		oRow.appendChild(oCell);
		
		var oCell = document.createElement('td');
		var oDiv = document.createElement('div');
		oDiv.id = 'd_deposit_' + id;
		oDiv.className = 'link';
		Xeon.Event.observe(oDiv, 'click', callback);
		oDiv.appendChild(document.createTextNode(cells[1]));
		oCell.appendChild(oDiv);
		oRow.appendChild(oCell);
		
		for(var i = 2; i < cells.length; i++) {
			var oCell = document.createElement('td');
			oCell.appendChild(document.createTextNode(cells[i]));
			oRow.appendChild(oCell);
		}

		this.tBobyElement.appendChild(oRow);
	};
	
	this.show = function()
	{
		if (this.placeHolder.style.display == 'none') {
			this.placeHolder.style.display = 'block';
		}
	};

	this.hide = function()
	{
		if (this.placeHolder.style.display != 'none') {
			this.placeHolder.style.display = 'none';
		}
	};
	
	this.clearBody = function()	{		
		var cntRows = this.tBobyElement.childNodes.length;
		var skipHeader = false;
		for(var i = 0 ; i < cntRows; i++) {
			if (this.tBobyElement.childNodes[i].nodeName == 'TR') {
				skipHeader = i;
				break;
			}
		}
		for(var i = cntRows - 1; i > skipHeader; i--) {
			this.tBobyElement.removeChild(this.tBobyElement.childNodes[i]);
		}
	}
}
