/*
 *  DHTMLScroll
 *
 *  Roberto Pérez Guzmán
 *  gedas Mexico
 *
 *
 *
 *
 *  DEPENDENCIAS
 *    DHTML.js
 *    DHTMLLayer.js
 *    DHTMLButton.js
 */

var theSpacerBackground = "../images/transparente.gif"
 
DHTMLScroll.prototype.doHScroll     = DHTMLScroll_doHScroll
DHTMLScroll.prototype.doVScroll     = DHTMLScroll_doVScroll
DHTMLScroll.prototype.doStop        = DHTMLScroll_doStop

DHTMLScroll.prototype.currentScroll   = ""

function DHTMLScroll_cancelDrag(){
	if( event ){
		event.returnValue = false
	}
	return false
}

function DHTMLScroll_doHScroll( theEvent ){
  if( theEvent ){
    eval( DHTMLScroll.prototype.currentScroll + ".hScroll(theEvent)" )
  }
  else{
    eval( DHTMLScroll.prototype.currentScroll + ".hScroll( null )" )
  }
}

function DHTMLScroll_doVScroll( theEvent ){
  if( theEvent ){
    eval( DHTMLScroll.prototype.currentScroll + ".vScroll(theEvent)" )
  }
  else{
    eval( DHTMLScroll.prototype.currentScroll + ".vScroll( null )" )
  }
}

function DHTMLScroll_doStop( theEvent ){
  if( theEvent ){
    eval( DHTMLScroll.prototype.currentScroll + ".stop(theEvent)" )
  }
  else{
    eval( DHTMLScroll.prototype.currentScroll + ".stop( null )" )
  }  
}


function DHTMLScroll( left, top, width, height,
                      bgColor, backgroudImage, imgPad,
                      leftButtonImage, leftButtonWidth, leftButtonHeight,
                      rightButtonImage, rightButtonWidth, rightButtonHeight,
                      horizontalScrollImage, horizontalScrollWidth, horizontalScrollHeight,
                      horizontalFill,
                      upButtonImage, upButtonWidth, upButtonHeight,
                      downButtonImage, downButtonWidth, downButtonHeight,
                      verticalScrollImage, verticalScrollWidth, verticalScrollHeight,
                      verticalFill,
                      zIndex ){
                      
/*
   * Atributos
   */
  this._left          = left
  this._top           = top
  this.zIndex         = zIndex
  this.width          = width
  this.height         = height
  this.bgColor        = bgColor
  this.backgroudImage = backgroudImage

  do{
    this.divName = "dhtmlScroll" + parseInt(Math.random()*1000000) 
  }while( MM_findObj( this.divName ) )
  
  
  this.getStyle       = DHTMLScroll_getStyle
  this.divStart       = DHTMLScroll_divStart
  this.divEnd         = DHTMLScroll_divEnd
  this.toString       = DHTMLScroll_toString
  
  if( !leftButtonImage        || !leftButtonWidth       || 
      !leftButtonHeight       || !rightButtonImage      || 
      !rightButtonWidth       || !rightButtonHeight     ||
      !horizontalScrollImage  || !horizontalScrollWidth || 
      !horizontalScrollHeight || !horizontalFill ){
    this.hBar = null
  }
  else{
    var tmpWidth = verticalScrollWidth?verticalScrollWidth:0
    this.hBar = new DHTMLHBar( 0, (height - horizontalScrollHeight), 
                               (width - tmpWidth), horizontalScrollHeight,
                               leftButtonImage, leftButtonWidth, leftButtonHeight,
                               rightButtonImage, rightButtonWidth, rightButtonHeight,
                               horizontalScrollImage, horizontalScrollWidth, horizontalScrollHeight,
                               horizontalFill,
                               true,
                               zIndex )
  }
  
  if( !upButtonImage        || !upButtonWidth       || 
      !upButtonHeight       || !downButtonImage     || 
      !downButtonWidth      || !downButtonHeight    ||
      !verticalScrollImage  || !verticalScrollWidth || 
      !verticalScrollHeight || !verticalFill ){
    this.vBar = null
    
  }
  else{
    var tmpHeight = horizontalScrollHeight?horizontalScrollHeight:0
    this.vBar = new DHTMLVBar( (width - verticalScrollWidth), 0, 
                               verticalScrollWidth, (height - tmpHeight),
                               upButtonImage, upButtonWidth, upButtonHeight,
                               downButtonImage, downButtonWidth, downButtonHeight,
                               verticalScrollImage, verticalScrollWidth, verticalScrollHeight,
                               verticalFill,
                               true,
                               zIndex )
  }


  if( imgPad && this.vBar && this.hBar ){
    this.pad = new DHTMLButton( width-upButtonWidth, 
                                height-leftButtonHeight, 
                                upButtonWidth, leftButtonHeight, 
                                imgPad, 
                                null, null, true, zIndex )
    //this.pad.setVisible( false )
  }
  else{
    this.pad = null
  }                               

  /*
   * Métodos
   */
  this.init   = DHTMLScroll_init
  
  this.scrollUp     = DHTMLScroll_scrollUp
  this.scrollDown   = DHTMLScroll_scrollDown
  this.scrollLeft   = DHTMLScroll_scrollLeft
  this.scrollRight  = DHTMLScroll_scrollRight

  this.initVScroll  = DHTMLScroll_initVScroll
  this.initHScroll  = DHTMLScroll_initHScroll
  
  this.vScroll      = DHTMLScroll_vScroll
  this.hScroll      = DHTMLScroll_hScroll

  this.up           = DHTMLScroll_up
  this.down         = DHTMLScroll_down
  this.left         = DHTMLScroll_left
  this.right        = DHTMLScroll_right
  this.stop         = DHTMLScroll_stop
  this.refresh      = DHTMLScroll_refresh
  
  this.getContent   = DHTMLScroll_getContent
  
  this.relativeVScroll = DHTMLScroll_relativeVScroll
  this.relativeHScroll = DHTMLScroll_relativeHScroll
  
}    

