/*
    Manages a change in the type : will reset all other boxes
    changedObject is the object changed : here the engine type drop-down
*/
function PWC_engineSearch_type_change(changedObject)
{
    var typeID = changedObject.options[changedObject.selectedIndex].value;
    var takeoffDD = document.getElementById('PWC_engineSearch_takeoff');
    var lengthDD = document.getElementById('PWC_engineSearch_length');
    var diameterDD = document.getElementById('PWC_engineSearch_diameter');
    var widthDD = document.getElementById('PWC_engineSearch_width');
    var heightDD = document.getElementById('PWC_engineSearch_height');

    //Change takeoff DD : enable/disable and set options depending on type    
    takeoffDD.selectedIndex = 0;
    takeoffDD.disabled = typeID == 0 || PWC_engineSearch_takeoffOptions[typeID].length == 1;
    PWC_engineSearch_changeOptions(takeoffDD, PWC_engineSearch_takeoffOptions[typeID]);
    lengthDD.selectedIndex = 0;
    lengthDD.disabled = typeID == 0 || PWC_engineSearch_lengthOptions[typeID].length == 1;
    PWC_engineSearch_changeOptions(lengthDD, PWC_engineSearch_lengthOptions[typeID]);
    diameterDD.selectedIndex = 0;
    diameterDD.disabled = typeID == 0 || PWC_engineSearch_diameterOptions[typeID].length == 1;
    PWC_engineSearch_changeOptions(diameterDD, PWC_engineSearch_diameterOptions[typeID]);
    widthDD.selectedIndex = 0;
    widthDD.disabled = typeID == 0 || PWC_engineSearch_widthOptions[typeID].length == 1;
    PWC_engineSearch_changeOptions(widthDD, PWC_engineSearch_widthOptions[typeID]);
    heightDD.selectedIndex = 0;
    heightDD.disabled = typeID == 0 || PWC_engineSearch_heightOptions[typeID].length == 1;
    PWC_engineSearch_changeOptions(heightDD, PWC_engineSearch_heightOptions[typeID]);
}

/*
    Changes a drop-down list options given its object and an array of option
    objects
*/
function PWC_engineSearch_changeOptions(dropdownObject, newOptions)
{
    dropdownObject.options.length = 0;
    for (var i = 0; i < newOptions.length; i++) {
        dropdownObject.options[i] = newOptions[i];
    }
}