// JavaScript Document		
function isHolliday(date)
{	

	var currDate = new Date();
	currDate.setTime(date.valueOf());
	currDate.setDate(date.getDate()+1);
	
	var monthNo = currDate.getUTCMonth();
	
	/* Get the current month name */
   var monthName = getMonthName(monthNo+1);
	
	/* Get the month node */
	var month = xmlDates.getElementsByTagName(monthName); 

	/* if the node exists check if it's the current day */
	if(month.length > 0)
	{
		/* get month hollidays */
		var monthHollidays = month[0].getElementsByTagName("Feriado"); 

		for(i=0; i < monthHollidays.length ; i++)
		{
			/* get holliday day */ 
			var day = monthHollidays[i].getElementsByTagName("Dia");
			var corr = parseInt(day[0].getAttribute("corr"));
			var dayValue = day[0].firstChild.nodeValue;
			
			var hollidayDate = new Date();
			hollidayDate.setFullYear(date.getFullYear(), monthNo, parseInt(dayValue), 0,0,0);
			
			if(corr!=0)
				hollidayDate.setDate(hollidayDate.getDate()+corr);
			
			/* set both dates to 00 hours */				
			hollidayDate.setUTCHours(00,00,00,00);	
			currDate.setUTCHours(00,00,00);
			
			if( currDate.valueOf() == hollidayDate.valueOf())				
			{	
				var desc = monthHollidays[i].getElementsByTagName("Descricao")[0].firstChild.nodeValue;
				
				
				if(currDate.getUTCMonth() == currentMonth-1)
				{
					/* side text */
					var hollidayHtml =  "<span class='ui-state-error'>" + dayValue +"</span> - " + desc;
					
					var sideText = "<div id='"+dayValue+"' style='float:left; margin:5px; clear:both;'>"+hollidayHtml+ "</div>";
					
					if( $("#"+dayValue).html() == null )
						$("#hollidays").append(sideText);
				}

				return new Array(false,"holliday",desc);
			}
		}
	}
	
	return null;		
}	
	
function getMonthName(monthNo)
{
	switch(monthNo)
	{
		case 1: return "Janeiro";
		case 2: return "Fevereiro";
		case 3: return "Março";
		case 4: return "Abril";
		case 5: return "Maio";
		case 6: return "Junho";
		case 7: return "Julho";
		case 8: return "Agosto";
		case 9: return "Setembro";
		case 10: return "Outubro";
		case 11: return "Novembro";
		case 12: return "Dezembro";
	}
}
	
function styleHolliday()
{
	//add id for the current element only!
	$(".holliday").attr("name","holliday");

	/* clean childs classes...*/	
	$("*[name='holliday'] *").removeAttr("class");
	
	//remove all element classes, add holliday class and remove his id
	$("*[name='holliday']").removeAttr("class").removeAttr("name").addClass("ui-state-error");
}


function updateText(month)
{
	currentMonth = month;
	$("#hollidays").empty();
}