// Remember getTime is in milliseconds. To calculate a day 
// in terms of days, we need to divide by 1000 to get time in 
// seconds, divide by 60 to get time in minutes, divide by 60 
// again to get time in hours, divide by 24 to get time in days.

function dateToDays(zDate) {
	var time = zDate.getTime()
	var msPerDay = (1000 * 60 * 60 * 24)
	var numDays = (time - (time % msPerDay)) / msPerDay
	return numDays
}

function daysUntil(startDate, targetDate) {
	var numDays = dateToDays(targetDate) - dateToDays(startDate)
	return numDays
} 

/*----------------------------------------------------------------*/
/*                                                                */
/* Program name: Florida Countdown and schedule                   */
/* Author : Ben Costales                                          */
/* Created: 01/28/10                                              */
/* Last Modified: 01/28/10                                        */
/* Purpose: It countdowns days till Florida and tells the schedule*/
/*          of what we are doing                                  */
/*                                                                */
/*                                                                */
/*----------------------------------------------------------------*/


var today = new Date()

// set extraneous hours, minutes, seconds, and ms to 0
today.setHours(0); today.setMinutes(0)
today.setSeconds(0); today.setMilliseconds(0)

var month = today.getMonth() + 1	
var thisYear = today.getFullYear()
var nextYear = thisYear + 1
var travelDayToFL = new Date(thisYear, 2, 18)		    // Thursday the 18th - Leave for Florida: March 18
var parkHopingOne = new Date(thisYear, 2, 19)		    // Friday the 19th - Park Hoping: March 19
var performanceDay = new Date(thisYear, 2, 20)      //Saturday the 20th - Performance Day: March 20
var parkHopingTwo = new Date(thisYear, 2, 21)       //Sunday the 21st - Park Hoping: March 21
var travelHomeDay = new Date(thisYear, 2,22)        //Monday the 22nd - Travel Back Home: March 22



// make certain years are set to next year if target date has 
// already passed this year
if (today.getTime() > travelDayToFL.getTime()) {		
	travelDayToFL.setFullYear(nextYear)
}

/*---------------------------------------------------------------*/
/*                                                               */
/* switch is based on the month by using the                     */
/* var month = today.getMonth() + 1                              */
/*                                                               */
/*---------------------------------------------------------------*/

switch (month)  {

case 1:

    if (daysUntil(today, travelDayToFL) < 65) {
        if (daysUntil(today, travelDayToFL) >=0) {
                    document.writeln("<p>We only have ",
                    daysUntil(today, travelDayToFL),
                    " days left until we leave for Florida!</p>")
        }
    } 

break

case 2:

    if (daysUntil(today, travelDayToFL) < 65) {
        if (daysUntil(today, travelDayToFL) >=0) {
                    document.writeln("<p>We only have ",
                    daysUntil(today, travelDayToFL),
                    " days left until we leave for Florida!</p>")
        }
    } 

break


case 3:
    
    if (daysUntil(today, travelDayToFL) < 65) {
        if (daysUntil(today, travelDayToFL) >= 0)    { 
            if (daysUntil(today, travelDayToFL) == 0) {
                document.writeln("<p>We are leaving for Florida today!</p>")
            }   else if (daysUntil(today, travelDayToFL) == 1)   {
                document.writeln("<p>Only 1 more day till we leave for Florida!</p>")
            }   else {
                document.writeln("<p>We only have ",
                daysUntil(today, travelDayToFL),
                " days left until we leave for Florida!</p>")
            }
        } 
    }

    if (daysUntil(today, parkHopingOne) == 0) {
                document.writeln("<p>Today we are park hoping in Walt Disney World!</p>")
    }
    
    if (daysUntil(today, performanceDay) == 0) {
                document.writeln("<h3>Today we are performing in Downtown Disney!</p>")
    }
    
    if (daysUntil(today, parkHopingTwo) == 0) {
                document.writeln("<p>Today we are park hoping in Walt Disney World!</p>")
    }

    if (daysUntil(today, travelHomeDay) == 0) {
                document.writeln("<p>We are traveling back home to New Mexico today. See you soon!</p>")
    }
    
break
 
}
