/**
* JSONP-Call to the Server, on success the function handleResponse(msg) is 
called
*/
function callToServer(category, eventtype, logdata){
	//alert(category +":"+ eventtype +":"+logdata);
	var whereTo = new Array();
	whereTo.category=category;
	whereTo.eventtype=eventtype;
	whereTo.logdata=logdata;
	if (top.enable_Logging){
		sendCall(whereTo,callb);
	};
}
/**
 * Dummy Callback fuer callTOServer
 * @return
 */
function callb(){
	//tue erstmal nix
}

/**
 * Shows the comment of the item at index i in a tutor bubble.
 */
function showComment(i) {
	/*
	 * var win = window.open("about:blank", "comment",
	 * "scrollbars=yes,width=500,height=400"); win.document.open();
	 * win.document.writeln(part[i].comment); win.document.close();
	 */
	var resActual = top.getCurrentPage().res;
	var type = "";
	var logData="";
	
	if(typeof part[i].casediag != 'undefined'){
		type = "Diagnose";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].casediag);
	}else if(typeof part[i].therapkette != 'undefined'){
		type="Therapieprinzipien";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].therapkette);
	}else if(typeof part[i].loghist != 'undefined'){
		type="Anamnese";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].loghist);
	}else if(typeof part[i].logphys != 'undefined'){
		type="Körperliche Untersuchung";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].logphys);
	}else if(typeof part[i].loglab != 'undefined'){
		type="Laborunterrsuchung";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].loglab);
	}else if(typeof part[i].logtech != 'undefined'){
		type="Technische Untersuchung";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].logtech);
	}else{
		type="unknown";
		top.callToServer("Expertenkommentar","open",type + "#" +part[i].itemid);
	}
	showTutorText(part[i].comment);
}

/**
 * Unescapes HTML to Text
 * 
 * @html HTML-Text (Bsp. mit &auml; etc.)
 * @return Text (Bsp. mit   etc.
 */
function unescapeHTML(html) {
	var htmlNode = document.createElement("DIV");
	htmlNode.innerHTML = html;
	if (htmlNode.innerText)
		return htmlNode.innerText; // IE
	return htmlNode.textContent; // FF
}

/**
 * Sets the State of the item at index "checkbox.name" to the state of the given
 * checkbox. Operates on the variable part.
 */
function checkItem(checkbox) {
	if (checkbox.checked == true) {
		part[checkbox.name].selected = true;
	} else {
		part[checkbox.name].selected = false;
	}
}

function selectItem(checkbox) {
	checkbox.checked = true;
	checkItem(checkbox);
}

/**
 * Writes all media to the given item "item". small indicates, if the icon for
 * the media should be small or large (small = true -> small icons). question
 * indicates, if the media has to be shown in a question true => question
 */
