// Generates the footer of the dynamic datagrid view (generated by JQuery DataTable) 
function generateTableFooter(nFoot, aasData, iStart, iEnd, aiDisplay ) {
	// Will be set as true if a sum is computed
	var hasSums = false;
	
	if (aiDisplay.length > 0) {
    	// Table which stores sums
    	var result = [];
    	var ths = jq('#dynamictable > tbody > tr:first-child > td').each(function (index, element) {
    		if (jq(element).hasClass('displaysum'))
				result[index] = 0;
    		else
    			result[index] = NaN;
    	});

    	// Sums computation of displayed data
    	for (var i = 0; i < aiDisplay.length; i++) {
			for (var j = 0; j <result.length; j++) {
				if (!isNaN(result[j]))
					result[j] += Number(aasData[aiDisplay[i]][j]);
			}
		}
		
    	// Display of sums
    	for (var i = 0; i < result.length; i++) {
        	// Replace NaN by ""
        	var colResult = result[i];
        	if (isNaN(colResult))
	        	colResult = "";
        	else
        		hasSums = true;
        	jq('th', nFoot).eq(i).text(colResult);
		}
	}
	
	// Display the footer if there is sums to display
	if (!hasSums)
    	jq(nFoot).hide();
	else
		jq(nFoot).show();
}

// Returns a string storing every selected documents, separated by '@'
function dynamicview_selecteddocuments() {
	var docs = jq('input:checked', oDynamicTable.fnGetNodes()).toArray();
	var docids = "";
	for (var i = 0; i < docs.length; i++)
		docids += docs[i].value + '@';
	
	return docids;
}
