'use strict'; (function (w) { var darx = {}; darx.addEvent = function (elem, event, fn) { if (elem.addEventListener) { elem.addEventListener(event, fn, false); } else { elem.attachEvent('on' + event, function () { return (fn.call(elem, window.event)); }); } }; darx.fireEvent = function (elem, event) { var evt = elem.createEvent('Event'); evt.initEvent(event, true, true); elem.dispatchEvent(evt); }; darx.get = function (url, data, callback) { sendRequest('GET', url, data, callback); }; darx.post = function (url, data, callback) { sendRequest('POST', url, data, callback); }; darx.getJSON = function (url, data, callback) { var callbackName = 'darx_jsonp_' + Math.round(1000000000 * Math.random()); window[callbackName] = function(data) { delete window[callbackName]; document.body.removeChild(script); callback(data); }; var script = document.createElement('script'); script.type = "text/javascript"; script.async = true; data.callback = callbackName; script.src = url + '?' + http_build_query(data); document.body.appendChild(script); }; var http_build_query = function (data) { var params = []; var type; for (var key in data){ if (data.hasOwnProperty(key)) { type = Object.prototype.toString.call(data[key]); if (type === '[object Array]' || type === '[object Object]') { for (var i in data[key]) { if (data[key].hasOwnProperty(i)) { params.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(data[key][i])); } } } else { params.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key])); } } } return params.join('&'); }; var sendRequest = function (method, url, data, callback) { var xhr = false; var XMLHttpFactories = [ function () {return new XMLHttpRequest()}, function () {return new ActiveXObject("Msxml2.XMLHTTP")}, function () {return new ActiveXObject("Msxml3.XMLHTTP")}, function () {return new ActiveXObject("Microsoft.XMLHTTP")} ]; for (var i=0; i