function writeMedia(item, small, question) {
	// check, if array "media" is set ...

	if (item.media) {
		// iterate through media
		var i = 0;
		while (item.media[i]) {

			var file = item.media[i].url;
			if (file.indexOf(":/") == -1)
				file = top.getCaseDir() + "/" + file;
			if (small == true) {
				// display small form ..
				document.writeln("<a href=\"#\" onclick=\"showMedium('" + file
						+ "', '" + item.media[i].mime + "', "
						+ item.media[i].width + ", " + item.media[i].height
						+ ", '" + item.name + "', '" + item.media[i].desc
						+ "');return false\">");
				document.writeln("<img border=\"0\" src=\""
						+ getStandardIcon(item.media[i].mime) + "\">");
				document.writeln("</a>");
			} else {
				if (question == false) {
					if (item.media[i].mime == 'video/x-flv') {
						document.writeln("<div class=\"media\">");
						document
								.writeln("<table border=\"0\"><tr><td valign=\"top\">");
						document.writeln("<a href=\"#\" onclick=\"showMedium('"
								+ file + "', '" + item.media[i].mime + "', "
								+ item.media[i].width + ", "
								+ item.media[i].height + ", '" + item.name
								+ "', '" + item.media[i].desc
								+ "');;return false\">");
						document.writeln("<img border=\"0\" src=\""
								+ getIconURL(item.media[i]) + "\">");
						document.writeln("</a>");
						document.writeln("</td><td>");
						// write medium description
						document.writeln(item.media[i].desc);
						document.writeln("</td></tr></table>");
						document.writeln("</div>");
					} else {
						// display large form ...
						document.writeln("<div class=\"media\">");
						document
								.writeln("<table border=\"0\"><tr><td valign=\"top\">");
						document.writeln("<a href=\"#\" onclick=\"showMedium('"
								+ file + "', '" + item.media[i].mime + "', "
								+ item.media[i].width + ", "
								+ item.media[i].height + ", '" + item.name
								+ "', '" + item.media[i].desc
								+ "');return false\">");
						document.writeln("<img border=\"0\" src=\""
								+ getIconURL(item.media[i]) + "\">");
						document.writeln("</a>");
						document.writeln("</td><td>");
						// write medium description
						document.writeln(item.media[i].desc);
						document.writeln("</td></tr></table>");
						document.writeln("</div>");
					}
				} else {
					if (item.media[i].mime == 'video/x-flv') {
						document.writeln("<div class=\"media\">");
						document
								.writeln("<table border=\"0\"><tr><td valign=\"top\">");
						document.writeln("<a href=\"#\" onclick=\"showMedium('"
								+ file + "', '" + item.media[i].mime + "', "
								+ item.media[i].width + ", "
								+ item.media[i].height + ", '" + item.name
								+ "', '" + item.media[i].desc
								+ "');;return false\">");
						document.writeln("<img border=\"0\" src=\""
								+ getIconURL(item.media[i]) + "\">");
						document.writeln("</a>");
						document.writeln("</td><td>");
						// write medium description
						document.writeln(item.media[i].desc);
						document.writeln("</td></tr></table>");
						document.writeln("</div>");
					} else 

					if ((item.media[i].mime == "image/gif")
							|| (item.media[i].mime == "image/jpeg")) {
						// display large form ...
						document.writeln("<div class=\"media\">");
						document
								.writeln("<table border=\"0\"><tr><td valign=\"top\">");
						var file = item.media[i].url;
						if (file.indexOf(":/") == -1)
							file = top.getCaseDir() + "/" + file;
						document.writeln('<img src="' + file + '" width = "'
								+ item.media[i].width + '" height="'
								+ item.media[i].height + '" >');
						document.writeln("</td><td>");
						// write medium description
						document.writeln(item.media[i].desc);
						document.writeln("</td></tr></table><br>");
						document.writeln("</div>");

					} else if (item.media[i].mime == "video/mpeg") {
						var file = item.media[i].url;
						if (file.indexOf(":/") == -1)
							file = top.getCaseDir() + "/" + file;
						if (checkPlugin() == true) {
							if (detectWindowsMedia() == true) {
								// hier die Anweisung f r Mediaplayer
								document
										.writeln('<object id="mediaPlayer" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" align="center" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" viewastext>');
								document
										.writeln('<param name="FileName" value="' + file + '">');
								document
										.writeln('<param name="animationatStart" value="false">');
								document
										.writeln('<param name="transparentatStart" value="true">');
								document
										.writeln('<param name="autoStart" value="true">');
								document
										.writeln('<param name="showControls" value="true">');
								document
										.writeln('<param name="volume" value="-200">');
								document
										.writeln('<param name="ShowStatusBar" value="true">');
								document
										.writeln('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" src="'
												+ file
												+ '" width="'
												+ item.media[i].width
												+ '" height="'
												+ item.media[i].height + '">');
								document.writeln('</embed>');
								document.writeln('</object>');
							} else if (detectQuickTime() == true) {
								// hier die Anweisung f r Quicktime
								document
										.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"  width="320" height="256" codebase="http://www.apple.com/qtactivex/qtplugin.cab">');
								document
										.write('<param name="SRC" value="' + file + '">');
								document
										.write('<param name="CONTROLLER" value="TRUE">');
								document
										.write('<param name="AUTOPLAY" value="TRUE">');
								document
										.write('<param name="CACHE" value="FALSE">');
								document
										.write('<embed src="'
												+ file
												+ '" width="'
												+ item.media[i].width
												+ '" height="'
												+ item.media[i].height
												+ '" controller="TRUE" autoplay="TRUE" cache="FALSE" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>');
							} else if (detectReal() == true) {
								// hier die Anweisung f r Realplayer
								win.document
										.writeln('<table border="0" width="100%">');
								win.document.writeln('<tr>');
								win.document
										.writeln('<td width="90%" valign="top" colspan="2"><p align="center"><font color="#004080" size="4" face="Comic Sans MS">' + title + '</font><font color="#004080" size="4" face="Comic Sans MS"><br></font>');

								win.document
										.writeln('<object ID="video1" CLASSID="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" height="'
												+ item.media[i].height
												+ '" width="'
												+ item.media[i].width + '">');
								win.document
										.writeln('<param name="_ExtentX" value="8467">');
								win.document
										.writeln('<param name="_ExtentY" value="6350">');
								win.document
										.writeln('<param name="AUTOSTART" value="-1">');
								win.document
										.writeln('<param name="SHUFFLE" value="0">');
								win.document
										.writeln('<param name="PREFETCH" value="0">');
								win.document
										.writeln('<param name="NOLABELS" value="0">');
								win.document
										.writeln('<param name="SRC" value="' + file + '">');
								win.document
										.writeln('<param name="CONTROLS" value="ImageWindow">');
								win.document
										.writeln('<param name="CONSOLE" value="Clip1">');
								win.document
										.writeln('<param name="LOOP" value="0">');
								win.document
										.writeln('<param name="NUMLOOP" value="0">');
								win.document
										.writeln('<param name="CENTER" value="0">');
								win.document
										.writeln('<param name="MAINTAINASPECT" value="0">');
								win.document
										.writeln('<param name="BACKGROUNDCOLOR" value="#000000"><embed SRC="'
												+ url
												+ '" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ImageWindow" HEIGHT="'
												+ item.media[i].height
												+ '" WIDTH="'
												+ item.media[i].width
												+ '" AUTOSTART="false">');
								win.document.writeln('</object>');

								// win.document.writeln('<br><font face="Comic
								// Sans MS">Hier die Unterschrift<br></font>');
								win.document.writeln('<br><br>');

								win.document
										.writeln('<object ID="video2" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT="25" WIDTH="220">                  ');
								win.document
										.writeln('<param name="_ExtentX" value="5821">');
								win.document
										.writeln('<param name="_ExtentY" value="661">');
								win.document
										.writeln('<param name="AUTOSTART" value="0">');
								win.document
										.writeln('<param name="SHUFFLE" value="0">');
								win.document
										.writeln('<param name="PREFETCH" value="0">');
								win.document
										.writeln('<param name="NOLABELS" value="0">');
								win.document
										.writeln('<param name="CONTROLS" value="ControlPanel">');
								win.document
										.writeln('<param name="CONSOLE" value="Clip1">');
								win.document
										.writeln('<param name="LOOP" value="0">');
								win.document
										.writeln('<param name="NUMLOOP" value="0">');
								win.document
										.writeln('<param name="CENTER" value="0">');
								win.document
										.writeln('<param name="MAINTAINASPECT" value="0">');
								win.document
										.writeln('<param name="BACKGROUNDCOLOR" value="#000000"><embed align="center" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel" HEIGHT="40" WIDTH="275" AUTOSTART="true">');
								win.document.writeln('</object>');
								win.document.writeln('</td>');
								win.document.writeln('</tr>');
								win.document.writeln('</table>');
							} else {
								document
										.writeln("WindowsMediaPlayer, Quicktime and Realplayer are not supported!");
							}

						} else {
							document.writeln("plugins are not supported!");
						}

						document.writeln("<br><br><br>");
					}

				}

			}
			i++;
		}
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
 * Functions for detect the supported Players returns 0 => Plugins not supported
 * returns 1 => Plugins supported
 * 
 */
var detectableWithVB = false;
var pluginFound = false;

function checkPlugin() {

	if ((navigator.userAgent.indexOf('MSIE') != -1)
			&& (navigator.userAgent.indexOf('Win') != -1)) {
		document.writeln('<script language="VBscript">');

		document
				.writeln('\'do a one-time test for a version of VBScript that can handle this code');
		document.writeln('detectableWithVB = False');
		document.writeln('If ScriptEngineMajorVersion >= 2 then');
		document.writeln('  detectableWithVB = True');
		document.writeln('End If');

		document.writeln('\'this next function will detect most plugins');
		document.writeln('Function detectActiveXControl(activeXControlName)');
		document.writeln('  on error resume next');
		document.writeln('  detectActiveXControl = False');
		document.writeln('  If detectableWithVB Then');
		document
				.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
		document.writeln('  End If');
		document.writeln('End Function');

		document.writeln('\'and the following function handles QuickTime');
		document.writeln('Function detectQuickTimeActiveXControl()');
		document.writeln('  on error resume next');
		document.writeln('  detectQuickTimeActiveXControl = False');
		document.writeln('  If detectableWithVB Then');
		document.writeln('    detectQuickTimeActiveXControl = False');
		document.writeln('    hasQuickTimeChecker = false');
		document
				.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
		document.writeln('    If IsObject(hasQuickTimeChecker) Then');
		document
				.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
		document.writeln('        detectQuickTimeActiveXControl = True');
		document.writeln('      End If');
		document.writeln('    End If');
		document.writeln('  End If');
		document.writeln('End Function');

		document.writeln('</scr' + 'ipt>');
	}
	if (detectableWithVB || (navigator.plugins && navigator.plugins.length > 0)) {
		return true;
	} else {
		return false;
	}
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
	pluginFound = detectPlugin('Windows Media');
	// if not found, try to detect with VisualBasic
	if (!pluginFound && detectableWithVB) {
		pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
	}
	return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
	pluginFound = detectPlugin('QuickTime');
	// if not found, try to detect with VisualBasic
	if (!pluginFound && detectableWithVB) {
		pluginFound = detectQuickTimeActiveXControl();
	}
	return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
	pluginFound = detectPlugin('RealPlayer');
	// if not found, try to detect with VisualBasic
	if (!pluginFound && detectableWithVB) {
		pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control')
				|| detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') || detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
	}
	return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
	// check for redirection
	if (redirectURL
			&& ((pluginFound && redirectIfFound) || (!pluginFound && !redirectIfFound))) {
		// go away
		goURL(redirectURL);
		return pluginFound;
	} else {
		// stay here and return result of plugin detection
		return pluginFound;
	}
}

function detectPlugin() {
	// allow for multiple checks in a single pass
	var daPlugins = detectPlugin.arguments;
	// consider pluginFound to be false until proven true
	var pluginFound = false;
	// if plugins array exists and not fake
	if (navigator.plugins && navigator.plugins.length > 0) {
		var pluginsArrayLength = navigator.plugins.length;
		// for each plugin...
		for (pluginsArrayCounter = 0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++) {
			// loop through all desired names and check each against the current
			// plugin name
			var numFound = 0;
			for (namesCounter = 0; namesCounter < daPlugins.length; namesCounter++) {
				// if desired plugin name is found in either plugin name or
				// description
				if ((navigator.plugins[pluginsArrayCounter].name
						.indexOf(daPlugins[namesCounter]) >= 0)
						|| (navigator.plugins[pluginsArrayCounter].description
								.indexOf(daPlugins[namesCounter]) >= 0)) {
					// this name was found
					numFound++;
				}
			}
			// now that we have checked all the required names against this one
			// plugin,
			// if the number we found matches the total number provided then we
			// were successful
			if (numFound == daPlugins.length) {
				pluginFound = true;
				// if we've found the plugin, we can stop looking through at the
				// rest of the plugins
				break;
			}
		}
	}
	return pluginFound;
} // detectPlugin

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/**
 * Writes all links to the given item "item". small indicates, if the icon for
 * the links should be small or large (small = true -> small icons).
 */
function writeLinks(item, small) {
	if (item.link) {
		var i = 0;
		while (item.link[i]) {
			if (small != true)
				document.writeln("<br>");
			document.writeln("<a target='_blank' href='" + item.link[i].url
					+ "'>");
			document.writeln("<img src='" + top.getBaseDir()
					+ "/icons/internal_link.gif' border=0>");
			document.writeln("</a>");
			if (small != true) {
				document.writeln("<a target='_blank' href='" + item.link[i].url
						+ "'>");
				document.writeln(item.link[i].text);
				document.writeln("</a>");
			}
			i++;
		}
	}
}

/**
 * Returns the URL to the icon of the given medium.
 */
function getIconURL(medium) {
	// if medium is image, get URL of ico-File
	var file = medium.url;
	if (medium.mime.indexOf("image/") != -1 || medium.mime.indexOf("video/x-flv") || medium.mime.indexOf("application/zip")) {
		if (file.indexOf(":/") == -1)
			file = top.getCaseDir() + "/" + file;
		return file.substring(0, file.lastIndexOf(".")) + "ico.jpg";
	}
	// return standard icon otherwise
	return getStandardIcon(medium.mime, false);
}

/**
 * Returns the URL of the standard icon of the given mime-type. Small indicates
 * the size of the icons. Large icons have the suffix _l. For example, short
 * icon for mime type image has the name "image.gif", large icon has the name
 * "image_l.gif" All icons are stored in the directory "<basedir>/icons/medien" .
 */
function getStandardIcon(mime, small) {
	var suffix = "";
	if (small == false)
		suffix = "_l";
	if (mime.indexOf("image/") != -1) {
		return top.getBaseDir() + "/icons/medien/image" + suffix + ".gif";
	}
	if (mime.indexOf("application/pdf") != -1) {
		return top.getBaseDir() + "/icons/medien/pdf" + suffix + ".gif";
	}
	if (mime.indexOf("video/") != -1) {
		return top.getBaseDir() + "/icons/medien/video" + suffix + ".gif";
	}
	if (mime.indexOf("audio/") != -1) {
		return top.getBaseDir() + "/icons/medien/audio" + suffix + ".gif";
	}
	if (mime.indexOf("text/") != -1) {
		return top.getBaseDir() + "/icons/medien/text" + suffix + ".gif";
	}
	if (mime.indexOf("application/zip") != -1) {
		return top.getBaseDir() + "/icons/medien/zip" + suffix + ".gif";
	}
	return top.getBaseDir() + "/icons/medien/unknown" + suffix + ".gif";
}

function nameExtract(wholeurl){
	x=wholeurl.length;
	while((wholeurl.substring(x,x-1)) != "."){
		x--;
	}
	clipend = x;
	while((wholeurl.substring(x,x-1)) != "/"){
		x--;
	}
	clipstart = x;
	return wholeurl.substring(clipend-1, clipstart);
}

function showMedium(url, mime, width, height, title) {
	showMedium(url, mime, width, height, title, "");
}

/**
 * Show a medium at URL "url" in a separate window. The medium is rendered
 * depending on the given mime type in a window with "width" and "height".
 * "title" is the title of the new window.
 */
function showMedium(url, mime, width, height, title, desc) {
	top.callToServer("Medium","open",nameExtract(url));
	if (mime == 'application/zip') {
		var win = testWin(
				url.substring(0, url.lastIndexOf('.')) + '/index.html',
				'MEDIUM', 'resizable=yes,width=' + width + ',height=' + height);
	} else

	if (mime == 'video/x-flv' || mime == 'audio/mpeg') {
		var win = testWin('about:blank', 'MEDIUM', 'resizable=yes,width='
				+ (mime == 'audio/mpeg' ? 300 : width) + ',height=' + height);
		if (win) {
			win.document.open();
			win.document.writeln ('<html><head><title>' + title + '</title><style type="text/css">body{margin:0px;padding:0px;}</style></head><body><table cellspacing="0" border="0" cellpadding="0" width="100%" height="100%"><tr><td height="100%" valign="top">');
			win.document.writeln (getEmbedFlash ( mime == 'audio/mpeg', url));
			win.document.writeln('</td></tr>');
			if (desc != '')
 			   win.document.writeln('<tr><td><div style="width:100%;font-family:sans-serif;height:50px;overflow:auto;padding:3px">' + desc + '</div></td></tr>');
			win.document.writeln('</table></body></html>');
			win.document.close();
		}
	} else {
		var options = "scrollbars=yes";
		// if size is bigger than 800x600 resize window
		if (width > 800)
			width = 800;
		if (height > 600)
			height = 600;
		if (width < 0)
			width = 400;
		if (height < 0)
			height = 300;
		// create options for window.open()-call
		options = options + ",width=" + (width + 50) + ",height="
				+ (height + 50);
		// open window
		var win = window.open("about:blank", "_blank", options);
		// create HTML-Code in window
		win.document.open();
		if (!title || title == "")
			title = "Medium";
		// set title in HTML
		win.document.writeln('<head><title>' + title + '</title></head>');
		win.document.writeln('<body>');
		// Render medium depending on mime-type
		if (mime.indexOf("image/") != -1) {
			// image -> img-tag
			win.document.writeln('<img src="' + url + '">');
		} else {

			// other type -> embed-tag
			// VORHER:
			win.document
					.writeln('<object width="'
							+ width
							+ '" height="'
							+ (height + 16)
							+ '" '
							+ 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
							+ 'codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" '
							+ 'value="'
							+ url
							+ '"><param name="autoplay" value="true"><param name="controller" '
							+ 'value="true"><embed src="'
							+ url
							+ '" width="'
							+ width
							+ '" height="'
							+ (height + 16)
							+ '" '
							+ 'autoplay="true" controller="true" '
							+ 'pluginspage="http://www.apple.com/quicktime/download/"></embed></object>');

			// NACHHER
			/*
			 * win.document.writeln('<table border="0" width="100%">');
			 * win.document.writeln('<tr>'); win.document.writeln('<td width="90%" valign="top" colspan="2"><p align="center"><font
			 * color="#004080" size="4" face="Comic Sans MS">'+title+'</font><font
			 * color="#004080" size="4" face="Comic Sans MS"><br></font>');
			 * 
			 * win.document.writeln('<object ID="video1"
			 * CLASSID="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA"
			 * height='+(height)+' width='+(width)+'>'); win.document.writeln('<param
			 * name="_ExtentX" value="8467">'); win.document.writeln('<param
			 * name="_ExtentY" value="6350">'); win.document.writeln('<param
			 * name="AUTOSTART" value="-1">'); win.document.writeln('<param
			 * name="SHUFFLE" value="0">'); win.document.writeln('<param
			 * name="PREFETCH" value="0">'); win.document.writeln('<param
			 * name="NOLABELS" value="0">'); win.document.writeln('<param
			 * name="SRC" value="../cases/114927/115236.mpg">');
			 * win.document.writeln('<param name="CONTROLS"
			 * value="ImageWindow">'); win.document.writeln('<param
			 * name="CONSOLE" value="Clip1">'); win.document.writeln('<param
			 * name="LOOP" value="0">'); win.document.writeln('<param
			 * name="NUMLOOP" value="0">'); win.document.writeln('<param
			 * name="CENTER" value="0">'); win.document.writeln('<param
			 * name="MAINTAINASPECT" value="0">'); win.document.writeln('<param
			 * name="BACKGROUNDCOLOR" value="#000000"><embed SRC="'+url+'"
			 * type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1"
			 * CONTROLS="ImageWindow" HEIGHT="240" WIDTH="320"
			 * AUTOSTART="false">'); win.document.writeln('</object>');
			 * 
			 * //win.document.writeln('<br><font face="Comic Sans MS">Hier die
			 * Unterschrift<br></font>'); win.document.writeln('<br><br>');
			 * 
			 * win.document.writeln('<object ID="video2"
			 * CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT="25"
			 * WIDTH="220"> '); win.document.writeln('<param name="_ExtentX"
			 * value="5821">'); win.document.writeln('<param name="_ExtentY"
			 * value="661">'); win.document.writeln('<param name="AUTOSTART"
			 * value="0">'); win.document.writeln('<param name="SHUFFLE"
			 * value="0">'); win.document.writeln('<param name="PREFETCH"
			 * value="0">'); win.document.writeln('<param name="NOLABELS"
			 * value="0">'); win.document.writeln('<param name="CONTROLS"
			 * value="ControlPanel">'); win.document.writeln('<param
			 * name="CONSOLE" value="Clip1">'); win.document.writeln('<param
			 * name="LOOP" value="0">'); win.document.writeln('<param
			 * name="NUMLOOP" value="0">'); win.document.writeln('<param
			 * name="CENTER" value="0">'); win.document.writeln('<param
			 * name="MAINTAINASPECT" value="0">'); win.document.writeln('<param
			 * name="BACKGROUNDCOLOR" value="#000000"><embed align="center"
			 * type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1"
			 * CONTROLS="ControlPanel" HEIGHT="40" WIDTH="275"
			 * AUTOSTART="true">'); win.document.writeln('</object>');
			 * win.document.writeln('</td>'); win.document.writeln('</tr>');
			 * win.document.writeln('</table>');
			 */
		}

		win.document.writeln('<br>' + desc);
		win.document.writeln('</body>');
		win.document.close();
		/*
		 * } else { var win = window.open("about:blank", "_blank", options);
		 * win.document.open(); win.document.writeln("<head><title>"+title+"</title>");
		 * win.document.writeln("<frameset rows=\"*\"><frame src="+url+"></frameset>");
		 * win.document.writeln("</head>"); win.document.close(); }
		 */
	}
}

function changeLabel(element, text, pos) {
	element.innerHTML = '<label for="' + pos + '">' + text + '</label>';
}

function replaceCriticalChars(value){
	value=value.replace(/'/g, '\\\'');
	value=value.replace(/\n/g, '\\\n');
	return value;	
}

function printOption(pos, item, feedback) {
	
	var ret = true;
	if (item) {
		document.write("<tr>");
		if ((top.isCompleteFeedback() && feedback != true)
				|| (!item.feedback && !top.isCompleteFeedback())) {
					
			document
					.write("<td width=20 height=22 align='center' valign='top'><input type=\"checkbox\" id=\""
							+ pos
							+ "\" name=\""
							+ pos
							+ "\" onClick=\"checkItem(this);deselectCatCheckbox('ss"
							+ item.cat + "')\"");
			if (item.selected == true) {
				document.write("checked");
			}
			var kurz;
			if (item.sname)
				kurz = item.sname;
			else
				kurz = item.name;

			document.write("></td><td>");
			if (item.full != undefined)
				document.write("<a onmouseover=\"changeLabel(this,'"
						+ replaceCriticalChars(item.full) + "', " + pos
						+ ");return true;\" onmouseout=\"changeLabel(this,'"
						+ kurz + "', " + pos + ");return true;\">");
			if (item.sname) {
				document.write("<label for='" + pos + "'>" + item.sname
						+ "</label>");
			} else {
				document.write("<label for='" + pos + "'>" + item.name
						+ "</label>");
			}
			if (item.full != undefined) {
				document.write("</a>");
				// document.write("<a
				// href='javascript:selectItem(document.listform.elements["+pos+"]);showTutorText(\"<b>"+top.getBasicResource().tutorAnamnese+"</b><br>"+item.full+"\");void(0);'><img
				// src=\""+top.getBaseDir()+"/icons/expert.gif\"
				// border=\"0\"></a>");
			}
			document.writeln("</td>");
		} else {
			ret = false;
			if (top.isCompleteFeedback()) {
				document.writeln("<td width=20 height=22></td><td>");
				writeItem(pos, item);
				document.writeln("</td>");
			} else {
				document
						.write("<td width=20 height=22 valign=\"center\" align=\"center\"><img src=\""
								+ top.getBaseDir()
								+ "/img/checkbox_selected.gif\" ></td><td bgcolor=\"");
				if (item.status == 101) {
					document.write("#AAFFAA");
				} else if (item.status == 102) {
					document.write("#DDDDDD");
				} else {
					document.write("#FFAAAA");
				}
				document.write("\">");
				var kurz;
				if (item.sname)
					kurz = item.sname;
				else
					kurz = item.name;

				if (item.full != undefined)
					document.write("<a onmouseover=\"this.innerHTML='"
							+ replaceCriticalChars(item.full) + "'\" onmouseout=\"this.innerHTML='"
							+ kurz + "'\">");
				if (item.sname)
					document.write(item.sname);
				else
					document.write(item.name);
				if (item.full != undefined) {
					document.write("</a>");
				}
				document.writeln("</td>");
			}
		}
		document.writeln("</tr>");
	}
	return ret;
}

/**
 * Get feedback mode of the given item.
 */
function getItemMode(item) {
	var mod;
	if (item.selected) {
		if (item.status == 101) {
			mod = "selected-necessary";
		} else if (item.status == 102) {
			mod = "selected-relevant";
		} else {
			mod = "selected-not-relevant";
		}
	} else if (item.status == 101) {
		mod = "not-selected-necessary";
	} else if (item.status == 102) {
		mod = "not-selected-relevant";
	} else {
		mod = "not-selected-not-relevant";
	}
	return mod;
}

/**
 * Writes one lab item with feedback.
 */
function writeLabItem(pos, item) {
	// writeItemStart(pos, item);
	var mod = getItemMode(item);
	// ist
	// Hintergrund gr n bei selected-neccesary und selected-relevant
	// rot bei selected-not-relevant
	// blau bei not selected-neccesary und not-selected-relevant
	// grau bei not selected-not-relevant

	// soll
	// erst alle neccesary, dann alle relevant, dann alle not-relevant
	// innerhalb: erst  bereinstimmend (selected-neccesary) dann nicht
	//  bereinstimmend (not-selected-neccesary)

	document.writeln("<tr id='" + mod + "'>");
	document.writeln("<td valign='top' width=50>");

	// diese checkbox gibt an obs der fallersteller f r notwendig, irrelevant
	// erachtet hat oder ncith ausgew hlt hat
	if ((mod == 'selected-necessary') || (mod == 'not-selected-necessary')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_selected.gif\">");
	} else if ((mod == 'selected-not-relevant')
			|| (mod == 'not-selected-not-relevant')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_non_relevant.gif\">");
	} else {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_selected.gif\">");
	}

	// diese checkbox gibt an ob ausgew hlt wurde oder nicht
	if ((mod == 'selected-necessary') || (mod == 'selected-not-relevant')
			|| (mod == 'selected-relevant')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/checkbox_selected.gif\">");
	} else {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/checkbox_unselected.gif\">");
	}

	if (item.patho != undefined) {
		var patho = "patho";
		if (item.patho == 1) {
			patho += "_high";
		} else if (item.patho == 2) {
			patho += "_low";
		}
		document.writeln("<img src='" + top.getBaseDir() + "/lf/img/" + patho
				+ ".gif'>");
	}
	document.writeln("</td>");
	document.writeln("<td valign='top'><div class=" + mod + "-title'>"
			+ item.name + "</div>");
	document.writeln("<font color=#999999 size=1>" + item.spec + "</font>");
	document.writeln("</td>");
	document.writeln("<td valign='top'>" + item.result + "<br>");
	if (top.isShowComments()) {
		if (item.comment && item.comment != "")
			document.writeln("<a href=\"javascript:showComment(" + pos
					+ ");void(0);\"><img border=\"0\" src=\""
					+ top.getBaseDir() + "/icons/expert.gif\"></a>");
	}
	if (item.media) {
		// writeMedia(item, true, false);
		writeMedia(item, false, false);

	}
	if (item.link) {
		writeLinks(item, true, false);
	}
	document.writeln("</td>");
	var norm = "&nbsp;";
	if (item.norm)
		norm = item.norm;
	document.writeln("<td valign='top'><nobreak>" + norm + "</nobreak></td>");
	document.writeln("</tr>");
	// writeItemEnd();
}

