var desktopStartedFromJS = false;
var desktopSharingURL = "";
var desktopSharingStreamName = "";
var listener = null;

//hq tool javascript
var pluginPresent = false;
var systemCapable = "Unavailable";
var callbackClientName;

var javaPresent = true;


var isVEncoder = false;
var skypeName = null;
var desktopAppletAlreadyLoaded = false;
var isFullScreen = false;

function setFullScreen(v)
{
	isFullScreen = v;
	 try
     {
         swtFullScreen(v);
     }
     catch(e)
     {
     }
}

function getFullScreen()
{
	return isFullScreen;
}

function exitFullScreen()
{
	try
	{
		getFlashMovie(callbackClientName).jsExitFullScreen();
	}
	catch(e)
	{
	}
}

function registerListener(v)
{
	listener = v;
}

function clientEmailFunction(subjectVal, emailContentVal){
	location.href = "mailto:?subject="+subjectVal+"&body="+emailContentVal;
}
function sendPublicMessage(msgText)
{
	//alert("Sending Message " + msgText);
	if(typeof(frames['chatFrame'].sendPublicMessage) == "function")
		frames['chatFrame'].sendPublicMessage(msgText);
}

function sendStatus(status)
{
	//alert("Sending Message " + msgText +" to " + to);
	if(typeof(frames['chatFrame'].sendStatus) == "function")
		frames['chatFrame'].sendStatus(status);
}

function openPopup(url)
{
        window.open(url,'','width=600,height=300');
}

function openPageInNewWindow(url)
{
	window.open(url);
}

function openPage(url)
{
	window.location = url;
}

function reloadPage()
{
	window.location.reload();
}

function sendPrivateMessage(to, msgText)
{
	//alert("Sending Message " + msgText +" to " + to);
	if(typeof(frames['chatFrame'].sendPrivateMessage) == "function")
		frames['chatFrame'].sendPrivateMessage(to,msgText);
}

function loadDesktopSharingApplet()
{
	//alert('Loading applet');
	if(desktopAppletAlreadyLoaded || javaLoadDone) return;
	var frame = document.getElementById("appletFrame");
	//alert(isVEncoder);
	if(!(window.domain === undefined))
	{
		frame.src = "static/desktopSharingApplet.jsp?launchMode="+launchMode+"&vencoder="+isVEncoder+"&domain="+escape(document.domain)+"&mode="+eventMode;
	}
	else
	{
		frame.src = "static/desktopSharingApplet.jsp?launchMode="+launchMode+"&vencoder="+isVEncoder+"&mode="+eventMode;
	}
//	alert(frame.src);
	desktopAppletAlreadyLoaded = true;
}

function isAppletLoading()
{
	return (desktopAppletAlreadyLoaded && !javaLoadDone);
}

function isAppletLoaded()
{
	return javaLoadDone;
}

var swtApplet = false;
var parentApplet = false;
function isSWTBrowser()
{
	return swtApplet;
}

function registerSWTApplet()
{
	swtApplet = true;
}

function registerParentApplet()
{
	parentApplet = true;
}
// desktopSharing-host 
//Applets have to be embedded using object and embed for them to work on both ff and ie 
//The same applet is specified in both object and embed tags -> each browser interprets either the object tag or the embed tag but not both.
//The catch is the applet name shouldn't be the same. So, to get around it, we give different names and obtain the proper name using this function.
function getBrowserIndependentApplet(){
	var applet ;
	if(swtApplet)
	{
		if(!parentApplet)
		{
			return (new SWTApplet());
		}
		else
		{
			return (new ParentApplet());
		}
	}
	
	applet = document.hqtoolIE;
	if(isValidAppletElement(applet)) return applet;
	
	applet = document.hqtool;
	if(isValidAppletElement(applet)) return applet;

	if(frames['appletFrame'] != null){
		applet = frames['appletFrame'].document.hqtoolIE;
		if(isValidAppletElement(applet)) return applet;
	}
	
	if(frames['appletFrame'] != null){
		applet = frames['appletFrame'].document.hqtool;
		if(isValidAppletElement(applet)) return applet;
	}
	
	return applet;
}

