var phpAds_campain_big;
var phpAds_campain_sky;
function comment(parent,relation,country,article) {
	if (last = document.getElementById('input_form')){
		var last_id = document.getElementById('input_form').getAttribute('parent_id');
		document.getElementById('a_' + last_id).style.display = 'inline';
		document.getElementById('c_' + last_id).removeChild(last);
	}

	if (document.getElementById("login_div")){
		document.getElementById("c_0").removeChild(document.getElementById("login_div"));
	}
	if  (!document.getElementById("user_name")) {
		var form = document.createElement('form');
		form.style.borderTop = '1px solid #b2b2b2';
		form.style.paddingTop = '10px';
		form.setAttribute('parent_id',parent);
		form.setAttribute('id','input_form');
		form.setAttribute('name','input_form');
		form.setAttribute('action','/auth/login');
		form.setAttribute('method','post');
		form.setAttribute('accept-charset','UTF-8');

		form.appendChild(document.createTextNode('Sie können im Forum nur posten, wenn Sie eingeloggt sind.'));
		form.appendChild(document.createElement('br'));
		form.appendChild(document.createElement('br'));

		var hidden = document.createElement('input');
		hidden.setAttribute('type','hidden');
		hidden.setAttribute('name','dest');
		hidden.setAttribute('value',document.URL + '#p' + parent);
		form.appendChild(hidden);

		var div2 =  document.createElement('div');
		var text2 = document.createTextNode(' Username ');
		var login = document.createElement('input');
		login.setAttribute('type','text');
		login.setAttribute('name','username');
		div2.appendChild(login);
		div2.appendChild(text2);
		form.appendChild(div2);

		var div3 =  document.createElement('div');
		var text3 = document.createTextNode(' Passwort ');
		var passwd = document.createElement('input');
		passwd.setAttribute('type','password');
		passwd.setAttribute('name','password');
		div3.appendChild(passwd);
		div3.appendChild(text3);
		form.appendChild(div3);

		var div4 =  document.createElement('div');
		div4.style.textAlign = 'right';

		var submit = document.createElement('input');
		submit.setAttribute('type','submit');
		submit.setAttribute('value','einloggen');
		div4.appendChild(submit);

		form.appendChild(div4);

		var div5 = document.createElement('div');
		var register = document.createElement('a');
		register.setAttribute('href','/auth/show');
		register.setAttribute('target','_blank');
		register.appendChild(document.createTextNode('Ich möchte einen neuen Account anlegen bzw ich habe mein Passwort vergessen.'));
		div5.appendChild(register);

		form.appendChild(div5);

	} else {

		var form = document.createElement('form');
		form.setAttribute('action','/cat/postings/post_comment');
		form.setAttribute('id','input_form');
		form.setAttribute('name','input_form');
		form.setAttribute('method','post');
		form.setAttribute('enctype','application/x-www-form-urlencoded');
		form.setAttribute('accept-charset','utf-8');
		form.setAttribute('onSubmit', 'return check(' + parent + ')');
				form.setAttribute('parent_id',parent);
				form.style.borderTop = '1px solid #b2b2b2';
				form.style.paddingTop = '10px';

				var moderated = document.createElement('div');
				moderated.style.color = 'red';
				var anon = document.createTextNode('Unsere Foren sind moderiert. Beiträge werden erst nach Sichtung freigeschalten. Dies kann je nach Tageszeit unterschiedlich lange dauern. Wir bitten um Verständnis.');
				moderated.appendChild(anon);
				form.appendChild(moderated);
				var fett = document.createElement('b');
				var richt = document.createElement('a');
                richt.setAttribute('href','/agb/richtlinien.shtml');
                richt.setAttribute('target','_blank');
                var richt_text = document.createTextNode('Bitte beachten Sie die Richtlinen');
                richt.appendChild(richt_text);

				fett.appendChild(richt);
				form.appendChild(fett);
				var br = document.createElement('br');
				form.appendChild(br);
				var br = document.createElement('br');
				form.appendChild(br);

				var parent_id = document.createElement('input');
				parent_id.setAttribute('type','hidden');
				parent_id.setAttribute('name','parent_id');
				parent_id.setAttribute('value', parent);

				var rel_id = document.createElement('input');
				rel_id.setAttribute('type','hidden');
				rel_id.setAttribute('name','relation');
				rel_id.setAttribute('value',relation);

				var country_id = document.createElement('input');
				country_id.setAttribute('type','hidden');
				country_id.setAttribute('name','country');
				country_id.setAttribute('value',country);

				form.appendChild(parent_id);
				form.appendChild(rel_id);
				form.appendChild(country_id);

				var div_text = document.createElement('div');
				div_text.appendChild(document.createTextNode('Sie schreiben als "'));
				var anonym = document.createElement('span');
				anonym.style.fontWeight = 'bold';
				anonym.appendChild(document.createTextNode(document.getElementById("user_name").innerHTML));
				div_text.appendChild(anonym);
				div_text.appendChild(document.createTextNode('".'));

				if (article) {
					var subject = document.createElement('input');
					subject.setAttribute('type','hidden');
					subject.setAttribute('name','article');
					subject.setAttribute('value',article);
					
				} else {
					var subject = document.createElement('input');
					subject.setAttribute('type', 'text');
					subject.setAttribute('name', 'subject');
					subject.setAttribute('title', 'Sie können hier eine kurze Überschrift angeben.');
					subject.style.width = '100%';					
				}

				form.appendChild(div_text);
                if (parent != 0) {
                    var parent_subject =  document.getElementById('rs_' + parent);
                    var subjstr;
                    if (parent_subject.firstChild.firstChild) {
                        subjstr = parent_subject.firstChild.firstChild.nodeValue;
                    } else {
                        subjstr = "";
                    }

					if (subjstr.match(/^Re/)) {
						var pattern = /^Re\((\d+)\)(.*)/; 
						pattern.exec(subjstr);
						var count = RegExp.$1;
						count = parseInt(count);
						count += 1;
						subjstr = "Re(" + count + ")" + RegExp.$2;
					} else {
						subjstr = "Re: " + subjstr;						
					}
					
                    subject.setAttribute('value', subjstr );
                }

                var div_subj = document.createElement('div');
                div_subj.setAttribute('id','sdb_' + parent);
                div_subj.appendChild(subject);
                form.appendChild(div_subj);

				var body = document.createElement('textarea');
				body.setAttribute('name','body');
				body.setAttribute('title','Tragen Sie hier Ihr Kommentar ein.');
				body.setAttribute('style','width:100%;');
				body.setAttribute('rows','12');
				body.style.width = '100%';

				var div_body = document.createElement('div');
				div_body.setAttribute('id','fdb_' + parent);
				div_body.appendChild(body);
				form.appendChild(div_body);

				var submit = document.createElement('input');
				submit.setAttribute('type', 'submit');
				submit.setAttribute('value', 'absenden');

				form.appendChild(submit);
	}
	document.getElementById('c_' + parent).appendChild(form);
	document.getElementById('a_' + parent).style.display = 'none';

}


