<!--
var snapit_x, snapit_y, snapit_width, snapit_height, snapit_contentref, _mouseloc;

// Text for speech variables
var tfs_x, tfs_y, tfs_width, tfs_height;

function checkPreview(courseId) {
	// Dummy
}


function doBeforeUnload() {
	nullFlashLoopFunction();
	doLMSFinish();
	window.onUnload = null;
}

function nullFlashLoopFunction() { 
	__flash_savedUnloadHandler = null;
}

window.onbeforeunload = doBeforeUnload;

function openwindow(parameter) {
	return openNewWindow(parameter);
}

function exit() {
	window.top.close();
	return true;
}

function returnlanguages() {
	return _courselanguage;
}
function returncoursetitle() {
	return _coursetitle;
}

function initializenewsco(parameter, id) {
	return	initializesco(parameter, id);
}

function returnbrowserparameters() {
	var newCourseName = getURLParameter("coursename");
	var newCourseLanguages = getURLParameter("language");
	var newSettingsId = getURLParameter("settingsid");
	if (newCourseName == "" || newCourseName == undefined) {
		newCourseName = _coursetitle;
	}
	if (newCourseLanguages == "" || newCourseLanguages == undefined) {
		newCourseLanguages = _courselanguage;
	}
	if (newSettingsId == "" || newSettingsId == undefined) {
		newSettingsId = _settingsid;
	}
	var returnVal = "coursename="+newCourseName+"&&courselanguages="+newCourseLanguages+"&&settingsid="+newSettingsId;
	if (_previewmode) {returnVal+="&&previewmode=true";}
	return returnVal;
}

function returncoursesize() {
	return _courseWidth + "x" + _courseHeight;
}
/**
* Opens a new browser window according to any arguments sent to the function
*/
function openNewWindow(argsString) {
	var args = argsString.split("#");
	var sURL = args[0];
	var sName = args[1];
	var sFeatures = args[2];
	window.open(sURL, sName, sFeatures);
	return true;
}

function geturl() {
	return unescape(document.URL.replace(/\\/g,"\/"));
}

function getURLParameter(paramName) {
	var url = unescape(document.URL.replace(/\\/g,"\/"));
	if (url.indexOf((paramName+"=")) != -1) {
		var paramPath = url.substring(url.indexOf((paramName+"="))+paramName.length+1,url.length);
		var endIndex = paramPath.length;
		if (paramPath.indexOf("&") != -1) {
			endIndex = paramPath.indexOf("&");
		}
		paramPath = paramPath.substring(0,endIndex);
		return paramPath;
	} else {
		return "";
	}
}

/**
* PRINT FUNCTIONALITY
*/

var textToWrite = "";

function openprintwindow() {
	textToWrite = "";
	return "openprint";
}

function addprinttext(inText) {
	if (inText.indexOf("??undefined??") != -1) {
		var textlist = inText.split("??undefined??");
		var username = prompt("Enter your name / Skriv inn navn:");
		inText = textlist[0] + username + textlist[1];
	}
	textToWrite += inText;
	return "inserttext";
}

function wrapupprintwindow() { 
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resize=yes"; 
      disp_setting+="width=650, height=600, left=50, top=25";
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><link href="publisherprint.css" rel="stylesheet" type="text/css" /><title>Publisher Print</title>'); 
   docprint.document.write('</head><body onLoad="self.print()" bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="40" marginwidth="60" marginheight="60"><center>');          
   docprint.document.write(textToWrite);
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
   return "wrapup";
}

/**
* SAVE FUNCTIONALITY
*/
function opensavewindow() {
	textToWrite = "";
	return "opensave";
}

function addsavetext(inText) {
	if (inText.indexOf("??undefined??") != -1) {
		var textlist = inText.split("??undefined??");
		var username = prompt("Enter your name / Skriv inn navn:");
		inText = textlist[0] + username + textlist[1];
	}
	textToWrite += inText;
	return "inserttext";
}

function wrapupsavewindow() { 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=50, top=25";
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><link href="publisherprint.css" rel="stylesheet" type="text/css" /><title></title>'); 
   docprint.document.write('<script lanugage="javascript">');
   docprint.document.write('function saveHtml() { document.execCommand("SaveAs",null,"PublisherCourse.txt"); }');
   docprint.document.write('</script>');
   docprint.document.write('</head><body onLoad="saveHtml()">');          
   docprint.document.write(textToWrite);
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
   return "wrapup";
}

