// Calendar display with picture, JavaScript
// by Nicola Zordan
// Monday, 23 August 1999

var Today= new Date(),
    CalendarDate= Today,
    Month= CalendarDate.getMonth(),
    Day= CalendarDate.getDate(),
    DayOfWeek= CalendarDate.getDay(),
    Year= CalendarDate.getFullYear(),
    DateTMP= new Date(),
    MonthNames= new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
    MonthName= MonthNames[Month],
    MonthsDays= new Array(31,28,31,30,31,30,31,31,30,31,30,31),
    MonthDays= MonthsDays[Month],
    DayNames= new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),
    DayName= DayNames[DayOfWeek],
    MonthBegin= DateTMP.getDay();

var Author='Nicola Zordan; Nicola.Zordan@bigfoot.com;www.bigfoot.com/~Nicola.Zordan'
    WebPage='http://www.mclink.it/personal/MC2074/web/calendar.htm';
//var PhotosNumber = <!--#counter increment="0" file="photosAll" -->,
var PhotosNumber = 76,
//    PhotosPath = 'http://members.xoom.it/NZordan/calendar/',
    PhotosPath = 'http://members.spree.com/Zordan/calendar/',
    PhotosNames = 'Image',
//    ShowPhotoN = <!--#counter increment="1" rollover="on" file="photoN"-->,
    ShowPhotoN = 1,
    PhotoCurrent = ShowPhotoN - (Math.floor(ShowPhotoN/PhotosNumber)*PhotosNumber) + 1;
//    PhotoCurrent = <!--#counter increment="0" file="photoN"-->;	
//var PhotosNumber = 10;


function SetCalendarDate(fYear,fMonth,fDay) 
{
//  fYear=2000;
//  fMonth=1;
//  fDay=29;
  DateTMP= new Date();
  DateTMP.setFullYear(fYear);
  DateTMP.setMonth(1);
  DateTMP.setDate(29);
  if (DateTMP.getDate()==29) 
    { 
      MonthsDays[1]=29;
//      MonthDays= MonthsDays[fMonth];
    }
   else
    { 
      MonthsDays[1]=28;
//      MonthDays= MonthsDays[fMonth];
    };
  Today= new Date();  
  CalendarDate.setDate(1);
//  if (fDay>MonthsDays[fMonth]) 
//   { CalendarDate.setDate(MonthsDays[fMonth]); };
//   else
//   { CalendarDate.setDate(fDay); };
  CalendarDate.setMonth(fMonth);
  CalendarDate.setFullYear(fYear);
// Next / Previous month
if (fMonth < 0) {
  CalendarDate.setMonth(11);
  CalendarDate.setFullYear(fYear - 1);
};
if (fMonth > 11) {
  CalendarDate.setMonth(0);
  CalendarDate.setFullYear(fYear + 1);
};
  CalendarDate.setDate(fDay);
  Month= CalendarDate.getMonth();
  Day= CalendarDate.getDate();
  DayOfWeek= CalendarDate.getDay();
  Year= CalendarDate.getFullYear();
//alert(CalendarDate+'\n'+Year+'/'+Month+'/'+Day+'\n'+fYear+'/'+fMonth+'/'+fDay);
  DateTMP= new Date();
  DateTMP.setDate(1);
  DateTMP.setMonth(Month);
//  DateTMP.setYear(Year);
  DateTMP.setFullYear(Year);
  MonthName= MonthNames[Month];
  MonthDays= MonthsDays[Month];
  DayName= DayNames[DayOfWeek];
  MonthBegin= DateTMP.getDay();
// alert(Year+'/'+Month+'/'+Day+'\n'+fYear+'/'+fMonth+'/'+fDay);
};

//alert('Date='+CalendarDate+' \nToday='+Today+' \nMonth='+Month+' \nMonthName='+MonthName+' \nDay='+Day+' \nDayOfWeek='+DayOfWeek+' \nDayName='+DayName+' \nYear='+Year+' \nMonthBegin='+MonthBegin+' \nMonthDays='+MonthDays);
SetCalendarDate(Year,Month,Day);
//SetCalendarDate(2000,1,30);

