function getUniqueArray(array) 
{
    var uniqueArray = [];

    array.forEach(function (arrayValue) {
        arrayValue = arrayValue.trim();

        if (arrayValue !== "" && uniqueArray.indexOf(arrayValue) === -1) {
            uniqueArray.push(arrayValue);
        }
    });

    return uniqueArray;
}

function getUrlsInformation(urls, ajaxUrl, urlsTable, processFunction)
{
    if(typeof urls !== "undefined" && urls.length > 0) {
        var currentUrl = encodeURIComponent(urls[0]);
        jQuery.ajax({
            url: ajaxUrl, 
            dataType: "json",
            method: "get",
            data: {
                url: currentUrl
            },
            success: function (data) {
                if (typeof(processFunction) === 'function') {
                    processFunction(data, urls, ajaxUrl, urlsTable);
                }
            }
        });
    }
}

var processResponse = function processUrlResponse(urlData, urls, ajaxUrl, urlsTable)
{
    if (typeof(urlData) !== 'object' || typeof(urlData.status) == 'undefined') {
        return false;
    }

    var tableBody = urlsTable.find('tbody');
    var tableRow = jQuery(document.createElement('tr')).appendTo(tableBody);
    if (urlData.status !== 'success') {
        jQuery(document.createElement('td')).html(urlData.url).appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
    } else {
        jQuery(document.createElement('td')).html(urlData.url).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.statusCode).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.redirectsNumber).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.finalUri).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.finalStatusCode).appendTo(tableRow); 
    }
    urls.splice(0, 1);
    getUrlsInformation(urls, ajaxUrl, urlsTable, processResponse);
}

var processInfo = function processUrlInfo(urlData, urls, ajaxUrl, urlsTable)
{
    if (typeof(urlData) !== 'object' || typeof(urlData.status) == 'undefined') {
        return false;
    }

    var tableBody = urlsTable.find('tbody');
    var tableRow = jQuery(document.createElement('tr')).appendTo(tableBody);
    if (urlData.status !== 'success') {
        jQuery(document.createElement('td')).html(urlData.url).appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
        jQuery(document.createElement('td')).html('-').appendTo(tableRow); 
    } else {
        jQuery(document.createElement('td')).html(urlData.url).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.title.join('|<br/>')).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.h1.join('|<br/>')).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.description.join('|<br/>')).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.keywords.join('|<br/>')).appendTo(tableRow); 
        jQuery(document.createElement('td')).html(urlData.canonical.join('|<br/>')).appendTo(tableRow); 

    }
    urls.splice(0, 1);
    getUrlsInformation(urls, ajaxUrl, urlsTable, processInfo);
}

jQuery(document).ready(function () {
    jQuery('.js-check-form').click(function (event) {
        event.preventDefault();
        var urlsTextarea = jQuery(this).parents('.js-form-container').find('.js-form-area');
        var urls = urlsTextarea.val().split("\n");

        urls = getUniqueArray(urls);
        urlsTextarea.val(urls.join("\n"));
    });

    jQuery('.js-clear-form').click(function (event) {
        event.preventDefault();
        var urlsTable = jQuery(this).parents('.js-form-container').find('.js-form-table');
        urlsTable.find('tbody').empty();
    });

    jQuery('.js-response-get').click(function (event) {
        event.preventDefault();
        var urlsTable = jQuery(this).parents('.js-form-container').find('.js-form-table');
        var urlsTextarea = jQuery(this).parents('.js-form-container').find('.js-form-area');
        var urls = urlsTextarea.val().split("\n");
        getUrlsInformation(urls, '/url-data/url-response', urlsTable, processResponse);
    });

    jQuery('.js-info-get').click(function (event) {
        event.preventDefault();
        var urlsTable = jQuery(this).parents('.js-form-container').find('.js-form-table');
        var urlsTextarea = jQuery(this).parents('.js-form-container').find('.js-form-area');
        var urls = urlsTextarea.val().split("\n");
        getUrlsInformation(urls, '/url-data/url-info', urlsTable, processInfo);
    });
});

@@ -850,32 +850,33 @@
  %7D%0A            %7D
+,
 %0A        %7D);%0A   
@@ -872,51 +872,90 @@
     
-%7D);%0A    %7D%0A%7D%0A%0Avar processResponse 
+    error: function () %7B%0A                if (typeof(processFunction) ==
 = 
+'
 function
  pro
@@ -954,174 +954,221 @@
 tion
- processUrlResponse(urlData, urls, ajaxUrl, urlsTable)%0A%7B%0A    if (typeof(urlData) !== 'object' %7C%7C typeof(urlData.status) == 'undefined') %7B%0A        return false;%0A    %7D%0A
+') %7B%0A                    processFunction(null, urls, ajaxUrl, urlsTable);%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%7D%0A%0Avar processResponse = function processUrlResponse(urlData, urls, ajaxUrl, urlsTable)%0A%7B
 %0A   
@@ -1286,32 +1286,64 @@
 eBody);%0A    if (
+typeof(urlData) !== 'object' %7C%7C 
 urlData.status !
@@ -2397,118 +2397,8 @@
 )%0A%7B%0A
-    if (typeof(urlData) !== 'object' %7C%7C typeof(urlData.status) == 'undefined') %7B%0A        return false;%0A    %7D%0A%0A
     
@@ -2523,16 +2523,48 @@
     if (
+typeof(urlData) !== 'object' %7C%7C 
 urlData.
@@ -3041,33 +3041,32 @@
 endTo(tableRow);
- 
 %0A    %7D else %7B%0A  
@@ -3662,17 +3662,16 @@
 eRow); %0A
-%0A
     %7D%0A  

fix process function (add it for error & fix process for empty data)