function user_cal(cal_path) {
var u_year=document.forms.choose_year.choose_year.value;
u_year=parseInt(u_year,10);
if (u_year<1900) {
   u_year=1900;
   }

make_cal_explicit(1,12,u_year,cal_path);

}


function make_cal_triplet(cal_path,go_year,go_mon,cal_path,view_mode) {

var uvar="undefined";
if (typeof cal_path==uvar || cal_path=="") var cal_path="!";
if (typeof view_mode==uvar) var view_mode=3;

var go_hueck = new Date();
var go_day = go_hueck.getDate();
if (!go_mon) {
   var go_mon = go_hueck.getMonth()+1;
   }
if (!go_year) {
   var go_year = go_hueck.getYear();
   }

var previous = go_mon - 1;
var next = go_mon + 1;

if (!view_mode) {
   view_mode=1
   }

make_cal_explicit(previous,next,go_year,cal_path,view_mode);

}

function make_cal_explicit(go_mon,end_mon,go_year,cal_path,view_mode) {

//alert('Anzeige-Modus: ' + view_mode);

var uvar="undefined";
if (typeof cal_path==uvar || cal_path=="") var cal_path="!";
if (typeof view_mode==uvar) var view_mode=3;


var go_hueck = new Date();
if (!go_mon) {
  var go_mon = go_hueck.getMonth()+1;
  }


if (!go_year) {
  var go_year = go_hueck.getYear();
}


if (!cal_path) {
  cal_path='cals/';
}


if (view_mode>1) {
   document.writeln('<TABLE border="1" cellpadding="0">');
   document.writeln('<TR valign="top">');
   }


var cc=0;
var go_start = go_mon;
var go_to = end_mon;
  if (go_mon>end_mon) {
    make_cal(cal_path,go_mon,(go_year-1));
    go_start=1;
    }

  if (end_mon<go_mon) {
    go_to=12+go_mon;
    }

for (cc=go_start;cc<=go_to;cc++) {
  if (view_mode>1) {
     document.writeln('<TD width="280" valign="top">');
     }
     if (cc>12) {
        go_mon=cc-12;
        go_year=go_year+1;
        }
     else {
        go_mon = cc
        }
     make_cal(cal_path,go_mon,go_year);

  if (view_mode>1) {
     document.writeln('</TD>');
     }
  }

if (view_mode>1) {
   document.writeln('</TR>');
   document.writeln('</TABLE>');
   }

}

function make_cal(cal_path,go_mon,go_year) {



var go_hueck = new Date();
var go_day = go_hueck.getDate();
var go_doy = go_hueck.getDay();
if (!go_mon) {
  var go_mon = go_hueck.getMonth()+1;
  }


if (!go_year) {
  var go_year = go_hueck.getYear();
}

var go_hour = go_hueck.getHours();
var go_min = go_hueck.getMinutes();
var go_sec = go_hueck.getSeconds();

if (!cal_path || cal_path=="!" || cal_path=="") {
cal_path='!';
calimg="";
}
else {

var calimg_base = 'monimg_'
var calimg_suffix = "jpg";
var calimg = cal_path + calimg_base + adjust(go_mon,2) + '.' + calimg_suffix;
}

if (go_year<999) {
   go_year += 1900
   }
// alert(go_year + ' ' + go_mon);

var specials = user_list().split("|");
var free_days ='1.1.|1.5.|3.10.|1.11.|25.12.|26.12.|'
var easter_date = get_easter(go_year);
var easter_sun = easter_day;
var edp = easter_date.search(/\./);
var easter_day = easter_date.substring(0,edp);
var easter_mon = easter_date.substring(edp + 1,(easter_date.length)-1);
var easter_doy = tell_doy(go_year,easter_mon,easter_day)
//alert('Ostern: ' + go_year + ':' + easter_mon + ':' + easter_day  + ' = ' + easter_doy);
var easter_fr = doy_to_date(go_year,easter_doy-2);
var easter_mo = doy_to_date(go_year,easter_doy+1);
var pente_mo = doy_to_date(go_year,easter_doy+50);
var christ_beamup = doy_to_date(go_year,easter_doy+40);
//alert('Karfreitag: ' + easter_fr);
//alert('Pfingsten: ' + pente_mo);

free_days = free_days + easter_fr + '|' + easter_mo + '|' + christ_beamup + '|' + pente_mo + '|'
var no_workday = free_days.split("|");

var day_free='';
var day_special='';


   var ii = 0;
   while ((no_workday[ii])) {
//   alert(dom + ' ' + ii + ') ' + no_workday[ii]);

       var pos_month=no_workday[ii].search(/\./) + 1
       var match_month=no_workday[ii].substring(pos_month,no_workday[ii].length);
       if(parseInt(match_month)==go_mon) {
          day_free=day_free + no_workday[ii].substring(0,pos_month-1) + '/';

          }
	ii = ii + 1;
       }

var ii=0
   while((specials[ii])) {
       var pos_month=specials[ii].search(/\./) + 1;
       var pos_info=specials[ii].search(/[:;,]/) + 1;
       var match_month=specials[ii].substring(pos_month,pos_info);
       if(parseInt(match_month)==go_mon) {

       var day_special=day_special + specials[ii].substring(0,pos_month-1) +  ':' +  specials[ii].substring(pos_info,specials[ii].length) + '/';
//       alert(day_special);
       }
       ii=ii+1;

}


calmonth(go_mon,go_year,go_day,go_doy,1,1,1,calimg,day_free,day_special)



}

