﻿/* 	For easier recognition of functions, all methods and global vars 
	specific for showing the details of an Unort should start with DU_
*/

// ========================= Detail unort variables ========================= //

// General

var DU_form_redirect = 2;

var DU_stored_step= "";
var DU_targetDragmarker;
var DU_UNORT_ID = "";

// form 1 - info
var DU_form1_unort_id = "";
var DU_form1_quarter_id = "";
var DU_form1_type = "";
var DU_form1_solved = "0";
var DU_form1_nickname = "";
var DU_form1_user_id = "";
var DU_form1_date = "";
var DU_form1_title = "";
var DU_form1_text = "";
var DU_form1_voters = "";
var DU_form1_vote_yes = "";
var DU_form1_vote_no = "";
var DU_form1_categories = "";

// form 2 - comments
var DU_form2_comments = "";
var DU_form2_commentCount = "";
var DU_form2_commentCountFromOthers = "";
var DU_form2_media = "";

// form 3 - add comments
var DU_form3_new_comment = "Kommentar kann nach dem Speichern nicht mehr verändert werden";
var DU_form3_comment_type = "0";

// form 4 - media
var DU_form4_media = "";
var DU_form4_mediaCount = "";
var DU_form4_mediaCountFromOthers = "";
var DU_form4_uploadWindow;

// form 5 - add media

// form 6 - ratings
var DU_form6_category_votes = "";
var DU_form6_category_info = new Array();
var DU_form6_voters_categories = 0;

// form 7 - rate
var DU_form7_vote_unort = 0;
var DU_form7_vote_categories = 0;
var DU_form7_vote_btn = [ [new Image(), new Image()], [new Image(), new Image()] ];
DU_form7_vote_btn[0][0].src = "img/btn/btn_no.gif";
DU_form7_vote_btn[0][1].src = "img/btn/btn_no_a.gif";
DU_form7_vote_btn[1][0].src = "img/btn/btn_yes.gif";
DU_form7_vote_btn[1][1].src = "img/btn/btn_yes_a.gif";
var DU_form7_vote_selection = -1;

// form 8 - info
var DU_form8_new_date = "";
var DU_form8_new_title = "";
var DU_form8_new_text = "";
var DU_form8_type = "";
var DU_form8_move_btn = [ new Image(), new Image() ];
DU_form8_move_btn[0].src = "img/btn/btn_move_d.png";
DU_form8_move_btn[1].src = "img/btn/btn_move.png";

// Holding image references used in greybox
var image_set = [];

// ========================= Init Form code below ========================= //

function DU_initAndOpenDetailUnortWindow( dragmarker, id ) {
	DU_targetDragmarker = dragmarker;
	DU_UNORT_ID = id;
	setHash(DU_UNORT_ID);
	
	// console.log('disable scroll');
	map.disableScrollWheelZoom();
	// Reset the variables
	
	// form1
	DU_form1_unort_id = "";
	DU_form1_quarter_id = "";
	DU_form1_type = "";
	DU_form1_solved = "0";
	DU_form1_nickname = "";
	DU_form1_user_id = "";
	DU_form1_date = "";
	DU_form1_title = "";
	DU_form1_text = "";
	DU_form1_voters = "";
	DU_form1_vote_yes = "";
	DU_form1_vote_no = "";
	
	// form2
	DU_form2_comments = "";
	DU_form2_commentCount = "";
	DU_form2_commentCountFromOthers = "";
	
	// form3
	DU_form3_new_comment = "Kommentar kann nach dem Speichern nicht mehr verändert werden";

	// form4
	DU_form4_media = "";
	DU_form4_mediaCount = "";
	DU_form4_mediaCountFromOthers = "";
	
	// form6
	DU_form6_category_votes = "";
	DU_form6_category_info = new Array();
	
	// form 8 - info
	var DU_form8_new_date = "";

	//DU_init_step1();
	
	// Group 4 ajax calls for info before loading any info screen
	window.addEvent('domready', function() {
		
		
		
		var xmlDetails = "";
		var xmlComments = "";
		var xmlMedia = "";
		var xmlVoting = "";
		
		var queryDetails = "sys/detailunort.php?query_type=unort_info&place_id=" + DU_UNORT_ID;
		var queryComments = "sys/comments.php?place_id=" + DU_UNORT_ID;
		var queryMedia = "sys/media.php?place_id=" + DU_UNORT_ID;
		var queryVoting = "sys/voting.php?action=checkVoting&user_id="+ globalStatus.user_id  +"&place_id=" + DU_UNORT_ID;
				
		// Retrieve info about the unort
		var xhr1 = new Ajax(queryDetails, {
			method: 'get',
			evalScripts: true,
			onComplete: function(response, responseXML) {
							xmlDetails = responseXML
						}
		});
		
		// Retrieve info about the comments
		var xhr2 = new Ajax(queryComments, {
				method: 'get',
				evalScripts: true,
				onComplete: function(response, responseXML) {
								xmlComments = responseXML
							}
		});
		
		// Retrieve info about the media
		var xhr3 = new Ajax(queryMedia, {
				method: 'get',
				evalScripts: true,
				onComplete: function(response, responseXML) {
								xmlMedia = responseXML
							}
		});
		
		// Retrieve info about the voting
		var xhr4 = new Ajax(queryVoting, {
				method: 'get',
				evalScripts: true,
				onComplete: function(response, responseXML) {
								xmlVoting = responseXML
							}
		});
		
		xhr1.setHeader('Pragma', 'no-cache');
		xhr1.setHeader('Cache-Control', 'must-revalidate');
		xhr1.setHeader('If-Modified-Since', document.lastModified);
		xhr2.setHeader('Pragma', 'no-cache');
		xhr2.setHeader('Cache-Control', 'must-revalidate');
		xhr2.setHeader('If-Modified-Since', document.lastModified);
		xhr3.setHeader('Pragma', 'no-cache');
		xhr3.setHeader('Cache-Control', 'must-revalidate');
		xhr3.setHeader('If-Modified-Since', document.lastModified);
		xhr4.setHeader('Pragma', 'no-cache');
		xhr4.setHeader('Cache-Control', 'must-revalidate');
		xhr4.setHeader('If-Modified-Since', document.lastModified);
		
		var group = new Group(xhr1, xhr2, xhr3,xhr4);
		group.addEvent('onComplete', function()  {
			DU_handleGetUnortInfoEasy(xmlDetails);
			DU_handleGetCommentsEasy(xmlComments);
			DU_handleGetMediaEasy(xmlMedia);
			DU_handleCheckVotesLeftEasy(xmlVoting);			
			switch (OPEN_TAB){
				/*
				case 8:			 	
					DU_init_step8();			  	
					break;
				*/
			 default:
			  	DU_step2();
			  	break;
			}
		});
		xhr1.request();
		xhr2.request();
		xhr3.request();
		xhr4.request();
	});	
}

