On the $(document).ready call change:
var d = new Date(element.name);
to var d = Date.parse(element.name);
This will solve the "undefined NaN, NaN:aN PM" issue.