﻿// Open centered window.
// @param target: Target window
// @param w: Width in pixels or percent (0.01 - 1)
// @param h: Height in pixels or percent (0.01 - 1)
// @param href: Hyperlink
// @param features: optional window features
function openCenteredWindow (target, w, h, href, features)
{
	var sw = screen.availWidth;
	var sh = screen.availHeight;
	if (w==null || w<0) w = 0.85;
	if (h==null || h<0) h = 0.85;
	if (w>0 && w<=1) w = sw * w;
	if (h>0 && h<=1) h = sh * h;

	var left = ((sw - w - 10) * .5);
	var top = ((sh - h - 30) * .5);
	if (left<1) left=1;
	if (top<1) top=1;

	openNewWindow(target, w, h, href, left, top, features);
	return (false);
}


// @param features - optional window features
function openNewWindow (winname, width, height, myurl, xpos, ypos, features)
{
	var winref;
	var options;
	//alert(xpos + "," + ypos);

	if (width == "")
	{
		width = 500;
		//width = window.screen.availWidth - 4;
	}

	if (features != null)
	{
		options = features + ",width=" + width;
	}
	else
	{
		options = "toolbar=no,location=no,resizable=yes,scrollbars=yes,width=" + width;
	}

	if (height != "")
	{
		options += ",height=" + height;
	}
	if (xpos != null && xpos != "")
	{
		options += ",left=" + xpos;
	}
	if (ypos != null && ypos != "")
	{
		options += ",top=" + ypos;
	}
	//alert(options);

	winref = window.open("", winname, options);
	if(winref == null || winref.closed)
	{
		showWinError();
		return null;
	}

	if (myurl != null && myurl.length != 0)
	{
		winref.location.replace(myurl);
	}

	try	{ winref.focus(); }
	catch (e) { showWinError(); }

	return (winref);
}

function showWinError()
{
	alert(g_msg_var_UnableToOpenWindow_Line1 + "\n\n" + g_msg_var_UnableToOpenWindow_Line2 + "\n" + g_msg_var_UnableToOpenWindow_Line3);
}


function openNewsItem(newsitem)
{
	var url='news/news' + newsitem + '.htm';
	openCenteredWindow("DynisticsNewsArticle", 600, 700, url);
}
