//opens a new window, centered**********************************************************************************************************************************************
function openwindow(purl, pwidth, pheight, pname, pcentered, pmaximized)
{
	//purl : mandatory : string : url to the new window
	//pwidth : optional : int : height of the new window, default is 790 pixels
	//pheight : optional : int : height of the new window, default is 550 pixels
	//pname : optional : string : name of the new window, default is unique name
	//pcentered : optional : true or false : should the window be centered, default is true NOTE: cannot be empty string
	//pmaximized : optional : true or false : should the user have the option to maximize the window, default is false	 NOTE: cannot be empty string

	//tested for compatiability with:
	//Mozilla Firefox 1.0
	//Internet Explorer 6.0 SP2
	//Mozilla 1.7

	//alerts the user if a url is not passed, and stops execution
	if (purl == "" || purl == undefined)
	{
		alert("Error: No url was passed to the openwindow function.");
		return null;
	}
	
	//defaults the new window width to 790 pixels if not specified
	if (pwidth == "" || pwidth == undefined)
	{pwidth = 790;}
	
	//defaults the new window height to 550 pixels if not specified
	if (pheight == "" || pheight == undefined)
	{pheight = 550;}	
	
	//calculates a unique name for the window if pname is not specified
	if (pname == "" || pname == undefined)
	{
			var now = new Date()
			var year = now.getYear();
			var month = now.getMonth();
			var day = now.getDay();
			var hours = now.getHours();
			var minutes = now.getMinutes();
			var seconds = now.getSeconds();
			pname = year.toString() + month.toString() + day.toString() + hours.toString() + minutes.toString() + seconds.toString();			
	}

	//calculates the x and y cordinates of the new window, if pcentered is not set to false
	if (pcentered == true || pcentered == "true" || pcentered == undefined)
	{
		var winx = (screen.availWidth - pwidth) * .5;
		var winy = (screen.availHeight - pheight) * .5;
		
		//sets the features of the window if the window is to be centered
		var winfeatures = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,width=" + pwidth + ",height=" + pheight + ",left =" + winx + ",top =" + winy;
	}
	else
	{
		//sets the features of the window if the window is not to be centered		
		var winfeatures = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,width=" + pwidth + ",height=" + pheight + ",left =0,top =0";		
	}
	
	//calculates the x and y cordinates of the new window, if pcentered is not set to false
	if (pmaximized == false || pmaximized == "false" || pmaximized == undefined)
	{winfeatures += ",resizable=0";}
	else
	{winfeatures += ",resizable=1";}


	//opens the new window
	window.open(purl, pname, winfeatures);
}
//*********************************************************************************************************************************************************************************


//breaks out of a frame*********************************************************************************************************************************************************
function breakfromframe()
{
	if (top != self)
	{top.location = location;}
}
//*********************************************************************************************************************************************************************************


//maximize the window********************************************************************************************************************************************************
function maxwindow()
{
	var scrheight = screen.availHeight;
	var scrwidth = screen.availWidth;
	window.resizeTo(scrwidth, scrheight)
}
//*********************************************************************************************************************************************************************************


//close the window*************************************************************************************************************************************************************
function closewindow()
{
	//find parent
	var win = window;
	while ((win.parent != null) && (win.parent != win))
	{win = win.parent;}
	
	//close the window
	win.close();	
}
//*********************************************************************************************************************************************************************************


//session has timed out*******************************************************************************************************************************************************
function sessiondead(purl)
{
	//for example see the ablation overview course
	
	//find parent
	var win = window;
	while ((win.parent != null) && (win.parent != win))
	{win = win.parent;}
	
	//redirect the opener back to the login page
	win.opener.location.href = purl;
	
	//close the window
	win.close();
}
//*********************************************************************************************************************************************************************************
