
var DaysList = new Array("Component Translation 'Monday' not found.", "Component Translation 'Tuesday' not found.", "Component Translation 'Wednesday' not found.", "Component Translation 'Thursday' not found.", "Component Translation 'Friday' not found.", "Component Translation 'Saturday' not found.", "Component Translation 'Sunday' not found.");
var MonthsList = new Array("Component Translation &#39;01&#39; not found&#46;", "Component Translation &#39;02&#39; not found&#46;", "Component Translation &#39;03&#39; not found&#46;", "Component Translation &#39;04&#39; not found&#46;", "Component Translation &#39;05&#39; not found&#46;", "Component Translation &#39;06&#39; not found&#46;", "Component Translation &#39;07&#39; not found&#46;", "Component Translation &#39;08&#39; not found&#46;", "Component Translation &#39;09&#39; not found&#46;", "Component Translation &#39;10&#39; not found&#46;", "Component Translation &#39;11&#39; not found&#46;", "Component Translation &#39;12&#39; not found&#46;");

var LabelList = {"Hours" : "Component Translation 'Hours:' not found.", "Location" : "Component Translation 'Location:' not found.", "Style" : "customer-seasons", "ImgCSSURL" : "/CORP/FR/Neutral/Images/"};

var Content = new Array();
var Events = new Array();
var Attractions = new Array();
var Parks = new Array();
var Seasons = new Array();
var Default = {"Title" : "Component Translation 'Default Calendar Message' not found."};

var Today = new Date();
// Get the year (YYYY)
var CurrentYear = Today.getFullYear();
//var TodaysYear = CurrentYear;
var TodaysYear =  getURLVariable('year')
// Get the month (0..11)
var CurrentMonth = Today.getMonth();
//var TodaysMonth = CurrentMonth;
var TodaysMonth = getURLVariable('month')
// Get the day in the month (1..31)
var CurrentDay = Today.getDate();
//var TodaysDate = CurrentDay;
var TodaysDate = getURLVariable('day')
// Get the day in the week for the current date (0..6, 0=>Sunday, ...)
var TodaysDay = GetDayNumber(Today.getDay());
// Get the day in the week for the first day of the month
Today = new Date(TodaysYear,TodaysMonth,1);
var TodaysFirstDay = GetDayNumber(Today.getDay());

// Get informations of the next month
if(parseInt(TodaysMonth)+1>11){
	Today = new Date(parseInt(TodaysYear)+1,0,1);
}
else{
	Today = new Date(parseInt(TodaysYear),parseInt(TodaysMonth)+1,1);
}
var NextYear = Today.getFullYear();
var NextMonth = Today.getMonth();
var NextFirstDay = GetDayNumber(Today.getDay());

var MonthLength = new Array(31,GetFebruaryNbDays(TodaysYear),31,30,31,30,31,31,30,31,30,31);

/*
 ** Construct the calendar for the previous month
 */
function GoToMonthPrevious(){
	NextYear = TodaysYear;
	NextMonth = TodaysMonth;
	NextFirstDay = TodaysFirstDay;
	
    TodaysMonth -= 1;
    if(TodaysMonth<0){
        TodaysMonth = 11;
        TodaysYear -= 1;
        // reCalculate the number of days for the month of february (in case of a bissextile year)
        MonthLength[1] = GetFebruaryNbDays(TodaysYear)
    }
    Today = new Date(TodaysYear,TodaysMonth,1);
    TodaysFirstDay = GetDayNumber(Today.getDay());

    ConstructCalendar();
}
/*
 ** Construct the calendar for the next month
 */
function GoToMonthNext(){
	TodaysYear = NextYear;
	TodaysMonth = NextMonth;
	TodaysFirstDay = NextFirstDay;
	
    NextMonth += 1;
    if(NextMonth>11){
        NextMonth = 0;
        NextYear += 1;
        // reCalculate the number of days for the month of february (in case of a bissextile year)
        MonthLength[1] = GetFebruaryNbDays(NextYear)
    }
    Today = new Date(NextYear,NextMonth,1);
    NextFirstDay = GetDayNumber(Today.getDay());

    ConstructCalendar();
}
/*
 ** Construct the calendar for the previous day
 */
