text: // Global Ajax Setup
  var globalAjaxOptions = {};
  $.ajaxSetup = function (options) {
      if (options.type) options.method = options.type;
      for (var option in options) {
          globalAjaxOptions[option]  = options[option];
      }
  };
  
  // Ajax
  var _jsonpRequests = 0;
  $.ajax = function (options) {
      var defaults = {
          method: 'GET',
          data: false,
          async: true,
          cache: true,
          user: '',
          password: '',
          headers: {},
          xhrFields: {},
          statusCode: {},
          processData: true,
          dataType: 'text',
          contentType: 'application/x-www-form-urlencoded',
          timeout: 0
      };
      var callbacks = ['beforeSend', 'error', 'complete', 'success', 'statusCode'];
  
      //For jQuery guys
      if (options.type) options.method = options.type;
  
      // Merge global and defaults
      for (var globalOption in globalAjaxOptions) {
          if (callbacks.indexOf(globalOption) < 0) defaults[globalOption] = globalAjaxOptions[globalOption];
      }
      // Global callbacks
      function globalAjaxCallback(callback) {
          if (callback in globalAjaxOptions) globalAjaxOptions[callback](arguments[1], arguments[2], arguments[3], arguments[4]);
      }
  
      // Merge options and defaults
      for (var prop in defaults) {
          if (!(prop in options)) options[prop] = defaults[prop];
      }
  
      // Default URL
      if (!options.url) {
          options.url = window.location.toString();
      }
      // UC method
      var _method = options.method.toUpperCase();
      // Data to modify GET URL
      if ((_method === 'GET' || _method === 'HEAD') && options.data) {
          var stringData;
          if (typeof options.data === 'string') {
              // Should be key=value string
              if (options.data.indexOf('?') >= 0) stringData = options.data.split('?')[1];
              else stringData = options.data;
          }
          else {
              // Should be key=value object
              stringData = $.serializeObject(options.data);
          }
          if (options.url.indexOf('?') >= 0) options.url += '&' + stringData;
          else options.url += '?' + stringData;
      }
      // JSONP
      if (options.dataType === 'json' && options.url.indexOf('callback=') >= 0) {
          
          var callbackName = 'f7jsonp_' + Date.now() + (_jsonpRequests++);
          var requestUrl, abortTimeout;
          var callbackSplit = options.url.split('callback=');
          if (callbackSplit[1].indexOf('&') >= 0) {
              var addVars = callbackSplit[1].split('&').filter(function (el) { return el.indexOf('=') > 0; }).join('&');
              requestUrl = callbackSplit[0] + 'callback=' + callbackName + (addVars.length > 0 ? '&' + addVars : '');
          }
          else {
              requestUrl = callbackSplit[0] + 'callback=' + callbackName;
          }
  
          // Create script
          var script = document.createElement('script');
          script.type = 'text/javascript';
          script.onerror = function() {
              clearTimeout(abortTimeout);
              globalAjaxCallback('error', null, 'scripterror');
              if (options.error) options.error();
          };
          script.src = requestUrl;
  
          // Handler
          window[callbackName] = function (data) {
              clearTimeout(abortTimeout);
              globalAjaxCallback('success', data);
              if (options.success) options.success(data);
              script.parentNode.removeChild(script);
              script = null;
              delete window[callbackName];
          };
          document.querySelector('head').appendChild(script);
  
          if (options.timeout > 0) {
              abortTimeout = setTimeout(function () {
                  script.parentNode.removeChild(script);
                  script = null;
                  globalAjaxCallback('error', null, 'timeout');
                  if (options.error) options.error(null, 'timeout');
              }, options.timeout);
          }
  
          return;
      }
  
      // Cache for GET/HEAD requests
      if (_method === 'GET' || _method === 'HEAD') {
          if (options.cache === false) options.url += ('_nocache=' + Date.now());
      }
  
      // Create XHR
      var xhr = new XMLHttpRequest();
  
      // Save Request URL
      xhr.requestUrl = options.url;
  
      // Open XHR
      xhr.open(_method, options.url, options.async, options.user, options.password);
  
      // Create POST Data
      var postData = null;
      
      if ((_method === 'POST' || _method === 'PUT') && options.data) {
          if (options.processData) {
              var postDataInstances = [ArrayBuffer, Blob, Document, FormData];
              // Post Data
              if (postDataInstances.indexOf(options.data.constructor) >= 0) {
                  postData = options.data;
              }
              else {
                  // POST Headers
                  var boundary = '---------------------------' + Date.now().toString(16);
  
                  if (options.contentType === 'multipart\/form-data') {
                      xhr.setRequestHeader('Content-Type', 'multipart\/form-data; boundary=' + boundary);
                  }
                  else {
                      xhr.setRequestHeader('Content-Type', options.contentType);
                  }
                  postData = '';
                  var _data = $.serializeObject(options.data);
                  if (options.contentType === 'multipart\/form-data') {
                      boundary = '---------------------------' + Date.now().toString(16);
                      _data = _data.split('&');
                      var _newData = [];
                      for (var i = 0; i < _data.length; i++) {
                          _newData.push('Content-Disposition: form-data; name="' + _data[i].split('=')[0] + '"\r\n\r\n' + _data[i].split('=')[1] + '\r\n');
                      }
                      postData = '--' + boundary + '\r\n' + _newData.join('--' + boundary + '\r\n') + '--' + boundary + '--\r\n';
                  }
                  else {
                      postData = options.contentType === 'application/x-www-form-urlencoded' ? _data : _data.replace(/&/g, '\r\n');
                  }
              }
          }
          else {
              postData = options.data;
          }
              
      }
  
      // Additional headers
      if (options.headers) {
          for (var header in options.headers) {
              xhr.setRequestHeader(header, options.headers[header]);
          }
      }
  
      // Check for crossDomain
      if (typeof options.crossDomain === 'undefined') {
          options.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(options.url) && RegExp.$2 !== window.location.host;
      }
  
      if (!options.crossDomain) {
          xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
      }
  
      if (options.xhrFields) {
          for (var field in options.xhrFields) {
              xhr[field] = options.xhrFields[field];
          }
      }
  
      var xhrTimeout;
      // Handle XHR
      xhr.onload = function (e) {
          if (xhrTimeout) clearTimeout(xhrTimeout);
          if (xhr.status === 200 || xhr.status === 0) {
              var isSuccess, responseData;
              if (options.dataType === 'json') {
                  try {
                      responseData = JSON.parse(xhr.responseText);
                      $(document).trigger('ajaxSuccess', {xhr: xhr});
                      globalAjaxCallback('success', responseData, xhr.status, xhr);
                      if (options.success) {
                          options.success(responseData, xhr.status, xhr);
                      }
                  }
                  catch (e) {
                      $(document).trigger('ajaxError', {xhr: xhr, parseerror: true});
                      globalAjaxCallback('error', xhr, 'parseerror');
                      if (options.error) options.error(xhr, 'parseerror');
                  }
              }
              else {
                  $(document).trigger('ajaxSuccess', {xhr: xhr});
                  globalAjaxCallback('success', responseData, xhr.status, xhr);
                  if (options.success) {
                      responseData = xhr.responseText;
                      options.success(responseData, xhr.status, xhr);
                  }
              }
          }
          else {
              $(document).trigger('ajaxError', {xhr: xhr});
              globalAjaxCallback('error', xhr, xhr.status);
              if (options.error) options.error(xhr, xhr.status);
          }
          if (options.statusCode) {
              if (globalAjaxOptions.statusCode && globalAjaxOptions.statusCode[xhr.status]) globalAjaxOptions.statusCode[xhr.status](xhr);
              if (options.statusCode[xhr.status]) options.statusCode[xhr.status](xhr);
          }
          $(document).trigger('ajaxComplete', {xhr: xhr});
          globalAjaxCallback('complete', xhr, xhr.status);
          if (options.complete) {
              options.complete(xhr, xhr.status);
          }
      };
      
      xhr.onerror = function (e) {
          if (xhrTimeout) clearTimeout(xhrTimeout);
          $(document).trigger('ajaxError', {xhr: xhr});
          globalAjaxCallback('error', xhr, xhr.status);
          if (options.error) options.error(xhr, xhr.status);
      };
  
      // Ajax start callback
      $(document).trigger('ajaxStart', {xhr: xhr});
      globalAjaxCallback('start', xhr);
      globalAjaxCallback('beforeSend', xhr);
      if (options.start) options.start(xhr);
      if (options.beforeSend) options.beforeSend(xhr);
  
      // Send XHR
      xhr.send(postData);
  
      // Timeout
      if (options.timeout > 0) {
          xhrTimeout = setTimeout(function () {
              xhr.abort();
              $(document).trigger('ajaxError', {xhr: xhr, timeout: true});
              $(document).trigger('ajaxComplete', {xhr: xhr, timeout: true});
              globalAjaxCallback('error', xhr, 'timeout');
              globalAjaxCallback('complete', xhr, 'timeout');
              if (options.complete) options.complete(xhr, 'timeout');
              if (options.error) options.error(xhr, 'timeout');
          }, options.timeout);
      }
  
      // Return XHR object
      return xhr;
  };
  // Shrotcuts
  (function () {
      var methods = ('get post getJSON').split(' ');
      function createMethod(method) {
          $[method] = function (url, data, success) {
              return $.ajax({
                  url: url,
                  method: method === 'post' ? 'POST' : 'GET',
                  data: typeof data === 'function' ? undefined : data,
                  success: typeof data === 'function' ? data : success,
                  dataType: method === 'getJSON' ? 'json' : undefined
              });
          };
      }
      for (var i = 0; i < methods.length; i++) {
          createMethod(methods[i]);
      }
  })();