// Gaia Ajax Widgets Copyright (C) 2007  Frost Innovation AS. details at http://ajaxwidgets.com/
/* 
 * Gaia Ajax Widgets, an Ajax Widget Library
 * Copyright (C) 2007  Frost Innovation AS
 * All rights reserved.
 * This program is distributed under either GPL version 2 
 * as published by the Free Software Foundation or the
 * Gaia Commercial License version 1 as published by
 * Frost Innovation AS
 * read the details at http://ajaxwidgets.com/
 */



/* ---------------------------------------------------------------------------
   Class basically wrapping the ASP.DropDownList WebControl class
   --------------------------------------------------------------------------- */
Gaia.DropDownList = function(element, options){
  this.initialize(element, options);
}

// Inheriting from WebControl
Object.extend(Gaia.DropDownList.prototype, Gaia.WebControl.prototype);

// Adding custom parts
Object.extend(Gaia.DropDownList.prototype, {
  // "Constructor"
  initialize: function(element, options){
    // Calling base class constructor
    this.baseInitializeWebControl(element, options);
  },

  // Sets the tabindex of the control
  setTabIndex: function(value){
    this.element.tabIndex = value;
    return this;
  },

  setSelectedIndex: function(value){
    // In cases where selected item is set to a HIGHER value than what's currently available...
    if( value < this.element.options.length)
      this.element.selectedIndex = value;
    return this;
  },

  clearItems: function(){
    this.element.options.length = 0;
    return this;
  },

  addItem: function(item){
    this.element.options[this.element.options.length] = new Option(item.text, item.value);
    if( item.selected )
      this.element.value = item.value;
    return this;
  },

  setAutoCallBack: function(value){
    return this;
  },

  _getElementPostValue: function(){
    return '&' + this.getCallbackName() + '=' + $F(this.element.id);
  },

  _getElementPostValueEvent: function(){
    return '&' + this.getCallbackName() + '=' + $F(this.element.id)+'&__EVENTTARGET='+this.getCallbackName();
  }
});

Gaia.DropDownList.browserFinishedLoading = true;
