		var confirm_msg = "Det verkar som om du är mitt inne i en träningsaktivitet.\nOm du klickar på denna länk så kommer inte ditt resultat hittills i denna träning att sparas.\nÄr du säker på att du vill fortsätta?";
		var logout_msg 	= "Är du säker på att du vill logga ut?";
		var use_haltmsg = true; // Använda varningsmeddelande om sparning?
	
		function openSupport(path){
        	if (!path) { path = ""; }
			window.open(path + 'support.mm2', "supportwin", "width=620,height=220,status=no,toolbar=no,menubar=no,scrollbars=no");
		}
        function openReq(path){
        	if (!path) { path = ""; }
			window.open(path + 'systemrequirements.php', "reqwin", "width=500,height=330,status=no,toolbar=no,menubar=no,scrollbars=no");
		}
        function openContact(){
			window.open('request_info.php', "info", "width=250,height=300,status=no,toolbar=no,menubar=no,scrollbars=no");
		}
		function check_login(f){
        	if(f.ies_login.value=="" || f.ies_passwd.value==""){
				f.ies_login.focus();
				return false;
			}
			return true;
        }
		
		function IZExit()
		{
			parent.training_isloaded = false;
			top.training_isloaded = false;
			if (self.location.href.indexOf("mercuri") > -1) {
				if (window.opener) {
					window.opener.location.reload();
				}

				if (self.location.href.indexOf("eval") > -1) {
					self.close();
				} else {
					var module = location.href.replace(/^http:\/\/.*?\//g, '').replace(/[^\d]/g, '') * 1;
					module += 5;
					
					location.href = 'mercuri_eval.php?moduleID=' + module;
				}
			} else {
				//alert("")
				history.back();
			}
		}
		
		function IZStart()
		{
			top.training_isloaded = true;
		}
		
		function TrainingIsLoaded(val){
			if (val==0){
				parent.training_isloaded = false;
			} else {
				parent.training_isloaded = true;
			}
		}

        function check(f)
        {
			f.sEmail.value = trim(f.sEmail.value);
			email = f.sEmail.value;
			if (email==""){
				f.sEmail.focus();
				return false;
			}
			return true;
        }
		
		// remove leading AND trailing whitespace
		function trim(sString){
			sString = sString.replace(/^([ |\t|\n]+)/gi,"");
			sString = sString.replace(/([ |\t|\n]+)$/gi,"");
			return sString;
		}

		function search_check(f)
	    {
			if (f.qry.value==""){
				return false;
			}
			return true;
	    }
	
		    // remove ALL whitespace
	    function fullTrim(sString)
	    {
	        re=/ /gi;
	        sString = sString.replace(re,"");
	        return sString;
	    }
		
	    function checkOK(f){
			new_clearingnr = fullTrim(f.new_clearingnr.value);
			if (new_clearingnr==""){
				return false;
			}
			return true;
		}

	    
	    function editUser(id){
			window.open('edit_user.mm2?id='+ id, "editWin", "width=450,height=300,top=100,left=200,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
		}
		
		function fetchUserStat(id, qry)
	    {
			window.open('user_stat.mm2?id=' + id + '&qry=' + qry, "userStat", "width=450,height=350,left=350,top=100,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
	    }

	    function confirmExit(){
	    	if (confirm(confirm_msg)){
	    		parent.training_isloaded = false;
	    		return true;
	    	}
	    	return false;
	    }
	    
		function setMeActive(thepath, theid){
			if (use_haltmsg && parent.training_isloaded){
				if (confirm(confirm_msg)){
					top.frames[0].location.href = thepath;
					resetLinks();
					setActiveLink(theid);
					parent.training_isloaded = false;
					return true;
				} else {
					return false;
				}
			} else {
				resetLinks();
				setActiveLink(theid);
				top.frames[0].location.href = thepath;
				parent.training_isloaded = false;
				return true;
			}
		}
		
		function resetLinks(){
			var i = 0;
			for (i=0; i<document.links.length; i++){
				if (document.links[i].id) {
					//alert(document.links[i].id);
					document.links[i].className = "menyUnder";
				}
			}
		}
		
		function setActiveLink(theid){
		//	alert("ID: " + theid);
			document.getElementById(theid).className = "selecteditem";
		}
		
        function openModule(file){
        	if (file!=""){
	       		//window.open(file, "training", "width=780,height=500,left=10,top=10,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
	       		self.location.href = file;
    	   		IZStart();
        	}
        }
        
        function openModulePopup(file, width, height){
        	if (!width)  width  = 780;
        	if (!height) height = 500;

        	if (file!=""){
	       		window.open(file, "training", "width=" + width + ",height=" + height + ",left=10,top=10,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes");
	       		//self.location.href = file;
    	   		//IZStart();
        	}
        	
        	return false;
        }

        function setNewcolor(obj, color, islink){
			if (typeof(obj.style) != 'undefined'){
				obj.style.backgroundColor = color; 
				if (islink){
					obj.style.cursor='pointer'
				}
			}
		}
		
		function redirectUser(path){
			self.location.href= path;
		}
		
		function doLogout()
		{
			var loc = (location.href.indexOf('dealmaker') > -1) ? 
				'../logout.mm2?is_dealmaker=1' : 'logout.mm2';
			if (use_haltmsg && parent.training_isloaded){
				if (confirm(confirm_msg)){
					top.location.href = loc;
				}
			} else {
				if (confirm(logout_msg)){
					top.location.href = loc;
				}
			}
		}
		
		function switchTab(i, mode, sUrl)
		{
			var a;
			if (mode==1){ // INTE inloggad
				for (a=0;a<=2;a++){
					if (a==i){
						document.getElementById("item"+a ).className = "mainmenu_on";
					} else {
						document.getElementById("item"+a ).className = "mainmenu_off";
					}
				}
			} else {
				if (top.is_admin){
					len = 2;
				} else {
					len = 1
				}
			}
			//alert(document.getElementById("item1").classname);
			if (sUrl!=""){
				frames["mainframe"].location.href = sUrl;
			}
		}
		
		function setSelected(f, a, adm, sUrl){
			var menus = document.getElementsByTagName("tr");
			var i = 0;

			
			if (use_haltmsg && parent.training_isloaded){
				if (!confirm(confirm_msg)){
					return false;
				}
			}		
			for(i = 0; i < menus.length; i++) {
				if (menus[i].getElementsByTagName("td")[0].className != "menuItemTop"){
					menus[i].getElementsByTagName("td")[0].className = "menuItem";
				}
				if (document.getElementById("adminitem" + i)){
					document.getElementById("adminitem" + i).className = "menuItemAdmin";
					if (document.getElementById("staticon" + i)){
						document.getElementById("staticon" + i).src = "images/stat_icon.png";
					}
				}
			}
			if (adm){
				document.getElementById("adminitem" + a).className = "menuItemSelectAdmin";
				if (document.getElementById("staticon" + a)){
					document.getElementById("staticon" + a).src = "images/stat_icon_blue.gif";
				}
				//document.getElementById(f.id).className = "menuItemSelect";
			} else {
				document.getElementById(f.id).className = "menuItemSelect";
			}
			parent.training_isloaded = false;
			if (sUrl!=""){
				parent.frames['mainframe'].location.href=sUrl;
			}
			return true;
		}
		
		function setAdminSelected(a, sUrl){
			var menus = document.getElementsByTagName("tr");
			var i = 0;

			
			if (use_haltmsg && parent.training_isloaded){
				if (!confirm(confirm_msg)){
					return false;
				}
			}		
			for(i = 0; i < menus.length; i++) {
				if (menus[i].getElementsByTagName("td")[0].className != "menuItemTop"){
					if ( i != a && document.getElementById("adminitem" + i)){
						document.getElementById("adminitem" + i).className = "menuItemAdmin";
					}
				}
			}
			document.getElementById("adminitem" + a).className = "menuItemSelect";
			parent.training_isloaded = false;
			if (sUrl!=""){
				top.frames['mainframe'].location.href=sUrl;
			}
			return true;
		}
		
		function showDelayMarker(sUrl)
		{
			document.getElementById("delaymarker").style.visibility ='visible';
			//setTimeout("setLocation('"+sUrl+"')",100);
			setLocation(sUrl);
			
		}
		
		function setLocation(sUrl)
		{
			self.location.href=sUrl;
		}
		

		/*
		 * Event addition and removal 
		 * http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
		 */
		function addEvent( obj, type, fn )
		{
			if (obj.addEventListener)
				obj.addEventListener( type, fn, false );
			else if (obj.attachEvent)
			{
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
				obj.attachEvent( "on"+type, obj[type+fn] );
			}
		}
		
		function removeEvent( obj, type, fn )
		{
			if (obj.removeEventListener)
				obj.removeEventListener( type, fn, false );
			else if (obj.detachEvent)
			{
				obj.detachEvent( "on"+type, obj[type+fn] );
				obj[type+fn] = null;
				obj["e"+type+fn] = null;
			}
		}

		
		function checkIfLoaded()
		{
			if (top.training_isloaded) {
				window.onbeforeunload = function ()
				{
					// Utan detta kommer alltid frågan
					top.training_isloaded = false;
					
					// För att få en egen sträng måste denna med
					return confirm_msg;
				}
			}
		}
		
		// Fråga innan du går ifrån träningar
		addEvent(window, 'load', checkIfLoaded);
