Edit calendar form  javascript refactored