// To be used to list the files in the RB, DB, and any other location as needed.
// will redraw the HTML table

function listfiles(scriptname, method, system, id, listname, htmltableid, useuid, urllocation)
{
//alert("listfiles table: " + htmltableid);
	DWREngine._execute(scriptname, null, method, {'fk_sid':system, 'fk_id':id, 'useUID':useuid, 'listname':listname, 'htmltableid':htmltableid, 'urllocation':urllocation}, showFilesList);	
}


function ajaxdeleteFile(scriptname, method, fileID, system, id, listname, htmltableid, useuid, urllocation)
{
	var retvalues = new Object();
	retvalues['scriptname'] = scriptname;
	retvalues['method'] = method;
	retvalues['fileid'] = fileID;
	retvalues['system'] = system;
	retvalues['id'] = id;
	retvalues['listname'] = listname;
	retvalues['htmltableid'] = htmltableid;
	retvalues['useuid'] = useuid;
	retvalues['urllocation'] = urllocation;
//alert ("delete file: " + urllocation);
	DWREngine._execute(scriptname, null, method, {'fileId':fileID, 'callBackParams':retvalues}, remvoveRow);
}

function remvoveRow(retvar)
{
//alert ("retvar.urllocation: " + retvar.urllocation);
 	var method = "getFileListAjax"; // need to reset the method. deletefile is passed in.
					// the rest of the values can be used from the retvar returned after ajaxdeleteFile is called
	listfiles(retvar.scriptname, method, retvar.system, retvar.id, retvar.listname, retvar.htmltableid, 0, retvar.urllocation);

}


function showFilesList(retvar)
{ //RETVAR sent from the wrapper
//alert("hello");
//alert("id: " + retvar.htmltableid);
	var desc1 = function(thisRow) { return thisRow.desc1; }
	var datecreated = function(thisRow) { return thisRow.datecreated; }
	var createdby = function(thisRow) { return thisRow.createdby; }
	var id = function(thisRow) { return thisRow.id; }
	var mimetype = function(thisRow) { return thisRow.mimetype; }
	var filetitle = function(thisRow) { return thisRow.filetitle; }
	//var timecreated = function(thisRow) {return thisRow.timecreated; }
	var delButton = function(thisRow) { return thisRow.delbutton; }
	var typeDesc = function(thisRow) { return thisRow.description; }
//alert("remove rows");
	DWRUtil.removeAllRows(retvar.htmltableid);

	DWRUtil.addRows(retvar.htmltableid, retvar.thequery, [filetitle, desc1, typeDesc, createdby, datecreated, delButton], null);
	//DWRUtil.addRows(retvar.htmltableid, retvar.thequery, [filetitle, desc1, typeDesc, createdby, datecreated], null);

	// loop over the table changing the row colors appropriately.
	altTblClrs(retvar.htmltableid, null, null);  // altTblClrs no longer uses the 2nd and 3rd parameters
}
