15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)<html> 
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  <head> 
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> 
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    <script language="javascript">
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Split a string in 2 parts. The first is the leading number, if any,
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // the second is the string following the numbers.
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function splitNum(s) {
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var results = new Array();
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        results[0] = 'None';
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        for (var i = 0; i < s.length; i++) {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var substr = s.substr(0, i+1)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (isNaN(substr)) {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // Not a number anymore.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            results[1] = s.substr(i)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            break;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          } else {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // This is a number. update the results.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            results[0] = parseFloat(substr);
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return results;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Compare 2 strings using a custom alphanumerical algorithm.
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // This is similar to a normal string sort, except that we sort
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // first by leading digits, if any.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // For example:
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      //  100hello > 2goodbye
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Numbers anywhere else in the string are compared using the normal
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // sort algorithm.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function alphanumCompare(a, b) {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var parsedA = splitNum(a);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var parsedB = splitNum(b);
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var numA = parsedA[0];
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var numB = parsedB[0];
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var strA = parsedA[1];
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var strB = parsedB[1];
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (isNaN(numA) == false && isNaN(numB) == false) {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // They both start with numbers.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (numA < numB) return -1;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (numA > numB) return 1;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Identical. Fallback to string.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          return (strA < strB) ? -1 : (strA > strB ? 1 : 0)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // If only one starts with a number, we start with that one as
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // the lowest.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (isNaN(numA) == false) return -1
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (isNaN(numB) == false) return 1
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // They are both strings. 
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return (a < b) ? -1 : (a > b ? 1 : 0)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    </script>
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  </head> 
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  <body> 
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    <script type="application/javascript"> 
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      String.prototype.startsWith = function(str) {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return (this.match('^' + str) == str)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Helper function to retrieve the value of a GET query parameter.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Greatly inspired from http://alturl.com/8rj7a
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function getParameter(parameterName) {
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Add '=' to the parameter name (i.e. parameterName=value)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var parameterName = parameterName + '=';
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var queryString = window.location.search.substring(1);
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (queryString.length <= 0) {
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          return '';
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Find the beginning of the string
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        begin = queryString.indexOf(parameterName);
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // If the parameter name is not found, skip it, otherwise return the
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // value.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (begin == -1) {
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          return '';
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Add the length (integer) to the beginning.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        begin += parameterName.length;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Multiple parameters are separated by the '&' sign.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        end = queryString.indexOf ('&', begin);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (end == -1) {
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          end = queryString.length;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Return the string.
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return unescape(queryString.substring(begin, end));
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Given a tag and a node, returns the value for this tag on this node.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function getNodeValue(node, tag) {
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return node.getElementsByTagName(tag)[0].firstChild.nodeValue;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Displays the directory listing given the XML and path.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function displayList(xmlstring, root, path, pathRoot) {
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Display the header
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<h1>Index of /' + path + '</h1>');
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Start the table for the results.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<table style="border-spacing:15px 0px;">');
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var sortOrder = getParameter('sort');
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var sortLink = location.pathname + '?path=' + path;
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (sortOrder != 'desc') {
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          sortLink += '&sort=desc';
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Display the table header.
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<tr><th><img src="' + root + pathRoot +
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       'icons/blank.gif" alt="[ICO]"></th>');
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<th><a href="' + sortLink + '">Name</a></th>');
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<th>Last modified</th>');
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<th>Size</th>');
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<th>Storage Class</th>');
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<th>ETag</th></tr>');
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<tr><th colspan="6"><hr></th></tr>');
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Display the 'go back' button.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (path != '') {
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var backpath = location.pathname;
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // If there is more than one section delimited by '/' in the current
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // path we truncate the last section and append the rest to backpath.
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var delimiter = path.lastIndexOf('/');
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (delimiter >= 0) {
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            delimiter = path.substr(0, delimiter).lastIndexOf('/');
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            if (delimiter >= 0) {
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              backpath += '?path=';
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              backpath += path.substr(0, delimiter+1);
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            }
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<tr><td valign="top"><img src="' + root + pathRoot +
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         'icons/back.gif" alt="[DIR]"></td>');
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td><a href="');
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write(backpath);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('">Parent Directory</a></td>');
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td>&nbsp;</td>');
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">  - </td></tr>'); 
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Set up the variables.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var directories = new Array();
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var files = new Array();
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        for (var iter = 0; iter < xmlstrings.length; iter++) {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var xmlstring = xmlstrings[iter];
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Parse the XML output.
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var parser = new DOMParser();
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var xmlDoc = parser.parseFromString(xmlstring, 'text/xml');
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Get the main element.
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var results = xmlDoc.getElementsByTagName('ListBucketResult');
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Get all the directories.
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var prefixes = results[0].getElementsByTagName('CommonPrefixes');
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          for (var i = 0; i < prefixes.length; i++) {
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var prefix = getNodeValue(prefixes[i], 'Prefix');
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            directories.push(prefix.substr(path.length));
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Get all the files.
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var contents = results[0].getElementsByTagName('Contents');
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          for (var i = 0; i < contents.length; i++) {
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var obj = new Object();
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            obj.keyName = getNodeValue(contents[i], 'Key');
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            obj.lastModified = getNodeValue(contents[i], 'LastModified');
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            obj.eTag = getNodeValue(contents[i], 'ETag');
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            obj.size = getNodeValue(contents[i], 'Size');
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            files.push(obj);
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        files.sort(alphanumCompare);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        directories.sort(alphanumCompare);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Reverse the list for a descending sort.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (sortOrder == 'desc') {
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          files.reverse();
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          directories.reverse();
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Display the directories.
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        for (var i = 0; i < directories.length; i++) {
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var lnk = location.pathname.substr(0, location.pathname.indexOf('?'));
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          lnk += '?path=' + path + directories[i];
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<tr>');
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td valign="top"><img src="' + root + pathRoot +
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         'icons/folder.gif" alt="[DIR]"></td>');
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td><a href="' + lnk + '">' +
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         directories[i].split('/')[0] + '</a></td>');
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">-</td>');
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">-</td>');
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">-</td>');
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">-</td>');
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('</tr>');
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Display the files.
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        for (var i = 0; i < files.length; i++) {
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var link = root + files[i].keyName;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var filename = files[i].keyName.substr(path.length);
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var size = files[i].size / 1024 / 1024;
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          var lastModified = files[i].lastModified.replace('T', ' ');
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          lastModified = lastModified.substr(0, lastModified.indexOf('.'));
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Remove the entries we don't want to show.
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (filename == '') {
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            continue;
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (filename.indexOf('$folder$') >= 0) {
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            continue;
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          // Display the row.
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<tr>');
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td valign="top"><img src="' + root + pathRoot +
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         'icons/binary.gif" alt="[DIR]"></td>');
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td><a href="' + link + '">' + filename +
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         '</a></td>');
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">' + lastModified + '</td>');
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right">' + size.toFixed(2) + 'MB</td>');
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('<td align="right"><pre>' +
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         files[i].eTag.split('"')[1] + '</pre></td>');
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          document.write('</tr>');
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // Close the table.
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('<tr><th colspan="6"><hr></th></tr>');
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        document.write('</table>');
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      var xmlstrings = new Array();
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      function fetchAndDisplay(marker) {
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var path = getParameter('path');
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var lastSlash = location.pathname.lastIndexOf("/");
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var filename = location.pathname.substring(lastSlash + 1);
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var firstSlash = location.pathname.indexOf("/", 1);
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var root = location.pathname.substring(0, firstSlash + 1);
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var pathRoot = location.pathname.substring(firstSlash + 1,
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   lastSlash + 1);
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (!path) {
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          path = location.pathname.substring(firstSlash + 1, lastSlash + 1);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var markerParam = '';
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (marker != '') {
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          markerParam = '&marker=' + marker;
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        var http = new XMLHttpRequest();
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        http.open('GET',
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  root + '?delimiter=/&prefix=' + path + markerParam,
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  true);
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        http.onreadystatechange = useHttpResponse;
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        http.send(null);
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        function useHttpResponse() {
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          if (http.readyState == 4) {
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var xmlstring = http.responseText;
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            xmlstrings.push(xmlstring);
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // Check if the data is truncated. if so, we need to request the
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // rest.
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var parser = new DOMParser();
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var xmlDoc = parser.parseFromString(xmlstring, 'text/xml');
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // Get the main element.
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var results = xmlDoc.getElementsByTagName('ListBucketResult');
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            // Get IsTruncated.
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var truncated = getNodeValue(results[0], 'IsTruncated');
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            var nextMarker = '';
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            if (truncated == 'true') {
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              nextMarker = getNodeValue(results[0], 'NextMarker');
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              fetchAndDisplay(nextMarker);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            } else {
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              displayList(xmlstrings, root, path, pathRoot);
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            }
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          }
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      fetchAndDisplay('');
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    </script> 
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  </body> 
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)</html>
298