function setBGColour( mySelection, myBGColour )
{
	mySelection.style.backgroundColor = myBGColour;
}

function setClass( mySelection, myClass )
{
	mySelection.className = myClass;
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
			while(1) 
			{
				curleft += obj.offsetLeft;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
	else if(obj.x)
			curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
			while(1)
			{
				curtop += obj.offsetTop;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
	else if(obj.y)
			curtop += obj.y;
	return curtop;
}

function findWindowScrollXY() {
  var scrX = 0, scrY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrY = window.pageYOffset;
    scrX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrY = document.body.scrollTop;
    scrX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrY = document.documentElement.scrollTop;
    scrX = document.documentElement.scrollLeft;
  }
  return [ scrX, scrY ];
}

function showPopup( popupDivID )
{
	var scroll = findWindowScrollXY();
	var scrollX = scroll[0];
	var scrollY = scroll[1];
	
	var winHeight = 0, winWidth = 0;
	// find window height and width
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		winHeight = window.innerHeight;
		winWidth = window.innerWidth;
	} else if( document.documentElement &&  document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		winHeight = document.documentElement.clientHeight;
		winWidth = document.documentElement.clientWidth;
	} else if( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		winHeight = document.body.clientHeight;
		winWidth = document.body.clientWidth;
	}
	
	// set visibility, position and width of popup div
	var popupDiv = document.getElementById( popupDivID );
	popupDiv.style.visibility='visible';
	popupDiv.style.top = 40 + scrollY + 'px';
	popupDiv.style.left = scrollX + 'px';
	popupDiv.style.width = winWidth + 'px';
	
	// set visibility and position of background div
	var popupBG = document.getElementById('PopupBG');
	popupBG.style.visibility='visible';
	popupBG.style.top = scrollY + 'px';
	popupBG.style.left = scrollX + 'px';
  
	var popupMain = document.getElementById(popupDivID + 'Main');
	// if popup is too tall for window...
	if(popupMain.offsetHeight > (winHeight - 80)) {
		// ...adjust content width to allow for scrollbar...
		var contentDiv = document.getElementById(popupDivID + 'Content');
		contentDiv.style.marginLeft = '10px';
		contentDiv.style.marginRight = '10px';
		// ...and reduce popup height
		contentDiv.style.width = contentDiv.offsetWidth - 20 + 'px';
		popupMain.style.height = winHeight - 80 + 'px';
		popupMain.style.overflow = 'scroll';
	}
	
	document.body.style.overflow='hidden';		// remove scrollbars
	window.scroll(scrollX,scrollY);				// scroll back to original window position (Firefox)
}

function hidePopup( popupDivID )
{
	document.getElementById( popupDivID ).style.visibility='hidden';
	document.getElementById('PopupBG').style.visibility='hidden';
	document.body.style.overflow='auto';
}