/*  JavaScript toolbox
    General tools for JavaScript development
    
    Created 1 April 2005
      Jonathan Barrett

    Current Revision $Revision$
    Latest Change by $Author$ on $Date$
*/


/*  --  DOM API class  --  */

function  Dom_Object( id ) {
  if  ( !id || id == "" )  {
    return false;
  }
  
  if  ( document.getElementById ) {
    this.obj      = document.getElementById(id);
    this.style    = document.getElementById(id).style;
  }
  else
  if  ( document.all )  {
    this.obj      = document.all[id];
    this.style    = document.all[id].style;
  }
  else
  if  ( document.layers ) {
    this.obj      = document.layers[id];
    this.style    = document.layers[id];
  }
  
  function  get_value( )  {
    return  this.obj.value;
  }
  this.get_value  = get_value;
  
  function  print( tx ) {
    return  this.obj.innerHTML  = tx;
  }
  this.print  = print;
}

/*  --  DOM API collection class  --  */

function  Dom_Collection( ) {
  if  ( document.getElementsByTagName ) {
    this.obj      = document.getElementsByTagName("*");
  }
  else
  if  ( document.all )  {
    this.obj      = document.all
  }
}



/*  --  form actions  --  */

function  jump_menu( id )  {
  menu  = new Dom_Object(id);
  if  ( !menu ) {
    return  false;
  }
  
  loc = menu.get_value();
  document.location = loc;
  return  false;
}

function	focus_on( id )	{
	el	=	new Dom_Object(id);
  if  ( !el ) {
    return  false;
  }
  
  return	el.obj.focus();
}



/*  --  dhtml actions --  */

function  write_to_page( tx, id ) {
  nd  = new Dom_Object(id);
  if  ( nd.print )  {
    return  nd.print(tx);
  }
  else  {
    return  document.write(tx);
  }
}

function  hide_object( id ) {
  obj = new Dom_Object(id);
  if  ( !obj )  {
    return  false;
  }
  
  return  obj.style.display  = "none";
}

function  show_object( id ) {
  obj = new Dom_Object(id);
  if  ( !obj )  {
    return  false;
  }
  
  return  obj.style.display = "block";
}

function  toggle_object_display( id ) {
  obj = new Dom_Object(id);
  if  ( !obj )  {
    return  false;
  }
  
  if  ( obj.style.display != "block" ) {
    return  obj.style.display = "block";
  }
  else  {
    return  obj.style.display = "none";
  }
}



/*  --  initialiser methods --  */

function  add_event( o, et, f ) {
  if  ( o.addEventListener )  {
    o.addEventListener(et,f,true);
    return  true;
  }
  else
  if  ( o.attachEvent ) {
    return  r = obj.attachEvent("on"+et,f);
  }
  else  {
    return  false;
  }
}