//-----------------------------------------------------------------------------
//
// File:    ampCal.js
// Purpose: This is the source file for the ampCal JavaScript Calendar.
// Author:  Andrew M. Pierce
// Date:    08/21/1998
//
// adapted: Martin Divis
// Date:    2004-2008
//-----------------------------------------------------------------------------

//document.write("<br> Here are the jokes of the month till today ...");

var winname = "orpheus";
function NeuWindows(Ziel,breite,hoehe) {
    NewWindow = window.open(path2pic + Ziel+".jpg","target","screenX=300,screenY=100,width=640,height=640,resizable=yes,scrolling=yes");
    NewWindow.focus();
}


function ampCalendar_setFebDays()
{
  if ( this.month == 1 ) 
  {
    //alle Jahre die durch 4 ohne Rest teilbar sind, sind Schaltjahre
    if ( this.year % 4 == 0 )
    {
      //alle Jahre die durch 100 ohne Rest teilbar sind, sind KEINE Schaltjahre
      if ( this.year % 100 == 0)
      {
        this.m_rgDays[1] = 29;

        //alle Jahre die durch 400 ohne Rest teilbar sind, sind Schaltjahre
        if ( this.year % 400 == 0) 
          this.m_rgDays[1] = 29;
      }
      else
        this.m_rgDays[1] = 29;
    }
  }
}

function ampCalendar_setItem( nDay, strText )
{
  x = this.m_rgDay.length;
  this.m_rgDay[x + 1] = nDay;
  this.m_rgTxt[x + 1] = strText;
}

function ampCalendar_getText( n )
{
  var x = 0;
  while( x < this.m_rgDay.length ) 
  {
    if ( n == this.m_rgDay[x] ) 
    return this.m_rgTxt[x] ;

    x++;
  }
  return "";
}

function ampCalendar_getWeek(day, month,allDays_array)
{
  totalDays  = 0;
  actualWeek = 0;

  for (j = 0; j < month -1 ; j++) {
    totalDays = totalDays + allDays_array[j];
  }
  totalDays = totalDays + day; 
  
  var jetzt = new Date();
  var Jahr = jetzt.getYear();

  if(Jahr < 999) Jahr+=1900;

  var Wochentag = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");

  for (j = 1; j < 8 ; j++) {
    var Januar = new Date(Jahr,0,j);
    var TagInWoche = Januar.getDay();
    //document.writeln("DEBUG: Wochentag for: "+Januar+" is "+Wochentag[TagInWoche]+"<br>");
      // now we have to find the first monday in this year
      // and subtract the number of days till 1st monday in january
      // from totaldays
    if (Wochentag[TagInWoche] == "Montag")
      totalDays = totalDays - j ;
  }

  //ganzzahliger Anteil von actualWeek
  actualWeek = Math.floor((totalDays + 7) / 7);
  //document.writeln("<br>"+"DEBUG: actualWeek from ampCalendar_getWeek = " + actualWeek + "<br>");
  return actualWeek;
}

function ampCalendar( m, y )
{
  // properties
  this.m_rgDay = new Array();
  this.m_rgTxt = new Array();

  // Static stuff

  // Colors
  this.m_strDead = "C0C0C0";
  this.m_strFutr = "F5DEB3";
  this.m_strPast = "E1E1D1";
  this.m_strNow  = "F08080";

  this.m_rgDays = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); 
  this.m_rgMths = new Array( "january", "february", "march", "april", 
   "may", "june", "july", "august", 
   "september", "october", "november", "dezember" );

  this.font      = "Verdana, Arial, Helvetica";
  this.fontSize  = "-1";
  this.headSize  = "-1";

  this.month = m;
  this.year  = y;

  //i.e. Wed Apr 19 2006 11:03:17 GMT+0200 (MEST)
  this.m_now = new Date();   
  this.m_day = this.m_now.getDate();
  this.m_myDate  = new Date(y, m - 1, 1);

  this.monthName = this.m_rgMths[ this.m_myDate.getMonth() ];
  this.title = this.monthName + " " + this.year;

  // Constructors (because NO parameters)
  this.setFebDays = ampCalendar_setFebDays;
  //this.display = ampCalendar_Display;
  this.setItem = ampCalendar_setItem;
  this.getText = ampCalendar_getText;
  //this.getWeek = ampCalendar_getWeek(this.m_day,m ,this.m_rgDays);
  this.getWeek = ampCalendar_getWeek;
  //document.writeln("DEBUG: actualWeek= " + actualWeek + "<br>");

  this.setFebDays();
  //document.writeln("DEBUG: days of february: " + this.m_rgDays[1] + "<br>");
  
  //special pic = pic00
  pic00 = "Osterspecial2006.html";

  //usual ones following
  pic01 = "DESIGN01";
  pic02 = "DESIGN02";
  //pic02 = "DESIGN03";
  pic03 = "DESIGN03";
  pic04 = "DESIGN04";
  pic05 = "DESIGN05";
//  pic06 = "Design06.html";
//  pic07 = "Design07.html";
//  pic08 = "Design08.html";
//  pic09 = "Design09.html";
//  pic10 = "Design10.html";

  picsAll = new Array(pic01,pic02,pic03,pic04,pic05);
  //document.writeln("<br>");
 

  // initialisierung von week = new array();
  week = new Array();
  for (i=0; i < 5; i++) { week[i]    = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+5]  = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+10] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+15] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+20] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+25] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+30] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+35] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+40] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+45] = picsAll[i]; }
  for (i=0; i < 5; i++) { week[i+50] = picsAll[i]; }  
  for (i=0; i < 5; i++) { week[i+3]  = picsAll[i]; }

  //now if you have a special action in i.e. week 25, overwrite it with special pic00
  //week[25-1] = pic00;
}
// http://angola:9900/BOOKS/SPRACHEN/JAVASCRIPT/JS_GALILEO/javascript13.htm#Xxx921401
//
// Methoden definieren 
//
// Fast genauso einfach wie die Definition von Objekteigenschaften ist die Definition von Objektmethoden. 
// Auch hier ist der this-Operator wieder von Bedeutung. Beim Setzen einer Methode verwendet man folgende 
// Syntax im Konstruktor:
//
// this.methode = funktion
//
// Bei jedem Aufruf der Methode wird funktion() ausgefu"hrt, und innerhalb von funktion() kann man 
// mit this auf die verwendete Instanz des Objekts zugreifen. Beachten Sie, dass auch hier die Klammern fehlen.
//
// Als Beispiel soll die Methode toString() implementiert werden. Dazu muss zuna"chst MakeArray() 
// folgenderma?en gea"ndert werden:
//
// function MakeArray(n){
//   for (var i=0; i<n; i++)
//      this[i] = 0
//   this.length = n
//   this.toString = arraytoString
// }
//
// Die Funktion arraytoString() gibt die Elemente des Arrays, durch Kommata voneinander getrennt, aus. 
// Dazu werden einfach alle Elemente in this abgefragt und miteinander verkettet.
//
// function arraytoString(){
//   var returnstring = ""
//   for (var i=0; i<this.length-1; i++)
//      returnstring += this[i] + ","
//   returnstring += this[this.length-1]
//   return returnstring
// }