function isValidAppletElement(applet){
	return (applet != null) && (typeof(applet) != "undefined") && (typeof(applet.swfLoaded) != "undefined");
}

function deskTopSharing_handleEvent(event){
	getBrowserIndependentApplet().handleRDCMessage(event);
}
function desktopSharingJava_SetFlowName(flowname){
	desktopSharingStreamName = flowname;
	getBrowserIndependentApplet().desktopSharingJava_SetFlowName(flowname);
}
function desktopSharingJava_SetServerUrl(serverurl){
	desktopSharingURL = serverurl;
	getBrowserIndependentApplet().desktopSharingJava_SetServerUrl(serverurl);
}
function desktopSharingJava_ConnectToServer(){
	getBrowserIndependentApplet().desktopSharingJava_ConnectToServer();
}
function desktopSharingJava_StartStreaming(){
	//alert(getBrowserIndependentApplet());
	try
	{
		if(getBrowserIndependentApplet() === undefined || getBrowserIndependentApplet() == null)
		{
			setTimeout('showDesktopError()', 1000);
			return false;
		}
		else
		{
			return getBrowserIndependentApplet().desktopSharingJava_StartStreaming();
		}
	}
	catch(e)
	{
		//alert(e);
	}
}

function startDesktopSharing(source,mic)
{
	desktopStartedFromJS = true;
	var message = "<message>\n<command>startStream</command>\n" +
			"<destination>vencoder</destination>\n" +
			"<parameters>\n" +
			"<videoCaptureSource>desktop</videoCaptureSource>\n" +
			"<cam> "+source+" </cam>\n" +
			"<mic> "+mic+" </mic>\n" +
			"<url>"+desktopSharingURL+"</url>\n" +
			"<streamName>"+desktopSharingStreamName+"_desktop"+"</streamName>\n" +
			"<bitrate>" + "500;:" + "500</bitrate>\n" +
			"<frameSize>25</frameSize>\n" +
			"<codec>avc1</codec>\n" +
			"</parameters>\n" +
			"</message>"; 
	getBrowserIndependentApplet().handleMessage(message);
}

function stopStream()
{
	var message = "<message>\n<command>stopStream</command>\n" +
	"<destination>vencoder</destination>\n" +
	"</message>";
	getBrowserIndependentApplet().handleMessage(message);
	desktopStreamingStopped();
}

function showDesktopError()
{
	alert("Unable to launch Screen Sharing.\nInstall Java and restart your browser to enable this.");
	desktopStreamingStopped();
}
function desktopSharingJava_StopStreaming(){
	return getBrowserIndependentApplet().desktopSharingJava_StopStreaming();
}
function desktopSharingJava_SetBitRate(rate){
	getBrowserIndependentApplet().desktopSharingJava_SetBitRate(rate);
}
function desktopSharingJava_SetKeyFrameDelay(millis){
	getBrowserIndependentApplet().desktopSharingJava_SetKeyFrameDelay(millis);
}
function desktopSharingJava_SetNumIntraFrames(intraframes){
	getBrowserIndependentApplet().desktopSharingJava_SetNumIntraFrames(intraframes);
}
function desktopSharingJava_SetFrameDelay(millis){
	getBrowserIndependentApplet().desktopSharingJava_SetFrameDelay(millis);
}

function showCustomInviteDialog()
{
	try
	{
		displayInviteDialog(flashvars.flow);
	}
	catch(e)
	{
	}
}
function customMicrophoneMute(state)
{
	try
	{
		muteMicrophone(state);
	}
	catch(e)
	{
	}
}

function debugIt(str){
	alert(str);
}
//desktop flash interop javascritp 
var javaLoadDone = false;
var swfLoadDone = false;

var swfConsoleType = 'clientConsole';

function getSwfObject(consoleName){
	var client = window.getFlashMovie(consoleName);
	return client;
}


function getTheFlashMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
    	return window[movieName]
    }
    else {
    	return document[movieName]
    }
}

