$(document).ready(function(){ 
	
// Config and Setup 
	
	var urlroot = $("#urlroot").text();                //  e.g. /cosdev/
	var docroot = $("#docroot").text();                // e.g. /var/www/camellia/cosdev/
	var fqdn = $("#fqdn").html();                      // e.g. http://camellia.../cosdev/
	var newPageName = 'Please enter a page name here.';
	var loggedInAs = $("#loggedinas").html();
	var username = $("#user").attr('value');
	var fullname = $("#fullname").html();
	var page = $("#pageRequest").attr('value');
	var iconpath = urlroot + 'libs/jqueryFileTree/images/';
	var ajxresp = ''; 
	var c = 0; // for multifig function
	var n = 0;
	var map ;
	var showPopupOnHover = false;
	var text = new Array("Informationen zur Karte anzeigen","Informationen zur Karte verstecken");
	var lang = $("#language").html();
	var contMsg = {'_e':'Message to ', '':'Nachricht an '};
	var contErr = {'_e':'Please fill out subject and from line.', '':'Bitte Absender und Betreff ausfüllen.'};
	$("body").data('contMsg',contMsg);
	$("body").data('lang',lang);
	$("body").data('fqdn',fqdn);
	$("body").data('username',username);
	$("body").data('page',page);
	$("body").data('loggedInAs',loggedInAs);
	$.ajaxSetup({
			url: fqdn + 'responder.php',
			type: "POST",
			async: false
	});
	var bannerPicInterval = setInterval('changeCosImage(' + urlroot + ')',12000); 
	if($("#map").css('visibility') == 'visible'){
		drawmap();
	}
	$(".needjs").toggle();
//	$(".needjs").css('display','block');

// Main dialog openers
	
	$("#editcoworker").click(function(event,ui){
		$("#CoWEditBox").dialog('open');
	});
	$("#editpage").click(function(event,ui){
		if ($("#pageEditBox").css('visibility') == 'hidden') {
			$("#pageEditBox").dialog('open');
		}
		else {
			$("#pageEditBox").dialog('close');
		}
	});
	$("#copypage").click(function(event,ui){
		$("#copyBox").dialog('open');
	});
	$("#newpage").click(function(event,ui){
		var newPageName = prompt('Please provide a name for the page to be created:');
		var goAhead = true;
		$(".pageListItem > a").each(function(i, v){
			if ($(this).html() == newPageName) {
				alert('There already is a page with that name for this user. If you want to edit that existing page, please navigate there and use the "Edit page" button. If you really want to create a new page, please try again and provide another name.');
				goAhead = false;
			}
		});
		if (goAhead) {
			var headline = 'init';
			var caption = '';
			var imgsrc = '';
			var imgalt = '';
			var parnum = 0;
			var imgtotal = 0;
			var imgnum = 0;
			$("#pageName").val(newPageName);
			$("#editArea").val('[#ANCHORS#]');
			$("#pageEditBox").dialog('open');
			var out = '[#ANCHORS#]';
			while(headline != '' && headline != null){
				parnum++;
				//[#MULTIFIG| image1.jpg | Text for caption 1 | image2.jpg | Text for caption 3 | image3.jpg | Text for caption 3 #]
				imgtotal = 0;imgnum = 0;
				headline = prompt('Provide a paragraph header (leave empty if you do not want any more questions):');
				if(headline != '' && headline != null){
					out += '<h2><a name="par' + parnum + '"></a>' + headline + "</h2>\n";
					imgtotal = prompt('How many images do you want to insert in this paragraph?');
					if (imgtotal > 0) {
						if (imgtotal > 1) {
							out += "[#MULTIFIG";
						}else{
							out += '<table align="right" border="0"><tbody><tr><td>' + "\n";
						}
						while (imgnum < imgtotal) {
							imgnum++;
							imgsrc = prompt('Please provide the filename for image ' + imgnum + '. (Has to reside in your image folder.)');
							if (imgtotal == 1) {
								imgalt = prompt('Please provide a short description for image ' + imgnum + ':');
							}
							caption = prompt('Please provide a caption for image ' + imgnum + ':');
							if (imgtotal == 1) {
								out += '<img src="' + fqdn + 'data/' + username + '/images/' + imgsrc + '" title="' + imgalt + '"alt="' + imgalt + '"></td></tr>' + "\n" + '<tr><td>';
								out += caption + "\n";			
							}
							else {
								out += '| ' + imgsrc + ' | ' + caption + " \n";
							}
						}
						if (imgtotal > 1) {
							out += "#]\n";
						}else{
							out += "</td></tr></tbody></table>\n";
						}
					}
					
					out += "<p>Please insert your content here.</p>\n";
				}
			}
			if(out == '[#ANCHORS#]'){
				out = '';
			}
			$('#editArea').tinymce().execCommand('mceInsertContent',false,out + "\n");
		}
	});
	$("#pagelist").click(function(event,ui){
		$("#pageListBox").dialog('open');
	});
	$("#newpasswd").click(function(event,ui){
		$("#passwdBox").dialog('open');
	});
	$("#newuser").click(function(event,ui){
		$("#CoWEditBox input").attr('value','');
		$("#CoWEditBox select").val('');
		$("#currentbelongsto").html('');
		$("#currentusername").html('');
		$('<div style="text-align:left;width:100%;margin:4px;" id="UsernameContainer"><b>Username</b>:&nbsp;<input type="text" class="configforminput" id="Username" name="Username" maxlength="253" value=""></div>').insertBefore("#CoWEditBox table.config");
		$("#CoWEditBox textarea").html('');
		$("#CoWEditBox").dialog('open');
	});
	$("#fileManBtn").click(function(event,ui){
		if($("#filemanagerbox").css('visibility') == 'hidden'){
			$("#filemanagerbox").dialog('open');
		}else {
			$("#filemanagerbox").dialog('close');
		}
	});
	$("#grant").click(function(event,ui){
		$("#grantBox").dialog('open');
	});
	$("#eventman").click(function(event,ui){
		window.location.href = fqdn + 'events/';
	});
	$("#backintime").click(function(event,ui){
		$("#bitbox").dialog('open');
	});
	$("#backup").click(function(event, ui){
		var descriptor = prompt('Give a one word despription for the DB dump (optional). Type exit to cancel backup.','exit');
		if(descriptor == 'exit' || descriptor == 'EXIT' || descriptor == 'Exit'){return false;}
		$.ajax({
			data: {
				obj: loggedInAs,
				user: username,
				mode: 'bkp',
				descriptor: descriptor 
			},
			success: function(resp){
				$("#msgBoxPar").css('text-align','left');
				$("#msgBoxPar").html('Click to download:<br />' + resp);
				$("#msgBoxPar a").css('color','#900');
				$("#msgBox").dialog('open');
			}
		})
	});
	$("#deluser").click(function(event,ui){
		$("#CoWdelbox").dialog('open');
	});
	$("#rightcolmods").click(function(event,ui){
		$("#rightmodbox").dialog('open');
	});
	$("#showallusers").click(function(event,ui){
		showEverybody();
	});
	
// Active link elements
	
	$("#searchclick").click(function(event,ui){
		$("#searchbox").css('display','block');
	});
	$("#zyx").click(function(event,ui){
		$("#xyz").dialog('open');
	});
	$(".hoverer").mouseenter(function(){
		if ($("#helperbox").dialog('isOpen')) {
			$("#helperbox").dialog('close');
		}
		else {
			n = parseInt($(this).attr('id').replace('hlp', ''));
			$("#helperboxcont").html(hlp[n]);
			$("#helperbox").dialog('open');
		}
	});
	$("#nzpgbox").submit(function(event,ui){
		var nk = $("body").data('nk');
		var t = $("#nzpgbox > input").val();
		var tt = '';
		var tn = 0;
		
		for(var i = 0; i < t.length; i++){
			tn = (parseInt(t.charCodeAt(i)) + parseInt(nk));
			if(tn >= 255){
				tn -= 255;
			}
			tn = ('000' + tn).slice(-3);
			tt += tn;
		}
		$("#nzpgbox > input").css('visibility','hidden');
		$("#nzpgbox > input").val(tt);
	});
	glva();
	$("#loginClicker").click(function(event,ui){
		if ($("#loginBox").css('display') == 'block') {
			$("#loginBox").css('display', 'none');
		}
		else {
			$("#loginBox").css('display', 'block');
			$("#loginBox > :hidden").css('visibility', 'visible');
		}
	});
	$("#staffquery").keypress(function(event,ui){
		var q = $("#staffquery").val();
		if (event.which == 13) {
			$.ajax({
				data: {
					obj: loggedInAs,
					q: q,
					user: username,
					mode: 'stfsrch'
				},
				dataType: 'json',
				success: function(resp){
					if (resp.length == 1) {
						resp = resp[0];
						location.href = fqdn + 'index.php/' + resp.Username + '?l=' + lang;
					}
					else 
						if (resp.length > 1) {
							location.href = fqdn + 'index.php/searchcos' + '?l=' + lang + '&query=' + escape(q);
						}else{
							if(lang == '_e'){
								alert('Sorry. We could not find this name.');
							}else{
								alert('Die Suche brachte kein Ergebnis.');
							}
							
						}
				}
			});
		}
	
	});
	
// In-Dialog action buttons 
	
	$("#pageReset").click(function(event,ui){
		$("#pageResetWarnBox").dialog('open');
	});
	$("#pageClear").click(function(event, ui){
		$("#editArea").html('');
	});
	$("#pageoff").click(function(event, ui){
		$("#pageoffbox").dialog('open');
	});
	$("#CoWSave").click(function(event,ui){
		var dat = $('[class^="configform"]').serializeArray();
		if(typeof $("#Username").attr('value') != 'undefined'){
			var usernm = $("#Username").attr('value');
			var newCoW = true;
			var usernmsuggest = '';
			while(usernm.length < 2){
				usernmsuggest = $("#Vorname").attr('value').substring(0,1) + '.' + $("#Nachname").attr('value');
				usernmsuggest = usernmsuggest.toLowerCase();
				usernmsuggest = usernmsuggest.replace(/ä/,'ae');
				usernmsuggest = usernmsuggest.replace(/ö/,'oe');
				usernmsuggest = usernmsuggest.replace(/ü/,'ue');
				usernmsuggest = usernmsuggest.replace(/ß/,'ss');
				usernmsuggest = usernmsuggest.replace(/ /,'_');
				usernm = prompt('Please provide a username for the new user or type "cancel" to abort:',usernmsuggest);
				if(usernm == 'cancel' || usernm == 'Cancel' || usernm == 'CANCEL' || usernm == 'cancel.' || usernm == 'Cancel.'){
					return false;
				}
			}
			$.ajax({
				data: {
					obj: loggedInAs,
					nmqu: usernm,
					mode: 'userNmChk'
				},
				success: function(resp){
					if(resp == 'TAKEN'){
						alert('That name is already taken. Please check your data.'); 
						usernm = '';
					}
				}
			});
		}
		else {
			var usernm = $("#user").attr('value');
			var newCoW = false;
		}
		if(usernm.length < 2){
			return false;
		}
		$.ajax({
			data: {
				obj: loggedInAs,
				data: dat,
				user: usernm,
				mode: 'CoW',
				newcow: newCoW
			},
			success: function(resp){
				var ajxresp = resp;
				$("#lastresp").attr('value', ajxresp);
				if(ajxresp == 'OK'){
					alert("Written to database.");
				}else{
					alert('An error occurred. The server said: ' + ajxresp);
				}
				
			}
		});
		$('[class^="configform"]').css('border','1px #900 solid');
		$('[class^="configform"]').css('color','#000000');
		$("#CoWEditBox").dialog('close');
	});
	$("#pageSave").click(function(event, ui){
	
		var target = $("#target").attr('value');
		var boss = $("#boss").attr('value');
		var page = $("#pageRequest").attr('value');
		var user = $("#user").attr('value');
		var lng = $("#lng").attr('value');
		var cont = $("#editArea").attr('value');
		var pageId = $("#pageId").attr('value');
		if ($("#pageName").val() != newPageName && $("#pageName").val() != '') {
			$.ajax({
				data:{
					obj: loggedInAs,
					cont: cont,
					user: user,
					mode: 'Page',
					acc: $("#pageacc").val(),
					ID: pageId,
					l: lng,
					page: $("#pageName").val()
				},
				success: function(resp){
					ajxresp = resp;
					$("#lastresp").attr('value', ajxresp);
				}
			});
			$("#pageEditBox").dialog('close');
			location.reload();
		}
		else {
			$("#msgBox").html('Please name the page.');
			$("#msgBox").dialog('option','title','Missing page name');
			$("#msgBox").dialog('open');
		}
	});
	$("#pageClose").click(function(event, ui){
		$("#pageEditBox").dialog('close');
	});
    $(function() {
		var baseUrl = urlroot ;
		 $('textarea.tinymce').tinymce({
            // Location of TinyMCE script
            script_url : '/libs/tinymce/jscripts/tiny_mce/tiny_mce.js',

            // General options
            theme : "advanced",
			skin : "o2k7",
        	skin_variant : "silver",
            plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			relative_urls : false,
			width: "740",
			height:"480",
	        force_br_newlines : true,
	        force_p_newlines : false,
			forced_root_block: '',
			apply_source_formatting : true,
			preformatted : true,
			remove_linebreaks : false,
			
            // Theme options
            theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons1 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media",
            theme_advanced_buttons2 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,nonbreaking,template,pagebreak",
				theme_advanced_buttons4 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : false,
            /*
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,
			*/

            // Example content CSS (should be your site CSS)
            content_css : baseUrl + "css/cos.css",

            // Drop lists for link/image/media/template dialogs
			
			template_external_list_url : baseUrl + "helpers/mce_templates.php",
            external_link_list_url : baseUrl + "helpers/link_list.php/" + $("#user").attr('value'),
            external_image_list_url : baseUrl + "helpers/image_list.php/" + $("#user").attr('value'),
            media_external_list_url : baseUrl + "helpers/image_list.php/" + $("#user").attr('value'),

            // Replace values for the template plugin
            template_replace_values : {
                    username : $("#user").attr('value'),
					USERNAME : $("#user").attr('value'),
                    lsfid : $("#lsfId").attr('value'),
					LSFID : $("#lsfId").attr('value')
            }
        });
    });
	$("#lsfGetter").click(function(event,ui){
		var lsfid = $("#LSFID").attr('value');
		$.ajax({
			url:fqdn + 'helpers/lsfgetter.php',
			dataType: 'json',
			type: 'GET',
			data:{
				obj: loggedInAs,
				lsfpid:lsfid
			},
			async:false,
			success: function(jsndat){
				var jsn = jsndat;
				$.each($('[class^="configform"]'),function(k,v){
					var oval = this.value;
					var key = this.id;
					var nval = jsn[key];
					if (typeof nval != 'undefined') {
						$(this).val(nval);
						if(nval != oval){
							$(this).css('border','2px #f00 solid');
							$(this).css('color','#ff0000');
						}else{
							$(this).css('border','1px #900 solid');
							$(this).css('color','#000000');
						}
					}else{
							$(this).css('border','1px #fs6 solid');
							$(this).css('color','#0a0');
					}
					$("#InMenue").val('N');
					$("#IsPerson").val('Y');
					$("#LSFManaged").val('N');
					$("#Hidden").val('N');
			});
			}
		});
	});
	$("#pageImporter").click(function(event,ui){
		var target = prompt('Please provide an URL for the page to be imported:');
		$.ajax({
				url: fqdn+'helpers/magpie.php',
				data:{
					obj: loggedInAs,
					user: username,
					ext: target
				},
				success: function(resp){
					if (resp.substring(0, 6) == 'Failed') {
						alert(resp);
					}
					else {
						$('#editArea').html($('#editArea').html() + resp);
					}
				}
			});
	});
	$("#pagePubmed").click(function(event, ui){
		var keyword = '';
		keyword = prompt('Please provide a keyword for your Pubmed search. Leave blank to use your name.');
		if(typeof keyword == 'undefined' || keyword == ''){
			keyword = username.split('.');
			keyword = keyword[1] + ' ' + keyword[0];
		}
		var affil = prompt('You can provide an "Affiliation" keyword to filter your search.', 'Heidelberg');
		var morekey = prompt('Any additional search criteria? E.g. "OR EMBL[Affiliation]" (see Pubmed Help)');
		var query = keyword + '[Author]';
		if(typeof affil != 'undefined' && affil !=''){
			query += ' AND ' + affil + '[Affiliation]';
		}
		query += ' ' + morekey;
		keyword = prompt('Please check the query string that will be sent to Pubmed:', query);
		$.ajax({
			url: fqdn + 'helpers/pubmedimp.php',
			data: {
				obj: loggedInAs,
				user: username,
				pub: keyword,
				aff: affil,
				addi: morekey
			},
			success: function(resp){
				if (resp.substr(0, 9) == 'No result') {
					alert(resp);
				}
				else {
					//$("#pmsortlist").html(resp);
					//$("#pubmedsorter").dialog('open');
					//$("#pmsortlist").sortable();
					
					$('#editArea').html($('#editArea').html() + resp);
				}
			}
		});
	});
	$("#pubmedsorter").dialog(
		{
			autoOpen: false,
			width: 'auto',
			height: 800,
			title: 'Pubmedimportsort',
			open: function(){
				$(this).css('visibility','visible');
			},
			close: function(){
				$(this).css('visibility','hidden');
			}
		}
	);
	$("#LSFID_morebtn").click(function(){
		lsfsearch();
	});
	
// Main dialog definitions 
	
	$("#CoWEditBox").dialog({
		autoOpen: false,
		width:748,
		height:720,
		title: "Configuration",
		open: function(){
			var target = $("#target").attr('value');
			var boss = $("#boss").attr('value');
			var page = $("#pageRequest").attr('value');
			$(this).css('visibility','visible');
		},
		close: function(){
			$("#UsernameContainer").detach();
			location.reload();
			$(this).css('visibility','hidden');
		}
	});
	$("#pageEditBox").dialog({
		autoOpen: false,
		width:780,
		height:660,
		title:"Edit Page",
		open: function(){
				var target = $("#target").attr('value');
				var boss = $("#boss").attr('value');
				var page = $("#pageRequest").attr('value');
				$(this).css('visibility','visible');
				$("#editArea").css('width','480');
			},
		close: function(){
				$(this).css('visibility','hidden');
			}
	});
	$("#pageListBox").dialog({
		autoOpen: false,
		width:380,
		height:540,
		title:"List pages for " + username,
		open: function(){
				var target = $("#target").attr('value');
				var boss = $("#boss").attr('value');
				var page = $("#pageRequest").attr('value');
				$(this).css('visibility','visible');
			},
		close: function(){
				$(this).css('visibility','hidden');
			}
	});
	$("#passwdBox").dialog({
		modal: true,
		autoOpen: false,
		title: 'Set/change password',
		width: 540,
		buttons: {
			"Ok": function(){
				var pw1 = $("#passwd1").attr('value');
				var pw2 = $("#passwd2").attr('value');
				var pw0 = $("#passwd0").attr('value');
				var unm = $("#user").attr('value');
				
				if (pw1 == pw2) {
					if (pw1.length > 4) {
						$.ajax({
							async: true,
							data:{
								obj: loggedInAs,
								pw: pw1,
								pwo: pw0,
								user: unm,
								mode: 'Pawo'
							},
							success: function(resp){
								alert(resp);
								ajxresp = resp;
								$("#lastresp").attr('value', ajxresp);
							}
						});
						$(this).dialog('close');
					}
					else {
						$("#msgBox").html('The passwords you entered are too short. Please try again.');
						$("#msgBox").dialog('option', 'title', 'Password error');
						$("#msgBox").dialog('open');						
					}
				}
				else {
					$("#msgBox").html('The passwords you entered do not match. Please try again.');
					$("#msgBox").dialog('option', 'title', 'Password mismatch');
					$("#msgBox").dialog('open');
				}
			},
			"Cancel": function() { 
				$(this).dialog("close"); 
			}},
		open: function(){
				$(this).css('visibility','visible');
		},
		close: function(){
			$("#passwd1").attr('value','');
			$("#passwd2").attr('value','');
			$("#passwd0").attr('value','');
			$(this).css('visibility','hidden');
		},
		width:390
	});
	$("#pageoffbox").dialog({
		autoOpen:false,
		modal:true,
		title:'Inactivate this page',
		buttons:{
			"Continue": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'unpage',
						page: $("#pageName").val(),
						user: username,
						l: $("#lng").attr('value'),
					},
					success: function(resp){
						ajxresp = resp;
						alert(resp);
					}
				});
				$(this).dialog('close');
				location.reload();
			},
			"Cancel":function(){
				$(this).dialog('close');
			}
		},
		open: function(ui,event){
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
		}
	});
	$("#filemanagerbox").dialog({
		modal: false,
		autoOpen:false,
		open: function(ui,event){
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
		}
	});
	$("#xyz").dialog({
		autoOpen: false,
		modal: true,
		width: 460,
		position: ['center',50],
		title: contMsg[lang] + $("#xyz_n").html(),
		buttons: {
			"Cancel": function(){
				$(this).dialog('close');
			},
			"Send": function(){
				if ($("#xyz_s").val().length < 1 && $("#xyz_f").val().length < 7) {
					alert(contErr[lang]);
				}
				else {
					$.ajax({
						data: {
							obj: loggedInAs,
							mode: 'xyz',
							user: $("#xyz_u").html(),
							xyz_t: $("#xyz_t").val(),
							xyz_f: $("#xyz_f").val(),
							xyz_s: $("#xyz_s").val()
						},
						success: function(resp){
							alert(resp);
							$("#xyz").dialog('close');
						}
					});
				}
			}
		},
		open: function(){
			$("#xyz_t").val('');
			$("#xyz_s").val('');
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$(this).css('visibility', 'hidden');
			$("#xyz_u").html(username);
			$("#xyz_n").html(fullname);
			$(this).dialog('option','title',contMsg[lang] + $("#xyz_n").html());
		}
	});
	$("#rightmodbox").dialog({
		modal: false,
		autoOpen: false,
		title: 'Modules to use',
		width: 'auto',
		height: 'auto',
		buttons:{
			"Save": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'setrightmods',
						user: username,
						pages: $("#rightmodPages").val(),
						mods:  $("#rightmodMods").val()
					},
					success: function(resp){
						alert(resp);
						$("#rightmodbox").dialog('close');
					}
				});
			},
			"Delete definition": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'droprightmods',
						user: username,
						pages: $("#rightmodPages").val(),
					},
					success: function(resp){
						alert(resp);
						$("#rightmodbox").dialog('close');
					}
				});
				
			},
			"Cancel": function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility','visible');
			$.ajax({
				data:{
					obj: loggedInAs,
					mode: 'getrightmods',
					user: username,
					page: page
				},
				dataType: 'json',
				success: function(resp){
					$("#rightmodPages").val(resp.pages);
					$("#rightmodMods").val(resp.mods);
				}
			});
		}
	});
	$("#bitbox").dialog({
		autoOpen: false,
		modal: true,
		width: 740,
		buttons:{
			"Close":function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$.ajax({				
				data: {
					obj: loggedInAs,
					mode: 'getbits',
					user: username,
					page: page,
					l:lang
				},
				success: function(resp){
					$("#bitlist").html(resp);
				}
				
			});
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
			location.reload();
		}
	});
	$("#grantBox").dialog({
		autoOpen: false,
		modal: true,
		width: 789,
		height: 'auto',
		buttons: {
			"Cancel": function(){
				$(this).dialog('close');
			},
			"OK": function(){
				saveGrantArea();
				$(this).dialog('close');
			}
		},
		open: function(){
			$.ajax({
				data: {
					obj: loggedInAs,
					mode: 'getgrants',
					user: username,
					l: lang
				},
				success: function(resp){
					$("#grantArea").html(resp);
				}
			});
			$(this).css('visibility', 'visible')
		},
		close: function(){
			$(this).css('visibility', 'hidden');
			$("#grantArea").html('');
		}
	});
	$("#copyBox").dialog({
		autoOpen: false,
		modal: true,
		width: 'auto',
		height: 'auto',
		buttons: {
			"Cancel": function(){
				$(this).dialog('close');
			},
			"Copy": function(){
				$.ajax({
					data: {
						obj: loggedInAs,
						mode: 'lngcp',
						user: username,
						targ: page,
						l: lang
					},
					success: function(resp){
						alert(resp);
					}
				});
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility', 'visible')
		},
		close: function(){
			$(this).css('visibility', 'hidden');
		}
	});
	
// Secondary dialogs and warning messages
	
	$("#pageResetWarnBox").dialog({
		autoOpen:false,
		modal: true,
		title: "Reset page editor",
		open: function(){
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
		},
		buttons:{
			"Continue":function(){
				$("#editArea").html($("#editAreaReset").html());
				$("#pageName").val($("#pageNameReset").html());
				$("#pageacc").val($("#pageaccReset").html());
				$(this).dialog('close');
			},
			"Cancel":function(){
				$(this).dialog('close');
			}
		}
	});
	$("#mkdirbtn").click(function(event,ui){
		$.ajax({
			data:{
				obj: loggedInAs,
				mode:'mkdir',
				targ: $("#selectedDir").val() + prompt('Please enter a name for the folder to be created:',''),
			},
			success:
				function(resp){
					ajxresp = resp;
					$("#lastresp").attr('value', ajxresp);
					$("#selectedFileBx").html('');
					$("#selectedFile").val('');
					$("#preview").css('visibility','hidden');
					alert(resp);
					$("#refresh").click();
				}
			}
		);
		
	});
	$("#rmdirbtn").click(function(event,ui){
		$("#rmdirbox").dialog('open');
	});
	$("#delbtn").click(function(event, ui){
		$("#delbox").dialog('open');
	});
	$("#rmdirbox").dialog({
		autoOpen: false,
		resizable: false,
		height: 200,
		modal: true,
		buttons: {
			"Delete folder and contents": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'rmdir',
						targ: $("#selectedDir").val(),
					},
					success: function(resp){
						ajxresp = resp;
						$("#lastresp").attr('value', ajxresp);
						$("#selectedFileBx").html('');
						$("#selectedFile").val('');
						$("#selectedDirBx").html('');
						$("#selectedDir").val('');
						$("#previewName").attr('href', '#');
						$("#previewName").html('');
						$("#preview").css('visibility', 'hidden');
						alert(resp);
					}
				});
				$( this ).dialog( "close" );
			},
			Cancel: function(){
				$(this).dialog("close");
			}
		},
		open: function(){
			$(this).css('visibility','visible');
		},
		close: function(){
			$("#refresh").click();
		}
	});
	$("#delbox").dialog({
		autoOpen: false,
		resizable: false,
		height: 200,
		modal: true,
		buttons: {
			"Delete selected file": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'del',
						targ: $("#selectedDir").val() + $("#selectedFile").val(),
					},
					success: function(resp){
						ajxresp = resp;
						$("#lastresp").attr('value', ajxresp);
						$("#selectedFileBx").html('');
						$("#selectedFile").val('');
						$("#previewName").attr('href', '#');
						$("#previewName").html('');
						$("#preview").css('visibility', 'hidden');
						alert(resp);
					}
				});
				$( this ).dialog( "close" );
			},
			Cancel: function(){
				$(this).dialog("close");
			}
		},
		open: function(){
			$(this).css('visibility','visible');
		},
		close: function(){
			$("#refresh").click();
		}
	});
	$("#CoWdelbox").dialog({
		autoOpen: false,
		resizable: false,
		height: 'auto',
		modal: true,
		buttons: {
			"Delete user now!": function(){
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'CoWDel',
						user: username,
					},
					success: function(resp){
						alert(resp);
					}
				});
				$( this ).dialog( "close" );
			},
			Cancel: function(){
				$(this).dialog("close");
			}
		},
		open: function(){
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
		}
	});
	$("#rmpgbox").dialog({
		autoOpen: false,
		resizable: false,
		height: 200,
		modal: true,
		buttons: {
			"Delete version now!": function(){
				if ($("body").data('rmpgid') > 0) {
					$.ajax({
						url: fqdn + 'responder.php',
						type: "POST",
						async: false,
						data: {
							obj: loggedInAs,
							mode: 'rmbit',
							user: $("body").data('username'),
							page: $("body").data('page'),
							gobid: $("body").data('rmpgid'),
							l: $("body").data('lang')
						},
						success: function(resp){
							alert(resp);
							$("#bitbox").dialog('open');
						}
					})
				}else{
					alert("No page ID given. Aborting.");
				}
				$(this).dialog("close");
			},
			Cancel: function(){
				$(this).dialog("close");
			}
		},
		open: function(){
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$("body").data('rmpgid','');
			$(this).css('visibility', 'hidden');
		}
	});
	$("#renamebtn").click(function(event,ui){
		$.ajax({
			data:{
				obj: loggedInAs,
				mode:'ren',
				targ: $("#selectedDir").val() + $("#selectedFile").val(),
				newnm: prompt('Please enter the new name:','')
			},
			success:
				function(resp){
					ajxresp = resp;
					$("#lastresp").attr('value', ajxresp);
					$("#selectedFileBx").html('');
					$("#selectedFile").val('');
					$("#selectedDirBx").html('');
					$("#selectedDir").val('');
					$("#preview").css('visibility','hidden');
					alert(resp);
					$("#refresh").click();
				}
			}
		);
	});
	$("#manpwbtn").click(function(event,ui){
		$("#manpwbox").dialog('open');
	});
	$("#manpwbox").dialog({
		autoOpen: false,
		modal: false,
		width:500,
		title: "Manage folder passwords",
		buttons: {
			"OK": function(){
				$("#manpwconf").val('1');
				$(this).dialog('close');
			},
			"Cancel":function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility','visible');
			$("#manpwconf").val('0');
			$("#manpwbox > ul").html('');
			$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'getpws',
						user: username
					},
					dataType: 'json',
					success: function(resp){
						$.each(resp, function(i,v){
							$("#manpwbox > ul").append('<li>Name:<input type="text" value="' + i + '" style="width:8em;">&nbsp;&nbsp;PW:<input type="text" value="" style="width:8em;"></li>')
						});
					}
				});
		},
		close: function(){
			if ($("#manpwconf").val() == '1') {
				var cred = new Array();
				var cra = new Array();
				$("#manpwbox > ul > li").each(function(i, v){
					cred[i] = new Object;
					$(this).find("input").each(function(ii, vv){
						cra[ii] = $(this).val();
					});
					cred[i]['name'] = cra[0].replace(/ /g,'');
					cred[i]['pwd'] = cra[1];
				});
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'pwds',
						user: username,
						creds: cred
					},
					success: function(resp){
						$("#manpwbox > ul").html('');
						alert(resp);
					}
				});
			}
			$(this).css('visibility','hidden');
		}
	});
	$("#protectbtn").click(function(event,ui){
		$("#protbox").dialog('open');
	});
	$("#protbox").dialog({
		autoOpen: false,
		modal: false,
		width:400,
		title: "Password-protect folder",
		buttons: {
			"OK": function(){
				$("#protconf").val('1');
				$(this).dialog('close');
			},
			"Cancel":function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility','visible');
			$("#protconf").val('0');
			$("#protbox > ul").html('');
			if($("#selectedDir").val() == ''){
				$("#protbox").dialog('close');
			}
			$("#protboxhdl").html('Protect ' + $("#selectedDir").val());
			$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'getpws',
						user: username
					},
					dataType: 'json',
					success: function(resp){
						$.each(resp, function(i,v){
							if (i !== '') {
								$("#protbox > ul").append('<li><input type="checkbox" style="width:1.5em;" value="' + i + '">&nbsp;Name:<span>' + i + '</span>&nbsp;</li>');
							}
						});
					}
				});
		},
		close: function(){
			if($("#protconf").val() == '1')
			{
				var prots = '';
				$("#protbox > ul > li > input:checked").each(function(i,v){
					prots += ' ' + $(this).val(); 
				});
				$.ajax({
					data:{
						obj: loggedInAs,
						mode: 'hta',
						targ: $("#selectedDir").val(),
						user: username,
						prots: prots
					},
					success: function(resp){
						$("#protbox > ul").html('');
						alert(resp);
					}
				});
				targ: $("#selectedDir").val()
			}
			$(this).css('visibility','hidden');
		}
		
	});
	$("#closebtn").click(function(event,ui){
		$("#filemanagerbox").dialog('close');
	});
	$("#fromtopicker").dialog({
		title: "Create timed entry",
		autoOpen: false,
		modal: false,
		stack: true,
		zIndex: 99999,
		buttons: {
			"OK": function(){
				var ftp = '[#FROMTO|' + $("#frompick").val() + '|' + $("#topick").val() + '|' + $("#textpick").val() + '#]';
				$('#editArea').val($('#editArea').val().replace('!FT!',ftp));
				$(this).dialog('close');
			},
			"Cancel": function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$("#pageEditBox").dialog('close');
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$("#pageEditBox").dialog('open');
			$(this).css('visibility', 'hidden');
		}
		
	});
	$("#frompick,#topick").datepicker({
		dateFormat:'mm/dd/yy',
		showOn: 'button',
		showWeek:true,
		constrainInput: false
	});
	$("#msgBox").dialog({
		modal: true,
		autoOpen: false,
		title: 'Info',
		buttons: {
			"Ok": function(){
				$(this).dialog("close");
			}
		},
		open: function(){
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$(this).css('visibility', 'hidden');
			$(this).dialog('option', 'width', 240);
			$(this).dialog('option', 'height', 'auto');
			$("#msgBoxPar").html('');
			$("#msgBoxPar").css('display', 'block');
			$(".msgBoxDv").remove();
		}
	});
	$("#helperbox").dialog({
		autoOpen:false,
		title: 'Help',
		open: function(){
			$(this).css('visibility','visible');
		},
		close: function(){
			$(this).css('visibility','hidden');
		}
	});
	$("#helperbox").mouseleave(function(){
		$("#helperbox").dialog('close');
	});
	function persofunkbox(){
		$("body").append('<div id="persofunkbox" style="text-align:left;"></div>');
		$("#persofunkbox").dialog({
			title: 'Personalfunktionen',
			height: 'auto',
			width: 'auto',
			autoOpen: false,
			modal: true,
			open: function(ui,event){
				$.ajax({
					url: $("body").data('fqdn') + 'helpers/persofunk.php',
					data: {
						obj: $("body").data('loggedInAs'),
						user: $("body").data('username'),
						mode: 'inputs'
					},
					success: function(resp){
						$("#persofunkbox").html(resp);
					}
				});
			},
			close: function(event,ui){
				$("#persofunkbox").remove();
			},
			buttons: {
				'OK':function(){
					var pf = $("#persofunk1").val() + "\n" + $("#persofunk2").val() + "\n" + $("#persofunk3").val() + "\n";
					$("#Personalfunktion").val(pf);
					$("#persofunkbox").dialog('close');
				},
				'Close': function(){
					$("#persofunkbox").dialog('close');
				}
			}
		}).dialog('open');
	}
	$(".events").accordion({
		collapsible: true,
		active: false,
		event: "click"
	});
