//function to add days to a given date.
var returnDate = new Date(
This keeps things simple and makes for fairly reliable and readable code. By creating the date this way, the month and year adjust themselves based on the day of the month used. Thus if it is a negative number it will go to previous months and potentially years and the inverse for larger positive numbers.