//*****getBrowser v1.0
function getBrowser()
{
  var nav = navigator.appName;
  var ver = navigator.appVersion;
  
  //no need to do an extensive search.. most browser respond to ie5+ and ns6+
  this.dom = document.getElementById?1:0;
  this.ie4 = !this.dom && document.all?1:0;
  this.ie5 = this.dom && ver.indexOf("MSIE")>=1?1:0;
  this.ns4 = !this.dom && document.layers?1:0;
  this.ns6 = this.dom && parseInt(ver)>=5?1:0;
  //short
  this.ie = this.ie4 || this.ie5?1:0;
  this.ns = this.ns4 || this.ns6?1:0;
  
  return this;
}
var br;
br = new getBrowser();

//*****getDiv v1.0
function getDiv(id)
{
  if(br.ie5 || br.ns6)
    return document.getElementById(id);
  else if(br.ns4)
    return document.layers[id];
  else if(br.ie4)
    return eval("document.all." + id);
  
  return null;
}

//*****hideDiv v1.2
//v1.2 return true
//v1.1 check for valid div.
function hideDiv(id)
{
  var div;
  div = getDiv(id);

  //valid div
  if(div == null)
    return false;
    
  if(br.ns4)
    div.visibility = "hidden";
  else
    div.style.visibility = "hidden";
  return true;
}

//*****showDiv v1.2
//v1.2 return true
//v1.1 check for valid div.
function showDiv(id)
{
  var div;
  div = getDiv(id);

  //valid div
  if(div == null)
    return false;

  if(br.ns4)
    div.visibility = "visible";
  else
    div.style.visibility = "visible";
  return true;
}

//*****moveDiv v1.2
//v1.2 return true
//v1.1 check for valid div.
function moveDiv(id,x,y)
{
  var div;
  div = getDiv(id);

  //valid div
  if(div == null)
    return false;
      
  if(br.ns4)
    div.moveTo(x,y);
  else if(br.ie)
  {
    div.style.pixelLeft = x;
    div.style.pixelTop = y;
  }
  else if(br.ns6)
  {
    div.style.left = x;
    div.style.top = y;
  }
  return true;
}

//*****bgDiv v1.1
//v1.1 return true
function bgDiv(id,color)
{
  var div;
  div = getDiv(id);

  //valid div
  if(div == null)
    return false;

  if(br.dom)
    div.style.background = color;
  return true;
}

//*****innerDiv v1.2
//v1.2 added append
//v1.1 return true
function innerDiv(id,src,append)
{
  var div;
  div = getDiv(id);

  //valid div
  if(div == null)
    return false;
  
  if(!append)
    div.innerHTML = src;
  else
    div.innerHTML = div.innerHTML + src;
    
  return true;
}

//*****infoDiv v1.0
//v1.0 return top,left,bottom,right,width,height (IE ONLY FOR NOW)
function infoDiv(id)
{
  var d;
  
  if(!br.ie)
    return false;

  d = getDiv(id);
  if(d)
  {
    this.top = d.offsetTop;
    this.left = d.offsetLeft;
    this.bottom = d.offsetHeight + d.offsetTop;
    this.right = d.offsetWidth + d.offsetLeft;
    this.width = d.offsetWidth;
    this.height = d.offsetHeight;
    return this;
  }
  else
    return "";
}

//*********************
//*****SCREEN INFORMATION
//*********************
//*****v1.0 Ie only
function infoScreen()
{
  var b;
  
  if(br.ie)
  {
    b = document.body;
    //window properties
    this.width = b.clientWidth;
    this.height = b.clientHeight;
    this.top = b.scrollTop;
    this.left = b.scrollLeft;
    this.bottom = this.height + this.top;
    this.right = this.width + this.left;
    return this;
  }
  else if(br.ns)
  {
    //window properties
    this.width = window.innerWidth;
    this.height = window.innerHeight;
    this.top = window.pageYOffset;
    this.left = window.pageXOffset;
    this.bottom = this.height + this.top;
    this.right = this.width + this.left;
    return this;
  }
    //window properties
/*    //div properties
    if(br.ns6)
    {
      pop_w = d.offsetWidth+16;
      pop_h = d.offsetHeight+16;
    }
    else
    {
      pop_w = d.document.width;
      pop_h = d.document.height;
    }*/
}


//*********************
//*****EVENT FUNCTION (include them all for script to work properly)
//*********************

//*****getPos v1.1
//v1.1 added scrollLeft to always get an accurate valu of X using ie
//ev is for netscape (ie uses global self.event)
function mouse_event()
{
  return; //function prototype (to be redefined)
}
function mouseUp()
{
  return; //function prototype (to be redefined)
}
function mouseDown()
{
  return; //function prototype (to be redefined)
}

function getPos(ev)
{
  if(br.ie)
  {
    br.x = event.clientX+document.body.scrollLeft;
    br.y = event.clientY+document.body.scrollTop;
  }
  else if(br.ns)
  {
    br.x = ev.pageX;
    br.y = ev.pageY;
  }
  else
  {
    br.x = 0;
    br.y = 0;
  }
  //redef this if needed
  mouse_event();
}

//*****captureEvent Div v1.0
//some function like 'mouseUp' need to be coded outside this lib
function captureMouse()
{
  //event mousemove to keep x & y
  if(br.ns)
  {
    document.captureEvents(Event.MOUSEMOVE);
    document.captureEvents(Event.MOUSEUP);
  }
  document.onmousemove=getPos;
  document.onmouseup=mouseUp;
  document.onmousedown=mouseDown;
}