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

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};

function newsletter(restaurant) {

	lightBox = '<input type="hidden" id="wo" name="wo" value="'+restaurant+'" /><p><img src="./images/inhalt/schriften/'+restaurant+'.png" alt="'+restaurant+'" /></p><p>E-Mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="email" id="email" style="width:200px;" /></p><p><div class="lb-newletter-button-div"><input type="image" src="./images/aboAnmelden.png" title="Abo anmelden" alt="Button Abo anmelden" onclick="ajaxNewsletter(\'anmelden\');" /></div><div class="lb-newletter-button-div"><input type="image" src="./images/aboAbmelden.png" title="Abo abmelden" alt="Button Abo abmelden" onclick="ajaxNewsletter(\'abmelden\');" /></div><div class="clearer"></div></p><img src="./images/lightbox-btn-close.gif" alt="Schließen" title="Schließen" id="lb-button-close" />';

	$("#lb-lightbox-content").css("width","350px").css("height","150px");
	$("#lb-lightbox-content").html(lightBox);

	$('#lb-overlay,#lb-lightbox,#lb-lightbox-content').css("display","block");

	var arrPageSizes = getPageSize();
	// Style overlay and show it
	$('#lb-overlay').css({
		backgroundColor:	"#000000",
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	// Get page scroll
	var arrPageScroll = getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#lb-lightbox').css({
		top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
		left:	arrPageScroll[0]
	}).show();
	// Assigning click events in elements to close overlay

	$('#lb-overlay, #lb-button-close').click(function() {
		$('#lb-overlay,#lb-lightbox,#lb-lightbox-content').css("display","none");
		$("#lb-lightbox-content").html();
	});
}

function showLightBox(was) {
	if (was == "karte") {
		lightBox = '<img src="images/tirolkarte.jpg" style="position:absolute; top:5px; left:5px; width: 990px; height: 447px;" /><img src="images/lightbox-btn-close.gif" alt="Schließen" title="Schließen" id="lb-button-close" />';
		$("#lb-lightbox-content").css("width","980px");
		$("#lb-lightbox-content").css("height","500px");
	}
	else if (was == "impressum") {
		lightBox = '<h1><img src="./images/imp_fuerInhalt.png" /></h1><h1><img src="./images/imp_prima.png" /></h1><p>Kirchstieglstra&szlig;e 14<br />6322 Kirchbichl<br />Tel.: 05332/87882<br>Fax: 05332/87882-80<br />E-Mail: <a href="mailto:zentrale@primagast.at">zentrale@primagast.at</a></p><p>Firmenbuch Nr. FN 23819d<br>Landesgericht Innsbruck</p><h1><img src="./images/imp_konzeption.png" /></h1><p>acc cross media GmbH.<br />Adamgasse 23<br />A 6020 Innsbruck<br /><a href="http://www.accxmedia.com" target="_blank">www.accxmedia.com</a></p><img src="./images/lightbox-btn-close.gif" alt="Schließen" title="Schließen" id="lb-button-close" />';
		$("#lb-lightbox-content").css("width","320px").css("height","350px");
	}
	$("#lb-lightbox-content").html(lightBox);

	$('#lb-overlay,#lb-lightbox,#lb-lightbox-content').css("display","block");

	var arrPageSizes = getPageSize();
	// Style overlay and show it
	$('#lb-overlay').css({
		backgroundColor:	"#000000",
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	// Get page scroll
	var arrPageScroll = getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#lb-lightbox').css({
		top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
		left:	arrPageScroll[0]
	}).show();
	// Assigning click events in elements to close overlay

	$('#lb-overlay, #lb-button-close').click(function() {
		$('#lb-overlay,#lb-lightbox,#lb-lightbox-content').css("display","none");
		$("#lb-lightbox-content").html();
	});	

}

function ajaxNewsletter(typ) {
	if (typ == "abmelden")
		data="ajaxAction=newsletterAbmeldung";
	else
		data="ajaxAction=newsletterAnmeldung";

	data += "&wo="+$("#wo").val();
	data += "&email="+$("#email").val();

	$.ajax({
		type: "POST",
		url: "ajaxServer.php",
		data: data,
		success: function(response) {
			temp = trim(response);
			if (temp.length > 0) {		
				alert(temp);
				
				$('#lb-overlay,#lb-lightbox,#lb-lightbox-content').css("display","none");
				$("#lb-lightbox-content").html();
			}
		}
	});

	return false;
}
