Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
 



function htmlspecialchars(html, enter) {
	if (html != null) {
		html = html.replace(/</g, '&lt;');
		html = html.replace(/>/g, '&gt;');
		if (enter) {
			html = html.replace(new RegExp("\\n", "g"), "<br>");
		}
	} else {
		html = '';
	}
  return html;
}

function sortNumber(a, b)
{
return a - b;
}

Array.prototype.myconcat = function(arr) {
	var output_arr = new Array();
	arr = arr.concat(this);
	arr = arr.sort(sortNumber);
	for(var i = 0, l = arr.length; i < l; i++) {
		if (i == 0 || arr[i] != arr[i-1]) {
			output_arr.push(arr[i]);
		}
	}
	
	return output_arr;
}

function jsarray2sqlarry(arr) {
	var output = '{';
	for (var i = 0; i < arr.length; i++) {
		if (i > 0) {output += ',';}
		output += arr[i];
	}
	output += '}';
	return output;
}

function escape_double_qoute(text) {
	if (text != null) {
		text = text.replace(new RegExp( '"', "g" ), "&quot;");
	} else {
		text = '';
	}
  
  return text;
}

function calcTime(sdate, offset) {

    // create Date object for current location
    d = new Date(sdate);
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (offset * 60000);
   
    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));
   
    // return time as a string
    return  nd.toLocaleString();
	//return  utc.toLocaleString();

}