// ========================= Form code below ========================= //


function DU_closeWindow() {
	DU_saveState();
	
	globalStatus.open_window = false;
	globalStatus.place_id = null;
	if (overlayWindow != null) {
		// overlayWindow.remove();
		map.removeOverlay( overlayWindow );
		overlayWindow = null;
	}
	map.enableScrollWheelZoom();
	enableDragging();
}

function DU_composeDetailUnort2Window(){ // Kommentare
	var form2 = 
		'<div class="ewin detail_unort" id="unort_details_comments1" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' +
			'<form name="unort" method="post" action="" accept-charset="utf-8">' +
				'<div class="topbox">' +
					'<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
					'<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
				'</div>' +
				'<div class="bodybox">' +
				'<div class="column tab">' +
					'<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei_a.png" /></a>' +
					'<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med.png" title="Galerie mit Bildern zum Punkt" /></a>' +
					'<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
					DU_showSettings() +
					'<img src="img/tab/tab_base.png" />' +
				'</div>' +
				'<div class="column">' +
				'<div class="author_info w_shl">Autor des Unorts: '+ 
					user_list_view_link( DU_form1_user_id, DU_form1_nickname ) + ' - ' + DU_form8_new_date + 
					reporting_and_unort_list_view_link(DU_form1_unort_id) +
				'</div>' +
			'</div>' +
			'<div class="dark_line"></div>' +
				'<div class="window">' +
				'<table><tr>' +
					'<td class="media">' +
						DU_form2_media +
						'<div class="column w_hl">'+ DU_form1_title +'</div>';
	
	form2 +=	'<div class="column w_txt">' + DU_form1_text + '</div>' +
					'</td>' +
				'</tr></table>';
	
	if (DU_form1_categories != '') {
			form2 += '<div class="column w_txt"><span class="w_shl">Kategorien:</span> ' + DU_form1_categories + '</div>';
	}
	
	if (DU_form2_commentCount > 0) {
		form2 +=
					'<div class="dark_line"></div>' +
					'<div class="column count w_shl">Kommentare: '+ DU_form2_commentCount + '</div>' +
					'<div class="dark_line"></div>' +
					DU_form2_comments;
	}
	
		
	form2 += '		</div>';
	
	if (checkLoggedIn( false )){
		form2+=
				'<div class="btn_area">'+
					'<div class="right">'+
						'<a href="javascript:DU_form2_submit();">'+
							'<img src="img/btn/comment_new.png" title="Einen neuen Kommentar zum Unort verfassen" />'+
						'</a>'+
					'</div>' +
		'		</div>';
	} else {
		form2 +=
				'<div class="btn_area">'+
					'<div class="right">'+
						'Bitte erst <a href="javascript:loginClicked();">anmelden</a> oder '+
						'<a href="sys/register.php">registrieren</a>!&nbsp;&nbsp;'+
						'<img src="img/btn/comment_new_d.png" title="Einen neuen Kommentar zum Unort verfassen" />'+
					'</div>' +
		'		</div>';
	}
	/*
	//mf
	form2+=
		'		<div class="btn_area">' +
		'			<div class="right"><a href="javascript:DU_saveState();DU_step3();"><img src="img/btn/btn_new_comment.png" title="Einen neuen Kommentar zum Unort verfassen" /></a></div>' +
		'		</div>';
	*/
	
	form2 +=
		'	</div>' +
		'	<div class="footerbox">' +
		'		<img src="img/win/win_point.gif" />' +
		'	</div>' +
		'</form>' +
		'</div>';
	return form2;
}

function DU_form2_submit() {
	if (!checkLoggedIn( true ))
		return;
	
	DU_saveState();
	DU_step3();
}


function DU_composeDetailUnort3Window(){ // neuer Kommentar
	var form3 =
		'<div class="ewin detail_unort" id="unort_details_comments2" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' + 
		'<form name="unort_details_comments2" method="post" action="" accept-charset="utf-8">' + 
		'	<div class="topbox">' +
		'		<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
		'		<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
		'	</div>' +
		'	<div class="bodybox">' + 
		'		<div class="column tab">' +
		'			<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei_a.png" /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med.png" title="Galerie mit Bildern zum Punkt"  /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
					DU_showSettings() +
		'			<img src="img/tab/tab_base.png" />' +
		'		</div>' +
		'		<div class="column w_hl">Neuer Kommentar</div>' + 
		'		<div class="dark_line"></div>' +
		'		<div class="column">' +
		'			<iframe src="sys/edit2.iframe.php?type=comm" name="editframe" id="editframe" class="if_addcomment"></iframe>'+
		'		</div>' +
		'		<div class="dot_line"></div>' + 
		'		<div class="btn_area">' +
		'			<div class="left">' +
		'			<a href="javascript:DU_form3_cancel();"><img src="img/btn/btn_abbrechen.gif" alt="abbrechen" />' +
		'			</div>' +
		'			<div class="right">' +
		'			<a href="javascript:DU_form3_submit();"><img src="img/btn/comment_save.png" alt="Kommentar speichern" />' +
		'		</div>' + 
		'		</div>' + 
		'	</div>' + 
		'	<div class="footerbox">' + 
		'		<img src="img/win/win_point.gif" />' + 
		'	</div>' + 
		'</form>' + 
		'</div>';
	return form3;
}

function DU_form3_cancel() {
	DU_saveState();
	DU_init_step2();
}
function DU_form3_submit() {
	//DU_form3_new_comment = editframe.document.getElementById( "text" ).value;
	if (!checkLoggedIn( true ))
		return;
	
	DU_form3_new_comment = encodeURIComponent( frames[0].document.form.text.value );
	if (DU_form3_new_comment == '' || DU_form3_new_comment == IN_input_defaults['du1'][1])
		displayMessage( "Sie haben keinen Kommentar geschrieben." );
	else {
		DU_saveState();
		DU_storeNewComment( DU_UNORT_ID );
	}
}

