var Select = Class.create( {
    initialize : function(ID, firstLine, comps)
    {
	this.ID = ID;
	this.firstLine = firstLine;
	this.components = comps.clone();
    },

    toHTML : function()
    {
	var retval = '<select id="#{ID}">'.interpolate(this);
	if (this.firstLine) {
	    retval += ('<option value="" selected>#{firstLine}<' + '/option>').interpolate(this);
	}
	this.components.each (function(menu) {
	    retval += menu.toHTML();
	} );
	retval += '<' + '/select>';
	return retval;
    }
} );

Select.Option = Class.create( {
    initialize : function(text, url)
    {
	this.text = text;
	this.url = url;
    },

    toHTML : function()
    {
	var retval = ('<option value="#{url}">#{text}<' + '/option>').interpolate(this);
	return retval;
    }
} );

Select.openWindow = function(event)
{
    var elem = event.element();
    
    if (elem.tagName == "SELECT") {
	if (elem.value.startsWith("http")) {
	    window.open(elem.value, '_blank');
	    elem.options[0].selected = true;
	} else if (elem.value != "") {
	    window.open(elem.value, '_self');
	}
	
    } else {
	alert("alien element:" + elem);
    }
}

