// Gaia Ajax Copyright (C) 2008 - 2009 Gaiaware AS. details at http://gaiaware.net/

/* 
 * Gaia Ajax - Ajax Control Library for ASP.NET
 * Copyright (C) 2008 - 2009 Gaiaware AS
 * All rights reserved.
 * This program is distributed under either GPL version 3 
 * as published by the Free Software Foundation or the
 * Gaia Commercial License version 1 as published by
 * Gaiaware AS
 * read the details at http://gaiaware.net
 */

/* ---------------------------------------------------------------------------
   Class basically wrapping the ASP.LinkButton WebControl class
   --------------------------------------------------------------------------- */
Gaia.LinkButton = Class.create();

Gaia.LinkButton.fooBar = function(){
  // Do nothing, just dereferenced in href of hyperlink
}

// Inheriting from WebControl
Object.extend(Gaia.LinkButton.prototype, Gaia.WebControl.prototype);

// Adding custom parts
Object.extend(Gaia.LinkButton.prototype, {

  // "Constructor"
  initialize: function(element, options){
    this.initializeLinkButton(element, options);
  },

  initializeLinkButton: function(element, options){
    // Calling base class constructor
    this.initializeWebControl(element, options);

    // we keep this one to make it possible to create Gaia solutions for browser with no JavaScript...??
    this.element.href = 'javascript:Gaia.LinkButton.fooBar();';
  },
  
  // 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;
  },

  // 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();
  }
});

Gaia.LinkButton.browserFinishedLoading = true;