function DU_composeDetailUnort4Window(){ // Galerie
	var form4 = 
		'<div class="ewin detail_unort" id="unort_details_media" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' + 
		'<form name="unort" method="post" action="" accept-charset="utf-8">' + 
		'	<div class="topbox">' +
		'		<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
		'		<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
		'	</div>' +
		'	<div class="bodybox">' + 
		'		<div class="column tab">' + 
		'			<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei.png" /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med_a.png" id="tab_media" title="Galerie mit Bildern zum Punkt"  /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
					DU_showSettings() +
		'			<img src="img/tab/tab_base.png" />' +
		'		</div>' + 
		'		<div class="column">' + 
		'			<div class="author_info w_shl">Dateien: '+ DU_form4_mediaCount + '</div>' + 
					reporting_and_unort_list_view_link( DU_form1_unort_id ) +
		//mf '			<div class="right"><img src="img/btn/btn_rss.gif" /></div>' + 
		'		</div>' + 
		'		<div class="dark_line"></div>' +
		'		<div class="window">' + 
					DU_form4_media +
		'		</div>';
		
		if (checkLoggedIn( false )) {
			form4 +=
						'<div class="btn_area">'+ 
							'<div class="right">'+
								'<a href="javascript:DU_form4_submit();">'+
									'<img src="img/btn/new_media.png" title="Ein neues Bild in die Galerie hochladen" />'+
								'</a>'+
							'</div>' + 
				'		</div>';
		} else {
			form4 +=
						'<div class="btn_area">' + 
							'<div class="right">'+
								'Bitte erst <a href="javascript:loginClicked();">anmelden</a> oder '+
								'<a href="sys/register.php">registrieren</a>!&nbsp;&nbsp;'+
								'<img src="img/btn/new_media_d.png" title="Ein neues Bild in die Galerie hochladen" />'+
							'</div>'+ 
						'</div>';
		}
		
		form4 +=
		'	</div>' + 
		'	<div class="footerbox">' + 
		'		<img src="img/win/win_point.gif" />' + 
		'	</div>' + 
		'</form>' + 
		'</div>';
	return form4;
}

function DU_form4_submit() {
	if (!checkLoggedIn( true ))
		return;
	
	return popupAddMediaUploadWindow();
}

function DU_composeDetailUnort5Window() { // ?????
	var form5 = 
		'<div class="ewin detail_unort" id="unort_details_media_new" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' +
		'<form name="unort" method="post" action="" accept-charset="utf-8">' +
		'	<div class="topbox">' +
		'		<div class="title txt_win">Details zum Unort ' + DU_form1_unort_id + ' - ' + DU_form1_title + '</div>' +
		'		<div class="closer"><img src="img/win/win_x.gif" onclick="DU_saveState();overlayWindow.hide();"/></div>' +
		'	</div>' +
		'	<div class="bodybox">' +
		'		<div class="container tab">' +
		'			<img src="img/tab/tab_bei.png" onclick="DU_saveState();DU_init_step2();"/>' +
		'			<img src="img/tab/tab_med_a.png" onclick="DU_saveState();DU_init_step4();"/>' +
		'			<img src="img/tab/tab_bew.png" onclick="DU_saveState();DU_init_step6();"/>' +
			DU_showSettings() +
		'			<img src="img/tab/tab_base.png" />' +
		'		</div>' +
		'		<div class="container">' +
			    '       <div align="center"><img src="img/btn/btn_upload_media.gif" onClick="return popupAddMediaUploadWindow()"/></div>' +
		'			</div>' +
		'		</div>' +
		'	</div>' +
		'	<div class="footerbox">' +
		'		<img src="img/win/win_point.gif" />' +
		'	</div>' +
		'</form>' +
		'</div>';
	return form5;
}

function popupAddMediaUploadWindow() {
	DU_form4_uploadWindow = window.open(
			"sys/fileupload.php?place_id="+DU_UNORT_ID, 
			"popup_id", 
			"z-lock=yes,resizable=no,personalbar=no,location=no,menubar=no,depent,width=380,height=320,screenX=400,screenY=300"
		);
	DU_form4_uploadWindow.focus();
}

function refreshMedia() {
	DU_init_step4();
}

function getLatestMedia(param){
}

function DU_composeDetailUnort6Window() { // Bewertungen Ergebnisse
	var form6 = 
		'<div class="ewin detail_unort" id="unort_details_rating" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' +
		'<form name="unort" method="post" action="" accept-charset="utf-8">' +
		'	<div class="topbox">' +
		'		<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
		'		<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
		'	</div>' +
		'	<div class="bodybox">' +
		'		<div class="column tab">' +
		'			<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei.png" /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med.png" title="Galerie mit Bildern zum Punkt"  /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew_a.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
			DU_showSettings() +
		'			<img src="img/tab/tab_base.png" />' +
		'		</div>' +
		'		<div class="column">' +
		'			<div class="author_info w_shl">Ergebnisse der Abstimmung</div>' +
					reporting_and_unort_list_view_link(DU_form1_unort_id) +
		'		</div>' +
		'		<div class="dark_line"></div>' +
		'		<div class="column bullet w_shl">Ist dieser Ort ein Unort?</div>' +
		'		<div class="column w_txt">' +
		'			<table class="rate">';
		
		
		var width_yes = 125;
		var width_no = 125;	
		if (DU_form1_voters > 0){
			width_yes = Math.round((DU_form1_vote_yes / DU_form1_voters)*250);
			width_no = 250 - width_yes;
		}
		
		form6 +=	'<tr><td id="yes"><span class="bold">JA</span><br />' + DU_form1_vote_yes+ '</td>' +
								'<td id="bar">' +
								'<img src="img/win/bar_element_green.png" width="'+ width_yes+ '" height="10"/><img src="img/win/bar_element_red.png" width="' + width_no + '" height="10" />' +
								'<br />' + DU_form1_voters + ' Stimmen gesamt' +
								'</td>' +
								'<td id="no"><span class="bold">NEIN</span><br />'+ DU_form1_vote_no+'</td>'+
							'</tr>'+
						'</table>' +
					'</div>' +
					'<div class="dot_line"></div>' +
					DU_showVotingCategoriesInfo();
		
		if (!checkLoggedIn( false )) {
			form6 +=
					'<div class="btn_area">' +
						'<div class="right">'+
							'Bitte erst <a href="javascript:loginClicked();">anmelden</a> oder '+
							'<a href="sys/register.php">registrieren</a>!&nbsp;&nbsp;'+
							'<img src="img/btn/btn_vote_d.gif" />'+
						'</div>' +
					'</div>';
		} else if (!DU_votesLeft()) {
			form6 +=
					'<div class="btn_area">' +
						'<div class="right">'+
							'Sie haben bereits f&uuml;r diesen Unort abgestimmt! '+
							'<img src="img/btn/btn_vote_d.gif" />'+
						'</div>' +
					'</div>';
		} else {
			form6 +=
					'<div class="btn_area">' +
						'<div class="right">'+
							'<a href="javascript:DU_form6_submit();">'+
								'<img src="img/btn/btn_vote.gif" />'+
							'</a>'+
						'</div>' +
					'</div>';
		}
		
		form6 +=
				'</div>' +
				'<div class="footerbox">' +
					'<img src="img/win/win_point.gif" />' +
				'</div>' +
			'</form>' +
		'</div>';
	return form6;
}

