
/**
 * DynamicIframe Version 0.8
 * by Mathias Karstaedt, Birger Pannwitt
 */


/*
 * Es muss festgestellt werden, ob das prototyp.js vorhanden ist
 */
var prototypeExists = true;

try {
    if (Abstract.TimedObserver);
	prototypeExists = true;
} catch (e) {
    prototypeExists = false;
    //alert('prototype not exists! ' + e);
} 

if (prototypeExists) {
 
    var IframeObserver = Class.create(Abstract.TimedObserver, {
	getValue: function() {
		try{
			var iframeWindow = (this.element.contentWindow || this.element.contentDocument.defaultView);
			var iframeHtmlElement = iframeWindow.document.documentElement;
			var iframeContentHeight = (document.all) ?  iframeWindow.document.body.scrollHeight + 50 : iframeHtmlElement.offsetHeight;
			var parent = this.element.parentNode;
			return iframeContentHeight + parent.getWidth();
		}catch(e){}
	}
    });

    var DynamicIframe = Class.create({
	initialize: function(iframe) {
		this.iframe = $(iframe);
		this.parent = this.iframe.parentNode;
		Event.observe(this.iframe, 'load', this.resizeIframe.bind(this));
		
		if (Prototype.Browser.IE6) {
			// 25.08.2009 Birger : macht im IE6 Probleme
			// Event.observe(this.iframe, 'resize', this.resizeIframe.bind(this));
		}
		else {
			Event.observe(this.iframe, 'resize', this.resizeIframe.bind(this));
		}
		Event.observe(this.iframe, 'load', this.scrollToTop.bind(this));
	},
	
	scrollToTop: function() {		
		$(parent).window.scrollTo(0, 0);
	},
	
	resizeIframe: function() {
		var parentDimensions = $(this.parent).getDimensions();
		$(this.iframe).setStyle({
			'width': "100%"/*parentDimensions.width + "px"*/,
			'overflow': "hidden"
		});
		try {
			var iframeWindow = (this.iframe.contentWindow || this.iframe.contentDocument.defaultView);
			var iframeHtmlElement = iframeWindow.document.documentElement;
			var iframeContentHeight = (document.all) ?  iframeWindow.document.body.scrollHeight + 50 : iframeHtmlElement.offsetHeight;
			$(this.iframe).setStyle({
				'height': iframeContentHeight + "px"
			});
		} catch (e) {}
		if (!this.iframe.resizeListener) this.iframe.resizeListener = new IframeObserver(this.iframe, 0.2, this.resizeIframe.bindAsEventListener(this));
	}
    });



/**
 * LPMenu Version 0.1
 * by Mathias Karstaedt
 */

var LPMenu = Class.create({

	initialize: function(menuElement) {
		this.menuElement = $(menuElement);
		if (this.menuElement) {
			this.initULElement(this.menuElement);
		}
	},

	initULElement: function(ul) {
		var self = this;
		//Alle li durchlaufen
		ul.childElements().each(function(li) {
			li.parentUl = ul;
			//Schauen ob es untermenupunkte gibt
			var subUl = li.getElementsBySelector("ul").first();
			if (subUl) {
				li.subUl = subUl;
				subUl.hide();
				subUl.parentLi = li;
				self.initULElement(subUl);
			}
			//Schauen ob es ein Link gibt
			var link = self.getMenuItemLink(li);
			if (link) {
				if (link.hash) Event.observe(link, "click", function() {
					subUl.toggle();
				});
				if (link.href == document.location.href) {
					self.activateMenuItem(li);
				}
			}
		});
	},
	
	getMenuItemLink: function(li) {
		return li.getElementsBySelector("a").first();
	},

	activateMenuItem: function(itemId) {
		var li = $(itemId);
		if (li) 
			this.activate(li);
	},
	
	activate: function(li) {
		if (this.oldMenuItem) 
			this.deactivate(this.oldMenuItem); 
			
		this.openPath(li);
		var link = this.getMenuItemLink(li);
		if (link) 
			link.addClassName("active");
		this.oldMenuItem = li;
	},
	
	deactivate: function(li) {
		var link = this.getMenuItemLink(li);
		if (link) link.removeClassName("active");
		this.closePath(li);
	},

	openPath: function(li) {
		li.parentUl.show();
		if (li.subUl) li.subUl.show();
		if (li.parentUl.parentLi) this.openPath(li.parentUl.parentLi);
	},
	
	closePath: function(li) {
		if (li.subUl) li.subUl.hide();
		if (li.parentUl.parentLi) this.closePath(li.parentUl.parentLi);
	}
});


}

function editPage() {
	var currentLocation = document.location.href;
	if (currentLocation.indexOf('?')>0) {
		document.location.href = currentLocation + "&" + "edit=true";
	}
	else {
		document.location.href = currentLocation + "?" + "edit=true";
	}
}


function openWindow(url, target, options) {
	window.open(url, '_blank', '');
	return false;
}

/**
 * Pr&uuml;ft, ob die &uuml;bergebene Emailadresse g&uuml;ltig ist.
 * @param true | false
 * @return
 */
function isValidEmail(email) {
	var isValid = email != "" && email.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
	return isValid;
}