function loadAppletToInitializeDesktopPanel()
{
	var client = getTheFlashMovie(swfConsoleType);
	
	if(client != null && typeof(client.loadAppletToInitializeDesktopPanel) == "function"){
		try
		{
			client.loadAppletToInitializeDesktopPanel();
		}
		catch(e)
		{
		}
			
	}
}

function participantStartDesktopShare()
{
	var client = getTheFlashMovie(swfConsoleType);
	
	if(client != null && typeof(client.participantStartDesktopShare) == "function"){
		try
		{
			client.participantStartDesktopShare();
		}
		catch(e)
		{
		}
	}
}




var swfNotified = false;
function notifySwfOfJavaLoad(){
	
	var client = getTheFlashMovie(swfConsoleType);
	
	if(client != null && typeof(client.javaAppletLoaded) == "function"){
		try
		{
			if(!swfNotified)
			{
				client.javaAppletLoaded();
			}
		}
		catch(e)
		{
		}
			
	}
	else{
		//try in 5 secs again although this should never be triggered if <flash>.javaAppletLoaded is present.
		setTimeout("notifySwfOfJavaLoad()",5000);
	}
}

function notifyJavaOfSwfLoad(){
	// NOT REQUIRED AS OF NOW
	
	/*var app = getBrowserIndependentApplet();
	
	if(app != null && typeof(app.swfLoaded) == "function")
	{
		getBrowserIndependentApplet().swfLoaded();
	}
	else
	{
		// Try in 5 seconds again
		//setTimeout("notifyJavaOfSwfLoad()",5000);
	}*/
}
function isJavaPresent()
{
	var version = '1.6.0_10';
	var minorVersion = '10';
	var majorVersion = '1.6';
	
	var foundJava = false;
	// We also support Macs with 1.5 but the minorVersion needs to be different
	if(navigator.platform == 'MacIntel')
	{
		if(!deployJava.versionCheck(majorVersion))
		{
			majorVersion = '1.5';
			minorVersion = '20';
		}
		else
		{
			//Anything with Java 1.6 is OK on Macs
			foundJava = true;
			return foundJava;
		}
	}
	
	var getJREs = deployJava.getJREs();
	
	for(var i=0;i<getJREs.length;i++)
	{
		var detectedMajorVersion = parseFloat(getJREs[i]);
		var requiredMajorVersion = parseFloat(majorVersion)
		//if majorVersion == 1.6
		if( detectedMajorVersion == requiredMajorVersion)
		{
			//alert(getJREs[i].substring(getJREs[i].indexOf("_")+1));
			if(parseInt(getJREs[i].substring(getJREs[i].indexOf("_")+1)) >= minorVersion)
			{
				foundJava = true;
				break;
			}
		}
		//if majarVersion > 1.6
		if(detectedMajorVersion > requiredMajorVersion)
		{
			foundJava = true;
			break;
		}
		//work around for ie where return value of getJRE[i] doesn't include minor version (1.6.0_10 or 1.6.0_29 give the same value of 1.6.0)
		//This test also passes for 1.6.0_10
		if(deployJava.versionCheck('1.6.0_10+'))
		{
			foundJava = true;
			break;
		}
		
	}
	return foundJava;;
}

function javaAppletLoaded(flag)
{
	flag = (typeof flag == 'undefined') ? true : flag;
	
	javaPresent = flag;
	
	javaLoadDone = true;
	//alert("Applet Loaded");
	setTimeout('notifyChildren()', 600);
}

function notifyChildren()
{
	if(swfLoadDone){
		notifySwfOfJavaLoad();
		notifyListeners();
		//notifyJavaOfSwfLoad();		
	}
	try
	{
		appletLoaded();
	}catch(e)
	{
	}
}

function notifyListeners()
{
	if(swfLoadDone && javaLoadDone)
	{
		try
		{
			listener.consoleLoaded();
		}
		catch(e)
		{
		}	
	}
}


