// Routines to manipulate DIV layers
// - mostly taken from: http://www.howtocreate.co.uk/

//****************************************************//
function getRefToDiv(divID,oDoc) {
  if( !oDoc ) { oDoc = document; }
  if( document.layers ) {
     if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } 
     else {
       //repeatedly run through all child layers
       for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
         //on success, return that layer, else return nothing
         y = getRefToDiv(divID,oDoc.layers[x].document); 
       }
       return y; 
     } 
  }
  if( document.getElementById ) {
      return document.getElementById(divID); 
  }
  if( document.all ) {
      return document.all[divID]; 
  }
  return false;
}

//****************************************************//
function hideDiv(divID) {
  myReference = getRefToDiv(divID);
  if( !myReference ) {
      window.alert('hideDiv:Nothing works in this browser');
      return false; //don't go any further
  }
  //now we have a reference to it
  if( myReference.style ) { //DOM & proprietary DOM
      myReference.style.visibility = 'hidden';
  } else {
      if( myReference.visibility ) { //Netscape
          myReference.visibility = 'hide';
      } else {
          window.alert('hideDiv:Nothing works in this browser');
          return false; //don't go any further
      }
  }
  return true;
}

//****************************************************//
function showDiv(divID) {
  myReference = getRefToDiv(divID);
  if( !myReference ) {
      window.alert('showDiv:Nothing works in this browser');
      return false; //don't go any further
  }
  //now we have a reference to it
  if( myReference.style ) { //DOM & proprietary DOM
      myReference.style.visibility = 'visible';
  } else {
      if( myReference.visibility ) { //Netscape
          myReference.visibility = 'show';
      } else {
          window.alert('showDiv:Nothing works in this browser');
          return false; //don't go any further
      }
  }
  return true;
}

//****************************************************//
function rwDiv(divID,contents) {
  var myReference = getRefToDiv(divID);
  if( !myReference ) { window.alert('rwDiv:Nothing works in this browser'); return; }
  if( myReference.innerHTML ) { myReference.innerHTML = contents; } else {
    if( myReference.document && myReference.document != window.document ) {
      myReference.document.open();
      myReference.document.write( contents );
      myReference.document.close();
    } else {
      window.alert('rwDiv:This browser does not allow the contents to be re-written.');
    }
  }
}

//****************************************************//
function moveDiv(divID,left,top) {
  var myReference = getRefToDiv(divID);
  var noPx = document.childNodes ? 'px' : 0;
  if( !myReference ) { window.alert('moveDiv:Nothing works in this browser'); return; }
  if( myReference.style ) { myReference = myReference.style; }
  myReference.left = (left) + noPx;
  myReference.top = (top) + noPx; 
}

//****************************************************//
function resizeDiv(divID,newWidth,newHeight) {
  var myReference = getRefToDiv(divID), noPx = document.childNodes ? 'px' : 0;
  if( myReference.style ) { myReference = myReference.style; }
  if( myReference.resizeTo ) { myReference.resizeTo( newWidth, newHeight ); }
  myReference.width = newWidth + noPx; myReference.pixelWidth = newWidth;
  myReference.height = newHeight + noPx; myReference.pixelHeight = newHeight;
}

//****************************************************//
function chColorDiv(divID,color) {
  var myReference = getRefToDiv(divID);
  if( !myReference ) { window.alert('Nothing works in this browser'); return; }
  if( myReference.style ) { myReference = myReference.style; }
  if( typeof( myReference.background ) != 'undefined' ) {myReference.background = color;} 
  else {
    if( myReference.backgroundColor ) { myReference.backgroundColor = color; } 
    else {
          if( typeof( myReference.bgColor ) != 'undefined' ) { myReference.bgColor = color; } 
	  else {window.alert('Nothing works in this browser'); return;} 
    } 
  }
}

//****************************************************//
