/*
 Datei: kalender.js
 Datum: 18.08.04
 Version: 0.1

 jstruebig@web.de

 modified rma 2004-11-24

*/

/////////////////////////////////////////////////
// Globale Einstellungen:

var background = '#fff';     // Farbe f&#252;r den Hintergrund
var color      = '#000';     // Farbe f&#252;r den vordergrund
var markSunday = '#00AB84';     // Sonntage f&#228;rben
var markSaturday = '#6DE0BB';   // Samstage f&#228;rben
var funktion   = 'getDatum'; // Die Funktion, die bei einem Klick ausgef&#252;hrt werden soll
var close      = true;       // Schliessen nach Klick
var popup_w    = 220;
var popup_h    = 220;
var popup_x		= 400; // x-position popup added rma 2004-11-30
var popup_y		= 150; // y-position popup added rma 2004-11-30

function monatsBlatt(m, j)
{
   var today = new Date();

   if(!j) j = today.getFullYear();
   
   var tmp = checkDate(m);
   if(!tmp)
   {
         if(!m || m < 1 || m > 12 ) m = 1 + today.getMonth();
         m--;
   }

   var d = tmp || new Date(j, m, 1);

   
   var win = window.open('', 'kalender', 'width=' + popup_w + ',height=' + popup_h + ',left=' + popup_x + ',top=' + popup_y);

   var text = '<html>'
   + '<head>'
   + '<title>' + 'Datumsw&#228;hler' + '</title>'
   + '<style>'
   + 'body{text-align:center;margin:auto;padding:0; font:bold 11px "Arial";} div, th {font:bold 12px "Arial"; color: #000;}'
   + 'caption{font-weight:bold; font-size: 12px; font-family: Arial, Verdana;}'
   + 'td{text-align:center; padding:1px}'
   + 'a {text-decoration:none; }'
   + 'a.blaettern {text-decoration:none; color: #000;}'
   + 'body{background-color:' + background
   + ';color:' + color
   + '}'
   + '.active{background-color:#ccc; padding:2px; margin:1px; border:1px #ccc solid;}'
   + '.inactive{background-color:#fff; padding:2px; margin:1px; border:1px #ddd solid; }'
   + '</style></head>'
   + '<body ><br><center>'
   ;

   text += datumTitel(d)  + '<tr>';

   var i = 0;
   tag = 0;
   for(i = 0; i < 7; i++)
   {
        tag++;
        if(tag == LOCALE.abday.length) tag = 0;
        var t = LOCALE.abday[tag].substring(0,1).toUpperCase() + LOCALE.abday[tag].substring(1,2);
        var style = (tag == 6 ? markSaturday : '') +  (tag == 0 ? markSunday : '');
        text += '<th >' + t + '</th>';/* style="' + style + '"  rma 2004-11-30 */
   }
   text += '</tr><tr>';

   d.setDate(1);
   for(i = 1; i < 7; i++)
   {
       if( d.getDay() == i) break;
       text += tabellenZelle();
   }
   var tag = 1;
   while(tag < 32 )
   {
         d.setDate(tag);
         if(d.getMonth() > m) break;

         text += tabellenZelle(d, (d.getTime() == today.getTime()) );
         if( !(i % 7) ) { text += '</tr><tr>'; }
         i++;
         tag++;
   }
   i--;
   if((i %7))  while((i++) % 7 ) {text += tabellenZelle(); }

   text += '</tr></table>';

   text += '</center></body></html>';

   win.document.open();
   win.document.write(text);
   win.document.close();
   win.focus();
}
function tage(m, j)
{
    var d = new Date(j, m, 1);
    d.setDate(0);
    return(d.getDate());
}

function datumTitel(d)
{
   var j = d.getFullYear();
   var m = d.getMonth();
   var t = d.getDate();

   d.setDate(1);
   d.setMonth(m - 1);
   var back = '<a href="#" onclick="opener.monatsBlatt('
   + ( 1 + d.getMonth() ) + ',' + d.getFullYear()  + ');return false;" class="blaettern">'
   + '&lt;&lt;' + '</a>&nbsp;'
   ;
   d.setFullYear(j);
   d.setMonth( m + 1 );

   var fore = '&nbsp;<a href="#" onclick="opener.monatsBlatt('
   + ( 1 + d.getMonth() ) + ',' + d.getFullYear()  + ');return false;" class="blaettern">'
   + '&gt;&gt;' + '</a>'
   ;
   d.setFullYear(j);
   d.setMonth( m );
   d.setDate(t);
   return '<table>'
   + '<caption>' + back
   + LOCALE.mon[m] + '/' + d.getFullYear()
   + fore + '</caption>'
   ;
}
function tabellenZelle(d, heute)
{
    var date ="&nbsp;";
    var style = 'class="inactive"';
    if(d){

    var day = d.getDay();
    date = d.getDate();
    style = 'class="active" style="cursor:pointer;'
    + (day == 6 ? markSaturday : '')
    +  (day == 0 ? markSunday : '')
    + (heute ?  'background-color:#ff9;font-weight:bold;' : '')
    + '" '
    + getJS(d)
    ;
    }
    return '<td> <div ' + style + '>' + date + '</div> </td>'
    ;
}
function getJS(d)
{
    return ' onclick="opener.' + funktion + '('
    + d.getDate() + ',' + d.getMonth() + ',' + d.getFullYear() + ');'
    + (close ? 'self.close();' : '')
    + '" '
    ;
}

function getDatum(t, m, j)
{
var datum = new Date(j, m, t);
self.focus();
document.forms["quicktimetableright"].datum.value = formatDate(datum);
//datum.setTime( datum.getTime() + oneDay * document.forms["quicktimetable"].days.value);
//document.forms["fahrplanform"].d2.value = formatDate(datum);

}
markSunday = markSunday ? 'background-color:' + markSunday : '';
markSaturday = markSaturday ? 'background-color:' + markSaturday : '';
var oneDay = 24 * 60 * 60 * 1000;