function get(id)
{
	return document.getElementById(id);
}
function ContentContainer() 
{
	this.content = {};
	this.setContent = function(prop,val,type) 
	{
		this.content[prop] = val;
	};
	this.getContent = function(prop) 
	{
		return this.content[prop] || "";
	};
}
var appPath = "fileadmin/elearning/HACCPTest03_wbt/";
var setsPath = appPath + 'sets/';
var bgImage = "navigation_bg.jpg";
// create dummy objects to be able to properly load the necessary IDA javascript
// files.
var IdaLaunch =
{
	settings : {}
	, languages : {}
	, getPref : function(prop,def) {return this.settings[prop] || def;}
	, handleError : function(e, f)
	{
		alert(e);
	}
	, getBook : function(langCode)
	{
		return this.languages[langCode || this.curLang] || {};
	}
	,arguments : 
	{
		initialize : function(params)
		{
			if (!params) return;
			params = params.substring(1);
			var allP = params.split("&");
			for (var i=0; i<allP.length; i++)
			{
				var curP = allP[i].split("=");
				if(curP[0] != 'initialize' && curP[0] != 'toString' && curP[0] != 'valueOf')
				{
					if(curP.length > 1)
					{
						this.arguments[curP[0]] = curP[1];
					}
					else
					{
						this.arguments[curP[0]] = true;
					}
				}
			}
		}
	}
};
IdaLaunch.arguments.initialize(location.search);
document.write('<script type="text/javascript" src="' + appPath + 'bootstrap.js"><\/script>');
var langs = "de".split(",");
// book and getBook will be used to pass the content of the bookcontent files
// into valid objects
IdaLaunch.curLang = langs[0];
// check for valid UA
var Browser = new Object();
Browser.initialize = function() 
{
	// may we use another algorythm instead of the userAgent string which might
	// be manipulated?
	var ua = navigator.userAgent.toLowerCase();
	var vers;
	if (ua.indexOf("opera") >= 0)
	{
		this.compatible = false;
	}
	else if (ua.indexOf("msie") >= 0) 
	{
		ver = Number(ua.match(/msie\s*(...)/)[1]);
		this.compatible = ver && ver >= 5;
	}
	else if (ua.indexOf("gecko")) 
	{
		vers = ua.match(/rv:(...)/);
		this.compatible = (vers ? Number(vers[1]) : 1) >= 1;
	}
	else 
	{
		this.compatible = true;	// actually this might probably be wrong, but
								// for a changed UA string or Konqueror in a next
								// release, IDA might work anyway
	}
};
Browser.initialize();
function startCourse(lang,path)
{
	lang = lang || window.idalang || null;
	var size = IdaLaunch.settings["app.size"].split(",");
	var params = location.search ? "&" + location.search.substring(1) : "";
	var width = parseInt(size[0])||1016;
	var height = parseInt(size[1])||708;
	// reduce the size for IE as it assumes, that it's border is 2 pixel wider than it 
	// actually is (because we set border-width of the body to 0)
	if (document.all && window.ActiveXObject) 
	{
		width -= 4;
		height -= 4;
	}
	var useScroll = (width+8 > screen.width || height + 60 > screen.height) ? "yes":"no";
	var lProps = "left=0,top=0,width=" 
		+ width 
		+ ",height=" 
		+ height 
		+ ",resizable=yes,scrollbars=" 
		+ useScroll 
		+ ",toolbar=no,statusbar=no,menubar=no";
	path = (path ? path : appPath) 
		+ "loader.html?lang=" 
		+ (lang ? lang : IdaLaunch.curLang) 
		+ "&width=" 
		+ width 
		+ "&height=" 
		+ String(height) 
		+ params;
	if (typeof IdaStandalone != "undefined")
	{
		location.href = path;
	}
	else 
	{
		var win = window.open(path,"ida_mainWindow",lProps);
		win.focus();
	}
}
onload = function() 
{
	var elm = get(Browser.compatible ? "content" : "not-compatible");
	elm.style.display = "block";
	elm.style.visibility = "visible";
	elm = get("titlebar");
	if (bgImage) 
	{
		// make sure the image will be hidden when it is not found
		elm.onerror = function() 
		{
			this.style.display = "none";
		}
		elm.src = setsPath + "set/pic/" + bgImage;
	}
	else
	{
		elm.style.display = "none";
	}
	var headline = "";
	var pagetext = "";
	if (Browser.compatible) 
	{
		var error = false;
		// check the used languages. If more than one was exported, show a selection
		// for each language
		var startTbl = '';
		if (langs.length > 1) 
		{
			// more than one language
			startTbl += '<table id="startapp" cellpadding="5">';
			var choose, code, lang;
			for (var i=0; i<langs.length; i++) 
			{
				try 
				{
					code = langs[i];
					lang = IdaLaunch.language.getLanguage(code);
					choose = IdaLaunch.languages[code].getContent("langPleaseChoose");
					a = '<a href="#" onclick="startCourse(\'' + code + '\');return false">';
					startTbl += '<tr><td>' + a +
					choose + '</a></td>' +
					'<td>' + a +
					'<img src="' + setsPath + 'pic/flag_' + code +
					'.jpg" width="70" height="47" class="flag" alt="' + lang + '"></a></td>' +
					'<td>' + a + lang + '</a></td></tr>';
					headline += IdaLaunch.languages[code].getContent("startHeadline") + "<br>";
					pagetext += IdaLaunch.languages[code].getContent("startPagetext") + "<br>";
				}
				catch(e) 
				{
					error = true;
					if(self.IdaLaunch && self.IdaLaunch.handleError)
					{
						self.IdaLaunch.handleError(e);
					}
				}
			}
			startTbl += '</table>';
		}
		else 
		{
			// one language only
			try 
			{
				var b = IdaLaunch.getBook();
				startTbl = '<a href="#" onclick="startCourse();return false" id="startapp">' + (b.getContent("startStartApp") || 'START') + '</a>';
				headline += b.getContent("startHeadline");
				pagetext += b.getContent("startPagetext");
			}
			catch(e)
			{
				error = true;
				if(self.IdaLaunch && self.IdaLaunch.handleError)
				{
					self.IdaLaunch.handleError(e);
				}
			}
		}
		if (error)
		{
			startTbl = '<a href="#" onclick="startCourse();return false" id="startapp">START</a>';
		}
		get("headline").innerHTML = headline || "";
		get("pagetext").innerHTML = pagetext || "";
		get("chooseLang").innerHTML = startTbl;
		if (!pagetext)
		{
			get("pagetext").style.display = "none";
		}
		// check for enabled and needed cookies
		if (IdaLaunch.getPref("session.type") == 1 && !navigator.cookieEnabled) 
		{
			var lang = IdaLaunch.getPref("lang.defaultLanguage") || "de";
			var msg = IdaLaunch.languages[lang].getContent("hintCookiesNotActivated");
			var elm
			if (msg) 
			{
				elm = get("nocookies");
				elm.style.display = "block";
				get("nocookiesHead").innerHTML = msg.replace(/\n/g,"<br>");
			}
			get("explainCookiesDE").href = appPath + "explain/cookies_de.html";
			get("explainCookiesEN").href = appPath + "explain/cookies_en.html";
		}
	}
};