optimized datepick js code.