// 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.LinkButton WebControl class
   --------------------------------------------------------------------------- */
Gaia.LinkButton = function(element, options){
  this.initialize(element, options);
}

// Inheriting from WebControl
Object.extend(Gaia.LinkButton.prototype, Gaia.WebControl.prototype);

// Adding custom parts
Object.extend(Gaia.LinkButton.prototype, {
  // "Constructor"
  initialize: function(element, options){
    // Calling base class constructor
    this.baseInitializeWebControl(element, options);
    this.element.href = 'javascript:';
  },
  
  // Sets text of button
  setText: function(value){
    this.element.innerHTML = value;
    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 '&__EVENTARGUMENT=&__EVENTTARGET=' + this.getCallbackName();
  },

  _shouldSerializeValue: function(){
    // A button is NOT supposed to serialize it's value unless it has been "clicked" since otherwise it'll be defined
    // as a "click" on that button, therefor for OTHER controls events we DON'T serialize the button "value"
    return false;
  }
});

Gaia.LinkButton.browserFinishedLoading = true;
