organizing javascript to comply with security rules & making button clicks work