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

var isIE6 				= false;
var w3cDOMsupport		= (document.getElementById && document.createElement) ? true : false;
var isIE				= (document.all && !document.addEventListener) ? true : false;
var isIE50				= (isIE && !document.createEventObject) ? true : false;
var isIE55				= (isIE && document.createEventObject && !document.compatMode) ? true : false;
var isIE60				= (isIE && document.defaultCharset && document.compatMode) ? true : false;
var isFirefox			= (window.XML) ? true : false;
var isOpera				= (document.detachEvent && document.addEventListener) ? true : false;
var msgBoxEnlarged		= false;
var msgBoxWidth			= null;
var msgBoxHeight		= null;

function insertCode(str)
{
	document.getElementById('msg').value += ' '+str;
};
 
function addTag(obj, targetField)
{
	tag = obj.innerHTML;
	if (document.getElementById(targetField)) {
		document.getElementById(targetField).value += tag +', ';
	}
	return false;
};
 
function changeEdition(selector)
{
	var editionASIN = selector[selector.selectedIndex].value;
	var amazonLink = String(document.getElementById('amazon-link').href);
	document.getElementById('amazon-link').href = amazonLink.replace(/\/product\/.*\?/ig, '/product/'+editionASIN+'?');
	document.getElementById('cover').src = 'http://meine.literatur-couch.de/covers/'+editionASIN.substr((editionASIN.length-2),2)+'/'+editionASIN+'_m.jpg';
}; 
 
function checkFieldValue(obj)
{
	if (obj.value.substr(0,1) == '<') obj.value='';
};

/**
 *
 */

function validateForm(f)
{
	if (f.id == 'book-comment') {
		var commentMinLength = 300;
		f.comment.value = strip_tags(trim(remove_duplicates(f.comment.value)));
		var commentPosted = f.comment.value;
		if (commentPosted.length < commentMinLength) {
			informUser('Bitte geben Sie mindestens '+commentMinLength+' Zeichen ein. Sie haben '+commentPosted.length+' eingegeben.');
			return false;
		} else {
			return true;
		}
	}
	f.submitButton.value= '... einen Moment ...';
	f.submitButton.disabled = true;
};

function informUser(s)
{
	alert(s);
};

/**
 *
 */

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 pasteQuotation(id)
{
		var thisMsgHTML = document.getElementById("msg-"+id);
		var thisMsg = thisMsgHTML.innerHTML;
		var msgBody = thisMsg.split("<p");
		msgBody[0] = trim(msgBody[0]);
		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 pop(obj, width, height, scrolling)
{ 
	var x=(screen.width-width)/2; 
	var y=(screen.height-height)/2;
	if (scrolling) {
		scrollbars = "yes";
	} else {
		scrollbars = "no";
	}
	popUpWindow = window.open(obj.href, "", "width="+width+",height="+height+",resizable=no,scrollbars="+scrollbars+",screenX="+x+",screenY="+y+",left="+x+",top="+y);
	//popUpWindow.focus();
	return false;
};

function getCookie(key) 
{
	var s, e;
	if (document.cookie) {
		s = document.cookie.indexOf(key+"=");
		if (s < 0) return null;
		s = document.cookie.indexOf("=", s) + 1;
		e = document.cookie.indexOf(";", s);
		if (e < 0) {
			e = document.cookie.length;
		}
		return unescape(document.cookie.substring(s, e));
 	} else {
 		return null;
 	}
};

function setCookie(key, value, lifetime)
{
	var now = new Date();
	var expiry = new Date(now.getTime() + lifetime*24*60*60*1000);
	if ((key != null) && (value != null)) {
		document.cookie = key + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/; domain=.krimi-couch.de";
		alert('Diese Ansicht wurde als Ihre neue Standard-Ansicht gespeichert.');
	}
};

function dropCookie(key) 
{
	document.cookie = key+ "=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.krimi-couch.de";
};

function savePreferredDisplay(obj)
{
	if (obj.value && obj.checked) {
		setCookie('BookshelfPreferredDisplay', obj.value, 30);
	}
};

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

function strip_tags(s) {
	return s.replace(/(<([^>]+)>)/ig,""); 
};

function remove_duplicates(s) {
	return s.replace(/([\d\D])\1{3,}/ig, "$1"); 
};

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

function confirmSubmit(question)
{
	var agree = confirm(question);
	return agree ? true : false;
};

$(document).ready(function() {
	
	if ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7) {
		isIE6 = true;
		$('#top-navigation ul li').hover(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		);
		
		$('img[src$=.png]').each( function() {
			width  = $(this).attr('width');
			height = $(this).attr('height');
			$(this).attr('writing-mode', 'tb-rl');
			$(this).css('background-image', 'none');
			$(this).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+$(this).attr('src')+'",sizingMethod="scale")');
			$(this).attr('src', '/images/layout/transp.gif');
			$(this).attr('width', width);
			$(this).attr('height', height);
		});
		
	} else {
		isIE = false;
	}	
	
	$(':input').focus(
		function() {
			if ($(this).val().substr(0,1) == '<') {
				$(this).val('');
			}			
		}
	);
	
	$('a[rel=lightbox]').lightBox({
		overlayOpacity: 0.5,
		containerResizeSpeed: 350,
		imageLoading: '/images/layout/3.0/ajax-loader-img.gif',
		txtImage: '',
		txtOf: ''
	});	
	
});

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