/* 
 This file was generated by Dashcode.  
 You may edit this file to customize your widget or web page 
 according to the license.txt file included in the project.
 */

var listController = {
    // This object acts as a controller for the list UI.
    // It implements the dataSource methods for the list.
    
    // This dataSource uses fixed data for the content of the list.  Some applications may have such static data for their lists, others will want to replace this with information fetched remotely via XMLHttpRequest.
    _rowData: [
        "Randstad",
        "Amsterdam",
        "Rotterdam",
        "Den Haag",
        "Utrecht",
        "Eindhoven",
        "Noord",
        "Oost",
        "Zuid",
        "Noord-Oost",
        "Noord-West",
        "Zuid-Oost",
        "Zuid-West",
        "België",
        "Ruhrgebied",
        "Aken/Keulen",
        "Munster/Osnabrück",
    ],
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return this._rowData.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.rowTitle) {
            templateElements.rowTitle.innerText = this._rowData[rowIndex];
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function() {
            var resort = self._rowData[rowIndex];
            detailController.setRepresentedObject(resort);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevel'), resort);
        };
        rowElement.onclick = handler;
    }
};

var detailController = {
    // This object acts as a controller for the detail UI.
    
    setRepresentedObject: function(representedObject) {
        // To start, the represented object of our detail controller is simply a string, the title of the list row that the user chose.  You may want to make the represented object any kind of object when you customize the template.
        this._representedObject = representedObject;

        var detailBox = document.getElementById('detailBox');
        detailBox.innerHTML = '' ;       

        var regio = representedObject.toLowerCase();
        
        var url = 'http://www.jordgubb.nl/fileradar/bin/999.php?regio='+ regio + '&width=320' ;
        var xmlhttp = new XMLHttpRequest();

        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = stateChange;
            xmlhttp.open('GET', url, true);
            xmlhttp.send(null);
        } else {
            alert('Your browser does not support XMLHTTP.'); 
        }

        function stateChange() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var detailBox = document.getElementById('detailBox');
                    detailBox.innerHTML = xmlhttp.responseText ;                  
                } else {
                    alert('Problem retrieving XML data.');
                }
            }
        }         
    }
};

//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
    dashcode.setupParts();
}