/**
 * Writes an item in a list.
 */
function writeItem(pos, item) {
	// get feedback mode of the item
	var mod = getItemMode(item);

	// Write anchor, so that the item can be accessed directly
	document.writeln("<a name='" + item.id + "'>");
	// div for full item
	document.writeln("<div class='record-item' id='" + mod + "'>");
	// div for title
	document.writeln("<div>");
	if ((mod == 'selected-necessary') || (mod == 'not-selected-necessary')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_selected.gif\">");
	} else if ((mod == 'selected-not-relevant')
			|| (mod == 'not-selected-not-relevant')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_non_relevant.gif\">");
	} else {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/expert_checkbox_selected.gif\">");
	}

	if ((mod == 'selected-necessary') || (mod == 'selected-not-relevant')
			|| (mod == 'selected-relevant')) {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/checkbox_selected.gif\">");
	} else {
		document.writeln("<img src=\"" + top.getBaseDir()
				+ "/img/checkbox_unselected.gif\">");
	}

	// short name

	document.write("<span class='" + mod + "'>");
	document.write(item.name);
	document.write("</span>");
	// Full name, if available (e.g. history question
	// have as short name a keyword, as full name a complete question
	if (item.full != undefined) {
		document.write(" <span class='" + mod + "-full'>(" + item.full
				+ ")</span>");
	}
	document.writeln();
	if (top.isShowComments()) {
		// Comment, if available
		if (item.comment && item.comment != "")
			document
					.writeln("<img border=\"0\" src=\""
							+ top.getBaseDir()
							+ "/icons/expert.gif\" style=\"cursor:pointer\" onclick=\"showComment("
							+ pos + ")\">");
	}
	document.writeln("</div>");
	document.writeln("<div class=\"result\">");
	// Render result (examinations only)
	if (item.result != null && item.result != undefined) {
		if (top.hasRenderer(item)) {
			// write renderer, if available
			top.renderItem(document, item);
		} else {
			// else write just result text ...
			document.writeln(item.result);
		}
	} else {
		document.writeln("&nbsp;");
	}
	// append media, large icons
	writeMedia(item, false, false);
	// append links, large icons
	writeLinks(item, false, false);
	// close open tags ...
	document.writeln("</div>");
	document.writeln("</div></a>");
}