function toggle(id) {
	var sibling = document.getElementById(id);
	var toggled = sibling.getAttribute('toogled');
	var thread = sibling.getAttribute('thread_id');
	var level = sibling.getAttribute('level');

	if (toggled == 'yes') {
		document.getElementById('i_' + id).setAttribute('src', '../../Threads/arrowd.png');
		sibling.setAttribute('toogled','no');
	} else {
		document.getElementById('i_' + id).setAttribute('src', '../../Threads/arrow.png');
		sibling.setAttribute('toogled','yes');
	}

	while(sibling = sibling.nextSibling) {
		if (sibling.nodeName == 'DIV' && sibling.className == 'threads_comment') {
			if (Number(sibling.getAttribute('level')) <= Number(level) || sibling.getAttribute('thread_id') != thread) {
				break;
			}
			if (toggled == 'yes') {
				var togglecount = sibling.getAttribute('togglecount');
				sibling.setAttribute('togglecount',--togglecount);
				if (togglecount == 0) {
					sibling.style.display = 'block';
				}
			} else {
				var togglecount = sibling.getAttribute('togglecount');
				sibling.setAttribute('togglecount',++togglecount);

				sibling.style.display = 'none';
			}
		}
	}
}





function login() {
	if (document.getElementById("login_div")){
		document.getElementById("c_0").removeChild(document.getElementById("login_div"));
	} else {
		if (last = document.getElementById('input_form')){
			var last_id = document.getElementById('input_form').getAttribute('parent_id');
			document.getElementById('a_' + last_id).style.display = 'inline';
			document.getElementById('c_' + last_id).removeChild(last);
		}

		var div = document.createElement('div');
		div.setAttribute('id','login_div');

		var form = document.createElement('form');
		form.style.borderTop = '1px solid #b2b2b2';
		form.style.paddingTop = '10px';
		form.setAttribute('action','/auth/login');
		form.setAttribute('method','post');
		div.appendChild(form);
		var hidden = document.createElement('input');
		hidden.setAttribute('type','hidden');
		hidden.setAttribute('name','dest');
		hidden.setAttribute('value',document.URL + '#threads');
		form.appendChild(hidden);

		var div2 =  document.createElement('div');
		var text2 = document.createTextNode(' Username ');
		var login = document.createElement('input');
		login.setAttribute('type','text');
		login.setAttribute('name','username');
		div2.appendChild(login);
		div2.appendChild(text2);
		form.appendChild(div2);

		var div3 =  document.createElement('div');
		var text3 = document.createTextNode(' Passwort ');
		var passwd = document.createElement('input');
		passwd.setAttribute('type','password');
		passwd.setAttribute('name','password');
		div3.appendChild(passwd);
		div3.appendChild(text3);
		form.appendChild(div3);

		var div4 =  document.createElement('div');
		div4.style.textAlign = 'right';

		var submit = document.createElement('input');
		submit.setAttribute('type','submit');
		submit.setAttribute('value','einloggen');
		div4.appendChild(submit);

		form.appendChild(div4);

		var div5 = document.createElement('div');
		var register = document.createElement('a');
		register.setAttribute('href','/auth/show');
		register.setAttribute('target','_blank');
		register.appendChild(document.createTextNode('Ich möchte einen neuen Account anlegen bzw ich habe mein Passwort vergessen.'));
		div5.appendChild(register);

		form.appendChild(div5);


		document.getElementById("c_0").appendChild(div);
		div.setAttribute('tgl','true');
	}
}