function GoToDayPrevious(){
    TodaysDate -= 1;
    if(TodaysDate<1){
        GoToMonthPrevious();
		TodaysDate = MonthLength[TodaysMonth];
    }

	ConstructDayCalendar();
}
/*
 ** Construct the calendar for the next day
 */
function GoToDayNext(){
	TodaysDate += 1;
	if(TodaysDate>MonthLength[TodaysMonth]){
        GoToMonthNext();
		TodaysDate = 1;
	}

	ConstructDayCalendar();
}
/*
 ** Construct the calendar
 */
function ConstructCalendar(){
    // Change the label (Month + Year)
    document.getElementById("labelCurrentMonthYear").innerHTML = MonthsList[TodaysMonth] + " " + TodaysYear;
	document.getElementById("labelNextMonthYear").innerHTML = MonthsList[NextMonth] + " " + NextYear;
	
	// Change the calendar of the current month
	document.getElementById("calendarContent").innerHTML = ConstructMonthCalendar(TodaysFirstDay,TodaysMonth,TodaysYear);
	// Change the calendar of the next month
	document.getElementById("calendarContentNext").innerHTML = ConstructMonthCalendar(NextFirstDay,NextMonth,NextYear);
}
/*
 ** Construct the month calendar with a day, a month and a year
 */
function ConstructMonthCalendar(day,month,year){
    var calendarContent = "";
    var numDay;

    // Calculate the number of line in the calendar (possibility : 4, 5 or 6)
    var nbLine = 4;
    for(i=4 ; i<=6 ; i++){
        if( i*7 >= (day - 1 + GetMonthLength(month))){
            nbLine = i;
            break;
        }
    }
    for(i=0 ; i<nbLine ; i++){
        calendarContent += "<div class=\"CalendarR\">";
        for(j=1 ; j<=7 ; j++){
            if(((i * 7) + j) < day){
                // Day of the previous month
                calendarContent += "<div class=\"CalendarC\"></div>";
			}
			else if(((i * 7) + j - day + 1) > GetMonthLength(month)){
			    // Day of the next month
			    calendarContent += "<div class=\"CalendarC\"></div>";
			}
			else{
			    // Day of the current month
			    numDay = (i * 7) + j - day + 1
                if(numDay == CurrentDay && month == CurrentMonth && year == CurrentYear){
		            // Day of today
		            calendarContent += "<div class=\"CalendarToday\"><a href=\"javascript:DisplayDay("+numDay+","+month+","+year+");\">"+numDay+"</a></div>";
		        }
		        else{
		            // Other day of the current month
					
		            calendarContent += "<div class=\"CalendarC\"><a href=\"javascript:DisplayDay("+numDay+","+month+","+year+");\">"+numDay+"</a></div>";
		        }    
			}
        }
        calendarContent += "</div>";
		calendarContent += "<div class=\"clear\"></div>"
    }
  
    return calendarContent;
}

/*
 ** Construct the day calendar
 */
function DisplayDay(day,month,year){
	TodaysDate = day;
	TodaysMonth = month;
	TodaysYear = year;
	ConstructDayCalendar();
}
function getParksHours(){
	var theDay;
    if(CurrentDay < 10){
        theDay = "0"+CurrentDay;
    }
    else{
        theDay = CurrentDay;
    }
    var theMonth;
    if((CurrentMonth+1) < 10){
        theMonth = "0"+(CurrentMonth+1);
    }
    else{
        theMonth = CurrentMonth+1;
        
    }
    theMonth = theMonth.toString();
    var key = theDay+theMonth+CurrentYear;
    key = key.toString();
	var result = "";
	for(var i=0 ; i<Content.length ; i++){
        if(Content[i][key]){
			 result +=  Content[i]["Name"]+ ": "+ Content[i][key] +"<br/>";
		}
	}
                if(document.getElementById("ParksHours") != null){
	    document.getElementById("ParksHours").innerHTML = result;
                }
}

