
var dName   =  new Array("Lu","Ma","Me","Je","Ve","Sa","Di")//eintag der Wochentagsnamen aus der localtext
var monName    =  new Array ("JANVIER","F&Eacute;VRIER","MARS","AVRIL","MAI","JUIN","JUILLET","AO&Ucirc;T","SEPTEMBRE","OCTOBRE","NOVEMBRE","D&Eacute;CEMBRE");
function makeCal(formS, formE, depImg, arrImg, n)
{
 this.name    =  n;
 this.calXpos    =  new Array();
 this.calYpos    =  new Array();
 this.calXpos[0] =  findPos(depImg).xPos - (nc? 40 : 0);
 this.calYpos[0] =  findPos(depImg).yPos + ((mac || br.unix)? 60 : (nc? 30 : 0));
 this.calXpos[1] =  findPos(arrImg).xPos - (nc? 40 : 0);
 this.calYpos[1] =  findPos(arrImg).yPos + ((mac || br.unix)? 60 : (nc? 30 : 0));
 this.outForm    =  new Array();
 this.outForm[0] =  formS;
 this.outForm[1] =  formE;
 this.posDiv        =  posDiv;
 this.initCal    =  initCal;
 this.nextMonth    =  nextMonth;
 this.pastMonth    =  pastMonth;
 this.writeCal    =  writeCal;
 this.wrForm     =  wrForm;
 this.dplCal     =  dplCal;
}

function posDiv()
{
 dRefS("calendar").left =  this.calAktX;
 dRefS("calendar").top  =  this.calAktY;
}

//function initCal(rdIdx, akIdx, x, y)
function initCal(rdIdx, akIdx)
{
 this.calAktForm    =  akIdx;
 //this.calAktX    =  x;
 //this.calAktY    =  y;
 this.calAktX    =  this.calXpos[akIdx];
 this.calAktY    =  this.calYpos[akIdx];
 var date        =  this.outForm[rdIdx].value;
// var reg            =    /^([0-9]{1,2})[\.\,\-\/]([0-9]{1,2})[\.\,\-\/]([0-9]{2,4})$/;
 var reg            =    /^([0-9]{2,4})[\.\,\-\/]([0-9]{1,2})[\.\,\-\/]([0-9]{1,2})$/;
 if(reg.exec(date) && akIdx)
 {
 var datArr    =    reg.exec(date);
// datArr[3]    =    (datArr[3].length == 2)? "20" + datArr[3] : datArr[3];
 datArr[1]    =    (datArr[1].length == 2)? "20" + datArr[1] : datArr[1];
 datArr[2]    =    (datArr[2]> 0 )? datArr[2] - 1 : 11;
// aktDate         =    new Date(datArr[3], datArr[2], datArr[1]);
 aktDate         =    new Date(datArr[1], datArr[2], datArr[3]);
 }
 else
 {
 aktDate    =   new Date();
 } 
 aktMonth    =    aktDate.getMonth();
 aktYear        =    aktDate.getYear();
 if (aktYear <1000) aktYear += 1900;
 aktDay        =    aktDate.getDate();
 aktDay        =    new Date(aktYear, aktMonth, aktDay);
 aktDay        =    aktDay.getTime();
 calendrier = akIdx;
 this.writeCal();
 this.posDiv();
 this.dplCal(1);
}

