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

	CHANGEBACKGROUND :: 
	
********************************************************************/
function changeBackground (url) {
  
  if (document.layers) {
    if (!backgroundLayer) {
      backgroundLayer = new Layer(1);
    }
    background = url;
    //document.cookie = 'background=' + escape(background);
    var l = backgroundLayer;
    if (!url) 
	{
      var html = '<HTML>' + '<BODY BGCOLOR="' + document.bgColor + '"'
                + ' BACKGROUND="' + blankImage.src + '"><\/BODY><\/HTML>';
    }
    else 
    {  
	  var html = '<HTML><BODY BACKGROUND="' + url + '"><\/BODY><\/HTML>'; 
    } 
	
   l.zIndex = 0;
   //l.clip.width = window.innerWidth + 10;
   //l.clip.height = window.innerHeight + 10;  
   l.document.open();
   l.document.write(html);
   l.document.close();
   l.visibility = 'show';
  
  }
  else if (document.body)
    document.body.background = url;
}




/* directions for use:
put onload="Loaded();" in the body tag
create a div with a unique id and the following style attribute:
   style="position:absolute; top:0; left:0; visibility:hidden;"

Then you can use the following commands in any event handler (they 
will only work after the page has loaded, however)
   layerVis("foo","show|switch|hide");
      {"show" will make the "foo" div visible}
      {"switch" will make the "foo" div visible, hiding the previous div turned on}
      {"hide" makes "foo" hidden; this is the default}
   layerMatch("foo", "bar");
      {move the top-left corner of "foo" to the top-left corner of "bar"}
   layerMove("foo", 10, 25, "abs|rel");
      {moves "foo" to position 10, 25 (if "abs"olute), or moves it right 10 and down 25 (if "rel"ative)}
      {if niether "abs" nor "rel" is supplied, it defaults to "abs"}
   
Combine layerMatch() with layerMove("rel") to move the layer near another object
*/




function layerMatch(Div,Dest) {

   if (!PageLoaded) return;
   
   var It = findDiv(Div);
   var Li = getObjProps(Dest);
   
   It.style.left = Li.x;
   It.style.top  = Li.y;

}



function layerMove(Div, dX, dY, RelAbs) {

   if (!PageLoaded) return;
   
   var It = findDiv(Div);
   var bX = (RelAbs.toLowerCase().indexOf('rel') +1) ? parseInt(It.style.left) : 0;
   var bY = (RelAbs.toLowerCase().indexOf('rel') +1) ? parseInt(It.style.top)  : 0;
   
   if (!isNaN(bX) && !isNaN(bY) && !isNaN(dX) && !isNaN(dY)) {
      It.style.left = bX + dX;
      It.style.top  = bY + dY;
   }

}



var PrevLayer = "";
function layerVis(Div, Act) {

   if (!PageLoaded) return;
   
   var It = findDiv(Div);
   var Do = (Act == "show" || Act == "switch") ? "visible" : "hidden";
   It.style.visibility = Do;
   
   if (Act == "switch" && PrevLayer && PrevLayer != Div) {
      var Pr = findDiv(PrevLayer);
      Pr.style.visibility = "hidden";
   }
   if (Act == "switch")
   {
      PrevLayer = Div;
   }
  
}








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







function findDiv(Which) {

   if (NN4) {
      var Tmp = new Object();
      Tmp.style = document.layers[Which];
      return Tmp;
   }
   else if (IE4)
      return eval('document.all.'+Which);
   else if (DOM)
      return document.getElementById(Which);

}



function getRealOffset(Obj,TopLeft) {

   iPos = 0;
   while (Obj != null) {
      iPos += Obj["offset"+TopLeft];
      Obj   = Obj.offsetParent;
   }
   return iPos;

}

function getObjProps(Nm) {

   if (document.images[Nm]) {
      var I = document.images[Nm];
      if (DOM || IE4) {
         this.x = getRealOffset(I,"Left");
         this.y = getRealOffset(I,"Top");
         this.h = I.height;
         this.w = I.width;
      } else if (NN4) {
         this.x = I.x;
         this.y = I.y;
         this.h = I.height;
         this.w = I.width;
      }
   } else {
      var D = findDiv(Nm);
      this.x = D.style.left;
      this.y = D.style.top;
      this.h = D.style.height;
      this.w = D.style.width;
   }

   return this;

}










var OnLoadVar = "";
function addToOnLoad(Code) {
   if (Code.charAt(Code.length -1) != ";") Code += ";";
   OnLoadVar += Code;
}


function Loaded() {
   if (OnLoadVar) eval(OnLoadVar);
}


var NN4 = (document.layers)         ? true : false;
var IE4 = (document.all)            ? true : false;
var DOM = (document.getElementById) ? true : false;


var PageLoaded = false;
addToOnLoad("PageLoaded = true;");



if (NN4) {
   var GG_R = (top.onresize) ? top.onresize.toString():'{}';
   top.onresize = new Function(
      GG_R.substring(GG_R.indexOf('{') +1, GG_R.lastIndexOf('}')) + 
      "if (top.innerWidth!="+top.innerWidth+" || top.innerHeight!="+top.innerHeight+") top.location.reload();"
   );
}