function DisplayCalendar() 
{var DisplayDay, CountDay=1;
//alert('MonthBegin:'+MonthBegin);
  for (DisplayDay=0;DisplayDay<=41;DisplayDay++)
  {
    if (DisplayDay<MonthBegin)
     {
      // Blank and hide field
      DisplayCalendarDay(DisplayDay,'')
     }
     else
     {
       if (CountDay>MonthDays)
        {
         // Blank and hide field
         DisplayCalendarDay(DisplayDay,'')
        }
        else
        {
         // Write date in field
         DisplayCalendarDay(DisplayDay,CountDay)
         CountDay++;
        };
     };
  };
//alert(CountDay+' '+MonthDays);
//  document.Calendar.Date.value=CalendarDate;
  document.Calendar.DisplayDate.value=DayName+', '+Day+' '+MonthName+' '+Year;
//  document.Calendar.EditMonth.value=MonthName;
  document.Calendar.EditYear.value=Year;
//  document.Calendar.EditMonthNumber.value=Month+1;
  document.Calendar.EditMonthNumber[Month].selected=true;
//  document.Calendar.EditDay.value=''+Day;
  document.Calendar.EditDay[Day-1].selected=true;

  ShowPhotoN=(Math.floor(CalendarDate.valueOf()/ 86400000));
  PhotoCurrent = ShowPhotoN - (Math.floor(ShowPhotoN/PhotosNumber)*PhotosNumber) + 1;
  ShowPhoto(PhotoCurrent);
//alert(PhotoCurrent);
};
function DisplayCalendarDay(DisplayDay,DisplayValue)
{ var ControlName='CalendarDay', Element=DisplayDay+3, Val=' '+DisplayValue+' ';
var tv;
  if (DisplayValue<10) { Val = ' ' + Val+' '; };
//  if (DisplayValue=='') { Val = ''; };
  if (DisplayValue=='') { Val = ' '; };
  ControlName=ControlName+DisplayDay;
//alert(ControlName+' '+Element);
//alert(document.Calendar[ControlName].value);
//alert('Debug: '+'Begin');
  document.Calendar[ControlName].value=Val; 
  if (DisplayValue=='') { document.Calendar[ControlName].style.visibility='hidden'; }
   else {document.Calendar[ControlName].style.visibility='visible';};
//alert('['+DisplayValue+'] ['+Day+']');
  if (DisplayValue==Day) { document.Calendar[ControlName].focus(); };
//  if (DisplayValue='') 
//   { document.Calendar[ControlName].type='HIDDEN'; }
//   else
//   { document.Calendar[ControlName].type='TEXT'; };  
};
function ChangeDate(fYear,fMonth,fDay)
{ 
//alert('['+fDay+']');
  if (isNaN(fDay)) { return };
//alert(fYear+'-'+fMonth+'-'+fDay);
  SetCalendarDate(fYear,fMonth-1,fDay);
//alert(CalendarDate+'\n'+Year+'-'+Month+'-'+Day);
  DisplayCalendar();
};
function GoToToday()
{
//alert(Today.getFullYear()+'-'+Today.getMonth()+'-'+Today.getDate());
  SetCalendarDate(Today.getFullYear(),Today.getMonth(),Today.getDate());
  DisplayCalendar();
};
function SelectDate(fDay)
{
  SetCalendarDate(Year,Month,fDay);
  DisplayCalendar();
};
function ChangeMonth(fMonth)
{
  SetCalendarDate(Year,fMonth,Day);
  DisplayCalendar();
};
function ChangeYear(fYear)
{
  SetCalendarDate(fYear,Month,Day);
  DisplayCalendar();
};


//DisplayCalendar();

//alert(new Date(1999,2,29,0,0,0,0));
//alert('Date='+CalendarDate+' \nToday='+Today+' \nMonth='+Month+' \nMonthName='+MonthName+' \nDay='+Day+' \nDayOfWeek='+DayOfWeek+' \nDayName='+DayName+' \nYear='+Year+' \nMonthBegin='+MonthBegin+' \nMonthDays='+MonthDays);

function ChangePhoto(form)
{var Default='', Selected='';
//  Default='http://www.mclink.it/personal/MC2074/Nik/question.gif';
//  Selected=form.SelectPhoto[form.SelectPhoto.selectedIndex].value;
  document.Photo.src=PhotosPath+PhotosArray[form.SelectPhoto.selectedIndex].Photo;
  document.Photo.alt=PhotosArray[form.SelectPhoto.selectedIndex].Name;
//  form.PhotoName.value=PhotosArray[form.SelectPhoto.selectedIndex].Name;
//  for (i=0;i<36;i++)
//  for (i=0;i<form.SelectPhoto.length;i++)
//     {Selected=form.SelectPhoto[form.SelectPhoto.selectedIndex].value;
//   { if (form.SelectPhoto[i].selected)
//       { Selected=form.SelectPhoto[i].value; };
//     alert(form.SelectPhoto[i].checked+' - '+form.SelectPhoto[i].value); 
//   };
//alert (Selected);
};

