// Javascript with general functions and methods

// cross browser function to get reference to object
function getElement(id){    
	if(document.getElementById){
		getElement = function(id){ return document.getElementById(id); }
	}else if(document.all){
		getElement = function(id){ return document.all[id]; };
	}else if(document.layers){
		getElement = function(id){ return document.layers[id]; };
	}else{
		getElement = function() { return null; }
	}    
	// When we get here, the getElement function has been replaced.
	// So we return the result of the new function.
	return getElement(id);
}

// cross browser function to add loading scripts
function AddOnload(myfunc){
  if(window.addEventListener)
    window.addEventListener('load', myfunc, false);
  else if(window.attachEvent)
    window.attachEvent('onload', myfunc);
}

// cross browser function to get size and positions
function getElementDimensions(obj) {
  var objLeft = objTop = objHeight = objWidth = 0;
  if (obj.offsetParent) {
    objLeft = obj.offsetLeft
    objTop = obj.offsetTop     
    objHeight = obj.offsetHeight
    objWidth = obj.offsetWidth      
    while (obj = obj.offsetParent) {
      objLeft += obj.offsetLeft
      objTop += obj.offsetTop
    }
  }
	return [objLeft,objTop,objHeight,objWidth];
}

function getWindowDimensions() {
  var winWidth = winHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winWidth = document.documentElement.clientWidth;
    winHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winWidth = document.body.clientWidth;
    winHeight = document.body.clientHeight;
  }
  return [winWidth,winHeight];
}

// cookie functions
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
  var mycookie = name + "=" + escape( value ) +
  ((expires) ? "; expires=" + expires : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = mycookie;
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Apr-98 00:00:01 GMT";
  }
}


