var windowCount = 0;
var show_scrollbars, can_resize, height, width, href, show_status;

function openWindow() {
	windowCount++;
	args = openWindow.arguments;
	if(args.length < 1 || args.length > 6) {
		alert('Incorrect number of arguments passed to openWindow function');	
	}
	else {
		href = args[0];
		if(args[1]) width = args[1];
		else width = 300;
		if(args[2]) height = args[2];
		else height = 300;
		(args[3] == true) ? show_scrollbars = "yes": show_scrollbars = "no";
		(args[4] == true) ? can_resize = "yes": can_resize = "no";
		(args[5] == true) ? show_status = "yes": show_status = "no";
        var winleft = (screen.width - width) / 2;
        var wintop = (screen.height - height) / 2;
		(args[6] == true) ? window_target = args[6]: window_target = "window"+windowCount;
	    controlWindow=window.open(href, "window" + windowCount ,"toolbar=no,height=" + height + ",width=" + width + ",left="+winleft+",top="+wintop+",location=no,directories=no,status="+show_status+",menubar=no,scrollbars="+show_scrollbars+",resizable=" + can_resize);
	}
}

var targetWindow = '';

function openTargetWindow() {
	windowCount++;
	args = openTargetWindow.arguments;
	if(args.length < 1 || args.length > 6) {
		alert('Incorrect number of arguments passed to openTargetWindow function');	
	}
	else {
		href = args[0];
		if(args[1]) width = args[1];
		else width = 300;
		if(args[2]) height = args[2];
		else height = 300;
		if(args[3]) window_target=args[3]; else window_target = "window"+windowCount;
//		(args[3] == true) ? window_target = args[3]: window_target = "window"+windowCount;
		(args[4] == true) ? show_scrollbars = "yes":show_scrollbars = "no";
		(args[5] == true) ? can_resize = "yes": can_resize = "no";
		(args[6] == true) ? show_status = "yes": show_status = "no";
        var winleft = (screen.width - width) / 2;
        var wintop = (screen.height - height) / 2;

		if (!targetWindow.closed && targetWindow.location) {
			targetWindow.location.href = href;
		}
		else {
			targetWindow=window.open(href, window_target,"toolbar=no,height=" + height + ",width=" + width + ",left="+winleft+",top="+wintop+",location=no,directories=no,status="+show_status+",menubar=no,scrollbars="+show_scrollbars+",resizable=" + can_resize);
			if (!targetWindow.opener) targetWindow.opener = self;
		}
//		if (window.focus) {
			targetWindow.focus();
		//}

/*		if(targetWindow)
			targetWindow.location = href;
		else
			targetWindow=window.open(href, window_target,"toolbar=no,height=" + height + ",width=" + width + ",left="+winleft+",top="+wintop+",location=no,directories=no,status="+show_status+",menubar=no,scrollbars="+show_scrollbars+",resizable=" + can_resize);
		targetWindow.focus();*/
	}
}


function helpWindow(src)
{
	openWindow('content/help?page=' + src, 300, 300, true, false);
}
