PHP to Javascript conversion