/* JSRoloURL
** Copyright (c) 1999 Christopher D. Doemel
**
** Permission to use and modify this script is granted, so long as
** the above copyright is maintained, any modifications are
** documented, and credit is given for use of the script.
**
** Version 1.0.0, February 1999
**
** 1.0.0   Initial release (08 Feb 1999)
*/

/* RoloURL_setTitle(newTitle)
**     Accessor method to set the title of the RoloURL (in other words,
**     what "prompt" is displayed in the first item of the menu).  The
**     newTitle argument is a string to use for the prompt.  This method
**     should be called through the RoloURL object as setTitle().
*/
function RoloURL_setTitle(newTitle) {
    this.title = newTitle;
}

/* RoloURL_setTarget(targetWindow)
**     Accessor method to set the target of the RoloURL.  The target
**     allows you to use the menus to change different windows.  The
**     targetWindow argument should be a string with the path to the
**     window object.  By default, the window in which the menu appears
**     is used.  This method should be caleld through the RoloURL
**     object as setTarget().
*/
function RoloURL_setTarget(targetWindow) {
    this.target = targetWindow;
}

/* RoloURL_setTarget(theIndex)
**     Internal function used to move to the selected page.
*/
function RoloURL_goToItem(theIndex) {
    if (theIndex != 0) {
        var theURL = this.itemArray[theIndex - 1].itemURL;
        if (theURL != "") {
            eval(this.target + ".location.href = '" +
                theURL + "'");
        }
    }
}

/* RoloURL_addDestination(menuText, itemURL)
**     This method adds a menu item to the RoloURL.  The menuText
**     argument will be displayed in the menu, and the itemURL
**     argument is the URL used when the item is selected.  Should
**     be called through the RoloURL object as addDestination().
*/
function RoloURL_addDestination(menuText,itemURL) {
    this.itemArray[this.numItems++] = new MenuItem(menuText,itemURL);
}

/* RoloURL_display()
**     Creates the HTML for the RoloURL.  Should be called through
**     the RoloURL object as display().
*/
function RoloURL_display() {
    // Only display the RoloURL if one or more items have been added
    // to the RoloURL.
    if (this.numItems > 0) {
        document.writeln('<FORM NAME="form_' + this.name + '">');
        document.writeln('<SELECT NAME="select_' + this.name + '" onChange="' +
            this.name + '.goToItem(this.selectedIndex)">');
        document.writeln('<OPTION>' + this.title);
        for (i = 0; i < this.numItems; i++) {
            document.writeln('<OPTION VALUE="' + this.itemArray[i].itemURL + '">' +
                this.itemArray[i].menuText);
        }
        document.writeln('</SELECT></FORM>');
    }
}

/* MenuItem()
**     Internal object used to store menu items.  Users should not
**     call this method directly.
*/
function MenuItem(menuText,itemURL) {
    this.menuText = menuText;
    this.itemURL  = itemURL;
}

/* RoloURL(roloURLName)
**     The external interface to the RoloURL.  The roloURLName
**     argument should be the same as the variable that stores
**     the RoloURL.
*/
function RoloURL(roloURLName) {
    this.name   = roloURLName;
    
    this.numItems  = 0;
    this.itemArray = new Object();
            
    this.title  = "Select a Destination...";
    this.target = "window";
    
    this.setTitle       = RoloURL_setTitle;
    this.setTarget      = RoloURL_setTarget;
    this.goToItem       = RoloURL_goToItem;
    this.addDestination = RoloURL_addDestination;
    this.display        = RoloURL_display;
}