var wait = 0;
function showCal(path, month, year, lang)
{
	$(document).ready(function()
	{
		$.ajax(
	      {type: "POST", url: path+"/calendar/calendar.php", 
			beforeSend: function()
			{
				wait = 1;
				setTimeout(function(){ displayWait(path)}, 200);
			}
			 ,data: ({ lang: lang, monat: month, jahr: year, path: path  }),
		 	success: function(data)
			{					
				wait = 0;
				$("#cal").html(data);
				//$("#"+parentElmId).unbind("ajaxStart");
			}
		});
	});
}

function displayWait(path)
{
  if(wait)
    $("#cal").html('<p>&nbsp;</p><p class="center"><img src="'+path+'/images/loader.gif" /></p>');
}

function calendarclick(path, month, year, lang)
{
    if(month == 13)
    {
    	month = 1;
    	year = year + 1;
	}
	if(month == 0)
    {
		month = 12;
		year = year - 1;
	}
	
	showCal(path, ""+month+"", ""+year+"", lang);
    
}

function overlib(typ, desc, zeitraum, lang, evt)
{
	var divmutter = document.getElementById("cal");
	var divneu = document.createElement("div");
	var divoben = document.createElement("div");
	var divclose = document.createElement("div");
	var divunten = document.createElement("div");
	var position = $("#cal").position();

	//Position des Mauszeigers ermittel um das overlib zu positionieren
	var x = (evt.x || evt.layerX);
	var y = (evt.y || evt.layerY);
	
	var overlibX;
	var overlibY;
	if(navigator.userAgent.indexOf("Safari") == -1)
	{
		//all other browser
		overlibX = x-211;
		overlibY = y+1;
	}
	else
	{
		//if safari
		overlibX = (x-position.left)-218;
		overlibY = (y-position.top)+13;
	}
	divmutter.style.zIndex = 1;
	
	divneu.setAttribute('id',"neu");
	divneu.style.width = "213px";
	divneu.style.height = "auto";
	divneu.style.border = "1px #89b81d solid";
	divneu.style.top = overlibY+"px";
	divneu.style.fontSize = "10px";
	divneu.style.left = overlibX+"px";
	divneu.style.zIndex = 1;
	divneu.style.backgroundColor = "#EEEEEE";
	divneu.style.position = "absolute";
	divneu.style.display = "none";
		
		//var text = document.createTextNode("<img src='wait.gif' />");
	//divneu.innerHTML = tag;
	divmutter.appendChild(divneu);
	
	
	divoben.setAttribute('id',"oben");
	divoben.style.width = "210px";
	divoben.style.height = "12px";
	divoben.style.textAlign = "left";
	divoben.style.paddingLeft = "3px";
	divoben.style.borderBottom = "1px #89b81d solid";
	divoben.style.fontSize = "10px";
	divoben.style.zIndex = 1;
	divoben.style.backgroundColor = "#CCCCCC";
	divoben.style.position = "relative";
	
	divclose.setAttribute('id',"obenc");
	divclose.style.position = "absolute";
	divclose.style.cursor = "pointer";
	divclose.style.left = "200px";
	divclose.style.top = "0";
	if(typ != "Feiertag")
		divclose.innerHTML = "<span onclick=\"close2()\">X</span>";	
	
	divoben.innerHTML = "Datum: "+zeitraum;
	divneu.appendChild(divoben);
	//divneu.setAttribute('onmouseout',"close2()");
	divoben.appendChild(divclose);
	divunten.setAttribute('id',"unten");
	divunten.style.width = "210px";
	divunten.style.height = "auto";
	divunten.style.minHeight = "30px";
	divunten.style.textAlign = "left";
	divunten.style.paddingLeft = "3px";
	//divunten.style.border = "1px #AA0000 dashed";
	divunten.style.fontSize = "10px";
	divunten.style.zIndex = 1;
	divunten.style.backgroundColor = "#FFFFFF";
	
	divunten.innerHTML = desc;
	divneu.appendChild(divunten);

	$("#neu").fadeIn("slow");
}

function close2()
{
	try
	{
		var divneu = document.getElementById("neu");
		var divmutter = document.getElementById("cal");
		var divoben = document.getElementById("oben");
		var divclose = document.getElementById("obenc");
		var divunten = document.getElementById("unten");
		
		divoben.removeChild(divclose);
		divneu.removeChild(divoben);
		divneu.removeChild(divunten);
		divmutter.removeChild(divneu);
	} catch(e)
	{}
}
