var op=navigator.userAgent.indexOf('Opera')!=-1;
var mo=navigator.userAgent.indexOf('Mozilla')!=-1;
var ie=navigator.userAgent.indexOf('IE')!=-1;
var op7=navigator.userAgent.indexOf('Opera 7')!=-1;
var op8=navigator.userAgent.indexOf('Opera 8')!=-1;

var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;

function getRef(id) {
   if (isDOM) return document.getElementById(id);
   if (isIE4) return document.all[id];
   if (isNS4) return document.layers[id];
}
function getSty(id) {return (isNS4 ? getRef(id) : getRef(id).style);}

function colorObj(o, c){var s=getSty(o); return s.backgroundColor=c;}
function colorObjTxt(o, c) {var s=getSty(o); return s.color=c;}

function showObj(o) {var s=getSty(o); return s.visibility="visible";}
function hideObj(o) {var s=getSty(o); return s.visibility="hidden";}

// moveObj() requires string inputs
function moveObj(o, x, y){var s=getSty(o); s.left=x; return s.top=y;}
// moveObjn() requires numerical inputs
function moveObjn(o, x, y){var s=getSty(o); s.left=""+x+"px"; return s.top=""+y+"px";}

function getObjTop(obj){
  var e = getRef(obj);
  var r = 0;
  if (document.defaultView){
    var style=document.defaultView;
    var cssDecl=style.getComputedStyle(e, "");
    r=cssDecl.getPropertyValue("top");
  }
  else if (e.currentStyle) {r=e.currentStyle.top;}
  else if (e.style) {r=e.style.top;}
  else if (isNS4) {r=e.top;}
  return parseInt(r)
}
function getObjLeft(obj){
  var e = getRef(obj);
  var r = 0;
  if (document.defaultView){
    var style=document.defaultView;
    var cssDecl=style.getComputedStyle(e, "");
    r=cssDecl.getPropertyValue("left");
  }
  else if (e.currentStyle) {r=e.currentStyle.left;}
  else if (e.style) {r=e.style.left;}
  else if (isNS4) {r=e.left;}
  return parseInt(r)
}
function getObjWidth(obj){
  var e = getRef(obj);
  var r = 0;
  if (e.offsetWidth){
    if (e.scrollWidth && (e.offsetWidth != e.scrollWidth)){r = e.scrollWidth;}
    else {r = e.offsetWidth;}
  }
  else if (e.clip && e.clip.width){r=e.clip.width;}
  else if (e.style && e.style.pixelWidth) {r=e.style.pixelWidth;}
  return parseInt(r)
}
function getObjHeight(obj){
  var e = getRef(obj);
  var r = 0;
  if (e.offsetHeight){r=e.offsetHeight;}
  else if (e.clip && e.clip.height){r=e.clip.height;}
  else if (e.style && e.style.pixelHeight){r=e.style.pixelheight;}
  return parseInt(r)
}
function getObjRight(obj){
  var l=getObjLeft(obj);
  return l + getObjWidth(obj);
}
function getObjBottom(obj){
  var t=getObjTop(obj);
  return t + getObjHeight(obj);
}
function getWindowWidth(){
  if (window.innerWidth) {return window.innerWidth;}
  else if (isIE6CSS) {return document.body.parentElement.clientWidth;}
  else if (document.body && document.body.clientWidth){return document.body.clientWidth;}
  return 0;
}
function getWindowHeight(){
  if (window.innerHeight) {return window.innerHeight;}
  else if (isIE6CSS) {return document.body.parentElement.clientHeight;}
  else if (document.body && document.body.clientHeight){return document.body.clientHeight;}
  return 0;
}
// centerObj() centers the object horizontally with a 5px minimum on the left -- the following function handles 
//    the idea of margins with greater flexibility
function centerObj(o){
  var w=getObjWidth(o);
  var l=getWindowWidth()/2-w/2;
  var s=getSty(o);
  if (l>=5) return s.left=""+l+"px";
  else return s.left=""+2+"px";
}
function ctrObjN(o,l,t){    // this varies in that it sets margins on the left (l) and top (t)
  var w=getObjWidth(o);
  var lf=getWindowWidth()/2-w/2;
  var s=getSty(o);
  if (lf>=l) return s.left=""+lf+"px";
  else return s.left=""+l+"px";
}
// The following centering functions do not set any limit on where the left and/or top can be -- portions could be offscreen
function ctrObjV(o){
  var h=getWindowHeight();
  var s=getSty(o);
  return s.top=""+(h - getObjHeight(o))/2+"px";
}
function ctrObjH(o){
  var w=getWindowWidth();
  var s=getSty(o);
  return s.left=""+(w - getObjWidth(o))/2+"px";
}
function ctrObj(o){
  ctrObjV(o);
  return ctrObjH(o);
}