function writeCal()
{
 firstDay    =    new Date(aktYear, aktMonth, 1);
 firstDayId    =    firstDay.getDay();
 firstDayId    =    (firstDayId> 0)? firstDayId - 1 : 6;
 nextMonth    =    new Date(aktYear, aktMonth + 1 ,1);
 monthDur    =    nextMonth - (1000*60*60*23);
 lastDay        =    new Date(monthDur);
 lastDayDate    =    lastDay.getDate();
 if(ie4 || dom)
 {
 dRef("monthTd").innerHTML =  '<span class=scf>' + monName[aktMonth]+ '&nbsp;' + aktYear + '<\/span>';
 for(var k in dName) dRef("dayName" + k).innerHTML =  dName[k];
 dRef("close").innerHTML = '<a href="Javascript:'+ this.name +'.dplCal(0)"  class="norm" >X</a>';
 dRef("backTd").innerHTML = '<A class=norm href="Javascript:'+ this.name +'.pastMonth();">&lt;&lt;</A>';
 dRef("nextTd").innerHTML = '<A class=norm href="Javascript:'+ this.name +'.nextMonth();">&gt;&gt;<\/A>';
 }
 else if(nc)
 {
 table =  '<span class=border><table cellspacing=1 cellpadding="1" border="0"><tr>';
 table += '<td class=dayTd width="18"><A class=norm href="Javascript:' + this.name + '.pastMonth();">&lt;&lt;</A><\/td>';
 table += '<td class=dayTd colspan="5" align="center" width="90"><span class=scf>' + monName[aktMonth]+ "&nbsp;" + aktYear + '<\/span><\/td>';
 table += '<td class=dayTd align="right" width="18"><A class=norm href="Javascript:' + this.name + '.nextMonth();">&gt;&gt;<\/A><\/td><\/tr><tr>';
 for(var k in dName) table += '<td id="dayName' + k + '" class="dayName" align="right" width="18">' + dName[k] + '<\/td>';
 table += '<\/tr><tr>';
 }
 var cnt =  1;
 for(var i = 0; i <42; i++)
 {
 var txt, aTag, table;
 var temp    =  new Date(aktYear, aktMonth, cnt);
 if(temp.getTime() <aktDay)
 {
 if(calendrier)
 {
 txt     =  cnt;
 }
 else
 {
 aTag    =    '<a class=norm href="Javascript:' + this.name + '.wrForm(' + this.calAktForm + ', ' + cnt + '); ">';
 txt        =    aTag + cnt + '<\/a>';
 }
 }
 else if(temp.getTime() == aktDay)
 {
 aTag    =    '<a class=scf href="Javascript:' + this.name + '.wrForm(' + this.calAktForm + ', ' + cnt + ');">';
 txt        =    aTag + cnt + '<\/a>';
 }
 else
 {
 if(calendrier)
 {
 aTag    =    '<a class=norm href="Javascript:' + this.name + '.wrForm(' + this.calAktForm + ', ' + cnt + '); ">';
 txt        =    aTag + cnt + '<\/a>';
 }
 else
 {
 txt     =  cnt;
 }
 }
 if(firstDayId <= i && cnt <= lastDayDate)
 {
 if(ie4 || dom) dRef("day" + i).innerHTML =  txt;
 else if(nc)
 {
 table += '<td' + ((i + 1)%7 == 0? ' class="sun"' : ' class="dayTd"') + ' align="right">' + txt + '<\/td>';
 table += (i + 1)%7 == 0? '<\/tr>' + (i <41? '<tr>' : ''): '';
 }
 cnt++;
 }
 else
 {
 if(ie4 || dom) dRef("day" + i).innerHTML =  "&nbsp;";
 else if(nc)
 {
 table += '<td' + ((i + 1)%7 == 0? ' class="sun"' : ' class="dayTd"') + '>&nbsp;<\/td>';
 table += (i + 1)%7 == 0? '<\/tr>' + (i <41? '<tr>' : ''): '';
 }
 }
 }
 if(nc)
 {
 table += '<tr><td class=dayTd colspan="7" align="center"><a href="Javascript:' + this.name + '.dplCal(0)"  class="norm" >Fermer le calendrier</a></td></tr></table></span>';
 writeDiv(dRef('calendar'), table);
 }
}

function nextMonth()
{
 if (aktMonth <12) aktMonth += 1;
 if (aktMonth == 12)
 {
 aktYear += 1;
 aktMonth = 0;
 }
 this.writeCal();
}

function pastMonth()
{
 if (aktMonth> -1) aktMonth -= 1;
 if (aktMonth == -1)
 {
 aktYear -= 1;
 aktMonth = 11;
 }
 this.writeCal();
}
var arrivalSet = false;

function wrForm(index, id)
{
 var depDate                          =  new Date(aktYear,aktMonth, parseInt(id)+1);
 var depDay                           =  depDate.getDate();
 var depMonth                         =    depDate.getMonth();
 var depYear                             =    depDate.getYear();
 if (depYear <1000) depYear          += 1900;
// this.outForm[index].value            =  id     + "." + (aktMonth + 1) + "." + aktYear;
 this.outForm[index].value            =  aktYear + "-" + (aktMonth + 1) + "-" + id;

 if(index == 0 && (!arrivalSet || this.outForm[0].value>this.outForm[1].value)) this.outForm[1].value = depYear + "-" + (depMonth + 1) + "-" + id;
// if(index == 0 && (!arrivalSet || this.outForm[0].value>this.outForm[1].value)) this.outForm[1].value =  id + "." + (depMonth + 1) + "." + depYear;
 else arrivalSet = true;
 this.dplCal(0);
}

function dplCal(stat)
{
 dRefS("calendar").visibility             =  stat? "visible" : "hidden";
}


