The problem is here:
var Date = new Date(dDate); // JAVASCRIPT ERROR HERE...
You've hidden the global "Date" constructor with your local variable. Change your variable name to something else and it should work better.
In a JavaScript function, all var
declarations from the body of the function "happen" as if they were all at the top. The assignment part of the declaration happens at the point in the code where the declaration is actually found, but the declaration — the addition of the named variable to the function scope, in other words — happens at the top. Thus, when you try to call the "Date" constructor on the right-hand side of the initialization, you're trying to use the value of your "Date" variable, which is undefined
at that point.
Also, your .replace()
calls are backwards, and you don't need two:
dDate = dDate.replace(/\//g, '-');
Some browsers don't need that (Firefox is OK with the slashes).
edit — oh, and getting a date that's one day after a given date is easy:
var nextDay = new Date( someDate.getTime() );
nextDay.setDate( nextDay.getDate() + 1 );