Changed javascript variable scope to Global