document.write('<script type="text/javascript" src="/js/jquery/jquery.tooltip.mod.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery/jquery.lightbox-0.5.pack.js"></script>');

var w3cDOMsupport		= (document.getElementById && document.createElement) ? true : false;
var isIE6				= (document.defaultCharset && document.compatMode) ? true : false;
var isIE				= false;
var msgBoxEnlarged		= false;
var msgBoxWidth			= null;
var msgBoxHeight		= null;

if (document.getElementById('kcAmount')) {
	document.getElementById('kcAmount').value = 0;
}

function validateForm(f) {
	f.submitButton.value= '... Ihr Beitrag wird geschrieben - bitte etwas Geduld ...';
	f.submitButton.disabled = true;
}

function resizeTextarea(obj) {
	var msgBox = document.getElementById(obj);
	if (msgBoxEnlarged == false) {
		msgBoxWidth = msgBox.style.width;
		msgBoxHeight = msgBox.rows;
		msgBox.style.width ="99%";
		msgBox.rows = msgBoxHeight*2;
		msgBoxEnlarged = true;
		document.getElementById("resizeButton").value = "Eingabefeld verkleinern";
		if (document.getElementById("msgHelp")) {
			document.getElementById("msgHelp").style.visibility = "hidden";
			document.getElementById("msgHelp").style.position= "absolute";
		}
	} else {
		document.getElementById("resizeButton").value = "Eingabefeld vergrößern";
		msgBox.style.width=msgBoxWidth;
		msgBox.rows=msgBoxHeight;
		msgBoxEnlarged = false;
		if (document.getElementById("msgHelp")) {
			document.getElementById("msgHelp").style.visibility = "visible";
			document.getElementById("msgHelp").style.position= "relative";
		}
	}
}

function checkFieldValue(obj) {
	if (obj.value.substr(0,1) == '<') obj.value='';
}

function validateForm(f)
{
	f.submitButton.value= '... Ihr Beitrag wird geschrieben - bitte etwas Geduld ...';
	f.submitButton.disabled = true;
};

function resizeTextarea(obj)
{
	if (w3cDOMsupport) {
		var msgBox = document.getElementById(obj);
		if (msgBoxEnlarged == false) {
			msgBoxWidth = msgBox.style.width;
			msgBoxHeight = msgBox.rows;
			msgBox.style.width ="99%";
			msgBox.rows = msgBoxHeight*2;
			msgBoxEnlarged = true;
			document.getElementById("resizeButton").value = "Eingabefeld verkleinern";
			if (document.getElementById("msgHelp")) {
				document.getElementById("msgHelp").style.visibility = "hidden";
				document.getElementById("msgHelp").style.position= "absolute";
			}
		} else {
			document.getElementById("resizeButton").value = "Eingabefeld vergrößern";
			msgBox.style.width=msgBoxWidth;
			msgBox.rows=msgBoxHeight;
			msgBoxEnlarged = false;
			if (document.getElementById("msgHelp")) {
				document.getElementById("msgHelp").style.visibility = "visible";
				document.getElementById("msgHelp").style.position= "relative";
			}
		}
	}
};


function openMailDialogue(obj) {
	var m = obj.innerHTML;
	m = m.replace(/\s+at\s+/, '@');
	document.location = 'mailto:'+m;
}

function bewerten(param) {
	x=(screen.width/2) - 160;
	y=(screen.height/2) - 90;
	popUpWindow = window.open("/bewerten.html?"+param, "", "width=320,height=180, resizable=no, scrollbars=no, screenX="+x+", screenY="+y+", left="+x+", top="+y);
	popUpWindow.focus();
}


function validateBookForm(f) {
	if (f.msg.value.length < 200) {
		alert("Bitte geben Sie einen aussagekräftigen Kommentar ein (mindestens 200 Zeichen, Sie haben "+f.msg.value.length+" Zeichen geschrieben).");
		f.msg.focus();
		return false;
	} else if (f.username.value.length < 3) {
		alert("Bitte geben Sie Ihren Namen ein (mindestens 3 Zeichen).");
		f.username.focus();
		return false;


        } else {
		f.submitButton.value= '... Ihr Beitrag wird geschrieben - bitte etwas Geduld ...';
		f.submitButton.disabled = true;
		return true;
	}
}

