Date.prototype.getFullDays = function(m, y) {
	for(var x=28; x<=31; ++x) {
		if(new Date(y,m-1,x).getMonth()
		!=new Date(y,m-1,1).getMonth())
		break;
	}
	return x-1;
};
var datum = new Date();
var aktmonth=1;



function monthup(field,kid){
	aktmonth++;
	openKalender(field,kid);
}

function monthdown(field,kid){
	aktmonth--;
	openKalender(field,kid);
}

function newOpenKalender(field,kid){
	mouspos=getMousPos();
	document.getElementById(kid).style.visibility='visible';
	document.getElementById(kid).style.left=(mouspos[0]-30)+"px";
	document.getElementById(kid).style.top=(document.getElementById(kid).offsetTop-10)+"px";
	openKalender(field,kid);
}

function openKalender(field,kid){
	
	day=datum.getDate();
	monat=datum.getMonth()+aktmonth;
	year=datum.getFullYear();
	if(monat<1){
		monat=12-(monat*-1);
		year=year-1;
	}else	if(monat>12){
		monat=monat-12;
		year=year+1;
	}
	
	
	days=datum.getFullDays(monat,year);
	output="<div class=\"kalenderhead\"><a class=\"kalenderbutton\" href=\"javascript:monthdown('"+field+"','"+kid+"');\"><<</a> "+getMonat((monat-1))+"  "+year+" <a class=\"kalenderbutton\" href=\"javascript:monthup('"+field+"','"+kid+"');\">>></a></div>";
	for(i=0;i<days;i++){
		data=(i+1)+"."+monat+"."+year;
		output+="<a href=\"javascript:insertIntoField('"+field+"','"+data+"','"+kid+"')\" class=\"kalendertag\">"+(i+1)+"</a>";
	}
	document.getElementById(kid).innerHTML="";
	document.getElementById(kid).innerHTML=output;
}

function insertIntoField(field,value,kid){
	document.getElementsByName(field)[0].value=value;
	document.getElementById(kid).style.visibility='hidden';
}

function getMonat(m){
	switch(m){
		case 0:
			return "Januar";
			break;
		case 1:
			return "Februar";
			break;
		case 2:
			return "März";
			break;
		case 3:
			return "April";
			break;
		case 4:
			return "Mai";
			break;
		case 5:
			return "Juni";
			break;
		case 6:
			return "Juli";
			break;
		case 7:
			return "August";
			break;
		case 8:
			return "September";
			break;
		case 9:
			return "Oktober";
			break;
		case 10:
			return "November";
			break;
		case 11:
			return "Dezember";
			break;
	}
}	
var posarray= new Array();
function setMouspos(e){
	
	posarray[0] = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	posarray[1] = (document.all) ? window.event.y + document.body.scrollTop   : e.pageY;

}

function testScroll(){
	alert(window.event.y);
	alert(window.event.clientY);
}

function getMousPos(){
	outoutarray= new Array();
	outoutarray=posarray;
	return outoutarray;
}

function setHelpPos(id){
	mouspos=getMousPos();
	//alert(document.getElementById(id).offsetTop);
	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).style.left=mouspos[0]+"px";
	document.getElementById(id).style.top=document.getElementById(id).offsetTop+"px";
}

function init(){
	document.onmousemove = setMouspos;
	if(typeof(load)=="function"){
		load();
	}
}

window.onload = init;

