/* $Id: pu.js,v 1.2 2005/09/29 19:05:31 psubhedar Exp $ */

var pu_conf = [
	{ re: /./, width: 0, height: 0 }
];

function _pu(param) {
	var def = {
		url: null,
		width: 791,
		height: 570,
		left: null,
		right: null,
		target: null,
		focus: true,
		scroll: null,
		resizable: null,
		avoid_ie4_win32_taint_errors: false
	}
	
	// Generate local variable based on the properties used for this function:
	var p = {};
	for (prop in def) {
		p[prop] = (typeof param[prop] == 'undefined') ? def[prop] : param[prop];
	}

	var ua = navigator.userAgent;
	for (var i = 0; i < pu_conf.length; i++) {
		if (pu_conf[i].re.test(ua)) {
			if (p.width != null || typeof p.width != 'undefined') {
				p.width += pu_conf[i].width;
			}
			if (p.height != null || typeof p.height != 'undefined') {
				p.height += pu_conf[i].height;
			}
			break;
		}
	}
	if (typeof screen.width != 'undefined') {
		p.left = (screen.width - p.width) / 2;
		p.top = (screen.height - p.height) / 2;
	}

	var features = "";

	if (!(p.top == null || typeof p.top == 'undefined') ) {
		features += ",top=" + p.top + ",screenY=" + p.top;
	}
	if (!(p.left == null || typeof p.left == 'undefined') ) {
		features += ",left=" + p.left + ",screenX=" + p.left;
	}
	if (!(p.width == null || typeof p.width == 'undefined') ) {
		features += ",width=" + p.width;
	}
	if (!(p.height == null || typeof p.height == 'undefined') ) {
		features += ",height=" + p.height;
	}
	if (!(p.scroll == null || typeof p.scroll == 'undefined') ) {
		features += ",scrollbars=" + p.scroll;
	}
	if (!(p.resizable == null || typeof p.resizable == 'undefined') ) {
		features += ",resizable=" + p.resizable;
	}

	if (features.length > 0) {
		features = features.substr(1);
	}

	if (typeof pop_win == 'undefined') {
		pop_win = [];
	}

	// Generate random targetname:
	if (p.target == null || typeof p.target == 'undefined') {
		p.target = "" + Math.random();
		p.target = "t" + p.target.substr(2);
	}

	var i = 0;
	if (!(p.url == null || typeof p.url == 'undefined') ) {
		if (p.url.length > 0) {
			while (typeof pop_win[i] != 'undefined') {
				i++;
			}
			pop_win[i] = window.open(p.url,p.target,features);
		}
	}

	// IE4 errors on accessing common properties of windows in another domain:
	if (!p.avoid_ie4_win32_taint_errors
		&& navigator.userAgent.indexOf("MSIE 4.0") == -1
		&& navigator.platform == "Win32"
	) {
		if (typeof window.focus != 'undefined'
			&& !(p.focus == null || typeof p.focus == 'undefined')
		) {
			pop_win[i].focus();
		}
	}
	return pop_win[i];
}
