// Utility function to add an event listener
function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}
function loadScript(url)
{
    document.write('<script src="', url, '" type="text/javascript"></script>');
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
	( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement &&
      	( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function setObjectCenterXY(o,width,height)
{
	var windowXY = getWindowSize();
	var scrollXY = getScrollXY();
	o.style.position = 'absolute';
	o.style.left = scrollXY[0] + ((windowXY[0] - width) / 2) + 'px';
	o.style.top = scrollXY[1] + ((windowXY[1] - height) / 2) + 'px';
}

var PopupWin = null;
function OpenPopup(url,w,h) {
	if (PopupWin) { PopupWin.close(); }
	if (PopupWin==null || PopupWin.closed) {
		settings=
		 "left="+(screen.width-w)/2+","
		 +"top="+(screen.height-h)/2+","
		 +"width="+w+","
		 +"height="+h+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=yes,"
		 +"resizable=yes"
		 PopupWin = window.open(url,'PopupWin',settings);
	}
	PopupWin.focus();
}
