// #######################################################################################################
// LearnCube Funktionen für Rechtsklick, Returnweitergabe und Window-Handling

// Author: Che Hohwieler, Kai Jansen, Frank Blöcher
// #######################################################################################################
//In welchem Browser läuft das framework
browserType = undefined;

//*************************************************************************************

//-------------------------------------------------------------------------------------
//sende klick an swf
function sendRightClick(Event) {
		var e = Event || window.event;

        //Mausklick-Position muss bei anderer Screen-Resolution korrigiert werden
        var mouseX = e.clientX - checkScreenWidth ();
        var mouseY = e.clientY - checkScreenHeight ();

				//rechte Maustaste? IE oder Firefox
        if(e.button == 2 || e.type == "contextmenu" ){
				/* replaced with mlab workaround*/
                document.framework.SetVariable("_root.rightClickHotSpotMouseX", mouseX);
                document.framework.SetVariable("_root.rightClickHotSpotMouseY", mouseY);
                document.framework.SetVariable("_root.rightClickHotSpotClick", "right");
 				/*setFlashVariables('framework','rightClickHotSpotMouseX='+mouseX);
				setFlashVariables('framework','rightClickHotSpotMouseY='+mouseY);
				setFlashVariables('framework','rightClickHotSpotClick='+"right");*/
        }else{
                //also isser 1 und damit links -> richtiger Hotspot, falsche Taste
				/* replaced with mlab workaround*/
                document.framework.SetVariable("_root.rightClickHotSpotMouseX", mouseX);
                document.framework.SetVariable("_root.rightClickHotSpotMouseY", mouseY);
                document.framework.SetVariable("_root.rightClickHotSpotClick", "left");
				/*setFlashVariables('framework','rightClickHotSpotMouseX='+mouseX);
				setFlashVariables('framework','rightClickHotSpotMouseY='+mouseY);
				setFlashVariables('framework','rightClickHotSpotClick='+"left");*/
        }

}

//-------------------------------------------------------------------------------------
//sende wrong klick an swf
function sendWrongClick(Event){
		var e = Event || window.event;
		//Mausklick-Position muss bei anderer Screen-Resolution korrigiert werden
		var mouseX = e.clientX - checkScreenWidth ();
        var mouseY = e.clientY - checkScreenHeight ();

        //für den melg_player ist "left" gleichbedeutend mit "falsch"
		/* replaced with mlab workaround*/
		document.framework.SetVariable("_root.rightClickHotSpotMouseX", mouseX);
        document.framework.SetVariable("_root.rightClickHotSpotMouseY", mouseY);
        document.framework.SetVariable("_root.rightClickHotSpotClick", "right");
		/*setFlashVariables('framework','rightClickHotSpotMouseX='+mouseX);
		setFlashVariables('framework','rightClickHotSpotMouseY='+mouseY);
		setFlashVariables('framework','rightClickHotSpotClick='+"right");*/
}

//-------------------------------------------------------------------------------------
//@method checkScreenWidth
//@descripxion Für Rechtsklick auf Hotspots, falls Auflösung grösser als Einstellung in
// der learncube.xml
//@date 14.12.2004
//@author Che Hohwieler
function checkScreenWidth () {
	var windowBreite = undefined;
	if ( navigator.userAgent.indexOf( "Firefox" ) != -1 || navigator.userAgent.indexOf( "Netscape" ) != -1) {
		windowBreite = window.innerWidth;
	}
	else {
		windowBreite = document.body.offsetWidth;
	}

	var offsetBreite = 0;
	if (windowBreite > framework_width) {
	     offsetBreite = (windowBreite - framework_width) / 2;
	}

 return offsetBreite;
}
//-------------------------------------------------------------------------------------
//@method checkScreenHeight
//@descripxion Für Rechtsklick auf Hotspots, falls Auflösung grösser als Einstellung in
// der learncube.xml
//@date 14.12.2004
//@author Che Hohwieler
function checkScreenHeight () {
	var windowHoehe = undefined;
	if ( navigator.userAgent.indexOf( "Firefox" ) != -1 || navigator.userAgent.indexOf( "Netscape" ) != -1) {
		windowHoehe = window.innerHeight;
	}
	else {
		windowHoehe = document.body.offsetHeight;
	}
	var offsetHoehe = 0;
	if (windowHoehe > framework_height) {
	     offsetHoehe = (windowHoehe - framework_height) / 2;
	}

 return offsetHoehe;
}
//-------------------------------------------------------------------------------------
//positioniert layer für rechtsklick
//Wird vom melg_player aufgerufen
// @Param: 	x = x-Position
//		y = y-Position
//		w = Breite
//		h = Hoehe
//	    rcHsp = rightClickFeedbackHotspot (Boolean) wenn es sich um einen FeedbackHotspot handelt