function calmonth(month_is,year_is,today_is,dow_is,b_attr,s_attr,p_attr,cal_image,list_free,list_special) {
if (month_is < 0) {
   month_is = 0;
   }

var iwi=200;
var squot = String.fromCharCode(39);
var now_is = new Date();
var now_month = now_is.getMonth() + 1;
var is_free=list_free.split("/");
var is_special=list_special.split("/");
var l_week = 7;
var dom_work = '000000';
var dom_free = 'E10000';
var bg_shade = 'EFEFEF';
var bg_today = '9FCFFF';
var bg_standard = 'FFFFFF';
var dom_back = 'FFFFFF';
var dom_status = dom_work;
var mo_names = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
var mo_length = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var we_days_de = new Array('Woche','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag');
var cal_label = new Array(8);
var probe_nowork = '';

for (ii=0;ii<=7;ii++) {
  cal_label[ii] = we_days_de[ii];
  }
//Schalt-Tag im Februar berücksichtigen
  mo_length[1]=mo_length[1] + is_leap(year_is);
var doys = new Array();
var cal_week = 1;
doys[0] = 0;
for (ii=1;ii<=12;ii++) {
doys[ii] = doys[ii - 1] + mo_length[ii - 1];
}
var footer_txt='<h5>' + 'CalenderTool JavaScripted by<br>Frank Scheerer 2006' + '</h5>';
   if (now_month==month_is) {
   showup=true }
   else {
   showup=false;

   }
var month_name = mo_names[month_is - 1];
document.writeln('<TABLE cols="8" border="' + b_attr + " cellspacing=" + s_attr + '" cellpadding="' + p_attr +'">');
document.writeln('<TR>');
document.writeln('<TD align="center" valign="center" colspan="8">');
document.writeln('<h3>' + month_name + ' ' + year_is + '</h3>');
document.writeln('</TD>');
document.writeln('</TR>');
if (!cal_image || cal_image=='' || cal_image=="!")
{
}
else
{
   document.writeln('<TR>');
   document.writeln('<TD colspan="8" align="center">');
   document.writeln('<img name="cal_motiv" src="' + cal_image + '" width="' + iwi + '"' + 'onClick=fullsize(' +squot + '^cal_motiv' + squot +',' + squot +  squot +',' + squot + squot + ',' + squot + '800' + squot + ')'+'>')
   document.writeln('</TD>');
   document.writeln('</TR>');
}
document.writeln('<TR>');

for (ii=0;ii<=7;ii++) {
document.write('<TD width="25">');
document.write(cal_label[ii].substring(0,2));
document.write('</TD>');
}
document.writeln('</TR>');
document.writeln('<TR>');

var dow_first=doweek(year_is,month_is,'01');
var dow_last =doweek(year_is,month_is,mo_length[month_is - 1]);
//alert(dow_first + '|' + dow_last);
cal_week=Math.floor((doys[month_is - 1] + 1)/l_week) + 1;
document.write('<TD>' + cal_week + '</TD>');
// Nicht belegte Felder "ausgrauen"

for (ii=1;ii<=dow_first;ii++) {
document.writeln('<TD bgcolor="' + bg_shade + '"');
document.writeln('>');
document.writeln('</TD>');
}
var dom=0;
//Kalendertage generieren
for (dom=1;dom<=mo_length[month_is - 1];dom++) {

var cal_day = dom + dow_first;

// Zeilenumbruch nach Wochenende
if ((cal_day - 1)%l_week == 0) {
   if (dom>1) {
//   alert(dom + ' ' + (cal_day - 1));
     document.writeln('<TR>');
     document.writeln('<TD width="30">');
     cal_week=Math.floor((doys[month_is - 1] + dom)/l_week) + 1;
     document.writeln(cal_week);
     document.writeln('</TD>');
   }
   }
//Sonntage rot
   if ((dom + dow_first)%l_week == 0) {
   dom_status = dom_free;
   }
else
   {
   probe_nowork = parseInt(dom,10);
   dom_status = dom_work;
   var ii = 0;
   while ((is_free[ii])) {
//   alert(dom + ' ' + ii + ') ' + is_free[ii]);

       if(probe_nowork==is_free[ii]) {
          dom_status=dom_free;
          }
	ii = ii + 1;
       }
}


//Aktuellen Tag markieren
if (dom==today_is & month_is==now_month) {
dom_back=bg_today;
}
else
  {
  dom_back=bg_standard;
  }

document.write('<TD')
document.write(' bgcolor="#' + dom_back +'"');
document.write('>');
document.write('<font color="#' + dom_status + '">');
document.writeln(dom);
document.writeln('</FONT>');
document.writeln('</TD>');
}



//alert(dom + ' ' + mo_length[month_is - 1]);
if ((cal_day - 1 )%l_week == 0 & (dom<mo_length[month_is - 1])) {
  document.writeln('</TR>');
  }

//Rest ausgrauen

for (ii=dow_last + 1;ii<l_week;ii++) {
document.writeln('<TD bgcolor="' + bg_shade + '"');
document.writeln('>');
document.writeln('</TD>');
}
//Cal-Tabelle fertig
document.writeln('</TR>');

//Zusatz-Infos in separate Zeilen


//Spezielle Daten abfragen und ausgeben (Geburtstage/Termine etc.)
if (list_special) {
   document.writeln('<TR>');
   document.writeln('<TD colspan="8" align="left">');
   document.writeln('<H5>');
   ii=0;
//   alert(list_special);
   while (is_special[ii]) {
     var pos_event=is_special[ii].search(/[:;]/);
     var day_special=is_special[ii].substring(0,pos_event);
     var day_event=is_special[ii].substring(pos_event+1,is_special[ii].length);
     document.write(day_special + '.' + day_event + '&nbsp;&nbsp;')
     ii=ii+1;;
   }
   document.writeln('</H5>');
   document.writeln('</TD>');

  document.writeln('</TR>');
}

   if (showup==true) {
     document.writeln('<TD align="center" valign="bottom" colspan="8">');
     document.writeln(footer_txt)
     document.writeln('</TD>');
     }

  document.writeln('</TABLE>');
}


