var grabbed = new Array()
var posx = 0
var posy = 0
var preposx = 0
var preposy = 0


function mouse( e )
{
  if( !e ) var e = window.event
  if( e.pageX || e.pageY )
  {
    posx = e.pageX
    posy = e.pageY
  }
  else //if( e.clientX || e.clientY )
  {
    posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft
    posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop
  }
  if( grabbed[4] )
    div_move()
}


function div_move()
{
  if(preposx || preposy)
  {
    document.getElementById( grabbed[0] ).style.top = parseInt( document.getElementById( grabbed[0] ).style.top ) + posy - preposy
    document.getElementById( grabbed[0] ).style.left = parseInt( document.getElementById( grabbed[0] ).style.left ) + posx - preposx
  }
  preposx = posx
  preposy = posy
}


function div_grab( id )
{
  grabbed[0] = id
  grabbed[1] = document.getElementById( id ).style.top
  grabbed[2] = document.getElementById( id ).style.left
  grabbed[3] = document.getElementById( id ).style.zIndex
  grabbed[4] = 1
  document.getElementById( id ).style.zIndex = 98
  document.getElementById( id ).style.cursor = "move"
}


function div_release()
{
  document.getElementById( grabbed[0] ).style.zIndex = grabbed[3]
  document.getElementById( grabbed[0] ).style.cursor = "default"
  grabbed = new Array()
  preposx = 0
  preposy = 0
}

onmousemove = mouse