function drawRightClick(x,y,w,h,rcHsp){
	//layer positionieren (Flash übergibt string, deshalb parseInt())
	//Angabe "px" ist MUSS für FireFox!
	document.getElementById("catchRightClick").style.left = (parseInt(x)+parseInt(document.getElementById("framework").style.left))*scale/100+"px";
	document.getElementById("catchRightClick").style.top  = (parseInt(y)+parseInt(document.getElementById("framework").style.top))*scale/100+"px";

	//Inhalt (image) skalieren (document.catchRightClickImg ist das blank.gif im layer)
	document.catchRightClickImg.width  = (parseInt(w)*scale)/100;
	document.catchRightClickImg.height = (parseInt(h)*scale)/100;

	//Nur wenn es sich um einen FeedbackHotspot handelt
	if (rcHsp) {
			var offset = document.getElementById("framework").style.left;
			
	        //und dann den catchWrongClick positionieren
	       	if ( parseInt(x) > -1 ) {
        	       	//document.getElementById("catchWrongClick").style.left = (offset+15)+"px";
       	       		document.getElementById("catchWrongClick").style.left = "0px";
					//catchWrongClickImg Image skalieren
		        	document.catchWrongClickImg.width  = framework_width;
        			document.catchWrongClickImg.height  = framework_height-50;
	        }
	}
	//sonst wird das catchWrongClick-Image nicht gebraucht
	else {
         document.getElementById("catchWrongClick").style.left = -framework_width+"px";
	}

}

//-------------------------------------------------------------------------------------
//Öffnet neues Fenster
function newPopUp(wUrl,wTitle,hSize,vSize, wOptions){
		 newWin = window.open(wUrl,wTitle,'width='+hSize+',height='+vSize+','+wOptions);
		 newWin.moveTo(((screen.width/2)-(hSize/2)),((screen.height/2)-(vSize/2)));
		 newWin.focus();
}

//-------------------------------------------------------------------------------------
function framework_DoFSCommand(command, args) {
  if (command == "setContent") {
        newWin.setContent(args);
  }
}
//-------------------------------------------------------------------------------------
function closePrint() {
  if (window.newWin) {
    window.newWin.close();
  }

}
//-------------------------------------------------------------------------------------
//Schliesst aktuelles Fenster
function closeWin() {
	if (doLSOForwardOnFinish == true) {
		return;
	}

	var tryOther = false;
	try {
        self.top.close();
	} catch (e) {
		tryOther = true;
	}
	if (tryOther == true){ 
		tryOther = false;
		try {
	        self.top.opener.opener = self.top;
	        self.top.opener.close();
		} catch (e) {
			tryOther = true;
		}
	}
	if (tryOther == true){ 
		tryOther = false;
		try {
	        self.close();
		} catch (e) {
			tryOther = true;
		}
	}
}

//-------------------------------------------------------------------------------------
//sende Return an swf, Bug im Texteingabefeld
//@method returnKeyPressed
//@date 17.09.2004
//@author Che Hohwieler
function returnKeyPressed(evt) {
	//var e = Event || window.event;
	evt || (evt = window.event);
	var keyCode = evt.which ? evt.which : evt.keyCode;
	//ASCII/ANSI-Wert fuer Return-Taste
	if (keyCode == 13) {
	/* replaced with mlab workaround*/
     document.framework.SetVariable("_root.ReturnKeyPressed", "true");
	//setFlashVariables('framework','ReturnKeyPressed='+"true");
	}

}


//-------------------------------------------------------------------------------------
//Listener aktivieren
function init() {
	 checkBrowser();
	 if ( browserType == "Firefox" ) {
	 		//Eventlistener für Rechtsklick anhaengen
	 		//document.getElementById("catchRightClick").addEventListener("contextmenu", sendRightClick, true);
			//Eventlistener für Links-/Rechtsklick auf FeedbackHotspot anhaengen
			//document.getElementById("catchWrongClick").addEventListener("contextmenu", sendWrongClick, true);
			//document.getElementById("catchWrongClick").addEventListener("click", sendWrongClick, true);
			//Eventlistener für Return-Taste anhaengen
			//alert (document.getElementById("fw").style.height);
	 		//document.addEventListener("keypress", returnKeyPressed, true);
	 }
}
//-------------------------------------------------------------------------------------
//Browserweiche
function checkBrowser() {
	 if ( navigator.userAgent.indexOf( "Firefox" ) != -1 ) {
		browserType = "Firefox";
	 }
	 else {
		browserType = "Compatible";
	 }
}

