Help with calendar date disabling

Hey all i have this piece of code before that disables the given dates i put into an array. This works great for day 2-30 (out of a 31 day month) but it does not seem to work when i select either day 1 or day 31.

For day 1 it blocks out day 1 and i do not want that. The user should be able to select that day since it was selected. It does not do this for any other day. If the user selects day 2 then day 2 is selected on the calender and is not blocked.

As for day 31, i don’t know whats wrong with it because it never shows me an error. It’s the type of error that shuts down the website with “System Unavailable” for about a minute before i can connect to the page again.

Here is my code:


var disabledDays = ['3-31-2010','3-30-2010','3-29-2010','3-28-2010','3-27-2010','3-26-2010','3-25-2010','3-24-2010','3-23-2010','3-22-2010','3-21-2010','3-20-2010','3-19-2010','3-18-2010','3-17-2010','3-16-2010','3-15-2010','3-14-2010','3-13-2010','3-12-2010','3-11-2010','3-10-2010','3-9-2010','3-8-2010','3-7-2010','3-6-2010','3-05-2010'];
 
	function nationalDays(date) {
	var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();

	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
				
	for (i = 0; i < disabledDays.length; i++) {
		if(ArrayContains(disabledDays,(m+1) + '-' + d + '-' + y) || new Date() > date) {
			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
			return [false];
		}
	}
		//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
		return [true];
	}
		
	function noWeekendsOrHolidays(date) {
		return nationalDays(date);
	}
 
	function ArrayIndexOf(array,item,from){
	var len = array.length;

	for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
		if (array[i] === item) return i;
	}
		return -1;
	}
			
	function ArrayContains(array,item,from){
		return ArrayIndexOf(array,item,from) != -1;
	}

Any help would be great! :slight_smile:

David

What test HTML code would you use for a sample calendar?

I ask this so that we can simulate your situation, so that our solution will most easily work in your own situation.

I have a page where i have the test site on. Maybe that will allow you to make a better judgement call about my profile?

http://www.nextbowluser.com/cal/final/basic-views.html

Set your date on your pc to march 1st so you know what i am talking about once you click on the day 1.

David

Thank you for that. It will make it all the easier for someone to help you with this.

I am not in a position to make that sort of change to my system, so hopefully someone else will be able to help.

If it any consolation, it doesn’t appear that the code you posted is responsible for the issue at hand.

You may though, want to use the more official compatibility code for Array.indexOf


if (!Array.prototype.indexOf)  
{  
  Array.prototype.indexOf = function(elt /*, from*/)  
  {  
    var len = this.length >>> 0;  
  
    var from = Number(arguments[1]) || 0;  
    from = (from < 0)  
         ? Math.ceil(from)  
         : Math.floor(from);  
    if (from < 0)  
      from += len;  
  
    for (; from < len; from++)  
    {  
      if (from in this &&  
          this[from] === elt)  
        return from;  
    }  
    return -1;  
  };  
}