Javascript Not A Function When It Is Defined