function installPresenterSoftware()
{
	getBrowserIndependentApplet().jsInstallPresenterSoftware();
}
function flashLoaded(){
	swfLoadDone = true;
	if(javaLoadDone){
		//notifyJavaOfSwfLoad();
		notifySwfOfJavaLoad();
	}
	notifyListeners();
}
function hostInitialized()
{
	try
	{
		consoleInitialized();
	}
	catch(err)
	{
	}
}
function refreshPage()
{
	alert("You need to restart your browser for the settings to take effect.");
	//window.location.reload();
}


function desktopStreamPublishStart(){
	var client = getTheFlashMovie(swfConsoleType);
	if(client != null && typeof(client.desktopStreamPublishStart) == "function")
	{
		client.desktopStreamPublishStart();
		if(desktopStartedFromJS)
		{
			client.desktopStreamingStarted();
		}
	}
	else
	{
		alert("Error in notifying desktop stream publish start");
	}
	
	if ((parent != null) && (parent != this) && (typeof(parent.desktopSharingStarted) == "function"))
	{
		parent.desktopSharingStarted();
	}
}

function controlMessageReceived(str)
{
	var client = getTheFlashMovie(swfConsoleType);
	if ((client != null) && (typeof(client.onJSControlMessage) == "function"))
	{
		
		client.onJSControlMessage(str+"");
	}
	else
	{
		//alert("Error in notifying desktop streaming stopped");
	}
	/*var command = "";
	if (window.DOMParser)
    {
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(str,"text/xml");
            command = xmlDoc.documentElement.childNodes[0].textContent;
    }
    else // Internet Explorer
    {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(str);
            command = xmlDoc.documentElement.childNodes[0].text;
    }
    if(command == "serverStarted")
    {
    	setTimeout("startHeartBeat();", 30000);
    }
    else if(command == "heartBeat")
	{
    	replyToHeartBeat();
	} */
}

function startHeartBeat()
{
	 var message;

     message = "<message>\n<command>startHeartBeat</command>\n";
     message += "<destination>vencoder</destination>\n" +
     "<parameters>\n" +
 	"<heartBeatInterval>4</heartBeatInterval>\n "+
 	"</parameters>\n";
     message += "</message>";

     getBrowserIndependentApplet().handleMessage(message);
}

function stopHeartBeat()
{
	 var message;

     message = "<message>\n<command>stopHeartBeat</command>\n";
     message += "<destination>vencoder</destination>\n" +
     "<parameters>\n" +
 	"</parameters>\n";
     message += "</message>";

     getBrowserIndependentApplet().handleMessage(message);
}

function replyToHeartBeat()
{
	 var message;

     message = "<message>\n<command>heartBeatReply</command>\n";
     message += "<destination>vencoder</destination>\n<parameters>\n";
     message += "</parameters>\n</message>";

     getBrowserIndependentApplet().handleMessage(message);
}

function desktopStreamingStopped()
{
	var client = getTheFlashMovie(swfConsoleType);
	if ((client != null) && (typeof(client.desktopStreamingStopped) == "function"))
	{
		client.desktopStreamingStopped();
	}
	else
	{
		//alert("Error in notifying desktop streaming stopped");
	}
	
	if ((parent != null) && (parent != this) && (typeof(parent.desktopSharingStopped) == "function"))
	{
		parent.desktopSharingStopped();
	}
}

function desktopSharingInitialized()
{
	if ((parent != null) && (parent != this) && (typeof(parent.desktopSharingInitialized) == "function"))
	{
		parent.desktopSharingInitialized();
	}
}

function desktopSharingPlaybackStarted()
{
	if ((parent != null) && (parent != this) && (typeof(parent.desktopSharingPlaybackStarted) == "function"))
	{
		parent.desktopSharingPlaybackStarted();
	}
}

function desktopSharingPlaybackStopped()
{
	if ((parent != null) && (parent != this) && (typeof(parent.desktopSharingPlaybackStopped) == "function"))
	{
		parent.desktopSharingPlaybackStopped();
	}
}

//Detect if the browser is IE or not.
//If it is not IE, we assume that the browser is NS.
var isIE = document.all ? true : false;
		
//If NS -- that is, !IE -- then set up for mouse capture
if (!isIE)
{
	document.captureEvents(Event.MOUSEMOVE);
}

document.onmousemove = handleMouseMove;