function DHTMLScroll_getContent(){
  return this.divName + "CONTENT" 
}

function DHTMLScroll_toString(){
  return  this.getStyle() +
          this.divStart() +
          this.divEnd()
}


function DHTMLScroll_getStyle(){
  var tmpWidth
  var tmpHeight
  
  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"
  if( this.bgColor ){
    innerHTML += "  layer-background-color:#" +  this.bgColor + ";\n"
    innerHTML += "  background-color:#" + this.bgColor + ";\n"
  }
  //innerHTML += "  overflow:hidden;\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" 
  
  
  //--
  //--

  innerHTML += "#" + this.divName + "CONTAINER{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:0;\n"
  innerHTML += "  top:0;\n"
  tmpWidth = this.vBar?(this.width -this.vBar.getWidth()):this.width
  innerHTML += "  width:" + tmpWidth + ";\n"
  tmpHeight = this.hBar?(this.height - this.hBar.getHeight()):this.height
  innerHTML += "  height:" + tmpHeight + ";\n"
  if( this.bgColor ){
    innerHTML += "  layer-background-color:#" +  this.bgColor + ";\n"
    innerHTML += "  background-color:#" + this.bgColor + ";\n"
  }
  if( this.backgroudImage ){
    innerHTML += "  background-image: url('" + this.backgroudImage + "');\n"
    innerHTML += "  layer-background-image: url('" + this.backgroudImage + "');\n"
  }
  if( !document.layers ){
    innerHTML += "  overflow:hidden;\n"
  }
  innerHTML += "  z-index:" + ( this.zIndex  ) +";\n"
  innerHTML += "  clip: rect( 0 " + tmpWidth + " " +  tmpHeight + " 0);\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n" 

  //--
  //--
    
  innerHTML += "#" + this.divName + "CONTENT{\n" 
  innerHTML += "  position:absolute;\n" 
  innerHTML += "  left:0;\n"
  innerHTML += "  top:0;\n"
  //innerHTML += "  overflow:visible;\n"
  innerHTML += "  z-index:" + ( this.zIndex  ) +";\n"
  innerHTML += "  border: 0px none #000000\n"
  innerHTML += "}\n\n" 

  innerHTML += "-->\n"

  innerHTML += this.vBar?this.vBar.getStyle():""
  innerHTML += this.hBar?this.hBar.getStyle():""
  innerHTML += this.pad?this.pad.getStyle():""
  
  return innerHTML
}

