function updateSport () {
    showThrobber();
    url = '/static/kssportsconnection/customize.php';
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(response) {
                populateSelect('sport', response);
                hideThrobber();
                document.getElementById('sport-wrapper').style.display = 'block';
                document.getElementById('manufacturer-wrapper').style.display = 'none';
              //  document.getElementById('character-wrapper').style.display = 'none';
               // document.getElementById('budget-wrapper').style.display = 'none';
            }
    });
}

function updateManufacturer () {
    document.getElementById('manufacturer-wrapper').style.display = 'block';
    //document.getElementById('character-wrapper').style.display = 'none';
    //document.getElementById('budget-wrapper').style.display = 'none';
    sport = getSelected('sport');
    if (sport == '') return false;
    showThrobber();
    url = '/static/kssportsconnection/customize.php?sport='+encodeURI(sport);
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(response) {
                populateSelect('manufacturer', response);
                hideThrobber();
                document.getElementById('manufacturer-wrapper').style.display = 'block';
            }
    });
}

/*
function updateCharacter () {
    document.getElementById('character-wrapper').style.display = 'none';
    document.getElementById('budget-wrapper').style.display = 'none';
    continent = getSelected('continent');
    climate = getSelected('climate');
    if (climate == '') return false;
    showThrobber();
    url = '/static/kssportsconnection/customize.php?continent='+encodeURI(continent)+'&climate='+encodeURI(climate);
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(response) {
                populateSelect('character', response);
                hideThrobber();
                document.getElementById('character-wrapper').style.display = 'block';
            }
    });
}

function updateBudget () {
    document.getElementById('budget-wrapper').style.display = 'none';
    continent = getSelected('continent');
    climate = getSelected('climate');
    character = getSelected('character');
    if (character == '') return false;
    showThrobber();
    url = '/static/kssportsconnection/customize.php?continent='+encodeURI(continent)+'&climate='+encodeURI(climate)+'&character='+encodeURI(character);
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(response) {
                populateSelect('budget', response);
                hideThrobber();
                document.getElementById('budget-wrapper').style.display = 'block';
            }
    });
}
*/

function getSelected (type) {
    type_select = document.getElementById(type);
    return type_select.options[type_select.options.selectedIndex].value;
}

function populateSelect(id, response) {
    select = document.getElementById(id);

    for(var count = select.options.length - 1; count >= 0; count--) { select.options[count] = null; }

    var newoptions = eval('(' + response.responseText + ')');
    if (newoptions.length == 0) {
        select.options[0] = new Option('-- None --', '');
    } else {
        select.options[0] = new Option('-- Select --', '');
        if (id == 'continent') select.options[1] = new Option('Any', 'Africa,Antarctica,Asia,Downunder,Europe,North America,Oceania,South America');
        for (j = 0; j < newoptions.length; j++) {
            i = select.options.length;
            select.options[i] = new Option(newoptions[j][0], newoptions[j][1]);
        }
    }
}

function showThrobber () {
    $('throbber').style.display = 'inline';
}

function hideThrobber () {
    $('throbber').style.display = 'none';
}
