Change PHP functions to JS