function getMeetNgreetHours(meetName,meetTitle){
    var theDay;
    if(CurrentDay < 10){
        theDay = "0"+CurrentDay;
    }
    else{
        theDay = CurrentDay;
    }
    var theMonth;
    if((CurrentMonth+1) < 10){
        theMonth = "0"+(CurrentMonth+1);
    }
    else{
        theMonth = CurrentMonth+1;
        
    }
    theMonth = theMonth.toString();
    var key = theDay+theMonth+CurrentYear;
    key = key.toString();
	theMonth = theMonth.toString();
    var key = theDay+theMonth+CurrentYear;
    key = key.toString();
	var result = "";
	for(i=0 ; i<Parks.length ; i++){
		cpt = 0;
		for(j=0 ; j<Events.length ; j++){
			if(Events[j]["Title"]== meetTitle){
				if(Events[j]["Hours"][key]){
					cpt++;
					result = Events[j]["Hours"][key]
				}
			}
		}
	}
	document.getElementById(meetName).innerHTML = result;
}

function getParadsHours(paradName,paradTitle){
    var theDay;
    if(CurrentDay < 10){
        theDay = "0"+CurrentDay;
    }
    else{
        theDay = CurrentDay;
    }
    var theMonth;
    if((CurrentMonth+1) < 10){
        theMonth = "0"+(CurrentMonth+1);
    }
    else{
        theMonth = CurrentMonth+1;
        
    }
    theMonth = theMonth.toString();
    var key = theDay+theMonth+CurrentYear;
    key = key.toString();
	var result = "";
	for(i=0 ; i<Parks.length ; i++){
		cpt = 0;
		for(j=0 ; j<Events.length ; j++){
		    if(Events[j]["Title"]== paradTitle){
				if(Events[j]["Hours"][key]){
					cpt++;
					result = "<h3>" + Events[j]["Location"]+ "<h3/>" + "<h3>" + Events[j]["Hours"][key] + "<h3/>"
				}
			}
		}
	}
	document.getElementById(paradName).innerHTML = result;
}


/*
 ** Construct the day calendar
 */
