Implementing isLoaded JavaScript function