function getobj(id) {
  return document.getElementById ?
             document.getElementById(id) :
             document.all[id];
}

function add(parent, tag, attr) {
  var el = document.createElement(tag);
  if (attr) {
    for (key in attr) {
      el[key] = attr[key];
    }
  }
  if (parent) parent.appendChild(el);
  return el;
}

function findpos(obj) {
  var x=0, y=0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      x += obj.offsetLeft;
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
  } else {
    if (obj.x) x += obj.x;
    if (obj.y) y += obj.y;
  }
  return [x,y];
}

function xmlhttpreq() {
  if (window.XMLHttpRequest) {
    xmlhttpobj = new XMLHttpRequest()
  } else {
    try {
      xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttpobj = null;
      }
    }
  }
  return xmlhttpobj;
}

function doreq(url,orsc) {
  var req = xmlhttpreq();
  req.open("GET", url, true);
  req.onreadystatechange = (function(r,e){return function() {
      if(r.readyState==4&&r.status&&r.status==200)e(r);
  }})(req,orsc);
  req.send("");
}

function setopacity(obj,o) {
  if (o>1) o=1;
  if (o<0) o=0;
  obj.style.opacity = o;
  obj.style.filter = "alpha(opacity=" + (o*100) + ")";
}

function removecontents(obj) {
  while(obj.childNodes.length > 0) {obj.removeChild(obj.firstChild);}
}




var evntmgr = new Object();
evntmgr.list = new Array();
evntmgr.intlist = new Array();
evntmgr.intrate = 250;

evntmgr.register = function(evnt,fn) {
  if (evnt.indexOf("interval:") == 0) {
    evntmgr.intlist.push([fn,0,evnt.substr(9)]);
  } else {
    if (!evntmgr.list[evnt]) { evntmgr.list[evnt] = new Array(); }
    evntmgr.list[evnt].push(fn);
  }
};

evntmgr.invoke = function(evnt, args) {
  if (evntmgr.list[evnt]) {
    for (var i=0; i<evntmgr.list[evnt].length; i++) {
      evntmgr.call(evntmgr.list[evnt][i], args);
    }
  }
};

setInterval("evntmgr.checkint()", evntmgr.intrate);
evntmgr.checkint = function() {
  for(var i=0; i<evntmgr.intlist.length; i++) {
    evntmgr.intlist[i][1]+=evntmgr.intrate;
    if (evntmgr.intlist[i][1] >= evntmgr.intlist[i][2]) {
      evntmgr.intlist[i][1] %= evntmgr.intlist[i][2];
      evntmgr.call(evntmgr.intlist[i][0]);
    }
  }
};

evntmgr.call = function(fn, args) {
  if (!fn) return;
  if (fn.constructor == Function) {
    fn(args);
  } else if (fn.constructor == String) {
    try {
      eval(fn);
    } catch (e) {}
  }
};

window.onload = function() { evntmgr.invoke("load"); };
window.onunload = function() { evntmgr.invoke("unload"); };
window.onresize = function() {
  var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  evntmgr.invoke("resize", [w,h]);
};
window.onclick = function() { evntmgr.invoke("click"); };
document.onmousemove = function(e) {
  var x,y;
  if (e) {
    x = e.pageX;
    y = e.pageY;
  } else {
    x = event.clientX + document.body.scrollLeft;
    y = event.clientY + document.body.scrollTop;
  }
  evntmgr.invoke("mousemove", [x,y]);
};
document.onkeypress = function(e) {
  var kc = e ? e.which : event.keyCode;
  evntmgr.invoke("keypress", kc);
};

evntmgr.register("load", window.onresize);




var infopop = {};
infopop.dom = {};

infopop.show = function(content) {
  infopop.dom.content.innerHTML=content;
  infopop.dom.div.style.display="inline";
};
infopop.hide = function() {
  infopop.dom.div.style.display="none";
};

evntmgr.register("mousemove", function(args) {
  if (!infopop.ready) return;
  infopop.dom.div.style.left = args[0]+15+"px";
  infopop.dom.div.style.top  = args[1]+ 7+"px";
});

evntmgr.register("load", function() {
  var body = document.getElementsByTagName("body")[0];
  with((infopop.dom.div = add(body, "div", {id:'infopop'})).style) {
    position = "absolute";
    display = "none";
    padding = "2px";
    zIndex = "1000";
    opacity = ".9";
    backgroundColor = "#eeeeee";
    border = "1px solid #aaaaaa";
    color = "#000000";
  }
  infopop.dom.content = add(infopop.dom.div, "span", {id:'infopop_content'});
  infopop.ready = true;
});


