﻿/* 
***Date created: June 4,2009
***Programmer Name: Michael Murphy
*/
 

function Calc_birth(Month, Day) 
{
    if (document.C_form.R1[0].checked) 
    {
        //Array to hold the months
        var Month1 = new Array(12);
        Month1[0] = "January";
        Month1[1] = "February";
        Month1[2] = "March";
        Month1[3] = "April";
        Month1[4] = "May";
        Month1[5] = "June";
        Month1[6] = "July";
        Month1[7] = "August";
        Month1[8] = "September";
        Month1[9] = "October";
        Month1[10] = "November";
        Month1[11] = "December";

        //Set the users date
        var myDate = new Date();
        myDate.setFullYear(myDate.getFullYear(), Month - 1, Day-1);
        // Math variables
        var i;
        var n = new Date();

        // Calculate the pregnancy time
        i = 282 * (24 * 60 * 60 * 1000) + (12 * 60 * 60 * 1000);
        n.setTime(i + myDate.getTime());

        //Grab the div and input the date the calf is due
        //Also Check for innerText useability 
        if (document.all) {
            var div1 = document.getElementById("Results");
            div1.innerText = "The calf is due " + Month1[n.getMonth()] + " " + n.getDate();
        } else {
            var div1 = document.getElementById("Results");
            div1.textContent = "The calf is due " + Month1[n.getMonth()] + " " + n.getDate();
        }
            
        
    }

    else if (document.C_form.R1[1].checked) {
       //Set an array with the months.    
        var Month1 = new Array(12);
        Month1[0] = "January";
        Month1[1] = "February";
        Month1[2] = "March";
        Month1[3] = "April";
        Month1[4] = "May";
        Month1[5] = "June";
        Month1[6] = "July";
        Month1[7] = "August";
        Month1[8] = "September";
        Month1[9] = "October";
        Month1[10] = "November";
        Month1[11] = "December";
        
        //Set the users date
        var myDate = new Date();
        myDate.setFullYear(myDate.getFullYear(), Month - 1, Day);
        // Math variables
        var i;
        var n = new Date();

        // Calculate the pregnancy time
        i = 283 * ((24 * 60 * 60 * 1000) + (12 * 60 * 60 * 1000));
        n.setTime(i + myDate.getTime());
        //I don't know why but it was off by 24 days so this piece of code just adds 24 days.
        n.setDate(n.getDate() + 23);

        //Grab the div and put the day the service was done.
        if (document.all) {

            var div1 = document.getElementById("Results");
            div1.innerText = "Service took place " + Month1[n.getMonth()] + " " + n.getDate();
        }
        else {
            var div1 = document.getElementById("Results");
            div1.textContent = "Service took place " + Month1[n.getMonth()] + " " + n.getDate();
        }
         
        

    }
}
