function restrictedDates(checkDate)
{
	var checkRestrictDate = (checkDate.getMonth()+1) + '/' + checkDate.getDate() + '/' + checkDate.getFullYear();

	for (x in restrictedDateArray)
	{
		if (restrictedDateArray[x] == checkRestrictDate)
			return true;
	}
	
	return false;
}

function restrictedDateName(checkDate)
{
	var checkRestrictDate = (checkDate.getMonth()+1) + '/' + checkDate.getDate() + '/' + checkDate.getFullYear();

	for (x in restrictedDateArray)
	{
		if (restrictedDateArray[x] == checkRestrictDate)
			return restrictedDateNameArray[x];
			//return true;
	}
	
	return '';
}

function restrictedDateComment(checkDate)
{
	var checkRestrictDate = (checkDate.getMonth()+1) + '/' + checkDate.getDate() + '/' + checkDate.getFullYear();

	for (x in restrictedDateArray)
	{
		if (restrictedDateArray[x] == checkRestrictDate)
			return restrictedDateCommentArray[x];
			//return true;
	}
	
	return '';
}

$(function()
{
	$('.date-pick')
		.datePicker(
			{
				createButton:true,
				renderCallback:function($td, thisDate, month, year)
				{
					if (restrictedDates(thisDate))
					{
						$td.addClass('weekend');
						$td.css('backgroundColor','red');
					}

					else if (thisDate.isWeekend()) {
						$td.addClass('weekend');
					}
					else {
						
					}
					
					
				}
			}
		)
		.bind('click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
		.bind('dateSelected',
			function(e, selectedDate, $td)
			{
				if (restrictedDates(selectedDate))
				{
					$(this).css('backgroundColor','red');
					$(this).val('Invalid Date');
					alert(restrictedDateName(selectedDate) + '\n' + restrictedDateComment(selectedDate));
					//alert(restrictedDateName(selectedDate));
				}
				else
				{
					$(this).css('backgroundColor','');
					
					console.log('You selected ' + selectedDate);
					document.chooseDateForm.submit();
				}
			}
			
		);
});
