// Alex_K, 02.04.2008 23:17:57
// http://www.koscheev.ru

function Wopen() {
	// 1 - URL (required, string)
	// 2 - width of the window (required, integer)
	// 3 - height (required, integer)
	// 4 - show scrollbars (yes|no|auto, optional, default no)
	// 5 - allow resize (yes|no, optional, default no)
	// 6 - position of the window (optional, 0-7, default is 0)
	// 6.0 - center
	// 6.1 - right top
	// 6.2 - right middle
	// 6.3 - right bottom
	// 6.4 - center bottom
	// 6.5 - left bottom
	// 6.6 - left middle
	// 6.7 - left top
	// 7 - window name (optional, default is current timestamp)
	
	var today = new Date();
	var wName = arguments[6] || today.getTime();
	var sw = screen.availWidth, sh = screen.availHeight;
	var w = arguments[1], h = arguments[2];
	if (w > sw || !w) w = sw;
	if (h > sh || !h) h = sh;

	var showSB;
	if (arguments[3] == 'no') {
		showSB = 'no';
	} else if (arguments[3] == 'yes') {
		showSB = 'yes';
	} else if (arguments[3] == 'auto') {
		if (arguments[1] > sw || arguments[2] > sh) {
			showSB = 'yes';
		} else {
			showSB = 'no';
		}
	} else {
		showSB = 'no';
	}

	if (arguments[3] != 'yes') arguments[3] = 'no';

	if (arguments[4] != 'yes') arguments[4] = 'no';
	if (isNaN(arguments[5])) arguments[5] = 0;

	var l, t;
	var wMargin = 10;


	if ( arguments[5] == 0 ) {
		l = (sw - w) / 2; t = (sh - h) / 2;
	} else if ( arguments[5] == 1 ) {
		l = sw - w - wMargin; t = 0;
	} else if ( arguments[5] == 2 ) {
		l = sw - w - wMargin; t = (sh - h) / 2;
	} else if ( arguments[5] == 3 ) {
		l = sw - w - wMargin; t = sh - h - wMargin;
	} else if ( arguments[5] == 4 ) {
		l = (sw - w) / 2; t = sh - h - wMargin;
	} else if ( arguments[5] == 5 ) {
		l = 0; t = sh - h - wMargin;
	} else if ( arguments[5] == 6 ) {
		l = 0; t = (sh - h) / 2;
	} else if ( arguments[5] == 7 ) {
		l = 0; t = 0;
	}
	open(arguments[0], wName, "left=" + l + ", top=" + t + ", width=" + w + ", height=" + h + ", scrollbars=" + showSB + ", resizable=" + arguments[4]);
}
