var AccountSystem = { findByFullName: function(name) { var url = "http://timfalken.com/account/?action=find&query=" + name; this.getJSON(url, function(status, response) { context = context || this; callback && callback.call(this, response); }) }, loadUserImage: function(user, callback, context) { var avatarImage = new image(user.avatar + ".png"); avatarImage.g_image.addEventListener('load', function() { context = context || this; callback && callback.call(this, avatarImage); }); avatarImage.g_image.addEventListener("error", function(error) { console.error(error) }); }, login: function(email, password, callback, context) { var url = "http://timfalken.com/account/?action=login&email=" + email + "&password=" + btoa(password); this.getJSON(url, function(status, response) { context = context || this; callback && callback.call(this, response); }) }, register: function(name, email, password, callback, context) { var url = "http://timfalken.com/account/?action=register&username=" + name + "&email=" + email + "&password=" + btoa(password); this.getJSON(url, function(status, response) { context = context || this; callback && callback.call(this, response); }) }, setData: function(email, password, data, callback, context) { var url = "http://timfalken.com/account/?action=updatedata&key=emVybzIxMTI=&email=" + email + "&password=" + btoa(password) + "&newdata=" + btoa(JSON.stringify(data)); this.getJSON(url, function(status, response) { context = context || this; callback && callback.call(this, response); }) }, getJSON: function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'json'; xhr.onload = function() { var status = xhr.status; if (status === 200) { callback(null, xhr.response); } else { callback(status, xhr.response); } }; xhr.send(); } }