function logBook () {
	var self = this;
	this.data = null;
	this.message = null;
	this.content;
	this.openform = null;
	this.label_colors = 		['FFCCFF','CCFFFF','9999FF','99FF00','9966CC','9966FF', 'Lightcoral', 'Moccasin', '	Palegreen', 'Rosybrown', 'Mistyrose', 'FFCCFF','CCFFFF','9999FF','99FF00','9966CC','9966FF', 'Lightcoral', 'Moccasin', 'Palegreen', 'Rosybrown', 'Mistyrose', 'FFCCFF','CCFFFF','9999FF','99FF00','9966CC','9966FF', 'Lightcoral', 'Moccasin', 'Palegreen', 'Rosybrown', 'Mistyrose'];
		
	
	this.files = new Array();

	this.login = function () {
		html  = '<br><div style="margin-right: 10px; margin-left: 10px;">';
		html += '<form method="post" action="index.php?page=home&session_id='+this.data[0][3]+'">';
		html += '<table>';
		if (this.data[0][1] == 'login') {
			html += '<tr><td colspan="2">'+ this.data[0][2] +'<br><br></td></tr>';
			html += '<tr><td>'+ this.message['user_name'] +'</td><td><input type="text" name="user_name" style="width: 130px;"></td></tr>';
			html += '<tr><td>'+ this.message['password'] +'</td><td><input type="password" name="password" style="width: 130px;"></td></tr>';
			html += '<tr><td colspan="2"><input name="remember_me" value="true" type="checkbox">'+ this.message['remember_me'] +'</td></tr>';
			html += '<tr><td colspan="2"><input type="hidden" value="login" name="action"><input type="submit" value="'+this.message['sign_in']+'"><input onclick="my_logBook.forgot_password()" type="button" id="new_password" value="'+ this.message['forgot_password'] +'"></td></tr>';
		} else if (this.data[0][1] == 'forgot_password') {
			html += '<tr><td colspan="2">'+ this.data[0][2] +'<br></td></tr>';
			html += '<tr><td>'+ this.message['email_address'] +'</td><td><input type="text" name="email_address"></td></tr>';
			html += '<tr><td colspan="2"><input type="hidden" value="forgot_password" name="action"><input type="submit" value="'+this.message['send_email']+'"></td></tr>';
		}else {
			html += '<tr><td colspan="2">'+ this.message[this.data[0][2]] +'<br></td></tr>';
		}
		
		html += '</table>';
		html += '</form>';		
		html += '</div><br>';
		this.content.innerHTML = html;		
		



	}
	
	this.forgot_password = function () {
		var self = this;
		this.data[0][1] = 'forgot_password';
		this.data[0][2] = this.message['explanation_new_passord'];
		self.login();
	}
	
	this.start = function () {
		
		var self = this;
		this.content = document.getElementById('content');
		if (this.data[0][0] == false) {
			self.login();
		} else {
			
			//change menu
			var html = '<div class="top" id="navtop">';
			var menu = ["home", "user_profile", "logout"];
			
			if (this.data[0][5] == 'projectmanager') {menu.push('admin');}
			for (var i = 0; i < menu.length; i++) {
					html += '<a href="index.php?page='+menu[i]+'&session_id='+this.data[0][3]+'">'+this.message['menu_' + menu[i]]+'</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logged in: ' + this.data[0][7] +' (' +this.data[0][5] + ')';
			html += '</div>';
			
			document.getElementById('menu').innerHTML = html;
			

				this.content.innerHTML = 'loading...';
				switch(this.data[1][0]) {
					case 'home': 
						self.projects();
						break;
						
					case 'problems': 
						self.problems();
						break;		
						
					case 'help': 
						this.content.innerHTML = this.message['menu_help'];
						break;	
						
					case 'topics': 
						self.topics();
						break;							
	
					case 'user_profile': 
						self.profile();
						break;	
						
					case 'admin': 
						self.admin();
						break;	
	
					case 'logout':
						this.content.innerHTML = '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.message['bye'] + '<br><br>';
						document.getElementById('menu').innerHTML = '<div class="top" id="navtop"><a href="index.php">' + this.message['menu_home'] + '</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="login_help.html">' + this.message['menu_help'] + '</a></div>';
						break;	
									
					case 'report': 
						self.report();
						break;							
	
					case 'old_report': 
						self.old_report();
						break;		
	
				}
				
				//show errors
				if (this.data[1][1][0]) {
					var error_message = this.data[1][1][1];
					if (error_message.indexOf("\n") > 0) {
						error_message = error_message.slice(0,error_message.indexOf("\n")); 	//alles na enter verwijderen.
					}
					alert(error_message);
				}
		}
	}
	
	this.profile = function() {
		var profile_data =  this.data[1][2];
		
		var html = '';
		html += '<form method="post" action="index.php?page=home&session_id='+this.data[0][3]+'">';
		html += '<input type="hidden" name="action" value="edit_profile">';
		html += '<input type="hidden" name="user_name" value="'+profile_data[1] +'">';
		html += '<table>'

			html += '<tr><td>old password:</td><td><input type="password" name="old_password"></td><tr>';
			html += '<tr><td>new password:</td><td><input type="password" name="new_password1"></td><tr>';
			html += '<tr><td>new password:</td><td><input type="password" name="new_password2"></td><tr>';
			html += '<tr><td></td><td><input type="submit" name="new_password" value="Save"></td><tr>';
		html += '</table>'
		this.content.innerHTML = html;
	}
	
	this.topics = function() {
		var functie = 			this.data[0][5];

		var ingelogd = 			this.data[0][7];
		
		var total_topics = 		this.data[1][2][0][0];
		var project = 			this.data[1][2][0][1];
		var offset = 			this.data[1][2][0][2];
		var project_name = 		this.data[1][2][0][3];
		var limit = 			this.data[1][2][0][4];
		var request_time = 		this.data[1][2][0][5];
		var list_title = 		this.data[1][2][0][6];
		
		var order_by = 			this.data[1][2][0][7];
		var closed = 			this.data[1][2][0][8];
		var unanswered = 		this.data[1][2][0][9];
		var self_started =		this.data[1][2][0][10];
		var extern = 			this.data[1][2][0][11];
		var extern_reageren = 	this.data[1][2][0][12];
		var project_members = 	this.data[1][2][0][13];
		var order_direction = 	this.data[1][2][0][14];
		var all_reports = 		this.data[1][2][0][15];
		var filtered_report = 	this.data[1][2][0][16];
		var unread_filter = 	this.data[1][2][0][17];
		var frontpage_img = 	this.data[1][2][0][18];
		var prioriteit_filter = this.data[1][2][0][19];
		var architect = 		((this.data[1][2][0][20] == null) ? '' : this.data[1][2][0][20]);
		var opdrachtgever = 	((this.data[1][2][0][21] == null) ? '' : this.data[1][2][0][21]);
		var constructeur = 		((this.data[1][2][0][22] == null) ? '' : this.data[1][2][0][22]);;
		var installatieadviseur = 		((this.data[1][2][0][23] == null) ? '' : this.data[1][2][0][23]);
		var overigen =	 		((this.data[1][2][0][24] == null) ? '' : this.data[1][2][0][24]);
		var filter_label_action=this.data[1][2][0][25];
		
		
		//kleuren van de labels 
		var label_colors = 		this.label_colors
	
		var topic_length = this.data[1][2][1].length;
		
		
		
		
		
		
		var action_url_without_offset = 'index.php?page=topics&project='+ escape(project)+ '&order_by='+escape(order_by) + '&direction=' + order_direction;
		if (extern == true) {action_url_without_offset += '&extern=true';} else if (extern == false) {action_url_without_offset += '&extern=false';}
		if (self_started == true) {action_url_without_offset += '&own_topic_only=true';}
		if (closed == true) {action_url_without_offset += '&show_close=true';} else if (closed == false) {action_url_without_offset += '&show_close=false';}
		if (unanswered == true) {action_url_without_offset += '&not_own_post_as_last=true';}
		if (filter_label_action != null) {action_url_without_offset += '&label_filter_action=' + filter_label_action;}
		

		for (var o = 0; o < all_reports.length; o++) {
			action_url_without_offset += '&label_index_'+o+'=' + all_reports[o][0];
			if (filtered_report.in_array(all_reports[o][0])) {
				action_url_without_offset += '&label_check_'+o+'=true';
			} 
		}
	
		
		
		if (unread_filter) {action_url_without_offset += '&unread=true';}
		if (prioriteit_filter != null) {action_url_without_offset += '&prioriteit=' + prioriteit_filter;}
		action_url_without_offset += '&session_id=' + this.data[0][3];
		
		var action_url = action_url_without_offset + '&offset='+ offset;
		
		
		

		//--------------------------------------------------------------------------------------------------------------------------------
		//title bar
		//--------------------------------------------------------------------------------------------------------------------------------
		var output = '';
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 40px;">';
			output += '<table cellspacing="0" border="0" cellpadding="0">';
				output += '<tr>';
					if (list_title != '' && list_title != null ) {
						list_title_text = 'filtered: ' + list_title;
					} else {
						list_title_text = '';
					}
						
					output += '<td><div style=" overflow: hidden; color: white; padding: 8px 5px 5px 10px; height: 39px; width: 360px;"><span style="font-size: 14px;"><b> '+ project_name  + '</b></span><br> ' + list_title_text + '</div></td>';
					output += '<td><div style=" color: white; text-align: right; padding: 8px 5px 5px 10px; width: 380px;">';
						if ((functie == 'projectmanager') || (functie == 'modeller') || (functie == 'extern' && extern_reageren == 'topics starten') ) {
							output += '<span style="cursor: pointer;" onclick="my_logBook.openTopic(true)" >New Topic</span> | ';
						}
						output += '<a onclick="my_logBook.openEditList(true)" style="cursor: pointer;">Filter</a> | ';
						output += '<a href="'+action_url+'" style="text-decoration: none; color: white;">Refresh</a> | ';
						output += '<span id="expand_all_div_id"><span onclick="my_logBook.expand_all(true);" style="cursor: pointer;">Expand All</span></span>';
						output += ' | <span id="print_div_id"><span onclick="my_logBook.openPrint(true);" style="cursor: pointer;">Print</span></span>';
						if (functie == 'projectmanager') {
							output += ' | <span id="report_div_id"><span onclick="my_logBook.goto_report();" style="cursor: pointer;">Labels</span></span>';
							



						}
					output += '</div></td>';
				output += '</tr>';
			output += '</table>';
		output += '</div>';		
		
		
		
		

		
		

		
		
		





		//--------------------------------------------------------------------------------------------------------------------------------
		//print	topics
		//--------------------------------------------------------------------------------------------------------------------------------
			if (closed == true) {var qclosed = 'true'} else if (closed == false) {var qclosed = 'false';} else {var qclosed = '';}
			if (extern == true) {var qextern = 'true'} else if (extern == false) {var qextern = 'false';} else {var qextern = '';}
			if (unanswered == true) {var qunanswered = 'true'}	else {var qunanswered = '';}
			if (self_started == true) {var qself_started = 'true'}	else {var qself_started = '';}
			if (filter_label_action != null) {q_filtered_report = filter_label_action;} else {q_filtered_report = '';}
			if (unread_filter) {qunread = '&unread=true';} else {qunread = '';}		
			if (prioriteit_filter != null) {q_prioriteit_filter = prioriteit_filter} else {q_prioriteit_filter = '';}	
			
			
			
			
			
							
						
		output += '<div id="print" style="display: none;">';
			output += '<form method="get" action="print.php" target="_blank">';
			output += '<input type="hidden" value="new_topic" name="action"> ';	
			output += '<input type="hidden" value="'+project+'" name="project"> ';
			output += '<input type="hidden" value="'+q_filtered_report+'" name="filter_label_action"> ';
			
			
			for (var o = 0; o < all_reports.length; o++) {
				//action_url_without_offset += '&label_index_'+o+'=' + all_reports[o][0];
				output += '<input type="hidden" value="'+all_reports[o][0]+'" name="label_index_'+o+'"> ';	
				if (filtered_report.in_array(all_reports[o][0])) {
					//action_url_without_offset += '&label_check_'+o+'=true';
					output += '<input type="hidden" value="true" name="label_check_'+o+'">';	
				} 
			}			
			
			
			
			
			output += '<input type="hidden" value="'+qunread+'" name="unread"> ';
			output += '<input type="hidden" value="'+order_by+'" name="order_by"> ';
			output += '<input type="hidden" value="'+order_direction+'" name="direction"> ';
			
			output += '<input type="hidden" value="'+this.data[0][3]+'" name="session_id">';
			output += '<input type="hidden" value="'+qclosed+'" name="show_close"> ';
			output += '<input type="hidden" value="'+qextern+'" name="extern"> ';
			output += '<input type="hidden" value="'+qunanswered+'" name="not_own_post_as_last"> ';
			output += '<input type="hidden" value="'+qself_started+'" name="own_topics_only"> ';
			output += '<input type="hidden" value="'+q_prioriteit_filter+'" name="prioriteit"> ';
			output += '<input type="hidden" name="print"> ';
			
			output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';			
			output += '<div style="padding: 20px 40px 0px 40px;">';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >'+frontpage_img;
					output += '<table cellspacing="0" border="0" cellpadding="0" >';
						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>Print topics</b></div></td>';
						output += '</tr>';
				
						output += '<tr>';
							
							output += '<td>Project onderdeel&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>';
							output += '<td><input name="projectpart" value="" style="width: 300px"> </td>';
							output += '<br><br><br>';
						output += '</tr>';
						
					
						output += '<tr>';
						output += '<td valign="top">Rapport&nbsp;:</td>';
						output += '<td><input name="rapport_nummer" value="" style="width: 300px"></td>';
						output += '</tr>';
					
						
						var d = new Date();
						var curr_date = d.getDate();
						var curr_month = d.getMonth() + 1;
						var curr_year = d.getFullYear();
						output += '<tr>';
							output += '<td valign="top">Datum&nbsp;:</td>';
//							output += '<td><input name="datum" value="'+Date()+'" style="width: 300px"><br><br></td>';
							output += '<td><input name="datum" value="'+curr_date+'-'+curr_month+'-'+curr_year+'" style="width: 300px"><br><br></td>';
						output += '</tr>';
						
						output += '<tr>';
							output += '<td valign="top">Onderwerp&nbsp;:</td>';
							output += '<td><input name="onderwerp" value="" style="width: 300px"></td>';
						output += '</tr>';												
	
						output += '<tr>';
							output += '<td valign="top">Selectie&nbsp;:</td>';
							output += '<td><input name="selectie" value="'+ list_title +'" style="width: 300px"></td>';
						output += '</tr>';	
						
						output += '<tr>';
							output += '<td>Vrije ruimte&nbsp;:<br></td><td><textarea style="width: 300px" rows="3" name="vrije_ruimte"></textarea></td>';
						output += '</tr>';						
	
					if (frontpage_img != '' && frontpage_img != null) {
						
						output += '<tr>';
							output += '<td valign="top">Voorpagina afb&nbsp;:</td>';
							output += '<td><img width="300px" src="http://bouwconnector.mediadesign.nl/logbook/file.php?action=front_image&project='+ project +'&name='+ frontpage_img +'"><br><input checked type="checkbox" value="'+ frontpage_img +'" name="afbeelding"> show image</td>';
						output += '</tr>';		
					}
						output += '<tr>';
							output += '<td>Opdrachtgever: </td>';
							output += '<td colspan="2"><input name="opdrachtgever" value="'+opdrachtgever+'" style=" width: 300px;"></td>';
						output += '</tr>';		
	
						output += '<tr>';
							output += '<td>Architect: </td>';
							output += '<td colspan="2"><input name="architect" value="'+architect+'" style=" width: 300px;"></td>';
						output += '</tr>';	
						
						output += '<tr>';
							output += '<td>Constructeur: </td>';
							output += '<td colspan="2"><input name="constructeur" value="'+constructeur+'" style=" width: 300px;"></td>';
						output += '</tr>';	

						output += '<tr>';
							output += '<td>Installatieadviseur: </td>';
							output += '<td colspan="2"><input name="installatieadviseur" value="'+installatieadviseur+'" style=" width: 300px;"></td>';
						output += '</tr>';	

						output += '<tr>';
							output += '<td>Overige partijen: </td>';
							output += '<td colspan="2"><input name="overigen" value="'+overigen+'" style=" width: 300px;"></td>';
						output += '</tr>';	

						output += '<tr>';
							output += '<td height="35px" >Naam en tijdstip:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							output += '<td><input type="checkbox" value="true" name="show_name_and_time"> selecteer dit vakje als je wilt dat namen en tijdstippen vermeld worden in het rapport.</td>';
						output += '</tr>';		
		
//						output += '<tr>';
//							output += '<td height="35px" >paper:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
//							output += '<td colspan="2"><select><option>A4 format</option></select></td>';
//						output += '</tr>';		
						
						
											
						output += '<tr>';
							output += '<td colspan="3"><input type="submit" value="Create PDF"><input type="reset" value="Cancel" onclick="my_logBook.openPrint(false)"> use the "filter" option in the menu to make a selection.</td>';
						output += '</tr>';
																
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
			output += '</div>';
			output += '<input type="hidden" value=".pdf" name="extensie">';
			output += '</form>';
		output += '</div>';	
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';



			
		//--------------------------------------------------------------------------------------------------------------------------------
		//new topic
		//--------------------------------------------------------------------------------------------------------------------------------
		var input_extern = '';
		var input_intern = 'checked'; 
		var title_name = 'title_eng';
		var textarea_name = 'text_eng'

		if (functie == 'extern') {
				title_name = 'title_dut';
				textarea_name = 'text_dut'	
		}	
		
 
		if (this.data[1][1][0] && this.data[1][1][2][0] == 'new_topic') {
			//previous failed request;
			var display = 'block';
			this.openform = 'New topic';
			var title_value = this.data[1][1][2][3];
			var textarea_value = this.data[1][1][2][4];
			if (this.data[1][1][2][5] == 'true') {input_extern = 'checked'; input_intern = '';} 
			
		} else {
			var display = 'none';
			var title_value = '';
			var textarea_value ='';
		}			
		output += '<div id="newtopic" style="display: '+display+';">';
			output += '<form method="post" name="new_topic_form" action="'+action_url+'" enctype="multipart/form-data">';
			output += '<input type="hidden" value="new_topic" name="action"> ';	
			output += '<input type="hidden" value="'+project+'" name="project"> ';
			output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';			
			output += '<div style="padding: 20px 40px 0px 40px;">';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_new_topic" cellspacing="0" border="0" cellpadding="0" >';
						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>New Topic</b></div></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>title:</td>';
							output += '<td colspan="2"><input id="new_topic_title" name="'+title_name+'" type="text" value="'+escape_double_qoute(title_value)+'" style="width: 570px"></td>';
						output += '</tr>';					
						output += '<tr>';
							output += '<td>text:</td>';
							output += '<td colspan="2"><textarea  rows="5" id="new_topic_text_r" name="'+textarea_name+'" style="width: 570px">'+htmlspecialchars(textarea_value, false)+'</textarea></td>';
						output += '</tr>';
						
						
						output += '<tr>';
							output += '<td>image*:</td>';
							output += '<td colspan="2">';
								
								output += '<input id="new_topic_file_0" onchange="my_logBook.add_file_new_topic()" name="file_0" type="file" style="width: 260px">';
								output += ' description: <input title="new file name" name="file_0_name" type="text" style="width: 240px">';
							
							output += '</td>';
						output += '</tr>';
						this.files[0] = 0;
						
						
						if (functie != 'extern')	{
						output += '<tr><td colspan="3"><table><tr>';
						var num_rows_reports = Math.ceil(all_reports.length/3)  ;
					 	for (var q = 0; q < 3; q++ ) {
							
							output += '<td valign="top">';
								output += '<div style=" overflow: hidden; width: 218px;"> ';
									output += '<table cellspacing="0" border="0" cellpadding="0">';

										if ((q == 0) || (q==1 && all_reports.length > 1 ) || (q==3 && num_rows_reports * 3 - all_reports.length == 0 ) ) {
											var loop = num_rows_reports;
										} else {
											if (q == 1)  {
												var loop = 0;
											} else {
												var loop = num_rows_reports - (num_rows_reports * 3 - all_reports.length );
											}
										}  

									for (var p = 0; p < loop; p++) {
										z = q * num_rows_reports + p;
										output += '<tr>';
											output += '<td>';	
												output += '<input type="hidden" name="label_id_'+ z +'" value="'+all_reports[z][0]+'">';										
												output += '<input type="checkbox" value="true" name="label_check_'+ z +'"> ';
											output += '</td>';
											output += '<td>';
												output += all_reports[z][0] + ' ' + all_reports[z][1];
											output += '</td>';
										output += '</tr>';
										
									}
									output += '</table>';
								output += '</div>';
							output += '</td>';
						}
						output += '</tr></table></td></tr>';
						}
						
						
						if (functie == 'projectmanager') {
							output += '<tr>';
								output += '<td>priority:</td>';
								output += '<td><div style="padding: 3px 2px 2px 2px; width:  100px; height: 20px; overflow: hidden;">';
									output += '<input checked type="radio" name="priority" value="normal"> normal';
								output += '</div></td>';
								output += '<td><div style="padding: 3px 2px 2px 2px; width:  500px; height: 20px; overflow: hidden;">';
									output += '<input type="radio" name="priority" value="high"> high';
								output += '</div></td>';				
							output += '</tr>';							
							output += '<tr>';
								output += '<td>publish:</td>';
								output += '<td><div style="padding: 3px 2px 2px 2px; width:  100px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_new_topic(true)" '+input_intern+' name="extern" value="false" type="radio">intern</div></td>';
								output += '<td><div style="padding: 3px 2px 2px 2px; width:  500px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_new_topic(false)"'+input_extern+' name="extern" value="true" type="radio">extern</div></td>';
							output += '</tr>';
						} else if (functie == 'extern') {
							output += '<tr><input type="hidden" name="priority" value="normal"><input type="hidden" name="extern" value="true"></tr>';
						} else {
							output += '<tr><input type="hidden" name="priority" value="normal"><input type="hidden" name="extern" value="false"></tr>';
						}
						

			
						
											
						output += '<tr>';
							output += '<td colspan="3"><input type="submit" value="Save"><input type="reset" value="Cancel" onclick="my_logBook.openTopic(false)">&nbsp; &nbsp; &nbsp; * Supported formats: jpeg, png, bmp and gif</td>';
						output += '</tr>';										
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
			output += '</div>';
			output += '</form>';
		output += '</div>';	
		

		//output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';
		
		
		
		//--------------------------------------------------------------------------------------------------------------------------------
		//filter
		//--------------------------------------------------------------------------------------------------------------------------------		
		output += '<div id="filter" style="display: none;">';
		output += '<form method="get" action="index.php">';
		output += '<input type="hidden" value="topics" name="page">';	
			output += '<input type="hidden" value="'+this.data[0][3]+'" name="session_id">';	
			output += '<input type="hidden" value="'+offset+'" name="offset">';	
			output += '<input type="hidden" value="topics" name="page">';	
			output += '<input type="hidden" value="'+project+'" name="project">';			
			output += '<div style="padding: 20px 40px 0px 40px;">';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_new_topic" cellspacing="0" border="0" cellpadding="0" >';
						output += '<tr>';
							output += '<td colspan="2"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>Edit topic list</b></div></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>Filter: </td>';
							output += '<td>';
								output += '<input name="show_close" value="true" type="radio"' + ((closed == true) ? ' CHECKED' : '') + '> closed ';
								output += '<input name="show_close" value="false" type="radio"' + ((closed == false) ? ' CHECKED' : '') + '> open ';
								output += '<input name="show_close" value="" type="radio"' + ((closed == null) ? ' CHECKED' : '') + '> both ';
							output += '</td>';
						output += '</tr>';
							
						if (functie != 'extern') {
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
									
									output += '<input name="extern" value="true" type="radio"' + ((extern == true) ? ' CHECKED' : '') + '> extern ';
									output += '<input name="extern" value="false" type="radio"' + ((extern == false) ? ' CHECKED' : '') + '> intern ';
									output += '<input name="extern" value="" type="radio"' + ((extern == null) ? ' CHECKED' : '') + '> both ';
								output += '</td>';
							output += '</tr>';
						}	
						
						if ((functie == 'projectmanager') || (functie == 'modeller') || (functie == 'extern' && extern_reageren == 'topics starten') )  {
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
									output += '<input name="own_topics_only" value="true" type="checkbox"' + ((self_started == true) ? " CHECKED" : "") + '>Hide if I did not start topic';
								output += '</td>';						
							output += '</tr>';
						}						



						if (functie == 'extern' && extern_reageren == 'niet') {
							//niks
						}
						else {
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
										output += '<input name="not_own_post_as_last" value="true" type="checkbox"' + ((unanswered) ? " CHECKED" : "") + '>Hide if last comment from me';
								output += '</td>';
							output += '</tr>';
						}
						
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
									output += '<input name="unread" value="true" type="checkbox"' + ((unread_filter) ? " CHECKED" : "") + '>Hide topics already opened, except topics with new comments';
								output += '</td>';
							output += '</tr>';
						
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
								
									output += 'Priority: <select name="prioriteit">';
										output += '<option value="">all</option>'
										output += '<option value="normal" '+((prioriteit_filter == 'normal') ? " selected " : "")+'>normal</option>';
										output += '<option value="high"'+((prioriteit_filter == 'high') ? " selected " : "")+'>high</option>'
									output += '</select>'
								output += '</td>';
							output += '</tr>';							
							

						//if (functie == 'projectmanager') {
							output += '<tr>';
								output += '<td></td>';
								output += '<td>';
										output += 'Show topics having <input '+((filter_label_action == 'ALL IN') ? ' CHECKED' : '')+' name="label_filter_action" type="radio" value="ALL IN"> all selected labels (AND)';
										output += '<input '+((filter_label_action == 'ANY IN') ? ' CHECKED' : '')+' name="label_filter_action" type="radio" value="ANY IN"> at least one of the selected labels (OR).';
										output += '<input '+((filter_label_action == null) ? ' CHECKED' : '')+' name="label_filter_action" type="radio" value=""> Label filter off ';
										
								
									
									output += '<div style="height: 80px; width: 200px; padding: 5px; overflow: auto; border: 1px solid grey; bgcolor: red;">';
											for (var o = 0; o < all_reports.length; o++) {
												
												if (filtered_report.in_array(all_reports[o][0])) {checked = 'checked';} else {checked = '';}
												
												output += '<input type="hidden" name="label_index_' + o + '" value="'+all_reports[o][0]+'">';
												output += '<input type="checkbox" name="label_check_'+ o +'" value="true" '+checked+'>';
												if (functie == 'extern') {
													output += all_reports[o][6] + ' <br>'
												} else {
													output += all_reports[o][1] + ' <br>'
												}
											}
											
									output += '</div>'		

								output += '</td>';						
							output += '</tr>';
												

						output += '<tr>';
							output += '<td nowrap>Order by: </td>';
							output += '<td>';
								output += '<select name="order_by">';
									output += '<option value="topic_number"' + ((order_by == 'topic_number') ? ' SELECTED' : '') + '>Topic ID</option>';
									output += '<option value="last_post_poster"' + ((order_by == 'last_post_poster') ? ' SELECTED' : '') + '>Last poster</option>';
									output += '<option value="last_post_time"' + ((order_by == 'last_post_time') ? ' SELECTED' : '') + '>Last post date </option>';
									output += '<option value="topic_poster_name"' + ((order_by == 'topic_poster_name') ? ' SELECTED' : '') + '>Topic Starter</option>';
								output += '</select> ';
								if (order_direction == 'ASC') {
									output += '<input checked name="direction" value="ASC" type="radio"> ascending'; 
									output += '<input name="direction" value="DESC" type="radio"> descending';
								} else {
									output += '<input name="direction" value="ASC" type="radio"> ascending';
									output += '<input checked name="direction" value="DESC" type="radio"> descending';			
								}					
							output += '</td>';						
						output += '</tr>';
						
						output += '<tr>';
							output += '<td colspan="2"><input type="submit" value="Filter"> <input type="button" value="Cancel" onclick="my_logBook.openEditList(false)"></td>';
						output += '</tr>';	
															
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
			output += '</div>';
			output += '</form>';
		output += '</div>';	
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';
		if (topic_length == 0) {
			output += '<br>&nbsp;&nbsp;&nbsp;No topics<br><br>';
			
		}

		for (var i = 0; i < topic_length; i++) {
			var topic = this.data[1][2][1][i];
			
			var topic_number = topic[0];
			
			var topic_title_eng = topic[1];
			var topic_title_dut = topic[2];
			var extern = topic[3];
			var accomplished = topic[4];
			var accomplished_by = topic[5];
			var extern_in_past = topic[6];
			var num_post = topic[7];
			var posts = topic[8];
			var priority = topic[9];
			var reports = topic[10];
			var unread = topic[11];
		
			//bijhorende label namen bij label nummer zoeken.
			var reports_string = '';
			var reports_string_length = 0;
			for (var u = 0; u < reports.length; u++) {
				for (var b = 0; b < all_reports.length; b++) {
					if (all_reports[b][0] == reports[u]) {
						
						var string;
						if ((this.data[1][2][0][11] == true) || (functie == 'extern')) {
							// filter = extern || functie = extern
							string = all_reports[b][6];
						} else {
							string = all_reports[b][1];
						}
						if (string == null) {
							string = '';
						}
						var characters = 10;
		
						//characters = Math.abs(characters - string.length)
						
						if ( string.length > characters ) {
							 string = string.slice(0,characters);
						} 
						
						reports_string_length += string.length + 1;
						
						reports_string += '<span title="label: '+all_reports[b][1]+'" style="background-color: '+ label_colors[b] +'">' + string + '</span> ';
						// hier zo nog break() kunnen staan weet alleen niet of javascript dat ondersteunt
					}
				}
			}
			
			var last_post = posts[posts.length - 1];
			var last_post_id = last_post[0];
			var last_post_eng = last_post[1];
			var last_post_dut = last_post[2];
			var last_poster_name = last_post[4];
			
		
			var last_post_time = new Date (last_post[5])
			
			
			var last_post_own_post = last_post[8];
			
			



			if (extern) {
				if (functie == 'modeller' && (topic_title_eng != null && topic_title_eng != ''  )) {
					var topic_title = topic_title_eng;
					var last_post_text = last_post_eng;
				} else {
					var topic_title = topic_title_dut;
					var last_post_text = last_post_dut;
				}
				
				
			} else {
				var last_post_text = last_post_eng;
				var topic_title = topic_title_eng
			}
			
			if (last_post_text == null) {
				last_post_text = '';
			}
			

			var input_extern = '';
			var input_intern = 'checked';  
			var textarea_value ='';
			

			var collapsed_display = 'block';
			var expanded_display = 'none';			
			var display_comment = 'none';
			var display_edit_comment = 'none';
			var display_topics = 'block';	
			var extern_display = 'none';		
			var display_edit_last_post = 'none'
			
			
			
			//automatisch topic openen na wijzigen of nieuw topic
			if (this.data[1][2][2][0] && (this.data[1][2][2][1] == 'last'  || this.data[1][2][2][1] == topic_number ) ) {
						display_comment = 'none';
						display_topics = 'block';
						collapsed_display = 'none';
						expanded_display = 'block';	
						this.data[1][2][2][0] = false;
			}
			
			
			
			if (this.data[1][1][0]) {
				if (topic_number == this.data[1][1][2][2]) {
					
					if (this.data[1][1][2][0] == 'new_post' ){
						this.openform = 'New comment by topic ' + topic_number;
						//previous failed request;
						//["new_post","PR1","7","03 FEB 2008 18:58:35.905632","","false"]
						display_comment = 'block';
						display_topics = 'none';
						collapsed_display = 'none';
						expanded_display = 'block';
						textarea_value = this.data[1][1][2][4];
						if (this.data[1][1][2][5] == 'true') {post_eng = true;} else {post_eng = false;}
					} else if (this.data[1][1][0] && (this.data[1][1][2][0] == 'topic_to_extern' || this.data[1][1][2][0] == 'topic_to_intern')) {
						this.openform = 'publish to extern/intern by topic ' + topic_number;
						collapsed_display = 'none';
						extern_display = 'block';	
						expanded_display = 'none';	
					} else if (this.data[1][1][0] && this.data[1][1][2][0] == 'edit_post') {
						this.openform = 'Edit last comment by topic ' + topic_number;
						display_topics = 'none';
						collapsed_display = 'none';
						expanded_display = 'block';	
						display_edit_last_post = 'block'
					}			
				}
			} 
			
			//if (post_eng) {
			if (extern) {
					var textarea_name = 'text_dut'
					input_dut = 'checked';	
					input_eng = ''
				} else {
					var textarea_name = 'text_eng'
					input_eng = 'checked';
					input_dut = '';
;						
			}	
			

			
			//collapse topic
			var unread_class =  (unread) ? 'class="gelezen"' : '';
			output += '<div '+ unread_class +' style=" cursor: pointer; display: '+collapsed_display+'; " id="collapse_'+topic_number+'"  onclick="my_logBook.expand('+topic_number+','+true+')">';
				output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td align="center" valign="center"><div style="width:  30px; height: 23px; overflow: hidden;">';
								if (priority == 'high' && accomplished) {
									output += '<img src="images/beide.gif">';
								} else if (accomplished) {
									output += '<img src="images/accomplished.gif">';
								} else if (priority == 'high') {
									output += '<img src="images/uitroepteken.gif">';
								}

								
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 16px; overflow: hidden; ">'+topic_number+'.</div></td>';
						output += '<td nowrap><div style="padding: 5px 2px 2px 2px; width: 522px; height: 16px; overflow: hidden; ">';
						

							output += reports_string;
							output += ''+ htmlspecialchars(topic_title, false)+' ';
							if (extern && functie != 'extern') {
								output += ' <span style="color: orange;">  [extern] </span> '; 
							}	
							
							short_last_post_text = last_post_text;
							
							
							
							var characters = 87;
							if (extern && functie != 'extern') {
								var characters = 80;	
							}
								
							characters = Math.abs(characters - topic_title.length - reports_string_length)
							
							if ( last_post_text.length > characters ) {
								 short_last_post_text = last_post_text.slice(0,characters) + '...' ;
							} 
							
													
							output += '<span style="color: 8d8d8d;"> - <i>'+htmlspecialchars(short_last_post_text, false)+'</i></span>';
							
							
							
						output += '</div></td>';
						
						
						if (last_poster_name.length > 16) {
							var display_last_poster_name = last_poster_name.slice(0, 16) + '...';
						} else {
							var display_last_poster_name = last_poster_name;
						}
						
						
						output += '<td nowrap><div style="padding: 5px 2px 2px 2px; width: 120px; height: 16px; overflow: hidden; ">'+display_last_poster_name+'</div></td>';
						
						var datum_now = new Date();
						var datum_today = new Date(datum_now.getFullYear() + '/' + (datum_now.getMonth() + 1 )+ '/' + datum_now.getDate()  );
						
						
						
						
						if (last_post_time.getTime() > datum_today.getTime()) {
							last_post_time_string = last_post_time.getHours() + ':';

							if ( last_post_time.getMinutes() < 10) 
							{last_post_time_string += '0';}
							
							last_post_time_string += last_post_time.getMinutes()
							
							
							
						} else {
							var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
							
							last_post_time_string = last_post_time.getDate() + ' ' + Months[last_post_time.getMonth()];
						}
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 54px; height: 16px; overflow: hidden;">'+last_post_time_string+'</div></td>';
					output += '</tr>';
				output += '</table>	';
			output += '</div>';				



			
			
			
			//--------------------------------------------------------------------------------------------------------------------------------
			//expanded
			//--------------------------------------------------------------------------------------------------------------------------------
			output += '<div id="expand_'+topic_number+'" style="display: '+expanded_display+';">';
				output += '<!-- titel -->';
				output += '<div onclick="my_logBook.expand('+topic_number+','+false+')" style="cursor: pointer">';
				output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 35px; overflow: hidden;">';
								if (priority == 'high' && accomplished) {
									output += '<img src="images/beide.gif">';
								} else if (accomplished) {
									output += '<img src="images/accomplished.gif">';
								} else if (priority == 'high') {
									output += '<img src="images/uitroepteken.gif">';
								}
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 28px; overflow: hidden;">'+topic_number+'.</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 702px; height: 28px; overflow: hidden;">';
							output += reports_string;
							output += ''+ htmlspecialchars(topic_title, false)+'';
							if (extern && functie != 'extern') {
								output += ' <span style="color: orange;"> [extern]  </span> '; 
							}								
						output += '</div></td>';
					output += '</tr>';
				output += '</table>';	
				output += '</div>';



			for (var j = 0; j <posts.length; j++) {
				var post_id = posts[j][0];
				var post_text_eng = posts[j][1];
				var post_text_dut = posts[j][2];
				var post_marked_as_extern = posts[j][3];
				var poster_name = posts[j][4];
				var poster_functie = posts[j][7];
				var post_time = new Date (posts[j][5]);
				var own_post = posts[j][8];
				var images = posts[j][9];
				

				
				
				//messages 
				output += '<div style="padding: 0px 40px 0px 40px;">';
					output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
						output += '<div>';
							output += '<!-- default language -->';
							if (post_marked_as_extern && functie != 'extern' && extern) {   
								output += '<span style="color: orange;"><b> [extern] </b></span>'; 
								if (functie == 'modeller' && post_text_eng != null) {
									var post_text = post_text_eng;
								} else {
									var post_text = post_text_dut;
								}
								
							} else if (functie == 'extern') {	
								var post_text = post_text_dut;
							
							} else {
								var post_text = post_text_eng;
							}
							output += htmlspecialchars(post_text, true);
						output += '<br><br></div>';		
						output += '<div >';
							for (var q = 0; q <images.length; q++) {
								if (images[0] != '') {
									
									var file = 'file.php?project='+project+'&session_id=' + this.data[0][3]+'&name='+images[q][0];
									output += '&nbsp;&nbsp;<img onclick="my_logBook.open_image(\''+file+'\', '+images[q][2]+', '+images[q][1]+')" title="filename: '+images[q][0] + " description: "+ images[q][3] +'" src="'+file+'&tumbnail" width="150px"> ';
								}
							}
						output += '</div>	';	
						output += '<div>';
							output += '<!-- post info -->';
							output += '<span style="color: 8d8d8d;">';
								//output += '<span style="cursor: pointer;" onclick="alert(\'edit\')" >edit</span> ';
								output += 'Posted by ';
								if (functie == 'projectmanager' && poster_functie == 'modeller' && extern) {
									output += '<span style="text-decoration: line-through;">'+ poster_name +'</span> ' + ingelogd;
								} else if (functie == 'extern' && poster_functie == 'modeller') {
									output += ingelogd;
								} else {
									output += poster_name;
								}
								output += ' On   ';
								output += post_time;
								output += '<br>';
								output += calcTime(post_time, '+3.5');
								output += ' IST';
								
								
								
								//if (post_text_eng != '' && post_text_dut != '' ) {
								//	if (eng) {
								//		output += ' (view <span style="cursor: pointer;" onclick="alert(my_logBook.data[1][2][1]['+i+'][8]['+j+'][2])" >Dutch version</span>)';
								//	} else {
								//		output += ' (view <span style="cursor: pointer;" onclick="alert(my_logBook.data[1][2][1]['+i+'][8]['+j+'][1])" >English version</span>)';
								//	}
								//	
								//}
								
								
								
							output += '</span>';
						output += '</div>	';											
					output += '</div>';
					output += '<div style="height: 5px; width: 500px; overflow: hidden;" >';
							output += '<!-- horizontale streep??? -->';
					output += '</div>';
				output += '</div>';	
			} //end posts
			

			
			
		
			
			

			
			
			//--------------------------------------------------------------------------------------------------------------------------------
			// topic options in expanded div
			//--------------------------------------------------------------------------------------------------------------------------------
			if ( 
					(functie == 'projectmanager') 
							|| 
					(functie == 'modeller' && extern == false )  
							|| 
					(functie == 'extern' && accomplished == false && extern_reageren != 'niet') 
							
								
				) {
			
			output += '<div style="padding: 0px 40px 0px 40px; display: '+display_topics+';" id="topic_options_'+topic_number+'">';
					output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
						output += '<table  cellspacing="0" border="0" cellpadding="0" >';
							output += '<tr>';
							
							
									if (accomplished == false)  {
										if ((functie == 'projectmanager') || ( extern == false) || (functie == 'extern' && (extern_reageren == 'reageren' || extern_reageren == 'topics starten'))) {
											output += '<td>';
												output += '<input type="button" value="New comment" onclick="my_logBook.expand_new_post('+topic_number+', true)">&nbsp; ';
											output += '</td>';

											if (functie == 'projectmanager') {
												output += '<td>';												
													output += '<input type="button" onclick="my_logBook.edit_topic('+topic_number+', true)" value="Edit topic">&nbsp; ';
												output += '</td>';	
											}	
											
											
											if (functie == 'modeller') {
												output += '<td>';												
													//output += '<input type="button" onclick="alert(\'Under construction...\')" value="Labels">&nbsp; ';
													output += '<input type="button" onclick="my_logBook.edit_labels('+topic_number+', true)" value="Labels">&nbsp; ';
												output += '</td>';	
											}	

																					
										} 
										if (last_post_own_post) {
											output += '<td>';
												output += '<input type="button" onclick="my_logBook.expand_edit_post('+topic_number+', true)" value="Edit last comment">&nbsp; ';
											output += '</td>';										
										}
									}
									
									
									
									
									if (functie == 'projectmanager') {	
										output += '<td>';						
										if (extern == false) {
											output += '<input type="button" onclick="my_logBook.to_extern('+topic_number+', true)" value="To extern">&nbsp; ';
										} else {
											output += '<input type="button" onclick="my_logBook.to_extern('+topic_number+', true)" value="To intern">&nbsp; ';					
										}
										output += '</td>';
									}
								
								
								
								
								if ( (functie == 'projectmanager') || ( functie == 'modeller' && extern == false) ) {
								output += '<td>';	
									
									if (accomplished) {
											var submit_value = 'Re-open topic';
											var form_action = 'open_topic'
									} else {
											var submit_value = 'Close topic';
											var form_action = 'close_topic';
									}				
													
									output += '<form method="post" action="'+action_url+'">';
									output += '<input type="hidden" value="'+form_action+'" name="action"> ';	
									output += '<input type="hidden" value="'+project+'" name="project"> ';
									output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
									output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';																	
									output += '<input type="submit" value="'+submit_value+'">&nbsp; ';
									output += '</form>';									
								output += '</td>';
								
								
								
								

								
								
								}
								
								
								
								//email notificatie
								output += '<td>';
									output += '<input type="button" onclick="my_logBook.expand_email('+topic_number+', true)" value="Email">&nbsp; ';
								output += '</td>'
								
							output += '</tr>';
						output += '</table >';
					output += '</div>';
					output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
							output += '<!-- wit regel-->';
					output += '</div>';
			output += '</div>';						
			
			}

			//--------------------------------------------------------------------------------------------------------------------------------
			//new commment  in expanded div
			//--------------------------------------------------------------------------------------------------------------------------------			
			output += '<div style="padding: 0px 40px 0px 40px; display: '+display_comment+';" id="new_post_'+topic_number+'">';
				output += '<form method="post" action="'+action_url+'" enctype="multipart/form-data">';
				output += '<input type="hidden" value="new_post" name="action"> ';	
				output += '<input type="hidden" value="'+project+'" name="project"> ';
				output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
				output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_new_post_'+topic_number+'" cellspacing="0" border="0" cellpadding="0" >';
					output += '	<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>New comment</b></div></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>text:</td>';
							
							if (extern) {
								textarea_name = 'text_dut';
							}
							output += '<td colspan="2"><textarea rows="5" id="new_post_textarea_'+topic_number+'" name="'+textarea_name+'" style="width: 570px">'+htmlspecialchars(textarea_value, false)+'</textarea></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>image*:</td>';
							output += '<td colspan="2">';
								output += '<input id="new_post_file_'+topic_number+'_0" onchange="my_logBook.add_file_new_post('+topic_number+')" name="file_0" type="file" style="width: 260px">';
								output += ' Description: <input title="new file name" name="file_0_name" type="text" style="width: 240px">';
							output += '</td>';
						output += '</tr>';
						
						
						this.files[topic_number] = 0;
						//if (eng) {
						//	var input_eng = 'checked';
						//	var input_dut = '';
						//} else {
						//	var input_eng = '';
						//	var input_dut = 'checked';
						//}							
						
						//output += '<tr>';
						//	output += '<td>language:</td>';
						//	output += '<td><div style="padding: 3px 2px 2px 2px; width:  100px; height: 20px; overflow: hidden;"><input value="true"  name="language" onchange="my_logBook.change_lang_new_post('+topic_number+',true);"   '+input_eng+' type="radio">english</div></td>';
						//	output += '<td><div style="padding: 3px 2px 2px 2px; width:  500px; height: 20px; overflow: hidden;"><input value="false" name="language" onchange="my_logBook.change_lang_new_post('+topic_number+',false);"  '+input_dut+' type="radio">dutch</div></td>';
						//output += '</tr>	';



						if (functie == 'projectmanager') {
							
							if (extern) {
								output += '<tr>';
									output += '<td>publish:</td>';
									output += '<td><div style="padding: 3px 2px 2px 2px; width:  120px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_new_post('+topic_number+',true);" name="extern" value="false" type="radio">intern (english)</div></td>';
									output += '<td><div style="padding: 3px 2px 2px 2px; width:  480px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_new_post('+topic_number+',false);" checked name="extern" value="true" type="radio">extern (dutch)</div></td>';
								output += '</tr>';
							} else {
								output += '<tr><input type="hidden" name="extern" value="false"></tr>';
							}
							
						} else if (functie == 'extern') {
							output += '<tr><input type="hidden" name="extern" value="true"></tr>';
						} else {
							output += '<tr><input type="hidden" name="extern" value="false"></tr>';
						}						
						
						
						
						output += '<tr>';
							output += '<td colspan="3"><br><input type="submit" value="Submit"><input type="button" value="Cancel" onclick="my_logBook.expand_new_post('+topic_number+', false)">&nbsp; &nbsp; &nbsp;  * Supported formats: jpeg, png, bmp and gif</td>	';
						output += '</tr>	';										
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
				output += '</form>';
			output += '</div>	';			
			
			
			
			
			//--------------------------------------------------------------------------------------------------------------------------------			
			//email notification
			//--------------------------------------------------------------------------------------------------------------------------------			
			output += '<div style="padding: 0px 40px 0px 40px; display: none;" id="email_'+topic_number+'">';
				output += '<form method="post" action="'+action_url+'">';
				output += '<input type="hidden" value="email" name="action"> ';	
				output += '<input type="hidden" value="'+project+'" name="project"> ';
				output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
				output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue;" >';
				
				
					//project_members to send email to
					output += '<table id="table_email_topic_'+topic_number+'" cellspacing="0" border="0" cellpadding="0" >';
						output += '	<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>Email notification</b></div></td>';
						output += '</tr>';		
						output += '<tr>';
					
					var num_rows_email = Math.ceil(project_members.length/3)  ;
					var z = 0;  
					for (var q = 0; q < 3; q++ ) {
							
							output += '<td valign="top">';
								output += '<div style=" overflow: hidden; width: 218px;"> ';
									output += '<table cellspacing="0" border="0" cellpadding="0">';

										if ((q == 0) || (q==1 && project_members.length > 1 ) || (q==3 && num_rows_email * 3 - project_members.length == 0 ) ) {
											var loop = num_rows_email;
										} else {
											if (q == 1)  {
												var loop = 0;
											} else {
												var loop = num_rows_email - (num_rows_email * 3 - project_members.length );
											}
										}  

									for (var p = 0; p < loop; p++) {
										output += '<tr>';
											output += '<td>';	
																					
										if ((extern && project_members[(q * num_rows_email + p)][2] == 'modeller')||(extern == false && project_members[(q * num_rows_email + p)][2] == 'extern')) {
											output += '<input disabled type="checkbox">';
										} else {
											output += '<input type="hidden" name="receiver_id_'+ z +'" value="'+project_members[(q * num_rows_email + p)][0]+'">';
											output += '<input type="checkbox" value="true" name="receiver_check_'+ z +'"> ';
											z++;
										}
											output += '</td><td> ';
											output += project_members[(q * num_rows_email + p)][1];
											output += '</td>';
										output += '</tr>';
										
									}
									output += '</table>';
								output += '</div>';
							output += '</td>';
					}
						output += '</tr>';
					
					
									

						output += '<tr>';
							output += '<td colspan="3"><br><input type="submit" value="Send"> <input type="button" value="Cancel" onclick="my_logBook.expand_email('+topic_number+', false)"></td>	';
						output += '</tr>	';										
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
				output += '</form>';
			output += '</div>	';	
			

			if (functie == 'modeller') {
			//--------------------------------------------------------------------------------------------------------------------------------			
			//edit labels
			//--------------------------------------------------------------------------------------------------------------------------------			
			output += '<div style="padding: 0px 40px 0px 40px; display: none;" id="edit_labels_'+topic_number+'">';
				output += '<form method="post" action="'+action_url+'">';
				output += '<input type="hidden" value="edit_topic" name="action"> ';	
				output += '<input type="hidden" value="'+project+'" name="project"> ';
				output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
				output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_edit_labels_'+topic_number+'" cellspacing="0" border="0" cellpadding="0" >';
						output += '<tr>';
						var num_rows_reports = Math.ceil(all_reports.length/3)  ; 
						for (var q = 0; q < 3; q++ ) {
							
							output += '<td valign="top">';
								output += '<div style=" overflow: hidden; width: 218px;"> ';
									output += '<table cellspacing="0" border="0" cellpadding="0">';

										if ((q == 0) || (q==1 && all_reports.length > 1 ) || (q==3 && num_rows_reports * 3 - all_reports.length == 0 ) ) {
											var loop = num_rows_reports;
										} else {
											if (q == 1)  {
												var loop = 0;
											} else {
												var loop = num_rows_reports - (num_rows_reports * 3 - all_reports.length );
											}
										}  

									for (var p = 0; p < loop; p++) {
										z = q * num_rows_reports + p;
										output += '<tr>';
											output += '<td>';	
												output += '<input type="hidden" name="label_id_'+ z +'" value="'+all_reports[z][0]+'">';										
										if (reports.in_array(all_reports[z][0])) {
												output += '<input checked type="checkbox" value="true" name="label_check_'+ z +'">';
										} else {
												output += '<input type="checkbox" value="true" name="label_check_'+ z +'"> ';
										}
											output += '</td>';
											output += '<td>';
												output += all_reports[z][0] + ' ' + all_reports[z][1];
											output += '</td>';
										output += '</tr>';
										
									}
									output += '</table>';
								output += '</div>';
							output += '</td>';
						}
						output += '</tr>';
						
						output += '<tr>';
							output += '<td colspan="3"><input type="submit" value="Submit"><input type="button" value="Cancel" onclick="my_logBook.edit_labels('+topic_number+', false)">&nbsp; &nbsp; &nbsp;  * Supported formats: jpeg, png, bmp and gif</td>	';
						output += '</tr>	';										
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
				output += '</form>';
			output += '</div>	';	
		output += '	</div>	';			
						
						
						
			}
			
			
		
		
			//--------------------------------------------------------------------------------------------------------------------------------			
			//edit last comment  in expanded div
			//--------------------------------------------------------------------------------------------------------------------------------			
			
			if (last_post_eng == '') {
				var textarea_name = 'text_dut';
				input_eng = '';
				input_dut = 'checked';
			} else {
				var textarea_name = 'text_eng';
				input_dut = '';
				input_eng = 'checked';
			}
			output += '<div style="padding: 0px 40px 0px 40px; display: '+display_edit_last_post+';" id="edit_post_'+topic_number+'">';
				output += '<form method="post" action="'+action_url+'" enctype="multipart/form-data">';
				output += '<input type="hidden" value="edit_post" name="action"> ';	
				output += '<input type="hidden" value="'+project+'" name="project"> ';
				output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
				output += '<input type="hidden" value="'+request_time+'" name="last_request_time"> ';
				output += '<input type="hidden" value="'+last_post_id+'" name="post_id"> ';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_edit_post_'+topic_number+'" cellspacing="0" border="0" cellpadding="0" >';
						output += '	<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>Edit last comment</b></div></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>text:</td>';
							if (extern) {
								textarea_name = 'text_dut';
							}							
							output += '<td colspan="2"><textarea  rows="5" id="edit_post_textarea_'+topic_number+'" name="'+textarea_name+'" style="width: 570px">'+htmlspecialchars(last_post_text, false)+'</textarea></td>';
						output += '</tr>';
						output += '<tr>';
							output += '<td>image*:</td>';
							output += '<td colspan="2">';
								output += '<input id="edit_post_file_'+topic_number+'_0" onchange="my_logBook.add_file_edit_post('+topic_number+')" name="file_0" type="file" style="width: 260px">';
								output += ' description: <input title="new file name" name="file_0_name" type="text" style="width: 240px">';
								
							output += '</td>';
						output += '</tr>';
						for (var q = 0; q <images.length; q++) {
							if (images[0] != '') {
							output += '<tr>';
								output += '<td>' + ((q==0) ? 'delete:' : '') + '</td>';
								output += '<td colspan="2"><input type="hidden" name="delete_file_name_' + q + '" value="' + images[q][0] + '">';
								output += '<input type="checkbox" name="delete_file_action_' + q + '" value="true">' + images[q][0];
								output += '</td>';
							output += '</tr>';
							}
						}
						this.files[topic_number] = 0;
						
						
						//output += '<tr>';
						//	output += '<td>language:</td>';
						//	output += '<td><div style="padding: 3px 2px 2px 2px; width:  100px; height: 20px; overflow: hidden;"><input value="true"  name="language" onchange="my_logBook.change_lang_edit_post('+topic_number+',true);"   '+input_eng+' type="radio">english</div></td>';
						//	output += '<td><div style="padding: 3px 2px 2px 2px; width:  500px; height: 20px; overflow: hidden;"><input value="false" name="language" onchange="my_logBook.change_lang_edit_post('+topic_number+',false);"  '+input_dut+' type="radio">dutch</div></td>';
						//output += '</tr>';
						
						
						if (functie == 'projectmanager') {
							
							if (extern) {
								output += '<tr>';
									output += '<td>publish:</td>';
									output += '<td><div style="padding: 3px 2px 2px 2px; width:  120px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_edit_post('+topic_number+',true);" name="extern" value="false" type="radio">intern (english)</div></td>';
									output += '<td><div style="padding: 3px 2px 2px 2px; width:  480px; height: 20px; overflow: hidden;"><input onchange="my_logBook.change_lang_edit_post('+topic_number+',false);" checked name="extern" value="true" type="radio">extern (dutch)</div></td>';
								output += '</tr>';
							} else {
								output += '<tr><input type="hidden" name="extern" value="false"></tr>';
							}
							
						} else if (functie == 'extern') {
							output += '<tr><input type="hidden" name="extern" value="true"></tr>';
						} else {
							output += '<tr><input type="hidden" name="extern" value="false"></tr>';
						}	
						
						
						
						
						
						output += '<tr>';
							output += '<td colspan="3"><input type="submit" value="Submit"><input type="button" value="Cancel" onclick="my_logBook.expand_edit_post('+topic_number+', false)">&nbsp; &nbsp; &nbsp;  * Supported formats: jpeg, png, bmp and gif</td>	';
						output += '</tr>	';										
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
				output += '</form>';
			output += '</div>	';	
		output += '	</div>	';
		//--------------------------------------------------------------------------------------------------------------------------------			
		//end expanded div
		//--------------------------------------------------------------------------------------------------------------------------------	
			
			
	

		
		//--------------------------------------------------------------------------------------------------------------------------------			
		//to extern	   
		//--------------------------------------------------------------------------------------------------------------------------------		
		if (functie == 'projectmanager' && extern == false) {
		output += '<div id="extern_'+topic_number+'" style="padding: 0px 0px 20px 0px; display: '+extern_display+';">';
		output += '<form method="post" action="'+action_url+'">';
		output += '<input type="hidden" value="topic_to_extern" name="action"> ';	
		output += '<input type="hidden" value="'+project+'" name="project"> ';
		output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
		output += '<input type="hidden" value="'+request_time+'" name="last_request_time">';	
			output += '<!-- titel balk -->';
			output += '<div onclick="alert(\'First Save or Cancel the publish to extern\')" style="cursor: pointer">';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 35px; overflow: hidden;">';
								if (accomplished) {
									output += '<img src="images/close.png">';
								}
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 28px; overflow: hidden;"><b>'+topic_number+'.</b></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 702px; height: 28px; overflow: hidden;">';
							output += '<b>'+ htmlspecialchars(topic_title, false)+'</b>';
							
							//output += '<span style="color: blue;"> closed by persijnbrongers</span>';
						output += '</div></td>';
					output += '</tr>';
			output += '</table>	';
			output += '</div>';
			output += '<div>';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
				output += '<tr>';
					output += '<!-- edit title -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal title</td>';
									output += '<td>External title</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><input name="topic_title_eng" value="'+escape_double_qoute(topic_title_eng)+'" style="width: 325px"></td>';
									output += '<td><input name="topic_title_dut" value="'+escape_double_qoute(topic_title_dut)+'" style="width: 325px"></td>';
								output += '</tr>	';
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					output += '<td></td>';
				output += '</tr>';
		
				
			for (var j = 0; j <posts.length; j++) {
				var post_id = posts[j][0];
				var post_text_eng = posts[j][1];
				var post_text_dut = posts[j][2];
				var post_marked_as_extern = posts[j][3];
				var poster_name = posts[j][4];
				var poster_functie = posts[j][7];
				var post_time = posts[j][5];
				var own_post = posts[j][8];
				output += '<tr>';
					output += '<!-- edit posts for extern publish -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal comment</td>';
									output += '<td>External comment</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><textarea rows="5" id = "extern_text_eng_'+i+'_'+j+'" name="post_text_eng_'+j+'"' + (post_marked_as_extern ? '' : ' disabled') + ' style="width: 325px;">'+htmlspecialchars(post_text_eng, false)+'</textarea></td>';
									output += '<td><textarea rows="5" id = "extern_text_dut_'+i+'_'+j+'" name="post_text_dut_'+j+'"' + (post_marked_as_extern ? '' : ' disabled') + ' style="width: 325px;">'+htmlspecialchars(post_text_dut, false)+'</textarea></td>';
								output += '</tr>	';						
								output += '<tr>';
									output += '<td colspan="2">	';				
										output += '<div>';
										output += '<!-- post info -->';
										output += '<span style="color: blue;">';
											output += 'Posted by ';
											if (poster_functie == 'modeller') {
													output += '<span style="text-decoration: line-through;">'+ poster_name +'</span>' + ingelogd;
											} else {
												output += poster_name;
											}
											output += ' On  ';
											output += post_time;
											output += '</span>';
										output += '</div>';	
									output += '</td>';
									
								output += '</tr>';
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					output += '<td><input onchange="my_logBook.mark_as_extern(\''+i+'_'+j+'\');" name="extern_'+j+'" value="true" type="checkbox"' + (post_marked_as_extern ? ' CHECKED' : '') + '><input name="post_id_'+j+'" value="'+post_id+'" type="hidden"></td>';
/*					if (post_marked_as_extern) {
alert(document.getElementById('extern_text_eng_'+ i+'_'+j));
						my_logBook.mark_as_extern(i+'_'+j);
					}*/
				output += '</tr>	';
			}  
				output += '<tr>';
					output += '<!-- submit -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
								output += '<input type="submit" value="Publish to extern"> <input type="button" onclick="my_logBook.to_extern('+topic_number+', false)" value="Cancel">';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					output += '<td></td>';
				output += '</tr>';
			output += '</table>	';
			output += '</div>';		
		output += '</form>';
		output += '</div>';				
		} else if (functie == 'projectmanager' && extern) {
			
			
			
			
			
			
			
			
		//--------------------------------------------------------------------------------------------------------------------------------			
		//to intern	   
		//--------------------------------------------------------------------------------------------------------------------------------			
		output += '<div id="extern_'+topic_number+'" style="padding: 0px 0px 20px 0px; display: '+extern_display+';">';
		output += '<form method="post" action="'+action_url+'">';
		output += '<input type="hidden" value="topic_to_intern" name="action"> ';	
		output += '<input type="hidden" value="'+project+'" name="project"> ';
		output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
		output += '<input type="hidden" value="'+request_time+'" name="last_request_time">';	
			output += '<!-- titel balk -->';
			output += '<div onclick="alert(\'First Save or Cancel the publish to extern\')" style="cursor: pointer">';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 35px; overflow: hidden;">';
								if (accomplished) {
									output += '<img src="images/close.png">';
								}
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 28px; overflow: hidden;"><b>'+topic_number+'.</b></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 702px; height: 28px; overflow: hidden;">';
							output += '<b>'+ htmlspecialchars(topic_title, false)+'</b>';
							
							//output += '<span style="color: blue;"> closed by persijnbrongers</span>';
						output += '</div></td>';
					output += '</tr>';
			output += '</table>	';
			output += '</div>';
			output += '<div>';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
				output += '<tr>';
					output += '<!-- edit title -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal title</td>';
									output += '<td>External title</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><input name="topic_title_eng" value="'+escape_double_qoute(topic_title_eng)+'" style="width: 325px"></td>';
									output += '<td><input name="topic_title_dut" value="'+escape_double_qoute(topic_title_dut)+'" style="width: 325px"></td>';
								output += '</tr>	';
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td></td>';
				output += '</tr>';
		
				
			for (var j = 0; j <posts.length; j++) {
				var post_id = posts[j][0];
				var post_text_eng = posts[j][1];
				var post_text_dut = posts[j][2];
				var post_marked_as_extern = posts[j][3];
				var poster_name = posts[j][4];
				var poster_functie = posts[j][7];
				var post_time = posts[j][5];
				var own_post = posts[j][8];
				
				if (post_marked_as_extern) {
				output += '<tr>';
					output += '<!-- edit posts for intern publish -->';
					output += '<td><input name="post_id_'+j+'" value="'+post_id+'" type="hidden"><input name="extern_'+j+'" value="true" type="hidden">';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal comment</td>';
									output += '<td>External comment</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><textarea rows="5" name="post_text_eng_'+j+'" style="width: 325px;">'+htmlspecialchars(post_text_eng, false)+'</textarea></td>';
									output += '<td><textarea rows="5" name="post_text_dut_'+j+'" style="width: 325px;">'+htmlspecialchars(post_text_dut, false)+'</textarea></td>';
								output += '</tr>	';						
								output += '<tr>';
									output += '<td colspan="2">	';				
										output += '<div>';
										output += '<!-- post info -->';
										output += '<span style="color: blue;">';
											output += 'Posted by ';
											output += poster_name +' (' + poster_functie + ') ';
											output += ' On ';
											output += post_time;
											output += '</span>';
										output += '</div>';	
									output += '</td>';
									
								output += '</tr>';
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td><input onchange="my_logBook.mark_as_extern(\''+i+'_'+j+'\');" name="extern_'+j+'" value="true" type="checkbox"></td>';
				output += '</tr>	';
				} else {
					output += '<tr>';
					output += '<td><input name="post_id_'+j+'" value="'+post_id+'" type="hidden"></td>';
					output += '</tr>';
				}
			}  
				output += '<tr>';
					output += '<!-- submit -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
								output += '<input type="submit" value="Publish to intern"> <input type="button" onclick="my_logBook.to_extern('+topic_number+', false)" value="Cancel">';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td></td>';
				output += '</tr>';
			output += '</table>	';
			output += '</div>';		
		output += '</form>';
		output += '</div>';				
		}

		
		
		//--------------------------------------------------------------------------------------------------------------------------------			
		//edit whole topic at once	   
		//--------------------------------------------------------------------------------------------------------------------------------			
		if (functie == 'projectmanager') {
		output += '<div id="edit_topic_'+topic_number+'" style="padding: 0px 0px 20px 0px; display: none;">';
		output += '<form method="post" action="'+action_url+'">';
		output += '<input type="hidden" value="edit_topic" name="action"> ';	
		output += '<input type="hidden" value="'+project+'" name="project"> ';
		output += '<input type="hidden" value="'+topic_number+'" name="topic"> ';
		output += '<input type="hidden" value="'+request_time+'" name="last_request_time">';	
			output += '<!-- titel balk -->';
			output += '<div onclick="alert(\'You can close edit topic with the Cancel button\')" style="cursor: pointer">';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 35px; overflow: hidden;">';
								if (accomplished) {
									output += '<img src="images/close.png">';
								}
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 28px; overflow: hidden;"><b>'+topic_number+'.</b></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 702px; height: 28px; overflow: hidden;">';
							output += '<b>'+ htmlspecialchars(topic_title, false)+'</b>';
							
							//output += '<span style="color: blue;"> closed by persijnbrongers</span>';
						output += '</div></td>';
					output += '</tr>';
			output += '</table>	';
			output += '</div>';
			output += '<div>';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
				output += '<tr>';
					output += '<!-- edit title -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal title</td>';
									output += '<td>External title</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><input name="topic_title_eng" value="'+escape_double_qoute(topic_title_eng)+'" style="width: 325px"></td>';
									output += '<td><input name="topic_title_dut" value="'+escape_double_qoute(topic_title_dut)+'" style="width: 325px"></td>';
								output += '</tr>	';
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td></td>';
				output += '</tr>';
		
				
			for (var j = 0; j <posts.length; j++) {
				var post_id = posts[j][0];
				var post_text_eng = posts[j][1];
				var post_text_dut = posts[j][2];
				var post_marked_as_extern = posts[j][3];
				var poster_name = posts[j][4];
				var poster_functie = posts[j][7];
				var post_time = posts[j][5];
				var own_post = posts[j][8];
				output += '<tr>';
					output += '<!-- edit posts for extern publish -->';
					output += '<td><input name="post_id_'+j+'" value="'+post_id+'" type="hidden">';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table  cellspacing="0" border="0" cellpadding="0" >';
								output += '<tr>';
									output += '<td>Internal comment</td>';
									output += '<td>External comment</td>';
								output += '</tr>';
								output += '<tr>';
									output += '<td><textarea rows="5" name="post_text_eng_'+j+'" style="width: 325px;">'+htmlspecialchars(post_text_eng)+'</textarea></td>';
									output += '<td><textarea rows="5" name="post_text_dut_'+j+'" style="width: 325px;">'+htmlspecialchars(post_text_dut)+'</textarea></td>';
								output += '</tr>	';						
								output += '<tr>';
									output += '<td colspan="2">	';				
										output += '<div>';
										output += '<!-- post info -->';
										output += '<span style="color: blue;">';
											output += 'Posted by ';
											output += poster_name +' (' + poster_functie + ') ';
											output += ' On   <!-- of last edited: -->';
											output += post_time;
											output += '</span>';
										output += '</div>';	
									output += '</td>';
									
								output += '</tr>';
								
								
								
								
								
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td><input onchange="my_logBook.mark_as_extern(\''+i+'_'+j+'\');" name="extern_'+j+'" value="true" type="checkbox"><input name="post_id_'+j+'" value="'+post_id+'" type="hidden"></td>';
				output += '</tr>	';
			}  
			
				output += '<tr>';
					output += '<!-- submit -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
							output += '<table>';
			
			
							output += '<tr>';
					
					var num_rows_reports = Math.ceil(all_reports.length/3)  ; 
					for (var q = 0; q < 3; q++ ) {
							
							output += '<td valign="top">';
								output += '<div style=" overflow: hidden; width: 218px;"> ';
									output += '<table cellspacing="0" border="0" cellpadding="0">';

										if ((q == 0) || (q==1 && all_reports.length > 1 ) || (q==3 && num_rows_reports * 3 - all_reports.length == 0 ) ) {
											var loop = num_rows_reports;
										} else {
											if (q == 1)  {
												var loop = 0;
											} else {
												var loop = num_rows_reports - (num_rows_reports * 3 - all_reports.length );
											}
										}  

									for (var p = 0; p < loop; p++) {
										z = q * num_rows_reports + p;
										output += '<tr>';
											output += '<td>';	
												output += '<input type="hidden" name="label_id_'+ z +'" value="'+all_reports[z][0]+'">';										
										if (reports.in_array(all_reports[z][0])) {
												output += '<input checked type="checkbox" value="true" name="label_check_'+ z +'">';
										} else {
												output += '<input type="checkbox" value="true" name="label_check_'+ z +'"> ';
										}
											output += '</td>';
											output += '<td>';
												output += all_reports[z][0] + ' ' + all_reports[z][1];
											output += '</td>';
										output += '</tr>';
										
									}
									output += '</table>';
								output += '</div>';
							output += '</td>';
					}
							output += '</tr>';
				
			
			
			
							output += '</table>';
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td></td>';
				output += '</tr>';			
			
			
			
				output += '<tr>';
					output += '<!-- submit -->';
					output += '<td>';
					output += '<div style="padding: 0px 0px 0px 40px;">';
						output += '<div style="padding: 5px 10px 5px 10px; background: AliceBlue ;" >';
								output += '<input type="submit" value="Save"> <input type="button" onclick="my_logBook.edit_topic('+topic_number+', false)" value="Cancel">';
								
								if (priority == 'normal') {
									var checked_normal = 'checked';
									var checked_high = '';
								} else {
									var checked_normal = '';
									var checked_high = 'checked';
								}
							
								output += ' Change priority:  <input '+checked_normal+' type="radio" name="priority" value="normal"> normal  <input '+checked_high+' type="radio" name="priority" value="high"> high';
						
						output += '</div>';
					output += '</div>';
					output += '</td>';
					//output += '<td></td>';
				output += '</tr>';
			output += '</table>	';
			output += '</div>';		
		output += '</form>';
		output += '</div>';				
		}
		
					

				
				
		//--------------------------------------------------------------------------------------------------------------------------------	
		// blue line
		//--------------------------------------------------------------------------------------------------------------------------------		
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';
		}

			
		//--------------------------------------------------------------------------------------------------------------------------------	
		// page navigation
		//--------------------------------------------------------------------------------------------------------------------------------
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 60px; text-align: center;">';
				output += '<span style="color: white;">';
				var nav_url = action_url_without_offset + '&offset=';	
						if (offset == 0) {
							output += ' &lt;&lt; &lt; ';
						} else {
							output += '<a style="text-decoration: none; color: white;" href="'+nav_url+ 0 +'"> &lt;&lt; ';
							output += '<a style="text-decoration: none; color: white;" href="'+nav_url+ (offset - limit) +'"> &lt; ';
						}
						
						var num_pages = Math.ceil(total_topics/limit);
						for (var j = 1; j <=num_pages; j++) { 		
							if (offset == (j - 1)  * limit) {
								 output += '<b> ' + j + ' </b>';
							} else {
								output += '<a style="text-decoration: none; color: white;" href="'+nav_url+ ((j - 1) * limit) +'"> '+j+' </a>';
							}
						}			
						
						if (total_topics - topic_length == offset) {
							 output += ' &gt; &gt;&gt; ';
						} else {
							output += '<a style="text-decoration: none; color: white;" href="'+nav_url+ (offset + limit) +'"> &gt; ';
							output += '<a style="text-decoration: none; color: white;" href="'+nav_url+ ((num_pages -1 ) * limit) +'"> &gt;&gt; ';							
						}
					output += ' </span>';
		output += '</div>';	
			
		this.content.innerHTML = output;
		
	}
	
	
	this.openTopic = function (bool) {
		var div = document.getElementById('newtopic');
		//document.getElementById('new_topic_title').focus();
		
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'New topic';
				div.style.display = 'block';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			div.style.display = 'none';
		}	
		document.getElementById('new_topic_title').focus();
	} 

	
	this.openNewReport = function (bool) {
		var div = document.getElementById('newreport');
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'New Report';
				div.style.display = 'block';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			div.style.display = 'none';
		}	
	} 	
	

	this.openPrint = function (bool) {
		var div = document.getElementById('print');
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Create a PDF document';
				div.style.display = 'block';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			div.style.display = 'none';
		}	
	} 	
	
	
	this.openEditList = function (bool) {
		var div = document.getElementById('filter');
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Edit list';
				div.style.display = 'block';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			div.style.display = 'none';
		}	
	} 	
	
	
	this.expand_edit_post = function (id, bool) {
		var post_div = document.getElementById('edit_post_'+id);
		var topic_options_div = document.getElementById('topic_options_'+id);	
		
		if (bool) {
			if (this.openform == null ) {	
				this.openform = 'edit last comment by topic ' + id;
				post_div.style.display = 'block';
				topic_options_div.style.display = 'none';	
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}			
		} else {
			this.openform = null;
			post_div.style.display = 'none';
			topic_options_div.style.display = 'block';				
		}	
		
	}
	
	this.open_image = function (image, h, w) {
//		document.location.href=image;
		window.open(image,"_blank","toolbar=no, location=0, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width="+(w+25)+", height="+(h+25)+" ");
	}	
	
	this.expand_new_post = function (id, bool) {
		var post_div = document.getElementById('new_post_'+id);
		var topic_options_div = document.getElementById('topic_options_'+id);
		
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'New comment by topic ' + id;
				post_div.style.display = 'block';
				topic_options_div.style.display = 'none';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			post_div.style.display = 'none';
			topic_options_div.style.display = 'block';			
		}
		document.getElementById('new_post_textarea_'+id).focus();
	}

	
	
	this.edit_labels = function (id, bool) {
		//alert('under construction...');
		var post_div = document.getElementById('edit_labels_'+id);
		var topic_options_div = document.getElementById('topic_options_'+id);
		
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Edit labels by topic ' + id;
				post_div.style.display = 'block';
				topic_options_div.style.display = 'none';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			post_div.style.display = 'none';
			topic_options_div.style.display = 'block';			
		}
	}	
	
	
	this.expand_email = function (id, bool) {
		var post_div = document.getElementById('email_'+id);
		var topic_options_div = document.getElementById('topic_options_'+id);
		
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Sending email notification by topic ' + id;
				post_div.style.display = 'block';
				topic_options_div.style.display = 'none';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			post_div.style.display = 'none';
			topic_options_div.style.display = 'block';			
		}
	}	
	
	
	
	this.change_lang_edit_post = function (id, bool) {
		if (bool) {
			//document.getElementById('div_edit_text_eng_'+id).style.display = 'block';
			//document.getElementById('div_edit_text_dut_'+id).style.display = 'none';
			document.getElementById('edit_post_textarea_' + id).name = 'text_eng';			
		} else {
			//document.getElementById('div_edit_text_dut_'+id).style.display = 'block';
			//document.getElementById('div_edit_text_eng_'+id).style.display = 'none';
			document.getElementById('edit_post_textarea_' + id).name = 'text_dut';	
		}			
		
	}
	
	this.change_lang_new_topic = function(bool) {
		if (bool) {  //new_topic_title
			document.getElementById('new_topic_title').name = 'title_eng';
			document.getElementById('new_topic_text_r').name = 'text_eng';
		} else {
			document.getElementById('new_topic_title').name = 'title_dut';
			document.getElementById('new_topic_text_r').name = 'text_dut';
		
		}		
	}
	
	this.change_lang_new_post = function(id, bool) {
		if (bool) {
			document.getElementById('new_post_textarea_'+id).name = 'text_eng';    
			
		} else {
			document.getElementById('new_post_textarea_'+id).name = 'text_dut';
		}		
	}	
	
	
	this.add_file_new_post = function (id) {
		table = document.getElementById('table_new_post_'+id);
		var row = table.insertRow(this.files[id] + 3);
		document.getElementById('new_post_file_' + id + '_' + this.files[id]).onchange = null;
		row.insertCell(0).innerHTML = 'image*:';
		var cell = row.insertCell(1);
		
		cell.innerHTML = '<input id="new_post_file_'+id+'_'+(this.files[id] + 1)+'" onchange="my_logBook.add_file_new_post('+id+')" name="file_'+(this.files[id] + 1)+'" type="file" style="width: 260px">';
		cell.innerHTML += ' description: <input name= "file_'+ (this.files[id] + 1) +'_name" type="text" style="width: 240px" >';
		cell.colSpan = '2';
		this.files[id]++;
	}	

	this.add_file_edit_post = function (id) {
		table = document.getElementById('table_edit_post_'+id);
		var row = table.insertRow(this.files[id] + 3);
		document.getElementById('edit_post_file_' + id + '_' + this.files[id]).onchange = null;
		row.insertCell(0).innerHTML = 'image*:';
		var cell = row.insertCell(1);
		
		cell.innerHTML = '<input id="edit_post_file_'+id+'_'+(this.files[id] + 1)+'" onchange="my_logBook.add_file_edit_post('+id+')" name="file_'+(this.files[id] + 1)+'" type="file" style="width: 260px">';
		cell.innerHTML += ' description: <input name= "file_'+ (this.files[id] + 1) +'_name" type="text" style="width: 240px" >';
		cell.colSpan = '2';
		this.files[id]++;
	}
	
	this.add_file_new_topic = function () {
		
		table = document.getElementById('table_new_topic');
		
		var row = table.insertRow(this.files[0] + 4);
		document.getElementById('new_topic_file_' + this.files[0] ).onchange = null;
		row.insertCell(0).innerHTML = 'image*:';
		var cell = row.insertCell(1);
		
		cell.innerHTML = '<input id="new_topic_file_'+(this.files[0] + 1)+'" onchange="my_logBook.add_file_new_topic()" name="file_'+(this.files[0] + 1)+'" type="file" style="width: 260px">';
		cell.innerHTML +=  ' description: <input title="new file name" name="file_'+(this.files[0] + 1)+'_name" type="text" style="width: 240px">';
		cell.colSpan = '2';
		this.files[0]++;
	}	
	
	
	
	this.mark_as_extern = function (id) {
		var eng_t = document.getElementById('extern_text_eng_' + id);
		var dut_t = document.getElementById('extern_text_dut_' + id);
		if (eng_t.disabled == true ) {
			eng_t.disabled = false;
			dut_t.disabled = false;
		} else {
			eng_t.disabled = true;
			dut_t.disabled = true;
		}
		
	}
	

	this.expand_all = function (bool) {
		
		var topic_length = this.data[1][2][1].length;
		var div = document.getElementById('expand_all_div_id');
		if (bool) {
			div.innerHTML = '<span onclick="my_logBook.expand_all(false);" style="cursor: pointer;">Collapse All</span>';
			var topic_array = new Array();
			for (var j = 0; j <topic_length; j++) {
				var id = 	this.data[1][2][1][j][0];
				topic_array.push(id);
				document.getElementById('collapse_'+id).style.display = 'none';
				document.getElementById('expand_'+id).style.display = 'block';
				//this.expand(id, true);
			}
			//alert(topic_array);
			var session_id = this.data[0][3];
			var project = this.data[1][2][0][1];
				new Ajax.Request('index.php?page=no&session_id=' + session_id,
				  {
				    method:'post',
					parameters: {topics: jsarray2sqlarry(topic_array), project: project, action: 'mark_page_as_read'}, 
				    //onSuccess: function(transport){
				    //  var response = transport.responseText || "no response text";
				    // alert("Success! \n\n" + response);
				    //},
				    onFailure: function(){ alert('Server is unreachable, your messages will not be marked as read on the server.') }
				  });			
			
			
			
		} else {
			div.innerHTML = '<span onclick="my_logBook.expand_all(true);" style="cursor: pointer;">Expand All</span>';
			for (var j = 0; j <topic_length; j++) {
				var id = 	this.data[1][2][1][j][0];
				document.getElementById('collapse_'+id).style.display = 'block';
				document.getElementById('expand_'+id).style.display = 'none';
				//this.expand(id, false);
			}				
		}		
	}
	
	this.expand = function (id, bool) {
		//var self = this;
		var col_div = document.getElementById('collapse_'+id);
		var exp_div = document.getElementById('expand_'+id);

		if (bool) {
			col_div.style.display = 'none';
			col_div.className = '';
			exp_div.style.display = 'block';
			
			
			//alert(this.data);
			
			var session_id = this.data[0][3];
			var project = this.data[1][2][0][1];
			

			
			
			new Ajax.Request('index.php?page=no&session_id=' + session_id,
			  {
			    method:'post',
				parameters: {project: project, action: 'mark_as_read', topic_number: id}, 
			    //onSuccess: function(transport){
			    //  var response = transport.responseText || "no response text";
			    // alert("Success! \n\n" + response);
			    //},
			    onFailure: function(){ alert('Server is unreachable, your message will not be marked as read on the server.') }
			  });
			
			
			

		} else {
			col_div.style.display = 'block';
			exp_div.style.display = 'none';	
			col_div.style.fontWeight = 'bold';
			
		}
	}	
	
	this.expand_report = function (id, bool) {
		var col_div = document.getElementById('collapse_report_'+id);
		var exp_div = document.getElementById('expand_report_'+id);

		if (bool) {
			col_div.style.display = 'none';
			exp_div.style.display = 'block';

		} else {
			col_div.style.display = 'block';
			exp_div.style.display = 'none';			
		}
	}	
	
	this.to_extern = function (id, bool) {
		var extern_div = document.getElementById('extern_'+id);
		var expand_div = document.getElementById('expand_'+id);
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Extern/Intern publish by topic ' + id;
				extern_div.style.display = 'block';
				expand_div.style.display = 'none';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			extern_div.style.display = 'none';
			expand_div.style.display = 'block';			
		}

		
	}		
	
	this.edit_topic = function (id, bool) {
		var edit_topic_div = document.getElementById('edit_topic_'+id);
		var expand_div = document.getElementById('expand_'+id);
		if (bool) {
			if (this.openform == null ) {
				this.openform = 'Edit topic ' + id;
				edit_topic_div.style.display = 'block';
				expand_div.style.display = 'none';
			} else {
				alert('You can open one form at a time only, first close : ' + this.openform);
			}
		} else {
			this.openform = null;
			edit_topic_div.style.display = 'none';
			expand_div.style.display = 'block';			
		}

		
	}	

	
	this.admin = function() {
		var html = '';
		var tables = this.data[1][2];
		
		html += '<form method="get" action="index.php"><input type="hidden" name="page" value="admin"> <input type="hidden" name="session_id" value="' + this.data[0][3] + '">'; 
				
		
		//bedrijven
		html += '&nbsp;<b>Selection: </b>  <select name="filter_company"><option value="">all companies</option>';
		for (var j=0; j< tables[1][1].length; j++) {
			html += '<option value="'+tables[1][1][j][1]+'">'+tables[1][1][j][1]+'</option>';
		}
		html += '</select>';
		
		//projecten
		html += '&nbsp; <select name="filter_project"><option value="">all projects</option>';
		for (var j=0; j< tables[0][1].length; j++) {
			html += '<option value="'+tables[0][1][j][0]+'">'+tables[0][1][j][0]+'</option>';
		}
		html += '</select>';		
		
		html += '<input type="submit" value="execute"></form> <br>  <br> '; 
		

		
		
		
		for (var j = 0; j < tables.length; j++) {
			var rows = tables[j][1];
			var titles = tables[j][0];
			var table_name = tables[j][2];
			
			var form_tag = '<form enctype="multipart/form-data" method="post" action="index.php?page=admin&session_id=' + this.data[0][3] + '"><input type="hidden" name="action" value="admin"><input type="hidden" name="table" value="'+table_name+'">'; 
			
			
			
			html += '<b>&nbsp;&nbsp;&nbsp;Database table: "' + table_name + '"</b><br>';
			
			var total_width = 0;
			for (var i = 1; i < titles.length; i++) {
				total_width = (total_width * 1)  + ( titles[i][2] * 1);
			}
			
			
			
			//html += '<div style=" width: 770px; height:'+(rows.length * 24 + 120 + 17)+'px; overflow: auto;">';
			html += '<div style=" width: 770px;">';
			html += '<div style="height:'+(rows.length * 24 + 60)+'px; width: '+(total_width + 190)+'px;">';
			html += '<table  cellspacing="0" border="0" cellpadding="0" ><tr><td colspan="2">';
			html += '<input type="button" disabled style="width: 60px;">'
			var form = '';
			var form2 = '';
			for (var i = 1; i < titles.length; i++) {
				html += '<input type="button" disabled style="width: '+titles[i][2]+'px; height: 24px; color: black;"  value="' + titles[i][0]  + '">'
						if (titles[i][1] == 'fk') {
							form += '<select name="'+i+'" style="width: '+titles[i][2]+'px; height: 22px;;"><option value="">null</option>';
								for (var p = 0; p < titles[i][3].length; p++) {
									form += '<option value="'+titles[i][3][p][0]+'">'+titles[i][3][p][1]+'</option>';
								}
							form += '</select>';
						} else if (titles[i][1] == 'bool') {
							form += '<select name="'+i+'" style="width: '+titles[i][2]+'px; height: 22px;">';
								form += '<option value="">null</option>';
								form += '<option value="true">true</option>';
								form += '<option value="false">false</option>';
							form += '</select>';
						} else if (titles[i][1] == 'file') {
							form += '<input type="hidden" name="'+i+'" value=""><input disabled type="text" value="First save to upload" style="width: '+(titles[i][2])+'px; height: 24px;">'
						} else {
							form += '<input name="'+i+'" style="width: '+titles[i][2]+'px; height: 24px;">'
						}	
				form2 += '<input name="'+i+'" type="hidden">'	;	//De delete functie moet evenveel input/$_post variabelen hebben.
			}
			html += '<input type="button" disabled style="width: 60px; height: 24px;">'
			html += '</td></tr>';
			for (var i = 0; i < rows.length; i++) {
				html += '<tr><td>';	
				//update
				html += form_tag;
					html += '<input type="hidden" name="delete" value="false"><input type="submit" value="Update" style="width: 60px; height: 24px;"><input type="hidden" name="0" value="'+rows[i][0]+'">'
					for (var k = 1; k < rows[i].length; k++) {
							if (titles[k][1] == 'fk') {
								html += '<select name="'+k+'" style="width: '+titles[k][2]+'px; height: 22px;"><option value="">null</option>';
									for (var p = 0; p < titles[k][3].length; p++) {
										if (titles[k][3][p][0] == rows[i][k] ) {var select = 'selected'; } else  { var select = '';}
										html += '<option '+select+' value="'+titles[k][3][p][0]+'">'+titles[k][3][p][1]+'</option>';
									}
								html += '</select>';
								
							} else if (titles[k][1] == 'bool') {
								html += '<select name="'+k+'" style="width: '+titles[k][2]+'px; height: 22px;"><option value="">null</option>';
								if (rows[i][k] == true ) {html += '<option selected value="true">true</option>';} else {html += '<option value="true">true</option>';}
								if (rows[i][k] == false ) {html += '<option selected value="false">false</option>';} else {html += '<option value="false">false</option>';}
								html += '</select>';
							} else if(titles[k][1] == 'file') {
								html += '<input type="hidden" name="'+k+'" value="no file"><input name="0_name" type="file" style="width: '+(titles[k][2] - 50 )+'px; height: 24px;"><a href="file.php?action=front_image&project='+rows[i][0]+'&name=' + rows[i][k] + '" target="_blanc"><img src="images/image.gif"></a>';
							} else {
								html += '<input name="'+k+'" style="width: '+titles[k][2]+'px; height: 24px;" value="'+ rows[i][k]+'">';
							}
					}
				html += '</form>';	
				//delete
				html += '</td><td>' + form_tag;
					html += '<input type="hidden" name="delete" value="true"><input type="submit" value="Delete" style="width: 60px; height: 24px;"><input type="hidden" name="0" value="'+rows[i][0]+'">' + form2;
				html += '</form></td></tr>';
			}
			//insert	
			html += '<tr><td colspan="2">' + form_tag;
				html += '<input type="hidden" name="delete" value="false"><input type="submit" value="Insert" style="width: 60px; height: 24px;"><input type="hidden" name="0" value="">';
				html += form
				html += '<input type="button" disabled style="width: 60px; height: 24px;">'
			html += '</form></td></tr></table>';
			html += '</div>';
			html += '</div>';
			html += '<br><br><br><br><br>';	
			
		}
		
		this.content.innerHTML = html;
	}
	
	this.projects = function() {
		//overview projects

		//title bar
		var output = '';
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 40px;">';
			output += '<table cellspacing="0" border="0" cellpadding="0">';
				output += '<tr>';
					output += '<td><div style=" color: white; padding: 8px 5px 5px 10px; width: 402px;"><h3>'+ this.message['your_projects'] + '</h3></div></td>';
					output += '<td><div style=" color: white; text-align: right; padding: 8px 5px 5px 10px; width: 340px;">'; 
						output += '  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;';
					output += '</div></td>';
				output += '</tr>';
			output += '</table>';
		output += '</div>';			
		
		if (this.data[1][2] == '') {
			output += '<tr><td colspan="2">None</td></tr>'
		} else {
			for (var i = 0; i < this.data[1][2].length; i++) {
			
			
			output += '<div >';
				output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 23px; overflow: hidden;">';
	
						output += '</div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 120px; height: 16px; overflow: hidden;"><b>'+ this.data[1][2][i][0]+'.</b></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 392px; height: 16px; overflow: hidden;"><a href="index.php?page=topics&project=' + this.data[1][2][i][0] + '&show_close=false&label_filter_action=ANY+IN&order_by=topic_number&offset=0&direction=DESC&session_id='+this.data[0][3]+'">'+this.data[1][2][i][1]+'</a></div></td>';
					output += '</tr>';
				output += '</table>	';
			output += '</div>';			
			output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';
			}
		}

		
		this.content.innerHTML = output;
		
	}	
	
	this.goto_report = function() {
		var order_by = this.data[1][2][0][7];
		var closed = this.data[1][2][0][8];
		var unanswered = this.data[1][2][0][9];
		var self_started = this.data[1][2][0][10];
		var extern = this.data[1][2][0][11];
		
		
		if (closed == true) {closed = '&show_close=true'} else if (closed == false) {closed = '&show_close=false';} else {closed = '';}
		if (extern == true) {extern = '&extern=true'} else if (extern == false) {extern = '&extern=false';} else {extern = '';}
		if (unanswered == true) {unanswered = '&not_own_post_as_last=true'}	else {unanswered = '';}
		if (self_started == true) {self_started = '&own_topics_only=true'}	else {self_started = '';}
		
		if (this.openform == null ) {
			document.location.href= 'index.php?page=report&project=' + this.data[1][2][0][1]+ '&offset=0' + closed + unanswered + extern + self_started + '&order_by=' + order_by + '&session_id=' + this.data[0][3];
		} else {
			alert('You can open one form at a time only, first close : ' + this.openform);
		}		
	}



	this.old_report = function () {
				
		var project = this.data[1][2][0][1];
		var project_name = this.data[1][2][0][3];
		var order_by = this.data[1][2][0][7];
		var closed = this.data[1][2][0][8];
		var unanswered = this.data[1][2][0][9];
		var self_started = this.data[1][2][0][10];
		var extern = this.data[1][2][0][11];
		var direction = this.data[1][2][0][14];
		
		if (closed == true) {closed = '&show_close=true'} else if (closed == false) {closed = '&show_close=false';} else {closed = '';}
		if (extern == true) {extern = '&extern=true'} else if (extern == false) {extern = '&extern=false';} else {extern = '';}
		if (unanswered == true) {unanswered = '&not_own_post_as_last=true'}	else {unanswered = '';}
		if (self_started == true) {self_started = '&own_topics_only=true'}	else {self_started = '';}
		
		var action_url = 'pdf.php?project=' + this.data[1][2][0][1] + '&offset=0' + closed + extern  + self_started + unanswered + '&session_id=' + this.data[0][3];
		var output = '';
		//title bar
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 40px;">';
			output += '<table cellspacing="0" border="0" cellpadding="0">';
				output += '<tr>';
					output += '<td><div style=" color: white; padding: 8px 5px 5px 10px; width: 402px;"><h3>'+ project_name + ' - Report</h3></div></td>';
					output += '<td><div style=" color: white; text-align: right; padding: 8px 5px 5px 10px; width: 340px;">'; 
					output += '</div></td>';
				output += '</tr>';
			output += '</table>';
		output += '</div>';		

		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';
		output += '<div style="padding: 10px;">';

		output += '<form method="post" action="' + action_url + '" target="_blank" enctype="multipart/form-data">';
		output += '<input type="hidden" value="topics" name="page">';	
		output += '<input type="hidden" value="'+this.data[0][3]+'" name="session_id">';	
		output += '<input type="hidden" value="0" name="offset">';	
		output += '<input type="hidden" value="topics" name="page">';	
		//output += '<input type="hidden" value="'+project+'" name="project">';			
		//output += '<input type="hidden" value="'+closed+'" name="show_close">';			
		//output += '<input type="hidden" value="'+extern+'" name="extern">';			
		//output += '<input type="hidden" value="'+self_started+'" name="own_topics_only">';			
		//output += '<input type="hidden" value="'+order_by+'" name="order_by">';			
		output += '<table border="0">';
			output += '<tr><td>Projectonderdeel:</td><td> <input type="text" name="project_part"></td></tr>';			
			output += '<tr><td>Rapportnummer:</td><td> <input type="text" name="report_number"></td></tr>';			
			output += '<tr><td>Onderwerp:</td><td> <input type="text" name="subject"></td></tr>';
			
			// create the image
			var image = document.createElement('img');
			var file = 'report_frontpage_image.php?project='+project;
			image.setAttribute('src', file);

			if (image.complete) {
				output += '<tr><td>Current image:</td><td> <image src=' + file + ' width=\'200\'></td></tr>';
			} else {
				output += '<tr><td>Current image:</td><td> None</td></tr>';
			}
			output += '<tr><td>New image:<br>(leave blank to use current)</td><td> <input name="frontpageimage" type="file" style="width: 570px"></td></tr>';
			output += '<tr><td>Architect:</td><td> <input type="text" name="architect"></td></tr>';			

			output += '<tr><td><input type="submit" value="Create"> <input type="button" value="Cancel" onclick="history.back();"></td><td></td></tr>';
		
		output += '</table>';
		output += '</form>';			
		output += '</div>';		
		
		
		this.content.innerHTML = output;
		
	}



	this.report = function() {
//		alert('Under construction......');
		
		
		var report_admin = this.data[1][2];
		var project_afk = report_admin[0][0];
		var project_name = report_admin[0][1]; 
		var architect = report_admin[0][2]; 
		var constructeur = report_admin[0][3]; 
		var afbeelding = report_admin[0][4]; 
		var opdrachtgever = report_admin[0][5];
//		var installatieadviseur = (report_admin[0][6] == 'null') ? '' : ('-' + report_admin[0][6] + '-'); 
		var installatieadviseur = report_admin[0][6];
		var overigen = report_admin[0][7]; 
		var filter_status  = report_admin[0][8]; 
		var filter_extern = report_admin[0][9]; 
		var filter_not_own_post_as_last = report_admin[0][10]; 
		var filter_own_topics_only = report_admin[0][11]; 
		

		
		
		var topics = report_admin[1];
		var filtered_topics = report_admin[2];
		var projectmanagers = report_admin[3];
		var rapporten = report_admin[4];

		
		if (filter_status == true) {filter_status = '&show_close=true'} else if (filter_status == false) {filter_status = '&show_close=false'} else {filter_status = '';}
		if (filter_status == true) {filter_extern = '&extern=true'} else if (filter_extern == false) {filter_extern = '&extern=false'} else {filter_extern = '';}
		if (filter_not_own_post_as_last == true) {filter_not_own_post_as_last = '&not_own_post_as_last=true';} else {filter_not_own_post_as_last = '';}
		if (filter_own_topics_only == true) {filter_own_topics_only = '&own_topics_only=true'} else {filter_own_topics_only = '';}
		
		var action_url = 'index.php?page=report&project=' + project_afk + filter_status + filter_extern + filter_own_topics_only + filter_not_own_post_as_last + '&session_id=' + this.data[0][3];
		
		var output = '';
		//title bar
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 40px;">';
			output += '<table cellspacing="0" border="0" cellpadding="0">';
				output += '<tr>';
					output += '<td><div style=" color: white; padding: 8px 5px 5px 10px; width: 402px;"><h3>'+ project_name + ' - Labels</h3></div></td>';
					output += '<td><div style=" color: white; text-align: right; padding: 8px 5px 5px 10px; width: 340px;">'; 
						output += '<span style="cursor: pointer;" onclick="my_logBook.openNewReport(true)" >New Label</span> | ';
						output += '<a href="'+action_url+'" style="text-decoration: none; color: white;">Refresh</a> | ';
						output += '<a href="index.php?offset=0&page=topics&project='+project_afk+'&order_by=topic_number&direction=DESC&session_id=' + this.data[0][3]+ filter_status + filter_extern + filter_own_topics_only + filter_not_own_post_as_last+'" style="text-decoration: none; color: white;">Topics </a>';
					output += '</div></td>';
				output += '</tr>';
			output += '</table>';
		output += '</div>';		



		//new label	
		output += '<div id="newreport" style="display: none;">';
			output += '<form method="post" action="'+action_url+'">';
			output += '<input type="hidden" value="new_label" name="action"> ';	
			output += '<input type="hidden" value="'+project_afk+'" name="project"> ';
			output += '<div style="padding: 20px 40px 0px 40px;">';
				output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
					output += '<table id="table_new_topic" cellspacing="0" border="0" cellpadding="0" >';
						
						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>New Label</b></div></td>';
						output += '</tr>';
				
						output += '<tr>';
							output += '<td>Label name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							output += '<td colspan="2"><input name="label_name" style=" width: 223px;"> max 14 characters</td>';
						output += '</tr>';		
						
						
						output += '<tr>';
							output += '<td>Label name (dutch)*: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							output += '<td colspan="2"><input name="label_name_dutch" style=" width: 223px;"> max 14 characters</td>';
						output += '</tr>'
						
						
						output += '<tr>';
							output += '<td>Visible for: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							output += '<td colspan="2">';
								output += '<input type="radio" disabled name="visible_for" value="true" > extern ';
								output += '<input type="radio" name="visible_for" value="false" checked> intern ';
								output += '<input type="radio" name="visible_for" value=""> both ';
							output += '</td>';
						output += '</tr>';
						
						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;">* features are in development</div></td>';
						output += '</tr>';								

						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;"><b><br>Included topics: </b></div></td>';
						output += '</tr>';						
						
						//3 kolommen met topics.
						output += '<tr>';		
							
							
						var topics_length = filtered_topics.length;
						var num_rows_topics = Math.ceil(topics_length/3) ;

						
						for (var q = 0; q < 3; q++ ) {
								
								output += '<td valign="top">';
									output += '<div style=" overflow: hidden; width: 223px;"> ';
										output += '<table cellspacing="0" border="0" cellpadding="0">';

											if ((q == 0) || (q==1 && topics_length > 1 ) || (q==3 && num_rows_topics * 3 - topics_length == 0 ) ) {
												var loop = num_rows_topics;
											} else {
												if (q == 1)  {
													var loop = 0;
												} else {
													var loop = num_rows_topics - (num_rows_topics * 3 - topics_length );
												}
											}  

										//alert(project_members.length);
										for (var p = 0; p < loop; p++) {
											var k = q * num_rows_topics + p;
											var r = filtered_topics[k];
											
											
											var topic_number = topics[r][0];
											var topic_title_eng = topics[r][1];
											var topic_title_dut = topics[r][2];
											var topic_extern = topics[r][3];
											var topic_priority = topics[r][4];
											var topic_accomplished = topics[r][5];
											
	
											output += '<tr>';
												output += '<td>';
												output += '<input type="hidden" value="'+topic_number+'" name="topic_index_'+ k +'"> ';
												output += '<input type="checkbox" value="true" name="topic_check_'+ k +'"> ';
												output += '</td><td> ';
												output += topic_number + ': ';
												
												if (topic_extern) {output += '<span style="color: orange;"> <b> [ex] </b> </span> ';}
												if (topic_priority == 'high') {output += '<span style="color: red;"> <b> ! </b> </span> ';}
												if (topic_accomplished) {output += '<img src="images/close.png">';}
												
												
												if (topic_extern) {
													output += topic_title_dut;
												} else {
													output += topic_title_eng;
												}
												output += '</td>';
											output += '</tr>';
	
											
										}
										
										output += '</table>';
									output += '</div>';
								output += '</td>';
						}						
						
						output += '</tr>';
						
						
						output += '<tr>';
							output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;"><b><br>Report settings for label: </b></div></td>';
						output += '</tr>';
						
						output += '<tr>';
							output += '<td>Report name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							output += '<td colspan="2"><input name="report_name" style=" width: 223px;"> (hidden on report)</td>';
						output += '</tr>';							
		
						output += '<tr>';
							output += '<td>subject:</td>';
							output += '<td colspan="2"><input name="subject" style=" width: 223px;"></td>';
						output += '</tr>';		
						
						output += '<tr>';
							output += '<td>project part: </td>';
							output += '<td colspan="2"><input name="project_part" style=" width: 223px;"></td>';
						output += '</tr>';			
						
						
						//output += '<tr>';
						//	output += '<td>extern report: </td>';
						//	output += '<td colspan="2"><input checked type="checkbox" name="extern" value="true"> </td>';
						//output += '</tr>';
	

						output += '<tr>';
							output += '<td>architect: </td>';
							output += '<td colspan="2"><input disabled value="'+architect+'" style=" width: 223px;"><input value="true" type="checkbox" name="show_architect">(to be edited in Admin)</td>';
						output += '</tr>';	
						
						output += '<tr>';
							output += '<td>constructeur: </td>';
							output += '<td colspan="2"><input disabled value="'+constructeur+'" style=" width: 223px;"><input value="true" type="checkbox" name="show_constructeur">(to be edited in Admin)</td>';
						output += '</tr>';	

						output += '<tr>';
							output += '<td>opdrachtgever: </td>';
							output += '<td colspan="2"><input disabled value="'+opdrachtgever+'" style=" width: 223px;"><input value="true" type="checkbox" name="show_opdrachtgever">(to be edited in Admin)</td>';
						output += '</tr>';	



						output += '<tr>';
							output += '<td>afbeelding: </td>';
							output += '<td colspan="2"><input disabled value="'+afbeelding+'" style=" width: 223px;"><input value="true" type="checkbox" name="show_afbeelding">(to be edited in Admin)</td>';
						output += '</tr>';	
						
						output += '<tr>';
							output += '<td>topic status: </td>';
							output += '<td colspan="2">';
								output += '<input type="radio" name="status" value="true">open ';
								output += '<input type="radio" name="status" value="false">closed ';
								output += '<input checked type="radio" name="status" value="">both ';
							output +=  '</td>';
						output += '</tr>';	
																								
						output += '<tr>';
							output += '<td>published: </td>';
							output += '<td colspan="2">';
								output += '<input type="radio" name="extern" value="false">intern ';
								output += '<input type="radio" name="extern" value="true">extern ';
								output += '<input checked type="radio" name="extern" value="">both ';
							output +=  '</td>';
						output += '</tr>';				
											
						output += '<tr>';
							output += '<td colspan="3"><input type="submit" value="Save"><input type="reset" value="Cancel" onclick="my_logBook.openNewReport(false)"></td>';
						output += '</tr>';
																
					output += '</table >';
				output += '</div>';
				output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
				output += '</div>';
			output += '</div>';
			output += '</form>';
		output += '</div>';	
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';		
		
		





		
		
		if (rapporten.length == 0) {
			output += '<br>&nbsp;&nbsp;&nbsp;No labels<br><br>';
			
		}
		
		

		
			for (var u = 0; u < rapporten.length; u++) {
				var rapport_nummer = rapporten[u][0];
				var rapport_naam = rapporten[u][1];
				var rapport_onderdeel = rapporten[u][2];
				var rapport_onderwerp = rapporten[u][3];
				var rapport_eigenaar = rapporten[u][4];
				var extern = rapporten[u][5];
				var status = rapporten[u][6];
				var show_arch = rapporten[u][7];
				var show_opdr = rapporten[u][8];
				var show_constr = rapporten[u][9];
				var show_afb = rapporten[u][10];
				var show_eig = rapporten[u][11];
				var topics_included = rapporten[u][12];
				var label_name = rapporten[u][13];
				var printed_reports = rapporten[u][14];
				var label_name_dutch = rapporten[u][15];
				var visible_for = rapporten[u][16];
				var label_color = 		this.label_colors[u] ;
				

		
				
				
				
			// ingeklapt rapport
			output += '<div style="cursor: pointer; display: block;" id="collapse_report_' + rapport_nummer + '" onclick="my_logBook.expand_report(' + rapport_nummer + ',' + true + ')">';
			output += '<table  cellspacing="0" border="0" cellpadding="0" >';
			output += '<tr>';
				output += '<td align="center" valign="center"><div style="width:  30px; height: 23px; overflow: hidden;"></div></td>';
				output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 16px; overflow: hidden;"><b>' + rapport_nummer + '.</b></div></td>';
				output += '<td><div style="padding: 5px 2px 2px 2px; width: 522px; height: 16px; overflow: hidden;">';
				output += '<span style="background-color: '+ label_color +'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> ';
				output += '<b>' + htmlspecialchars(label_name, false) + '</b> ';
				output += '<span style="color: 8d8d8d;"><i>' + htmlspecialchars(rapport_onderwerp) + ' ' + htmlspecialchars(rapport_onderdeel, false) + '</i></span>';
				
				output += '</div></td>';
			output += '</tr>';
			output += '</table>	';
			output += '</div>';
				
				
			//--------------------------------------------------------------------------------------------------------------------------------
			// uitgeklapt rapport
			//--------------------------------------------------------------------------------------------------------------------------------
			output += '<div id="expand_report_'+rapport_nummer+'" style="display: none;">';
				output += '<!-- titel -->';
				output += '<div onclick="my_logBook.expand_report('+rapport_nummer+','+false+')" style=" cursor: pointer">';
				output += '<table  cellspacing="0" border="0" cellpadding="0" >';
					output += '<tr>';
						output += '<td><div style="width:  30px; height: 35px; overflow: hidden;"></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width:  30px; height: 28px; overflow: hidden;"><b>'+rapport_nummer+'.</b></div></td>';
						output += '<td><div style="padding: 5px 2px 2px 2px; width: 702px; height: 28px; overflow: hidden;">';
							output += '<span style="background-color: '+ label_color +'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> ';
							output += '<b>'+ htmlspecialchars(label_name, false)+'</b>';							
						output += '</div></td>';
					output += '</tr>';
				output += '</table>';	
				output += '</div>';



	
			output += '<div id="print" style=" display: block;">';
				output += '<form method="post" action="'+ action_url +'">';
				output += '<input type="hidden" value="edit_label" name="action"> ';	
				output += '<input type="hidden" value="'+project_afk+'" name="project"> ';
				output += '<input type="hidden" value="'+rapport_nummer+'" name="nummer"> ';
				output += '<div style="padding: 0px 40px 0px 40px;">';
					output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
						output += '<table id="table_new_topic" cellspacing="0" border="0" cellpadding="0" >';
						
						
							output += '<tr>';
								output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 20px; overflow: hidden;"><b>Edit Label</b></div></td>';
							output += '</tr>';
					
							output += '<tr>';
								output += '<td>Label name intern: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
								output += '<td colspan="2"><input name="label_name" value="'+escape_double_qoute(label_name)+'" style=" width: 223px;"> max 14 characters</td>';
							output += '</tr>';		

							output += '<tr>';
								output += '<td>Label name extern*: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
								output += '<td colspan="2"><input name="label_name_dutch" value="'+escape_double_qoute(label_name_dutch)+'" style=" width: 223px;"> max 14 characters</td>';
							output += '</tr>'
							
							
							var op1 = ''; var op2 = ''; var op3 = '';
							if (visible_for) {op1 = 'checked';} else if (visible_for == false ) { op2 = 'checked';} else {op3 = 'checked';}
							output += '<tr>';
								output += '<td>Visible for: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
								output += '<td colspan="2">';
									output += '<input '+op1+' type="radio" disabled name="visible_for" value="true">extern ';
									output += '<input '+op2+' type="radio" name="visible_for" value="false">intern ';
									output += '<input '+op3+' type="radio" name="visible_for" value="">both ';
								output +=  '</td>';
							output += '</tr>';	
							
							
		
							
							output += '<tr>';
								output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;">* features are in development</div></td>';
							output += '</tr>';								
	
							output += '<tr>';
								output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;"><b><br>Included topics: </b></div></td>';
							output += '</tr>';			
						
				
							

							
		
							
							output += '<tr>';
								output += '<td colspan="3">topics:</td>';
							output += '</tr>';
							
							//3 kolommen met topics.
							output += '<tr>';		
							
							
							var topics2 = topics_included.myconcat(filtered_topics);
								
							var topics_length = topics2.length;
							var num_rows_topics = Math.ceil(topics_length/3) ;
	
							
							for (var q = 0; q < 3; q++ ) {
									
									output += '<td valign="top">';
										output += '<div style=" overflow: hidden; width: 223px;"> ';
											output += '<table cellspacing="0" border="0" cellpadding="0">';
	
												if ((q == 0) || (q==1 && topics_length > 1 ) || (q==3 && num_rows_topics * 3 - topics_length == 0 ) ) {
													var loop = num_rows_topics;
												} else {
													if (q == 1)  {
														var loop = 0;
													} else {
														var loop = num_rows_topics - (num_rows_topics * 3 - topics_length );
													}
												}  
	
											
											for (var p = 0; p < loop; p++) {
												var k = q * num_rows_topics + p;
												var r = topics2[k];												
												
												var topic_number = topics[r][0];
												var topic_title_eng = topics[r][1];
												var topic_title_dut = topics[r][2];
												var topic_extern = topics[r][3];
												var topic_priority = topics[r][4];
												var topic_accomplished = topics[r][5];
												
											
												var selected_topics = '';
												
												if (topics_included.in_array(topic_number)) {
														selected_topics = 'checked';
												}
												
		
												output += '<tr>';
													output += '<td>';
													output += '<input type="hidden" value="'+topic_number+'" name="topic_index_'+ k +'"> ';
													output += '<input '+ selected_topics +' type="checkbox" value="true" name="topic_check_'+ k +'"> ';
													output += '</td><td> ';
													output += topic_number + ': ';
													
													
													if (topic_extern) {output += '<span style="color: orange;"> <b> [ex] </b> </span> ';}
													if (topic_priority == 'high') {output += '<span style="color: red;"> <b> ! </b> </span> ';}
													if (topic_accomplished) {output += '<img src="images/close.png">';}
													
													
													if (topic_extern) {
														output += topic_title_dut;
													} else {
														output += topic_title_eng;
													}
													output += '</td>';
												output += '</tr>';
		
												
											}
											
											output += '</table>';
										output += '</div>';
									output += '</td>';
							}						
							
							output += '</tr>';
							
							output += '<tr>';
								output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;"><b><br>Default report settings for label: </b></div></td>';
							output += '</tr>';							
							
							
							output += '<tr>';
								output += '<td>report name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
								output += '<td colspan="2"><input name="report_name" value="'+ escape_double_qoute(rapport_naam)+'" style=" width: 223px;">(hidden on report)</td>';
							output += '</tr>';		
			
							output += '<tr>';
								output += '<td>subject:</td>';
								output += '<td colspan="2"><input name="subject" value="'+escape_double_qoute(rapport_onderwerp)+'" style=" width: 223px;"></td>';
							output += '</tr>';		
							
							output += '<tr>';
								output += '<td>project part: </td>';
								output += '<td colspan="2"><input name="project_part" value="'+escape_double_qoute(rapport_onderdeel)+'" style=" width: 223px;"></td>';
							output += '</tr>';
							
							var arch_check = '';
							if (show_arch) {arch_check = 'checked'}
							output += '<tr>';
								output += '<td>architect: </td>';
								output += '<td colspan="2"><input disabled value="'+architect+'" style=" width: 223px;"><input value="true" title="Show on report" type="checkbox" '+arch_check+' name="show_architect">(to be edited in Admin)</td>';
							output += '</tr>';	

							var constr_check = '';
							if (show_constr ) {constr_check = 'checked'}							
							output += '<tr>';
								output += '<td>constructeur: </td>';
								output += '<td colspan="2"><input disabled value="'+constructeur+'" style=" width: 223px;"><input value="true" title="Show on report" type="checkbox" '+constr_check+' name="show_constructeur">(to be edited in Admin)</td>';
							output += '</tr>';	
	
							var opdr_check = '';
							if (show_opdr ) {opdr_check = 'checked'}
							output += '<tr>';
								output += '<td>opdrachtgever: </td>';
								output += '<td colspan="2"><input disabled value="'+opdrachtgever+'" style=" width: 223px;"><input value="true" title="Show on report" type="checkbox" '+opdr_check+' name="show_opdrachtgever">(to be edited in Admin)</td>';
							output += '</tr>';	
	
							var afb_check = '';
							if (show_afb ) {afb_check = 'checked'}	
							output += '<tr>';
								output += '<td>afbeelding: </td>';
								output += '<td colspan="2"><input disabled value="'+afbeelding+'" style=" width: 223px;"><input value="true" title="Show on report" type="checkbox" '+afb_check+' name="show_afbeelding">(to be edited in Admin)</td>';
							output += '</tr>';											
		
							var eigenaar_check = '';
							if(show_eig) {eigenaar_check = 'checked';}
							output += '<tr>';
								output += '<td>author: </td>';
								output += '<td colspan="2"><select name="eigenaar" style=" width: 223px;">';
									for (var t = 0; t < projectmanagers.length; t++) {
										var option_selected = '';
										if (projectmanagers[t][0] == rapport_eigenaar) {
											option_selected = 'selected';
										}
										output += '<option '+ option_selected +' value="'+projectmanagers[t][0] +'"> ' + projectmanagers[t][1] + '</option>';
										
									}
								output += '</select><input value="true" title="Show on report" type="checkbox" '+eigenaar_check+' name="show_eigenaar"></td>';
							output += '</tr>';									
																			
											
							var op1 = ''; var op2 = ''; var op3 = '';
							if (status) {op1 = 'checked';} else if (status == false ) { op2 = 'checked';} else {op3 = 'checked';}
							output += '<tr>';
								output += '<td>topic status: </td>';
								output += '<td colspan="2">';
									output += '<input '+op1+' type="radio" name="status" value="true">open ';
									output += '<input '+op2+' type="radio" name="status" value="false">closed ';
									output += '<input '+op3+' type="radio" name="status" value="">both ';
								output +=  '</td>';
							output += '</tr>';	
							
							var op1 = ''; var op2 = ''; var op3 = '';
							if (extern) {op2 = 'checked';} else if (extern == false ) { op1 = 'checked';} else {op3 = 'checked';}
							output += '<tr>';
								output += '<td>published: </td>';
								output += '<td colspan="2">';
									output += '<input '+op1+' type="radio" name="extern" value="false">intern ';
									output += '<input '+op2+' type="radio" name="extern" value="true">extern ';
									output += '<input '+op3+' type="radio" name="extern" value="">both ';
								output +=  '</td>';
							output += '</tr>';																		
												
							output += '<tr>';
								output += '<td colspan="3"><input name="save" type="submit" value="Save"><input name="save_and_new_rapport" type="submit" value="Save and Create new rapport"></td>';
							output += '</tr>';
							
							
																	
						output += '</table >';
					output += '</div>';
					output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
					output += '</div>';
				output += '</div>';
				output += '</form>';
			output += '</div>';					

			
			if (printed_reports.length > 0) {
			output += '<div id="printed" style=" display: block;">';
				output += '<form method="post" action="'+ action_url +'">';
				output += '<input type="hidden" value="new_report" name="action"> ';	
				output += '<input type="hidden" value="'+project_afk+'" name="project"> ';
				output += '<input type="hidden" value="'+rapport_nummer+'" name="nummer"> ';
				output += '<div style="padding: 0px 40px 0px 40px;">';
					output += '<div style="padding: 5px 5px 5px 5px; background: AliceBlue ;" >';
						output += '<table id="table_new_topic" cellspacing="0" border="0" cellpadding="0" >';			
			
							
							
								output += '<tr>';
								output += '<td colspan="3"><div style="padding: 3px 2px 2px 2px; width:  300px; height: 30px; overflow: hidden;"><b><br>Created reports: </b></div></td>';
								output += '</tr>';
								
								for (var p = 0; p < printed_reports.length; p++) {
									var versie = printed_reports[p][0];
									var datum = printed_reports[p][1];
									var rapport_naam_printed = printed_reports[p][3];
									output += '<tr>';
									output += '<td></td>';
									output += '<td colspan="2" style="height: 23px;">' + datum + ' ' + htmlspecialchars(rapport_naam_printed,false) + ' <a target="_blanc" href="print.php?project=' + project_afk + '&rapport_nummer=' + rapport_nummer + '&versie=' + versie + '&session_id=' + this.data[0][3] + '"> download </a></td>';
									output += '</tr>';
								}
							
							
						
										
						output += '</table >';
					output += '</div>';
					output += '<div style="height: 15px; width: 500px; overflow: hidden;" >';
					output += '</div>';
				output += '</div>';
				output += '</form>';
			output += '</div>';				
			}
			
					
		output += '</div>';	
		
			
			

			
			
	
		//--------------------------------------------------------------------------------------------------------------------------------	
		// blue line
		//--------------------------------------------------------------------------------------------------------------------------------		
		output += '<div style="background: #284975; overflow: hidden; width: 772px; height: 2px;"></div>';				
				
			}
		
			

		this.content.innerHTML = output;
		
	}
}	





	
