var the_subject = the_subsubject = the_chapter = the_slide = the_call = the_additional = found_images_array = '';
var src_hierarchy = '';

if(location.search.substring(1).indexOf('%7C') != -1) search_items = location.search.substring(1).split('%7C');
else search_items = location.search.substring(1).split('|');
/* if((location.search.length>0) && (location.search.substring(1).indexOf(document.title.toLowerCase())) == -1) location.href = '../index.html'; */
if(search_items.length>0){ 
	the_program = search_items[0];
}
if(search_items.length>1){ 
	the_subject = search_items[1];
	var subsubject_hierarchy =  the_program + '|' + the_subject;
}
if(search_items.length>2){ 
	the_subsubject = search_items[2];
	var chapter_hierarchy =  the_program + '|' + the_subject + '|' + the_subsubject;
}
if(search_items.length>3){ 
	the_chapter = search_items[3];
	var slide_hierarchy =  the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter;
}
if(search_items.length>4){ 
	the_slide = search_items[4];
	if(the_slide.indexOf('X') == -1) var src_hierarchy =  the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide;
}
if(search_items.length>5){ 
	the_call = search_items[5];
}
if(search_items.length>6){ 
	the_additional = search_items[6];
}
if(search_items.length>7){ 
	found_images_array = search_items[7].split('??');
}

var folderDepth = 0;
if(the_subject != 0) folderDepth = 1;


var theFontSize;
var cookieArray = getCookie('settings').split('|');
if((cookieArray[0] == 'NaN') || (cookieArray[0] == '')){
	theFontSize = 12;
}
else{
	theFontSize = parseInt(cookieArray[0]);
}

function getCarpetTitle(){
	for(i = 1;i <= course_titles.length-1;i++){
		var titles_array = course_titles[i].split('|');
		if(the_chapter == titles_array[1]){
			theCarpetTitle = titles_array[0];
		}
	}
	return theCarpetTitle;
}

function write_sitemap(){
	var theText = '<ul id="first-level">';
	for(i = 1;i <= subjects.length-1;i++){
		if(subjects[i].indexOf('*') != -1){ // a window exists
			var titlesArray = subjects[i].split('*');
			theText += '<li><a href="javascript:openWindow(\'' + titlesArray[1] + '\',' + folderDepth + ',\'' + titlesArray[2] + '\',\'' + titlesArray[3] + '\')" onmouseover="Tip(\'' + titlesArray[4] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> *<br />';
		}		
		else if(subjects[i].indexOf('|') != -1){
			var titlesArray = subjects[i].split('|');
			if(titlesArray[0] == 'Sitemap'){
				theText += '<li>' + titlesArray[0];
			}
			else{
				theText += '<li><a href="' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '"  target="_top" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a><br />';
				if(subsubarray.toString().indexOf(titlesArray[1]) != -1) {
					theText += '<ul id="second-level">'
					for(k=0;k<subsubarray.length;k++){
						if((subsubarray[k].indexOf('*') != -1) && (subsubtitles[0] == titlesArray[1])){
							var subsubtitles = subsubarray[k].split('|');
							var subsub_titles = subsubtitles[1].split('*');
							theText += '<li><a href="javascript:openWindow(\'' + subsub_titles[1] + '\',' + folderDepth + ',\'' + subsub_titles[2] + '\',\'' + subsub_titles[3] + '\')" onmouseover="Tip(\'' + subsub_titles[4] + '\',WIDTH,150)" onmouseout="UnTip()">' + subsub_titles[0] + '</a> *<br />';
						}
						else{
							var subsubtitles = subsubarray[k].split('|');
							if(subsubtitles[0] == titlesArray[1]){
								theText += '<li><a href="' + subsubtitles[0] + '_' + subsubtitles[2] + '.html?' + the_program + '|' + subsubtitles[0] + '|' + subsubtitles[2] + '" target="_top" onmouseover="Tip(\'' + subsubtitles[3] + '\',WIDTH,150)" onmouseout="UnTip()">' + subsubtitles[1] + '</a>';
								if(chaptersarray.toString().indexOf(subsubtitles[2]) != -1) {
									theText += '<ul id="third-level">'
									for(n=0;n<chaptersarray.length;n++){
										var chaptertitles = chaptersarray[n].split('|');
										if((chaptertitles[0] == subsubtitles[0]) && (chaptertitles[1] == subsubtitles[2])){
											if(subsubtitles[2] == 'cases'){
												theText += '<li><a href="case.html?' + the_program + '|' + subsubtitles[0] + '|' + subsubtitles[2] + '|' + chaptertitles[3] + '|1" target="_top">' + chaptertitles[2];
											}
											else{
												theText += '<li><a href="carpet.html?' + the_program + '|' + subsubtitles[0] + '|' + subsubtitles[2] + '|' + chaptertitles[3] + '" target="_top">' + chaptertitles[2];
											}
										}
									}
									theText += '</ul>'
								}
							}
						}
					}
					theText += '</ul>'
					
				}
			}
		}
	}
	theText += '</ul>';
	return theText;
}

function add_to_subsubarray(subsub_title){
	for(i=1;i<subsubjects.length;i++){
		var titlesArray = subsubjects[i].split('|');
		subsubarray[j+i] = subsub_title + '|' + titlesArray[0] + '|' + titlesArray[1] + '|' + titlesArray[2];
	}
	j += i-1;
}

function add_to_chaptersarray(subsub_title,chap_title){
	for(i=1;i<course_titles.length;i++){
		var chapArray = course_titles[i].split('|');
		chaptersarray[m+i] = subsub_title + '|' + chap_title + '|' + chapArray[0] + '|' + chapArray[1];
	}
	m += i-1;
}