/**
 * Returns with of the window.
 */
function getWidth() {
	var ns4 = (document.layers) ? true : false;
	var ie4 = (document.all) ? true : false;
	var winW = (ns4) ? window.innerWidth - 16 : document.body.offsetWidth - 20;
	return winW;
}

/**
 * Returns height of the window.
 */
function getHeight() {
	var ns4 = (document.layers) ? true : false;
	var ie4 = (document.all) ? true : false;
	var winH = (ns4) ? window.innerHeight : document.body.offsetHeight;
	return winH;
}

function createTutor() {
	if (top.isShowComments()) {
		// var w = getWidth() -105;
		// var h = getHeight() -100;
		// document.writeln("<div id=\"tutor\" style=\"position:fixed;
		// top:"+h+"px; left:"+w+"px; visiblity:visible;\">");
		// document.writeln("<img src=\"../img/default.gif\"
		// name=\"tutor_image\">");
		// document.writeln("</div>");
		document.write("<div id=\"tutor_bubble\"></div>");
	}
}

function closeEventComment(){
	top.callToServer("Expertenkommentar","close","");
}

/**
 * Shows the given text in the tutor bubble.
 */
function showTutorText(text) {
	top.startSpeaking();
	text = "<table border=0 cellspacing=0 cellpadding=0><tr><td height=10><img src=\"../img/bubble_left_top.gif\"></td><td background=\"../img/bubble_top.gif\"></td><td><img src=\"../img/bubble_right_top.gif\"></td></tr><tr><td background=\"../img/bubble_left.gif\"></td><td bgcolor=\"#FFFF88\"><form><div id=scrollbereich>"
			+ text
			+ "</div><div style=\"margin-top: 10px;\" align=\"center\"><input id='closeButton' value=\""
			+ top.getBasicResource().close
			+ "\" type=\"button\" onClick=\"closeBubble();closeEventComment();\"></div></form></td><td background=\"../img/bubble_right.gif\"></td></tr>";
	text = text
			+ "<tr><td align=\"right\" height=10><img src=\"../img/bubble_left_down.gif\"></td><td background=\"../img/bubble_down.gif\"></td><td><img src=\"../img/bubble_right_down.gif\"></td></tr></table>";
	top.layerWrite("tutor_bubble", window, text);
	document.getElementById('closeButton').focus();
}