function DU_form6_submit() {
	if (!checkLoggedIn( true ))
		return;
	
	DU_saveState();
	DU_step7();
}

function DU_composeDetailUnort7Window() { // Bewertungen Abstimmen
	var form7 = 
		'<div class="ewin detail_unort" id="unort_details_vote" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' +
		'<form name="unort_details_vote" accept-charset="utf-8">' +
		'	<div class="topbox">' +
		'		<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
		'		<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
		'	</div>' +
		'	<div class="bodybox">' +
		'		<div class="column tab">' +
		'			<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei.png" /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med.png" title="Galerie mit Bildern zum Punkt"  /></a>' +
		'			<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew_a.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
		DU_showSettings() +
		'			<img src="img/tab/tab_base.png" />' +
		'		</div>' +
		'		<div class="column">' +
		'			<div class="author_info w_shl">Abstimmen und Unorte bewerten</div>' +
					reporting_and_unort_list_view_link(DU_form1_unort_id) +
		'		</div>' +
		'		<div class="dark_line"></div>' +
		'		<div class="column bullet w_shl">Sind Sie der Ansicht, dass dies ein Kölner Unort ist?</div>' +
		'		<div id="yes_no">' +
		'			<div id="yes"><a href="javascript:DU_form7_select(1);"><img src="img/btn/btn_yes.gif" id="btn_yes" /></a></div>' +
		'			<div id="no"><a href="javascript:DU_form7_select(0);"><img src="img/btn/btn_no.gif" id="btn_no" /></a></div>' +
		'		</div>' +
		'		<div class="dot_line"></div>';
		
	if (DU_form6_category_info.length != 0) {
		form7 +=
			'		<div class="column bullet w_shl">Treffen die folgenden Kategorien auf diesen Ort zu?</div>' +
			'		<div class="window w_txt">' +
			'			<table class="cat">' +
			'				<tr>' +
			'					<th class="name"></td>' +
			'					<th class="yes">ja</td>' +
			'					<th class="no">nein</td>' +
			'					<th class="null">wei&szlig; nicht</td>' +
			'				</tr>';
		for (i = 0; i < DU_form6_category_info.length; i +=5) {
			var percent = DU_form6_category_info[i+4];
			form7 += 
				'				<tr>' +
				'					<td class="name">' + DU_form6_category_info[i+1] +'</td>' +
				'					<td class="yes"><input type="radio" name="vote'+(i/5)+'" value="1" /></td>' +
				'					<td class="no"><input type="radio" name="vote'+(i/5)+'" value="0" /></td>' +
				'					<td class="null"><input type="radio" name="vote'+(i/5)+'" value="2" checked="checked" /></td>' +
				'				</tr>';
		}
		
		form7 +=
			'			</table>' +
			'		</div>';
	}
	
	
	form7 +=
		'		<div class="btn_area">' +
		'			<div class="right">';
		
	if (DU_form7_vote_selection == -2)
		form7 += 'Bitte erst abstimmen! ';
		
	form7 += '<a href="javascript:DU_form7_submit();"><img src="img/btn/btn_save.gif" /></a></div>' +
		'		</div>' ;
					
	form7 +=
		'	</div>' +
		'	<div class="footerbox">' +
		'		<img src="img/win/win_point.gif" />' +
		'	</div>' +
		'</form>' +
		'</div>';
	
	return form7;
}

function DU_form7_select( nr ) {
	if (nr) {
		document.getElementById( "btn_no" ).src = DU_form7_vote_btn[0][0].src;
		document.getElementById( "btn_yes" ).src = DU_form7_vote_btn[1][1].src;
		DU_form7_vote_selection = 1;
	} else {
		document.getElementById( "btn_no" ).src = DU_form7_vote_btn[0][1].src;
		document.getElementById( "btn_yes" ).src = DU_form7_vote_btn[1][0].src;
		DU_form7_vote_selection = 0;
	}
}

function DU_form7_submit() {
	if (!checkLoggedIn( true ))
		return;
	
	if(DU_userVoted()) {
		var votes = new Array();
		for (i = 0 ; i < DU_form6_category_info.length; i += 5){
			for (j = 0; j < 2; j++){
				var radio = document.forms['unort_details_vote'].elements['vote'+(i/5)][j];
				if (radio.checked){
					votes.push(DU_form6_category_info[i]);
					votes.push(radio.value);
				}
			}
		}
		var voteList = votes.join(','); // merge votes
		
		DU_voteUnort( DU_form7_vote_selection, voteList );
	} else {
		DU_form7_vote_selection = -2;
		DU_step7();
	}
}

function DU_composeDetailUnort8Window() { // Einstellungen
	var select = '<select name="place_type" id="place_type" size="1">';
	for (var i=1; i<5; i++) {
		if (DU_form8_type == i) {
			select += '<option value="'+ i +'" selected="selected">'+ unort_types[i] +'</option>';
		} else {
			select += '<option value="'+ i +'">'+ unort_types[i] +'</option>';
		}
	}
	select += '</select>';
		
	
	var form8 = 
		'<div class="ewin detail_unort" id="unort_details_settings" onMouseOver="disableDragging()" onMouseOut="enableDragging()">' +
		'<form name="unort_details_settings" method="post" action="" accept-charset="utf-8">' +
			'<div class="topbox">' +
				'<div class="title">Unort ' + DU_form1_unort_id + ' - ' + trimStr( DU_form1_title, 34 ) + '</div>' +
				'<div class="closer"><a href="javascript:DU_closeWindow();"><img src="img/win/win_x.gif" /></a></div>' +
			'</div>' +
			'<div class="bodybox">' +
				'<div class="column tab">' +
					'<a href="javascript:DU_saveState();DU_init_step2();"><img src="img/tab/tab_bei.png" /></a>' +
					'<a href="javascript:DU_saveState();DU_init_step4();"><img src="img/tab/tab_med.png" title="Galerie mit Bildern zum Punkt"  /></a>' +
					'<a href="javascript:DU_saveState();DU_init_step6();"><img src="img/tab/tab_bew.png" title="Bewertungen ansehen und eigene abgeben" /></a>' +
					'<a href="javascript:DU_saveState();DU_init_step8();"><img src="img/tab/tab_ein_a.png" /></a>' +
					'<img src="img/tab/tab_base.png" />' +
				'</div>' +
				'<div class="column">' +
					'<div class="author_info w_shl">Einstellungen des Unorts ändern</div>' +
						reporting_and_unort_list_view_link( DU_form1_unort_id ) +
				'</div>' +
				'<div class="dark_line"></div>';
	if (isAdmin()) {
		form8 +=
				'<div class="column w_txt"><input type="checkbox" name="solved" id="solved" value="1" ';
		if (DU_form1_solved == "1")
			form8 += 'checked="checked" ';
		form8 += '/> Das Problem des Unorts wurde gelößt.</div>';
	} else {
		form8 +=
				'<div class="column w_txt">Bitte beachten: Unorte können nur verändert oder entfernt werden, solange kein anderer Teilnehmer Kommentare oder Dateien ergänzt.</div>';
	}
	form8 +=
				'<div class="dot_line"></div>' +
				'<div class="column w_shl">' +
					'<table width="95%"><tr>' +
						'<td>' +
							'<input type="text" name="date_noticed" id="date_noticed" disabled="disabled" value="' + DU_form8_new_date + '" /> ' + 
							'<a href="javascript:calendarShow(2);"><img src="img/win/btn_cal.gif" title="Kalender öffnen für Datumseingabe" /></a>' +
						'</td>' +
						'<td align="right">' + select + '</td>' +
					'</tr></table>' +
				'</div>' +
				'<div class="dot_line"></div>' +
				'<div class="column">' +
					'<iframe src="sys/edit2.iframe.php?type=edit" name="editframe" id="editframe" class="if_editunort"></iframe>'+
				'</div>' +
				'<div class="btn_area">' +
					'<div class="left">' +
						'<a href="javascript:DU_deleteUnort();"><img src="img/btn/delete_place.png" alt="Unort löschen" /></a>' +
					'</div>' +
					'<div class="right">' +
						'<a href="javascript:DU_form8_move();"><img id="btn_move" src="img/btn/btn_move.png" /></a>&nbsp;&nbsp;' +
						'<a href="javascript:DU_form8_submit();"><img src="img/btn/btn_save.gif" /></a>' +
					'</div>' +
				'</div>' +
			'</div>' +
			'<div class="footerbox">' +
				'<img src="img/win/win_point.gif" />' +
			'</div>' +
		'</form>' +
		'</div>';	
	return form8;
}

