


<!--

//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;

  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function to set options to today
function SetToToday(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  YearObject[0].selected = true;
  MonthObject[NowMonth].selected = true;

  ChangeOptionDays(Which);

  DaysObject[NowDay-1].selected = true;
}

//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION>";
    line += NowYear + i;
  }
  return line;
}

var msPerDay = 24*60*60*1000

function DaysToWD( days )
 {
  w = Math.floor(days/7)
  d = Math.floor(days - 7*w)

  s = w + "w" + d + "d"

  return s
 }


function formatDate( d )
 {
  f = document.Form1

  y = d.getYear()
  if( y < 100 ) y = y + 1900
  
/*  return f.FirstSelectDay.options[d.getDate()-1].text  + " " +
           f.FirstSelectMonth.options[d.getMonth()].text + " "  +
           y*/

	return d.getDate() + " " + f.FirstSelectMonth.options[d.getMonth()].text + " "  + y;
 }

function doTriCalc()
 {
  f = document.Form1

  day   = f.FirstSelectDay.selectedIndex + 1
  month = f.FirstSelectMonth.selectedIndex
  year  = f.FirstSelectYear.selectedIndex + 2010
  
  periode = f.cycle.value
   
  lmp = new Date(year,month,day)
  //lmp = new Date(2003,9,25)

 //------ Calc Ovulation Dates -------
  
  var e;
  e = getDate(lmp,periode - 15);
  f.Ovul01.value = formatDate(e)
    
  e = getDate(lmp,periode - 18);
  f.Start01.value = formatDate(e)
  
   e = getDate(lmp,periode - 14);
   f.End01.value = formatDate(e)

   e = getDate(lmp,periode*2 - 15);
   f.Ovul02.value = formatDate(e)
   
   e = getDate(lmp,periode*2 - 18);
   f.Start02.value = formatDate(e)
   
   e = getDate(lmp,periode*2 - 14);
   f.End02.value = formatDate(e)
   
   e = getDate(lmp,periode*3 - 15);
   f.Ovul03.value = formatDate(e)
   
   e = getDate(lmp,periode*3 - 18);
   f.Start03.value = formatDate(e)
   
   e = getDate(lmp,periode*3 - 14);
   f.End03.value = formatDate(e)   
}

function Clean()

 {
  f = document.Form1
	f.Ovul01.value =""
	f.Start01.value =""
 	f.End01.value =""
	f.Ovul02.value =""
	f.Start02.value =""
 	f.End02.value ="" 	
	f.Ovul03.value =""
	f.Start03.value =""
 	f.End03.value =""
}

// added by Sam Blanchard
// fix the strange bug (with the UTC who change in a setTime function)

function getDate(originalDate,addDay)
{
	var msPerHour = 3600 * 1000;
	var msPerDay = 24 * msPerHour;
	var data01 = new Date();

	data01.setTime(originalDate.getTime() + (addDay*msPerDay));

	var origineTimezone = originalDate.getTimezoneOffset();
	currentTimeZone = data01.getTimezoneOffset();

	if(currentTimeZone != origineTimezone)
	{
		// on rajoute les heures de differences pour contrer le bug !!!

		var hours = -((origineTimezone - currentTimeZone)/60);

		data01.setTime(originalDate.getTime() + (addDay*msPerDay) + msPerHour * hours);
	}

	return data01;
}
// -->