/**
 * Closes tutor bubble, if visible.
 */
function closeBubble() {
	top.layerWrite("tutor_bubble", window, "");
	top.stopSpeaking();
}

/**
 * Write header of the content page. The header contains an icon and a title.
 * The background of the title is colored in a specific color.
 * 
 * @res
 * @type_res
 */

function writeHeader(res, type_res) {
	writeHeader(res, type_res, 0);
}

function writeHeader(res, type_res, loop) {
	var isLoopStart = top.indicateNewTherapyLoop(top.getCurrentPageNumber());

        //document.write ('<div style="padding:10px">');

	if (top.getCaseNr() == "123" || top.getCaseNr() == "000000") {
		document
				.write("<table cellspacing=0 cellpadding=0 border=0 width='100%'><tr><td valign=center align=center width=20 height=20 >&nbsp;</td><td width=10></td><td>");
	} else {
		var icon = top.getCurrentPage().res;
		var text = res.title;
		if (icon == 4 && top.getCurrentPage().quest.answer == "") {
			icon = 15;
			text = top.getBasicResource().comment;
		}
		document
				.write("<table cellspacing=0 cellpadding=0 border=0 width='100%'><tr><td valign=center align=center width=20 height=20 bgcolor=\""
						+ type_res.color
						+ "\"><img src=\""
						+ top.getBaseDir()
						+ "/img/exam/"
						+ icon
						+ ".gif\"></td><td width=10></td><td>");
	}

	if (top.getCaseNr() == "123" || top.getCaseNr() == "000000") {
		document.writeln("<font size=3 color=\"#415D7B\"><b>"
				+ top.getBasicResource().welcome + "</b></font>");
	} else {
		if (type_res.type == 0) {
			document.writeln("<font size=3 color=\"#415D7B\"><b>" + text
					+ "</b></font>");
		}

		if (type_res.type == 1) {
			if (top.getNoFeedback() != true)
				document.writeln("<font size=3 color=\"#415D7B\"><b>"
						+ res.titlefeedback + "</b></font>");
			else
				document.writeln("<font size=3 color=\"#415D7B\"><b>"
						+ res.title + "</b></font>");
		}

		if (type_res.type == 2) {
			if (isLoopStart == 1) {
				document.writeln("<font size=3 color=\"#415D7B\"><b>"
						+ top.getBasicResource().schleife + " " + loop
						+ "</b></font>");
			} else {
				document.writeln("<font size=3 color=\"#415D7B\"><b>"
						+ res.titleconclusion + "</b></font>");
			}
		}

		if (type_res.type == 3) {
			document.writeln("<font size=3 color=\"#415D7B\"><b>" + text
					+ "</b></font>");
		}
		
	}
	if (top.enable_Debug){
		document.writeln("</td><td width='25'>" +  
			"<img border=0 src=\""
			+ top.getBaseDir()
			+ "/img/bug.png\" onclick='showDebug();' style='cursor:pointer'>");
	}
	if (top.enable_Help){
		//is defined on each page 0.html, 1.html,...
		writeHelp(res, type_res);
	}
	document.writeln("</td></tr></table>");
    //    document.write ('</div>');
	document.writeln("<hr width='99%' noshade color=\"" + type_res.color + "\">");
}