function DU_form8_move() {
	document.getElementById( "btn_move" ).src = DU_form8_move_btn[0].src;
	unortMarkersByID['u'+ DU_form1_unort_id ].enableDragging();
}

function DU_form8_submit() {
	document.getElementById( "btn_move" ).src = DU_form8_move_btn[1].src;
	
	DU_form8_new_title = frames[0].document.form.title.value;
	DU_form8_new_text = frames[0].document.form.text.value;
	if (!checkLoggedIn( true ))
		return;
	
	DU_saveState(); 
	DU_modifyUnort(); 
}

// ========================= Form loading and data storage for each form ========================= //

function DU_saveState(){
	if (DU_stored_step == 1)
		DU_storeDataFromStep1();
	else if (DU_stored_step == 2)
		DU_storeDataFromStep2();
	else if (DU_stored_step == 3)
		DU_storeDataFromStep3();
	else if (DU_stored_step == 4)
		DU_storeDataFromStep4();
	else if (DU_stored_step == 5)
		DU_storeDataFromStep5();
	else if (DU_stored_step == 6)
		DU_storeDataFromStep6();
	else if (DU_stored_step == 7)
		DU_storeDataFromStep7();
	else if (DU_stored_step == 8) {
		DU_storeDataFromStep8();
	}
}

function DU_init_step1(){	
	// Open the first window
	DU_form_redirect = 2;
	DU_getUnortInfo();
}


function DU_step1(){

}


function DU_storeDataFromStep1(){
	
}

function DU_init_step2(){
	DU_getComments();
}

function DU_step2(){
	DU_stored_step = 2;
	if (overlayWindow != null)
		overlayWindow.openOnMarker( DU_targetDragmarker, DU_composeDetailUnort2Window() );
	if (NEW_UNORT) {
		NEW_UNORT = false;
		centerTimelineOnDate( intDate( DU_form8_new_date ) );
	}
}


function DU_storeDataFromStep2(){
		
}

function DU_step3() {
	DU_stored_step = 3;
	overlayWindow.openOnMarker(DU_targetDragmarker,DU_composeDetailUnort3Window());
}

function DU_storeDataFromStep3(){
}

function DU_init_step4(){
	DU_getMedia();
}

function DU_step4(){
	DU_stored_step = 4;
	overlayWindow.openOnMarker(DU_targetDragmarker,DU_composeDetailUnort4Window());
}

function DU_storeDataFromStep4(){
		
}

function DU_step5(){
	DU_stored_step = 5;
	overlayWindow.openOnMarker(DU_targetDragmarker,DU_composeDetailUnort5Window());
}

function DU_storeDataFromStep5(){
		
}

function DU_init_step6(){
	DU_form_redirect = 6;
	DU_getVotingInfo();
}

function DU_step6(){
	DU_stored_step = 6;
	overlayWindow.openOnMarker( DU_targetDragmarker , DU_composeDetailUnort6Window() );
}

function DU_storeDataFromStep6(){
	
}

function DU_step7(){
	DU_stored_step = 7;
	overlayWindow.openOnMarker(DU_targetDragmarker,DU_composeDetailUnort7Window());
}

function DU_storeDataFromStep7(){

}

function DU_init_step8() {
	DU_form_redirect = 8;
	DU_getUnortInfo();
}

function DU_step8(){
	DU_form8_type = DU_form1_type;
	DU_request_for_form8 = 0;
	DU_stored_step = 8;
	overlayWindow.openOnMarker(DU_targetDragmarker,DU_composeDetailUnort8Window());
	document.forms['unort_details_settings'].date_noticed.value = DU_form8_new_date;
}

function DU_storeDataFromStep8(){
	unortMarkersByID['u'+ DU_form1_unort_id ].disableDragging();
	DU_form8_new_date = document.forms['unort_details_settings'].date_noticed.value;
	DU_form8_type = document.forms['unort_details_settings'].place_type.value;
	DU_form1_type = DU_form8_type;
	if (isAdmin() && document.forms['unort_details_settings'].solved.checked)
		DU_form1_solved = "1";
	else
		DU_form1_solved = "0";
	unortMarkersByID['u'+ DU_form1_unort_id ].setImage( DU_getImageURL( DU_form1_type, DU_form1_solved ) );
}

// ========================= Helper methods ========================= //

function DU_votesLeft() {
	//if (DU_form7_vote_unort == 1 && DU_form7_vote_categories == 1)
	if (DU_form7_vote_unort == 1)
		return true;
	else
		return false;
}

