﻿////  Debugging Control
////    Zero is off
////    Enable traces in firebug for debugging by setting this to 1.
var Debug = 0;


////  Trace Function Controlled by the Debug var. Prints traces to Firebug using console.log()
function trace( string ){
    if (Debug > 0){
        try {
            console.log( string );
        }
        catch(e){
            //do nothing
        }
    }
}





function countdownPatrick(){
	////
	//// Initialize the two dates
	////
	var today = new Date();
	var todayDate = today.getDate();
	var todayMonth = today.getMonth();
	var todayYear = today.getFullYear();

	var targetDate = 17;
	var targetMonth = 2; ////(Note this is based on jan=0, feb=1, march=2. stupid api
	var targetYear = todayYear;
	////Fix the year to be ahead by 1 if we are past Saint Patricks Day!
	if (   (todayDate > 17 && todayMonth >= 2)  || todayMonth > 2  ){
		targetYear = parseInt(todayYear) + 1;
	}

	var target = new Date();
	target.setFullYear(targetYear, targetMonth, targetDate);

	var todayAbsTime = today.getTime();
	var targetAbsTime = target.getTime();

	////
	//// Give msg depending on what day it is
	////
	
	if ( !(todayDate == targetDate && todayMonth == targetMonth) ){
		//// Compare the times
		var differenceAsAbsTime = targetAbsTime - todayAbsTime;
		var differenceAsDays = Math.round( differenceAsAbsTime / (24*60*60*1000) )
		//// Give msg, different if there is only 1 day
		if (differenceAsDays > 1) {
			document.write(differenceAsDays + " days to Saint Patricks Day!" );
		}
		else {
			document.write(differenceAsDays + " left before Saint Patricks Day!" );
		}
	}
		
	else {
		document.write("Saint Patrick's Day is Today!");
	}
}