function notify_tfs_positionchange(inparam) {
		var args          = inparam.split("-");
    tfs_x		  =	1*(args[0].split(",")[0]);
	tfs_y           = 1*(args[0].split(",")[1]);
	tfs_width        = 1*(args[1].split(",")[0]);
	tfs_height       = 1*(args[1].split(",")[1]);
	resizeLayer();



}
/**
* LAYER FUNCTIONALITY
*/

function showlayer(htmlSource) {
	// Shows external sequence in layer on top.
	var newhtml = htmlSource;
	if (newhtml.split(".")[1].toLowerCase() =="swf")
	{
		newhtml = "flashpreview_frameset.html?src="+newhtml +"&width="+ _courseWidth+ "&height=" +_contentHeight 
	}
	document.getElementById("htmlframe").src=newhtml ;
	document.getElementById("htmllayer").style.visibility="visible";
	resizeLayer();
}

function hidelayer() {
	// hides external sequence
	document.getElementById("htmlframe").src="blank.html";
	document.getElementById("htmllayer").style.visibility="hidden";
}

function showmenu() {
	// Shows content menu in layer on top
	document.getElementById("menulayer").style.visibility="visible";
	resizeLayer();
}

function hidemenu() {
	// Hides content menu
	document.getElementById("menulayer").style.visibility="hidden";
}


function resizeLayer() {
	// Sets layers in correct position (called when user resizes window)
	var posx = (document.body.clientWidth  - _courseWidth)/2;
	if (posx<0) {posx = 0}
	var posy = (document.body.clientHeight - _courseHeight)/2;
	if (posy<0) {posy = 0}

	document.getElementById("htmlframe").style.left = posx;
	document.getElementById("htmlframe").style.top =posy;


	document.getElementById("menulayer").style.left = posx;
	document.getElementById("menulayer").style.top =posy;


  
	if (snapit_width != undefined) {
		// position snapit window
	
	
		if (tfs_x == undefined)
		{
			tfs_x = 0; //_courseWidth;
			tfs_y =0; //_courseHeight;
			tfs_width = 0;
			tfs_height = 0;
		}

		// Calculate max height
		var  max_height = snapit_height ;
		if (snapit_height > _courseHeight-30-snapit_y){	max_height = _courseHeight-30-snapit_y	}

		// Calculate width and height for elements
		// Could probably be simplified - OB 2007-01-03
		document.getElementById("shieldL").style.left =posx+snapit_x;
		document.getElementById("shieldL").style.top =posy+snapit_y;
		document.getElementById("shieldL").style.width = Math.max(0,Math.min(snapit_width,tfs_x-snapit_x)) ;
		document.getElementById("filterL").style.width = Math.max(0,Math.min(snapit_width,tfs_x-snapit_x)) ;
		document.getElementById("filterL").style.height =max_height;


		document.getElementById("shieldR").style.left = posx+snapit_x+Math.max(0,Math.min(snapit_width,tfs_x-snapit_x)) + tfs_width ;
		document.getElementById("shieldR").style.top =posy+snapit_y;
		document.getElementById("shieldR").style.width = Math.max(0,   snapit_width  - (Math.max(0,Math.min(snapit_width,tfs_x-snapit_x))) -(Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width))))) ;
		document.getElementById("filterR").style.width = Math.max(0,   snapit_width  - (Math.max(0,Math.min(snapit_width,tfs_x-snapit_x))) -(Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width))))) ;
		document.getElementById("filterR").style.height = max_height;

		document.getElementById("shieldTM").style.left = posx+Math.max(snapit_x, Math.min(snapit_width,tfs_x)) ;
		document.getElementById("shieldTM").style.top =posy+snapit_y;
		document.getElementById("shieldTM").style.width =Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width)));
		document.getElementById("filterTM").style.width = Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width)));
		document.getElementById("filterTM").style.height = Math.max(0,Math.min(max_height,tfs_y-snapit_y));


		document.getElementById("shieldBM").style.left =posx+Math.max(snapit_x, Math.min(snapit_width,tfs_x)) ;
		document.getElementById("shieldBM").style.top =posy+ Math.min(max_height, tfs_y) +tfs_height;
		document.getElementById("shieldBM").style.width =Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width)));
		document.getElementById("filterBM").style.width = Math.max(0,tfs_width + Math.min(tfs_x- snapit_x,Math.min(0,snapit_x+snapit_width-tfs_x-tfs_width)));
		document.getElementById("filterBM").style.height =Math.max(0, max_height +snapit_y - (Math.min(max_height, tfs_y) +tfs_height));


	}


}