function DHTMLScroll_divStart(){
  var innerHTML = ""
  
  innerHTML += "<DIV id='" + this.divName + "'>\n" 
  innerHTML += "  <DIV id='" + this.divName + "CONTAINER'>\n" 
  innerHTML += "    <DIV id='" + this.divName + "CONTENT'>\n" 
  
  return innerHTML
}


function DHTMLScroll_divEnd(){
  var innerHTML = ""
  
  innerHTML += "    </DIV>\n"
  innerHTML += "  </DIV>\n"
  
  innerHTML += this.vBar?this.vBar.getInnerHTML():"";
  innerHTML += this.hBar?this.hBar.getInnerHTML():"";
  innerHTML += this.pad?this.pad.getInnerHTML():"";
  
  innerHTML += "</DIV>\n"
  
  return  innerHTML
}


function DHTMLScroll_init(){

  do{
    this.refName = "document._" + parseInt(Math.random()*1000000)
  }while( eval( this.refName ) != null )
	eval( this.refName + "= this" )

  this.deltaX = 10
  this.deltaY = 10
  this.incrX  = 10

  this.incrY  = 10
  this.timer  = null
  this.speed  = 100
  this.loop = false
   

  this.dhtmlScrollArea = new DHTMLScrollArea( this.divName + "CONTAINER",  
                                              this.divName + "CONTENT");
  
  if( this.hBar ){
    this.hBar.init()
    
    this.ref_HBAR     = MM_findObj( this.hBar.getName() );
    this.ref_HBODY    = MM_findObj( this.hBar.getBodyName() );
    this.ref_imgHBODY = MM_findObj( "img_" + this.hBar.getBodyName() + "BACKGROUND" );
    this.ref_LEFT     = MM_findObj( this.hBar.getLeftButtonName() );
    this.ref_RIGHT    = MM_findObj( this.hBar.getRightButtonName() );
    this.ref_HSCROLL  = new DHTMLLayer( this.hBar.getScrollButtonName() );
        
    if( document.layers ){
      this.ref_LEFT.captureEvents( Event.MOUSEDOWN | Event.MOUSEDRAG)
      this.ref_RIGHT.captureEvents( Event.MOUSEDOWN | Event.MOUSEDRAG)
    }

    this.ref_LEFT.onmousedown     = new Function( this.refName + ".scrollLeft()" ) 
    this.ref_LEFT.ondrag          = DHTMLScroll_cancelDrag 
    
    this.ref_RIGHT.onmousedown    = new Function( this.refName + ".scrollRight()" ) 
    this.ref_RIGHT.ondrag         = DHTMLScroll_cancelDrag 
    
    this.ref_HSCROLL.setMouseDownHandler( new Function( this.refName + ".initHScroll()" ) )
    this.ref_HSCROLL.setOnDragHandler( DHTMLScroll_cancelDrag )

    this.ref_imgHBODY.onmousedown     = doHScrollBody
    this.ref_imgHBODY.ondrag         = DHTMLScroll_cancelDrag 
    this.ref_imgHBODY.dhtmlObject    = this
  }
  else{
    this.ref_HBAR     = null;
    this.ref_HBODY    = null;
    this.ref_HSCROLL  = null;
    this.ref_LEFT     = null;
    this.ref_RIGHT    = null;
  }
 
 
  if( this.vBar ){
    this.vBar.init()
    
    this.ref_VBAR     = MM_findObj( this.vBar.getName() );
    this.ref_VBODY    = MM_findObj( this.vBar.getBodyName() );
    this.ref_imgVBODY = MM_findObj( "img_" + this.vBar.getBodyName() + "BACKGROUND" );
    this.ref_UP       = MM_findObj( this.vBar.getUpButtonName() );
    this.ref_DOWN     = MM_findObj( this.vBar.getDownButtonName() );
    this.ref_VSCROLL  = new DHTMLLayer( this.vBar.getScrollButtonName() );

    
    if( document.layers ){
      this.ref_UP.captureEvents( Event.MOUSEDOWN | Event.MOUSEDRAG )
      this.ref_DOWN.captureEvents( Event.MOUSEDOWN | Event.MOUSEDRAG )
    }

    this.ref_UP.onmousedown       = new Function( this.refName + ".scrollUp()" ) 
    this.ref_UP.ondrag            = DHTMLScroll_cancelDrag 
    
    this.ref_DOWN.onmousedown     = new Function( this.refName + ".scrollDown()" ) 
    this.ref_DOWN.ondrag          = DHTMLScroll_cancelDrag 
    
    this.ref_VSCROLL.setMouseDownHandler( new Function( this.refName + ".initVScroll()" ) )
    this.ref_VSCROLL.setOnDragHandler( DHTMLScroll_cancelDrag )
    
    this.ref_imgVBODY.onmousedown    = doVScrollBody
    this.ref_imgVBODY.ondrag         = DHTMLScroll_cancelDrag 
    this.ref_imgVBODY.dhtmlObject    = this    
  }
  else{
    this.ref_VBAR     = null;
    this.ref_VBODY    = null;
    this.ref_VSCROLL  = null;
    this.ref_UP       = null;
    this.ref_DOWN     = null;
  }  
  
  this.refresh()
}

