
	if ( !qFlux )
		var qFlux = {};
	qFlux.detail = {};
	
	//####################################################################################################
	
	qFlux.detail.sendDetail = function(id, type)
		{
			document.getElementById(type + '_error').innerHTML = '';
			document.getElementById(type + '_error').style.display = 'none';
			qFlux.detail.type = type;
			var text = document.getElementById(type + '_edit').value;
			if ( !text )
				{ return; }
			var error = false;
			if ( type == 'name' && ( text.replace(/ /g,'').length < 3 || text.length > 12 ) )
				{ error = 'name'; }
			if ( type == 'title' && ( text.replace(/ /g,'').length < 5 || text.length > 70 ) )
				{ error = 'title'; }
			if ( type == 'description' && ( text.replace(/\n| /g,'').length < 5 || text.length > 5000 ) )
				{ error = 'description'; }
			if ( type == 'e-mail' && !qFlux.validateMail(text) )
				{ error = 'mail'; }
			if ( type == 'password' && ( text.search(/ /) != -1 || text.length < 6 || text.length > 16 ) )
				{ error = 'password'; }
			if ( error )
				{
					qFlux.detail.showError(error);
					return;
				}
			qFlux.detail.text = text;
			var parameter = 'type=' + type + '&id=' + id;
			if ( type == 'password' )
				{
					document.getElementById(type + '_edit').value = '';
					var repeat = document.getElementById('password_repeat').value;
					document.getElementById('password_repeat').value = '';
					if ( repeat != text )
						{
							qFlux.detail.showError('difference');
							return;
						}
					parameter = parameter + '&text=' + hex_md5(text);
				}
			else
				{ parameter += '&text=' + text; }
			if ( document.getElementById(type + '_protect') )
				{
					var password = document.getElementById(type + '_protect').value;
					document.getElementById(type + '_protect').value = '';
					if ( !password || password.search(/ /) != -1 || password.length < 6 || password.length > 16 )
						{
							qFlux.detail.showError('key');
							return;
						}
					qFlux.detail.parameter = parameter;
					qFlux.detail.password = password;
					qFlux.xmlHttpRequest('detail.php', 'type=seed&id=0', 'qFlux.detail.receiveDetailSeed');
					return;
				}
			qFlux.xmlHttpRequest('detail.php', parameter, 'qFlux.detail.receiveDetail');
		}
	
	//####################################################################################################

	qFlux.detail.receiveDetailSeed = function() 
		{ 
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			if ( xmlHttp.responseText.length != 32 )
				{
					qFlux.detail.parameter = null;
					qFlux.detail.password = null;
					qFlux.detail.showError();
					qFlux.xmlHttpSend();
					return;
				}
			var parameter = qFlux.detail.parameter + '&key=' + hex_md5(hex_md5(qFlux.detail.password) + xmlHttp.responseText);
			qFlux.detail.parameter = null;
			qFlux.detail.password = null;
			qFlux.xmlHttpRequest('detail.php', parameter, 'qFlux.detail.receiveDetail');
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.receiveDetail = function() 
		{ 
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			if ( xmlHttp.responseText != 'success' )
				{
					qFlux.detail.showError(xmlHttp.responseText);
					qFlux.xmlHttpSend();
					return;
				}
			qFlux.detail.toggleInput(qFlux.detail.type);
			if ( qFlux.detail.type == 'password' )
				{
					qFlux.xmlHttpSend();
					return;
				}
			if ( qFlux.detail.type == 'title' )
				{
					document.getElementById('title').innerHTML = 'Guide Details - ' + qFlux.detail.text;
					document.title = 'questFlux Project - ' + qFlux.detail.text;
				}
			var text = qFlux.detail.text.replace(/(\r)*\n(\r)*\n(\r)*\n((\r)*\n)*/gi,"<br><br>");
			text = text.replace(/(\r)*\n/gi,"<br>");
			document.getElementById(qFlux.detail.type + '_value').innerHTML = text;
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.sendFaction = function(id, faction) 
		{
			qFlux.detail.type = 'faction';
			var parameter = "type=faction&id=" + id + "&faction=" + faction;
			qFlux.xmlHttpRequest('detail.php', parameter, 'qFlux.detail.receiveFaction');
		}
	
	//####################################################################################################

	qFlux.detail.receiveFaction = function()
		{
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			if ( xmlHttp.responseText == 'database' )
				{
					qFlux.detail.showError('database');
					qFlux.xmlHttpSend();
					return;
				}
			else if ( xmlHttp.responseText != '' )
				{
					var elements = document.getElementById('container_faction').childNodes;
					for ( var i in elements )
						{
							if ( elements[i].nodeName == 'INPUT' )
								{
									if ( elements[i].value == xmlHttp.responseText )
										{ elements[i].selected = true; }
									else
										{ elements[i].selected = false; }
								}
						}
				}
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.voteMouseOver = function(element) 
		{
			element.style.cursor = 'pointer';
			element.style.borderColor = 'rgb(255,0,0)';
		}
	
	//####################################################################################################

	qFlux.detail.voteMouseOut = function(element) 
		{ element.style.borderColor = 'rgb(65,100,0)'; }
	
	//####################################################################################################

	qFlux.detail.sendVote = function(id, vote) 
		{
			document.getElementById('vote_error').innerHTML = '';
			qFlux.detail.type = 'vote';
			var parameter = "type=vote&id=" + id + "&vote=" + vote;
			qFlux.xmlHttpRequest('detail.php', parameter, 'qFlux.detail.receiveVote');
		}
	
	//####################################################################################################

	qFlux.detail.receiveVote = function()
		{
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			var result = Number(xmlHttp.responseText);
			if ( !result && result != 0 )
				{
					qFlux.detail.showError('database');
					qFlux.xmlHttpSend();
					return;
				}
			if ( result == 0 )
				{ document.getElementById('vote_cancel').style.display = 'none'; }
			else
				{ document.getElementById('vote_cancel').style.display = 'inline'; }
			var elements = document.getElementById('vote').childNodes;
			for ( i in elements )
				{
					if ( elements[i].nodeName == 'DIV' )
						{
							if ( Number(elements[i].id) <= result )
								{ elements[i].style.background = 'rgb(' + ( 105 + Number(elements[i].id) * 30 ) + ',255,0)'; }
							else
								{ elements[i].style.background = ''; }
						}
				}
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.sendPublic = function(checkbox, id) 
		{
			var value = 0;
			if ( checkbox.checked == true )
				{ value = 1; }
			//document.getElementById('vote_error').innerHTML = '';
			qFlux.xmlHttpRequest('detail.php', 'type=public&id=' + id + '&value=' + value, 'qFlux.detail.receivePublic');
		}
	
	//####################################################################################################

	qFlux.detail.receivePublic = function() 
		{
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.toggleDelete = function(event)
		{
			if ( event == null )
				{ event = window.event; }
			var target = ( event.target == null ? event.srcElement : event.target );
			if ( target.id == 'delete_confirm' || target.id == 'delete_password' )
				{ return false; }
			qFlux.detail.seed = null;
			var secure = document.getElementById('delete_secure');
			if ( target.id != 'delete_cancel' && ( !secure.style.display || secure.style.display == 'none' ) )
				{ qFlux.xmlHttpRequest('detail.php', 'type=seed&id=0', 'qFlux.detail.receiveSeed'); }
			else
				{
					document.getElementById('delete_password').value = '';
					document.getElementById('delete_secure').style.display = 'none';
					document.getElementById('delete_header').style.display = 'block';
				}
		}
	
	//####################################################################################################

	qFlux.detail.sendDelete = function(id)
		{
			if ( !qFlux.detail.seed )
				{ return; }
			var password = document.getElementById('delete_password').value;
			if ( !password || password.search(/ /) != -1 || password.length < 6 || password.length > 16 )
				{
					document.getElementById('delete_password').value = '';
					document.getElementById('delete_secure').style.display = 'none';
					document.getElementById('delete_header').style.display = 'block';
					return;
				}
			qFlux.xmlHttpRequest('detail.php', 'type=delete&id=' + id + '&hash=' + '&hash=' + hex_md5(hex_md5(password) + qFlux.detail.seed) , 'qFlux.detail.receiveDelete');
		}
	
	//####################################################################################################

	qFlux.detail.receiveSeed = function() 
		{ 
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			if ( xmlHttp.responseText.length != 32 )
				{ return; }
			qFlux.detail.seed = xmlHttp.responseText;
			document.getElementById('delete_header').style.display = 'none';
			document.getElementById('delete_secure').style.display = 'block';
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.receiveDelete = function()
		{
			if ( xmlHttp.readyState != 4 && xmlHttp.readyState != 'complete' )
				{ return; }
			if ( xmlHttp.responseText != '' )
				{ window.location.href = xmlHttp.responseText; }
			else
				{
					document.getElementById('delete_password').value = '';
					document.getElementById('delete_secure').style.display = 'none';
					document.getElementById('delete_header').style.display = 'block';
				}
			qFlux.xmlHttpSend();
		}
	
	//####################################################################################################

	qFlux.detail.showError = function(status) 
		{
			var text;
			if ( status == 'mail' )
				{ text = 'Your entered mail address doesn\'t seem to be valid!'; }
			else if ( status == 'contact' )
				{ text = 'Your entered mail adress is already taken by another user!'; }
			else if ( status == 'name' )
				{ text = 'Your entered username is not valid as it has to be 3 - 12 characters long!'; }
			else if ( status == 'user' )
				{ text = 'Your entered username is already taken by another user!'; }
			else if ( status == 'title' )
				{ text = 'Your entered title is invalid as it has to be 5 - 70 characters long!'; }
			else if ( status == 'guide' )
				{ text = 'Your entered guide title is already taken by another guide!'; }
			else if ( status == 'description' )
				{ text = 'Your entered description is invalid as it has to be 5 - 5000 characters long!'; }
			else if ( status == 'password' )
				{ text = 'Your entered new password is invalid as it has to be 6 - 16 characters long!'; }
			else if ( status == 'key' )
				{ text = 'Your entered password is invalid!'; }
			else if ( status == 'difference' )
				{ text = 'Your entered new passwords are not identical!'; }
			else if ( status == 'database' )
				{ text = 'No database connection - please try again later!'; }
			else
				{ text = 'Uhmm ... something went terribly wrong ...'; }
			document.getElementById(qFlux.detail.type + '_error').innerHTML = text;
			document.getElementById(qFlux.detail.type + '_error').style.display = 'block';
		}
	
	//####################################################################################################
	
	qFlux.detail.toggleInput = function(type)
		{
			if ( document.getElementById(type + '_protect') )
				{
					document.getElementById(type + '_protect').value = '';
					if ( document.getElementById('password_repeat') )
						{ document.getElementById('password_repeat').value = ''; }
				}
			var input = document.getElementById(type + '_input');
			if ( !input.style.display || input.style.display == 'none' )
				{
					if ( type != 'password' )
						{
							var text = document.getElementById(type + '_value').innerHTML;
							text = text.replace(/<br><br><br>(<br>)*/gi,"\n\n");
							text = text.replace(/<br>/gi,"\n");
							document.getElementById(type + '_edit').value = text;
						}
					document.getElementById(type + '_value').style.display = 'none';
					input.style.display = 'block';
				}
			else
				{
					document.getElementById(type + '_edit').value = '';
					input.style.display = 'none';
					document.getElementById(type + '_error').innerHTML = '';
					document.getElementById(type + '_error').style.display = 'none';
					document.getElementById(type + '_value').style.display = 'block';
				}
		}

