
/*
 * Depends on table_data_base.js
 */

function TableDataAccount(menberEnc, startDate, endDate, headerClassNormal, headerClassUp, headerClassDown, pNameSpace, numPages, locale) {
	
	this.menberEnc = menberEnc;
	this.page = 1;
	this.order = 0;
	this.col = 0;
	this.startDate = startDate;
	this.endDate = endDate;
	
	this.headerClassNormal = headerClassNormal;
	this.headerClassUp = headerClassUp;
	this.headerClassDown = headerClassDown;
		
	this.pNameSpace = pNameSpace;
	this.numPages = numPages;
	this.locale = locale;

	this.numberOfColumns = 4;
	
	this.submitDates = function submitDates() {
		this.order = 0;
		this.col = 0;
		
		this.startDate = $("#" + this.pNameSpace + "SDDay").val() + "/" + $("#" + this.pNameSpace + "SDMonth").val() + "/" + $("#" + this.pNameSpace + "SDYear").val();
		this.endDate = $("#" + this.pNameSpace + "EDDay").val() + "/" + $("#" + this.pNameSpace + "EDMonth").val() + "/" + $("#" + this.pNameSpace + "EDYear").val();
		
		this.getRemoteListDataBean(1);
	}	
	
	this.getRemoteListDataBean = function getRemoteListDataBean(page) {
	    
		this.addLoading(this.pNameSpace + "Trans", this.numberOfColumns);	    
		var parent = this;
		var callbackProxy = function(dataFromServer) {
			callbackGetRemoteListDataBean(dataFromServer, page, parent);				
		};
		var exceptionHandlerProxy = function(exceptionMessage, exception) {
			callbackExceptionGetRemoteListDataBean(exceptionMessage, exception, parent, parent.numberOfColumns);				
		};
		
	    var callMetaData = {
	    	callback: callbackProxy,		  		  
		  	exceptionHandler: exceptionHandlerProxy
		};
		
	    AccountServiceRemoteService.getRemoteAccountListDataBean(this.menberEnc, this.startDate, this.endDate, page, this.order, this.col, this.locale, callMetaData);
	    
	}
	
	this.fillTable = function fillTable(resp) {
		var val;
		
		var cellFuncs = [
			function(data) {return data.dateToDisplay;},
		  	function(data) {return data.description;},
		  	function(data) {data.milesToDisplay.match("^-") ? val = data.milesToDisplay : val = ""; return val;},
		  	function(data) {!data.milesToDisplay.match("^-") ? val = "+" + data.milesToDisplay : val = ""; return val;}
		];	
		
		
		DWRUtil.removeAllRows(this.pNameSpace + "Trans");
		DWRUtil.addRows(this.pNameSpace + "Trans", resp.data, cellFuncs, 
		{ 
			rowCreator:function(options) {
			    var row = document.createElement("tr");			    
			    row.className = "tableListNormalTr";
			    return row;
		  	},
			cellCreator:function(options) {
			    var td = document.createElement("td");
			    var index = options.cellNum;
			    
			    switch(index) {
					case 0: td.className = "tableListNormal"; break;
					case 1: td.className = "tableListNormal"; break;
					case 2: td.className = "tableListMilesBold"; break;
					case 3: td.className = "tableListMilesBold"; break;
					default: td.className = "tableListNormal";
				}			   
			    return td;
			},
			escapeHtml:false 
		});		
	}
	
	this.orderListDataBean = orderListDataBean;
	this.getErrorHtml = getErrorHtml;
	this.addLoading = addLoading;
	this.backPaginatedPage = backPaginatedPage;
	this.nextPaginatedPage = nextPaginatedPage;
	this.changePaginatedPage = changePaginatedPage;
	this.updatePaginationTable = updatePaginationTable;			
}