var boxHeight=0;
var boxWidth=0;
var aYear=0;
	
function addmonth(mon, z)
{
	var cls = "ds";
	if(z==-2)
	{
		z="n.vf."; // nicht verfügbar
		cls="nv";
	}
	else if(z==0)
	{
		z = "vg."; // nicht fertig
		cls="nf";
	}
	else if(z==-1)
	{
		z = "n.vg."; // nicht erfaßt
		cls="ne";
	}
	else if(z==-3)
	{
		z = "0"; // Rumpfmonat, keine Datensätze, aber abgeschlossen
	}

   return "<td class=\"" + cls + " mon\">"+mon+"</td><td class=\""+cls+"\">"+z+"</td>";
}	
	
function mouseover(el) 
{
	boxHeight=0;
	boxWidth = 0;
	if(el.innerHTML!="")
	{
		aYear = parseInt(el.innerHTML);
	}

	var aDiv = document.getElementById("jdet");
	if(aDiv == null)
	{
		// Erzeuge neues Div-Element
		aDiv = document.createElement('div');
		aDiv.setAttribute('id', "jdet");
		aDiv.style.display="none";
		document.body.appendChild(aDiv);
	}

	
	var content = el.abbr;
	el.title="";
	var v = content.split(";");
	var aStatus = v[1]
	if(aStatus=="0")
	{
		v[2]=0; v[3]=0; v[16]=0;
		for(i=4;i<=15;i++)
			v[i]=-2;
	}
	
	var strOut = "<h1>" +v[0]+"</h1>" + v[2] + "/" + v[3] + " Monaten erfaßt: "+ v[16] +" Datensätze<table>";
	strOut += "<tr>"+addmonth("Jänner", v[4])+addmonth("Juli", v[10])+"</tr>";
	strOut += "<tr>"+addmonth("Februar", v[5])+addmonth("August", v[11])+"</tr>";
	strOut += "<tr>"+addmonth("März", v[6])+addmonth("September", v[12])+"</tr>";
	strOut += "<tr>"+addmonth("April", v[7])+addmonth("Oktober", v[13])+"</tr>";
	strOut += "<tr>"+addmonth("Mai", v[8])+addmonth("November", v[14])+"</tr>";
	strOut += "<tr>"+addmonth("Juni", v[9])+addmonth("Dezember", v[15])+"</tr>";
	strOut += "</table>";
		
	aDiv.innerHTML = strOut;
	"Jahr: " + v[0]+"\r\nJänner: "+v[1]+"\r\nFebruar: "+v[2]+"\r\nDezember: "+v[12];
	el.onmouseout=mouseout;
	document.body.onmousemove = mousemove;
}

function mouseout()
{
	//alert("mm");
}

function mouseouttable()
{
	boxHeight=0;
	boxWidth = 0;
	var aDiv = document.getElementById("jdet");
	aDiv.style.display="none";
	document.body.removeChild(aDiv);
	document.body.onmousemove = null;
}

function mousemove(ev)
{
	var aDiv = document.getElementById("jdet");
	aDiv.style.display="block";
	
	if(boxHeight==0 && boxWidth==0)
	{
			boxHeight = $('#jdet').outerHeight();
			boxWidth = $('#jdet').outerWidth();
	}
	
	var x = 0;
	var y = 0;
	var relX = 0;
	var relY = 0;

	if (!ev) var ev = window.event;
	if (ev.pageX || ev.pageY) 	
	{
		x = ev.pageX;
		y = ev.pageY;
	}
	else if (ev.clientX || ev.clientY) 	
	{
		x = ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		y = ev.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

/*	
	relXLeft = x-$(window).scrollLeft();
	relYTop = y-$(window).scrollTop();
	relXRight = $(window).width()-boxWidth-relXLeft-4;
	relYBottom = $(window).height()-boxHeight-relYTop-4;
*/  
  //if(relXRight<0)
  if(aYear % 10 >= 5)
		x -= (boxWidth+4);
	else
		x += 4;

	//if(relYBottom<0)
	if(aYear>=1800)
		y -= (boxHeight+4);
	else
		y +=4;
  
  aDiv.style.left = x+"px";
  aDiv.style.top = y+"px";
  
  
  //aDiv.innerHTML = myDivWidth + ": " + x + "/" + y + "   " + window.innerHeight + "$" +cposY+ "<br>" + relX + "/" + relY;
  //aDiv.innerHTML = relXLeft + " " + relYTop + "   /   " + relXRight + " " + relYBottom;
	
}