function DHTMLScroll_refresh(){

  if( this.dhtmlScrollArea == null ){
    if( this.ref_HBAR != null ){
      MM_showHideLayers( this.ref_HBAR.id, "", "hide");
    }
    if( this.ref_VBAR != null ){
      MM_showHideLayers( this.ref_VBAR.id, "", "hide");
    }
    return;
  }
  else{
    this.dhtmlScrollArea.move(0,0)
  }
  
  if( this.ref_HBAR && 
      this.dhtmlScrollArea.isHScroll() && 
      !this.dhtmlScrollArea.isVScroll() ){
      this.hBar.setWidth( this.width )
      if( this.pad ){
        this.pad.setVisible( false )
      }
  }
  else if(  this.ref_VBAR && 
            this.dhtmlScrollArea.isVScroll() && 
            !this.dhtmlScrollArea.isHScroll() ){
      this.vBar.setHeight( this.height )
      if( this.pad ){
        this.pad.setVisible( false )
      }

  }
  else if( this.ref_HBAR && this.ref_VBAR ){
    
    this.hBar.setWidth( this.width - this.vBar.getWidth() )
    this.vBar.setHeight( this.height - this.hBar.getHeight() )
      if( this.pad ){
        this.pad.setVisible( true )
      }
  }
  
  if( this.ref_VBAR != null ){
    if( this.dhtmlScrollArea.isVScroll() ){
      
      this.dhtmlScrollArea.container.setWidth( this.width - this.vBar.getWidth() )
      
      var count = parseFloat(this.dhtmlScrollArea.getScrollHeight()/10);
        
      if( document.layers ){
        /*
         * Netscape
         */
        var tmp
        tmp  = parseFloat( this.ref_VBODY.clip.height );
        tmp -= parseFloat( this.ref_VSCROLL.getHeight() );
        this.incrY = parseFloat(tmp/count) + 1;  
      }
      else{
        /*
         * IExplorer
         */
        var tmp
        tmp  = parseFloat( this.ref_VBODY.offsetHeight );
        tmp -= parseFloat( this.ref_VSCROLL.getHeight() );
        this.incrY = parseFloat( tmp/count ) + 1;  
      }
      
      if( this.incrY <= 0 ){
        this.incrY = 1;
      }
      MM_showHideLayers( this.ref_VBAR.id, "", "show");
    }
    else{
      
      MM_showHideLayers( this.ref_VBAR.id, "", "hide");
      this.dhtmlScrollArea.container.setWidth( this.width )
      if( this.pad ){
        this.pad.setVisible( false )
      }      
    }
  }

  if( this.ref_HBAR ){
    if( this.dhtmlScrollArea.isHScroll() ){
      this.dhtmlScrollArea.container.setHeight( this.height - this.hBar.getHeight() )
      var count = parseFloat(this.dhtmlScrollArea.getScrollWidth()/10) + 1;
      if( document.layers ){
        /*
         * Netscape
         */
        this.incrX = parseFloat( this.ref_HBODY.clip.width/count ) - 1;
      }
      else{
        /*
         * IExplorer
         */
        this.incrX = parseFloat( this.ref_HBODY.offsetWidth/count ) - 1;
      }
      
      if( this.incrX == 0 ){
          this.incrX = 1;
      }
      MM_showHideLayers( this.ref_HBAR.id, "", "show");
    }
    else{
      MM_showHideLayers( this.ref_HBAR.id, "", "hide");
      this.dhtmlScrollArea.container.setHeight( this.height )
      if( this.pad ){
        this.pad.setVisible( false )
      }      
    }
  }
}