// Helper for handling Vote Left check
function DU_handleCheckVotesLeftEasy( xmlResponse ) {
	try {
		xmlRoot = xmlResponse.documentElement;  
		// obtain arrays with comments 
		var responses = xmlRoot.getElementsByTagName( "voteinfo" );
		var response = responses[0];
		DU_form7_vote_unort = 0;
		DU_form7_vote_categories = 0;
		
		if (response.getAttribute( "votingUnort" ) == "enabled")
			DU_form7_vote_unort = 1;
		if (response.getAttribute( "votingCategories" ) == "enabled")
			DU_form7_vote_categories = 1;
			
		responses = xmlRoot.getElementsByTagName( "categories" );
		response = responses[0];
		var catInfo = response.getAttribute( "names" );
		var cats = catInfo.split( "," );
		DU_form1_categories = "";
		for (var i=0; i<cats.length; i += 2) {
			if (DU_form1_categories != "")
				DU_form1_categories += ", ";
			DU_form1_categories += '<a href="sys/list_all_unorte.php?catsearch='+ cats[i+1] +'">'+ cats[i] +'</a>';
		}
		
	} catch(e) {
		// display error message
		displayError( e.toString() );
	}
}

function DU_showVotingCategoriesInfo() {
	var result = "";
	if (DU_form6_category_info.length == 0){
		DU_form7_vote_categories = 0
		return "";
	}
	else{
		result +=
		'		<div class="column bullet w_shl">Bewertung der Kategorien:</div>' +
		'		<div class="window w_txt">' +
		'			<table class="cat">' +
		'				<tr>'+
		'					<th class="name">Kategorien</th>' +
		'					<th class="absolute">Gesamt</th>' +
		'					<th class="percent">Zustimmung</th>' +
		'				</tr>';
		
		for (i = 0; i < DU_form6_category_info.length; i +=5){
			var percent = DU_form6_category_info[i+4];
			result += 
			'			<tr>' +
			'				<td class="name"><div class="pad">' + DU_form6_category_info[i+1] +'</div></td>' +
			'				<td class="absolute"><div class="pad">'+ DU_form6_category_info[i+2]+ '</div></td>' +
			'				<td class="percent"><div class="pad"><div class="value">'+ percent+'%</div> <img src="img/win/bar_element_grey.gif" width="'+ ((percent/100)*45)+ '" height="14" /></div></td>' +
			'			</tr>';		
		}
		
		result +=
		'			</table>' +
		'		</div>';
	}	
	return result;
}

function DU_userVoted() {
	if (DU_form7_vote_selection == -1)
		return false;
	else
		return true;
}

// Checks wheter the settings tab needs to be shown
function DU_settingsEnabled(){
	//If Admin show settings
	if (isAdmin())
		return 1;
	// If the user is not the owner, no settings available
	if (globalStatus.user_id != DU_form1_user_id){
		return 0;
	}	
	// If comments from others are present, no settings available	
	if (DU_form2_commentCountFromOthers > 0){
		return 0;
	}
	
	// If media from others are present, no settings available			
	if (DU_form4_mediaCountFromOthers > 0){
		return 0;
	}

	
	// otherwise, settings can be shown	
	return 1;
}

function DU_showSettings(){
	if (DU_settingsEnabled())
		return '			<a href="javascript:DU_saveState();DU_init_step8();"><img src="img/tab/tab_ein.png" title="&auml;nderunegn am Unort vornehmen" /></a>';
	else
		return '';
}

// ============= AJAX code below - works =============== //

// ================ Form1 AJAX ================ //

function DU_getUnortInfo() {
	// only continue if xmlHttp isn't void
	if (xmlHttp) {
		// try to connect to the server
		try {
			// make asynchronous HTTP request to retrieve new message
			var query = "sys/detailunort.php?query_type=unort_info&place_id=" + DU_UNORT_ID;
			xmlHttp.open("GET", query , true);
			xmlHttp.onreadystatechange = DU_handleGetUnortInfo;
			xmlHttp.send(null);
		} catch(e) {
			displayError( e.toString() );
		}
	}
}

// function called when the state of the HTTP request changes
function DU_handleGetUnortInfo() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// continue only if HTTP status is "OK"
		//if (xmlHttp.status == 200) {
		if (true) {
			try {
				DU_handleGetUnortInfoEasy( xmlHttp.responseXML );
				if (DU_form_redirect == 6) {
					DU_step6();
				}
				else if (DU_form_redirect == 7) {
					DU_form_redirect = 6;
					DU_step7();
				}
				else if (DU_form_redirect == 8) {
						DU_step8();
					} else {
						DU_form_redirect = 2;
						DU_init_step2();
					}
			} catch(e) {
				// display error message
				displayError( e.toString() );
			}
		} else {
			// display error message
			displayError( xmlHttp.statusText );   
		}
	}
}

// function called when the state of the HTTP request changes
function DU_handleGetUnortInfoEasy(xmlResponse) {
	try {
		// obtain the unortinfo element
		var unortinfo = xmlResponse.getElementsByTagName('unortinfo');
		
		DU_form1_unort_id = unortinfo[0].getAttribute("id");
		DU_form1_quarter_id = unortinfo[0].getAttribute("quarter_id");
		DU_form1_type = unortinfo[0].getAttribute("type_id");
		DU_form1_solved = unortinfo[0].getAttribute("solved");
		DU_form1_nickname = unortinfo[0].getAttribute("nickname");
		DU_form1_user_id = unortinfo[0].getAttribute("user_id");
		DU_form1_date = unortinfo[0].getAttribute("date");
		DU_form1_title = unortinfo[0].getAttribute("title");
		DU_form1_text = unortinfo[0].getAttribute("text");
		DU_form1_voters = unortinfo[0].getAttribute("voters");
		DU_form1_vote_yes = unortinfo[0].getAttribute("voting");
		DU_form1_vote_no = DU_form1_voters - DU_form1_vote_yes;
		
		DU_form8_new_date = unortinfo[0].getAttribute("date");
		DU_form8_new_title = DU_form1_title;
		DU_form8_new_text = DU_form1_text;
		
		DU_getVotingInfo();
		
	} catch(e) {
		// display error message
		displayError( e.toString() );
	}
}

// ================ Form2 AJAX ================ //



function DU_getComments(){
	var emsg = 'Die Kommentare konnten nicht geladen werden.';
	var getCommentRequest = new XHR({method: 'get',onSuccess:function(rtxt,rxml){
		DU_handleGetCommentsEasy(rxml);
		DU_step2();	
	},onFailure:function(){
		displayError(emsg);
	},onExeption:function(){
		displayError(emsg);
	}}).send("sys/comments.php?place_id=" + DU_UNORT_ID);
}


