I have got some strange behavior from a script.

I am making myself a personal diary script that is a calendar and so far all is going well except for the months aspect of the script. The interface will eventually be linked to a database, that however is a long way off until I get the front end behaving itself, I can't progress.

First off I have to describe the problem...

I have four buttons, 1 set (two of the four) for advancing and regressing the years, works perfectly fine, not a problem with that.

The second set of buttons is for the months. The calendar is designed to start from the current month, so the page loads, in this instance the month being October shows up and when I click the advance month button, it moves to November, December then instead of rolling over in to January and advancing the year, it goes back to October but in the next year...

Going in the opposite direction, similar happens, instead of December and the year regressing when January is reached, it goes back to October but the year will be October of the previous year.

I figure its a case of can't see the wood for the trees, so here is the actual logic part of the of the script.

Code:
function buttonClick(o){
	
    switch(o.value){
        // year down
        case "previous year": y--;	break;
        // year up	
        case "next year": y++;	break;
        // month down	
        case "previous month": m = (m>=0)? m-1:11; y = (m==0)? y-1 : y;	break;
        // month up 
        case "next month": m = (m<=11)? m+1:0; y = (m==0)? y+1 : y;	break;
	
    }

}
The year buttons and month buttons are attached to the script button click and as soon as a change is made, the display up dates.

Now...
Code:
// year down
    case "previous year": y--;	break;
    // year up	
    case "next year": y++;	break;
works just fine and dandy... the problem is in this this part
Code:
// month down	
    case "previous month": m = (m>=0)? m-1:11; y = (m==0)? y-1 : y;	break;
    // month up 
    case "next month": m = (m<=11)? m+1:0; y = (m==0)? y+1 : y;	break;
Any ideas...