/*
 *  $Id: app.versions.js 8 2010-04-15 19:24:02Z stuart $
 *  
 *  dev.stuconnolly.com
 *  Open Source Software Development
 *
 *  Copyright (c) 2010 Stuart Connolly. All rights reserved.
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Updates the available versions for the selected application.
 */
function updateApplicationVersions()
{
    var form = document.forms['feedbackform'];
    
    var app = form.application.options[form.application.selectedIndex].value;
    
    var versionsScriptURL = '/scripts/app.versions.php?app=' + app;
    
    var request = createXMLHTTPRequest();
    
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            if (request.status == 200) {		
                var versions = request.responseXML.getElementsByTagName('version');
                
                // Remove all elements from drop down
                while (form.version.length) 
                {
                    form.version.remove(0);
                }
                           
                // Add new elements
                for (var i = 0; i < versions.length; i++) 
                {                                                        
                    var versionNum = versions[i].childNodes[1].childNodes[0].nodeValue;
                                   
                    var newOption = document.createElement('option');
                    
                    newOption.value     = versionNum;
                    newOption.innerHTML = versionNum;
                    
                    form.version.appendChild(newOption); 
                }
            } 
        }
    };

    request.open("POST", versionsScriptURL, true);
    request.send(null);
}