//********** Flash-PlugIn-Test (not IE) *****************
var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";
//****************************************************





//OS Test
function checkOS() {
	var agent = navigator.userAgent;
	if(agent.indexOf('Linux') != -1)
		{ var OpSys = 'Linux'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('95') != -1))
		{ var OpSys = 'Windows 95'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('NT 4') != -1)) 
		{ var OpSys = 'Windows NT 4.0'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('NT 5.0') != -1)) 
		{ var OpSys = 'Windows 2000'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('NT 5.1') != -1)) 
		{ var OpSys = 'Windows XP'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('NT 5.2') != -1)) 
		{ var OpSys = 'Citrix'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('NT 6.0') != -1)) 
		{ var OpSys = 'Windows Vista'; }
	else if((agent.indexOf('Win') != -1) && (agent.indexOf('98') != -1))
		{ var OpSys = 'Windows 98'; }
	else if(agent.indexOf('Mac OS X') != -1)
		{ var OpSys = 'Mac OS X'; }
	else if(agent.indexOf('Mac OS 9') != -1)
		{ var OpSys = 'Mac OS 9'; }
	else { var OpSys = agent; }
	return OpSys;
}

//Browser Test
function checkBrowser() {
	var agent = navigator.userAgent;
	if(agent.indexOf('Safari/125.9') != -1)
		{ var browser = 'Safari 1.2.3'; }
	else if(agent.indexOf('Safari/125.8') != -1)
		{ var browser = 'Safari 1.2.2'; }
	else if(agent.indexOf('Safari/125.1') != -1)
		{ var browser = 'Safari 1.2.1'; }
	else if(agent.indexOf('Safari/125') != -1)
		{ var browser = 'Safari 1.2'; }
	else if(agent.indexOf('Safari/92') != -1)
		{ var browser = 'Safari 1.1'; }
	else if(agent.indexOf('Safari/85') != -1)
		{ var browser = 'Safari 1.0'; }
	else if(agent.indexOf('MSIE 6.0') != -1)
		{ var browser = 'Microsoft Internet Explorer 6.0'; }
	else if(agent.indexOf('MSIE 7.0') != -1)
		{ var browser = 'Microsoft Internet Explorer 7.0'; }
	else if(agent.indexOf('MSIE 5.5') != -1)
		{ var browser = 'Microsoft Internet Explorer 5.5'; }
	else if(agent.indexOf('MSIE 5.0') != -1)
		{ var browser = 'Microsoft Internet Explorer 5.0'; }
	else if(agent.indexOf('Firefox/0.8') != -1)
		{ var browser = 'Firefox 0.8'; }
	else if(agent.indexOf('Firefox/0.9') != -1)
		{ var browser = 'Firefox 0.9'; }
	else if(agent.indexOf('Firefox/2.0') != -1)
		{ var browser = 'Firefox 2.0'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.7') != -1)) 
		{ var browser = 'Mozilla 1.7'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.6') != -1)) 
		{ var browser = 'Mozilla 1.6'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.5') != -1)) 
		{ var browser = 'Mozilla 1.5'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.4') != -1)) 
		{ var browser = 'Mozilla 1.4'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.3') != -1)) 
		{ var browser = 'Mozilla 1.3'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.2') != -1)) 
		{ var browser = 'Mozilla 1.2'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.1') != -1)) 
		{ var browser = 'Mozilla 1.1'; }
	else if((agent.indexOf('Mozilla') != -1) && (agent.indexOf('1.0') != -1)) 
		{ var browser = 'Mozilla 1.0'; }
	else if(agent.indexOf('Netscape') != -1)
		{ var browser = 'Netscape'; }
	else if(agent.indexOf('Opera') != -1)
		{ var browser = 'Opera'; }
	else { var browser = agent; }
	return browser;
 }
 
 //Cookies Test
function cookiesEnabled() { 

    var cookiesEnabled = false;
    document.cookie = "CheckerCookie=true"; 
	
	var cookieContent = document.cookie; 
 	if (cookieContent.length > 0) {
    	if( document.cookie.indexOf( "CheckerCookie=true" ) != -1 ) { 
			cookiesEnabled = true; 
			
    	} 
	}
    return cookiesEnabled; 
} 

function callJSFunc () {
alert ("callJSFunc");
}
function launchURL (wUrl,name,options) {
	if (!name) {
		name = "_blank";
	}
	try {
		newWin = window.open(wUrl,name,options);
		newWin.focus();
	} catch (e) {
		alert ("Exception in launchURL");
	}
}

