var RoomIDs = new Array();
var RoomNames = new Array();
var locations = new Array();

function ShowRooms(loc) {
    var loc_id = loc.options[loc.selectedIndex].value;

    SetRoomsForLocation(loc_id,0);

}
function SetRoomsForLocation(loc_id,roomID_to_select) {
    var op, rms, loc_index;
    //clear all options
    rms = document.getElementById("regID");
    ClearOptions(rms);

    //find location's index in array of locations
    loc_index = FindLocationIndex(loc_id);

    //set rooms for selected location
    if (loc_index >= 0) {
        //set options from array
        for (i=0;i<RoomIDs[loc_index].length;i++) {
            op = new Option(RoomNames[loc_index][i], RoomIDs[loc_index][i]);
            rms.options[i+1] = op;
        }
    }
    //select specified room
    for (i=0;i<rms.options.length;i++) {
        if (rms.options[i].value == roomID_to_select) {
            rms.options[i].selected = true;
            break;
        }
    }
}

function ClearOptions(rms) {
    var ty = rms.type;

    if (ty.toLowerCase().indexOf("select") > -1) {
        for (i=rms.options.length-1; i>0;i--) rms.options[i] = null;
    }
}
function FindLocationIndex(loc_id) {
    var index = -1;
    for(i=0;i<locations.length; i++) {
        if (locations[i] == loc_id) {
            index = i;
            break;
        }
    }
    return index;
}