Javascript Reference Error Variable Is Not In Scope