function sendData(url, data, success, type, error)
{
    if (success == undefined)
    {
        success = ajaxSuccess;
    }

    url = ajaxAppend(url);

    var page = $("#paging").html();

    if(page != "")
        url += "/page/"+page+"/";



    switch (type) {
        case 'json' :
        case 'script' :
        case 'xml' :
        case 'text' :
            break;
        default :
            type = "json";
            break;
    }


    $.ajax({
        url       : url,
        dataType  : type,
        data      : data,
        cache     : false,
        type      : 'post',
        success   : function(responce)
        {
            ajaxResponce(responce, success , error)
        },
        error : function(jqXHR, textStatus, errorThrown){
            alert(textStatus);
        }

    });
}

function ajaxAppend(url)
{
    url += '/is_ajax/1';

    return url;
}
function ajaxResponce(responce, success , error)
{


    if(responce.result == 'redirect')
    {
        window.location.href = responce.content;
        return;
    }
    if(responce.result == 'error' && !error)
    {
        alert(responce.messages);
        closePopup();
        return;
    }
    if( $.isFunction(success) )
    {
        success(responce);
    }
}

function trim(sInString)
{

    sInString = sInString.replace(/ /g,' ');

    return sInString.replace(/(^\s+)|(\s+$)/g, "");

}

function closePopup()
{
    this.parent.jQuery.fancybox.close();
}