// Method used by the grouped AJAX calls
function DU_handleGetCommentsEasy(xmlResponse) {

	try {
		// obtain the XML's document element
		xmlRoot = xmlResponse.documentElement;  
		// obtain arrays with comments 
		comments = xmlRoot.getElementsByTagName("comment");
		
		DU_form2_commentCount = comments.length;
		DU_form2_commentCountFromOthers = 0;
		DU_form2_comments = "";  
		// iterate through the arrays and create an HTML structure
		for (var i = 0; i < comments.length; i++) {
			DU_form2_comments +=
				'<div class="item">' +
					'<div class="column w_shl">' +
						user_list_view_link( comments[i].getAttribute("user_id"), comments[i].getAttribute("nickname") ) + ' | ' + 
						comments[i].getAttribute("date") + ' | ' + comments[i].getAttribute("time") +
					'</div>' +
					'<div class="w_txt">' + comments[i].getAttribute("text") + '</div>' +
				'</div>';
			
			if (i < comments.length -1)
				DU_form2_comments += '<div class="dot_line"></div>';
				
			if (parseFloat(comments[i].getAttribute("user_id")) != globalStatus.user_id )
				DU_form2_commentCountFromOthers++;
		}
	} catch(e) {
		// display error message
		displayError(e.toString());
	}
}

// ================ Form3 AJAX ================ //

function DU_storeNewComment(id){
	var emsg = 'Das Kommentar konnte nicht gespeichert werden. Einfach nochmal probieren.';
	var saveCommentRequest = new XHR({method: 'get',onSuccess:function(rtxt,rxml){
		DU_form3_new_comment = "";
		DU_getComments();
	},onFailure:function(){
		displayError(emsg);
	},onExeption:function(){
		displayError(emsg);
	}}).send("sys/comments.php?action=add&place_id=" + id + "&text=" + DU_form3_new_comment);
}



// ================ Form4 AJAX ================ //

// call server asynchronously
function DU_getMedia() {
	// only continue if xmlHttp isn't void
	if (xmlHttp)  {
		// try to connect to the server
		try {
			var query = "sys/media.php?place_id=" + DU_UNORT_ID;
			xmlHttp.open("GET", query , true);
			xmlHttp.onreadystatechange = DU_handleGetMedia;
			xmlHttp.send(null);
		} catch(e) {
			displayError();
		}
	}
}

// function called when the state of the HTTP request changes
function DU_handleGetMedia() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// continue only if HTTP status is "OK"
		if (xmlHttp.status == 200) {
			try {
				DU_handleGetMediaEasy(xmlHttp.responseXML);
				DU_step4();
			} catch(e) {
				// display error message
				displayError(e.toString());
			}
		} else {
			// display error message
			displayError(xmlHttp.statusText);   
		}
	}
}

// function called when the state of the HTTP request changes
function DU_handleGetMediaEasy( xmlResponse ) {
	try {
		// obtain the XML's document element
		xmlRoot = xmlResponse.documentElement;  
		// obtain arrays with comments 
		media = xmlRoot.getElementsByTagName("item");
		
		DU_form4_mediaCount = media.length;
		DU_form4_mediaCountFromOthers = 0;
		DU_form4_media = "<table>";  
		
		// Assemble the document root
		var doc_root = document.URL.substring( 0, document.URL.lastIndexOf( '/' ) + 1 );
		
		// Create the imageset for an unort
		var newImageLocations = [];
		for (var i = 0; i < media.length; i++) {
			// Try to determine the dimensions of an image
			var width = media[i].getAttribute('width');
			var height = media[i].getAttribute('height');
			if ((media[i].getAttribute('type')=='i') && ((width==0) || (height==0))) {
				var img = new Image();
				img.src = doc_root+media[i].getAttribute("filename_orig");
				width = img.width;
				height = img.height;
			}
			
			// Create new entry in the imagset (for Greybox)
			var newImageLocation = {
					'caption': media[i].getAttribute("title"), 
					'url': doc_root + "sys/mediapage.php?url=" + doc_root+media[i].getAttribute("filename") +
									"&type=" + media[i].getAttribute('type') + "&screenshot=" + doc_root+media[i].getAttribute('filename_screenshot') +
									"&author=" + media[i].getAttribute('nickname') + "&description=" + media[i].getAttribute('description') +
									"&duration=" + media[i].getAttribute("duration") + "&width=" + width+"&height=" + height,
					'width':width,
					'height':height
				};
			newImageLocations[i] = newImageLocation;

		}
		image_set[DU_UNORT_ID] = newImageLocations;
			
		// iterate through the arrays and create an HTML structure
		for (var i = 0; i < media.length; i++) {
			DU_form4_media +=
				'<tr>' + 
					'<td class="media" valign="top">' +
						'<div class="thumb">' +
							'<a href="#" onclick="return GB_showFullScreenSet(image_set['+DU_UNORT_ID+'],'+(i+1)+');">' +
								'<img class="thumb" src="' + media[i].getAttribute("filename_thumb") + '" title="Bild im Leuchtkasten &#246;ffnen" />';
							
			if ((media[i].getAttribute("type") == 'a') || (media[i].getAttribute("type") == 'v'))
				DU_form4_media +=
								'<img class="thumb_play" src="img/media/play-button.png" />';
							
			DU_form4_media +=
							'</a>' +
						'</div>';
						
			if ((media[i].getAttribute("user_id") == globalStatus.user_id ) || isAdmin())
				DU_form4_media += 
						'<div><a href="javascript:DU_deleteMedia('+media[i].getAttribute("id")+');"><img src="img/btn/delete_file.png" /></div>';
						
			DU_form4_media +=
					'</td>' + 
					'<td class="text" valign="top">' +
						'<div class="column bullet w_shl">' + 
							user_list_view_link(media[i].getAttribute("user_id"),media[i].getAttribute("nickname")) + ' | ' + media[i].getAttribute("date") + ' | ' + media[i].getAttribute("time") +
						'</div>' + 
						'<div class="w_shl">' + media[i].getAttribute("title") + '</div>' + 
						'<div class="w_txt">' + media[i].getAttribute("text") + '</div>' + 
						'</td>' +
					'</tr>';
					
			if (i < media.length -1)
				DU_form4_media += 
					'<tr><td colspan="2"><div class="dot_line"></div></td></tr>';
					
			if (parseFloat(media[i].getAttribute("user_id")) != globalStatus.user_id )
				DU_form4_mediaCountFromOthers++;
				
		}
		
		DU_form4_media += '</table>';
		
		if (media.length > 0) {
			DU_form2_media =
					'<div class="thumb">' +
						'<a href="#" onclick="return GB_showFullScreenSet(image_set['+DU_UNORT_ID+'],1);">' +
							'<img class="thumb" src="' + media[0].getAttribute("filename_thumb") + '" />';
							
			if ((media[0].getAttribute("type") == 'a') || (media[0].getAttribute("type") == 'v'))
				DU_form2_media +=
							'<img class="thumb_play" src="img/media/play-button.png" />';
							
			DU_form2_media += 
						'</a>' +
					'</div>';
					
		} else {
			DU_form2_media = '';
		}
		
	} catch(e) {
		// display error message
		//displayError(e.toString());
		displayError( e.toString() );
	}
}


