var openedWindow;

function openWindow(windowURL, windowName, windowWidth, windowHeight, isResizable, isMenuVisibled) {
	var userAgent = navigator.userAgent;
	var ie = /MSIE/.test(userAgent);
	var windowAttributes;
	var resizableString;
	var menuBarString;

	var positionX = (screen.availWidth / 2) - (windowWidth / 2);
	var positionY = (screen.availHeight / 2) - (windowHeight / 2);

	if (isResizable) {
		resizableString = "resizable=yes, scrollbars=yes";
	}
	else {
		resizableString = "resizable=no, scrollbars=no";
	}
	
	if (isMenuVisibled) {
		menuBarString = ", menubar=yes";
	}
	else {
		menuBarString = ", menubar=no";
	}	

	if (ie) {
		windowAttributes = "width=" + windowWidth + ", height=" + windowHeight + ", left=" + positionX + ", top=" + positionY + ", directories=no, status=no, toolbar=no, " + resizableString + menuBarString;
	}
	else {
		windowAttributes = "width=" + windowWidth + ", height=" + windowHeight + ", screenX=" + positionX + ", screenY=" + positionY + ", dependent=yes, directories=no, titlebar=no, status=no, toolbar=no, " + resizableString + menuBarString;
	}

	openedWindow = window.open(windowURL, windowName, windowAttributes);

	if (window.focus) {
		openedWindow.focus()
	}

	return false;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} 
	else {
		window.onload = function() { 
			if (oldonload) { oldonload(); } 
			func(); 
		} 
	} 
}

function addUnLoadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} 
	else {
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
} 
