function showPopup (page,width,height,resizeable,scrollbars) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('"+page+"', '" + id + "', 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizeable+',width="+width+",height="+height+"');");
};

function checkIE6 () {
	var Browser = {
	  Version: function() {
	    var version = 999; // we assume a sane browser
	    if (navigator.appVersion.indexOf("MSIE") != -1)
	      // bah, IE again, lets downgrade version number
	      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	    return version;
	  }
	}
	if (Browser.Version() < 7) {
	  document.getElementById('warning_ie6').style.display='block';
	}
}


function facebookShare() {
    var d = document,
        f = 'http://www.facebook.com/share',
        p = '.php?src=bm&v=4&i=1259575049&u=' +
            encodeURIComponent(document.location.href) +
            '&t=' + encodeURIComponent(d.title);
    function a() {
        if (!window.open(f + 'r' + p, 'sharer', 'toolbar=0,status=0,resizable=1,width=626,height=436')) {
            document.location.href = f + p;
        }
    }
    if (/Firefox/.test(navigator.userAgent)) {
        setTimeout(a, 0);
    } else {
        a();
    }
}


/* Text size stuff */
function setTextSize (size) {
	fontSize = 12;
	switch (size) {			
			case 1: fontsize = 12; break;
			case 2: fontSize = 14; break;
			case 3: fontSize = 16; break;

		}

 	$('#font_sizes a').removeClass ('marked');
	$('#font_sizes a:eq('+(size-1)+')').addClass ('marked');
	
	
  $('#content').css('font-size', fontSize);
  $.cookie('lechnerFontSize', size, {path:'/'});

}


function initTextSize () {
	var size = 2;
	if ($.cookie('lechnerFontSize')) {	  
		size = parseInt ($.cookie('lechnerFontSize'));
	
	}
	setTextSize (size);

}





/* Ajax popup window stuff */
popupWindowId = '';

function showPopupWindowFilter () {
	var filterWidth = jQuery(window).width();
	var filterHeight  = jQuery(document).height();
	if (filterHeight<jQuery(window).height())
		filterHeight= jQuery(window).height();
	
//	if (WSystem.ieVersion<7)
		jQuery('#popupWindowFilter').attr('style', 'display:block;width:100%;height:'+filterHeight+'px;');	
//	else
//		jQuery('#popupWindowFilter').attr('style', 'display:block;min-width:'+filterWidth+'px;min-height:'+filterHeight+'px;');

	jQuery('#popupWindowFilter').hide();	

	
	
/*
	if (WSystem.isIE)
		jQuery('#popupWindowFilter').css('filter', 'alpha(opacity=40)');


	jQuery('#popupWindowFilter').fadeIn('1000', function() {
    // Animation complete
  });
*/
	jQuery('#popupWindowFilter').show();	
}

function hidePopupWindowFilter () {
	$('#popupWindowFilter').hide();	
}

function closePopupWindow ()
{
	var obj = document.getElementById (popupWindowId);
	if (obj) {

		
		obj.style.display="none";
		obj.style.visibility = "hidden";

		hidePopupWindowFilter ();	
		WSystem.removeEvent (document,'keyup', onDocumentKeyPress);
		WSystem.removeEvent (document,'mousedown', onDocumentMouseClick);
	}
}

function onDocumentKeyPress (evt) {
	var keyCode = evt.which;
	if (navigator.appName.indexOf("Microsoft")!=-1)
		keyCode = window.event.keyCode;
	if (keyCode==27) { // ESC
		closePopupWindow ();
	}
	return true;
}

this.onDocumentMouseClick = function (evt)  {
	var mouseCoords = WSystem.getMouseCoords (evt);
	var obj = document.getElementById (popupWindowId);
	if (obj) {
		popupCoords = WSystem.getAbsoluteCoords (obj);
		var x  = popupCoords.x;
		var y  = popupCoords.y;
		var x2 = popupCoords.x+parseInt (obj.offsetWidth);
		var y2 = popupCoords.y+parseInt (obj.offsetHeight);
		if (!(
				mouseCoords.x>x && 
		    mouseCoords.x<x2 && 
		    mouseCoords.y>y && 
		    mouseCoords.y<y2 )) {
			// closePopupWindow ();
		}				
	}		
}

function showPopupWindow (id, popupURL, fAutoPrint) {
	var obj = document.getElementById (id);
	if (!obj)
		return;
	
	toggleFlag = true;
	currObjectImgIdx = 0;
	popupWindowId = id;
	var scrollPos = WSystem.getScrollPos ();
	var wndDim		= WSystem.getWindowDim ();
	var wndHeight = wndDim.windowHeight;
	var wndWidth  = wndDim.windowWidth;
	
	var x0 = scrollPos.x;			
	var x1 = x0 + wndWidth;
	var y0 = scrollPos.y;	
	var y1 = y0 + wndHeight;
	
  showPopupWindowFilter ();		
	obj.style.display="block";			

	// $('#popup_content').jScrollPane({scrollbarWidth: 0, dragMaxHeight:0});
	// Progress bar
	$('#'+id+'_content').html ('<div style="text-align:center;"><img src="images/progress.gif" /></div>');
	/*
	var mainFrame = document.getElementById ('main_frame');
	obj.style.left = mainFrame.offsetLeft + ((mainFrame.offsetWidth-obj.offsetWidth)/2) + 'px';
	obj.style.top  = mainFrame.offsetTop + 'px';
	*/
	obj.style.left = (x0+(wndWidth  - parseInt (obj.offsetWidth))  /2)+"px";
	obj.style.top  = (y0+(wndHeight - parseInt (obj.offsetHeight)) /2)+"px";
	
	obj.style.visibility = "visible";	

	// Esc key functions
	WSystem.addEvent (document,'keyup', onDocumentKeyPress, false);
	WSystem.addEvent (document,'mousedown', onDocumentMouseClick, false);

	// Load ajax content
	$.ajax({ url: popupURL, success: function(data) {
		$('#'+id+'_content').html (data); 			
		/*					
		if ($('#scroll_frame'))
			$('#scroll_frame').jScrollPane({scrollbarWidth: 8, dragMaxHeight:120, scrollbarMargin:20 });			
		*/
		if (fAutoPrint) {
			window.print ();
			closePopup ();
		}
	}});
}


function calendarNav (year_month, fProgess) {
	if (fProgess)
		$('#calendar_header').html ('<div style="text-align:center;">Lade Kalender ...</div>');
	$.ajax({ url: "http://"+document.domain+"/calendar.inc.php?year_month="+year_month, success: function(data) {
		if (data!='')
			$('#calendar').html (data); 				
	}});

}

function initMenu ()
{
	var ulObj = document.getElementById ("menuitems").firstChild;	
	menuItems = createMenuItemsFromULStruct (ulObj);
	menu = new Menu (document.getElementById ("main_menu"), "mainmenu", 0, 0, menuItems, true);
}


// Document loaded

$(document).ready(function() {  

	$('#focus_id').focus ();
/*
	
	$(window).resize(function () {
			closePopupWindow ();

	});  
*/       
});

