// Thanks to Accessify. Added some tweaks for the icon behavior
// Use the following in your popup links:
// rel="popup {standard,console,fullScreen} width height noicon"

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
		
	type = type.toLowerCase();

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.outerWidth;
    myHeight = window.outerHeight;
    bl = window.screenX;
	bt = window.screenY;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    bl = window.screenLeft;
	bt = window.screenTop;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    bl = window.screenLeft;
	bt = window.screenTop;
  }
  

var topPos = ((myHeight-strHeight)/2)+bt;
var leftPos = ((myWidth-strWidth)/2)+bl;

	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable=yes,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top="+topPos+",left="+leftPos;
	if (type == "console" || type == "fullscreen") tools = "resizable=no,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",top="+topPos+",left="+leftPos;
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();

}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "console";
var w = "640";
var h = "480";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}

function findPopUps()
{
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if (popups[i].rel.indexOf("popup")!=-1)
		{
		// attach popup behaviour
		popups[i].onclick = doPopUp;
		// add popup indicator
		if (popups[i].rel.indexOf("noicon")==-1)
			{
			popups[i].style.backgroundImage = "url(/_gr/_universal/icon_popup.gif)";
			popups[i].style.backgroundPosition = "0 center";
			popups[i].style.backgroundRepeat = "no-repeat";
			popups[i].style.paddingLeft = "14px";
			}
		// add info to title attribute to alert fact that it's a pop-up window
		popups[i].title = popups[i].title + " [Opens in pop-up window]";
		}
	}
}

addEvent(window, 'load', findPopUps, false);


// Toggle visibility

function changeVisibility(domid,domtype){
var dv = document.getElementById(domid);
switch (domtype)
{
case "hide": 
	dv.style.display = 'none'; 
	break;
case "show": 
	dv.style.display = 'block';
	break;
case "toggleblock": 
	dv.style.display = (dv.style.display=='none'?'block':'none');
		break;
case "toggletext": 
	dv.style.visibility = (dv.style.visibility != 'hidden' ? 'hidden' : 'visible' );
}
}
