function rate_init(){
	$("#rating_ajax").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#rating_ajax_div").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#rating_ajax_load").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	window.setTimeout('rate()', 500);
	return false;
}
function rate(){
	var dummy1 = document.getElementById('rating_ajax_sel').selectedIndex;
	var stars = document.getElementById('rating_ajax_sel').options[dummy1].value;
	
	jQuery.get('ajax_rate.php?book='+book+'&rate='+stars, null, rate_2, 'json');
	return false;
}
function rate_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	
		$("#rating_ajax_text").html(data.newtext)
		$("#rating_ajax_stars").removeAttr("class");
		$("#rating_ajax_stars").addClass(data.stars);		
	window.setTimeout('rate_3()', 500);
}
function rate_3(){
	$("#rating_ajax_load").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#rating_ajax").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#rating_ajax_div").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
}
function fav_init(){
	$("#fav_ajax").animate({opacity: 0.0}, 'normal', 'swing', fav);
	return false;
}
function fav(){
	jQuery.get('ajax_fav.php?book='+book, null, fav_2, 'text');
	return false;
}
function fav_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}	

	document.getElementById('fav_ajax_a').innerHTML = data;
	fav_3();
}
function fav_3(){
	$("#fav_ajax").animate({opacity: 1.0}, 'normal');
}

lastadded = false;
function comment_ajax_init(){
	$("#comment2_ajax_load").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#comment_ajax").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	window.setTimeout('comment_ajax()', 500);
	return false;
}
function comment_ajax(){
	jQuery.post('ajax_comment.php?answer='+document.getElementById('answer').value+'&mode='+document.getElementById('answer_t').value, 'text='+escape(document.getElementById('comment_ajax_text').value), comment_ajax_2, 'text');
	return false;
}

