﻿function PrintPage()
{
    window.print();
}

function LaunchCourse(CID,strW,strL,LID)
{	
	if (LID) 
    {
		window.open('http://workspaces.via3.com/Via3Admin/_media/'+CID+'/default.asp?lid='+LID, "moduleWin", "width="+ strW +",height=" + strL + ", resizable=0,");
	}
	else 
    {
		window.open('http://workspaces.via3.com/Via3Admin/_media/'+CID+'/default.asp', "moduleWin", "width="+ strW +",height=" + strL + ", resizable=0,");		
	}
}


var WIN_DEFAULT			= 0;
var WIN_EVENT_TOP		= 1;
var WIN_EVENT_RIGHT		= 2;
var WIN_EVENT_BOTTOM	= 4;
var WIN_EVENT_LEFT		= 8;
var WIN_CENTER			= 256;

function window_open(url, name, alignment, style, clickEvent)
{
	var nWidth	= 0;
	var nHeight	= 0;
	var nPosX	= 0;
	var nPosY	= 0;
	var win		= null;
	var sStats, aStats;
	var sURL = url;
	
	// Checks and handles popup URLs from .aspx pages
	if (url.search("aspx") > 0)
	{
		//alert("document.URL Before = " + document.URL);
		
		//If the url has a bookmark in it then strip it out because it
		//screws up the addition of the new bookmark in the query string
		var sQuerystring = null;
		if (document.URL.search("#") > 0)
		{
			sQuerystring = "?ref=" + document.URL.substring(0,document.URL.indexOf("#")-1);
		}
		else
		{
			sQuerystring = "?ref=" + document.URL;
		}
		//alert ("sQuerystring after = " + sQuerystring);
		
//	alert("If aspx true and Opening Widow URL " + location.url);
		// Checks for Anchor link in URL
		if (sURL.search("#") > 0)
		{
			//Inserts Querystring before the # for URLs with anchor links
			var i = sURL.indexOf("#");
//		alert("i = " + i);
			var sBaseURL = sURL.slice(0,i);
	//	alert("base URL " + sBaseURL);
			var sAnchor = sURL.substring(i);
			
			sURL = sBaseURL + sQuerystring + sAnchor;
//		alert("New URL with Query and Anchor " + sURL);
		}
		
	}
	
// alert("Redirecting URL outside of if " + sURL);
	sStats = arguments.length > 3 ? String(style).replace(/\s+/g, "").toLowerCase() : "";
	aStats = sStats.split(",");

	for(var ea in aStats)
	{
		var aProp = aStats[ea].split("=");
		if(aProp.length == 2)
		{
			switch(aProp[0])
			{
				case "width" :
					if(Number(aProp[1]) == aProp[1])
						nWidth = Number(aProp[1]);
					break;
				case "height" :
					if(Number(aProp[1]) == aProp[1])
						nHeight = Number(aProp[1]);
					break;
				default :
					break;
			}
		}
	}

	if ("" == name)
		name = "_window";
	win = window[name];

	// use a currently opened window, if possible.
	if(typeof win == "object" && typeof win.closed == "boolean" && !win.closed)
	{
		win.location = sURL;
		win.focus();
		return;
	}

	//	local functions:
	//	SetPositive(Number)
	//	window x/y coords shouldn't be negative values.
	function SetPositive(nAttrib)
	{
		return nAttrib < 0 ? 0 : nAttrib;
	}

	//	AdjustPosY(Number, Number)
	// adjust the y position of the popup, if it is otherwise going to situated so far down
	// on the page that the entire popup (and thereby the ok/cancel buttons) wont be visible.
	function AdjustPosY(nPosY, nPopupHeight)
	{
		var nMaxY = screen.availHeight - nPopupHeight - 30;
		return (nPosY > nMaxY) ? nMaxY : nPosY;
	}
	
	// specify screen location based upon the window "alignment" attribute.
	switch(alignment)
	{

		case 1: //WIN_EVENT_TOP

			if(!clickEvent) return;
			nPosX = SetPositive(clickEvent.screenX - (nWidth / 2) - 6);
			nPosY = SetPositive(clickEvent.screenY - (nHeight + 48));
			break;

		case 2: //WIN_EVENT_RIGHT

			if(!clickEvent) return;
			nPosX = SetPositive(clickEvent.screenX + 20);
			nPosY = AdjustPosY(SetPositive(clickEvent.screenY - 20), nHeight);
			break;
			
		case 4: //WIN_EVENT_BOTTOM

			if(!clickEvent) return;
			nPosX = SetPositive(clickEvent.screenX - (nWidth / 2) - 6);
			nPosY = AdjustPosY(SetPositive(clickEvent.screenY + 20), nHeight);
			break;

		case 8: //WIN_EVENT_LEFT

			if(!clickEvent) return;
			nPosX = SetPositive(clickEvent.screenX - (nWidth + 32));
			nPosY = AdjustPosY(SetPositive(clickEvent.screenY - 20), nHeight);
			break;

		case 256: //WIN_CENTER

			if(!nHeight) return;
			nPosX = SetPositive((screen.availWidth - nWidth) / 2);
			nPosY = SetPositive((screen.availHeight - nHeight) / 2);
			break;

		default:
			if (style && "" != style)
				win = window.open(sURL, name, style);
			else
				win = window.open(sURL, name);
			//win.focus();
			return;
	}

	// open the window using specified size attributes.
	sStats = "resizable=1,status=0,toolbar=0," + sStats + ",left=" + nPosX + ",top=" + nPosY;

	win = window.open(sURL, name, sStats);
	win.focus();

	// create a handle to the window.
	window[name] = win;
}