function DHTMLScroll_scrollUp(){
  this.stop()
  DHTMLScroll.prototype.currentScroll = this.refName
  if( document.layers ){
    window.captureEvents( Event.MOUSEUP );
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    document.onmouseup   =  DHTMLScroll.prototype.doStop
  }

	this.up();
	this.timer = setTimeout( this.refName + ".scrollUp()", this.speed );
}

function DHTMLScroll_scrollDown(){
  this.stop()
  DHTMLScroll.prototype.currentScroll = this.refName

  if( document.layers ){
    window.captureEvents( Event.MOUSEUP );
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    document.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  
	this.down();
	this.timer = setTimeout( this.refName + ".scrollDown()", this.speed );
}

function DHTMLScroll_scrollLeft(){
  this.stop()
  DHTMLScroll.prototype.currentScroll = this.refName

  if( document.layers ){
    window.captureEvents( Event.MOUSEUP );
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    window.document.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  
  this.left();
	this.timer = setTimeout( this.refName + ".scrollLeft()", this.speed );
}

function DHTMLScroll_scrollRight(){
  this.stop()
  DHTMLScroll.prototype.currentScroll = this.refName

  if( document.layers ){
    window.captureEvents( Event.MOUSEUP );
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    window.document.onmouseup =  DHTMLScroll.prototype.doStop
  }
  
	this.right();
	this.timer = setTimeout( this.refName + ".scrollRight()", this.speed );
}

function DHTMLScroll_up(){
  if( this.ref_VSCROLL == null ){
    return
  }
  
  var value = this.ref_VSCROLL.getY() - this.incrY;
  this.ref_VSCROLL.setY( value<0?0:value )
  this.relativeVScroll( this.ref_VSCROLL.getY() )

  /*
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.move( 0, this.deltaY ) 
  }
  */
  
}


function DHTMLScroll_down(){
  if( this.ref_VSCROLL == null ){
    return
  }
  
  var value = this.ref_VSCROLL.getY() + this.incrY;
  if( document.layers ){
    /*
     * Netscape
     */  
    if( value > (this.ref_VBODY.clip.height - this.ref_VSCROLL.getHeight() )){
      value = this.ref_VBODY.clip.height - this.ref_VSCROLL.getHeight();
    }
  }
  else{
    /*
     * IExplorer
     */  
    
    if( value > (this.ref_VBODY.offsetHeight - this.ref_VSCROLL.getHeight() )){
      value = this.ref_VBODY.offsetHeight - this.ref_VSCROLL.getHeight();
    }
    
  }

  this.ref_VSCROLL.setY( value ) 
  this.relativeVScroll( this.ref_VSCROLL.getY() ) 
  /*
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.move( 0, -this.deltaY ) 
  } 
  */
}

function DHTMLScroll_left(){
  if( this.ref_HSCROLL == null ){
    return
  }
  
  var offset = this.ref_HSCROLL.getX() - this.incrX;
  offset = offset<0?0:offset;
  this.ref_HSCROLL.setX( offset )
  this.relativeHScroll( this.ref_HSCROLL.getX() )
  /*
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.move( this.deltaX, 0 ) 
  }
  */
  
}

function DHTMLScroll_right(){
  if( this.ref_HSCROLL == null ){
    return
  }

   var offset = this.ref_HSCROLL.getX() + this.incrX;
  
  if( document.layers ){
    /*
     * Netscape
     */  
    if( offset > (this.ref_HBODY.clip.width - this.ref_HSCROLL.getWidth() )){
      offset = this.ref_HBODY.clip.width - this.ref_HSCROLL.getWidth();
    }
  }
  else{
    /*
     * IExplorer
     */  
    if( offset > (this.ref_HBODY.offsetWidth - this.ref_HSCROLL.getWidth() )){
      offset = this.ref_HBODY.offsetWidth - this.ref_HSCROLL.getWidth() ;
    }
  }
   
  this.ref_HSCROLL.setX( offset )
  this.relativeHScroll( this.ref_HSCROLL.getX() )
  /*
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.move( -this.deltaX, 0 ) 
  }
  */
}

function DHTMLScroll_stop(){
  DHTMLScroll.prototype.currentScroll = null
  clearTimeout( this.timer )
  this.loop = false
	this.timer = null
  
  if( document.layers  ){
    window.onmouseup    = null
    window.onmousemove  = null
  }
  else{
    document.onmouseup    = null
    document.onmousemove  = null
  }
}

function DHTMLScroll_initVScroll(){
  DHTMLScroll.prototype.currentScroll = this.refName

  clearTimeout( this.timer )
  this.timer = null
  this.loop = true
  
  if( document.layers ){
    window.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP );
    window.onmousemove =  DHTMLScroll.prototype.doVScroll
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    document.onmousemove = DHTMLScroll.prototype.doVScroll
    document.onmouseup   = DHTMLScroll.prototype.doStop
    this.startDrag       = parseInt( event.clientY )
  }
}

function DHTMLScroll_initHScroll( theEvent ){

  DHTMLScroll.prototype.currentScroll = this.refName

  clearTimeout( this.timer )
  this.timer = null
  this.loop = true
  
  if( document.layers ){
    window.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP );
    window.onmousemove =  DHTMLScroll.prototype.doHScroll
    window.onmouseup   =  DHTMLScroll.prototype.doStop
  }
  else{
    document.onmousemove = DHTMLScroll.prototype.doHScroll
    document.onmouseup   = DHTMLScroll.prototype.doStop
    this.startDrag       = parseInt( event.clientX )
  }  
  
}