function handleMouseMove(e)
{
	var evt;
	
	evt = window.event || e;
	computeContentPosition(evt);
}

var contentX = null;
var contentY = null;

function computeContentPosition(evt)
{
	contentX = evt.screenX - evt.clientX;
	contentY = evt.screenY - evt.clientY;
}

function getContentX()
{
	if (contentX != null)
	{
		return contentX;
	}
	else
	{
		return null;
	}
}

function getContentY()
{
	if (contentY != null)
	{
		return contentY;
	}
	else
	{
		return null;
	}
}

function desktopSharingJava_SetCombinedVideoFlowName(flowName){
	getBrowserIndependentApplet().desktopSharingJava_SetCombinedVideoFlowName(flowName);
}

function desktopSharingJava_SetCombinedVideoServerURL(serverURL){
	getBrowserIndependentApplet().desktopSharingJava_SetCombinedVideoServerURL(serverURL);
}

function desktopSharingJava_StartCombinedVideoStreaming(x, y, width, height)
{
	var contX;
	var contY;
	
	contX = getContentX();
	contY = getContentY();
	
	return getBrowserIndependentApplet().desktopSharingJava_StartCombinedVideoStreaming(x, y, width, height);
}

function desktopSharingJava_StopCombinedVideoStreaming()
{
	return getBrowserIndependentApplet().desktopSharingJava_StopCombinedVideoStreaming();
}

function desktopSharingJava_SetCombinedVideoRegion(x, y, width, height)
{
	var contX;
	var contY;
	
	contX = getContentX();
	contY = getContentY();
	if ((contX != null) && (contY != null))
	{
		getBrowserIndependentApplet().desktopSharingJava_SetCombinedVideoRegion((contX + x), (contY + y),
				                                                                width, height);
	}
}



function assignCallBack(param)
{
	callbackClientName = param;
}

function checkPlugin()
{
	/*try
	{
		getBrowserIndependentApplet().jsCheckAndStopFME();
	}
	catch(err)
	{
	}*/
}

function sendMessageToPlugin(message)
{
	getBrowserIndependentApplet().handleMessage(message);
}


function encoderStreamStopped(status,code)
{
	try
	{
		setTimeout('streamStopped(\''+status+'\',\''+code+'\')', 300);
	}
	catch(err)
	{
	}
}

function startArchiving()
{
	try
	{
		getFlashMovie(callbackClientName).startArchiving();
	}catch(err)
	{
	}
}

function stopArchiving()
{
	try
	{
		getFlashMovie(callbackClientName).stopArchiving();
	}catch(err)
	{
	}
}

function stopRecording()
{
	//alert('Ending event');
	try
	{
		getFlashMovie(callbackClientName).endEvent();
	}catch(err)
	{
	}
}

function streamStopped(status,code)
{
	try
	{
		getFlashMovie(callbackClientName).streamStopped(status,code);
	}catch(err)
	{
	}
}

var port = 5432;

function setControlPort(controlPort)
{
	port = parseInt(controlPort+"");
}

function getControlPort()
{
	/*
	 * Want to make sure we are returning int here.
	 */
	
	return parseInt(port+"");
}

function setPluginPresent(status)
{
	if(status == "true")
	{
		pluginPresent = true;
	}
	else
	{
		pluginPresent = false;
	}
	try
	{
		getFlashMovie(callbackClientName).pluginPresent();
	}
	catch(err)
	{
	}
}

function displayHighPerformanceModeWarning()
{
	try
	{
		getFlashMovie(callbackClientName).displayHighPerformanceModeWarning();
	}
	catch(err)
	{
	}
}

function setSystemCapablity(status)
{
	systemCapable = status;
	try
	{
		getFlashMovie(callbackClientName).systemCapability(status);
	}
	catch(err)
	{
	}
}
function isSystemCapable()
{
	return systemCapable;
}

