function NewWindow(mypage, myname, w, h, scroll) {

  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;

  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)

  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  
}

function isMoz() {
	if ( (window.navigator.userAgent.indexOf("Mozilla") != -1) && (navigator.product == "Gecko") ) {
		return true;
	}
	else {
		return false;
	}
}

function initPopUp() {
	maxWidth = 570;
	maxHeight = 570;
	
	popupHeight=(document.getElementById('entireBody')).offsetHeight;
	popupWidth=(document.getElementById('entireBody')).offsetWidth;
	
	popupWidth=(popupWidth < maxWidth ? popupWidth : maxWidth);
	popupHeight=(popupHeight < maxHeight ? popupHeight : maxHeight);
	
	popupWidth = maxWidth;
	
	if (isMoz()) {
		window.innerHeight = popupHeight;
		window.innerWidth = popupWidth;
	}
	else {
		diffHeight = popupHeight - (document.body.clientHeight + 10);
		diffWidth = popupWidth - document.body.clientWidth;
		window.resizeBy(diffWidth,diffHeight);
	}
}

var activeDivId = null;
var popupBlocked = false;
var hidElList = null;
var elsToHide = null;
var elsNotHid = false;

function Point(x, y) {
	this.x = x;
	this.y = y;
}

Point.prototype.toString = function() {
	return this.x + "x" + this.y;
}

function Rect(ul, br) {
	this.ul = ul;
	this.br = br;
	this.intersects = function(other) {return !((this.ul.x > other.br.x) || (this.br.x < other.ul.x) || (this.ul.y > other.br.y) || (this.br.y < other.ul.y));}
}

Rect.prototype.toString = function() {
	return "[" + this.ul.toString() + "-" + this.br.toString() + "]";
}

function getRect(el) {
	var ul = new Point(el.offsetLeft, el.offsetTop);
	var parent = el.offsetParent;
	while (parent && (parent.tagName.toUpperCase() != "BODY")) {
		ul.x += parent.offsetLeft;
		ul.y += parent.offsetTop;
		parent = parent.offsetParent;
	}
	var br = new Point(ul.x + el.offsetWidth, ul.y + el.offsetHeight)
	return new Rect(ul, br);
}

function OverlapElement(el) {
	this.el = el;
	this.iv = el.style.visibility;
	this.next = null;
	this.prev = null;
	this.restore = function () {
		this.el.style.visibility = this.iv;
	}
	this.getArea = function () {
		return getRect(this.el);
	}
	this.hide = function () {
		this.el.style.visibility = 'hidden';
	}
}

function unhideAll() {
	var c = hidElList;
	while (c != null) {
		c.restore();
		if (c.prev == null)
			hidElList = c;
		else
			c.prev.next = c.next;
		c = c.next;
	}
}

function unhideNonOverlapElements(apprRect) {
	var c = hidElList;
	while (c != null) {
		if (!apprRect.intersects(c.getArea())) {
			c.restore();
			if (c.prev == null)
				hidElList = c;
			else
				c.prev.next = c.next;
		}
		c = c.next;
	}
}

function detectElementsToHide() {
elsToHide = new Array();
	var sels = document.getElementsByTagName('SELECT');
	for (var j = 0; j < sels.length; j++)
		elsToHide[elsToHide.length] = sels[j];
if(!isMoz()) {
  var os = document.getElementsByTagName('OBJECT');
  for (var i = 0; i < os.length; i++) {
    var a = os[i].childNodes;
    var hide = true;
    for (var n = 0; n < a.length; n++) {
      var attr = a[n].attributes;
      var atst = '';
      var check = false;
      if(attr != null) {
        for (var e = 0; e < attr.length; e++) {
          if(attr[e].value != 'null' && attr[e].value != null && attr[e].value != '') {
            atst += attr[e].value.toUpperCase() + ' ';
          if(attr[e].value.toUpperCase() == 'WMODE')
            check = true;
          }
        }
        if (check && (atst.indexOf('TRANSPARENT') != -1 || atst.indexOf('OPAQUE') != -1)) {
          hide = false;
          elsNotHid = true;
          break;
        }
      }
    }
    if (hide)
      elsToHide[elsToHide.length] = os[i];
  }
}
else {
  var es = document.getElementsByTagName('EMBED');
  for (var ix = 0; ix < es.length; ix++) {
    var hidex = true;
    var attrx = es[ix].attributes;
    if(attrx != null) {
      for (var ex = 0; ex < attrx.length; ex++) {
        if(attrx[ex].name.toUpperCase() == 'WMODE' &&
            (attrx[ex].value.toUpperCase() == 'TRANSPARENT' || attrx[ex].value.toUpperCase() == 'OPAQUE')) {
          hidex = false;
          break;
        }
      }
    }
    if(hide)
      elsToHide[elsToHide.length] = es[i];
  }
}
	var as = document.getElementsByTagName('APPLET');
	for (var iy = 0; iy < as.length; iy++)
		elsToHide[elsToHide.length] = as[iy];
}


