improving popup, moving stuff from php to js