//**************************************************//
//*********** MEETING FUNCTIONS ********************//
//**************************************************//

//var launchURL = "/adw/web-conferencing-sign-up.asp";
var URLCreateFrameset = "/WebConference/URLCreateFrameset.aspx"; //this is what people get redirected to with a query string attached
var presentationSessionFormatID;
//determines how long to wait before redirecting or closing window
var returnToAccountManagerWait = 1000; //this is in milliseconds

//-----------------------------------------------------------------------//
// Tells whether the user browser is Internet Explorer
//-----------------------------------------------------------------------//

function isIE()
{  
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

//-----------------------------------------------------------------------//
// This is called by The Screen Sharing Component Download/Install pages.
// This lets the install page know if the user already has the INTERNET EXPLORER
// screen sharing plugin installed.
//-----------------------------------------------------------------------//
function detectPlugin()
{
	//if (isIE())
	//{
		 var oPlugin = document.getElementById("CosNetControl");
		 //var oPre = document.getElementById("install_status");
		 var oInstalled = "undefined";
		 	
		 try
		 {
		    oInstalled = typeof(oPlugin.FPS);
		    //if (asVer != "undefined")
		   //    asVer = "unknown";
		 }
		 catch(err)
		 {
		    oInstalled = "undefined";
		 }
		    
		 if (oInstalled != "undefined")
		   	return true;  	
		 else
		 	return false;
	//}
	//else
	//	return false;
}

//-----------------------------------------------------------------------//
// This is called by The Screen Sharing Component Download/Install pages.
// This lets the install page know if the user already has the MOZILLA FIREFOX 
// screen sharing plugin installed.
//-----------------------------------------------------------------------//

function detectApplet()
{
	var oPlugin = document.getElementById("CosNetControl");
	//var oPre = document.getElementById("install_status");
	if(oPlugin.isActive != undefined)
		return true;
	else
		return false;
}

//-----------------------------------------------------------------------//
// Open our screen sharing plugin install window
//-----------------------------------------------------------------------//

function InstallPlugin_new()
{
	MM_openBrWindow("http://" + serverWeb + "/component_download.asp?start=true","_install", "width=760,height=450,status=1");
}

//-----------------------------------------------------------------------//
// Open our High Quality Video Plugin install window
//-----------------------------------------------------------------------//

function OpenVideoPluginWindow()
{
	MM_openBrWindow("http://" + serverWeb + "/AccountManager/Other/VideoComponentDownload.aspx?start=true","_install", "width=760,height=450,status=1");
}




//**********************************************************************
//This group of functions dealing with the launching of a URL window

//-----------------------------------------------------------------------//
// Provided an appropriate web URL, open a new window with our custom 
// header frame up top.
//-----------------------------------------------------------------------//

function URLLaunch(theURL){
	var myWindow;
	var myScreen = getScreenSize();
	var rExp = /,_self/gi;
	var newString = new String(theURL);
	
	sentURL = newString.replace(rExp, '');	
	newString = null;
	launchURL = 'http://' + serverWeb + URLCreateFrameset + '?url=' + sentURL;
	urlWindow = window.open(launchURL,'urlWindow','width=780,height=500,screenX=120,screenY=120,top=120,left=120,toolbar=0,location=0,status=1,menubar=0,resizable=1,scrollbars=1');	
			
	setTimeout(checkURLLaunch, 2000);		
		
}

//function URLLaunch2()
//{
//	urlWindow = window.open(launchURL,'urlWindow','width=780,height=500,screenX=120,screenY=120,top=120,left=120,toolbar=0,location=0,status=1,menubar=0,resizable=1,scrollbars=1');	
//	hideBlockedURLMessage();
//}

//-----------------------------------------------------------------------//
// Allows user to hide the popup blocked message from view
//-----------------------------------------------------------------------//

function hideBlockedURLMessage()
{
	who = "launchedURLDiv";
	if(typeof who== 'string') who=document.getElementById(who);
    	if(who && who.parentNode)who.parentNode.removeChild(who);
}

//-----------------------------------------------------------------------//
// Let the user know that a pop up blocker grabbed our window
//-----------------------------------------------------------------------//

function showBlockedURLMessage()
{
	var myDiv = document.createElement("<div>");
	myDiv.id = "launchedURLDiv";
	myDiv.style.textAlign = "center";
	myDiv.style.position = "absolute";
	myDiv.style.zIndex = "200";
	myDiv.style.top = "30%";
	myDiv.style.backgroundColor = "#eeeeee";
	myDiv.style.left = "40%";
	myDiv.style.width = "300";
	myDiv.style.height = "200px";
	myDiv.style.border = "8px solid #cccccc";
	myDiv.style.padding = "4px";
	var closeLink = "<div align='right' style='font-family: arial; font-size: 10px; border-bottom: 1px solid #999999; padding-bottom: 2px;'><a href='#' onclick='hideBlockedURLMessage();'>[close]</a></div>";
	var myLink = "<font face='arial'><font size='4'>The Presenter has sent you a web page link, but it was blocked by your pop-up blocker.</font><br><br><a href='" + launchURL + "' target='urlWindow' onclick='hideBlockedURLMessage();'><font size='5'><b>Please click here to open the link now.</b></font></a><br><br><font size='2'><b>Note: You may need to hold the Control (CTRL) key while you click the link.</b></font></font>";
	myDiv.innerHTML = myLink;		
	document.body.appendChild(myDiv);
}

//-----------------------------------------------------------------------//
// Detect if the popup blocker grabbed our window and call the function
// to show the user an alert.
//-----------------------------------------------------------------------//

function checkURLLaunch()
{
	var IE = isIE();
	
	alertText = "WARNING: Your browser has a pop-up blocker installed.  The presenter has tried to send you this link below.\n\nCopy and paste this link into a new browser window.";
	
	if (urlWindow==null || typeof(urlWindow)=="undefined") 
	{
		
		//has pop-up blocker
		showBlockedURLMessage();
	}
	else
	{	
		try 
		{
			urlWindow.focus();
		}
		catch(e)
		{
			//has pop-up blocker	
			showBlockedURLMessage();
		}
	}
}

//-----------------------------------------------------------------------//
// Redirect to a Web URL, places our own custom header above in a 
// separate frame
//-----------------------------------------------------------------------//

function urlRedirect(theURL)
{	
	//if (theURL.toLowerCase().indexOf("http") == -1)
	//	theURL = "http://" + theURL;
	
	if (presentationSessionFormatID == 15) //video only API
		window.location = theURL;
	else	
	    if (theURL.indexOf("SYID=") > 0)
		    window.location = "http://" + serverWeb + URLCreateFrameset + "?url=" + theURL + '%26resultUnique=' + resultUnique;
		else
		    window.location = "http://" + serverWeb + URLCreateFrameset + "?url=" + theURL
}

//-----------------------------------------------------------------------//
// Redirects to breakout room
//-----------------------------------------------------------------------//

function doBreakout(theURL)
{	
	canClose = true;
	var url = theURL; //theURL + "?ScreenName=" + lScreenName + "&Email=" + lEmail;
	//alert("doBreakout: " + url);
	window.location = url;
}

//******************************************************************

function getFocus()
{
    //we may do something with this in the future
}


//**** SCREEN SHARING FUNCTIONS ************************************

//-----------------------------------------------------------------------//
// Global Variables
//-----------------------------------------------------------------------//

var protocol = "rtmp";
var port = "1935";
var curTries = 0;
var maxTries = 2;
var gsID;
var gR;
var connecting = false;
var SSControl;

var isMinimized = false;
var isScreenSharing = false;
var canClose = true;
var hasPlugin = true;

//-----------------------------------------------------------------------//
// CosNetControl (Screen Sharing component) Main Event Handler
// This handles status changes for the Screen Sharing Component
//-----------------------------------------------------------------------//

function onStatus(pCode) 
{		  	
	 if (pCode != "NetStream.Record.Start")
	 {
	 	if (pCode == "NetStream.Unpublish.Success" && isScreenSharing == false)
	 	{
	 		pCode = "NetConnection.Connect.Failed";
	 	}
	 	
		doCall("ip_control", "_level0.swfProxy_mc.IPScreenShare_mc.Plugin_onStatus," + pCode + ";" + "" + ";");

     	if (pCode == "NetStream.Publish.Start" || pCode == "NetStream.Unpublish.Success" || pCode == "NetConnection.Connect.Closed")
     	{     		     		     		
     		switch(pCode)
     		{
     			case "NetStream.Publish.Start":
     				//startedScreenShare();
     				isScreenSharing = true;
     				break;
     			case "NetStream.Unpublish.Success":
     			case "NetConnection.Connect.Closed":
     				stopScreenShare();
     				break;
     		}
     	}
     	     	
		if (pCode == "NetConnection.Connect.Success") 
		{
			curTries = 0;
			connecting = false;
			isScreenSharing = true;
		}
				
		if (pCode == "NetStream.Publish.BadName")
		{
			//msgbox "BadName";
		}
		
		if (pCode == "NetConnection.Connect.Failed")
		{
			protocol = "rtmpt";
			port = "80";
			
		 	if (curTries < maxTries && connecting == true) 
		 	{
		 		curTries++;
		 		setTimeout("retryStartScreenShare()", 500);
		 	}
		 	else
		 		stopScreenShare();		 	
		}
	}
}

//-----------------------------------------------------------------------//
// This attempts to start screen sharing again.
// This is typically used with a schedule command for when there is 
// problems connecting.
//-----------------------------------------------------------------------//

function retryStartScreenShare()
{
	//if (gsID != undefined && gR != undefined)	
	//if (isIE()) 
	startScreenShare(gsID, gR);
}

//-----------------------------------------------------------------------//
// Start Screen Sharing
//-----------------------------------------------------------------------//

function startScreenShare(sID, r)
{	
	//if (isIE())
	//{
		var CosNetControl = document.getElementById("CosNetControl");	
		if (CosNetControl != undefined)
		{		
			gsID = sID;
			gR = r;		
			
			if (isIE())
			{				
				CosNetControl.ColorQuality = 16;  // default is 24, possible values 4,8,24			
				CosNetControl.FPS = 4;// default is 2, possible values 1-5
				CosNetControl.ForceMode = 'WINDOWS_GDI'; //default is DIRECTX_9, possible values: WINDOWS_GDI, DIRECTX_9			
			}
			else
			{
				CosNetControl.setColorQuality(16);  // default is 24, possible values 4,8,24			
				CosNetControl.setFPS(4);// default is 2, possible values 1-5				
			}				
			
			var s = "Sharing" + sID;
			var a = protocol + "://" + serverScreenSharing + ":" + port + "/screenshare/" + sID;
			var rr = r.toUpperCase();
					
			SSControl = CosNetControl;
			
			if (isIE())
				setTimeout("SSControl.StartShareDesktop('" + s + "', '" + a + "', '" + rr + "', 1)", 500);
			else
			{
			    //alert('has ss: ' + checkHasScreenShare());
			    //alert(window.outerWidth);
				rr = r.toLowerCase();
				var strStart = "SSControl.startShareDesktop('" + s + "', '" + a + "', '" + rr + "', false)";			
				setTimeout(strStart, 500);
			}
						
			connecting = true;			
			
		}
	//}
}

//-----------------------------------------------------------------------//
// Called BEFORE startScreenShare()
// Sets variables and window settings to BEGIN the screen sharing process.
//-----------------------------------------------------------------------//
function startedScreenShare()
{	
	//var oScreen = getScreenSize();
	
//	window.moveTo(0,0);
//	window.resizeTo(250, screen.availHeight);

//	window.screenX = 0;
//	window.screenY = 0;				
}


//-----------------------------------------------------------------------//
// Stop Screen Sharing
//-----------------------------------------------------------------------//

function stopScreenShare()
{		
	if (isScreenSharing == true)
	{	
		stoppedScreenShare();
		
		var CosNetControl = document.getElementById("CosNetControl");	
		if (CosNetControl)
		{	
			if (isIE())
			{				
				if (CosNetControl.StopShareDesktop != undefined)
					CosNetControl.StopShareDesktop();						
			}
			else
			{
				CosNetControl.stopShareDesktop();
			}
		}
	}
}

//-----------------------------------------------------------------------//
// Called by stopScreenShare()
// Sets variables and window settings to END the screen sharing process.
//-----------------------------------------------------------------------//

function stoppedScreenShare()
{
	connecting = false;
	curTries = 0;
	/*
	if (isScreenSharing)
	{
		var oScreen = getScreenSize();
		
		window.moveTo(0, 0);
		//window.resizeTo(oScreen.width, oScreen.height);
		self.resizeTo(screen.availWidth,screen.availHeight);
	}
	*/
	isScreenSharing = false;
}

//-----------------------------------------------------------------------//
// Check to see if the Screen Sharing Element is present on the page
//-----------------------------------------------------------------------//

function checkHasScreenShare()
{
	var CosNetControl = document.getElementById("CosNetControl");	
	
	if (CosNetControl != undefined)
	{			
		if (isIE())
		{
			if (CosNetControl.ScreenXWidth != undefined)
				return true;		
			else
				return false;		
		}
		else
		{
			if (CosNetControl.getScreenXWidth != undefined)
				return true;		
			else
				return false;		
		}
		
	}
	else
		return false;
}

//function doOnResize()
//{	
//}

//function restoreMinimized()
//{
//	if (isMinimized == true)
//		Maximize();
//};


//-----------------------------------------------------------------------//
// Maximize the page window
//-----------------------------------------------------------------------//

function Maximize() 
{
	//alert("Maximize");
	window.moveTo(0,0);
	window.resizeTo(screen.width - 11, screen.height - 79);

	window.screenX = 0;
	window.screenY = 0;
	alwaysLowered = false;
	isMinimized = false;
};

//-----------------------------------------------------------------------//
// Minimize the page window
//-----------------------------------------------------------------------//

function Minimize() 
{
	window.resizeTo(10, 10);
	window.moveTo(screen.width, screen.height);	
	alwaysLowered = true;
	isMinimized = true;
};

//-----------------------------------------------------------------------//
// Called by the Presentation Active Upload file after it has successfully
// uploaded a file. This will let the Flash Meeting App know of the new
// file.
//-----------------------------------------------------------------------//

function fileUploaded(filename)
{
	//alert("fileUploaded: " + sp + filename);
	doCall("ip_control", "_level0.swfProxy_mc.presentation_mc.loadUploadedContent," + sp + filename);
}

//function doUnload()
//{
//	if (canClose == true)
//		return;
//	else
//		return "If you close this window, you will be logged out of the active presentation.";	
//}


//-----------------------------------------------------------------------//
// This is called to initialize the screen sharing plugins and set
// member variables indicating that the page has finished loading. 
// This is called by the default.aspx body tag when the page has 
// finished loading.
//-----------------------------------------------------------------------//

function doOnLoad()
{	
	canClose = false;
			
	//alert(typeof(initVideo));
	//if (typeof(initVideo) != "undefined")
	//	initVideo();
	
	/*	
	videohide();
	
	var oPlayer = document.getElementById("wmvMediaPlayer");
	//show or hide our player and start playing
	if (oPlayer)
	{
		if (oPlayer.URL != "")
		{
			videoshow();
			videoplay();
		}
		else
		{
			videohide();
		}
	}
	*/

//load ss plugin if we have a presenter
    if (p == 1)
    {
	    loadScreenSharePlugin();
	}
	if (checkHasScreenShare() == true)
	{
		hasPlugin = true;
		
	}
	else
	{
		hasPlugin = false;	
	}

	isLoaded = true;		
}



//-----------------------------------------------------------------------//
// Called by the HQ Video Download & Screen Sharing Video Download pages
// after the plugin has successfully installed.  This refreshes the page
// so that it recognizes that the plugin has been installed and allows 
// for immediate usage of the plugin
//-----------------------------------------------------------------------//
function refreshAfterPluginInstall(loadedWin)
{		
	if (loadedWin != null)
		loadedWin.close();
	
	/*
	var CosNetControl = document.getElementById("CosNetControl"); 
	if (CosNetControl != undefined)
	{
		canClose = true;		
		alert("ATTENTION: We will now reload the window so that the Screen Sharing plug-in may become active.");		
		window.location.reload();
	}
	*/
	loadScreenSharePlugin();
}

//-----------------------------------------------------------------------//
// Check to make sure the Screen Sharing Plugin is loaded, 
// responds with a DO CALL to the flash meeting app
//-----------------------------------------------------------------------//
function checkLoaded()
{
	if (checkHasScreenShare() == true)
		hasPlugin = true;
	else
		hasPlugin = false;
	
	//alert("checkLoaded: " + hasPlugin);	
	doCall("ip_control", "_level0.swfProxy_mc.IPScreenShare_mc.Plugin_resultHasPlugin," + hasPlugin.toString());	
    return hasPlugin;	
}

//Not used anywhere
function loadFromCodebase()
{	
	document.write("<OBJECT ID=\"CosNetControl\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:E901098E-6B97-485A-B712-9908683F5E9E\" codebase=\"#version=0,1,0,8\" onerror=\"noScreenSharePluginInstalled\" codebase=\"http://" + serverWeb + "/components/CosNetWebConference.cab#version=1,0,8,0\"></OBJECT>");	
}

//-----------------------------------------------------------------------//
// Load our ActiveX screen sharing plugin
//-----------------------------------------------------------------------//
function loadActiveXfromCodebase()
{
	unloadActiveX();
	var oPlugin = document.getElementById("plugin");
	
	if(oPlugin)
	{
		oPlugin.innerHTML = "<OBJECT ID=\"CosNetControl\" WIDTH=0 HEIGHT=0 events=\"true\" CLASSID=\"CLSID:E901098E-6B97-485A-B712-9908683F5E9E\" onerror=\"noScreenSharePluginInstalled\" codebase=\"/components/CosNetWebConference.cab#version=1,0,8,0\"></OBJECT>";
		var CosNetControl = document.getElementById("CosNetControl"); 
		CosNetControl.attachEvent("OnStatus", jsOnStatus);
		return checkLoaded();
	}
	else
		return false;
}



//-----------------------------------------------------------------------//
// Load ScreenSharing plugin for IE or Mozilla Firefox
//-----------------------------------------------------------------------//
function loadScreenSharePlugin()
{
    if (checkHasScreenShare() == true)
    {
        return;
    }
    var result;
    //alert("loadScreenSharePlugin");
	if (!isIE()) 
	{	
	    result = loadApplet();
		//alert("loaded Applet");
	}
	else if (isIE()) 
	{		
		result = loadActiveX();
		//alert("loaded IE");
	}
	else 
	{
		alert("Sorry, your browser is currently not supported for screen sharing.");
	}
//	if (result != true)
//	    alert("Could not load the screen sharing plugin");
}

//function unloadScreenSharePlugin()
//{
//    var oPlugin = document.getElementById("plugin");
//    
//    if (oPlugin)
//    {
//        oPlugin.innerHTML = "";
//        return true;
//    }
//    else
//        return true;

//}


//-----------------------------------------------------------------------//
// Load our JAVA Applet screen sharing plugin
//-----------------------------------------------------------------------//
function loadApplet()
{
    unloadApplet();
	var oPlugin = document.getElementById("plugin");
	//alert("here!");
	
	if(oPlugin)
	{
		
		oPlugin.innerHTML = "<applet mayscript='true' id='CosNetControl' code='com.cosnet.CosNetWebConference.class' width=0 height=0 archive='/applet/CosNetWebConference.jar'></applet>";		
		
	    return checkLoaded();
	}
	else
		return false;
}

//-----------------------------------------------------------------------//
// Unload our Java (Mozilla) Screen Sharing Plugin
//-----------------------------------------------------------------------//
function unloadApplet()
{			
	var CosNetControl = document.getElementById("CosNetControl"); 
	//alert(CosNetControl);
	if ((CosNetControl != undefined) && (CosNetControl))
	{
	    
		CosNetControl.removeChild(true);
		alert("You removed the applet from " + window.location);
	}
}

//-----------------------------------------------------------------------//
// Function that attaches the OnStatus event handler to our CosNet Control
//-----------------------------------------------------------------------//
function jsOnStatus()
{	
	CosNetControl_OnStatus(arguments[0], arguments[1], arguments[2], arguments[3]);
}


//-----------------------------------------------------------------------//
// Load our ActiveX screen sharing plugin
//-----------------------------------------------------------------------//
function loadActiveX()
{
	unloadActiveX();
	var oPlugin = document.getElementById("plugin");
	
	if(oPlugin)
	{
		oPlugin.innerHTML = "<OBJECT ID=\"CosNetControl\" WIDTH=0 HEIGHT=0 events=\"true\" CLASSID=\"CLSID:E901098E-6B97-485A-B712-9908683F5E9E\" codebase=\"#version=0,1,0,8\" onerror=\"noScreenSharePluginInstalled\"></OBJECT>";
		var CosNetControl = document.getElementById("CosNetControl"); 
		CosNetControl.attachEvent("OnStatus", jsOnStatus);
		return checkLoaded();
	}
	else
		return false;
}

//-----------------------------------------------------------------------//
// Unload our ActiveX (IE) Screen Sharing Plugin
//-----------------------------------------------------------------------//
function unloadActiveX()
{			
	var CosNetControl = document.getElementById("CosNetControl"); 
	if (CosNetControl != undefined)
		CosNetControl.removeNode(true);
}


//-----------------------------------------------------------------------//
// Tell the Browser that there is no screen sharing installed
//-----------------------------------------------------------------------//
function noScreenSharePluginInstalled(){
	//alert("noScreenSharePluginInstalled");
	hasPlugin = false;
}

//-----------------------------------------------------------------------//
// Make someone a Presenter and load screen sharing also
//-----------------------------------------------------------------------//
function makePresenter()
{	
    //only load our screen sharing plugin once
    //--- dont do this, hasPlugin may be set after makePresenter is called
    //if (hasPlugin == true)
   // {
	    loadScreenSharePlugin();
	//}
}


//-----------------------------------------------------------------------//
// Set the Presentation Session Format ( 10 = High Quality Video )
// If High Quality Video Format is selected, then Bandwidth is also set
//-----------------------------------------------------------------------//
function setFormatID(strFormat)
{
	presentationSessionFormatID = Number(strFormat);
	if (typeof(setBandwidthProfile) != "undefined")
	{
		switch(presentationSessionFormatID)
		{
			case 10:	
				setBandwidthProfile("small");
				/*
				if (p != 1)
				{
					var lScreen;
					lScreen = getScreenSize();
					//alert(window.outerHeight + ", " + document.body.clientHeight)
					var diff = lScreen.height - lScreen.innerHeight;
					window.resizeTo(lScreen.width,(lScreen.width * 0.5) + diff);
				}
				*/
				break;
			case 15:
				canClose = true;
				break;
			default:			
				setBandwidthProfile("small");
				break;
		}
	}
}
//-----------------------------------------------------------------------//
// This redirects Attendees to the proper exit page
//      * InstantPresenter Users get signup form
//      * My VSL users get signup form
//      * All other users get a blank page.
//-----------------------------------------------------------------------//
function goToExitPage()
{
    //anyone who is not a reseller customer gets taken to a signup page
	if (isReseller == "False")
	{
	    window.location = "/adw/WebConferencingSignUp.aspx";	
	}
	
	//all vsl customers get taken to a vsl signup page
	if (serverWeb.indexOf("myvsl.com") > 0)
	{
	    window.location = "http://www.videoseminarlive.com";	
	}
}

//-----------------------------------------------------------------------//
// This is how commands get passed to the Flash Meeting App. This is the
// main integration point from User Browser -----> Flash Meeting App
//-----------------------------------------------------------------------//
function doCall(swfId, what){
	//alert("doCall: " + what);
	var swf = document.getElementById(swfId)
	if (swf)
 		swf.SetVariable('_root.externalFunction', what);
}


//-----------------------------------------------------------------------//
// All Commands are passed through here via the Flash Meeting App 
// to talk to the browser. This is the main integration point from
// Flash Meeting App -----> User Browser
//-----------------------------------------------------------------------//
function ip_control_DoFSCommand(command, args) { 	
   //alert("command: " + command + ", args: " + args);	
	switch(command)
	{
	   
		case "returnToAccountManager":
		    //Presenter ended session without putting in a redirect URL
			if (p == 1)
			{
			 //PluginStopBroadcast();
			 	if (typeof(videohide) != 'undefined') videohide();
			    //send presenter to account manager after short delay, this gives our plugins TIME to UNLOAD
  				 setTimeout("returnToAccountManager()", returnToAccountManagerWait);  
  			}
  			else
  			{
  			    canClose = true;  				
  				goToExitPage();  				 				
  			}
  			
  				  							
  			break;  
  		case "startScreenShare":
  			//alert("fscommand - screenshare");
  			startedScreenShare();
      		startScreenShare(sid, args);
      		break;
        case "stopScreenShare":
           	stopScreenShare();
           	break;
        case "openURL":	    
	    	URLLaunch(args);
	    	break;
	   	case "redirectURL":
	   //	alert("redirect to URL");
	        //Presenter ended Session and put in a REDIRECT URL
    		canClose = true;	    		
    		
    		//send presenters back to the account manager
    		if (p == 1 && serverWeb.indexOf("icohere") == -1)	
    		{	  
    		    //call delayed return to account manager so our plugins have time to UNLOAD
    		    setTimeout("returnToAccountManager()", returnToAccountManagerWait);  			
			    
		    }
		    else
		    {
		        urlRedirect(args);
		    }
	    	break;	    	
		case "doBreakout":
			doBreakout(args);
			break;
	    case "openContentUpload":
	        //alert("selected command 'openContentUpload'");
  			openContentUploader(enceid);
  			break;
  		case "getHasPlugin":  			
		    doCall("ip_control", "_level0.swfProxy_mc.IPScreenShare_mc.Plugin_resultHasPlugin," + hasPlugin.toString());
		    break;
		case "getHasVideoPlugin":
		    if (typeof(PluginVideoCheckLoaded) != 'undefined') PluginVideoCheckLoaded();
		    break;
		case "PluginEnable":
		    if (typeof(pluginEnable) != 'undefined') pluginEnable(args);
		    break;
		case "installPlugin":
		    InstallPlugin_new();		    	
		    break;
	    case "getScreenSize":
	    	var CosNetControl = document.getElementById("CosNetControl");
	    	if (isIE())
				doCall("ip_control", "_level0.swfProxy_mc.IPScreenShare_mc.Plugin_resultScreenSize," + CosNetControl.ScreenXWidth + ";" + CosNetControl.ScreenYHeight);
			else
			{
				//alert("width: " + CosNetControl.getScreenXWidth() + ", height: " + CosNetControl.getScreenYHeight());
				doCall("ip_control", "_level0.swfProxy_mc.IPScreenShare_mc.Plugin_resultScreenSize," + CosNetControl.getScreenXWidth() + ";" + CosNetControl.getScreenYHeight());
			}
		   	break;
	    case "setQuality":	    	    	
	    		break;
	    case "setFrameRate":
	    		break;	    	
	    case "getFocus":
		    	getFocus();
		    	break;	    
		case "makePresenter":
			makePresenter();
			break;
		case "FormatID":
			setFormatID(args);
			break;
		case "onVideoSize":
	    		//alert("onVideoSize");
	    		if (typeof(videoresize) != 'undefined') videoresize(args);	    		
	    		break;	    
	    case "menuShow":	    		
	    		if (typeof(videohide) != 'undefined') videohide();
	    		break;
	    case "menuHide":
	    		if (typeof(videoshow) != 'undefined') videoshow();
	    		break;	
	    case "videoHide":	    		
	    		if (typeof(videohide) != 'undefined') videohide();
	    		break;
	    case "videoShow":
	    		if (typeof(videoshow) != 'undefined') videoshow();
	    		break;		    		
	    case "PluginStartBroadcast":	    		
	    		if (typeof(PluginStartBroadcast) != 'undefined') PluginStartBroadcast(args);
	    		break;
	    case "PluginStopBroadcast":	
	    		if (typeof(PluginStopBroadcast) != 'undefined') PluginStopBroadcast();
	    		break;
	    case "PluginSetMic":
	    		if (typeof(PluginSetMic) != 'undefined') PluginSetMic(args);
	    		break;
	    case "PluginSettings":
	    		if (typeof(PluginSettings) != 'undefined') PluginSettings(args);
	    		break;
	    case "PluginSetCamera":
	    		if (typeof(PluginSetCamera) != 'undefined') PluginSetCamera(args);
	    		break;
	    case "PluginVideoPauseBroadcast":
	    		if (typeof(PluginVideoPauseBroadcast) != 'undefined') PluginVideoPauseBroadcast(args);
	    		break;
	    case "PluginAudioPauseBroadcast":
	    		if (typeof(PluginAudioPauseBroadcast) != 'undefined') PluginAudioPauseBroadcast(args);
	    		break;
	    case "PluginSetVolume":
	    		if (typeof(PluginSetVolume) != 'undefined') PluginSetVolume(args);
	    		break;    	
	    case "PluginSetBandwidth":
	    		if (typeof(setBandwidthProfile) != 'undefined') setBandwidthProfile(args);
	    		break;    
		case "PluginSetBroadcastBuffer":				
	    		if (typeof(setBroadcastBuffer) != 'undefined') setBroadcastBuffer(args);
	    		break;  
		case "ToasterMessage":				
				ToasterMessage(args);
				break;				
		case "PluginBroadcastStarted":
				PluginBroadcastStarted();
				break;
	  }   	 
};

//-----------------------------------------------------------------------//
// Brings the Presenter back to the My Account page
//-----------------------------------------------------------------------//
function returnToAccountManager()
{	
	canClose = true;
	if (window.opener == "undefined" || !window.opener)
	{
	    //The parent window has been closed already, send the only window that's open back to the account manager
		window.location = "http://" + serverWeb + "/AccountManager/Default.aspx";
		  
	}
	else
	{	
	    try
	    {
	        //send parent window to account manager
		    window.parent.opener.location = "http://" + serverWeb + "/AccountManager/Default.aspx";
	    }
	    catch(err)
	    {
	        //do nothing
	       // alert(err.message);
	    }
	    
	  
    //alert("closing window");
	    //close the presentation window		    
		    window.close();
		
	}//end else
};


//-----------------------------------------------------------------------//
// Determines whether passed file name is an allowed upload file type
//-----------------------------------------------------------------------//
function isValidUploadType(filename)
{	
	var dot = filename.lastIndexOf(".");
	var extention = filename.substr(dot + 1);	
	
	var validTypes = validUploadFileTypes;
	if (validTypes.search(extention) != "-1")
		return true;
	else
		return false;
}

//-----------------------------------------------------------------------//
// Opens the Presentation Upload on the Fly window
//-----------------------------------------------------------------------//

function openContentUploader(encEventID)
{	
	var contentURL = "http://" + serverWeb + "/AccountManager/Presentation/PresentationActiveUpload.aspx?ip_e=" + encEventID;
	//window.showModalDialog(contentURL, self, "width=700,height=200");
	MM_openBrWindow(contentURL, "_upload", "modal,width=540,height=360,status=0");
	
	/*
	if (window.showModalDialog) // ie
	{
		window.showModalDialog(contentURL, self, "width=400,height=200,status=1,toolbars=0");
	}
	else
	{
		MM_openBrWindow(contentURL, "_upload", "modal,width=400,height=200,status=1");
	}*/
}

// Displays a little message in the lower right corner of the screen.
function ToasterMessage(msg)
{
	$('<p>' + msg + '</p>').toaster();
	//alert(msg);
}