function pasteQuotation(id)
{
	if (w3cDOMsupport) {
		var thisMsgHTML = document.getElementById("msg-"+id);
		var thisMsg = thisMsgHTML.innerHTML;
		var msgBody = thisMsg.split("<p");
		msgBody[0] = msgBody[0].replace(/^\s+/, "");
		msgBody[0] = msgBody[0].replace(/\s+$/, "");
		msgBody[0] = msgBody[0].replace(/<(\/)?strong>/ig,"[$1fett]");
		msgBody[0] = msgBody[0].replace(/<(\/)?em>/ig,"[$1kursiv]");
		//msgBody[0] = msgBody[0].replace(/<(\/)?blockquote>/ig,"[$1zitat]");
		msgBody[0] = msgBody[0].replace(/layout/ig,"$1.gif");
		msgBody[0] = msgBody[0].replace(/(<([^>]+)>)/ig,"");
		document.getElementById("msg").value = "[zitat]"+msgBody[0]+"[/zitat]";
		document.getElementById("reply2Msg").value = id;
		document.getElementById("msg").focus();
	}
};

function markItem(obj) {
	var row = obj.parentNode.parentNode.parentNode;
	var thisItem = document.getElementById(obj.htmlFor);
	if (thisItem.checked == false) {
		obj.htmlFor.checked = true;
		row.className = 'x';
		var shoppingCart = document.getElementById('amazonCart');
		var newISBN = document.createElement('input');
		newISBN.value = 1;
		newISBN.name = 'asin.'+thisItem.value;
		newISBN.id = 'asin-'+thisItem.value;
		newISBN.type = 'hidden';
		newISBN.className = 'amazon-'+thisItem.value;
		shoppingCart.appendChild(newISBN);
		shoppingCart.style.display = 'block';
		document.getElementById('kcAmount').value++;
		document.getElementById('amazonCartSubmit').value = "gewählte Artikel ("+document.getElementById('kcAmount').value+") in Ihren Amazon-Warenkorb legen";
		if (document.getElementById('kcAmount').value == 1) {

		}
	} else {
		row.className = '';
		var shoppingCart = document.getElementById('amazonCart');
		var amazonCartItem = document.getElementById('asin-'+thisItem.value);
		shoppingCart.removeChild(amazonCartItem);
		document.getElementById('kcAmount').value--;
		if (document.getElementById('kcAmount').value > 0) {
			document.getElementById('amazonCartSubmit').value = "gewählte Artikel ("+document.getElementById('kcAmount').value+") in Ihren Amazon-Warenkorb legen";
		} else {
			shoppingCart.style.display = 'none';
		}
	}
};

function resetAmazonCart(obj) {
	document.getElementById('kcAmount').value=0;
	obj.style.display='none';
	var items = obj.getElementsByTagName('input');
	for(i=0;i<items.length;i++) {
		if (items[i].className.substring(6,0) == "amazon") {
			var book = document.getElementById(items[i].className);
			book.checked = false;
			book.parentNode.parentNode.parentNode.className = "";
		}
	}
	window.location.reload();
};

function trim(s) {
	return s.replace(/^\s+(.*)\s+$/,"$1")
};

function coverTooltip(anch, isReview)
{
	href = anch.href.replace('http://'+window.location.host+'/', '');
	href = 'http://www.kinderbuch-couch.de/public/images/buchcover/'+href.replace('.html', '.jpg');
	var text = 'Lesen Sie die Rezension der Kinderbuch-Couch';
	tip = '<img src="'+href+'" width="80" />'+text;
	return tip;
}

$(function() {

	if ($.browser.msie) {
		isIE = true;
	}
	
	if ($('body').hasClass('home')) {	
		$('#new-publications a').tooltip({ 
		    showURL: false, 
		    bodyHandler: function() { 
		        return coverTooltip(this, true); 
		    } 
		});
	}

	if (isIE && parseInt($.browser.version.substr(0,1)) == 6) {
		$('#top-navigation li').mouseover(function(){
			if ($(this).parent().parent().parent().get(0).tagName == 'DIV') {
				$(this).addClass('hover');
			}
		}).mouseout(function(){
			if ($(this).parent().parent().parent().get(0).tagName == 'DIV') {
				$(this).removeClass('hover');
			}
		});
		$('#couch-hopper').mouseover(function(){
			$(this).addClass('hover');
		}).mouseout(function(){
			$(this).removeClass('hover');
		});
	}

	$('#couch-hopper').append('<a href="#" onclick="return false;">Couch wechseln</a><ul></li><li><a href="http://www.histo-couch.de/">Histo-Couch.de</a></li><li><a href="http://www.jugendbuch-couch.de/">Jugendbuch-Couch.de</a></li><li><a href="http://www.kochbuch-couch.de/">Kochbuch-Couch.de</a></li><li><a href="http://www.krimi-couch.de/">Krimi-Couch.de</a></li><li class="l"><a href="http://www.phantastik-couch.de/">Phantastik-Couch.de</a></ul>');
});

if (parent.frames.length) window.top.location.replace(document.location.href);
