/*V7.3*/
//
// Francois Simard
//  08/02/2002
// CROSS-BROWSER FUNCTIONS. THIS FILE IS USED BY OTHER SCRIPTS AND TK'S

// FOR NETSCAPE 6 and up

// Magical code for NS6. Implement the insertAdjacent Function.
if (document.childNodes&&!document.childNodes[0].insertAdjacentHTML)
  {
    HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
      {
        switch (where)
          {
            case 'beforeBegin':
              this.parentNode.insertBefore(parsedNode,this)
              break;
            case 'afterBegin':
              this.insertBefore(parsedNode,this.firstChild);
              break;
            case 'beforeEnd':
              this.appendChild(parsedNode);
              break;
            case 'afterEnd':
              if (this.nextSibling)
            	  this.parentNode.insertBefore(parsedNode,this.nextSibling);
              else
                this.parentNode.appendChild(parsedNode)
              break;
          }
      }

    HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
      {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var parsedHTML = r.createContextualFragment(htmlStr);
        this.insertAdjacentElement(where,parsedHTML)
      }
        
    HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
      {
        var parsedText = document.createTextNode(txtStr)
        this.insertAdjacentElement(where,parsedText)
      }
  }

var isMac = (navigator.userAgent.indexOf('Mac') == -1) ? false : true; // If it's any browser on MAc
var mac4  = (isMac && document.all && navigator.appVersion.indexOf('MSIE 4.5') != -1) ? true : false;

// Write to the document the given string. Has to be called before the onload event or this function will overwrite the whole page
function WC(content)
{
  document.body.insertAdjacentHTML('beforeEnd', content);
};

// Create Div
function CD(eleName, zID, dWidth, visibleVal)
{
  document.body.insertAdjacentHTML('beforeEnd', "<DIV id=\""+eleName+"\" STYLE=\"position:absolute;visibility:"+visibleVal+";z-index:"+zID+";left:0;top:0;\">&nbsp;</DIV>");
  return eleName;
}

// ChangeDivContent - Overwrite the div content with the given string
// ind being the Div ID (or layer tag for netscape) and newContent is the html code to put in the div
function CDC(ind, newContent)
{
  document.getElementById(ind).innerHTML = newContent;
};

// SetVisibility - Set the div Visibility
// divnum : Div (layer) ID
// vis : Either 'visible' or 'hidden'
function SV(divNum, vis)
{
  document.getElementById(divNum).style.visibility = vis;
};

// SetVisibility - Set the div display
// divnum : Div (layer) ID
// vis : Either 'none' or ''
function SD(divNum, display)
{
  eval('document.getElementById(divNum).style.display = "'+ display + '"');
};

// IsVisible True if the div Visibility property is set to visible
function isV(lName)
{
  if(document.getElementById(lName).style.visibility == 'visible')
    return true;
  else
    return false;
}

// Get the Left value IE ONLY
// In IE, when you get the position of an object, it is relative to it's parent element
// for example, if an image is in a table, is left value will be the amount of pixels between the
// table border and it's borders.
function GetRealLeft(zName)
{
	var xPos = document.getElementById(zName).offsetLeft;

  tempEl = (mac4) ? document.getElementById(zName).parentElement : document.getElementById(zName).offsetParent;

  while (tempEl != null)
    {
      xPos  += tempEl.offsetLeft;
    	tempEl = (mac4) ? tempEl.parentElement : tempEl.offsetParent;
    }
  return xPos;
};

// Get the Top value IE ONLY
// Same as GetRealLeft but for Top position
function GetRealTop(zName)
{
  var yPos   = document.getElementById(zName).offsetTop;
	
	tempEl = (mac4) ? document.getElementById(zName).parentElement : document.getElementById(zName).offsetParent;

  while (tempEl != null)
    {
      yPos  += tempEl.offsetTop;
    	tempEl = (mac4) ? tempEl.parentElement : tempEl.offsetParent;
    }
  return yPos;
};

// GetLeft - Return the LEFT value of a div
function GL(divNum)
{
  return document.getElementById(divNum).offsetLeft;
};

// GetTop - Return the TOP value of a div (or an element in IE)
// Same as GetLeft
function GT(divNum)
{
  return document.getElementById(divNum).offsetTop;
};

// SetLayerSize - Set the width and height of a div
// divNum: div ID
function SLS(divNum, wVal, hVal)
{
  document.getElementById(divNum).width  = wVal;
  document.getElementById(divNum).height = hVal;
};

// SetIndex - Set the index of a div
// Property z-index is used to place a layer on top of another one
function SI(divNum, val)
{
  document.getElementById(divNum).style.zIndex = val;
};

// MoveDivR - Move a given div
function MDR(divNum, topVal, leftVal)
{
  document.getElementById(divNum).style.top  = topVal;
  document.getElementById(divNum).style.left = leftVal;
};

// Returns the Object. If it does'nt exist, you get undefined
// so in your code, you can do : if( ItemExist("divName"))...
function ItemExist(dId)
{
  return document.getElementById(dId);
};

// Check if an image exist.
function ImageExist(dId)
{
  return document.images[dId];
};

// Get Screen Available Height
// (if the user resize his browser window, this value changes)
function GSH()
{
  return window.innerHeight;
};

// Get Screen Available Width
function GSW()
{
  return window.innerWidth;
};

//Event Stuff

//Get the Mouse X Pos
// ev is the event object from Netscape.
function GMouseX(ev)
{
  return ev.pageX;
};

//Get the Mouse Y Pos
// ev is the event object from Netscape.
function GMouseY(ev)
{
  return ev.pageY;
};

// Get Scroll Top (Used by GmouseY)
// If the user scroll down, this value is incremented
function GST()
{
  return window.pageYOffset;
};

// Get Scoll Left
function GSL()
{
  return window.pageXOffset;
};

// Get the element name from the event Object
function GE(ev)
{
  return ev.target.name;
};

// 2 functions for netscape 6 only when getting left and top value of an image.
// Get the image Left value
function GetRealImgLeft(zName)
{
	var xPos   = document.images[zName].offsetLeft;
	tempEl = document.images[zName].offsetParent;
  	while (tempEl != null)
    	{
    		xPos  += tempEl.offsetLeft;
    	  tempEl = tempEl.offsetParent;
    	}
   return xPos;
};

// Get the image Top value IE and NS6+ ONLY
function GetRealImgTop(zName)
{
  var yPos   = document.images[zName].offsetTop;
  tempEl = document.images[zName].offsetParent;
 	while (tempEl != null)
    {
      yPos  += tempEl.offsetTop;
    	tempEl = tempEl.offsetParent;
    }
   return yPos;
};

function GetImageWidth(ele)
{
  return GetWidth(ele);
}

function GetImageHeight(ele)
{
  return GetHeight(ele);
}

// Get the width of a div
function GetWidth(ele)
{
  return document.getElementById(ele).offsetWidth;
};

// Get the height of a div
function GetHeight(ele)
{
  return document.getElementById(ele).offsetHeight;
};