function isPluginPresent()
{
	return pluginPresent;
}
function startEncoder(cam,camDimension,mic,url,stream,bitrate,framesize, codec)
{
	try
	{
		//alert(codec);
		if(codec == null)
		{
			getBrowserIndependentApplet().jsStartStream(cam,camDimension, mic, url, stream, bitrate,framesize, "flv");
		}
		else
		{
			//alert(codec);
			getBrowserIndependentApplet().jsStartStream(cam,camDimension, mic, url, stream, bitrate,framesize, codec);
		}
	}
	catch(err)
	{
	}
}

function stopEncoder()
{
	try
	{
		getBrowserIndependentApplet().jsStopAll();
		
	}
	catch(err)
	{
	}
	try
	{
		stopAndroidEncoder();
	}
	catch(err)
	{
	}
	
}

//Detects if the current device is an Android OS-based device.
function requiresFlashAudioTermination()
{
	var uagent = navigator.userAgent.toLowerCase();
var deviceAndroid = "android";
 if (uagent.search(deviceAndroid) > -1)
    return true;
 else
    return false;
}


function setSkypeName(contactName)
{
	skypeName = contactName;
	try
	{
		getFlashMovie(callbackClientName).setRegsiteredSkypeName(contactName);
	}
	catch(err)
	{
	}
}
function getSkypeName()
{
	return skypeName;
}
/*function startSkypeCall(contactName)
{
	try
	{
		getBrowserIndependentApplet().jsCallContact(contactName);
	}catch(err)
	{
	}
}

function endSkypeCall()
{
	try
	{
		getBrowserIndependentApplet().jsEndCall();
	}catch(err)
	{
	}
}

function openSkypeConversation(skypeName)
{
	try
	{
		getBrowserIndependentApplet().jsOpenConversation(skypeName);
	}catch(err)
	{
	}
} */
function getFlashMovie(movieName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	  return (isIE) ? window[movieName] : document[movieName];
}

function isInternetExplorer()
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return isIE;
}

function installEncoder()
{
	if(getBrowserIndependentApplet() == null)
	{	
		loadDesktopSharingApplet();
	}
	else
	{
		try
		{
			//alert('here');
			if(isVEncoder && !isPluginPresent())
			{
				getBrowserIndependentApplet().jsInstallEncoder();
			}
		}
		catch(err)
		{ 
		}
	}
}

var participantsWithoutPlugin = [];

function addParticipantWithoutPlugin(usr)
{
	try
	{
		participantsWithoutPlugin[usr] = usr;
	}
	catch(e)
	{
		
	}
}

function getListOfParticipantsWithoutPlugin()
{
	var xmlString = '<?xml version="1.0" encoding="UTF-16"?>';
	xmlString += '<contacts>';
	for(i in participantsWithoutPlugin)
	{
		xmlString += '<skypeID>';
		xmlString += participantsWithoutPlugin[i];
		xmlString += '</skypeID>';
	}
	xmlString += '</contacts>';
	try
	{
		inviteParticipantsWithoutPlugin(xmlString);
	}
	catch(e)
	{
		
	}
}

var vhDriverInstallActive = false;
var appletAdded = false;
function installVHDriver()
{
	if(!navigator.javaEnabled()){
		var answer = confirm('You Require the latest version of Java to continue. \n Would you liek to install Java from http://java.com');
		if(answer)
			window.open('http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=java.com:80');
	}
	else{
		if(getBrowserIndependentApplet() == null)
		{	
			addApplet("hqtool","com.vivu.browserplugin.ViVuHQTool","/ViVuFlashWeb/plugin/browserplugin.jar?t=<%=(new Date()).getTime()%>",0,0,"enable Java",'installVHDriver');
		}
		else
		{
			try
			{
				getBrowserIndependentApplet().jsInstallVHdriver();
				vhDriverInstallActive = true;
			}
			catch(err)
			{ 
				vhDriverInstallActive = false;
			}
		}
	} 	
}

function addApplet(id,code,codebase,width,height,alt,message){
	  if(appletAdded)
		  return;
	  var a=document.createElement('applet');
	  a.setAttribute('id',id);
	  a.setAttribute('code',code);
	  a.setAttribute('archive',codebase);
	  a.setAttribute('width',width);
	  a.setAttribute('height',height);
	  a.setAttribute('alt',alt);
	  a.setAttribute('Message',message);
	  document.getElementById('appletDiv').appendChild(a);
	  appletAdded = true;
	}