function showfilter_fromflash(argsString){
   	var args          = argsString.split("#");
    var x			  =	1*(args[0]);
	var y             = 1*args[1];
	var width         = 1*args[2];
	var height        = 1*args[3];
	var contentref    = args[4];
	showfilter(x,y,width,height,contentref);

}



function hidefilter_fromflash(){
      hidefilter();
}


function showfilter(_x, _y, _width, _height,contentref){
	//Called from snapit sequence when right click is expected
	
	snapit_x = _x;
	snapit_y = _y;
	snapit_width =_width;
	snapit_height = _height;
	snapit_contentref=contentref;
	document.getElementById("shieldL").style.visibility="visible";
	document.getElementById("shieldR").style.visibility="visible";
	document.getElementById("shieldTM").style.visibility="visible";
	document.getElementById("shieldBM").style.visibility="visible";
  document.oncontextmenu = userrightclicked;
	resizeLayer();

}

function hidefilter() {
	// Hide filter for catching right clickes
	document.getElementById("shieldL").style.visibility="hidden";
	document.getElementById("shieldR").style.visibility="hidden";
	document.getElementById("shieldTM").style.visibility="hidden";
	document.getElementById("shieldBM").style.visibility="hidden";
	// Return to normal functionality
	document.oncontextmenu = null;
	snapit_width = undefined;


}

function hidefilter_temporary() {
	// Called when text-for-speech window is dragged
		document.getElementById("shieldL").style.visibility="hidden";
	document.getElementById("shieldR").style.visibility="hidden";
	document.getElementById("shieldTM").style.visibility="hidden";
	document.getElementById("shieldBM").style.visibility="hidden";

}

function showfilter_temporary() {
	// Called when text-for-speech window has been dragged
}



// Function to handle when the user right clicks on the shield
function userrightclicked() {
	setmouseloc();
	getmouseloc();
	// variabelen clickObject i Flash har watch p?nfo og vil kalle sin callback s?nart denne endres
   document.index.SetVariable(snapit_contentref+".clickObject.info", "right "+getmouseloc()+" "+Math.random());

	return false;
	
}

function waitForLeftClicked() {
	    setmouseloc();
		clicked = true;
		timeOutId = setTimeout("userLeftClicked()", 300)

	
}



function userMouseMove(){
   setmouseloc();
   document.index.SetVariable(snapit_contentref+".clickObject.info", "over "+getmouseloc()+" "+Math.random());



}




function userLeftClicked() {
	if  (clicked==true) {
      document.index.SetVariable(snapit_contentref+".clickObject.info", "left "+getmouseloc()+" "+Math.random());
	  clicked= false;
	}
	return false;
}


function userDoubleClicked() {
	clicked= false;
     document.index.SetVariable(snapit_contentref+".clickObject.info", "double "+getmouseloc()+" "+Math.random());

	return false;
}



function getmouseloc() {

	// Get the dimensions of the user's click

	return _mouseloc;
}



function setmouseloc(){
	// Get the dimensions of the user's click

	var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
	var posx = (document.body.clientWidth  - _courseWidth)/2;
	if (posx<0) {posx = 0}
	var posy = (document.body.clientHeight - _courseHeight)/2;
	if (posy<0) {posy = 0}

	if (isIE) {
	    var clickX = event.clientX + document.body.scrollLeft - (posx+snapit_x);
	    var clickY = event.clientY + document.body.scrollTop -(posy+snapit_y);
	} else {
		var clickX = Event.clientX + document.body.scrollLeft -(posx+snapit_x);
	    var clickY = Event.clientY + document.body.scrollTop -(posy+snapit_y);
	}
	_mouseloc= clickX +" " + clickY;



}
window.onresize = resizeLayer;

