//var holidayDaysBefore = "14";
var $hopDialog;

$(document).ready(function() {
    showHolidayHours();

    //$('.nyroModal').dialog({ width: 270, height: 270 });

    $hopDialog = $("#hopDiv").dialog({ autoOpen: false, title: 'Holiday Hours of Operation' });
    //	$('.nyroModal').nyroModal({
    //            width: 270,	// initial width
    //            height: 270,	// initial height
    //            minWidth: 270,	// minimum width
    //            minHeight: 270,	// minimum height
    //            showCloseButton: true,
    //            closeButton: '<div class="nyroModalClose" title="Close";>&nbsp;</div>'
    //	    });

});

function showHolidayPopup() {
    $hopDialog.dialog('open');
}

  
function showHolidayHours(){
    var holidayHoursTitle = false;
	if(!holidayDaysBefore || !(/^[0-9]+$/).test(holidayDaysBefore)){
			holidayDaysBefore = "14";
		}
	$(".holidayHoptr").each(function(){
		var thisday = $(this).find("span[id$=isoDateSpan]").text();
		var today = new Date();
		var thisDayYear = parseInt(today.getFullYear);
		var thisDayMonth = parseInt(today.getMonth);
		var thisDayDay = parseInt(today.getDay);
		//alert(thisday);
		var dateParts = thisday.match(/([0-9]+)-([0-9]+)-([0-9]+)/);
		if(dateParts.length = 4){
		    thisDayYear = parseInt(dateParts[1]);
		    thisDayMonth = parseInt(dateParts[2].replace(/^0+/,""))-1;
		    thisDayDay = parseInt(dateParts[3].replace(/^0+/,""));
		}
		var thisdayDate = new Date(thisDayYear,thisDayMonth,thisDayDay,0,0,0,0)//new Date(thisday);//Date.parse(thisday);
		//alert(thisdayDate);
		var dayInMilliSeconds = 1000*60*60*24;
		//alert(thisdayDate);
		
		var timeDiff = thisdayDate.getTime() - (today.getTime()-today.getTime()%dayInMilliSeconds);
		var dayDiff = parseInt(timeDiff/dayInMilliSeconds);
		//alert("thisday!: " +thisday+ ", dayDiff: " + dayDiff + " holidayDaysBefore: " +holidayDaysBefore );
		if(dayDiff >= 0 && dayDiff <= parseInt(holidayDaysBefore)){
			$(this).show();
			holidayHoursTitle = true;
		}else{
			$(this).hide();
		}
	});
	if(holidayHoursTitle == true){
	    $("#holidayHOPTitle").show();
	}
}

