var ss_media_server;

function loadApplet(media_server)
{
	ss_media_server = media_server;
	document.getElementById("sc").innerHTML =" <applet id='ScreenSharingWidget' code='to.screensharing.applet.SSWApplet' archive='/TOClient/bin/ScreenSharingWidget.jar,/TOClient/bin/jna.jar,/TOClient/bin/escher-0.3.jar' width='10' height='0' MAYSCRIPT> <param name='fmsIp' value='" + media_server  + "'> </applet>"; 
	try
	{
		//sprawdzenie czy applet rzeczywiście się zaladował 
		document.getElementById("ScreenSharingWidget").isActive();
	}
	catch(err)
	{
		showAlert('loadApplet_NOK','not_supported_os_for_screen_sharing');
	}
}

function startApplet(ssnCode, strName, usrLogin, usrPassword, ticket, type, frameTime, keyFrameTime, bitRate, maxDelay, compression) {
	if (document.getElementById("sc").innerHTML == '') loadApplet(ss_media_server);
        //type - R (rectangle); F - fullscreen
        document.ScreenSharingWidget.startApplet(ssnCode, strName, usrLogin, usrPassword, ticket, type, frameTime, keyFrameTime, bitRate, maxDelay, compression);
}

function startStr(ssn_code, strName, user, password, ticket) {
        startApplet(ssn_code, strName, user, password, ticket, 'A', null, null, null, null, null);
}

function changeParams(type, frameTime, keyFrameTime, bitRate, maxDelay, compression)
{
        document.ScreenSharingWidget.changeParams(type, frameTime, keyFrameTime, bitRate, maxDelay, compression);
}

function changeParamsTest()
{
        changeParams('F', null, null, null, null, null);
}

function close() {
    document.ScreenSharingWidget.close();
    document.getElementById("sc").innerHTML = '';
}

function setPresentationWindowLocation(x, y, width, height) {
    var l = getApplicationLocation().split(",");
    setDocumentClientHeight();
    document.ScreenSharingWidget.setPresentationWindowLocation(parseInt(x) + parseInt(l[0]), parseInt(y) + parseInt(l[1]), width, height);
}

function setDocumentClientHeight() {
	document.ScreenSharingWidget.setDocumentClientHeight(document.getElementById("main").clientHeight);
}

function getApplicationTitle() {
    document.ScreenSharingWidget.setApplicationTitle(document.title);
}

function showAlert(str,params)
{
	getMovie("main").ssStatus(String(str),String(params));
}

function showScreenSharingAlert(str)
{
        document.form1.resultScreenSharing.value += str + "\n";
}

function getMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
		return document[movieName]
	}
}

