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;

		}

 	jQuery('#font_sizes a').removeClass ('marked');
	jQuery('#font_sizes a:eq('+(size-1)+')').addClass ('marked');
	
	
  jQuery('#content').css('font-size', fontSize);
  jQuery.cookie('lechnerFontSize', size, {path:'/'});

}


function initTextSize () {
	var size = 2;
	if (jQuery.cookie('lechnerFontSize')) {	  
		size = parseInt (jQuery.cookie('lechnerFontSize'));
	
	}
	setTextSize (size);

}





/* Ajax popup window stuff */
popupWindowId = '';

function showPopupWindowFilter () {	
	if (WSystem.ieVersion<7) {
		var filterHeight  = jQuery(document).height()-4;
		if (filterHeight<jQuery(window).height())
			filterHeight = jQuery(window).height();
		jQuery('#popupWindowFilter').attr('style', 'position:absolute;left:0;top:0;display:block;width:100%;height:'+filterHeight+'px;');	
	}
	else
		jQuery('#popupWindowFilter').attr('style', 'position:fixed;left:0;top:0;display:block;width:100%;height:100%;');	
	jQuery('#popupWindowFilter').hide();	
	jQuery('#popupWindowFilter').show();	
}

function hidePopupWindowFilter () {
	jQuery('#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

	/*
	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
	if (popupURL!='') {
		jQuery('#'+id+'_content').html ('<div style="text-align:center;"><img src="images/progress.gif" /></div>');
		jQuery.ajax({ url: popupURL, success: function(data) {
			jQuery('#'+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) {
	var fVisible = jQuery.cookie('calendar_visible');
	if (fVisible && fVisible=='on') {
		jQuery ('#calendar').show ();
		jQuery ('#calendar_toggle_text').html ('ausblenden');
	}

	if (fProgess)
		jQuery('#calendar_header').html ('<div style="text-align:center;">Lade Kalender ...</div>');
	jQuery.ajax({ url: "http://"+document.domain+"/calendar.inc.php?year_month="+year_month, success: function(data) {
		if (data!='')
			jQuery('#calendar').html (data); 				
	}});

}

function calendarToggle () {

	var obj = document.getElementById ('calendar');
	if (obj) {
		Effect.toggle('calendar','BLIND',{duration:0});
		
		if (obj.style.display != 'none') {
			jQuery('#calendar_toggle_text').html ("einblenden");
			jQuery.cookie('calendar_visible', 'off', {path:'/'});
		}
		else {
			jQuery.cookie('calendar_visible', 'on', {path:'/'});
			jQuery('#calendar_toggle_text').html ("ausblenden");
		}
	}
}


function loadMachines () {
	document.machineform.cmd.value='load_machines';
	document.machineform.submit();
}

function initMenu ()
{
	var ulObj = document.getElementById ("menuitems").firstChild;	
	menuItems = createMenuItemsFromULStruct (ulObj);
	menu = new Menu (document.getElementById ("main_menu"), "mainmenu", 0, 0, menuItems, true);
}


jQuery(document).ready(function() {  

	jQuery('#focus_id').focus ();


	jQuery(window).resize(function () {

	});  

});