/**
 *  ffnet einen Modalen Dialog mit einer Hilfeseite
 * EXT muss auf der Seite definiert sein!
 * @return
 */
function writeHelp(res,type_res){
	//var url = top.helplink_introduction;
	var url = "http://duplo.mi.hs-heilbronn.de/campusdoc/index.php?title=Main_Page";
	var title = top.res[1000].carddoc+" || "+res.title;
	//welcome
	if (top.getCaseNr() == "123" || top.getCaseNr() == "000000") {
		url = top.helplink_welcome;
		title = top.res[1000].carddoc;
	}
	else{
		if (type_res.type == 0) {
			url = top.helplink_introduction;
		}
		else if (type_res.type == 1) {
			url = top.helplink_anamnese; 
		}
		else if (type_res.type == 2) {
			url = top.helplink_physExamination; 
		}
		else if (type_res.type == 3) {
			url = top.helplink_suspectedDiagnosis; 
		}
		else if (type_res.type == 4) {
			url = top.helplink_question; 
		}
		else if (type_res.type == 5) {
			url = top.helplink_summary1; 
		}
		else if (type_res.type == 6) {
			url = top.helplink_technicalExamination; 
		}
		else if (type_res.type == 7) {
			url = top.helplink_laboratory; 
		}
		else if (type_res.type == 8) {
			url = top.helplink_workingDiagnosis; 
		}
		else if (type_res.type == 9) {
			url = top.helplink_therapy; 
		}
		else if (type_res.type == 11) {
			url = top.helplink_dts; 
		}
		else if (type_res.type == 12) {
			url = top.helplink_clinicalProgression; 
		}
		else if (type_res.type == 13) {
			url = top.helplink_prognosis; 
		}
		else if (type_res.type == 14) {
			url = top.helplink_summary; 
		}
	}
	url += "?setlang="+top.getLanguage()+"&aaction=purge";
	document.writeln("</td><td align='right' width='25'>" +  
			"<img border=0 src=\""
			+ top.getBaseDir()
			+ "/img/help.png\" onclick='showHelp(\""+url+"\",\""+title+"\");' style='cursor:pointer'>");
	
}

