function I2D_writeMailLink(addr1,addr2,display) {
	var start1 = "<a href=\"m";
	var start2 = "ailto:";
	var end1 = "\">";
	var end2 = "</a>";
	
	document.write(start1+start2+addr1+"@"+addr2+end1+display+end2);
}

function I2D_createMail(addr1,addr2) {
	var start1 = "mai";
	var start2 = "lto:";
	
	location.href = start1+start2+addr1+"@"+addr2;
}

function I2D_winWidth() {
	if (window.innerWidth) {
		return window.innerWidth
	} else if (document.documentElement && document.documentElement.clientWidth) {
		return document.documentElement.clientWidth
	} else if (document.body) {
		return document.body.clientWidth
	}
	return 0;
}

function I2D_winHeight() {
	if (window.innerHeight) {
		return window.innerHeight
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight
	} else if (document.body) {
		return document.body.clientHeight
	}
  return 0;
}

var headerHeight = 114;
var footerHeight = 30;
var topMargin = 10;
var bottomMargin = 10;
var navName = 'subnavigation';
var contentName = 'content';

function I2D_adaptBoxesHeight() {
	var nav = document.getElementById(navName);
	var content = document.getElementById(contentName);

	if ( !nav || !content )
		return;

	var wh = I2D_winHeight();
	var sizeOK = true;
	if ( document.all ) {
		sizeOK = (document.body.offsetHeight > wh);
	} else {
		sizeOK	= (window.scrollMaxY > 0);
	}
	if ( sizeOK ) {
		window.onresize = I2D_adaptBoxesHeight;
		return;
	}

	var iebody = ( (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body );
	var dsoctop  = ( document.all ? iebody.scrollTop : window.pageYOffset );

	var navHeight = wh + dsoctop - topMargin - headerHeight - bottomMargin;
	var contentHeight = navHeight - footerHeight;

	nav.style.height = navHeight+"px";
	content.style.height = contentHeight+"px";

	window.onresize = I2D_adaptBoxesHeight;
}

var fmwWidth = 200;
var fmwHeight = 70; 
var fmwMsg = "Keine Nachricht vorhanden";

function I2D_showFloatingMsg(msg,msgWinWidth,msgWinHeight) {
	fmwMsg = msg;
	fmwWidth = msgWinWidth;
	fmwHeight = msgWinHeight;
	I2D_showFloatingMsg2();
}

function I2D_showFloatingMsg2() {
	var msgArea = (document.all ? document.all.floating_msg : document.getElementById("floating_msg"));
	if ( msgArea != null ) {
		var ww = I2D_winWidth();
		var wh = I2D_winHeight();
		var iebody = ( (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body );
		var dsocleft = ( document.all ? iebody.scrollLeft : window.pageXOffset );
		var dsoctop  = ( document.all ? iebody.scrollTop : window.pageYOffset );
		
		var xPos = Math.floor( (ww - fmwWidth) / 2 + 0.5 + dsocleft);
		var yPos = Math.floor( (wh - fmwHeight) / 2 + 0.5 + dsoctop );
		
		if ( xPos < 0 ) xPos = 0;
		if ( yPos < 0 ) yPos = 0;
		
		msgArea.style.left = xPos+"px";
		msgArea.style.top  = yPos+"px";
		msgArea.style.width  = fmwWidth+"px";
		msgArea.style.height  = fmwHeight+"px";
		msgArea.innerHTML = fmwMsg;
		
		msgArea.style.display  = "block";
		
		window.onresize = I2D_showFloatingMsg2;
	}
}

if(typeof window.Csp=="undefined"){
	window.Csp={};
}

Csp.Menu=function(id){
	this._id=id;
	this._menu=document.getElementById(id);
	this._hider=null;
	this._shower=null;
		
	$().keypress(Function.createDelegate(this,this.bodyKeyPress)).mouseover(Function.createDelegate(this,this.bodyMouseOver));
	$("a.h15-group",this._menu).mouseover(Function.createDelegate(this,this.triggerShow));
	
	if(Sys.Browser.agent==Sys.Browser.InternetExplorer){
		$("a.h15-link",this._menu).click(Function.createDelegate(this,this.linkClick));
	}else{
		$("a.h15-link",this._menu).mousedown(Function.createDelegate(this,this.linkClick));
	}

	$("div.h15-menu-container",this._menu).mouseover(Function.createDelegate(this,this.keepMenuVisible));
};
	
Csp.Menu.prototype={
	bodyKeyPress:function(e){
		if(e.keyCode==27){
			var menu=$(".h15-menu-container:visible",this._menu);
			this.hideMenus();
			menu.prev("a.h15-group").each(function(){this.focus();});
		}},
		
	bodyMouseOver:function(e){
		this.clearShower();
		this.triggerHide();
	},
	
	clearHider:function(){
		if(this._hider!=null){
			window.clearTimeout(this._hider);
			this._hider=null;
		}
	},
	
	clearShower:function(){
		if(this._shower!=null){
			window.clearTimeout(this._shower);
			this.shower=null;
		}
	},
	
	doubleQuote:function(s){
		return s.replace("'","''");
	},
	
	hideMenus:function(e){
		$("div.h15-groups table td").removeClass("h15-selected");
		$(".h15-menu-container",this._menu).hide();
	},
	
	keepMenuVisible:function(e){
		e.stopPropagation();
		this.clearHider();
		this.clearShower();
	},
	
	linkClick:function(e){
		var link=$(e.target);
		var subgroup=link.parents("ul.h15-links").prev("h6.h15-menu-header");
		var group=subgroup.parents("div.h15-menu-container").prev("a.h15-group");
	},
	
	showFlyout:function(e){
		var count=$(".h15-menu-container",this._menu).length;
		var index=$(".h15-menu-container",this._menu).index(e);
		if(document.documentElement.dir!="rtl"){
			if(index<2){
				this.showFlyoutLeft(e);
			}else if(index<count-2){
				if($(".h15-column:has(.h15-menu)",e).length>1){
					this.showFlyoutRightMulti(e);
				}else{
					this.showFlyoutLeft(e);
				}
			}else{
				if($(".h15-column:has(.h15-menu)",e).length>1){
					this.showFlyoutLeftMulti(e);
				}else{
					this.showFlyoutRight(e);
				}
			}
		}else{
			if(index<2){
				this.showFlyoutRight(e);
			}else if(index<count-2){
				if($(".h15-column:has(.h15-menu)",e).length>1){
					this.showFlyoutLeftMulti(e);
				}else{
					this.showFlyoutRight(e);
				}
			}else{
				this.showFlyoutLeft(e);
			}
		}
		e.show();
		window.setTimeout(function(){$(".h15-m1, .h15-m2, .h15-m3, .h15-m4",e).css("background","#fff");},0);
	},
	
	showFlyoutLeft:function(e){
		if(document.documentElement.dir=="rtl"){
			e.css("left",220-e.parent("td").width());
		}
	},
	
	showFlyoutLeftMulti:function(e){
		if(document.documentElement.dir=="rtl"){
			e.css("left",200-e.parent("td").width());
		}else{
			e.css("left",-200+e.parent("td").width());
		}
	},
	
	showFlyoutRight:function(e){
		if(document.documentElement.dir=="ltr"){
			e.css("left",-220+e.parent("td").width());
		}
	},
	
	showFlyoutRightMulti:function(e){
		e.css("left",-200+e.parent("td").width());
	},
	
	showMenu:function(e){
		this.hideMenus();
		var el=$(e.target);
		el.parent("td").addClass("h15-selected");
		this.showFlyout(el.next(".h15-menu-container"));
	},
	
	toggleMenu:function(e){
		e.preventDefault();
		this.clearHider();
		this.clearShower();
		var el=$(e.target).next(".h15-menu-container");
		var shown=el.css("display")!="none";
		this.hideMenus();
		if(!shown){
			el.parent("td").addClass("h15-selected");
			this.showFlyout(el);
		}
	},
	
	triggerHide:function(){
		if(this._hider==null){
			this._hider=window.setTimeout(Function.createDelegate(this,this.hideMenus),1000);
		}
	},
	
	triggerShow:function(e){
		e.stopPropagation();
		this.clearHider();
		if(this._shower!=null){
			this.clearShower();
		}
		this._shower=window.setTimeout(Function.createDelegate(this,function(){this.showMenu(e);}),125);
	},
		
	normalizePathname:function(path){
		return(path.startsWith("/"))?path:"/"+path;
	}
};

Csp.Menu.layout=function(layout,menu){
	var columns=$("div.h15-column",menu);
	var currentHeight=0;
	var index=0;
	var height=0;
	$("div.h15-menu",layout).each(function(){
		height=$(this).height()+5;
		if(currentHeight>0&&index<3&&currentHeight+height>350){
			index++;currentHeight=0;
		}
		currentHeight+=height;
		$(this).appendTo(columns[index]);
	});
	var menuHeight=0;
	columns.each(function(){
		menuHeight=Math.max(menuHeight,$(this).height());
	});
	var menuWidth=(index+1)*200;
	$(menu).height(Math.min(menuHeight,350)+5).width(menuWidth).css({visibility:"visible"});
	$(".h15-menu-inner",menu).height(menuHeight);
	columns.each(function(){
		var column=$(this);
		var ix=columns.index(this);
		if(ix<index){
			column.addClass("h15-dotted");
		}
		if(ix<=index){
			column.height(menuHeight);
		}else{
			column.hide();
		}
	});
};
 