// Window functions  v1.01
// http://www.dithered.com/javascript/window/index.html
// code by Chris Nott (chris@dithered.com)
// modified by Tim Morgan for use on timmorgan.info

var winReference = null;

// Open a window at a given position on the screen
function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac")!=-1 && agent.indexOf("msie") != -1 && agent.indexOf("msie 5.0")==-1) {
		height += 2;
		if (status) height += 15;
	}

	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
	var reference = openWindow(url, name, properties, openerName);
	
	return reference;
}


// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName, returnRef) {
	var x = 0;
	var y = 0;
	if (screen) x = (screen.availWidth - width) / 2;
	if (screen) y = (screen.availHeight - height) / 2;
	if (!status) status == '';
	if (!openerName) openerName == '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	if (returnRef) return reference;
}

// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {

	var agent = navigator.userAgent.toLowerCase();
        if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && document.getElementById !=-1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);

		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
        }

	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
	if (openerName) self.name = openerName;
	return winReference;
}