function doweek(i_year,i_month,i_day) {

// alert(i_year + ' ' + i_month + ' ' + i_day);

var opv_year = parseInt(i_year,10);
var opv_month = parseInt(i_month,10);
var offset_leapm = opv_month;
var opv_day = parseInt(i_day,10);
var dow_numb = 0;

if (opv_month<3) {

  offset_leapm = 12 + opv_month;
  opv_year = opv_year - 1;
  opv_day=opv_day-is_leap(i_year);
}

var opv_4 = parseInt(((offset_leapm+1)*3)/5, 10);
var is_leap_each4 = parseInt(i_year/4,10);
var no_leap100 = parseInt(i_year/100,10);
var is_leap400 = parseInt(i_year/400,10);

var opv_stage1 = opv_day+(offset_leapm*2)+opv_4+opv_year+is_leap_each4-no_leap100+is_leap400+2;
var opv_stage2 = parseInt(opv_stage1/7, 10);
var dow_numb = opv_stage1-(opv_stage2*7);
// alert(dow_numb);
if (dow_numb>1) {
   dow_numb = dow_numb = dow_numb -2;
   }
else
   {
   dow_numb=6 - (1 - dow_numb);
   }
// alert(dow_numb);
return dow_numb;

}

function tell_doy(year_is,month_is,day_is) {



var mo_length = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var doys = new Array();
var cal_week = 1;
doys[0] = 0;
for (ii=1;ii<=12;ii++) {
doys[ii] = doys[ii - 1] + mo_length[ii - 1];
}

if (is_leap(year_is) == 1 ) {

doys[2] = 29;

}

//alert(month_is + ' ' + day_is + '=' + doys[month_is]);
var doy_is = parseInt(doys[month_is],10) + parseInt(day_is);

return doy_is;

}