// call server asynchronously
function DU_deleteMedia( record_ID ) {
	if (confirm( "Wollen Sie die Datei wirklich löschen?" )) {
		// only continue if xmlHttp isn't void
		if (xmlHttp) {
			// try to connect to the server
			try {
				var query = "sys/filedelete.php?action=removemedia&record_id=" + record_ID;
				xmlHttp.open( "GET", query , true );
				xmlHttp.onreadystatechange = DU_DeleteMedia;
				xmlHttp.send( null );
			} catch(e) {
				// display error message
				// obtain the XML's document element
				xmlRoot = xmlResponse.documentElement;  
				// obtain arrays with comments 
				media = xmlRoot.getElementsByTagName("item");
				
				displayError(e.toString());
			}
		}
	}
}


// function called when the state of the HTTP request changes
function DU_DeleteMedia() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// continue only if HTTP status is "OK"
		if (xmlHttp.status == 200) {
			try {
				// Media deleted, refresh the mediascreen
				DU_getMedia();
			} catch(e) {
				// display error message
				displayError(e.toString());
			}
		} else {
			// display error message
			displayError(xmlHttp.statusText);   
		}
	}
}


// ================ Form6 AJAX ================ //

// call server asynchronously
function DU_getVotingInfo() {
	// only continue if xmlHttp isn't void
	if (xmlHttp2) {
		// try to connect to the server
		try {
			var query = "sys/categories.php?action=vote&place_id=" + DU_UNORT_ID;
			xmlHttp2.open("GET", query , true);
			xmlHttp2.onreadystatechange = DU_handleVotingInfo;
			xmlHttp2.send(null);
		} catch(e) {
			displayError();
		}
	}
}


// function called when the state of the HTTP request changes
function DU_handleVotingInfo() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp2.readyState == 4) {
		// continue only if HTTP status is "OK"
		if (xmlHttp2.status == 200) {
			try {
				DU_form6_category_info = new Array();
				DU_form6_category_votes = 0;
				
				// do something with the response from the server
				// read the message from the server
				var xmlResponse = xmlHttp2.responseXML; 
				// obtain the XML's document element
				xmlRoot = xmlResponse.documentElement;  
				// obtain arrays with categories	 
				categories = xmlRoot.getElementsByTagName("category");
				
				// iterate through the arrays and create an HTML structure
				for (var i = 0; i < categories.length; i++) {
					// Store the number of voters on the categories
					if (i == 0)
						DU_form6_voters_categories = categories[0].getAttribute("voters_categories");
					DU_form6_category_info.push(categories[i].getAttribute("category_id"));
					DU_form6_category_info.push(categories[i].getAttribute("name"));
					DU_form6_category_info.push(categories[i].getAttribute("voters"));
					DU_form6_category_votes += parseFloat(categories[i].getAttribute("voters"));
					DU_form6_category_info.push(categories[i].getAttribute("voting"));
					if (categories[i].getAttribute("voters") == "0")
						DU_form6_category_info.push(0);
					else
						DU_form6_category_info.push(Math.round((parseFloat(categories[i].getAttribute("voting"))/parseFloat(categories[i].getAttribute("voters")))*100));
				}
				
				switch (DU_form_redirect) {
					case 6: DU_step6(); break;
					case 8: DU_step8(); break;
					default: DU_step2(); 
				}
				
			} catch(e) {
				// display error message
				displayError( e.toString() );
			}
		} else {
			// display error message
			displayError( xmlHttp.statusText );   
		}
	}
}

// ================ Form7 AJAX ================ //

// call server asynchronously
function DU_voteUnort( vote, voteList ) {
	if (DU_form7_vote_unort == 1) {
		// only continue if xmlHttp isn't void
		if (xmlHttp) {
			// try to connect to the server
			try {
				var query = "sys/voting.php?action=vote&place_id=" + DU_UNORT_ID + "&vote=" + vote + "&votes=" + voteList;
				// make asynchronous HTTP request to retrieve new message
				xmlHttp.open("GET", query , false);
				xmlHttp.send( null );
			} catch(e) {
				//mf no error message
				displayError( e.toString() );
			}
		}
	}
	DU_form7_vote_unort = 0;
	DU_form7_vote_categories = 0;
	DU_form_redirect = 6;
	DU_getUnortInfo();
	//DU_step6();
}


// ================ Form8 AJAX ================ //

// call server asynchronously
function DU_modifyUnort() {
	DU_form1_type = DU_form8_type;
	DU_form1_title = DU_form8_new_title;
	DU_form1_text = DU_form8_new_text;
	
	// only continue if xmlHttp isn't void
	if (xmlHttp) {
		// try to connect to the server
		try {
			var point = unortMarkersByID['u'+ DU_form1_unort_id ].getLatLng();
			var lat = point.lat();
			var lng = point.lng();
			var query = "sys/modifyunort.php?unort_id=" + DU_form1_unort_id +
			"&title=" + DU_form8_new_title +
			"&text=" + DU_form8_new_text +
			"&type=" + DU_form8_type +
			"&solved=" + DU_form1_solved +
			"&date=" + DU_form8_new_date + 
			"&lat=" + lat +
			"&lng=" + lng;
			
			// make asynchronous HTTP request to retrieve new message
			xmlHttp.open( "GET", query , true );
			xmlHttp.onreadystatechange = function() {
					if (xmlHttp.readyState == 4) {
						displayMessage( "Die Änderungen wurden übernommen." );
						DU_form_redirect = 2;
						DU_getUnortInfo();
					}
				};
			xmlHttp.send(null);
		} catch(e) {
			displayError( e.toString() );
		}
	}
}

// call server asynchronously
function DU_deleteUnort() {
	if (confirm("Wollen Sie den Unort wirklich l"+String.fromCharCode(246)+"schen?")) {
		// only continue if xmlHttp isn't void
		if (xmlHttp) {
			// try to connect to the server
			try {
				var query = "sys/deleteUnort.php?unort_id=" + DU_form1_unort_id + "&user_id=" + globalStatus.user_id;
				// make asynchronous HTTP request to retrieve new message
				xmlHttp.open("GET", query , true);
				xmlHttp.onreadystatechange = function() {
								if (xmlHttp.readyState == 4) {
									window.location = "index.php";	
								}};
				xmlHttp.send(null);
			} catch(e) {
				displayError( e.toStrin() );
			}
		}
	}
}

function DU_getImageURL( type, solved ) {
	if (solved == "1")
		solved = 1;
	else
		solved = 0;
	return icon_image[type][solved];
}
