function createAuditDocList(XMLAuditDocs)
{
// The Audit Doc object class
function CAuditDoc(UNID, date, time, meridian)
{
this.UNID = UNID;
this.date = date;
this.time = time;
this.meridian = meridian;
}
// The "end of array" checking function for iterations
function endOfLoop(index, array)
{
return (index == array.length);
}
// Define variables
var rowID = '';
var rowDate = '';
var auditList = '';
var tempAuditDocObject = null;
var rawDocArray = new Array();
var finalDocArray = new Array();
// Loops through the XML Data, building an audit document object for each "row"
for (var i = 0; i < XMLAuditDocs.length; i++)
{
rowID = XMLAuditDocs.item(i).getAttribute("unid");
rowDate = getViewRowValues(XMLAuditDocs[i])[1];
tempAuditDocObject = new CAuditDoc(rowID,
rowDate.substr(0, 10),
rowDate.substr(11, 8),
rowDate.substr(20) );
rawDocArray.push(tempAuditDocObject);
}
/********************
* CAUTION: SORT AREA
********************/
// Define sorting variables
var lastDate = rawDocArray[0].date;
var lastMeridian = rawDocArray[0].meridian;
var meridianSwitch = false;
var dayDocArray = new Array();
var currentDate = '';
for (var j = 0; j < rawDocArray.length + 1; j++)
{
// If this isn't the last iteration, set the currentDate variable;
// If it is, then set the currentDate to null to force the last sort
currentDate = (!endOfLoop(j, rawDocArray)) ? rawDocArray[j].date : null ;
// If the current doc's date is different from the last one checked,
// process the last day's docs and then reset the sort;
// this also runs automatically on the very last iteration
if (currentDate != lastDate)
{
// Check to see if a sort is in order, and if so, do it
if (meridianSwitch)
while (dayDocArray[0].meridian != 'PM')
dayDocArray.push(dayDocArray.shift());
// Concat dayDocArray[] onto the end of finalDocArray[]
finalDocArray = finalDocArray.concat(dayDocArray);
// If this is not the last iteration, reset the sort variables
if ( !endOfLoop(j, rawDocArray) )
{
dayDocArray = new Array();
lastDate = rawDocArray[j].date;
lastMeridian = rawDocArray[j].meridian;
meridianSwitch = false;
}
}
// If this isn't the last iteration, then push the current rawDocArray[]
// onto the current dayDocArray[]
if ( !endOfLoop(j, rawDocArray) )
{
if ( rawDocArray[j].meridian != lastMeridian )
{
lastMeridian = rawDocArray[j].meridian;
meridianSwitch = true;
}
dayDocArray.push(rawDocArray[j]);
}
} // end for
/********************
* PROCEED NORMALLY
********************/
// Begin constructing HTML select object
auditList = 'Choose an audit trail... ';
auditList += '';
document.getElementById("XMLArea").innerHTML = auditList;
This function accepts an XML object of the following (repeated, of course):
[unid] mm/dd/yyyy hh:mm:ss AM|PM
Each viewentry represents a response document. The response's UNID is the "unid" attribute inside the viewentry tag -- the parent document's UNID is the first "column" of XML data. In this model, a parent document can have many response documents.
By the way, for anybody trying to post code online, "<span style="margin-left: 50px"></span>" works great for simulating tab stops!