function doy_to_date(year_is,what_doy) {

waht_doy=parseInt(what_doy);
var mo_length = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var doys = new Array();
var cal_week = 1;
doys[0] = 0;
for (ii=1;ii<=12;ii++) {
doys[ii] = doys[ii - 1] + mo_length[ii - 1];
}

if (is_leap(year_is) == 1 ) {
  doys[2] = 29;
  }

for (ii=1;ii<=12;ii++) {

  if (what_doy>doys[ii]) {
    var month_count=ii;
    var day_count = what_doy - doys[ii];
    }
}
  var date_is = day_count + '.' + month_count + '.';

//alert(what_doy + ': ' + date_is);
return date_is;

}

function countup(wait,formname,inputname) {

var uvar='undefined';

var now_time=new Date();
var elapsed=now_time - starttime;

var ehrs=Math.floor(elapsed/3600000,10);
var erest=elapsed-ehrs*3600000;
var emins=Math.floor(erest/60000,10);
var erest=erest-emins*60000;
var esecs=Math.round(erest/1000);
var eva='document.forms[\"' + formname + '\"].' + inputname + '.value=\"' + ehrs + ':' + emins + ':' + esecs + '\"';

eval(eva);

var timer=setTimeout('countup(' + wait + ',' + '"' + formname + '","' + inputname + '")',wait);

}


function countdown_cal (wait,clevel,day_to,month_to,year_to,hour_to,min_to,sec_to,formname,inputname,langid,umsg) {

var hueck = new Date();
var uvar="undefined";
if (typeof wait==uvar) var wait=1000;
if (typeof formname==uvar) var formname='infoline';
if (typeof inputname==uvar) var inputname='inputtext';
if (typeof langid==uvar) var langid="DE";
if (typeof umsg==uvar) var umsg="";
if (typeof clevel==uvar) var clevel="0";
var clevel = (clevel=="*") ? 4 : clevel;
var sec_to = (typeof sec_to==uvar) ? 0 : sec_to;
var min_to = (typeof min_to==uvar) ? 0 : min_to;
var hour_to = (typeof hour_to==uvar) ? 0 : hour_to;
var year_to = (typeof year_to==uvar) ? hueck.getFullYear() : year_to;
var month_to = (typeof month_to==uvar) ? hueck.getMonth() : month_to;
var bis=new Date(year_to,month_to - 1,day_to,hour_to,min_to,sec_to);
var duurt_noch = bis-hueck;

var eva='var mycount=document.forms[\"' + formname+ '\"].' + inputname;
var evasc=eva;
eval(eva);
if (typeof mycount==uvar) {
   /* alert(evasc); */
   var mycount=document.forms[formname].inputname;
}

switch (langid) {

case "DE": {
   	saach_daach="T";
	saach_stund="Std";
	saach_mins="m";
	saach_secs="s";
	break;
    }
case "EN": {
 	saach_daach="d";
	saach_stund="hrs";
	saach_mins="m";
	saach_secs="s";
	break;
    }
}
var msf=1000;
var duurt_noch=Math.round(duurt_noch/msf);
var duurt_woch=Math.floor(duurt_noch/7);

var duurt_daach=Math.floor(duurt_noch/86400);


var duurt_stund = (duurt_stund<10) ? '0' + duurt_stund : duurt_stund;
var duurt_mins = (duurt_mins<10) ? '0' + duurt_mins : duurt_mins;
var duurt_secs = (duurt_secs<10) ? '0' + duurt_secs : duurt_secs;
var ilevel=new Array(10);
ilevel[0]=duurt_daach + " " + saach_daach;
var duurt_noch=duurt_noch%86400;
var duurt_stund=Math.floor(duurt_noch/3600);
ilevel[1]=duurt_stund + " " + saach_stund;
var duurt_noch=duurt_noch%3600;
var duurt_mins=Math.floor(duurt_noch/60);
ilevel[2]=duurt_mins + " " + saach_mins;
var duurt_secs=duurt_noch%60;
ilevel[3]=duurt_secs + " " + saach_secs;
var et_duurt=umsg;
ilevel[4]=0;


for (oii=0;oii<=clevel;oii++) {
   outval=ilevel[oii];
   var et_duurt=et_duurt + outval + " ";

}

mycount.value=et_duurt;

var timer=setTimeout('countdown_cal(' + wait + ',' + clevel + ',' + day_to + ',' + month_to + ',' + year_to + ',' + hour_to + ',' + min_to + ',' + sec_to + ',"' + formname + '","' + inputname + '","' + langid + '","' + umsg + '")',wait);
return et_duurt;
}