function DHTMLScroll_vScroll( theEvent ){
  if( !this.loop ){
    return
  }
  
  var offset = this.ref_VSCROLL.getY();
  if( document.layers ){
    offset += parseInt( theEvent.layerY ); 
  }
  else{
    offset +=  parseInt( event.clientY - this.startDrag  );
    this.startDrag = event.clientY
  }
  
  var maxY 
  if( document.layers ) {
    maxY = this.ref_VBODY.clip.height 
  }
  else{
    maxY = this.ref_VBODY.offsetHeight
  }
  maxY -= this.ref_VSCROLL.getHeight()
  
  offset = offset<0?0:(offset>maxY?maxY:offset)
  
  this.ref_VSCROLL.setY( offset );
  this.relativeVScroll( offset )
}


function DHTMLScroll_hScroll( theEvent ){
  
  if( !this.loop ){
    return
  }
  
  var offset = this.ref_HSCROLL.getX();
  if( document.layers ){
    offset += parseInt( theEvent.layerX ) ; 
  }
  else{
    offset += parseInt( event.clientX - this.startDrag );
    this.startDrag = event.clientX 
  }
  
  
  var maxX
  
  if( document.layers ) {
    maxX = this.ref_HBODY.clip.width 
  }
  else{
    maxX = this.ref_HBODY.offsetWidth
  }
  
  maxX -= this.ref_HSCROLL.getWidth()
  
  offset = offset<0?0:(offset>maxX?maxX:offset)

  this.ref_HSCROLL.setX( offset )
  this.relativeHScroll( offset )    
}


