/*
Modificacion
	Gerado Garcia Hernández
	Gedas CRM
	Se cambio el background hacía el layer que funciona
	como desplazo, ya que estaba sobrel el fondo y luego se mostraba Fuera
	23/Feb/2004
*/
/*
 *	DHTMLHBar
 */


function DHTMLHBar( left, top,
                    width, height,
                    leftButtonImage, leftButtonWidth, leftButtonHeight,
                    rightButtonImage, rightButtonWidth, rightButtonHeight,
                    scrollButtonImage, scrollButtonWidth, scrollButtonHeight,
                    backgroudImage,
                    status,
                    zIndex ){

  this.init           = DHTMLHBar_init
  this.getInnerHTML   = DHTMLHBar_getInnerHTML
  this.getStyle       = DHTMLHBar_getStyle
  this.getFormatStyle = DHTMLHBar_getFormatStyle
  this.toString       = DHTMLHBar_toString
  
  this.getHeight      = DHTMLHBar_getHeight
  this.getWidth       = DHTMLHBar_getWidth
  this.setVisible     = DHTMLHBar_setVisible

  this.setWidth       = DHTMLHBar_setWidth
  
  this.getName             = DHTMLHBar_getName
  this.getBodyName         = DHTMLHBar_getBodyName
  this.getLeftButtonName   = DHTMLHBar_getLeftButtonName
  this.getRightButtonName  = DHTMLHBar_getRightButtonName
  this.getScrollButtonName = DHTMLHBar_getScrollButtonName
  
                    
  this.left           = left
  this.top            = top
  this.width          = width
  this.height         = height
  this.leftButton     = new DHTMLButton( 0, 0, leftButtonWidth, leftButtonHeight, leftButtonImage, null, null, true, zIndex+2  )
  this.rightButton    = new DHTMLButton( (width-rightButtonWidth), 0, rightButtonWidth, rightButtonHeight, rightButtonImage, null, null, true, zIndex+2  )
  this.backgroudImage = backgroudImage
  this.status         = status
  this.zIndex         = zIndex
  
  this.scrollButtonImage  = scrollButtonImage
  this.scrollButtonWidth  = scrollButtonWidth
  this.scrollButtonHeight = scrollButtonHeight
  
  do{
    this.divName = "DHTMLHBar" + parseInt(Math.random()*1000000) 
  }while( MM_findObj( this.divName ) )
}

function DHTMLHBar_setVisible( visible ){
  MM_showHideLayers( this.divName, null, visible?"visible":"hide" )
}

function DHTMLHBar_init(){
  if( document.layers ) {
    //var ref = MM_findObj( this.getBodyName() )
    var ref = MM_findObj( this.divName + "BACKGROUND" )
    ref.background.src = this.backgroudImage
  }
}

function DHTMLHBar_getBodyName(){
  return this.divName + "BODY"
}


function DHTMLHBar_getName(){
  return this.divName
}

function DHTMLHBar_getLeftButtonName(){
  return this.leftButton.divName
}

function DHTMLHBar_getRightButtonName(){
  return this.rightButton.divName
}

function DHTMLHBar_getScrollButtonName(){
  return this.divName + "SCROLL"
}
  
  

function DHTMLHBar_getFormatStyle(){
  var innerHTML = ""
  
  innerHTML += "<style>"
  innerHTML += this.getStyle()
  innerHTML += "</style>"
  return innerHTML
}

function DHTMLHBar_getHeight(){
  return this.height
}

function DHTMLHBar_getWidth(){
  return this.width
}