function ConstructDayCalendar(){
	document.getElementById("labelDay").innerHTML = TodaysDate + " " + MonthsList[TodaysMonth] + " " + TodaysYear;
	
	var theDay;
    if(TodaysDate < 10){
        theDay = "0"+TodaysDate.toString();
    }
    else{
        theDay = TodaysDate.toString();
    }
    var theMonth;
    if((TodaysMonth+1) < 10){
        theMonth = "0"+(TodaysMonth+1);
    }
    else{
        theMonth = TodaysMonth+1;
        
    }
    theMonth = theMonth.toString();
    var key = theDay+theMonth+TodaysYear.toString();
    key = key.toString();
	
	// Parks informations
    var result = "";
    for(var i=0 ; i<Content.length ; i++){
        if(Content[i][key]){
			result += "<div class=\"ParcHoursR\">";
			result += "<div class=\"ParcHoursC1\"><img src=\"" + LabelList["ImgCSSURL"] + LabelList["Style"].toLowerCase() + "-icon-" + Content[i]["Class"] + ".gif\" alt=\"\" /></div>";
			result += "<div class=\"ParcHoursC2\">" + Content[i]["Name"] + " &gt; " + Content[i][key] + "</div>";
			result += "<div class=\"clear\"></div>";
			result += "</div>";
        }
    }
    document.getElementById("ParksContent").innerHTML = result;

    // Season informations
	var result = "";
	var seasonTitle = "";
    for(var i=0 ; i<Seasons.length ; i++){
        if(Seasons[i]["Hours"][key]){
            result +="<img src=\""+Seasons[i]["Image"]+"\" class=\"ftLeft\" width=\"13\" heigth=\"14\" alt=\"\" />";
			seasonTitle = Seasons[i]["Title"];
			//alert(seasonTitle.length);
			if(seasonTitle.length > 17){
				//alert(seasonTitle.substr(0,14)+"...");
				seasonTitle = seasonTitle.substr(0,14)+"...";
			}
            result += "<div class=\"ftLeft\">" + seasonTitle + "</div>";
            break;
        }
    }
    	
	document.getElementById("SeasonContent").innerHTML = result;
	
	// Events informations
	result = "";
	var subResult;
	var cpt;
	for(i=0 ; i<Parks.length ; i++){
		cpt = 0;
		subResult = "<span class=\"Ttl1\">" + Parks[i] + "</span>";
		subResult += "<dl>";
		for(j=0 ; j<Events.length ; j++){
			if(Events[j]["Hours"][key] && Events[j]["Park"] == Parks[i]){
				cpt++;
				subResult += "<dt><a href=\"" + Events[j]["Link"] + "\">" + Events[j]["Title_name"] + "</a></dt>";
				subResult += "<dd>" + LabelList["Hours"] + " " + Events[j]["Hours"][key] + "<br />";
				subResult += LabelList["Location"] + " " + Events[j]["Location"] + "</dd>";
			}
		}
		subResult += "</dl>";
		if(cpt > 0){
			result += subResult;
		}
	}

	document.getElementById("EventsContent").innerHTML = result;
	
	// Attractions informations
	var isUpdate = false;
	result = "";
	key = theMonth+TodaysYear.toString();
    key = key.toString();
	for(i=0 ; i<Attractions.length ; i++){
		if(Attractions[i]["Hours"][key]){
			result += "<dl>";
			result += "<dt><a href=\"" + Attractions[i]["Link"] + "\">" + Attractions[i]["Title_name"] + "</a></dt>";
			result += "<dd>" + Attractions[i]["Hours"][key] + "</dd>";
			result += "</dl>";
			isUpdate = true;
		}
	}
	if(!isUpdate){
		result += "<dl>";
		result += "<dt>"+ Default["Title"] + "</dt>";
		result += "<dd></dd>";
	}

	
	document.getElementById("AttractionsContent").innerHTML = result;
}

/*
 ** Get the day number in a week (1=>Monday, ..., 7=>Sunday)
 */
function GetDayNumber(day){
    if(day == 0){
        return 7;
    }
    else{
        return day;
    }
}
/*
 ** Get the number of days in the month in parameter
 */
function GetMonthLength(month){
    if(month == -1){
        return MonthLength[11];
    }
    else if(month == 12){
        return MonthLength[0];
    }
    else{
        return MonthLength[month];
    }
}
/* 
 ** Get the number of days of the february month for the year in parameter
 */
function GetFebruaryNbDays(yy){
    if ((yy % 100 != 0 && yy % 4 == 0) || (yy % 400 == 0)){
        return 29;
    }
    else{
        return 28;
    }
}
/*
 ** Get the value of a variable in current page URL
 */
function getURLVariable(strVarNameToSearch){
    if(location.search.substring(1)){
        // Get all the argument in the URL in a table
        tbVar = location.search.substring(1).split('&');

	    for(i=0 ; i<tbVar.length ; i++){
		    // Look for equal character
		    intPosEgal = (tbVar[i].indexOf("=",0));
    		
		    // Get the name of the variable
		    strVarName = tbVar[i].substring(0,intPosEgal);
    		
    		if(strVarNameToSearch == strVarName){
		        // Return the variable value
		        return tbVar[i].substring(intPosEgal+1,tbVar[i].length);
		    }
	    }
    }
    // variable not found
    return ""
}