/*
 * Camera list
 */

var cameraList = "";
function setCameraList(list)
{
	cameraList = list;
	
	try
	{
		getFlashMovie(callbackClientName).setCameraList(list);
	}
	catch(err)
	{
	}
}

function getCameraList()
{
	return cameraList;
}

// THis is the code for running encoder and desktop sharing while running in the swt mode
function SWTApplet()
{
	this.handleRDCMessage = function(event)
	{
		handleRDCMessage(event);
	}
	this.desktopSharingJava_SetFlowName = function(event)
	{
		desktopSharingJava_SetFlowName(event);
	}
	this.desktopSharingJava_SetServerUrl = function(serverurl)
	{
		desktopSharingJava_SetServerUrl(serverurl);
	}
	this.desktopSharingJava_ConnectToServer = function()
	{
		desktopSharingJava_ConnectToServer();
	}
	this.desktopSharingJava_StartStreaming = function()
	{
		return desktopSharingJava_StartStreaming();
	}
	this.desktopSharingJava_StopStreaming = function()
	{
		return desktopSharingJava_StopStreaming();
	}
	this.desktopSharingJava_SetBitRate = function(rate)
	{
		desktopSharingJava_SetBitRate(rate);
	}
	this.desktopSharingJava_SetKeyFrameDelay = function(millis)
	{
		desktopSharingJava_SetKeyFrameDelay(millis);
	}
	this.desktopSharingJava_SetNumIntraFrames = function(intraframes)
	{
		desktopSharingJava_SetNumIntraFrames(intraframes);
	}
	this.desktopSharingJava_SetFrameDelay = function(millis)
	{
		desktopSharingJava_SetFrameDelay(millis);
	}
	
	this.desktopSharingJava_SetCombinedVideoFlowName = function(flowName)
	{
		desktopSharingJava_SetCombinedVideoFlowName(flowName);
	}
	
	this.desktopSharingJava_SetCombinedVideoServerURL = function(serverURL)
	{
		desktopSharingJava_SetCombinedVideoServerURL(serverURL);
	}
	
	this.desktopSharingJava_StartCombinedVideoStreaming = function(x, y, width, height)
	{
		return desktopSharingJava_StartCombinedVideoStreaming(x, y, width, height);
	}
	
	this.desktopSharingJava_StopCombinedVideoStreaming = function()
	{
		return desktopSharingJava_StopCombinedVideoStreaming();
	}
	
	this.desktopSharingJava_SetCombinedVideoRegion = function(x, y, width, height)
	{
		desktopSharingJava_SetCombinedVideoRegion(x, y, width, height);
	}
	
	this.sendMessageToPlugin = function(message)
	{
		sendMessageToPlugin(message);
	}
	
	this.handleMessage = function(message)
	{
		sendMessageToPlugin(message);
	}
	
	this.swfLoaded = function()
	{
		swfLoaded();
	}
	this.jsCheckAndStopFME = function()
	{
		jsCheckAndStopFME();
	}
	this.jsStartStream = function(cam,camDimension, mic, url, stream, bitrate,framesize, codec)
	{
		jsStartStream(cam,camDimension, mic, url, stream, bitrate,framesize, codec);
	}
	this.jsStopAll = function()
	{
		jsStopAll();
	}
}