/**
 * Extjs muss auf der Seite includiert sein!
 */
function showDebug(){
	if((typeof debugWindow=='undefined')||(debugWindow.closed)){
		debugWindow = showWindow(top.getBaseDir()+"/debug.html","Debug",600, 500, true);
	}else{
		debugWindow.focus();	
	}
}

/**
 *  ffnet einen Modalen Dialog mit einer Hilfeseite
 * EXT muss auf der Seite definiert sein!
 * @return
 */
function showHelp(url,title){
	if((typeof helpWindow=='undefined')||(helpWindow.closed)){
		helpWindow = showWindow(url,title,600, 500, true);
	}else{
		helpWindow.focus();
		
	}
}

function showWindow(url, title, width,height , center){
	var fenster = window.open(	url,title,
			"width="+width+",height="+height+",left=100,top=200,location=no, menubar=no,status=no, toolbar=no, scrollbars=no, resizable=no"
	);
	if (center==true){
		wleft = (screen.width - width) / 2;
		wtop = (screen.height - height) / 2;
		if (wleft < 0) {
		w = screen.width;
		wleft = 0;
		}
		if (wtop < 0) {
		h = screen.height;
		wtop = 0;
		}
		fenster.moveTo(wleft, wtop);
	}
	fenster.focus();
	return fenster;
}

/**
 * Shows the writeNoteDialog in a plain old window
 * @return
 */
function showWriteNoteDialogPlain(){
	if((typeof noteWindow=='undefined')||(noteWindow.closed)){
		noteWindow = showWindow(top.getBaseDir()+"/notes.html","Notizen",620, 500, true);
	}else{
		noteWindow.focus();		
	}
}

/**
 * Shows the writeNoteDialog.
 * 
 * @return
 */
