function popup(url, title, width, height, scroll) {
	var s = 'menubar=no,toolbar=no,location=no,resizable=yes,status=yes'
	s += ',scrollbars=' + scroll
	s += ',width=' + width + ',height=' + height;
	s += ',top=' + (screen.availHeight - height) / 2 + ',left=' + (screen.availWidth - width) / 2;

	//close existing window
	if (navigator.newwindow) navigator.newwindow.close();
	
	//save new window object in navigator object and activate
	navigator.newwindow = self.open(url, title, s);
	navigator.newwindow.focus();
	
	return false;
}

function popupDefault() {
	return popup('', 'DefaultPopup', 600, 500, 'yes')
}

function CloseWindow() {
	//Close window and activate opener
	window.close();
	if (window.opener)
		if (!window.opener.closed)
			window.opener.focus();
}

function addPopupEvents(wnd) {
	//Add event for keydown to trap escape key
	if (!wnd) {
		wnd = window;
	}
	if (wnd && wnd.document) {
		wnd.document.onkeydown = KeyDown;
	}
}

function KeyDown(e) {
	//Close window on escape key
	if (e && e.which == 27) CloseWindow(); //Netscape
	else if (event && event.keyCode == 27) CloseWindow(); //IE
}

function addEvent(obj, evType, fn) {
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		var r = null; //fallbackAddEventListener(obj, evType, fn);
		return r
	}
	return false;
}