function hideOverlapElements(apprRect) {
	for (var i = 0; i < elsToHide.length; i++) {
		var el = elsToHide[i];
		var rect = getRect(el);
		if ((el.style.visibility.toUpperCase().indexOf('HIDDEN') == -1) && apprRect.intersects(getRect(el))) {
			var he = new OverlapElement(el);
			if (hidElList == null)
				hidElList = he;
			else {
				var t = hidElList;
				hidElList = he;
				he.next = t;
				t.prev = he;
			}
			he.hide();
		}
	}
}

function displayDiv(newDivId) {
    if (activeDivId != null)
        hideDiv(activeDivId);
	var el = document.getElementById(newDivId);
	if (el != null) {
		positionContent(newDivId);
		hideOverlapElements(getRect(el));
		el.style.visibility = "visible";
		activeDivId = newDivId;
	}
    window.focus();
}

function hideDiv(divId) {
	var el = document.getElementById(divId)
	if (el != null) {
		el.style.visibility = "hidden";
		unhideNonOverlapElements(getRect(el));
	}
}

function viewPoint(topOffset, leftOffset) {
	var b = document.body;
	var e = document.documentElement;
	
	topOffset = topOffset/100;
	leftOffset = leftOffset/100;
    
//    alert("1. topOffset = "+topOffset+"\n leftOffset = "+leftOffset);

    var clientHeight = e.clientHeight;
    var clientWidth = b.clientWidth;
    
//   alert("2. clientHeight = "+clientHeight+"\n clientWidth = "+clientWidth);

    if (window.innerHeight) { //Proper DOM (Mozilla)
        clientHeight = window.innerHeight;
        clientWidth = window.innerWidth;
        
//        alert("3. clientHeight = "+clientHeight+"\n clientWidth = "+clientWidth);
    }
    
	if (clientHeight == 0) {
        clientHeight = b.clientHeight;            
//        alert("4. clientHeight = "+clientHeight+"\n clientWidth = "+clientWidth);
    }
	
    clientHeight = clientHeight*(topOffset);
    clientWidth = clientWidth*(leftOffset);
    
//    alert("5. clientHeight = "+clientHeight+"\n clientWidth = "+clientWidth);
    
	var offset = new Point(0,0);

//    alert("b.scrollLeft = "+b.scrollLeft+"\n clientWidth = "+clientWidth+"\n offset.x = "+offset.x+"\n b.scrollTop = "+b.scrollTop+"\n e.scrollTop = "+e.scrollTop+"\n clientHeight = "+clientHeight+"\n offset.y = "+offset.y);
    
    return new Point(b.scrollLeft + clientWidth + offset.x,
                     b.scrollTop + e.scrollTop + clientHeight + offset.y);
}

function positionContent(el) {
	var pu = document.getElementById(el);
	var pnt = viewPoint(15,10);
	pu.style.top = (pnt.y) + "px";
	pu.style.left = (pnt.x) + "px";
    var elRect = getRect(pu);
	hideOverlapElements(elRect);
	unhideNonOverlapElements(elRect);

}

function centerScroll() {
	positionContent(activeDivId);
}

function disableCentering() {
    if (window.detachEvent) {
        window.detachEvent("onscroll", centerScroll);
    } else {
        window.removeEventListener("scroll", centerScroll, false);
    }        
}

function enableCentering() {
    if (window.attachEvent) {
        window.attachEvent("onscroll", centerScroll);
    } else {
        window.addEventListener("scroll", centerScroll, false);
    }
    
}

function openPopup(initDivId) {
  var openPopup = false;
  
  try {
    if (window._pRmWin && window._pRmWin.opener && window._pRmWin.winAvailable) {
     openPopup = true;
    }
  } catch (e) { openPopup = false; }
  if (!popupBlocked
        && !openPopup) { //bug 6070
     var ml = document.getElementById("maskLayer");
     ml.style.height = document.body.scrollHeight;
     ml.style.width = document.body.scrollWidth;
     detectElementsToHide();
     if(!isMoz() || (isMoz() && !elsNotHid))
       ml.style.visibility = "visible";
     displayDiv(initDivId);
     enableCentering();
  }
}

function blockPopup() {
	popupBlocked = true;
}

function closePopup() {
	var ml = document.getElementById("maskLayer");
	ml.style.visibility = "hidden";
	hideDiv(activeDivId);
	disableCentering();
	unhideAll();
}

function confirm_action() {
	return confirm("This action can not be undone.  If you are certain you want to do this, click 'OK'.");
}

function displayAlert(message) {
	alert(message);
	return
}