/**
 * jQuery.spModal - A Modal Window System.
 *
 * This plugin requires: 
 *      1. jQuery >= 2.1.3
 *      2. jQuery.ui >= 1.11.4
 *
 * @author    Gonzalo Chumillas <gchumillas@email.com>
 * @license   https://github.com/soloproyectos/jquery.modal/blob/master/LICENSE MIT License
 * @link      https://github.com/soloproyectos/jquery.modal
 */
(function ($) {
    /**
     * Sends an HTTP request.
     * 
     * @param {String} method Request method. Can be either 'get' or 'post'
     * @param {String} url    URL
     * @param {Object} data   Parameters (not required)
     * @param {String} type   Expected document type (not required)
     */
    $.spModalRequest = function (method, url, data, type) {
        if ($.inArray(method, ['get', 'post']) < 0) {
            $.error('Method not allowed: ' + method);
        }
        
        this._method = method;
        this._args = Array.prototype.slice.call(arguments, 1);
        this._url = url;
        this._data = data;
        this._type = type;
    };
    
    /**
     * Reqest method.
     * This method can be either 'get' or 'post'
     * @var {String}
     */
    $.spModalRequest.prototype._method = null;
    
    /**
     * URL.
     * @var {String}
     */
    $.spModalRequest.prototype._url = "";
    
    /**
     * Parametes.
     * @var {Object}
     */
    $.spModalRequest.prototype._data = {};
    
    /**
     * Expected document type.
     * @var {String}
     */
    $.spModalRequest.prototype._type = "";
    
    /**
     * Sends an HTTP request.
     * 
     * @return {jQuery.Promise}
     */
    $.spModalRequest.prototype.send = function () {
        var ret = new $.Deferred();
        var req = null;

        var loading = new $.spModalLoading();
        loading.addButton('Cancel', function () {
            if (req != null) {
                req.abort();
            }
        });

        // sends a request
        req = $[this._method].call(
            this, this._url, this._data, function () {}, this._type
        ).always(function () {
            loading.close();
        }).done(function (data, status, xhr) {
            ret.resolve(data, status, xhr);
        }).fail(function (xhr, status) {
            var message = $.type(xhr.responseText) == 'string' && xhr.responseText.length > 0
                ? xhr.responseText
                : 'The request has failed';
            var title = $.type(xhr.statusText) == 'string' && xhr.statusText.length > 0
                ? xhr.statusText
                : 'HTTP Request Error';
            
            // document type not expected or malformed
            if (status == 'parsererror') {
                title = 'The document is not well formed';
            }
            
            $.spModal('error', title, message, function () {
                // aligns the text to the left if there are more than two lines
                var count = (message.match(/\n/g) || []).length;
                console.log(count);
                if (count > 1) {
                    this.setTextAlign('left');
                }
            });
        });

        return ret.promise();
    };
})(jQuery);

@@ -2217,162 +2217,109 @@
 var 
-message = $.type(xhr.responseText) == 'string' && xhr.responseText.length %3E 0%0A                ? xhr.responseText%0A                : 'The request has failed
+errorCode = parseInt(xhr.status, 10);%0A            var title = errorCode %3C 500? 'Error': 'Server Error
 ';%0A 
@@ -2329,28 +2329,30 @@
         var 
-titl
+messag
 e = $.type(x
@@ -2463,26 +2463,30 @@
  : '
-HTTP R
+The r
 equest 
-Error
+has failed
 ';%0A 
@@ -2618,16 +2618,51 @@
  title =
+ 'Error';%0A                message =
  'The do

improve error message