function printSessionTranscriptWindow(sessionGuid) 
{
	//load frame
	var d = new Date();
	document.getElementById('PrintFrame').style.display = 'inline';
	document.getElementById('PrintFrame').src = m_PrintUrl + sessionGuid + '&Now=' + d.getTime();

	//pause 2.5s then show print dialog (this allow whiteboards to finish loading, TODO: have whiteboards notify parent when they're done loading, then print)
	setTimeout('doPrint();', 2500);
}

function doPrint() 
{
	PrintFrame.focus();
	PrintFrame.print();

	document.getElementById('PrintFrame').style.display = 'none';
}

function setUnloadChecker(endpointUri)
{
	//load frame
	if (document.getElementById('UnloadCheckFrame'))
		document.getElementById('UnloadCheckFrame').src = 'UnloadCheck.aspx?E=' + escape(endpointUri);
}

function connectPlayBackVoice(server, confId) {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;
    flashVoiceObject.Connect(server, confId,"1");
}

function startStreamPlayBackVoice() {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;
    flashVoiceObject.Startstream("1");
}

function togglePlayBackVoice(server) {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;
    flashVoiceObject.TogglePlayback(server,true,"1");
}

function pausePlayBackVoice(Pause) {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;

    flashVoiceObject.PausePlayback(Pause);
}

function stopPlayBackVoice() {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;
    flashVoiceObject.StopPlayback();
}

function playBackVoiceAt(startat, offset) {

    var flashVoiceObject = thisMovie("playback");
    if (!flashVoiceObject)
        return;
    flashVoiceObject.PlaybackAt(startat, offset);
}

function setVoiceVisiblity(visible) {
	//show it (for microphone accept)
	var v = document.getElementById('voice');
	if (!v)
		return;

	var vc = document.getElementById('voicecontainer');

	var ve;
	if (navigator.appName.indexOf("Microsoft") != -1)
		ve = v;
	else
		ve = document.getElementById('voiceembed');

	if (visible) {
		v.style.height = '150px';
		vc.style.height = '150px';
		ve.style.height = '150px';
	}
	else {
		v.style.height = '1px';
		vc.style.height = '1px';
		ve.style.height = '1px';
	}

	doResize();
}

function doResize() {
	$('#xamlcontainer').height($('#form1').height() - $('#voicecontainer').height());
}

function connectVoice(server, confId, userid) 
{
	var flashVoiceObject = thisMovie("voice");
	if (!flashVoiceObject)
		return;

	if (null == flashVoiceObject.Connect || typeof(flashVoiceObject.Connect) == 'undefined') 
	{
		setTimeout("connectVoice('" + server + "','" + confId + "')", 500); 
		return;
	}
		    
	flashVoiceObject.Connect(server, confId, userid);
	
	flashVoiceObject.AddParty("0");
}

function disConnectVoice() 
{
	var flashVoiceObject = thisMovie("voice");
	if (!flashVoiceObject)
		return;
	flashVoiceObject.DisConnect();
}

function addVoiceParty(party) {
	var flashVoiceObject = thisMovie("voice");
	if (!flashVoiceObject)
		return;

	if (null == flashVoiceObject.Connect || typeof (flashVoiceObject.Connect) == 'undefined') {
		setTimeout("addVoicePart('" + server + "','" + confId + "')", 500);
		return;
	}

	flashVoiceObject.AddParty(party);
}

function toggleVoice(on) 
{
	var flashVoiceObject = thisMovie("voice");

	if (!flashVoiceObject)
		return;

	flashVoiceObject.ToggleVoice(on);
}

function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return document.getElementById(movieName);
	}
	else
	{
		return document[movieName];
	}
}

function IsTalking(active) 
{
	//hide it
	if (active == "reset")
	{
		//document.getElementById('voice').style.width = '1px';
		//document.getElementById('voice').style.height = '1px';

		var control = document.getElementById("Xaml1");
		control.Content.Page.OnMicrophoneAllowedResponse(true);
	}
	else if (active == "NoMicrophone")
	{
		alert("We're sorry, we could not detect your microphone. Please ensure your microphone is properly connected and try again.");
	}
	else if (active == "AccessDenied")
	{
		var control = document.getElementById("Xaml1");
		control.Content.Page.OnMicrophoneAllowedResponse(false);
	}
	else
	{
		var control = document.getElementById("Xaml1");
		control.Content.Page.ToggleVoiceOn(active);
	}
}

function focusWindow()
{
	try
	{
		//works for IE, FF3 doesn't support this feature
		window.focus();
	}
	catch (e)
	{
	    
	}
}
	 
function openUrlInOpenerOrNewWindow(url)
{
	try
	{
		if (top.opener)
		{
			try
			{
				//open in original window
				top.opener.location.href = url;
				top.opener.focus();
			}
			catch (e)
			{
				//fall back on opening in a new window
				window.open(url, '', "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
			}
		}
		else
		{
			//open in new window since we can't find the opener
			window.open(url, '', "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
		}
          
		//close this survey window
		top.window.close();
	}
	catch (e)
    { }
}

function openUrlInOpenerOrNewWindowDontCloseParent(url)
{
	try
	{
		if (top.opener)
		{
			try
			{
				//open in original window
				top.opener.location.href = url;
				top.opener.focus();
			}
			catch (e)
			{
				//fall back on opening in a new window
				window.open(url, '', "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
			}
		}
		else
		{
			//open in new window since we can't find the opener
			window.open(url, '', "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
		}
        
	}
	catch (e)
    { }
}

function openUrlInNewWindow(url)
{
	try
	{
		//open in new window 
		window.open(url, '', "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
	}
	catch (e)
    { }
}

function On_BeforeUnload(msg)
{			    
	if (document.all)	
	{
		if (event != null)
			event.returnValue = msg;
		else 
			return msg;
	}
	else
	{
		return msg;
	}
}	
    
function Reload()
{
	window.location.replace(window.location.href);
}    
    
function ReloadbySubjectID(subjectID)
{	
	var temp = new Array();
	temp = window.location.href.split('?');
	window.location.replace(temp[0] + "?SubjectId=" + subjectID);
}    
    
function popStudentClassroomWindow(url)
{
	width = 1004;
	height = 663;
                        
	posX = (screen.availWidth / 2) - (width / 2);
	posY = (screen.availHeight / 2) - (height / 2);

	//open up the classroom window; below, we will check to make sure the window has opened before posting to it
	// we will do all the work we can until we need to Post (to give the window as much time as possible to open)				
	var classroomWin;
	try
	{
		classroomWin = window.open('', 'classroomWindow', 'scrollbars=no,resizable,width=' + width + ',height=' + height + ',left=' + posX + ',top=' + posY + ',screenX=' + posX + ',screenY=' + posY);
	
		//this will throw an error if the classroom window is already open
		var nada = classroomWin.document;
	}
	catch (e)
	{
		//if we throw an exception here, it means the window is already open
		alert('Please first close your current classroom window.');
		return;
	}
	
	classroomWin.location = url;
	classroomWin.focus();
}

function callAnalytics(state)
{
	//make analytics call to register that a user is connected
	if (typeof Analytics_TrackPage != 'undefined')
	{
		Analytics_TrackPage('/classroom/classroom.aspx?classroom=' + state);
	}
}