//THis is the code for running encoder and desktop sharing while running in the swt mode && in iframe mode.
function ParentApplet()
{
	this.handleRDCMessage = function(event)
	{
		parent.handleRDCMessage(event);
	}
	this.desktopSharingJava_SetFlowName = function(event)
	{
		parent.desktopSharingJava_SetFlowName(event);
	}
	this.desktopSharingJava_SetServerUrl = function(serverurl)
	{
		parent.desktopSharingJava_SetServerUrl(serverurl);
	}
	this.desktopSharingJava_ConnectToServer = function()
	{
		parent.desktopSharingJava_ConnectToServer();
	}
	this.desktopSharingJava_StartStreaming = function()
	{
		return parent.desktopSharingJava_StartStreaming();
	}
	this.desktopSharingJava_StopStreaming = function()
	{
		return parent.desktopSharingJava_StopStreaming();
	}
	this.desktopSharingJava_SetBitRate = function(rate)
	{
		parent.desktopSharingJava_SetBitRate(rate);
	}
	this.desktopSharingJava_SetKeyFrameDelay = function(millis)
	{
		parent.desktopSharingJava_SetKeyFrameDelay(millis);
	}
	this.desktopSharingJava_SetNumIntraFrames = function(intraframes)
	{
		parent.desktopSharingJava_SetNumIntraFrames(intraframes);
	}
	this.desktopSharingJava_SetFrameDelay = function(millis)
	{
		parent.desktopSharingJava_SetFrameDelay(millis);
	}
	
	this.desktopSharingJava_SetCombinedVideoFlowName = function(flowName)
	{
		parent.desktopSharingJava_SetCombinedVideoFlowName(flowName);
	}
	
	this.desktopSharingJava_SetCombinedVideoServerURL = function(serverURL)
	{
		parent.desktopSharingJava_SetCombinedVideoServerURL(serverURL);
	}
	
	this.desktopSharingJava_StartCombinedVideoStreaming = function(x, y, width, height)
	{
		return parent.desktopSharingJava_StartCombinedVideoStreaming(x, y, width, height);
	}
	
	this.desktopSharingJava_StopCombinedVideoStreaming = function()
	{
		return parent.desktopSharingJava_StopCombinedVideoStreaming();
	}
	
	this.desktopSharingJava_SetCombinedVideoRegion = function(x, y, width, height)
	{
		parent.desktopSharingJava_SetCombinedVideoRegion(x, y, width, height);
	}
	
	this.sendMessageToPlugin = function(message)
	{
		parent.sendMessageToPlugin(message);
	}
	
	this.handleMessage = function(message)
	{
		parent.sendMessageToPlugin(message);
	}
	
	this.swfLoaded = function()
	{
		parent.swfLoaded();
	}
	this.jsCheckAndStopFME = function()
	{
		parent.jsCheckAndStopFME();
	}
	this.jsStartStream = function(cam,camDimension, mic, url, stream, bitrate,framesize, codec)
	{
		parent.jsStartStream(cam,camDimension, mic, url, stream, bitrate,framesize, codec);
	}
	this.jsStopAll = function()
	{
		parent.jsStopAll();
	}
}



function inviteVuRoomLessJoinees(skypeid)
{
	try
	{
		getFlashMovie(callbackClientName).inviteVuRoomLessJoinees(skypeid);
	}
	catch(e)
	{
	}		
}

/***
 * related to chat API to register object, send public message, send private message and handling received messages
 **/
var chatRegistered = false;
var chatListener = null;
function registerChatListener(l)
{
	chatListener = l;
	chatRegistered = true;
}

/***
* Become presenter API
**/

//------------API---------------
function enableChangePresenter()
{
	//send message to enable change presenter
	getFlashMovie(callbackClientName).enableChangePresenter();
}

function disableChangePresenter()
{
	//send message to disable change presenter
	getFlashMovie(callbackClientName).disableChangePresenter();
}

function becomePresenter()
{
	//send message to become presenter
	getFlashMovie(callbackClientName).becomePresenter();
}

//----------CALLBACK API-----------------
var becomePresenterListener = null;
var registeredBecomePresenterListener = false;
function registerBecomePresenterListener(l)
{
	becomePresenterListener = l;
	registeredBecomePresenterListener = true;
	
}

function notifyCurrentPresenter(p)
{
	if(registeredBecomePresenterListener && becomePresenterListener)
		becomePresenterListener.currentPresenterChanged(p);
}

function notifyChangePresenterEnabled()
{
	if(registeredBecomePresenterListener && becomePresenterListener)
		becomePresenterListener.changePresenterEnabled();
}

function notifyChangePresenterDisabled()
{
	if(registeredBecomePresenterListener && becomePresenterListener)
		becomePresenterListener.changePresenterDisabled();
}



