/* Changes to JavaScript
adddays to calcdays
datestr to datestr
date1 to breddate
date2 to tdy
date3 to breddate
date4 to duedate
days1 to infoaldays
days2 to gestdays
form name marecare to foalcalc
form name gestation to foalcalc
changed ultrasound #1 to 17 days
n to nd */


<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
 /* Credit goes to http://Javascript.Internet.com/Calculators/*/
<!-- 

function checkBrowser()
{
	var Brow = navigator.appName;
	var Ver = navigator.appVersion;
	if (Brow == "Netscape")
	{
		if (parseInt(Ver.substring(0,2)) < 3.0)
		{
			alert("This calculator may not work correctly with this version of Netscape.  A more current version can be downloaded from www.netscape.com")
		}
	}
}


function docalc(tempmonth, tempday, tempyear)
{

// translate the date into a Javascript date object
d = new Date((tempyear + 2000), tempmonth, tempday);
nd = new Date;
var i;
x = (24 * 60 * 60 * 1000);
y = (12 * 60 * 60 * 1000);


// Calculate the days & weeks pregnant
var ap;
dd = document.foalcalc.day.value;
mm = document.foalcalc.month.value;
yy = document.foalcalc.year.value;
with(document.foalcalc) {
}

//Validation - Is the date entered valid?
	main="valid";
	if ((mm < 1) || (mm > 12) || (dd < 1) || (dd > 31) || (yy < 1) ||(mm == "") || (dd == "") || (yy == ""))
	main = "Invalid";
	else 
	if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30))
	main = "Invalid";
	else 
	if (mm == 2) {
	if (dd > 29)
	main = "Invalid";
	else
	if((dd > 28) && (!lyear(yy)))
	main="Invalid";
			   		}
	else
	if((yy > 9999)||(yy < 0))
	main = "Invalid";
	else
	main = main;
	
	if(main == "valid") {
		function leapyear(a) {
	if(((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0))
		return true;
	else 
		return false;
								}
	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getYear();


//Determine time elapsed
	age = gyear - yy;
	if((mm == (gmonth + 1)) && (dd <= parseInt(gdate))) {
	age = age;
																	}
	else {
	if(mm <= (gmonth)) {
	age = age;
							}
	else {
	age = age - 1; 
		   }
			}
	if(age == 0)
	age = age;
	if(mm <= (gmonth + 1))
	age = age - 1;
	if((mm == (gmonth + 1)) && (dd > parseInt(gdate))) 
	age = age + 1;

//Determine Days Elapsed
var m;
var n;
if (mm == 12) { n = 31 - dd; }
if (mm == 11) { n = 61 - dd; }   
if (mm == 10) { n = 92 - dd; }  
if (mm == 9) { n = 122 - dd; } 
if (mm == 8) { n = 153 - dd; }   
if (mm == 7) { n = 184 - dd; }   
if (mm == 6) { n = 214 - dd; }  
if (mm == 5) { n = 245 - dd; } 
if (mm == 4) { n = 275 - dd; } 
if (mm == 3) { n = 306 - dd; }
if (mm == 2) { n = 334 - dd; if(leapyear(yy)) n = n + 1; }
if (mm == 1) { n = 365 - dd; if (leapyear(yy)) n = n + 1; }
if (gmonth == 1) m = 0;
if (gmonth == 2) { m = 31;   if (leapyear(gyear)) m = m + 1; }
if (gmonth == 3) { m = 59;   if (leapyear(gyear)) m = m + 1; }
if (gmonth == 4) { m = 90;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 5) { m = 120;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 6) { m = 151;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 7) { m = 181;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 8) { m = 212;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 9) { m = 243;  if (leapyear(gyear)) m = m + 1; }
if (gmonth == 10) { m = 273; if (leapyear(gyear)) m = m + 1; }
if (gmonth == 11) { m = 304; if (leapyear(gyear)) m = m + 1; }
if (gmonth == 12) { m = 334; if (leapyear(gyear)) m = m + 1; }
totdays = (parseInt(age) * 365);
totdays += age / 4;
totdays = parseInt(totdays) + gdate + m + n - 1;
document.foalcalc.days.value = totdays;


//Determine Weeks Elapsed
if (gmonth == 1) p = 31 + gdate;
if (gmonth == 2) { p = 59 + gdate;   if (leapyear(gyear)) m = m + 1; }
if (gmonth == 3) { p = 90 + gdate;   if (leapyear(gyear)) p = p + 1; }
if (gmonth == 4) { p = 120 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 5) { p = 151 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 6) { p = 181 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 7) { p = 212 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 8) { p = 243 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 9) { p = 273 + gdate;  if (leapyear(gyear)) p = p + 1; }
if (gmonth == 10) { p = 304 + gdate; if (leapyear(gyear)) p = p + 1; }
if (gmonth == 11) { p = 334 + gdate; if (leapyear(gyear)) p = p + 1; }
if (gmonth == 12) { p = 365 + gdate; if (leapyear(gyear)) p = p + 1; }
weeks = totdays / 7;
weeks += " weeks";
weeks = parseInt(weeks);
document.foalcalc.weeks.value = weeks;

}

	
	// Calculate due date using gestation period provided by user (average is 48 weeks)
	var gestdays = document.foalcalc.gestdays.value;
	i = (gestdays * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.dmonth.value = nd.getMonth() + 1;
	document.foalcalc.dday.value = nd.getDate();
	document.foalcalc.dyear.value = nd.getYear();

	// 17 days for Ultrasound #1 to detect pregnancy
	i = (17 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.omonth.value = nd.getMonth() + 1;
	document.foalcalc.oday.value = nd.getDate();
	document.foalcalc.oyear.value = nd.getYear();

    // 4 weeks (28 days) for Ultrasound #2 to detect heartbeat
	i = (28 * x) + y;
 	nd.setTime(i + d.getTime());
	document.foalcalc.jmonth.value = nd.getMonth() + 1;
	document.foalcalc.jday.value = nd.getDate();
	document.foalcalc.jyear.value = nd.getYear();

	// 12 weeks (84 days) for vaccinations
	i = (84 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.smonth.value = nd.getMonth() + 1;
	document.foalcalc.sday.value = nd.getDate();
	document.foalcalc.syear.value = nd.getYear();
        
    // 20 weeks (140 days) for first Rhino
	i = (140 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.pmonth.value = nd.getMonth() + 1;
	document.foalcalc.pday.value = nd.getDate();
	document.foalcalc.pyear.value = nd.getYear();

	// 28 weeks (196 days) for second Rhino
	i = (196 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.tmonth.value = nd.getMonth() + 1;
	document.foalcalc.tday.value = nd.getDate();
	document.foalcalc.tyear.value = nd.getYear();
       
	// 36 weeks (252 days) for third Rhino
	i = (252 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.fmonth.value = nd.getMonth() + 1;
	document.foalcalc.fday.value = nd.getDate();
	document.foalcalc.fyear.value = nd.getYear();
		
    // 44 weeks (308 days) for vaccinations, begin daily wormer, begin watching for signs
	i = (308 * x) + y;
	nd.setTime(i + d.getTime());
	document.foalcalc.rmonth.value = nd.getMonth() + 1;
	document.foalcalc.rday.value = nd.getDate();
	document.foalcalc.ryear.value = nd.getYear();
}

// end hidden script -->
