/*Clase JSButton*/
function _Button_SetGraphical()
{
  this.layer.lyHTML("");
  this.layer.lyWidth(this.layer.lyWidth()+ (this.layer.lyBorderWidth()*2));
  this.layer.lyHeight(this.layer.lyHeight()+ (this.layer.lyBorderWidth()*2));
  this.layer._lyStyle.textIndent="0px";
  this.layer.lyBorderWidth(0);
  this.layer.lyBorderStyle("none");
  this.layer.lyBorderColor("none");
  this.layer.lyBgColor("none");
  this.layer.imgButton = this.layer._lyLayout.appendChild(document.createElement("IMG"));
  if (arguments[0])
  {
    this.layer.imgReleased = new Image()
    this.layer.imgReleased.src = this.layer.imgButton.src = arguments[0]
  }
  if (arguments[1])
  {
    this.layer.imgPressed = new Image()
    this.layer.imgPressed.src = arguments[1]
  }
  this.layer.graphic = true;
}

function _Button(sNom)
{
  
  this.layer = new _Layer(sNom, (arguments[1]?arguments[1]:null), (arguments[2]?arguments[2]:0), (arguments[3]?arguments[3]:0), (arguments[4]?arguments[4]:14), (arguments[5]?arguments[5]:14));
  this.Name = sNom;
  this.pressed = false;
  this.layer.button = this;
  this.layer.graphic = false;
  this.layer.imgButton = new Image();
  this.layer.imgPressed = new Image();
  if (arguments[6]) this.layer.imgPressed.src = arguments[6];
  this.layer.imgReleased = new Image();
  if (arguments[7]) this.layer.imgReleased.src = arguments[7];
  this.onbuttonpressed = function () {void(0)};
  this.onbuttonreleased = function () {void(0)};
  with(this.layer)
  {
    pressed = false;
    _lyLayout.Container = this.layer;
    _lyStyle.textAlign="center";
    _lyStyle.cursor="default";
    _lyStyle.overflow="hidden";
    _lyLayout.onmousedown = function()
                               {
                                 this.Container.imgButton.src = this.Container.imgPressed.src;
                                 this.Container.pressed = true;
                                 this.Container.button.pressed = true;
                                 this.Container.button.onbuttonpressed();
                               };
    _lyLayout.onmouseup = _lyLayout.onmouseout = function()
                               {
                                 this.Container.imgButton.src = this.Container.imgReleased.src;
                                 this.Container.pressed = false;
                                 this.Container.button.pressed = false;
                                 this.Container.button.onbuttonreleased();
                               };
    lyAutoSize(false);
  }
}

_Button.prototype.setGraphical   = _Button_SetGraphical;

/*Clase JSGraphicScroll*/
var _moVScroll;
function _ScrollBar(oWindow, oLayout)
{
  this.window = oWindow;
  this.layout = oLayout;
  _moVScroll = this;

  //this.layout.lyAutoSizeHeight(true);
  this.delta = 10;

  this.Name = oWindow.Name + "_Scroll";
  this._Layer = new _Layer(oWindow.Name + "_Scroll", oWindow._lyLayout, 0, oWindow.lyWidth() - oWindow.lyBorderWidth() - 19, oWindow.lyHeight() - oWindow.lyBorderWidth() - 1, 19);

  this.CmdUp = new _Button(this.Name + "_treevScrollBarAup", this._Layer._lyLayout, 0, 0, 18, 18);
  
  this.CmdUp.setGraphical("../Images/upNewArrow.gif", "../Images/upNewArrowPressed.gif");
  this.CmdUp.scrollBar = this;
  this.CmdUp.window = this.window;
  this.CmdUp.layout = this.layout;

  with (this.CmdUp)
  {
    onbuttonpressed = function()
                      {
                        if (this.layout.lyHeight() <= (this.window.lyHeight() - this.window.lyBorderWidth())) return;
                        if (this.layout.lyTop() + this.scrollBar.delta < 0)
                          this.layout.lyTop(this.layout.lyTop() + this.scrollBar.delta);
                        else
                          this.layout.lyTop(0);
                        if (this.pressed) setTimeout("_moVScroll.CmdUp.onbuttonpressed()",20);
                      };
  }

  this.CmdDown = new _Button(this.Name + "_treevScrollBarADown", this._Layer._lyLayout, this._Layer.lyHeight() - 18, 0, 18, 18);
  
  this.CmdDown.setGraphical("../Images/downNewArrow.gif", "../Images/downNewArrowPressed.gif");
  this.CmdDown.scrollBar = this;
  this.CmdDown.window = this.window;
  this.CmdDown.layout = this.layout;

  with (this.CmdDown)
  {
    onbuttonpressed = function()
                      {
                        if (this.layout.lyHeight() <= (this.window.lyHeight() - this.window.lyBorderWidth())) return;
                        if (this.layout.lyTop() + this.layout.lyHeight() - this.scrollBar.delta >= (this.window.lyHeight() - this.window.lyBorderWidth()))
                          this.layout.lyTop(this.layout.lyTop() - this.scrollBar.delta);
                        else
                          this.layout.lyTop(this.window.lyHeight() - this.layout.lyHeight())
                        if (this.pressed) setTimeout("_moVScroll.CmdDown.onbuttonpressed()",20);
                      };
  }

  this.reposition = function()
                    {
                      with (this._Layer)
                      {
                         lyTop(0);
                         lyLeft(this.window.lyWidth() - this.window.lyBorderWidth() - 19);
                         lyHeight(this.window.lyHeight() - this.window.lyBorderWidth() - 1);
                         lyWidth(19);
                      }
                      with (this.CmdUp.layer)
                      {
                         lyTop(0);
                         lyLeft(0);
                         lyHeight(18);
                         lyWidth(18);
                      }
                      with (this.CmdDown.layer)
                      {
                         lyTop(this._Layer.lyHeight() - 18);
                         lyLeft(0);
                         lyHeight(18);
                         lyWidth(18);
                      }
                    }
}