function write_subjects(){
	var theText = '';
	for(i = 1;i <= subjects.length-1;i++){
		if(subjects[i].indexOf('|') != -1){
			var titlesArray = subjects[i].split('|');
			if((the_subject == titlesArray[1]) && (titlesArray[3] != undefined)){ // the chosen chapter hilited in red
				theText += '<a href="../../' + titlesArray[3] + '/htmls/' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '" id="current" target="_top"  onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else if(the_subject == titlesArray[1]){ // the chosen chapter hilited in red
				theText += '<a href="' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '" id="current" target="_top"  onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else if(titlesArray[3] != undefined){ //a chapter in another folder
				theText += '<a href="../../' + titlesArray[3] + '/htmls/' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '" target="_top" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else if(the_subject != 0){ // another subject (the same folder)
				theText += '<a href="' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '" target="_top" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else{ // a chapter one step down
					theText += '<a href="htmls/' + titlesArray[1] + '.html?' + the_program + '|' + titlesArray[1] + '"  target="_top" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
		}
		else if(subjects[i].indexOf('*') != -1){ // a window exists
			var titlesArray = subjects[i].split('*');
			theText += '<a href="javascript:openWindow(\'' + titlesArray[1] + '\',' + folderDepth + ',\'' + titlesArray[2] + '\',\'' + titlesArray[3] + '\')" onmouseover="Tip(\'' + titlesArray[4] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
		}		
		else{ // a chapter not implemented yet
			theText += subjects[i];
		}
	}
	return theText;
}

function write_subsubjects(){
	theText = '';
	for(i = 1;i <= subsubjects.length-1;i++){
		if(subsubjects[i].indexOf('|') != -1){ // a subsubject exists
			var titlesArray = subsubjects[i].split('|');
			if((the_subsubject == titlesArray[1])  && (titlesArray[3] != undefined)){ // the chosen chapter in another folder
				theText += '<a href="../../' + titlesArray[3] + '/htmls/' + the_subject + '_' + titlesArray[1] + '.html?' + the_program + '|' + the_subject + '|' + titlesArray[1] + '" id="current" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else if(the_subsubject == titlesArray[1]){ // the chosen chapter
				theText += '<a href="' + the_subject + '_' + titlesArray[1] + '.html?' + the_program + '|' + the_subject + '|' + titlesArray[1] + '" id="current" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else if((the_subsubject != titlesArray[1])  && (titlesArray[3] != undefined)){ // a chosable chapter in another folder
				theText += '<a href="../../' + titlesArray[3] + '/htmls/' + the_subject + '_' + titlesArray[1] + '.html?' + the_program + '|' + the_subject + '|' + titlesArray[1] + '"onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
			else{ // a chosable chapter
				theText += '<a href="' + the_subject + '_' + titlesArray[1] + '.html?' + the_program + '|' + the_subject + '|' + titlesArray[1] + '" target="_top" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
			}
		}
		else if(subsubjects[i].indexOf('*') != -1){ // a window exists
			var titlesArray = subsubjects[i].split('*');
			theText += '<a href="javascript:openWindow(\'' + titlesArray[1] + '\',' + folderDepth + ',\'' + titlesArray[2] + '\',\'' + titlesArray[3] + '\')" onmouseover="Tip(\'' + titlesArray[4] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a> ';
		}		
		else{ // a chapter not implemented yet
			theText += subsubjects[i];
		}
	}
	return theText;
}

function write_chapter_titles(){
	var theText = '';
	for(i = 1;i <= course_titles.length-1;i++){
		var titlesArray = course_titles[i].split('|');
		if(the_chapter == titlesArray[1]){ // this chapter is chosen
		    if((the_subsubject == 'cases') || (the_subject == 'labocase')){
				theText = write_slideList()  + theText; // the slides of the chosen Module
				theText = '<li><a href="case.html?' + slide_hierarchy + '|1" id="current" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()">' + actual_case + '<br />&gt; ' + titlesArray[0] + ' &lt;</a></li>' + theText;
				theText += '<li><a href="case.html?' + slide_hierarchy + '|1" id="current" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
				theCarpetTitle = titlesArray[0];
		    }
		    else if(the_subsubject == 'referral'){
				theText += '<li><a href="dento_referral?' + chapter_hierarchy +  '" id="current" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
				theText += write_slideList(); // the slides of the chosen Praktikum
				theCarpetTitle = titlesArray[0];
		    }
		    else if(titlesArray[2] != undefined){
				theText += '<li><a href="' + the_subject + '_' +titlesArray[1] + '.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" id="current" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150) onmouseout="UnTip()"">' + titlesArray[0] + '</a></li>';
		    }
		    else if(the_slide != ''){
				theText += '<li><a href="carpet.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" id="current" onmouseover="Tip(\'' + chapter_info + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
				theText += write_slideList(); // the slides of the chosen Praktikum
				theCarpetTitle = titlesArray[0];
			}
			else{ // the chosen chapter
				theText += '<li><a href="carpet.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" id="current" onmouseover="Tip(\'' + chapter_info + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
				theCarpetTitle = titlesArray[0];
			}
		}
		else{
			if((the_subsubject == 'cases') && (getCookie('cases_done').indexOf('-' + i + '-') != -1)){
				theText += '<li><a href="case.html?' + chapter_hierarchy + '|' + titlesArray[1] + '|1" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()" onclick="setCookie(\'casePage\',1)">' + titlesArray[0] + '<img src="../gifs/done.gif" border="0" /></a></li>';
				//  vor </a> einsetzen
			}
			else if((the_subsubject == 'cases') || (the_subject == 'labocase')){
				theText += '<li><a href="case.html?' + chapter_hierarchy + '|' + titlesArray[1] + '|1" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()" onclick="setCookie(\'casePage\',1)">' + titlesArray[0] + '</a></li>';
			}
		    else if(the_subsubject == 'referral'){
				theText += '<li><a href="slide.html?' + chapter_hierarchy + '|' + titlesArray[1] + '|1" onmouseover="Tip(\'' + case_info + '\',WIDTH,150)" onmouseout="UnTip()" onclick="setCookie(\'casePage\',1)">' + titlesArray[0] + '</a></li>';
		    }
		    else if(titlesArray[2] != undefined){
				theText += '<li><a href="' + the_subject + '_' +titlesArray[1] + '.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" onmouseover="Tip(\'' + titlesArray[2] + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
		    }
			else{
				theText += '<li><a href="carpet.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" onmouseover="Tip(\'' + chapter_info + '\',WIDTH,150)" onmouseout="UnTip()">' + titlesArray[0] + '</a></li>';
			}
		}
	}
	var theText = '<ol id="chapters-list">' + theText + '</ol>';
	return theText ;
}

function generate_directionslist(){
	var the_text = '';
	if(directions[1] != 0){
		for(i=1;i<directions.length;i++){
			var the_directionsarray = directions[i].split('|');
			the_text += the_directionsarray[0] + ' = ' + the_directionsarray[1] + '<br>';
		}
	}
	return (the_text);
}

function generate_modalitieslist(){
	var the_text = '';
	if(modalities[1] != 0){
		for(i=1;i<modalities_max;i++){
			var the_modalitiesarray = modalities[i].split('|');
			the_text += the_modalitiesarray[0] + ' = ' + the_modalitiesarray[1] + '<br>';
		}
	}
	return (the_text);
}

function get_modality(slideType) {
	var modality = '';
	for(n=1;n<modalities.length;n++){
		var modalitiesArray = modalities[n].split('|');
		if(slideType == modalitiesArray[0]) {
			modality = modalitiesArray[1];
			break;
		} 
	}
	return modality;
}

function write_slideList(){
	var theText = '<ol id="slides-list">';
	if((the_subsubject == 'cases') || (the_subject == 'labocase')){
		var counter = getCookie('casePage');
	}
	else{
		var counter = page_elements.length-1
	}
	for(j = 1;j <= counter;j++){
		var thePageContentArray = page_elements[j].split('|');
		if(the_slide == j){ // the chosen page, no link
			theText += '<li><a href="#" id="current">' + thePageContentArray[0];
		}
		else if((the_subsubject == 'cases') || (the_subject == 'labocase')) {
			if(debugonoff){ // chooosable page with debug information
				theText += '<li><a href="case.html?' + slide_hierarchy +'|' + j + '"  onmouseover="Tip(\'' + thePageContentArray[5] + '\',WIDTH,150,TITLE,\'' + preview + '\')" onmouseout="UnTip()">' + thePageContentArray[0];
			}
			else{  // chooosable page without debug information
				theText += '<li><a href="case.html?' + slide_hierarchy +'|' + j + '">' + thePageContentArray[0];
			}
		}
		else{
			if(debugonoff){ // chooosable page with debug information
				theText += '<li><a href="slide.html?' + slide_hierarchy +'|' + j + '"  onmouseover="Tip(\'<img src=\\\'../' + the_subject + '/images_i/' + thePageContentArray[5] + '_i.jpg\\\'>' + thePageContentArray[5] + '\',WIDTH,150,TITLE,\'' + preview + '\')" onmouseout="UnTip()">' + thePageContentArray[0];
			}
			else{  // chooosable page without debug information
				theText += '<li><a href="slide.html?' + slide_hierarchy +'|' + j + '"  onmouseover="Tip(\'<img src=\\\'../' + the_subject + '/images_i/' + thePageContentArray[5] + '_i.jpg\\\'>\',WIDTH,150,TITLE,\'' + preview + '\')" onmouseout="UnTip()">' + thePageContentArray[0];
			}
		}
		if(thePageContentArray[9] != '') theText +=  '. ' + thePageContentArray[9];
		theText += ': ' + thePageContentArray[1] + '</a></li>';
	}
	theText += '</ol>';
	return theText;
}

function  write_image_carpet(){
	var imageCounter = 0;
//	if(((document.all) && (navigator.appVersion.indexOf('Macintosh') > -1)) || (the_subject == 'ana') || (the_program == 'radiosurf')){
		var theText = '<table border="0" cellpadding="3" cellspacing="2"><caption align="top"><span class="imgtitle">' + theCarpetTitle + ' - ' + (page_elements.length-1) + ' ' + pages_word + '<\/span></caption><tr>';
		for(n = 1;n < page_elements.length; n++){
			var thePageContentArray = page_elements[n].split('|');
			theText += '<td class="carpet-cell"><div><a href="slide.html?' + slide_hierarchy +'|' + n + '">';
			if((the_program == 'radiosurf') || (the_program == 'pedirad') || (the_subsubject == 'imageatlas')){
				if((the_program == 'radiosurf')  || (the_program == 'pedirad')) slidebordercolor = 'black';
				else slidebordercolor = 'grey';
				var the_borders = icon_dimensions(thePageContentArray[11],thePageContentArray[12]);
				var borders_array = the_borders.split(',');
				theText += '<img src="../' + the_subject + '/images_i/' + thePageContentArray[5] + '_i.jpg" width="' + borders_array[0] + 'px" height="' + borders_array[1] + 'px" border="0" style="border-top: ' + borders_array[2] + 'px solid ' + slidebordercolor + '; border-right: ' + borders_array[3] + 'px solid ' + slidebordercolor + '; border-bottom: ' + borders_array[4] + 'px solid ' + slidebordercolor + '; border-left: ' + borders_array[5] + 'px solid ' + slidebordercolor + '; " />';
			}
			else{
				theText += '<img src="../' + the_subject + '/images_i/' + thePageContentArray[5] + '_i.jpg" width="' + icon_width + 'px" border="0" />';
			}
			theText += '</a></div>'
			theText += '<div class="carpet-div"><a href="slide.html?' + slide_hierarchy +'|' + n + '">' + thePageContentArray[0];
			if(thePageContentArray[9] != '') theText +=  '. ' + thePageContentArray[9];
			theText += ': ' + thePageContentArray[1] + '</a>';
			if(debugonoff == 1)theText +=  '<br />' + thePageContentArray[5];
			theText +=  '</div></td>'
			var imageCounter = imageCounter + 1;
			if((document.location.href.indexOf('print_carpet') != -1) && (imageCounter >= 4)){
				imageCounter = 0;
				theText += '</tr><tr>';
			}
			else if(imageCounter >= 5){
				imageCounter = 0;
				theText += '</tr><tr>';
			}
		}
		theText += '</tr></table>';
/* 	} */
/* 	else{ */
/* 		var theText = ''; */
/* 		for(n = 1;n < page_elements.length; n++){ */
/* 			var thePageContentArray = page_elements[n].split('|'); */
/* 			theText += '<div class="carpet-image"><div><a href="slide.html?' + slide_hierarchy +'|' + n + '"><img src="../' + the_subject + '/images_i/' + thePageContentArray[5] + '_i.jpg" width="' + icon_width + 'px" height="' + icon_height + 'px" border="0" /></a></div><div class="carpet-div">'; */
/* 			theText += '<a href="slide.html?' + slide_hierarchy +'|' + n + '">' + thePageContentArray[0]; */
/* 			if(thePageContentArray[9] != '') theText +=  '. ' + thePageContentArray[9]; */
/* 			theText += ': ' + thePageContentArray[1] + '</a>'; */
/* 			if(debugonoff == 1)theText +=  '<br />' + thePageContentArray[5]; */
/* 			theText +=  '</div></div>' */
/* 		} */
/* 	} */
	return theText ;
}

function  write_chapter_carpet(){
	var imageCounter = 0;
	var theText = '<table border="0" cellpadding="3" cellspacing="2"><tr>';
	for(n = 1;n < page_elements.length; n++){
		var elements_array = page_elements[n].split('|');
		theText += '<td class="carpet-cell"><a href="' + this_file + '?' + slide_hierarchy +'|' + n + '">';
		if((the_program == 'radiosurf') || (the_program == 'pedirad') || (the_subsubject == 'imageatlas')){
			if((the_program == 'radiosurf')  || (the_program == 'pedirad')) slidebordercolor = 'black';
			else slidebordercolor = 'grey';
			var the_borders = icon_dimensions(elements_array[11],elements_array[12]);
			var borders_array = the_borders.split(',');
			theText += '<img src="../' + the_subject + '/images_i/' + elements_array[5] + '_i.jpg" width="' + borders_array[0] + 'px" height="' + borders_array[1] + 'px" border="0" style="border-top: ' + borders_array[2] + 'px solid ' + slidebordercolor + '; border-right: ' + borders_array[3] + 'px solid ' + slidebordercolor + '; border-bottom: ' + borders_array[4] + 'px solid ' + slidebordercolor + '; border-left: ' + borders_array[5] + 'px solid ' + slidebordercolor + '; " />';
		}
		else{
			theText += '<img src="../' + the_subject + '/images_i/' + elements_array[5] + '_i.jpg" width="' + icon_width + 'px" border="0" />';
		}
		theText += '</a><br /><span class="footnote">' + elements_array[1] + '</span></td>'
		var imageCounter = imageCounter + 1;
		if(imageCounter >= 3){
			imageCounter = 0;
			theText += '</tr><tr>';
		}
	}
	theText += '</tr></table>';
	return theText ;
}

function  write_modality_carpet(){
	var imageCounter = 0;
	var theText = '<table border="0" cellpadding="3" cellspacing="2"><tr>';
	for(n = 0;n < found_images_array.length-1; n++){
		elements_array = found_images_array[n].split('%%');
		theText += '<td class="carpet-cell"><a href="' + this_file + '?' + the_program +'|' + elements_array[1] +'|' + elements_array[2] +'|' + elements_array[3] +'|' + elements_array[0] + 'X">';
		theText += '<img src="../' + the_subject + '/images_i/' + elements_array[0] + '_i.jpg" width="' + icon_width + 'px" border="0" />';
		while(elements_array[4].indexOf('%20') != -1){
			elements_array[4] = elements_array[4].replace('%20',' ');
		}
		theText += '</a><br /><span class="footnote">' + elements_array[4] + '</span></td>'
		var imageCounter = imageCounter + 1;
		if(imageCounter >= 3){
			imageCounter = 0;
			theText += '</tr><tr>';
		}
	}
	theText += '</tr></table>';
	return theText ;
}

function  write_praep_carpet(){
	var imageCounter = 0;
	var theText = '<table border="0" cellpadding="3" cellspacing="2"><tr>';
	for(n = 0;n < found_images_array.length-1; n++){
		elements_array = found_images_array[n].split('%%');
		theText += '<td class="carpet-cell"><a href="' + this_file + '?' + the_program +'|' + elements_array[1] +'|' + elements_array[2] +'|' + elements_array[3] +'|' + elements_array[0] + 'X">';
		theText += '<img src="../' + the_subject + '/images_i/' + elements_array[0] + '_i.jpg" width="' + icon_width + 'px" border="0" />';
		while(elements_array[4].indexOf('%20') != -1){
			elements_array[4] = elements_array[4].replace('%20',' ');
		}
		theText += '</a><br /><span class="footnote">' + elements_array[4] + '</span></td>'
		var imageCounter = imageCounter + 1;
		if(imageCounter >= 3){
			imageCounter = 0;
			theText += '</tr><tr>';
		}
	}
	theText += '</tr></table>';
	return theText ;
}

function  write_compare_page(){
	var the_text = '';
	if(the_call == 'chapter'){
		the_text += '<div class="imgtitle">' + chapter_word + ': ' + chapter_title + '</div>';
		the_text += '<div style="padding:4px 0">' + write_chapter_carpet(this_file) + '</div>';
	}
	else if((the_call == 'modality')){
		var the_modality = get_modality(the_additional);
		the_text += '<div class="imgtitle">' + modality_word + ': ' + the_modality + '</div>';
		the_text += '<div style="padding:4px 0">' + write_modality_carpet(this_file) + '</div>';
	}
	else if(the_call == 'praep'){
		var the_praep = get_modality('Pr');
		var elements_array = found_images_array[0].split('%%');
		while(elements_array[4].indexOf('%20') != -1){
			elements_array[4] = elements_array[4].replace('%20',' ');
		}
		the_text += '<div class="imgtitle">' + the_praep + ' ' + elements_array[5] + ': ' +  elements_array[4] + '</div>';
		the_text += '<div style="padding:4px 0">' + write_praep_carpet(this_file) + '</div>';
	}
	else if(the_call != 'start'){
		the_text += '<span class="imgtitle">' + chapter_word + ': ' + chapter_title + ' - </span>' + theCaption;
		if(stainName != 0) the_text += theStaining;
		the_text += '<div style="padding:4px 0"><img name="bild" src="../' + the_subject + '/images_m/' + imageSrc + '_m.jpg" height="' + image_height + 'px" width="' + image_width + 'px" border="0" />';
		the_text += '<span class="footnote"> <br />' + theCopyright + '</span></div>';
		if(the_kommentar != ''){
			the_text += '<div id="comment_div">' + the_kommentar + '</div>';
		}
	}
	return the_text ;
}


function get_slide_pos(the_slide){
	for(i=1;i<page_elements.length;i++){
		elements_array = page_elements[i].split('|');
		if(the_slide == elements_array[5]) the_slide = i;
	}
	return the_slide;
}

function icon_dimensions(image_width,image_height){
	image_width = parseInt(image_width);
	image_height = parseInt(image_height);
	var border_top = 0;
	var border_rig = 0;
	var border_bot = 0;
	var border_lef = 0;
	var ic_width = ic_height = icon_width;
	var the_factor = Math.round(image_width/ic_width);
	if(image_height > image_width){
		ic_width = Math.round((image_width/image_height)*ic_width);
		var border_width = (icon_width - ic_width)/2;
		border_rig = Math.floor(border_width)
		border_lef = Math.ceil(border_width)
	}
	else if(image_height < image_width){
		var border_height = (image_width - image_height)/(2*the_factor);
		border_top = Math.floor(border_height)
		border_bot = Math.ceil(border_height)
		ic_height = Math.round(image_height/the_factor);
	}
	var the_borders = ic_width + ',' + ic_height + ',' + border_top + ',' + border_rig + ',' + border_bot + ',' + border_lef;
	return the_borders;
}

function write_navig_arrows(the_slide, slide_type){
	var theText = '';
	if(the_slide == 0){ // definition of arrows in carpet
		theText += '<a href="' + slide_type + '.html?' + slide_hierarchy + '|' + (page_elements.length-1) + '" onmouseover="Tip(\'' + to_last_page + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&lt;&lt;&nbsp;</a> '
		theText += '<a href="' + slide_type + '.html?' + slide_hierarchy + '|' + (1) + '" onmouseover="Tip(\'' + to_first_page + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>'
	}
	else{ // definition of arrows in slides
		if(the_slide > 1){
			theText += '<a href="' + slide_type + '.html?' + slide_hierarchy +'|' + (the_slide-1) +'" onmouseover="Tip(\''+ to_prev_page + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&lt;&lt;&nbsp;</a>';
		}
		else if((slide_type == 'histo_compare') || (slide_type == 'ana_compare') || (slide_type == 'ophtha_compare') || (slide_type == 'kardio_ekgcompare') || (slide_type == 'endokrino_compare') || (slide_type == 'radthorax_compare') || (slide_type == 'pediradtx_compare') || (slide_type == 'radskeleton_compare') || (slide_type == 'radskeleton_normal')){
			theText += '<a href="' + slide_type + '.html?' + src_hierarchy + '|chapter" onmouseover="Tip(\''+ to_carpet + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&lt;&lt;&nbsp;</a>';
		}
		else{
			theText += '<a href="carpet.html?' + slide_hierarchy + '" onmouseover="Tip(\''+ to_carpet + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&lt;&lt;&nbsp;</a>';
		}
		if(the_slide < (page_elements.length-1)){  
			theText += '&nbsp;<a href="' + slide_type + '.html?' + slide_hierarchy +'|' + (parseInt(the_slide) + 1) + '" onmouseover="Tip(\'' + to_next_page + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>';
		}
		else if((slide_type == 'histo_compare') || (slide_type == 'ana_compare') || (slide_type == 'ophtha_compare') || (slide_type == 'kardio_ekgcompare') || (slide_type == 'endokrino_compare') || (slide_type == 'radthorax_compare') || (slide_type == 'pediradtx_compare') || (slide_type == 'radskeleton_compare') || (slide_type == 'radskeleton_normal')){
			theText += '&nbsp;<a href="' + slide_type + '.html?' + src_hierarchy + '|chapter" onmouseover="Tip(\''+ to_carpet + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>';
		}
		else if(eval_onoff){
			theText += '&nbsp;<a href="carpet.html?' + slide_hierarchy + '" onmouseover="Tip(\'' + to_carpet + '\',WIDTH,150)" onmouseout="UnTip()" onmouseup="openWindow(\'feedback\',1,\'700\',\'700\',1)">&nbsp;&gt;&gt;&nbsp;</a>';
		}
		else{
			theText += '&nbsp;<a href="carpet.html?' + slide_hierarchy + '" onmouseover="Tip(\'' + to_carpet + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>';
		}
	}
	return theText ;
}

function write_navig_arrows_case(){
	var theText = '';
	if(the_slide < (page_elements.length-1)){  
		theText += '<a href="javascript:check_form_case()" onmouseover="Tip(\'' + to_next_step + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>&nbsp;';
	}
	else if(eval_onoff){
		theText += '<a href="' + the_subject +'_' + the_subsubject +'.html?' + the_program + '|' + the_subject +'|' + the_subsubject +'" onmouseover="Tip(\''+ to_quiz_info + '\',WIDTH,150)" onmouseout="UnTip()" onmouseup="openWindow(\'feedback\',1,\'700\',\'700\',1)">&nbsp;&gt;&gt;&nbsp;</a>';
	}
	else{
		theText += '<a href="' + the_subject + '_' + the_subsubject + '.html?' + chapter_hierarchy + '" onmouseover="Tip(\'' + to_cases + '\',WIDTH,150)" onmouseout="UnTip()">&nbsp;&gt;&gt;&nbsp;</a>&nbsp;';
	}	
	return theText;
}

function check_form_case(){
	if(slideName == 'Indikationsstellung'){
		if(check_radios('indicationForm','txYesNo') == 0){
			alert(answer_below_alert);
			return;
		}
	}
	else if(slideName == 'Verordnung'){
		if(document.order_form.correct_exam_text.value == ''){
			alert(fillout_first_above);
			return;
		}
		else if(document.order_form.correct_question_text.value == ''){
			alert(fillout_first_above);
			return;
		}
		else if(document.order_form.correct_clinic_text.value == ''){
			alert(fillout_first_above);
			return;
		}
	}
	else if((slideName == 'Beurteilung') || (slideName == 'Verlauf')){
		if(document.forms[0].elements['summary'].value == ''){
			alert(fillout_summary);
			return;
		}
	}
	else if(the_subject == "endokrino"){
		if(check_numOfChoices(0) == 0) return;
	}
	location.href = 'case.html?' + slide_hierarchy +'|' + (parseInt(the_slide) + 1);
}

function openWindow(titlesArray1, folderDepth, the_width, the_height, add_src){
	var winURL = '';
	for(i=0;i<folderDepth;i++){
		winURL += '../'
	}
	winURL += 'wins/' + titlesArray1 + '.html';
	if(add_src == 1) winURL += '?' + src_hierarchy + '|' + imageSrc;
	if(add_src == 2) winURL += '?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + which_question;
	if(add_src == 3) winURL += '?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + filename;
	var newWin = window.open(winURL, titlesArray1, 'scrollbars=yes,toolbar=no,menubar=no,resizable=yes,width=' + the_width + ',height=' + the_height);
	newWin.focus()
}

function open_compare_win(){
	var winURL = the_subject + '_compare.html?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide + '|chapter';
	var newWin = window.open(winURL,'compare','scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,width=640,height=650');
	newWin.focus()
}

function open_normal_win(){
	var winURL = the_subject + '_normal.html?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide + '|0';
	var newWin = window.open(winURL,'normal','scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,width=640,height=700');
	newWin.focus()
}

function open_ref_win(the_ref){
	var winURL = 'ref.html?' + the_program + '|' + the_subject + '|' + the_ref;
	var newWin = window.open(winURL,'ref','scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,width=625,height=650');
	newWin.focus()
}

function open_normaltx(the_ref){
	var winURL = the_subject + '_normal.html?' + the_ref;
	var newWin = window.open(winURL,'ref','scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,width=625,height=650');
	newWin.focus()
}

function open_anim(the_ref,win_width,win_height){
	var winURL = '../' + the_subject + '/videos/' + the_ref;
	var newWin = window.open(winURL,'Animation','scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,width=' + win_width + ',height=' + win_height);
	newWin.focus()
}

function write_eval_titles(){
	var theText = '<ol id="chapters-list">';
	for(i = 1;i <= course_titles.length-1;i++){
		var titlesArray = course_titles[i].split('|');
		if(the_chapter == titlesArray[1]){ // this chapter is chosen
			the_chapter = titlesArray[0];
			theText += '<li><a href="' + the_subject + '_' + the_subsubject + '_' + titlesArray[1] + '.html?' + chapter_hierarchy + '|' + titlesArray[1] + '" id="current">' + titlesArray[0] + '</a></li>';
		}
		else{
			theText += '<li><a href="' + the_subject + '_' + the_subsubject + '_' + titlesArray[1] + '.html?' + chapter_hierarchy + '|' + titlesArray[1] + '">' + titlesArray[0] + '</a></li>';
		}
	}
	return theText ;
}

function changesrc(image_type){
	var img_type = imageSrc + '_' + image_type + '.jpg';
	var img_src = dd.elements.bild.src;
	if(img_src.indexOf(img_type) == -1){
		dd.elements.bild.swapImage('../' + the_subject + '/images_' + image_type + '/' + imageSrc + '_' + image_type + '.jpg');
		if(include_raws){
			dd.elements.zonelist.hide();
			infofield_onoff = 0;
		}
	}
	else{
		dd.elements.bild.swapImage('../' + the_subject + '/images_m/' + imageSrc + '_m.jpg');
/* 		if(the_subject == 'radthorax'){ */
/* 			dd.elements.pa_image.swapImage('../' + the_subject + '/images_maps/' + imageSrc + 'pa_m.jpg'); */
/* 			dd.elements.ds_image.swapImage('../' + the_subject + '/images_maps/' + imageSrc + 'ds_m.jpg'); */
/* 		} */
		if(include_raws){
			dd.elements.zonelist.show();
			infofield_onoff = 1;
		}
	}
}	

function simple_changesrc(image_type){
	var img_type = imageSrc + '_' + image_type + '.jpg';
	var img_src = dd.elements.bild.src;
	if(img_src.indexOf(img_type) == -1){
		dd.elements.bild.swapImage('../' + the_subject + '/images_' + image_type + '/' + imageSrc + '_' + image_type + '.jpg');
	}
	else{
		dd.elements.bild.swapImage('../' + the_subject + '/images_m/' + imageSrc + '_m.jpg');
	}
}	

function changesrc_hasmap(image_type){
	var img_type = imageSrc + '_' + image_type + '.jpg';
	var img_src = document.realbild.src;
	if(img_src.indexOf(img_type) == -1){
		document.realbild.src = '../' + the_subject + '/images_' + image_type + '/' + imageSrc + '_' + image_type + '.jpg';
		if(include_raws){
			dd.elements.zonelist.hide();
			infofield_onoff = 0;
		}
	}
	else{
		document.realbild.src = '../' + the_subject + '/images_m/' + imageSrc + '_m.jpg';
/* 		if(the_subject == 'radthorax'){ */
/* 			dd.elements.pa_image.swapImage('../' + the_subject + '/images_maps/' + imageSrc + 'pa_m.jpg'); */
/* 			dd.elements.ds_image.swapImage('../' + the_subject + '/images_maps/' + imageSrc + 'ds_m.jpg'); */
/* 		} */
		if(include_raws){
			dd.elements.zonelist.show();
			infofield_onoff = 1;
		}
	}
}	

function change_largeimg(imagetoshow){
	if(imagetoshow == 'pa'){
		if(dd.elements.pa_image.visible){
			dd.elements.pa_image.hide();
			dd.elements.ds_image.hide();
		}
		else{
			dd.elements.pa_image.show();
			dd.elements.ds_image.hide();
		}
	}
	else if(imagetoshow == 'ds'){
		if(dd.elements.ds_image.visible){
			dd.elements.pa_image.hide();
			dd.elements.ds_image.hide();
		}
		else{
			dd.elements.ds_image.show();
			dd.elements.pa_image.hide();
		}
	}
}

function showarrow(whicharrow){
	if((hasmap) && (htmlType != 'radthorax_question')){
		document.images['realbild'].src = '../' + the_subject + '/images_r/' + imageSrc + '_' + whicharrow + '.jpg';
		//var thesrc = splitStringForLastItem(document.images['map1_image'].src,'/');
		//alert(dd.elements["map1_image"].visible)
		//document.images['bild'].src = '../' + the_subject + '/images_r/' + imageSrc + '_' + whicharrow + '.jpg';	
	}
	else{
		dd.elements.bild.swapImage('../' + the_subject + '/images_r/' + imageSrc + '_' + whicharrow + '.jpg');
		if(selftest) hidetestfields();
	}
}

function hidearrow(whicharrow){
	if(hasmap && (htmlType != 'radthorax_question')){
		document.images['realbild'].src = '../' + the_subject + '/images_m/' + imageSrc + '_m.jpg';
	}
	else{
		dd.elements.bild.swapImage('../' + the_subject + '/images_m/' + imageSrc + '_m.jpg');
	}
}

function showmeter(){
	if(dd.elements.meter_image.visible){
		dd.elements.meter_image.hide();
	}
	else{
		dd.elements.meter_image.show();
	}
}

function call_region(theSelectedIndex,this_file){
	var which_chapter = document.forms[0].select_chapter.options[theSelectedIndex].value;
	if(which_chapter == 0){
		document.forms[0].select_chapter.options.selectedIndex = 0;
	}
	else{
		var which_subsubject = subsubject_array[document.forms[0].select_chapter.selectedIndex-2];
		document.location.href = this_file + '?' + the_program + '|' + the_subject + '|' + which_subsubject + '|' + which_chapter + '|' + the_slide + '|chapter';
	}
}

function call_chapter(theSelectedIndex,this_file){
	var which_chapter = document.forms[0].select_chapter.options[theSelectedIndex].value;
	if(which_chapter == 0){
		document.forms[0].select_chapter.options.selectedIndex = 0;
	}
	else{
		var which_subsubject = subsubject_array[document.forms[0].select_chapter.selectedIndex-2];
		document.location.href = this_file + '?' + the_program + '|' + the_subject + '|' + which_subsubject + '|' + which_chapter + '|' + the_slide + '|chapter';
	}
}

function go_carpet(this_file){
	document.location.href = this_file + '?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide + '|chapter';
}

function find_slides_by_modality(which_modality){
	var found_images_array = '';
	for(i=1;i<page_elements.length;i++){
		elements_array = page_elements[i].split('|');
		if(elements_array[0].indexOf(which_modality) != -1){
			found_images_array += elements_array[5] + '%%' + elements_array[elements_array.length-3] + '%%' + elements_array[elements_array.length-2] + '%%' + elements_array[elements_array.length-1]+ '%%' + elements_array[1] + '??';
		}
	}
	return found_images_array;
}

function call_modality(theSelectedIndex,this_file){
	var which_modality = document.forms[0].select_modality.options[theSelectedIndex].value;
	if(which_modality == 0){
		document.forms[0].select_modality.options.selectedIndex = 0;
	}
	else{
		var found_images = find_slides_by_modality(which_modality)
		document.location.href = this_file + '?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide + '|modality|' + which_modality + '|' + found_images;
	}
}

function find_slides_by_praep(which_praep){
	var found_images_array = '';
	for(i=1;i<page_elements.length;i++){
		elements_array = page_elements[i].split('|');
		if(elements_array[9] == which_praep){
			found_images_array += elements_array[5] + '%%' + elements_array[elements_array.length-3] + '%%' + elements_array[elements_array.length-2] + '%%' + elements_array[elements_array.length-1] + '%%' + elements_array[1] + '%%' + which_praep + '??';
		}
	}
	return found_images_array;
}

function call_praep(theSelectedIndex,this_file){
	var which_praep = document.forms[0].select_praep.options[theSelectedIndex].value;
	if(which_praep == 0){
		document.forms[0].select_praep.options.selectedIndex = 0;
	}
	else{
		var found_images = find_slides_by_praep(which_praep)
		document.location.href = this_file + '?' + the_program + '|' + the_subject + '|' + the_subsubject + '|' + the_chapter + '|' + the_slide + '|praep|' + which_praep + '|' + found_images;
	}
}

function give_correct_answer(the_id, the_answer){
	if(document.forms[0].elements[the_id +'_text'].value == ''){
		alert(fillout_first);
		return;
	}
	var which_cell = document.getElementById(the_id);
	which_cell.innerHTML = the_answer;
}

function check_radios(form_name,el_name){
	var check_button = 0;
	for(i=0;i<document.forms[form_name].elements[el_name].length;i++){
		if(document.forms[form_name].elements[el_name][i].checked){
			check_button = 1;
		}
	}
	return check_button;
}

function show_the_comment(the_id, the_answer){
	var which_cell = document.getElementById(the_id);
	which_cell.innerHTML = the_answer;
}

function check_numOfChoices(sender){
	var correctChoices = document.hid_form.correctChoices.value; // list of correct items by number
	var numOfCorrects = correctChoices.split(',').length; // number of correct items
	var choicesNum = document.vis_form.length-1; // number of all items
	var numOfChoices = 0;
	for(i=1;i<=choicesNum;i++){
		if(document.vis_form.elements['action'+i].checked == 1){
			numOfChoices += 1;
			if(numOfChoices > numOfCorrects){
				document.vis_form.elements['action'+sender].checked = 0;
				alert('Sie haben schon ' + numOfCorrects + ' Option(en) ausgewählt.');
				return;
			}
		}
	}
	if((sender == 0) && (numOfChoices < numOfCorrects)){
		alert('Sie haben noch nicht ' + numOfCorrects + ' Option(en) ausgewählt.');
		return 0;
	}
}

function check_choices(variant){
	if(check_numOfChoices(0) != 0){;
		var correctChoices = document.hid_form.correctChoices.value.split(','); // list of correct items by number
		var numOfCorrects = correctChoices.length; // number of correct items
		var choicesNum = document.vis_form.length-1; // number of all items
		var numCorrectCocen = 0; // number of correctly chosen items
		for(i=1;i<=choicesNum;i++){
			if(isImportant(i,numOfCorrects,correctChoices) == 1){ // correct item
				var boxCell = document.getElementById('box'+i);
				if(document.vis_form.elements['action'+i].checked == 1){ // correctly chosen item
					boxCell.style.backgroundColor = "#BBFFBB";
				}
				else{
					boxCell.style.backgroundColor = "#EEFFEE"; // wrongly not chosen
				}
				if(variant != 'pure'){
					var which_cell = document.getElementById('result_' + i);
					which_cell.innerHTML = document.hid_form.elements['res_'+i].value;
				}
			}
			else if(isImportant(i,numOfCorrects,correctChoices) == 0){ // wrong item
				var boxCell = document.getElementById('box'+i);
				if(document.vis_form.elements['action'+i].checked == 1){ // wrongly chosen item
					boxCell.style.backgroundColor = "#FFBBBB";
				}
				else{
					boxCell.style.backgroundColor = "#FFEEEE";
				}
			};
			var which_cell = document.getElementById('feedback_' + i);
			which_cell.innerHTML = document.hid_form.elements['feed_'+i].value;
		}
	}
}

function isImportant(n,numOfCorrects,correctChoices){
	for(j=0;j<numOfCorrects;j++){
		if(correctChoices[j]==n) return 1;
	}
	return 0;
}

function menus_off(){
	if(document.forms[0].elements[arguments[1]].checked){
		for(i=2;i<arguments.length;i++){
			document.forms[0].elements[arguments[i]].options.selectedIndex = arguments[0];
		}
	}

}

function checkbox_off(which_cb){
	document.forms[0].elements[which_cb].checked = 0;
}

function save_form_input(){
	if((document.order_form) && (the_slide < 4)){
		setCookie('order1',document.order_form.correct_exam_text.value + '|' + document.order_form.correct_question_text.value + '|' + document.order_form.correct_clinic_text.value)
	}
	else if((document.order_form) && (the_slide > 3) && (the_slide < 7)){
		setCookie('order2',document.order_form.correct_exam_text.value + '|' + document.order_form.correct_question_text.value + '|' + document.order_form.correct_clinic_text.value)
	}
	else if((document.order_form) && (the_slide > 7)){
		setCookie('order3',document.order_form.correct_exam_text.value + '|' + document.order_form.correct_question_text.value + '|' + document.order_form.correct_clinic_text.value)
	}
	else if((document.findings_form) && (the_slide < 5)){
		setCookie('findings1',document.findings_form.technic.value + '|' + document.findings_form.extrathoracic.value + '|' + document.findings_form.skeleton.value + '|' + document.findings_form.diaphragm.value + '|' + document.findings_form.pleura.value + '|' + document.findings_form.lung.value + '|' + document.findings_form.hili.value + '|' + document.findings_form.heart.value + '|' + document.findings_form.summary.value)
	}
	else if((document.findings_form) && (the_slide > 4) && (the_slide < 8)){
		setCookie('findings2',document.findings_form.technic.value + '|' + document.findings_form.extrathoracic.value + '|' + document.findings_form.skeleton.value + '|' + document.findings_form.diaphragm.value + '|' + document.findings_form.pleura.value + '|' + document.findings_form.lung.value + '|' + document.findings_form.hili.value + '|' + document.findings_form.heart.value + '|' + document.findings_form.summary.value)
	}
	else if((document.findings_form) && (the_slide > 8)){
		setCookie('findings3',document.findings_form.technic.value + '|' + document.findings_form.extrathoracic.value + '|' + document.findings_form.skeleton.value + '|' + document.findings_form.diaphragm.value + '|' + document.findings_form.pleura.value + '|' + document.findings_form.lung.value + '|' + document.findings_form.hili.value + '|' + document.findings_form.heart.value + '|' + document.findings_form.summary.value)
	}
}

function restore_form_input(){
	if(the_chapter != getCookie('case_num')){
		clear_case_cookies()
		setCookie('case_num', the_chapter, 1)
	}
	if(getCookie('casePage') == page_elements.length-1){
		var case_number = the_chapter.substr(4,the_chapter.length-4)
		var case_numbers = getCookie('cases_done');
		if(case_numbers.indexOf('-' + case_number + '-') < 0) setCookie('cases_done', case_numbers + '-' + case_number + '-')
	}
	if((document.order_form) && (the_slide < 4)){
		input_array = getCookie('order1').split('|');
		document.order_form.correct_exam_text.value = input_array[0];
		document.order_form.correct_question_text.value = input_array[1];
		document.order_form.correct_clinic_text.value = input_array[2];
	}
	else if((document.order_form) && (the_slide > 3) && (the_slide < 7)){
		input_array = getCookie('order2').split('|');
		document.order_form.correct_exam_text.value = input_array[0];
		document.order_form.correct_question_text.value = input_array[1];
		document.order_form.correct_clinic_text.value = input_array[2];
	}
	else if((document.order_form) && (the_slide > 7)){
		input_array = getCookie('order3').split('|');
		document.order_form.correct_exam_text.value = input_array[0];
		document.order_form.correct_question_text.value = input_array[1];
		document.order_form.correct_clinic_text.value = input_array[2];
	}
	else if((document.findings_form) && (the_slide < 5)){
		input_array = getCookie('findings1').split('|');
		document.findings_form.technic.value = input_array[0];
		document.findings_form.extrathoracic.value = input_array[1];
		document.findings_form.skeleton.value = input_array[2];
		document.findings_form.diaphragm.value = input_array[3];
		document.findings_form.pleura.value = input_array[4];
		document.findings_form.lung.value = input_array[5];
		document.findings_form.hili.value = input_array[6];
		document.findings_form.heart.value = input_array[7];
		document.findings_form.summary.value = input_array[8];
	}
	else if((document.findings_form) && (the_slide > 4) && (the_slide < 8)){
		input_array = getCookie('findings2').split('|');
		document.findings_form.extrathoracic.value = input_array[1];
		document.findings_form.skeleton.value = input_array[2];
		document.findings_form.diaphragm.value = input_array[3];
		document.findings_form.pleura.value = input_array[4];
		document.findings_form.lung.value = input_array[5];
		document.findings_form.hili.value = input_array[6];
		document.findings_form.heart.value = input_array[7];
		document.findings_form.summary.value = input_array[8];
	}
	else if((document.findings_form) && (the_slide > 8)){
		input_array = getCookie('findings3').split('|');
		document.findings_form.extrathoracic.value = input_array[1];
		document.findings_form.skeleton.value = input_array[2];
		document.findings_form.diaphragm.value = input_array[3];
		document.findings_form.pleura.value = input_array[4];
		document.findings_form.lung.value = input_array[5];
		document.findings_form.hili.value = input_array[6];
		document.findings_form.heart.value = input_array[7];
		document.findings_form.summary.value = input_array[8];
	}
}

function clear_case_cookies(){
	setCookie('case_num', ' ');
	setCookie('casePage',1)
	setCookie('indication',' ');
	setCookie('order1','||');
	setCookie('order2','||');
	setCookie('order3','||');
	setCookie('findings1','||||||||');	
	setCookie('findings2','||||||||');	
	setCookie('findings3','||||||||');	
}

function clear_cases_done(){
	setCookie('cases_done', '',10000);
	document.location.reload();
}

function change_comment(){
	if(showcomment == 1){
		setCookie('comment_onoff',0);
		document.location.reload();
	}
	else{
		setCookie('comment_onoff',1);
		document.location.reload();
	}
}

function showSolution(numOfFields){
	var filled_out = 0;
	for(i=0;i<document.findings.elements.length;i++){
		if(document.findings.elements[i].value != '') filled_out = filled_out + 1;
	}
	if(filled_out == 0) alert('Legen Sie sich zuerst fest!');
	else if(filled_out < numOfFields) alert('Beziehen Sie zu allen Punkten Stellung!');
	else{
		var solution =  document.getElementById('solution');
		solution.style.visibility = 'visible';
	}
}

