// 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.Button WebControl class
   --------------------------------------------------------------------------- */
Gaia.Button = function(element, options){
  this.initialize(element, options);
}

// Inheriting from WebControl
Object.extend(Gaia.Button.prototype, Gaia.WebControl.prototype);

// Adding Button customer parts
Object.extend(Gaia.Button.prototype, {
  // "Constructor"
  initialize: function(element, options){
    // Calling base class constructor
    this.baseInitializeWebControl(element, options);
    if( this.options.causeValidation != false && this.options.causeValidation != true )
      this.options.causeValidation = true;
  },

  // Sets text of button
  setText: function(value){
    this.element.value = value;
    return this;
  },

  setCausesValidation: function(value){
    this.options.causeValidation = false;
    return this;
  },

  // Sets text of button
  setPostBackUrl: function(value){
    this.options.url = value;
    return this;
  },

  // Called by control to check if we're supposed to actually raise a new Ajax.Request or not
  // Basically if the setPostBackUrl has been called, this will INSTEAD REDIRECT to THAT PAGE
  // with the correct viewstate and the control values etc instead of raising a new Ajax.Request!
  _shouldRunAjaxRequest: function(){
    return Gaia.ButtonHelper_shouldRunAjaxRequest.bind(this)();
  },

  // Sets a function to call when button is clicked
  setOnClientClick: function(value){
    Element.observe(this.element, 'click', value.bindAsEventListener(this));
    return this;
  },

  // Sets the tabindex of the button
  setTabIndex: function(value){
    this.element.tabIndex = value;
    return this;
  },

  _getElementPostValue: function(){
    return '';
  },

  _getElementPostValueEvent: function(){
    return '&' + this.getCallbackName() + '=' + $F(this.element.id);
  }
});

Gaia.Button.browserFinishedLoading = true;