// Plugins and active page elements
	
	$("#fileTree1").fileTree({
		root: 'data/' + username + '/',
		script: urlroot + 'libs/jqueryFileTree/connectors/jqueryFileTree.php',
		multiFolder: false
	}, function(selfile){
		$("#selectedFileBx").html(basename(selfile));
		$("#selectedFile").val(basename(selfile));
		$("#previewName").html(selfile.replace(/\\/g,'/').replace( /.*\//, '' ));
		var abslink = urlroot + selfile; 
		$.ajax({
			data:{
				obj: loggedInAs,
				mode:'filesz',
				targ: docroot + selfile,
			},
			async: true,
			success:
				function(resp){
					ajxresp = resp;
					$("#lastresp").attr('value', ajxresp);
					if(resp > 0){
						if(resp > 1000){
							$("#previewSize").html((resp / 1000) + '&nbsp;MB');
						}else if(resp > 1000000){
							$("#previewSize").html((resp / 1000000) + '&nbsp;GB');
						}else{
							$("#previewSize").html(resp + '&nbsp;kB');
						}
					} else {
						$("#previewSize").html('not accessible!');
					}
				}
			});
		$("#previewName").attr('href',abslink);
		if(selfile.replace(/\\/g,'/').replace(/\/[^\/]*$/, '') == 'data/' + username + '/images'){
			$("#previewImg").attr('src',abslink);
			$("#preview").css('visibility','visible');
		}else if(selfile.substr(-4) == '.jpg' || selfile.substr(-4) == '.png' || selfile.substr(-4) == '.gif' || selfile.substr(-5) == '.jpeg'){
			$("#previewImg").attr('src',abslink);
			$("#preview").css('visibility','visible');
		}else {
			switch(selfile.substr(-4).toLowerCase()){
				case '.pdf':
					var iconfile = 'pdf.png';
				break;
				case '.exe':
					var iconfile = 'application.png';
				break;
				case '.ppt':
					var iconfile = 'ppt.png';
				break;
				case '.odp':
					var iconfile = 'ppt.png';
				break;
				case 'pptx':
					var iconfile = 'ppt.png';
				break;
				case '.txt':
					var iconfile = 'txt.png';
				break;
				case '.xls':
					var iconfile = 'xls.png';
				break;
				case '.ods':
					var iconfile = 'xls.png';
				break;
				case 'xlsx':
					var iconfile = 'xls.png';
				break;
				case '.doc':
					var iconfile = 'doc.png';
				break;
				case 'docx':
					var iconfile = 'doc.png';
				break;
				case '.odt':
					var iconfile = 'doc.png';
				break;
				case '.zip':
					var iconfile = 'zip.png';
				break;
				case 'gzip':
					var iconfile = 'zip.png';
				break;
				case '.tif':
					var iconfile = 'picture.png';
				break;
				case 'tiff':
					var iconfile = 'picture.png';
				break;
				default:
					var iconfile = 'file.png';
			}
			$("#previewImg").attr('src',iconpath + iconfile);
			$("#preview").css('visibility','visible');
		}
	});
	$(".multifigcontainer").each(function(i, v){
		c++;
		var f = 0;
		$('#multifigcontainer' + c + ' > button').each(function(ii, vv){
			f++;
			$(this).data('myimg','fig' + c + '_' + f);
			$(this).data('mycontainer','multifigcontainer' + c);
			$(this).click(function(event, ui){
				var mycontainer = $(this).data('mycontainer');
				$("#" + mycontainer + " > .multifigimgcontainer").css('visibility', 'hidden');
				var myimg = $(this).data('myimg');
				$("#" + myimg).css('visibility', 'visible');
			});
		});
	});
 	$("#refresh").click(function(event,ui){
		var d = $("#selectedDirBx").html();
		d = d.replace(urlroot,'') + '/'; 
		$("#fileTree1").find('[rel$="' + d + '"]').click();
		$("#fileTree1").find('[rel$="' + d + '"]').click();
	});
	$('#file_upload').fileUploadUI({
        uploadTable: $('#files'),
        buildUploadRow: function (files, index) {
            return $('<tr><td>' + files[index].name.substring(0,6) + '...<\/td>' +
                    '<td class="file_upload_progress"><div><\/div><\/td>' +
                    '<td class="file_upload_cancel">' +
                    '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                    '<\/button><\/td><\/tr>');
        },
        buildDownloadRow: function (file) {
			return $('<tr><td>' + file.name + '<\/td><\/tr>');
        }		
    });
	 $("#Personalfunktion_morebtn").click(function(event,ui){
	 	persofunkbox();
	});
	$("#Hidden").change(function(){
		if ($("#Hidden").val() == 'Y') {
	  		$("#InMenue").val('N');
	  }
	});
	$("#citbtn").click(function(){
		$("#citbox").dialog('open');
	})
	$("#citbox").dialog({
		title: "Insert citation",
		autoOpen: false,
		modal: true,
		width: 'auto',
		height: 'auto',
		stack: true,
		buttons: {
			"Insert": function(){
					$('#editArea').tinymce().execCommand(
					'mceInsertContent',false,
					$("#citauth").val() + '. ' + 
					'(<strong>' + $("#cityear").val() + '</strong>). ' + 
					$("#cittitle").val() + '. ' + 
					'<strong>' + $("#citjourn").val() + '</strong>. ' + 
					$("#citvolpp").val() + '. ' + 
					'<br /><div class=pubblend1>Abstract<div class=pubblend2>' + $("#citabstr").val() + '</div></div>' + 
					'[' + $("#citurl").val() + ' ' + $("#citlnktxt").val() + ']<br />');
				$(this).dialog('close');
			},
			"Cancel": function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$(this).css('visibility', 'hidden');
		}
	});
});


// Helper functions on window.load

$(window).load(function(){
	var mfc = 0;
	var maxheight = 0;
	$(".multifigcontainer").each(function(i,v){
		maxheight = 0;
		mfc++;
		$('#multifigcontainer' + mfc + ' > [id^="fig"]').each(function(i,v){
			if($(this).outerHeight() > maxheight){
				maxheight = $(this).outerHeight();
			}
		});
		$(this).css('height',(maxheight + 32));
	});
	chkmenwidth();
	chkColLng();
	$(window).resize(function(event,ui){
		chkmenwidth();
		chkColLng();
	});
	function chkmenwidth(){
		var top = 10;
		var w = parseInt($("#topmenue").css('width'));
		if (w > 527) {
			$("#topmenue > div").css('margin', '4px 4px 4px 4px');

			$("#topmenue > div").each(function(i, e){
				$(this).css('width', '120px');
				$(this).css('height', '36px');
				$("a", this).css('font-size', '24px');
				$(this).css('line-height', '39px');
			});
		}
		else 
			if (w < 528 && w > 447) {
				$("#topmenue > div").css('margin', '4px 4px 4px 4px');

				$("#topmenue > div").each(function(i, e){
					$(this).css('width', '100px');
					$(this).css('height', '32px');
					$("a", this).css('font-size', '20px');
					$(this).css('line-height', '33px');
				});
			}
			else 
				if (w < 448 && w > 355) {
					$("#topmenue > div").css('margin', '3px 4px 2px 4px');

					$("#topmenue > div").each(function(i, e){
						$(this).css('width', '82px');
						$(this).css('height', '24px');
						$("a", this).css('font-size', '16px');
						$(this).css('line-height', '20px');
						$(this).css('padding-bottom', '3px');
						if (i == 0) {
							$(this).css('top', top + 'px');
							$(this).css('left', '0%');
						}else if (i == 1) {
							$(this).css('top', top + 'px');
							$(this).css('left', '25%');
						}
						else 
							if (i == 2) {
								$(this).css('top', top + 'px');
								$(this).css('left', '50%');
							}
							
							else 
								if (i == 3) {
									$(this).css('top', top + 'px');
									$(this).css('left', '75%');
								}
						
					});
					
				}
				else 
					if (w < 356) {
						$("#topmenue > div").css('margin', '3px 4px 2px 4px');
						$("#topmenue > div").each(function(i, e){
							$(this).css('width', '82px');
							$(this).css('height', '24px');
							$("a", this).css('font-size', '16px');
							$(this).css('line-height', '20px');
							$(this).css('padding-bottom', '3px');
							if (i == 0) {
								$(this).css('top', '0px');
								$(this).css('left', '0px');
							}else 
								if (i == 1) {
									$(this).css('top', '0px');
									$(this).css('left', '92px');
								}
							else 
								if (i == 2) {
									$(this).css('top', '36px');
									$(this).css('left', '0px');
								}
								else 
									if (i == 3) {
										$(this).css('top', '36px');
										$(this).css('left', '92px');
									}
							
						});
					}
	}
	function chkColLng(){
		var containheight = $("#pageContainer").outerHeight();
		var leftheight = $("#leftColumn").outerHeight();
		var rightheight = $("#rightColumn").outerHeight();
		var middleheight = $("#middleColumn").outerHeight();
		var mainheight = Math.max(containheight, leftheight,  middleheight);
		$("#leftColumn").css('min-height',mainheight + 'px');
		//$("#rightColumn").css('min-height',mainheight + 'px');
		$("#middleColumn").css('min-height',mainheight + 'px');
		$("#pageContainer").css('min-height',mainheight + 'px');
	}
});

// Helper functions on demand

function changeCosImage(urlroot)
{
	var nextPic = Math.floor(Math.random()*5) + 1;
	$("#bannerpic").attr('src',urlroot + 'images/bannerpics/banner80-' + nextPic + '.jpg');
}
function basename(path) {
    return path.replace(/\\/g,'/').replace( /.*\//, '' );
}
function dirname(path) {
    return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');;
}
function xzy(u, n){
	$("#xyz_u").html(u);
	$("#xyz_n").html(n);
	var contmsg = $("body").data('contMsg');
	var lang = $("body").data('lang');
	$("#xyz").dialog('option','title', contmsg[lang] + n);
	$("#xyz").dialog('open');
}
function gobit(id){
	var fqdn = $("body").data('fqdn');
	var user = $("body").data('username');
	var page = $("body").data('page');
	var lang = $("body").data('lang');
	var loggedInAs = $("body").data('loggedInAs');
	$.ajax({
			url: fqdn + 'responder.php',
			type: "POST",
			async: false,
			data: {
				obj: loggedInAs,
				mode: 'gobit',
				user: user,
				page: page,
				gobid: id,
				l:lang
			},
			success:function(resp){
				alert(resp);	
			}
	});
}
function saveGrantArea(){
	$.ajax({
		data: {
			obj: $("body").data('loggedInAs'),
			mode: 'setgrants',
			user: $("body").data('username'),
			acl: $("#grantArea").val(),
			l: $("body").data('lang')
		},
		success: function(resp){
			alert(resp);
		}
	});
}
function glva(){
	$("body").data('nk',$("#npgbtn").html());
	$("#npgbtn").remove();
}
function rmbit(id){
	var fqdn = $("body").data('fqdn');
	var user = $("body").data('username');
	var page = $("body").data('page');
	var loggedInAs = $("body").data('loggedInAs');
	$("body").data('rmpgid',id);
	$("#rmpgbox").dialog('open');
}
function diffbit(id){
	var fqdn = $("body").data('fqdn');
	var user = $("body").data('username');
	var page = $("body").data('page');
	var lang = $("body").data('lang');
	var loggedInAs = $("body").data('loggedInAs');
	$.ajax({
			url: fqdn + 'responder.php',
			type: "POST",
			async: false,
			data: {
				obj: loggedInAs,
				mode: 'diffbit',
				user: user,
				page: page,
				gobid: id,
				l: lang
			},
			success:function(resp){
				$("#msgBox").dialog('option','width',824);
				$("#msgBoxPar").css('display','none');
				$("#msgBox").append(
					'<div style="width:822px;text-align:left;" class="msgBoxDv">' + resp + '</div>'
				);
				$("#msgBox").dialog('open');
			}
	});
}
function cite(){
	$("#citbox").dialog('open');
	}
	
/*function cite(){
	$("#citbox").dialog({
		title: "Insert citation",
		autoOpen: false,
		modal: true,
		width: 'auto',
		height: 'auto',
		stack: true,
		buttons: {
			"Insert": function(){
					$('#editArea').tinymce().execCommand(
					'mceInsertContent',false,
					$("#citauth").val() + '. ' + 
					'(<strong>' + $("#cityear").val() + '</strong>). ' + 
					$("#cittitle").val() + '. ' + 
					'<strong>' + $("#citjourn").val() + '</strong>. ' + 
					$("#citvolpp").val() + '. ' + 
					'<br /><div class=pubblend1>Abstract<div class=pubblend2>' + $("#citabstr").val() + '</div></div>' + 
					'[' + $("#citurl").val() + ' ' + $("#citlnktxt").val() + ']<br />');
				$(this).dialog('close');
			},
			"Cancel": function(){
				$(this).dialog('close');
			}
		},
		open: function(){
			$(this).css('visibility', 'visible');
		},
		close: function(){
			$(this).css('visibility', 'hidden');
		}
	}).dialog('open'); // 
}*/
// OSM map scripts

function drawmap() {
    OpenLayers.Lang.setCode('de');
    map = new OpenLayers.Map('map', {
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG:4326"),
        controls: [
		new OpenLayers.Control.MouseDefaults(),
		new OpenLayers.Control.Attribution()],
        maxExtent:
            new OpenLayers.Bounds(-20037508.34,-20037508.34,
                                    20037508.34, 20037508.34),
        numZoomLevels: 18,
        maxResolution: 156543,
        units: 'meters'
    });
		
	// Noch mehr Kontrollelemente hinzufügen..
	
	map.addControl(new OpenLayers.Control.LayerSwitcher());
	map.addControl(new OpenLayers.Control.PanZoomBar());
	
	// Position und Zoomstufe der Karte
	
	lon = 9;
	lat = 49;
	zoom = 6; 
	
	checkForPermalink();
	
	// Layer hinzufügen
	
	layer_markers = new OpenLayers.Layer.Markers("Marker", { projection: new OpenLayers.Projection("EPSG:4326"),visibility: true, displayInLayerSwitcher: true });
	layer_vectors = new OpenLayers.Layer.Vector("Zeichnungen", { displayInLayerSwitcher: true } );map.addLayer(layer_vectors);map.addLayer(layer_markers)
	layers = new Array();
	layer_layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
	map.addLayer(layer_layerMapnik)
	layers.push(new Array(layer_layerMapnik,'layer_layerMapnik'));
	setLayer(0);
	
	// An die richtige Stelle springen..
	
	jumpTo(lon,lat,zoom);
	
	// Benutzte Marker Icons hinzufügen..
	
	icons = new Array();
	icons[6] = new Array('http://osmtools.de/easymap/images/pin_green.png','16','28','0','1');
	
	// Marker hinzufügen
	
	addMarker(layer_markers,8.6683073043959,49.414589158789,"<b>INF360</b><p /><div style=\"background-color:white;border:1px solid #fc6;\">R. Hell, T. Rausch, S. Strahl</div>",false,6);
	addMarker(layer_markers,8.6747016906871,49.417967350637,"<b>INF230</b><p /><div style=\"background-color:white;border:1px solid #fc6;\">S. Frings<br />T. Holstein<br />J. Lohmann<br />E. Pollerberg<br />D. Robinson<br />K. Schumacher<br />V. Storch<br />J. Wittbrodt</div>",false,6);
	addMarker(layer_markers,8.6690797805928,49.416124729367,"<b>INF345</b><p /><div style=\"background-color:white;border:1px solid #fc6;\">M. Koch</div>",false,6);
	
	geometries = new Array();
	
	// Nochmal was..
	
	jumpTo(lon, lat, zoom);
	toggleInfo();
	checkUtilVersion(4);
}