function comment_ajax_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}	

	splitted = data.split('|||||');
	document.getElementById('comment_ajax_R').innerHTML = splitted[0];
	window.setTimeout('comment2_ajax('+String(splitted[1])+')', 250);
	lastadded = splitted[1];
}
function comment2_ajax(id){
	jQuery.get('ajax_comments.php?book='+book+'&comment='+String(id), null, comment2_ajax_2, 'text');
	return false;
}
function comment2_ajax_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	
	document.getElementById('comments_ajax').innerHTML = data;
	$("#thecomment_"+String(lastadded)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#comment2_ajax_load").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	check_therearecomments();
}
function comments_show(){
  $("#comment_ajax").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
  $("#comment2_ajax_load").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
}
current_del_fav = false;
function fav_opt_init(id){
	jQuery.get('ajax_fav_opt.php?book='+id, null, fav_opt_2, 'text');
	current_del_fav = id;
}
function fav_opt_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
  $("#fav_"+String(current_del_fav)).animate({
    opacity: 'hide',
	height: 'hide'
  },'slow');
}
/* AJAX COMMENT-EDIT */
aktedit = false;
function nl2br( str ) {
    return (str + '').replace(/([^>])\n/g, '$1<br />\n');
}
function htmlentities(str,typ) {
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
	var entity=new Array(
		"&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
		"&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
		"&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
		"&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
		"&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
		"&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
		"&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
		"&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
		"&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
		"&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
		"&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
		"&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
	);
	for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
	return str;
}
function edit_comment(id) {
	edit_comment_close();
	closewritenew();
	edit_book_close();

	$("#editdiv_"+String(id)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#comment_text_"+String(id)).animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	aktedit = id;
}
function edit_comment_close() {
	if (aktedit == false) return;
	$("#editdiv_"+String(aktedit)).animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#comment_text_"+String(aktedit)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	aktedit = false;
}
function edit_comment_send() {
	$("#editdiv_"+String(aktedit)).animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#load_"+String(aktedit)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	jQuery.post('ajax_editcomment.php?id='+String(aktedit), 'text='+escape($("#editarea_"+String(aktedit)).val()), edit_comment_fertig, 'text');
}
function edit_comment_fertig(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	if (data != '') {
		alert(data);
	} else {
		$("#comment_text_"+String(aktedit)).html(nl2br(htmlentities($("#editarea_"+String(aktedit)).val(), 'str')));
	}
	$("#comment_text_"+String(aktedit)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#load_"+String(aktedit)).animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	check_therearecomments();
}
function closewritenew() {
	if (cdummy == false) return;
	cdummy = false;
	$("#comment_ajax").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
}

/* Bücher Editieren */
book_editing = false;
function edit_book() {
	edit_comment_close();
	closewritenew();
	edit_book_close();

	$("#edit_book").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#show_book").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
}
function edit_book_close() {
	if (book_editing == true) return;

	$("#edit_book").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#show_book").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
}
function edit_book_send() {
	$("#edit_book").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
	$("#editbook_load").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	jQuery.post('ajax_editbook.php?id='+String(book), 'desc='+escape($("#edit_bookdesc").val())+'&title='+escape($("#edit_booktitle").val())+'&author='+escape($("#edit_bookauthor").val())+'&tags='+escape($("#edit_booktags").val()), edit_book_fertig, 'text');
}
function edit_book_fertig(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	if (data != '') {
		alert(data);
	} else {
		$("#bookdesctext").html(nl2br(htmlentities($("#edit_bookdesc").val(), 'str')));
		$("#booktagstext").html(nl2br(htmlentities($("#edit_booktags").val(), 'str')));
		$("#theauthor").html(htmlentities($("#edit_bookauthor").val(), 'str')+':');
		$("#thetitle").html(htmlentities($("#edit_booktitle").val(), 'str'));
	}
	$("#show_book").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
	$("#editbook_load").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
}

/* AJAX COMMENT-DELETE */
function del_comment(id) {
	if (!confirm('Wirklich löschen?')) return;
	edit_comment_close();
	closewritenew();
	edit_book_close();

	aktedit = id;

	$("#load_"+String(aktedit)).animate({
			height: 'show',
			opacity: 'show'
		}, 'slow', 'swing', del_comment_send);
}
function del_comment_send() {
	jQuery.post('ajax_delcomment.php?id='+String(aktedit), del_comment_fertig, 'text');
}
function del_comment_fertig(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	if (data != '') {
		alert(data);
		$("#load_"+String(aktedit)).animate({
				height: 'hide',
				opacity: 'hide'
			}, 'slow');
	} else {
		$("#thecomment_"+String(aktedit)).animate({
				height: 'hide',
				opacity: 'hide'
			}, 'slow', 'swing', del_comment_entf);
	}
	
}
function del_comment_entf() {
	$("#thecomment_"+String(aktedit)).remove();
	aktedit = false;
	
	check_therearecomments();
}

/* Keine Kommentare vorhanden */
function check_therearecomments() {
	if ($("#comments_ajax").text() == '' || $("#comments_ajax").text() == ' ') {
		$("#nocomments").animate({
				height: 'show',
				opacity: 'show'
			}, 'slow');
	} else {
		$("#nocomments").animate({
				height: 'hide',
				opacity: 'hide'
			}, 'slow');
	}
}
function feedlink(){
  if(document.getElementById('opt_b').checked)
    opt_b = '1';
  else
    opt_b = '0';
  if(document.getElementById('opt_c').checked)
    opt_c = '1';
  else
    opt_c = '0';
  opt_l = document.getElementById('opt_l').value;
	$("#feedlink").animate({
				opacity: 0.0
			}, 'slow', 'swing', function(){window.setTimeout("jQuery.post('ajax_rssgen.php?"+post+"', feedlink_2, 'text');", 20);});
	post = "b="+opt_b+"&c="+opt_c+"&l="+opt_l;
	
}
function feedlink_2(data, textStatus){
	if (textStatus != 'success') {
		alert('Fehler:'+"\n"+textStatus);
		return;
	}
	$("#feedlink").html(data);
	window.setTimeout("feedlink_3()", 250);
}
function feedlink_3(){
	$("#feedlink").animate({
				opacity: 1.0
			}, 'slow');
}