function DHTMLHBar_getStyle(){
  var innerHTML = ""
  
  
  innerHTML += "\n<!--\n\n"
  
  innerHTML += "#" + this.divName + "{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:" + this.left + ";\n"
  innerHTML += "  top:" + this.top + ";\n"
  innerHTML += "  width:" + this.width + ";\n"
  innerHTML += "  height:" + this.height + ";\n"
 // innerHTML += "  background-image: url('" + this.backgroudImage + "');\n"
 // innerHTML += "  layer-background-image: url('" + this.backgroudImage + "');\n"
  innerHTML += "  z-index:" + this.zIndex +";\n"
  innerHTML += "  clip: rect( 0 " + this.width + " " + this.height + " 0);\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n"
  
  var tmpWidth = (  parseInt(this.width) - 
                    parseInt(this.rightButton.getWidth()) - 
                    parseInt(this.leftButton.getWidth()) )
  
  innerHTML += "#" + this.divName + "BODY{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:" + this.leftButton.getWidth() + " ;\n"
  innerHTML += "  top:0;\n"
  innerHTML += "  width:" + tmpWidth + ";\n"
  innerHTML += "  height:" + this.height + ";\n"
  innerHTML += "  z-index:" + (this.zIndex+1) +";\n"
 innerHTML += "  background-image: url('" + this.backgroudImage + "');\n"
 innerHTML += "  layer-background-image: url('" + this.backgroudImage + "');\n"
  innerHTML += "  clip: rect( 0 " + tmpWidth + " " + this.height + " 0);\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n"

  innerHTML += "#" + this.divName + "BACKGROUND{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:0;\n"
  innerHTML += "  top:0;\n"
  innerHTML += "  width:" + tmpWidth + ";\n"
  innerHTML += "  height:" + this.height + ";\n"
  innerHTML += "  z-index:" + (this.zIndex+1) +";\n"
 
  innerHTML += "  clip: rect( 0 " + tmpWidth + " " + this.height + " 0);\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n"
  
  this.imgBackground = "<IMG name='img_" + this.divName + "BODYBACKGROUND' " +
                       "width='" + tmpWidth + "' " +
                       "height='" + this.height + "' " +
                       "src='" + theSpacerBackground +"'>"
                       

  innerHTML += "#" + this.divName + "SCROLL{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:0;\n"
  innerHTML += "  top:0;\n"
  innerHTML += "  width:" + this.scrollButtonWidth + ";\n"
  innerHTML += "  height:" + this.scrollButtonHeight + ";\n"
  innerHTML += "  background-image: url('" + this.scrollButtonImage + "');\n"
  innerHTML += "  layer-background-image: url('" + this.scrollButtonImage + "');\n"
  innerHTML += "  z-index:" + (this.zIndex + 3 ) +";\n"
  innerHTML += "  clip: rect( 0 " + this.scrollButtonWidth + " " + this.scrollButtonHeight + " 0);\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n"
  
  innerHTML += "-->\n"
    
  
  innerHTML += this.leftButton.getStyle()
  innerHTML += this.rightButton.getStyle()
  
  return  innerHTML
}


function DHTMLHBar_getInnerHTML(){
  var innerHTML = ""
                        
  innerHTML += "<DIV id='" + this.divName + "'>\n" 
  innerHTML += this.leftButton.getInnerHTML()
  innerHTML += "  <DIV id='" + this.divName + "BODY'>\n" 
  innerHTML += "  <DIV id='" + this.divName + "BACKGROUND'>" + this.imgBackground + "</DIV>\n" 
  innerHTML += "    <DIV id='" + this.divName + "SCROLL'>\n" 
  innerHTML += "    </DIV>\n"
  innerHTML += "  </DIV>\n"
  innerHTML += this.rightButton.getInnerHTML()
  innerHTML += "</DIV>\n"
  return innerHTML
}


function DHTMLHBar_toString(){
  return  this.getFormatStyle() + 
          this.getInnerHTML()
}


function DHTMLHBar_setWidth( width ){
  if( !this.hbar ){
    this.hbar     = new DHTMLLayer( this.getName() )
    this.hbody    = new DHTMLLayer( this.getBodyName() )
    this.lButton  = new DHTMLLayer( this.getLeftButtonName() )
    this.rButton  = new DHTMLLayer( this.getRightButtonName() )
    this.sButton  = new DHTMLLayer( this.getScrollButtonName() )
  }
  
  this.hbar.setWidth( width )
  this.hbody.setWidth( width - this.rButton.getWidth() - this.lButton.getWidth() )
  this.rButton.setX( width - this.rButton.getWidth() )  

}