function countdown (year_to,month_to,day_to,hour_to,min_to,sec_to,use_form) {

var count_level=0;

if (hour_to || hour_to == 0) {
   count_level=1;
   }

if (min_to || min_to==0) {
   count_level=2;
   }

if (sec_to || sec_to == 0) {
   count_level=3;
   }

//alert(count_level + ' ' + hour_to + ':' + min_to + ':' + sec_to);
if (!sec_to) sec_to = 0;
if (!min_to) min_to=0;
if (!hour_to) hour_to=0;

var hueck = new Date();
var g_day = hueck.getDate();
var g_mon = hueck.getMonth()+1;
var g_year = hueck.getYear();
if (g_year <999) {
g_year += 1900
}
var g_hour = hueck.getHours();
var g_min = hueck.getMinutes();
var g_sec = hueck.getSeconds();

if (hour_to) {
   var sec_to = hour_to * 3600 + min_to * 60;
   var sec_now = g_hour * 3600 + g_min * 60 + g_sec;
   var sec_24h = 86400 - sec_now;
   var sec_frame = sec_24h + sec_to
   var sec_remain = sec_frame % 86400;
   var hour_dist = parseInt(sec_remain/3600,10);
   var min_dist = parseInt((sec_remain - (hour_dist*3600))/60);
   var sec_dist = parseInt((sec_remain - (hour_dist*3600)) - min_dist * 60);

}

var target_doy=tell_doy(year_to,month_to,day_to);

var year_offset = year_to - g_year;
if (year_offset > 0) {
   if (year_offset==1) {
      target_doy = target_doy + (365 + is_leap(g_year) - tell_doy(g_mon,g_day));
   }
   else

   {
   target_doy = 365 + is_leap(g_year) - tell_doy(g_mon,g_day);
   target_doy=target_doy + 365*year_offset;
   target_doy=target_doy + is_leap(year_to);

   }
}

var now_doy=tell_doy(g_year,g_mon,g_day);
var days_remain = target_doy - now_doy;
//if (sec_frame<=86400) {
//   days_remain -= 1;
//   }

//alert(count_level + '   ' + target_doy + '..>  ' + now_doy + '  =  ' + days_remain + '  ' + hour_dist +':' + min_dist + ':' + sec_dist);

var time_remain = days_remain;
if (count_level>0) {
   time_remain = time_remain + '  ' + adjust(hour_dist,2);
   }
if (count_level>1) {
   time_remain = time_remain + ':' + adjust(min_dist,2);
   }
if (count_level>2) {
   time_remain = time_remain + ':' + adjust(sec_dist,2);
}

if (use_form && use_form!='n') {

}

   return time_remain;

}

function is_leap(is_year) {

var leap4 = is_year%4;
var leap100 = is_year%100;
var leap400 = is_year%400;
var leapday = 0;

if (leap4==0) {
   if (leap100==0) {
      if (leap400==0) {
          leapday = 1;
          }
      else  {
          leapday=0;
          }
    }
   else {
       leapday=1;
   }
}
//alert(is_year + ' has ' + leapday);
return leapday;
}


function get_easter(which_yyyy) {

var easter = '';
var easter_offset=1990;
var easter_index=which_yyyy-easter_offset;
if (easter_index<0) {
   easter_index=0;
   }

var easter_list='15.4.|31.3.|19.4|11.4.|3.4.|16.4.|7.4.|30.3.|12.4.|4.4.|23.4.|15.4.|31.3.|20.4.|11.4.|27.3.|16.4.|8.4.|23.3.|12.4.|4.4.|24.4|8.4.|31.3.|20.4.|5.4.|27.3.|16.4|';

var easters=easter_list.split("|");
var easter_range = easters.length;
easter=easters[easter_index];
//alert(which_yyyy + '  ' + easter);


return easter;

}

function user_list() {

var spec_at= '';

return spec_at;

}