function showWriteNoteDialog(){
	//definiere ein Notes-Objekt
    function Notes(){
		//Attribute
		var dialog;
		var htmlEditorPanel;
		var notesPanel;
		var store;
		//Methode
		this.init = init;
		this.addNote = addNote;
		
		function init(){
            store = new Ext.data.Store({
				id: 'notestore',
                proxy: new Ext.data.ScriptTagProxy({
                    url: top.serverURL + '/NotesController',
                    nocache: true
                }),
                reader: new Ext.data.JsonReader({
                    root: 'rows',
                    id: 'id'
                },Ext.data.Record.create([
    				{name:'id',type:'int'},
                    {name:'time',type:'string'},
                    {name:'content',type:'string'}
                ]))
            
            });//store
            store.load({
                params: {
                    action: "init"
                },
                callback: function(records, options, success){
                	for (var i = 0; i < records.length; ++i){
                		var record = records[i]; 
                		addNote(record.get('time'), record.get('content'));
                	}
                }
            });
            htmlEditorPanel = new Ext.Panel({
                //layout: 'column',
				layout: 'fit',
                region: 'south',
                baseCls: 'x-plain',
                height: 200,
                //width: '100%',
                bodyStyle: 'background:#ffffff;padding:5px 10px;',
                items: [{
                    xtype: 'htmleditor',
                    id: 'edit',
                    height: 180
                    //columnWidth: 1.0
                }]
            });//htmlEditorPanel
            notesPanel = new Ext.Panel({
                bodyStyle: 'background-color:#ffffff;padding:5px 10px;border:0px',
                id: 'notepanel',
                border: false,
                baseCls: 'x-plain',
                //frame: false,
                autoScroll: true,
                items: [{
                    xtype: 'panel',
                    html: '<h2 align=center>' + top.res[1000].notes + '</h2>',
                    id: 'logmessage',
                    border: false
                }, {
                    xtype: 'panel',
                    id: 'note',
                    border: false,
                    layout: 'column',
                    defaults: {
                        // applied to each contained panel
                        //bodyStyle: 'padding:20px',
                        style: 'border: 0px;',
                        border: false,
                        width: '100%'
                    }
					//items werden dynamische hinzugef gt
                }],
                labelWidth: 80,
                region: 'center'
            });//notesPanel
            dialog = new Ext.Window({
                buttons: [{
                    handler: function(){
                        //Ext.getCmp('logmessage').body.update(Ext.getCmp('edit').getValue());
                        store.load({
			                params: {
			                    action: "add",
								note: Ext.getCmp('edit').getValue()
			                },
			                callback: function(records, options, success){
			                	for (var i = 0; i < records.length; ++i){
			                		var record = records[i]; 
			                		addNote(record.get('time'), record.get('content'));
			                	}
			                }
			            });
						Ext.getCmp('edit').setValue("");
                        Ext.getCmp('edit').focus();
                    },
                    scope: Notes,
                    text: top.res[1000].notes_add
                }],
                buttonAlign: 'center',
                closable: true,
                bodyStyle: 'padding:5px 35px;',
                draggable: true,
                height: 500,
                id: 'notes-win',
                layout: 'border',
                minHeight: 300,
                minWidth: 530,
                plain: false,
                resizable: true,
                items: [notesPanel, htmlEditorPanel],
                title: 'Card-Player || ' + top.res[1000].notes,
                width: 600
            });//dialog
            dialog.show();
		}
		//f gt eine neue Notiz hinzu
        function addNote(date, message){
            if ((Ext.util.Format.trim(date).length > 0) && (Ext.util.Format.trim(message).length > 0)) {
                panel1 = new Ext.Panel({
                    html: date+" :",
                    columnWidth: 0.1
                });
                panel2 = new Ext.Panel({
                    html: message,
                    columnWidth: 0.9
                });
                panel3 = new Ext.Panel({
                    html: '<hr width=90% align=center>',
                    colspan: 2,
                    columnWidth: 1.0
                });
				//falls das Fenster vorher geschlossen wurde
				if (Ext.getCmp('note')) {
					with (Ext.getCmp('note')) {
						add(panel1);
						add(panel2);
						add(panel3);
						doLayout();
					}
				}
				if (Ext.getCmp('notepanel'))
                	Ext.getCmp('notepanel').doLayout();
				//iE auch dolayout vom dialog?
				if (Ext.getCmp('notes-win'))
                	Ext.getCmp('notes-win').doLayout();
				
            }        
        }
	}
	//erstelle eine Instanz von Note
    var note = new Notes();
	note.init();
}

// Code for Levenshtein distance below ..

// ****************************
// Get minimum of three values
// ****************************

function min(a, b, c) {
	var mi;

	mi = a;
	if (b < mi) {
		mi = b;
	}
	if (c < mi) {
		mi = c;
	}
	return mi;
}

// *****************************
// Compute Levenshtein distance
// *****************************

function levenshtein(s, t) {
	// int d[][]; // matrix
	var d;
	var n; // length of s
	var m; // length of t
	var i; // iterates through s
	var j; // iterates through t
	var s_i; // ith character of s
	var t_j; // jth character of t
	var cost; // cost

	// Step 1
	n = s.length;
	m = t.length;
	if (n == 0) {
		return m;
	}
	if (m == 0) {
		return n;
	}
	d = new Array(n + 1);
	for (i = 0; i < n + 1; i++) {
		d[i] = new Array(m + 1);
	}
	// Step 2
	for (i = 0; i <= n; i++) {
		d[i][0] = i;
	}
	for (j = 0; j <= m; j++) {
		d[0][j] = j;
	}
	// Step 3
	for (i = 1; i <= n; i++) {
		s_i = s.charAt(i - 1);
		// Step 4
		for (j = 1; j <= m; j++) {
			t_j = t.charAt(j - 1);
			// Step 5
			if (s_i == t_j) {
				cost = 0;
			} else {
				cost = 1;
			}
			// Step 6
			d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1]
					+ cost);
		}
	}
	// Step 7
	return d[n][m];
}

// *****************************
// pruefe Popup-Blocker
// *****************************
function testWin(url, name, params) {
	var win = window.open(url, name, params);
	if (!win)
		alert('Bitte schalten Sie Ihren Popup-Blocker aus und versuchen Sie es erneut.');
	else
		win.focus();
	return win;
}

// *****************************
// liefert den Code um ein Flash-Medium einzubinden
// *****************************

function getEmbedFlash(isMP3, id, playerBaseURL) {
	var player = '';
	if(!playerBaseURL){
		playerBaseURL=top.getBaseDir();
	}
	player += playerBaseURL+ '/';
	player += 'mediaplayer.swf';
     var text = '';
     text += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%">';
     text += '<param name="movie" value="'+player+'" />';
     text += '<param name="flashvars" value="displayheight=9999&overstretch=fit&autostart=true&type='+(isMP3 ? 'mp3' : 'flv')+'&repeat=true&file='+id+'" />';
     text += '<!--[if !IE]>-->';
     text += '<object type="application/x-shockwave-flash" data="'+player+'" width="100%" height="100%">';
     text += '<!--<![endif]--><p>Please install Adobe <a href="http://www.adobe.de" target="_blank">Flash</a></p>';
     text += '<!--[if !IE]>-->';
     text += '<param name="flashvars" value="displayheight=9999&overstretch=fit&autostart=true&type='+(isMP3 ? 'mp3' : 'flv')+'&repeat=true&file='+id+'" />';
     text += '</object>';
     text += '<!--<![endif]-->';
     text += '</object>';
     return text;
}
