/*
 * DatePicker
 * @author Rick Hopkins
 * @modified by Micah Nolte and Martin Va?ina
 * @version 0.3.2
 * @classDescription A date picker object. Created with the help of MooTools v1.11
 * MIT-style License.

-- start it up by doing this in your domready:
 */

var datePickerRegistry = new Object();

var DatePicker = new Class({
	deliveryCalendarTypes: null,
	deliveryCalendarBulkMessages: null,
	dateSaver: null,
	calendarLastDate :null,

	/* set and create the date picker text box */
	initialize: function(dp)
	{
		// Mootools dollar
		this.$ = document.id;
		
		// Options defaults
		this.dayChars = 1; // number of characters in day names abbreviation
		this.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
		this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		this.format = 'dd/MM/yyyy';
		this.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		this.startDay = 7; // 1 = week starts on Monday, 7 = week starts on Sunday
		this.yearOrder = 'asc';
		this.yearRange = 10;
		this.yearStart = (new Date().getFullYear());

		// Finds the entered date, or uses the current date
		var values = dp.value.split('/');
		if(values.length == 3) {
			dp.then = new Date(Number(values[2]), Number(values[1])-1, Number(values[0]));
			dp.today = new Date();
		}
		else {
			dp.then = dp.today = new Date();
		}
		// Set beginning time and today, remember the original
		dp.oldYear = dp.year = dp.then.getFullYear();
		dp.oldMonth = dp.month = dp.then.getMonth();
		dp.oldDay = dp.then.getDate();
		dp.nowYear = dp.today.getFullYear();
		dp.nowMonth = dp.today.getMonth();
		dp.nowDay = dp.today.getDate();
		dp.nextDay = dp.nowDay + 1;
		dp.calendarID = dp.id.substring(('datePicker_').length);				
		dp.shippingMethodID = dp.calendarID.substring(dp.calendarID.lastIndexOf('_')+1);		//FFS-866		
		dp.namedDay = document.getElementById('namedDay_'+dp.calendarID);
		dp.holidays = document.getElementsByName('holidays');
		dp.deliveryCalendarURL = document.getElementById('DeliveryCalendarPipeline_'+dp.calendarID);
		dp.minDeliveryDay = dp.nextDay;
		dp.minDeliveryMonth = dp.nowMonth;
		dp.minDeliveryYear = dp.nowYear;
		var minDeliveryDate = document.getElementById('minDeliveryDate_'+dp.calendarID);
		if (minDeliveryDate != null && minDeliveryDate.value != null) {
			values = minDeliveryDate.value.split('/');
			if(values.length == 3) {
				dp.minDeliveryDay = Number(values[0]);
				dp.minDeliveryMonth = Number(values[1])-1;
				dp.minDeliveryYear = Number(values[2]);
			}
		}
		 
		// Pull the rest of the options from the alt attr
		if(dp.alt) {
			options = Json.evaluate(dp.alt);
		} else {
			options = [];
		}
		dp.options = {
			monthNames: (options.monthNames && options.monthNames.length == 12 ? options.monthNames : this.monthNames) || this.monthNames, 
			daysInMonth: (options.daysInMonth && options.daysInMonth.length == 12 ? options.daysInMonth : this.daysInMonth) || this.daysInMonth, 
			dayNames: (options.dayNames && options.dayNames.length == 7 ? options.dayNames : this.dayNames) || this.dayNames,
			startDay : options.startDay || this.startDay,
			dayChars : options.dayChars || this.dayChars, 
			format: options.format || this.format,
			yearStart: options.yearStart || this.yearStart,
			yearRange: options.yearRange || this.yearRange,
			yearOrder: options.yearOrder || this.yearOrder
		};
		dp.setProperties({'readonly':true});
		dp.container = false;
		dp.calendar = false;
		dp.interval = null;
		dp.active = false;
		this.dp = dp;
		var datePickerClass = this;

		datePickerRegistry[dp.id] = new Array();
		datePickerRegistry[dp.id]['self'] = dp;
		datePickerRegistry[dp.id]['event'] = dp.onclick = dp.onfocus = this.getDeliveryCalendarDates.pass(dp,this);
	},

	getDeliveryCalendarDates: function(dp)
	{
		this.$('Container_' + dp.get('rel')).empty();
		var url = dp.deliveryCalendarURL.value;
		var nextMonthUrl = url;
		
		// append 1 on url string at /ProductId=xxxxx1& for uk Courier Upgrade despatch
		if (dp.shippingMethodID == "ukCourierUpgrade")
		{	
			var url_string = url.split(/&/); 
			var url_0 = url_string[0] + "1&"; 
			var url_1 = url_string[1] + "&"; 
			var url_2 = url_string[2] + "&"; 
			var url_3 = url_string[3] + "&"; 
			var url_4 = url_string[4];
			
			url = url_0 + url_1 + url_2 + url_3 + url_4;
		}
		
		// append 2 on url string at /ProductId=xxxxx2& for same day despatch
		if (dp.shippingMethodID == "ukFloristSameDay")
		{	
			var url_string = url.split(/&/); 
			var url_0 = url_string[0] + "2&"; 
			var url_1 = url_string[1] + "&"; 
			var url_2 = url_string[2] + "&"; 
			var url_3 = url_string[3] + "&"; 
			var url_4 = url_string[4];
			
			url = url_0 + url_1 + url_2 + url_3 + url_4;
		}
		
		// append 3 on url string at /ProductId=xxxxx2& for same day despatch
		if (dp.shippingMethodID == "ukCourierXmas")
		{	
			var url_string = url.split(/&/); 
			var url_0 = url_string[0] + "3&"; 
			var url_1 = url_string[1] + "&"; 
			var url_2 = url_string[2] + "&"; 
			var url_3 = url_string[3] + "&"; 
			var url_4 = url_string[4];
			
			url = url_0 + url_1 + url_2 + url_3 + url_4;
		}
		
		nextMonthUrl = url;

		var month = parseInt(dp.month);
		url = url.replace("TheMonth",month+1);

		url = url.replace("TheYear",dp.year);
		
		if (month < 11) {
			nextMonthUrl = nextMonthUrl.replace("TheMonth",month+2);
			nextMonthUrl = nextMonthUrl.replace("TheYear",dp.year);
		}
		else {
			var nextMonthYear = parseInt(dp.year) + 1;
			nextMonthUrl = nextMonthUrl.replace("TheMonth",1);
			nextMonthUrl = nextMonthUrl.replace("TheYear",nextMonthYear);
		}
		
		var requestURLs = new Array();
		requestURLs.push(url);
		requestURLs.push(nextMonthUrl);
		
		this.request_urls = requestURLs;
		this.request_iterator = 0;
		this.makeRequests();
	},

	// AJAX part
 
	makeRequests: function()
	{
		var thisDp = this;
		if (thisDp.request_iterator < this.request_urls.length) {
			url = this.request_urls[thisDp.request_iterator];
			var myRequest = new Request({
				method: 'get',
				url: url,
				onSuccess: function(responseText, responseXML) {
					thisDp.http_response_text = responseText;
					thisDp.http_response_xml = responseXML;
					thisDp.readDeliveryDates();
					thisDp.request_iterator += 1;
					thisDp.makeRequests();
				},
				onFailure: function() {
					alert('There was a problem with the request.');
				}
			}).send();
		}
		else {
			// Create the instance of date picker
			this.create(this.dp);
		}
	},
 
    readDeliveryDates: function()
	{	
      	var responseText = this.http_response_text;
    	var responseXML = this.http_response_xml;
    	if (null == this.deliveryCalendarTypes) {
    		this.deliveryCalendarTypes = new Array();
    	}
    	if (null == this.deliveryCalendarBulkMessages) {
	  		this.deliveryCalendarBulkMessages = new Array();
    	}
        var xmldoc = responseXML;
        if (xmldoc == null || xmldoc.getElementsByTagName('deliveryCalendar').item(0) == null)
        {	
        	xmldoc = this.strToxml(responseText);
        }
        var root = xmldoc.getElementsByTagName('deliveryCalendar').item(0);
        for (var iNode = 0; iNode < root.childNodes.length; iNode++) 
        {
		   if (root.childNodes.item(iNode).tagName == "day")
		   {
               var day = root.childNodes.item(iNode);
			   var date = day.getAttribute('date');
			   var type = day.getAttribute('type');
			   var bulkMessage = day.getAttribute('bulkMessage');
			   this.deliveryCalendarTypes[date] = type;
			   this.deliveryCalendarBulkMessages[date] = bulkMessage;
		   }	   
        }
	},

	strToxml: function(str) 
	{ 
   		var xml = null; 
		if(window.ActiveXObject) 
		{ 
			xml = new ActiveXObject("Microsoft.XMLDOM"); 
			xml.loadXML(str); 
		} 
		else 
		{ 
			var parser = new DOMParser(); 
			xml = parser.parseFromString(str, "text/xml"); 
		} 
		return xml; 
	},
	
    // END AJAX part
	
	/* create the calendar */
	create: function(dp)
	{
		var thisDp = this;
		// Hide select boxes while calendar is up
		if (window.ie6) {
			//$$('select').addClass('dp_hide');
		}
		
		/* create the outer container */
		this.$('Container_' + dp.get('rel')).empty();
		dp.container = new Element('div', {'class':'dp_container','id':'dp_container'}).injectInside(this.$('Container_' + dp.get('rel')));
				
		/* create the calendar */
		dp.calendar = new Element('div', {'class':'dp_cal'}).injectInside(dp.container);
		dp.close = new Element('div', {'class':'dp_close','id':'dp_close'}).injectInside(dp.calendar);
		dp.closeLink = new Element('span', {'class':'dp_closeLink','id':'dp_closeLink'}).injectInside(dp.close);
		var newLinkText = document.createTextNode("close X");
		dp.closeLink.appendChild(newLinkText);
		
		/* onclick event for close button */
		dp.closeLink.onclick = function(){
			dp.interval = this.remove(dp);
		}.bind(this);
		
		/* onclick event for close button */
		dp.closeLink.onclick = function(){
			dp.interval = this.remove(dp);
		}.bind(this);
		
		/* create the date object */
		var date = new Date();
		
		/* create the date object */
		if (dp.month && dp.year) {
			date.setFullYear(dp.year, dp.month, 1);
		} else {
			dp.month = date.getMonth();
			dp.year = date.getFullYear();
			date.setDate(1);
		}
		dp.year % 4 == 0 ? dp.options.daysInMonth[1] = 29 : dp.options.daysInMonth[1] = 28;
		
		/* set the day to first of the month */
		var firstDay = (1-(7+date.getDay()-dp.options.startDay)%7);
		
		/* create the month select box */
		this.monthSel = new Element('select', {'id':dp.id + '_monthSelect'});
		for (var m = 0; m < dp.options.monthNames.length; m++){
			this.monthSel.options[m] = new Option(dp.options.monthNames[m], m);
			if (dp.month == m) this.monthSel.options[m].selected = true;
		}
		
		/* create the year select box */
		this.yearSel = new Element('select', {'id':dp.id + '_yearSelect'});
		i = 0;
		dp.options.yearStart ? dp.options.yearStart : dp.options.yearStart = date.getFullYear();
		if (dp.options.yearOrder == 'desc'){
			for (var y = dp.options.yearStart; y > (dp.options.yearStart - dp.options.yearRange - 1); y--){
				this.yearSel.options[i] = new Option(y, y);
				if (dp.year == y) this.yearSel.options[i].selected = true;
				i++;
			}
		} else {
			for (var y = dp.options.yearStart; y < (dp.options.yearStart + dp.options.yearRange + 1); y++){
				this.yearSel.options[i] = new Option(y, y);
				if (dp.year == y) this.yearSel.options[i].selected = true;
				i++;
			}
		}
		
		/* start creating calendar */
		this.calTable = new Element('table');
		this.calTableThead = new Element('thead');
		this.calSelRow = new Element('tr');
		this.calSelCell = new Element('th', {'colspan':'7'});
		this.monthSel.injectInside(this.calSelCell);
		this.yearSel.injectInside(this.calSelCell);
		this.calSelCell.injectInside(this.calSelRow);
		this.calSelRow.injectInside(this.calTableThead);
	  	this.dateSaver = new Array();
		
		if(document.getElementById('calendar_scroller').value=='true'){
			dp.prev = new Element('span', {'class':'dp_scroll','id':'dp_prev'});
			dp.current = new Element('span', {'class':'dp_current','id':'dp_current'});
			dp.next = new Element('span', {'class':'dp_scroll','id':'dp_next'});
			var newprevText = document.createTextNode("<");
			dp.prev.appendChild(newprevText);
			var newcurrentText = document.createTextNode(dp.options.monthNames[this.monthSel.selectedIndex]);
			dp.current.appendChild(newcurrentText);
			var newnextText = document.createTextNode(">");
			dp.next.appendChild(newnextText);
						
			calMonthScrollRow = new Element('tr');
			calMonthScrollCell1 = new Element('th');
			calMonthScrollCell2 = new Element('th', {'colspan':'5'});
			calMonthScrollCell3 = new Element('th');
			dp.prev.injectInside(calMonthScrollCell1);
			dp.current.injectInside(calMonthScrollCell2);
			dp.next.injectInside(calMonthScrollCell3);		
			calMonthScrollCell1.injectInside(calMonthScrollRow);
			calMonthScrollCell2.injectInside(calMonthScrollRow);
			calMonthScrollCell3.injectInside(calMonthScrollRow);
			calMonthScrollRow.injectInside(this.calTableThead);
		}
		
		this.calTableTbody = new Element('tbody');
		/* create day names */
		calDayNameRow = new Element('tr');
		for (var i = 0; i < dp.options.dayNames.length; i++) {
			calDayNameCell = new Element('th');
			calDayNameCell.appendText(dp.options.dayNames[(dp.options.startDay+i)%7].substr(0, dp.options.dayChars)); 
			calDayNameCell.injectInside(calDayNameRow);
		}
		calDayNameRow.injectInside(this.calTableTbody);
		
		/* create the day cells */
		var allDays = dp.options.daysInMonth[dp.month] + 8; // the selected month's days plus one week
		var newMonth = (parseInt(dp.month) + 1) == 12 ? 1 : parseInt(dp.month) + 2; // if this month is december, next is january
		var newMonthYear = newMonth == 1 ? parseInt(dp.year) + 1 : parseInt(dp.year); // if next month is january, this is next year
		var todayMarked = false; // if today's date was marked alread then don't mark it for the next month if in range

		while (firstDay <= allDays) {
			calDayRow = new Element('tr');
			for (i = 0; i < 7; i++) {
				
				var validateDay = 0;
				if ((firstDay <= dp.options.daysInMonth[dp.month]) && (firstDay > 0)){
				    var axis = dp.year + '|' + (parseInt(dp.month) + 1) + '|' + firstDay;
				    validateDay = firstDay;
					calDayCell = new Element('td', {'class':dp.id + '_calDay', 'axis':axis}).appendText(firstDay).injectInside(calDayRow);
				}
				// next month initial days made functional
				else if (firstDay > dp.options.daysInMonth[dp.month] && firstDay < allDays && firstDay > 0) {
					var newFirstDay = firstDay - dp.options.daysInMonth[dp.month]; // dates of next month
					var axis = newMonthYear + '|' + newMonth + '|' + newFirstDay;
				    validateDay = newFirstDay;
					calDayCell = new Element('td', {'class':dp.id + '_calDay', 'axis':axis}).appendText(newFirstDay).injectInside(calDayRow);
					calDayCell.addClass('dp_nextmonthweek');
				}
				else {
					validateDay = firstDay;
					calDayCell = new Element('td', {'class':'dp_empty'}).appendText(' ').injectInside(calDayRow);
				}
				// Show the previous day
				if ( (validateDay == dp.oldDay) && (dp.month == dp.oldMonth) && (dp.year == dp.oldYear)) {
					if(!calDayCell.hasClass('dp_nextmonthweek'))
						calDayCell.addClass('dp_selected');
					if(this.dateSaver[dp.calendarID] == null)
						this.dateSaver[dp.calendarID] = calDayCell;	
				}
				// Show the invalid days
				if ( this.isInvalid(dp, validateDay, axis) ) {
					calDayCell.addClass('dp_invalid');
				}
				// Show the bulk dates
				if ( this.isBulkDate(dp, validateDay, axis) ) {
					calDayCell.addClass('dp_bulk');
				}
				// Show today
				if ( (validateDay == dp.nowDay) && (dp.month == dp.nowMonth ) && (dp.year == dp.nowYear) && !todayMarked) {
					calDayCell.addClass('dp_today');
					todayMarked = true;
				}
			
				firstDay++;
			}
			calDayRow.injectInside(this.calTableTbody);
		}
		
		/* table into the calendar div */
		this.calTableThead.injectInside(this.calTable);
		this.calTableTbody.injectInside(this.calTable);
		this.calTable.injectInside(dp.calendar);
		
		//FFS-866 -month scroller must be displayed only for FFS
		if(dp.prev) {
		/* set the onclick event for the next month scroller */
			dp.prev.onclick = function(){
				if (this.monthSel.value > 0) {
					dp.month = this.monthSel.options[this.monthSel.selectedIndex-1].value;
					dp.year = this.yearSel.value;
				}
				if (this.monthSel.value == 0) {
					dp.month = 11;
					if (this.yearSel.options[this.yearSel.selectedIndex].value > dp.options.yearStart) {
						dp.year = this.yearSel.options[this.yearSel.selectedIndex-1].value;
					}
					else {
						return false;
					}
				}
				this.remove(dp);
				this.getDeliveryCalendarDates(dp);
			}.bind(this);
		
		/* set the onclick event for the next month scroller */
			dp.next.onclick = function(){
				if(this.monthSel.value<11){
				dp.month = this.monthSel.options[this.monthSel.selectedIndex+1].value;
				dp.year = this.yearSel.value;
				}
				if(this.monthSel.value==11){
				dp.month = this.monthSel.options[0].value;
				dp.year = this.yearSel.options[this.yearSel.selectedIndex+1].value;
				}
				
				this.remove(dp);
				this.getDeliveryCalendarDates(dp);
			}.bind(this);
		}
				
		/* set the onmouseover events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
		if ( !this.isInvalid(dp, Number(el.innerHTML), el.axis) ) {
			el.onmouseover = function(){
				el.addClass('dp_roll');
			}.bind(this);
		}
		}.bind(this));
		
		/* set the onmouseout events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onmouseout = function(){
				el.removeClass('dp_roll');
			}.bind(this);
		}.bind(this));
		
		previousDayToRemove = null;
		/* set the onclick events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			previousCalendar = dp.calendarID;
			var x = null;
			el.onclick = function(){
				if ( !this.isInvalid(dp, Number(el.innerHTML), el.axis) ) {
					ds = el.axis.split('|');
					//FFS-866
					if(document.getElementById('display_bulk').value=='true'){
						if(thisDp.deliveryCalendarTypes[el.axis]=='bulk'){
							document.getElementById('bulkMessage_'+dp.calendarID).value=thisDp.deliveryCalendarBulkMessages[el.axis];}
						else {
							document.getElementById('bulkMessage_'+dp.calendarID).value='1';
						}
						var bulkDate=document.getElementById('bulkMessage_'+dp.calendarID).value;
					
						if (null == this.calendarLastDate) {
					  		this.calendarLastDate = new Array();
				    	}
						
						//BEGIN highlight the right date that is chosen
						
						if(previousCalendar != dp.calendarID){
							previousDayToRemove = this.calendarLastDate[dp.calendarID];
							previousCalendar = dp.calendarID;
						}
						if(previousCalendar == dp.calendarID){
							if(previousDayToRemove != el){
								if(previousDayToRemove != null){
									previousDayToRemove.removeClass('dp_selected');
								}
								
								previousDayToRemove = el;
							}							
							
							previousCalendar = dp.calendarID;
						}
						
						this.calendarLastDate[dp.calendarID] = el;
						if(this.dateSaver[dp.calendarID]!= null && this.dateSaver[dp.calendarID].hasClass('dp_selected')){
							this.dateSaver[dp.calendarID].removeClass('dp_selected');
						}

						el.addClass('dp_selected');
						
						//END highlight the right date that is chosen
						
						//AJAX call
						var url1=document.getElementById('url_delivery').value;
						query1 = 'tid='+bulkDate+'&sid='+dp.shippingMethodID+'&oid='+dp.calendarID;
						var element = 'testAjax_'+dp.calendarID;
						//var ajax = new Ajax(url1, {method: 'get', data: query1, update:element}).request();
                        var ajax = new Request({
                            url: url1,
                            method: 'get',
                            data: query1,
                            update: element
                        }).send();
					
						//AJAX call
						document.getElementById('testAjax_'+dp.calendarID).style.visibility="visible";
						document.getElementById('testAjax_'+dp.calendarID).focus();
//						document.getElementById('datePicker_'+dp.calendarID+'_monthSelect').style.visibility = "hidden";
//						document.getElementById('datePicker_'+dp.calendarID+'_yearSelect').style.visibility = "hidden";
					}
					//FFS-866
					dp.value = this.formatValue(dp, ds[0], ds[1], ds[2]);
					//this.remove(dp);
				}
			}.bind(this);
		}.bind(this));
		
		/* set the onchange event for the month & year select boxes */
		this.monthSel.onfocus = function(){ dp.active = true; };
		this.monthSel.onchange = function(){
			dp.month = this.monthSel.value;
			dp.year = this.yearSel.value;
			this.remove(dp);
			this.getDeliveryCalendarDates(dp);
		}.bind(this);
		
		this.yearSel.onfocus = function(){ dp.active = true; };
		this.yearSel.onchange = function(){
			dp.month = this.monthSel.value;
			dp.year = this.yearSel.value;
			this.remove(dp);
			this.getDeliveryCalendarDates(dp);
		}.bind(this);
	},
	
	/* Format the returning date value according to the selected formation */
	formatValue: function(dp, year, month, day){
		/* setup the date string variable */
		var dateStr = '';
		
		/* check the length of day */
		if (day < 10) day = '0' + day;
		if (month < 10) month = '0' + month;
		
		/* check the format & replace parts // thanks O'Rey */
		dateStr = dp.options.format.replace( /dd/i, day ).replace( /mm/i, month ).replace( /yyyy/i, year );
		dp.month = dp.oldMonth = '' + (month - 1) + '';
		dp.year = dp.oldYear = year;
		dp.oldDay = day;
		
		/* return the date string value */
		return dateStr;
	},
	
	/* Remove the calendar from the page */
	remove: function(dp){
		$clear(dp.interval);
		dp.active = false;
		if (window.opera) dp.container.empty();
		else if (dp.container) dp.container.dispose();
		dp.calendar = false;
		dp.container = false;
		$$('select.dp_hide').removeClass('dp_hide');
	},

	/* checks if the passed day is a weekday */
	isWeekday: function(dp, day){
		var date = new Date (dp.year, dp.month, day);
		if (date.getDay() > 0 && date.getDay() < 6) return true;
		return false;
	},

	/* checks if the passed day is a saturday */
	isSaturday: function(dp, day){
		var date = new Date (dp.year, dp.month, day);
		if (date.getDay() == 6) return true;
		return false;
	},

	/* checks if the passed day is a saturday */
	isSunday: function(dp, day){
		var date = new Date (dp.year, dp.month, day);
		if (date.getDay() == 0) return true;
		return false;
	},

	/* checks, if it is a bulk date */
	isBulkDate: function(dp, day, axis){
		if (this.deliveryCalendarTypes[axis] == "bulk")
		   return true;
		else
		   return false;
	},
	/* checks if the passed day has to be disabled */
	isInvalid: function(dp, day, axis) 
	{
		if (this.deliveryCalendarTypes[axis] == "unavail")
		   return true;
		if (this.deliveryCalendarTypes[axis] == "avail")
		   return false;
		if (this.deliveryCalendarTypes[axis] == "bulk")
		   return false;
		if ( dp.namedDay != null && dp.namedDay.value.length > 0 ) {
			if ( (dp.year < dp.minDeliveryYear) ||
				 (dp.year == dp.minDeliveryYear && dp.month < dp.minDeliveryMonth) ||
				 (dp.year == dp.minDeliveryYear && dp.month == dp.minDeliveryMonth && day < dp.minDeliveryDay) ||
				 (dp.namedDay.value == 'saturday' && !this.isSaturday(dp, day)) ||
				 (dp.namedDay.value == 'weekday' && !this.isWeekday(dp, day)) ||
				 (dp.namedDay.value == 'weekdaySaturday' && this.isSunday(dp, day)) ) {
				return true;
			}
		}
		if (dp.holidays != null) {
			for (var i=0; i<dp.holidays.length; i++) {
				var dayStr = dp.holidays[i].value.split("/");
				if (day == Number(dayStr[0]) && Number(dp.month)+1 == Number(dayStr[1]) && Number(dp.year) == Number(dayStr[2])) {
					return true;
				}
			}
		}

		return false;
	}

});