function help() {
	if (document.getElementById("help_div")){
		document.getElementById("c_0").removeChild(document.getElementById("help_div"));
	} else {
		var help_div = document.createElement('div');
		help_div.style.borderTop = '1px solid #b2b2b2';
		help_div.style.borderBottom = '1px solid #b2b2b2';
		help_div.style.margin = '10px 12px 0px 12px';
		help_div.style.paddingBottom = '10px';
		help_div.style.paddingTop = '10px';
		help_div.setAttribute('id','help_div');
		help_div.appendChild(document.createTextNode('Hilfe:'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		var help_img3 = document.createElement('img');
		help_img3.setAttribute('src','/Threads/help3.png');
		help_div.appendChild(document.createTextNode(' Sie können im Forum nur posten, wenn Sie eingeloggt sind. Sollten Sie  noch keinen Account haben, registrieren Sie sich bitte '));
		var a = document.createElement('a');
		a.setAttribute('href','/auth/create');
		a.appendChild(document.createTextNode('hier.'));
		help_div.appendChild(a);
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Um sich einzuloggen, klicken Sie bitte auf '));
		help_div.appendChild(help_img3);
		help_div.appendChild(document.createTextNode('.'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Geben Sie dann im Formular (Abbildung 1) im ersten Feld (1) Ihren Benutzernamen und im zweiten Feld (2) Ihr Passwort ein und klicken sie anschließend auf einloggen (3).'));
		help_div.appendChild(document.createElement('br'));
		var help_img4 = document.createElement('img');
		help_div.appendChild(document.createElement('br'));
		help_img4.setAttribute('src','/Threads/help4.png');
		help_div.appendChild(help_img4);
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('(Abbildung 1)'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Um einen neuen Eintrag zu erstellen, bzw. einen bestehenden Eintrag zu kommentieren, klicken Sie auf den entsprechenden Link.'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Im Formular (Abbildung 2) können Sie im ersten Feld (1) eine Kommentar-Titel angeben.'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Im zweiten Feld (2) geben Sie bitte Ihren Kommentar ein.'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('Anschließend klicken Sie auf "absenden" (3). Ihr Kommentar erscheint, sobald dieser von der Redaktion freigegeben wird.'));
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createElement('br'));
		var help_img2 = document.createElement('img');
		help_img2.setAttribute('src','/Threads/help2.png');
		help_div.appendChild(help_img2);
		help_div.appendChild(document.createElement('br'));
		help_div.appendChild(document.createTextNode('(Abbildung 2)'));

		if (document.getElementById("c_0").firstChild){
			document.getElementById("c_0").insertBefore(help_div,document.getElementById("c_0").firstChild);
		} else {
			document.getElementById("c_0").appendChild(help_div);
		}
	}
}

function check(id) {
	var subject = document.input_form.subject.value;
	if (subject == '') {
		document.getElementById("sdb_" + id).style.border = '2px solid red';
		alert('Sie müssen einen Kommentar-Titel angeben!.');
		return false;
	}
	var body = document.input_form.body.value;
	if (body == '') {
		document.getElementById("fdb_" + id).style.border = '2px solid red';
		alert('Sie müssen einen Kommentar-Text angeben!.');
		return false;
	}
	return true;
}

function search_posts() {
	if (document.getElementById("search_form")){
		document.getElementById("c_0").removeChild(document.getElementById("search_form"));
		document.getElementById("c_0").removeChild(document.getElementById("search_results"));
		document.getElementById('comments').style.display = "block";
	} else {
		var root = document.getElementById("c_0");
		var form = document.createElement('form');
		form.setAttribute('id','search_form');
		form.setAttribute('action','javascript:submit_search()');
		var nick = document.createElement('input');
		nick.setAttribute('id','nick');
		nick.setAttribute('name','nick');
		nick.setAttribute('type','text');
		form.appendChild(nick);
		var nicks = document.createElement('div');
		nicks.setAttribute('id','nicks');
		nicks.setAttribute('class','autocomplete');
		form.appendChild(nicks);
		form.appendChild(document.createTextNode(' Poster Name'));
		var ind = document.createElement('img');
		ind.setAttribute('src','/Threads/ind.gif');
		ind.setAttribute('id','indn');
		ind.style.display = 'none';
		form.appendChild(ind);
		form.appendChild(document.createElement('br'));
		var select = document.createElement('select');
		select.setAttribute('size',1);
		select.setAttribute('id','forum');
		select.setAttribute('name','forum');
		var option1 = document.createElement('option');
		option1.setAttribute('value',0);
		option1.appendChild(document.createTextNode('alle Foren'));
		select.appendChild(option1);
		var option2 = document.createElement('option');
		option2.setAttribute('value','69');
		option2.appendChild(document.createTextNode('Allgemeines Forum'));
		select.appendChild(option2);
		form.appendChild(select);
		form.appendChild(document.createTextNode(' Forum'));
		form.appendChild(document.createElement('br'));
		var search = document.createElement('input');
		search.setAttribute('id','search');
		search.setAttribute('name','search');
		search.setAttribute('type','text');
		form.appendChild(search);
		form.appendChild(document.createTextNode(' Such Text'));
		form.appendChild(document.createElement('br'));
		var div = document.createElement('div');
		div.style.textAlign = "right";
		var ind2 = document.createElement('img');
		ind2.setAttribute('src','/Threads/ind.gif');
		ind2.setAttribute('id','ind2');
		ind2.style.visibility = 'hidden';
		div.appendChild(ind2);
		var submit = document.createElement('input');
		submit.setAttribute('type','submit');
		submit.setAttribute('value','suchen');
		div.appendChild(submit);
		form.appendChild(div);
		root.appendChild(form);
		var results = document.createElement('div');
		results.setAttribute('id','search_results');
		root.appendChild(results);

		new Ajax.Request('/cgi-bin/test/search.pl?action=foren', {onSuccess: insertforen()});
		new Ajax.Autocompleter("nick", "nicks", "/cgi-bin/test/search.pl", {indicator: 'indn', minChars: 1, parameters: 'action=nick'});
	}
}


var insertforen = function(t){
	var options = eval(t.responseText);
	for( i = 0; i < options.length; i++ ) {
		var length = $('tts').options.length;
		$('tts').options[length] = new Option(options[i][0],options[i][1]);
	}
};

/*
function submit_search() {
	$('ind2').style.visibility = 'visible';
	var param = "";

	if($F('nick')){
		param += "nick=" + $F('nick') + ";";
	}
	if($F('forum') != 0){
		param += "forum=" + $F('forum') + ";";
	}
	if($F('search')){
		param += "search=" + $F('search') + ";";
	}

	new Ajax.Request('/cgi-bin/test/search.pl', {onSuccess: insertsearchresults, onFailure: function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); }, parameters: 'action=search;' + param });
}
var insertsearchresults = function(t){
	$('comments').style.display = "none";

		$("c_0").removeChild(document.getElementById("search_results"));
		var results = document.createElement('div');
		results.setAttribute('id','search_results');
		$('c_0').appendChild(results);
	
	var results = eval(t.responseText);
	for( i = 0; i < results.length; i++ ) {
		var div = document.createElement('div');
		var head = document.createElement('div');
		head.setAttribute('class','threads_subj');
		var date = document.createElement('div');
		date.appendChild(document.createTextNode(results[i]['time']));
		date.style.float = 'right';
		date.style.textAlign = 'right';
		date.style.textSize = '10px';
		head.appendChild(date);
		head.appendChild(document.createTextNode(results[i]['nick']));
		var subj = document.createElement('div');
		subj.style.fontWeight = 'bold';		
		subj.appendChild(document.createTextNode(results[i]['subject']));
		head.appendChild(subj);
		var body = document.createElement('div');
		body.setAttribute('class','threads_body');
		body.style.fontSize = '10px';
		body.appendChild(document.createTextNode(results[i]['body']));
		div.appendChild(head);
		div.appendChild(body);
		$('search_results').appendChild(div);
		$('search_results').appendChild(document.createElement('br'));
	}
	$('ind2').style.visibility = 'hidden';

};
*/

