var tempString = unescape(location.href);

var Count=0;
var url = '';
var id0_message = 'Du musst erst dem Eintrag einen Titel geben und dann speichern !!';
while (tempString.indexOf('/')>-1 && Count<6) {
    Count=Count+1
    url = url +tempString.substr(0,tempString.indexOf('/'))+"/";
    tempString=tempString.substr(tempString.indexOf('/')+1,tempString.length-tempString.indexOf('/')+1);

}


function GetXmlHttpObject(){
	var xmlHttp = null;
	try{
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function SendReq(url, element){
	var req = GetXmlHttpObject();
	window.status='green';
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			if (element != ""){
				response = req.responseText;
		    	document.getElementById(element).innerHTML = response;
			}

	    }
    }
    req.open("GET", url, true);
    req.send(null);

}
function open_comment_window(url, x, y) {
        window.open(url,"js_window","width="+x+",height="+y+",dependent=yes,toolbar=no,menubar=no,scrollbars=no,resizable=yes,status=no,location=no,top=150,left=200");
}

function ajax_function(name,div){

	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }

	http =url+page+"?function="+name+"&class="+classname;
//	alert(http);
	SendReq(http,div);
}
function get_lexiconline_categories(letter,div){
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=get_lexiconline_categories"+"&letter="+letter;
	SendReq(http,div);
}

function add_lexiconline_category(){
	var classname = document.getElementById('classname').value;
	var level = document.getElementById('level').value;
	var parent_id = document.getElementById('parent_id').value;
	var title = document.getElementById('title').value;

	var page = "index.htm";
	if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=add_lexiconline_category"+"&level="+level+"&parent_id="+parent_id+"&title="+title;
	SendReq(http,'center_ajax');
}
function get_lexiconline_subcategories(cat_id,div){
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=get_lexiconline_categories"+"&cat_id="+cat_id;
	SendReq(http,div);
}

function add_weblog_category(cat_id){
	var classname = document.getElementById('class').value;
	var page = "index.htm";
	var http = url+page+"?function=add_weblog_category"+"&cat_id="+cat_id+"&classname="+classname;
	SendReq(http,'ajax_categories');
}
function remove_weblog_category(cat_id){
	var classname = document.getElementById('class').value;
	var page = "index.htm";
	var http = url+page+"?function=remove_weblog_category"+"&cat_id="+cat_id+"&classname="+classname;
	SendReq(http,'ajax_categories');
}

function add_category(art_id,category_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=add_category"+"&art_id="+art_id+"&category_id="+category_id;
	SendReq(http,'invisible');
}

function add_local_category(art_id,category_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=add_local_category"+"&art_id="+art_id+"&category_id="+category_id;
	SendReq(http,'invisible');
}

function remove_local_category(art_id,category_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=remove_local_category"+"&art_id="+art_id+"&category_id="+category_id;
	SendReq(http,'invisible');
}
function remove_category(art_id,category_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var classname = document.getElementById('classname').value;
	var page = "index.htm";
		 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
	var http = url+page+"?function=remove_category"+"&art_id="+art_id+"&category_id="+category_id;
	SendReq(http,'invisible');
}

function ajax_get_articles(name,arg){

	var classname = document.getElementById('classname').value;
	var page = "index.htm";

	 if (classname == 'bookmark') {
    	  page ="bookmarks.htm";
    }
	 if (classname == 'bild') {
    	  page ="photos.htm";
    }
if (document.getElementById('show_frontpage')==null) {

		var http = url+page+"?function=get_articles"+"&class="+classname+"&"+name+"="+arg;
}
else{
	var http = url+page+"?function=get_articles"+"&class="+classname+"&"+name+"="+arg+"&frontpage=1";
	}//	alert(http);
	SendReq(http,'center_ajax');
}


function view_version(art_id,ver_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";

	var http = url+page+"?function=view_version"+"&art_id="+art_id+"&ver_id="+ver_id;
	//	alert(http);
	SendReq(http,'ajax_version');
}


function delete_article(art_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var conf =  confirm('Bist Du sicher,dass Du den Eintrag löschen möchtest?');
	if (conf) {
	var page = "index.htm";

	var http = url+page+"?function=delete_article"+"&art_id="+art_id;
	SendReq(http,'center_ajax');
	}
}

function set_block(art_id,blocked){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=set_blocked"+"&art_id="+art_id+"&blocked="+blocked;
	SendReq(http,'center_ajax');
}

function show_trackback(art_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=show_trackback"+"&art_id="+art_id;
	SendReq(http,'article_content');
}
function show_article(art_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=show_article"+"&art_id="+art_id;
	SendReq(http,'article_content');
}
function show_notizen(art_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=show_notizen"+"&art_id="+art_id;
	SendReq(http,'article_content');
}

function remove_document(art_id,doc_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=remove_document"+"&art_id="+art_id+"&doc_id="+doc_id;
	SendReq(http,'article_files');
}
function show_permissions(art_id,own_groups){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=show_permissions"+"&art_id="+art_id+"&own_groups="+own_groups;
	SendReq(http,'article_content');
}

function add_group(art_id,group_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=add_group"+"&art_id="+art_id+"&group_id="+group_id;
	SendReq(http,'invisible_action');
}
function remove_group(art_id,group_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
	var http = url+page+"?function=remove_group"+"&art_id="+art_id+"&group_id="+group_id;
	SendReq(http,'invisible_action');
}

function set_pub_read(div_id,art_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	var page = "index.htm";
		if (div_id.checked){
	var http = url+page+"?function=set_pub_read"+"&art_id="+art_id+"&pub_read=1";
	}else {
	var http = url+page+"?function=set_pub_read"+"&art_id="+art_id+"&pub_read=0";

	}
	SendReq(http,'invisible_action');
}
function check_capability(div_id,art_id,group_id){
	if (art_id == 0) {
		return alert(id0_message);
	}
	if (div_id.checked){
 			add_group(art_id,group_id);
	}else{
	 	remove_group(art_id,group_id);
	}
}

function tag_foto(art_id){
	if (art_id == 0) {
		return show_alert();
	}
	var plak = document.getElementById('plak').value;
	if (plak == "") {
		return alert("Error: PLAK = NULL ");
	}
	var page = "index.htm";
	var http = url+page+"?function=tag_foto"+"&art_id="+art_id+"&plak="+plak;
	SendReq(http,'tag_div');
}

function invite_user(art_id){
	if (art_id == 0) {
		return show_alert();
	}
	var email = document.getElementById('email').value;
	if (email == "") {
		return alert("Error: EMAIL = NULL ");
	}
	var body = document.getElementById('bodytext').value;
	var page = "index.htm";
	var http = url+page+"?function=invite_user"+"&art_id="+art_id+"&email="+email+"&body="+body;
	SendReq(http,'einladung_div');
}
function show_alert(){
	return alert(id0_message);
}