function DHTMLScroll_relativeVScroll( offset ){
  var A,B,C
  
  B = this.dhtmlScrollArea.getScrollHeight()
  if( document.layers ) {
    A = this.ref_VBODY.clip.height 
  }
  else{
    A = this.ref_VBODY.offsetHeight 
  }
  
  A -= this.ref_VSCROLL.getHeight()
  
  C = parseInt(offset*B/A)
  
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.content.setY( -C )
  }
  
}

function DHTMLScroll_relativeHScroll( offset ){
  var A,B,C
  
  B = this.dhtmlScrollArea.getScrollWidth()
  if( document.layers ) {
    A = this.ref_HBODY.clip.width 
  }
  else{
    A = this.ref_HBODY.offsetWidth
  }
  
  A -= this.ref_HSCROLL.getWidth()
  
  C = parseInt(offset*B/A)
  
  if( this.dhtmlScrollArea != null ){
    this.dhtmlScrollArea.content.setX( -C )
  }
}

function doHScrollBody( theEvent ){
  var dhtmlObject
  var offset
  var width 
  
  if( theEvent ){
    dhtmlObject = theEvent.target.dhtmlObject    
    width = dhtmlObject.ref_LEFT.clip.width
    offset = theEvent.pageX
  }
  else{
    if( event.srcElement.dhtmlObject ){
      dhtmlObject = event.srcElement.dhtmlObject
      offset = event.clientX
      width = dhtmlObject.ref_LEFT.offsetWidth
    }
   }
   
   offset -= (dhtmlObject._left + width )

  var maxX
  
  if( document.layers ) {
    maxX = dhtmlObject.ref_HBODY.clip.width 
  }
  else{
    maxX = dhtmlObject.ref_HBODY.offsetWidth
  }
  
  maxX -= dhtmlObject.ref_HSCROLL.getWidth()
  
  offset = offset<0?0:(offset>maxX?maxX:offset)

  dhtmlObject.ref_HSCROLL.setX( offset )
  dhtmlObject.relativeHScroll( offset )       
}


function doVScrollBody( theEvent ){
  var dhtmlObject
  var offset
  var height 
  
  if( theEvent ){
    dhtmlObject = theEvent.target.dhtmlObject    
    height = dhtmlObject.ref_LEFT.clip.height
    offset = theEvent.pageY
  }
  else{
    if( event.srcElement.dhtmlObject ){
      dhtmlObject = event.srcElement.dhtmlObject
      offset = event.clientY
      height = dhtmlObject.ref_LEFT.offsetHeight
    }
   }
   
   offset -= (dhtmlObject._top + height )


  var maxY 
  if( document.layers ) {
    maxY = dhtmlObject.ref_VBODY.clip.height 
  }
  else{
    maxY = dhtmlObject.ref_VBODY.offsetHeight
  }
  maxY -= dhtmlObject.ref_VSCROLL.getHeight()
  
  offset = offset<0?0:(offset>maxY?maxY:offset)
  
  dhtmlObject.ref_VSCROLL.setY( offset );
  dhtmlObject.relativeVScroll( offset )
}

