var windowsCount = 0;
var windowsArray = new Array();

function browserInfo() {
	alert("appName: " + navigator.appName + "\n\nappVersion: " + navigator.appVersion + "\n\nappCodeName: " + navigator.appCodeName + "\n\nplatform: " + navigator.platform + "\n\ncookieEnabled: " + navigator.cookieEnabled);
}

function createWindow(windowURL, windowName, windowWidth, windowHeight) {
	if(checkWindowName(windowName)) {
		return focusWindow(windowName);
	} else {
		if(arguments.length == 4) {
			topLeftX = (screen.width / 2) - (windowWidth /2);
			topLeftY = (screen.height / 2) - (windowHeight /2);
		} else {
			if(arguments.length == 6) {
				topLeftX = arguments[4];
				topLeftY = arguments[5];
			}
		}
		windowObject = open(windowURL, windowName, "alwaysRaised=1, height=" + windowHeight + ", width=" + windowWidth + ", menubar=0, personalbar=0, resizable=0, screenX=" + topLeftX + ", screenY=" + topLeftY + ", scrollbars=0, status=0, titlebar=0, toolbar=0")
		return registerWindow(windowName, windowObject);
	}
	
}

function createResizableWindow(windowURL, windowName, windowWidth, windowHeight) {
	if(checkWindowName(windowName)) {
		getWindowObject(windowName).location.href=windowURL;
		return focusWindow(windowName);
	} else {
		if(arguments.length == 4) {
			topLeftX = (screen.width / 2) - (windowWidth /2);
			topLeftY = (screen.height / 2) - (windowHeight /2);
		} else {
			if(arguments.length == 6) {
				topLeftX = arguments[4];
				topLeftY = arguments[5];
			}
		}
		windowObject = open(windowURL, windowName, "alwaysRaised=1, height=" + windowHeight + ", width=" + windowWidth + ", menubar=0, personalbar=0, resizable=1, screenX=" + topLeftX + ", screenY=" + topLeftY + ", scrollbars=1, status=0, titlebar=0, toolbar=0")
		return registerWindow(windowName, windowObject);
	}
	
}

function focusWindow(windowName) {
	if(checkWindowName(windowName)) {
		getWindowObject(windowName).focus();
		return true;
	} else {
		return false;
	}
}

function closeWindow(windowName) {
	if(checkWindowName(windowName)) {
		getWindowObject(windowName).close();
		return true;
	} else {
		return false;
	}
}

function checkWindowName(windowName) {
	var counter = 0;
	for(counter = 0; counter < windowsArray.length; counter++) {
		if(windowsArray[counter][0] == windowName) {
			if(windowsArray[counter][1].closed) {
				return false;
			} else {
				return true;
			}
		}
	}
	return false;
}

function registerWindow(windowName, windowObject) {
	var counter = 0;
	for(counter = 0; counter < windowsArray.length; counter++) {
		if(windowsArray[counter][0] == windowName) {
			if(windowsArray[counter][1].closed) {
				windowsArray[counter] = new Array(windowName, windowObject);
				return true;
			}
		}
	}
	windowsArray[windowsCount] = new Array(windowName, windowObject);
	windowsCount++;
	
	return true;
}

function getWindowObject(windowName) {
	var counter = 0;
	for(counter = 0; counter < windowsArray.length; counter++) {
		if(windowsArray[counter][0] == windowName) return windowsArray[counter][1];
	}
	return null;
}

function cleanAll() {
	var counter = 0;
	for(counter = 0; counter < windowsArray.length; counter++) {
		if(! windowsArray[counter][1].closed) windowsArray[counter][1].close();
	}
	return true;
}