var Calendar=new Object();
Calendar.DateFormat="d.m.y";
Calendar.scroll=new Array();
Calendar.scroll={left: 0, top: 0}

Calendar.GetScroll=function() {
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		this.scroll.top=window.pageYOffset;
		this.scroll.left=window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		this.scroll.top=document.body.scrollTop;
		this.scroll.left=document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		this.scroll.top=document.documentElement.scrollTop;
		this.scroll.left=document.documentElement.scrollLeft;
	}
}
/*
Calendar.Create=function(name, x, y, event) {
	this.GetScroll();
        Calendar.Left=(x?x:0)+event.clientX+this.scroll.left;
        Calendar.Top=(y?y:0)+event.clientY+this.scroll.top;
        p=document.getElementById(name);
        df=Calendar.DateFormat.split(".", 3);
        date=p.value.split(".", 3);
        d=new Date();
        for (i=0; i<=2; i++) {
                if (df[i]=='y' | df[i]=='Y') {
                        Calendar.year=(date[i]<1000 ? 2000 : 0)+date[i]*1;
                } else if (df[i]=='m') {
                        Calendar.month=date[i];
                }
        }
        Calendar.year=(date[2]>0 ? Calendar.year : d.getFullYear());
        Calendar.month=((date[1]>=0 & date[1]<12) ? Calendar.month-1 : Calendar.month=d.getMonth());
        Calendar.name=name;
        Calendar.Update();
        Calendar.Show();
        return false;
}
*/

Calendar.Create=function(name, x, y) {
	this.GetScroll();
        Calendar.Left=(x?x:0);
        Calendar.Top=(y?y:0);
        p=document.getElementById(name);
        df=Calendar.DateFormat.split(".", 3);
        date=p.value.split(".", 3);
        d=new Date();
        for (i=0; i<=2; i++) {
                if (df[i]=='y' | df[i]=='Y') {
                        Calendar.year=(date[i]<1000 ? 2000 : 0)+date[i]*1;
                } else if (df[i]=='m') {
                        Calendar.month=date[i];
                }
        }
        Calendar.year=(date[2]>0 ? Calendar.year : d.getFullYear());
        Calendar.month=((date[1]>=0 & date[1]<12) ? Calendar.month-1 : Calendar.month=d.getMonth());
        Calendar.name=name;
        Calendar.Update();
        Calendar.Show();
        return false;
}


Calendar.Put=function() {
        document.write('<div id="calendar_window" style="display:none; position:absolute; background: #ffffff;">');
        document.write('<table width="210" cellspacing="0" cellpadding="0" border="0" class="calendar_border">');
        document.write('<tr>');
        document.write('<td width="180" colspan="6" id="cur" class="calendar_header">&nbsp;</td>');
        document.write('<td width="30" class="calendar_button" onclick="return Calendar.Hide();">x</td>');
        document.write('</tr>');
        document.write('<tr>');
        document.write('<td width="30" class="calendar_button" onclick="return Calendar.YearLeft();"><<</td>');
        document.write('<td width="30" class="calendar_button" onclick="return Calendar.MonthLeft();"><</td>');
        document.write('<td width="90" class="calendar_button" onclick="return Calendar.Today();" colspan="3"><b>Today</b></td>');
        document.write('<td width="30" class="calendar_button" onclick="return Calendar.MonthRight();">></td>');
        document.write('<td width="30" class="calendar_button" onclick="return Calendar.YearRight();">>></td>');
        document.write('</tr>');
        days=new Array(7);
        days[1]="Mon";
        days[2]="Tue";
        days[3]="Wed";
        days[4]="Thu";
        days[5]="Fri";
        days[6]="Sat";
        days[7]="Sun";
        for (i=0; i<=6; i++) {
                document.write('<tr>');
                for (j=1; j<=7; j++) {
                        if (!i) {document.write('<td width="30" class="calendar_header"><b>'+days[j]+'</b></td>');}
                        else {document.write('<td width="30" id="c'+i+j+'" class="calendar" align="center">&nbsp;</td>');}
                }
                document.write('</tr>');
        }
        document.write('</table>');
        document.write('</div>');
}

Calendar.Zero=function(n) {
        return (n<10 ? '0'+n : n);
}

Calendar.getFirstDay=function(m, y) {
        d=new Date(); d.setDate(1); d.setMonth(m); d.setFullYear(y);
        n=d.getDay();
        return (n ? n : 7);
}

Calendar.getDayCount=function(m, y) {
        s=new Date(); s.setDate(1); s.setMonth(m); s.setFullYear(y);
        if (m==11) {m=0; y++;}
        else {m++;}
        e=new Date(); e.setDate(1); e.setMonth(m); e.setFullYear(y);
        return Math.round((e-s)/(86400000));
}

Calendar.Update=function() {
        d=new Date();
        d.setDate(1); d.setMonth(Calendar.month); d.setFullYear(Calendar.year);
        n=Calendar.getFirstDay(Calendar.month, Calendar.year);
        m=Calendar.getDayCount(Calendar.month, Calendar.year);
        for (i=1; i<=6; i++) {
                for (j=1; j<=7; j++) {
                        p=document.getElementById('c'+i+j);
                        k=(i-1)*7+j-n+1;
                        p.innerHTML=(k<1|k>m ? '&nbsp;' : '<a href="#" onclick="return Calendar.Select('+k+');" class="calendar">'+k+'</a>');
                }
        }
        month=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
        p=document.getElementById('cur');
        p.innerHTML='<b>'+month[Calendar.month]+', '+Calendar.year+'</b>';
}

Calendar.MonthLeft=function() {
        if (Calendar.month>0) {Calendar.month--;}
        else {Calendar.month=11; Calendar.year--;}
        Calendar.Update();
        return false;
}

Calendar.MonthRight=function() {
        if (Calendar.month<11) {Calendar.month++;}
        else {Calendar.month=0; Calendar.year++;}
        Calendar.Update();
        return false;
}

Calendar.YearLeft=function() {
        Calendar.year--;
        Calendar.Update();
        return false;
}

Calendar.YearRight=function() {
        Calendar.year++;
        Calendar.Update();
        return false;
}

Calendar.Today=function() {
        d=new Date();
        Calendar.year=d.getFullYear();
        Calendar.month=d.getMonth();
        Calendar.Update();
        return false;
}

Calendar.Select=function(date) {
        p=document.getElementById(Calendar.name);
        df=Calendar.DateFormat.split(".", 3);
        p.value='';
        for (i=0; i<=2; i++) {
                p.value+=(i ? '.' : '');
                p.value+=(df[i]=='y' | df[i]=='Y' ? Calendar.year : (df[i]=='m' ? Calendar.Zero(Calendar.month+1) : Calendar.Zero(date)));
        }
        Calendar.Hide();
        return false;
}

Calendar.Show=function() {
        p=document.getElementById("calendar_window");
        p.style.display="block";
        p.style.left=Calendar.Left+'px';
        p.style.top=Calendar.Top+'px';
}

Calendar.Hide=function() {
        document.getElementById("calendar_window").style.display="none";
        return false;
}

Calendar.Put();