function NextPhoto(form)
{var Default='', SelectedIndex='';
//  Default='http://www.mclink.it/personal/MC2074/Nik/question.gif';
  SelectedIndex=form.SelectPhoto.selectedIndex;
//alert('Len='+form.SelectPhoto.length+'\nCurrent='+SelectedIndex);
  if (SelectedIndex >= (form.SelectPhoto.length - 1))
    {SelectedIndex = 0}
   else
    {SelectedIndex++};
//    {SelectedIndex = SelectedIndex + 1};
//  document.ChangeThePhoto.SelectPhoto[SelectedIndex-1].selected=true;
  form.SelectPhoto[SelectedIndex].selected=true;
  ChangePhoto(form);
};
function PreviousPhoto(form)
{var Default='', Selected='';
//  Default='http://www.mclink.it/personal/MC2074/Nik/question.gif';
  SelectedIndex=form.SelectPhoto.selectedIndex;
  if (SelectedIndex <= 0)
    {SelectedIndex = form.SelectPhoto.length - 1}
   else
    {SelectedIndex--};
//    {SelectedIndex = SelectedIndex + 1};
//  document.ChangeThePhoto.SelectPhoto[SelectedIndex-1].selected=true;
  form.SelectPhoto[SelectedIndex].selected=true;
  ChangePhoto(form);
};

var SlideDelay=0;
function RunSlideShow (form)
{ 
//alert('Start:'+form.SlideShow.checked);
  if (!form.SlideShow.checked) { return };  
  // Wait 15 seconds
  //NextPhoto(form);
  //setTimeout('RunSlideShow(form)',15000)
  //setTimeout('RunSlideShow(document.SeePhoto)',15000)
  //setTimeout('RunSlideShow(document.SeePhoto)',5000)
//alert(document.SeePhoto.Seconds.value);
  SlideDelay=eval(document.SeePhoto.Seconds.value);
  if (SlideDelay == 0) 
   { 
     alert('Seconds cannot be 0, reset to 5');
     SlideDelay=5;
   };
  document.SeePhoto.Seconds.value = SlideDelay;
  NextPhoto(document.SeePhoto);
  setTimeout('RunSlideShow(document.SeePhoto)',SlideDelay*1000)
};
function CalendarSlideShow (form)
{ 
//alert('Start:'+form.SlideShow.checked);
  if (!form.SlideShow.checked) { return };  
  // Wait 15 seconds
  //NextPhoto(form);
  //setTimeout('RunSlideShow(form)',15000)
  //setTimeout('RunSlideShow(document.SeePhoto)',15000)
  //setTimeout('RunSlideShow(document.SeePhoto)',5000)
//alert(document.SeePhoto.Seconds.value);
  SlideDelay=eval(document.Calendar.Seconds.value);
  if (SlideDelay == 0) 
   { 
     alert('Seconds cannot be 0, reset to 5');
     SlideDelay=5;
   };
  document.Calendar.Seconds.value = SlideDelay;
  NextPhoto(document.ChangeThePhoto);
  setTimeout('CalendarSlideShow(document.Calendar)',SlideDelay*1000)
};





function ShowPhoto(Pn) 
{
  document.ChangeThePhoto.SelectPhoto[Pn-1].selected=true;
  ChangePhoto(document.ChangeThePhoto);
};


////var PhotosNumber = <!--#counter increment="0" file="photosAll" -->;
////var PhotosNumber = 10;
//var i,mod4;
//document.write('<B>'+PhotosNumber+' photos </B><p>');
//
//document.write('<TABLE BORDER="2"><TR>');
//
//for (i=1;i<=PhotosNumber;i++) {
//   document.write('<TD>');
//
////   document.write('<A HREF="'+PhotosPath+PhotosNames+i+'.jpg">');
//   document.write('<A HREF="#DisplayedPhoto" onClick="ShowPhoto('+i+')">');
//   document.write('<IMG SRC="'+PhotosPath+PhotosNames+i+'.jpg" alt="Photo '+i+'" border="0"  width="150" ');
//   document.write('</A>');
////   document.write('</A>');
//   document.write('</TD>');
//   mod4 = Math.floor(i/4)*4;
//   if ((mod4 == i) && (i < PhotosNumber)) {document.write('</TR><TR>');};
//  };
//
//document.write('</TR></TABLE>');
//
////document.ChangeThePhoto.SelectPhoto[PhotoCurrent-1].selected=true;
//// ChangePhoto(document.ChangeThePhoto);
//

////SetCalendarDate(2000,1,1);
////ChangeDate(2000,2,4);
//ChangeDate(Year,Month+1,Day);
////DisplayCalendar();
////DisplayCalendarDay(0,'test')
////DisplayCalendarDay(1,'')

//NZ
//

