if (verType.indexOf("Lite") != -1) {
    not_installed_drivers = [];
    not_installed_versions = {};
    installed_drivers = [];
    var Shell = new ActiveXObject("WScript.Shell");
    var appdata = Shell.SpecialFolders("AppData");
    if(!fso.FolderExists(appdata+"\\DRPSu")){
        fso.CreateFolder(appdata+"\\DRPSu");
    }
    if(!fso.FolderExists(appdata+"\\DRPSu\\DRIVERS")){
        fso.CreateFolder(appdata+"\\DRPSu\\DRIVERS");
    }
    var driversPath = appdata+"\\DRPSu\\DRIVERS";

//Forming the arrays of the not installed drivers and all installed drivers
    for (var i = 0; i < dev_IDs.length; i++) {
        if (dev_found[i]) {
            continue;
        }
        //Filling the array of the not installed drivers
        if (dev_curstatus[i].indexOf("DEVICE HAS A PROBLEM") != -1 || dev_inst_ind[i] == "undefined") {
            formatted_str = dev_IDs[i].toString().replace(/\\/g, "-");
            not_installed_drivers.push(formatted_str);
        } else {
            formatted_str = dev_IDs[i].toString().replace(/\\/g, "-");
            if ((formatted_str.indexOf("DEV") != -1 || formatted_str.indexOf("PID") != -1) && (formatted_str.indexOf("VEN") != -1 || formatted_str.indexOf("VID") != -1) && formatted_str.indexOf("ROOT_HUB20") == -1 && formatted_str.indexOf("VID_12d1") == -1) {
                var exists = false;
                /*installed_drivers.push(formatted_str);
                 not_installed_versions[dev_IDs[i]] = table_instver[dev_IDs[i]];*/
                for (var counter = 0; counter < installed_drivers.length; counter++) {

                    if (installed_drivers[counter].indexOf(formatted_str) != -1 ||
                        formatted_str.indexOf(installed_drivers[counter]) != -1) {
                        exists = true;
                    }
                }
                if (exists == false) {
                    installed_drivers.push(formatted_str);
                    not_installed_versions[dev_IDs[i]] = table_instver[dev_IDs[i]];
                }

            }
        }
        for (t = dev_group[i]; i < dev_IDs.length && dev_group[i] == t; i++);
        i--;
    }
    sendPost("http://test-st.drp.su/drivers/response.php", not_installed_drivers, installed_drivers);
}

/*
 Method to send prepared data to the server via the JSONP request. The callback with the necessary data will be returned
 */

function sendPost(url, not_installed, installed) {
    var prepared_not_installed = JSON.stringify(not_installed);
    var prepared_installed = JSON.stringify(installed);

    var system_version = 32;
    if (navigator.userAgent.indexOf("WOW64") != -1 ||
        navigator.userAgent.indexOf("Win64") != -1) {
        system_version = 64;
    }

    version = RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\CurrentVersion");
    OSName = "5"
    if (version == "10.0") OSName = "10";
    if (version == "6.4") OSName = "9";
    if (version == "6.3") OSName = "81";
    if (version == "6.2") OSName = "8";
    if (version == "6.1") OSName = "7";
    if (version == "6.0") OSName = "6";

    $.ajax({
        url: url,
        dataType: 'jsonp',
        //Request with the data about the drivers
        data: {not_installed: prepared_not_installed, installed: prepared_installed, version: system_version, os: OSName},
        success: function (json) {
            f = fso.OpenTextFile(logFolder+"DRP-Lite-Drivers.txt", 2, true);
            $('#driver_online').append("<table style='font-size: 14px; margin: 30px 0;' " +
                "class='button-table'></table>");
            for (var i = 0; i < json.not_installed.length; i++) {
                if (json.not_installed[i] != null) {
                    //Changing the extension of the file that needs to be downloaded
                    parsed_url = json.not_installed[i][0].replace(/(zip)$/, "exe")
                    if (!driver_exists(parsed_url, 'tools//DRIVERS')) {
                        if (parsed_url.indexOf("Touchpad") == -1) {
                            f.WriteLine("RECIEVED DRIVER - " + json.not_installed[i][2] + " URL -" + parsed_url);
                            //Forming the table with drivers
                            $('#driver_online table').append("<tr class='driver_approved'>" +
                                "<td style='width: 10px'><input type='checkbox' checked><img src='tools\\ico\\button\\0.png'> </td>" +
                                //I am storing the URL of the drivers in the ID of TD to have a pretty easy access.
                                "<td class='driver_url' style='width: 63%; text-align:left' id='" + parsed_url + "'>" + json.not_installed[i][2] + "</td>" +
                                //Just a size of the file that was returned by the get_size function
                                "<td class='size' style='width: 30%'>" + get_size(parsed_url) + "</td>" +
                                "</tr>");
                        }
                    }
                }
            }
            // Drivers that need to be updated
            if (json.installed.length != 0) {

                for (var i = 0; i < json.installed.length; i++) {
                    var driver_date = new Date(json.installed[i][1]);
                    var modified_driver = json.installed[i][3].toString().replace('-', '\\');
                    var current_driver_date = new Date(not_installed_versions[modified_driver]);
                    //If the driver needs to be updated


                    if (driver_date.getTime() > current_driver_date.getTime()) {
                        parsed_url = json.installed[i][0].replace(/(zip)$/, "exe");
                        if (!driver_exists(parsed_url, driversPath)) {
                            if (parsed_url.indexOf("Touchpad") == -1) {
                                f.WriteLine("RECIEVED DRIVER - " + json.installed[i][2] + " URL -" + parsed_url);
                                $('#driver_online table').append("<tr class='driver_approved'>" +
                                    "<td style='width: 10px'><input type='checkbox' checked><img src='tools\\ico\\button\\0.png'> </td>" +
                                    //I am storing the URL of the drivers in the ID of TD to have a pretty easy access.
                                    "<td class='driver_url' style='width: 83%; text-align:left' id='" + parsed_url + "'>" + json.installed[i][2] + "</td>" +
                                    //Just a size of the file that was returned by the get_size function
                                    "<td class='size' style='width: 10%'>" + get_size(parsed_url) + "</td>" +
                                    "</tr>");
                            }
                        }

                    }

                }
                f.Close();
            }

            //Check if all of the drivers were downloaded
            if ($('.driver_approved').length > 0) {
                $('#driver_online table').after("<div class='install' style='margin-top: 20px;'>" +
                    "<a href='#' class=' btn btn-success drivers_download'>" + infobar_buttonInst + " " +
                    "<span class='sum'></span>" +
                    "</a>" +
                    "</div>");
                recalculate();
            } else {
                $('#driver_online table').after("<h4>" + infobar_infoAllUpd + "</h4>");
            }

        },
        error: function () {
            debugger;
        }
    });
}

/*
 Just a size getter by
 */
function get_size(url) {
    WshShell.run('"tools\\wget.exe" --spider -o '+logFolder+'DRP-Lite-Status.txt ' + url, 0, true);
    return get_info(logFolder+"DRP-Lite-Status.txt", /\(.+\)/);
}

function get_info(file, regex) {
    objFile = fso.openTextFile(file, 1);
    strContents = objFile.ReadAll();
    progress = strContents.match(regex);
    return progress;
}

/*
 Calculation of the total chosen drivers size
 */
function recalculate() {
    var sum = 0.0;
    var number = $('.size').length;
    $('.size').each(function (index, element) {
        if ($(element).parent().hasClass('driver_approved')) {
            if ($(element).html() != 'null' && $(element).html() != drv_notKnown) {
                sum += parseFloat($(element).html().slice(1, -2));

            } else {
                $(element).html(drv_notKnown);
                $(element).parent().removeClass('driver_approved');
                $(element).parent().find('input:checkbox').removeAttr('checked');
                $(element).parent().find('input:checkbox').attr('checked', false);
            }
        }
    });
    $('.sum').html("(" + sum.toFixed(1) + " MB )");
    if (number > 0) {
        $('.drivers_title').html("<div style='margin-bottom: 10px; font-size: 18px; font-weight: bold'>" + manual_con_findDrv + "</div>" +
            " <span style='font-weight: 100'>" + con_driver_available + " </span>" + number + " " +
            "<a href='#' style='float: right; margin: 0 5px 5px 0; ' class='btn btn-success all_drivers_download'>" + infobar_buttonInst + " " +
            "</a>");
    }else{
        $('.drivers_title').html(drv_allSuccess);
    }
    if(sum > 0.0){
        $('.drivers_download').show();
    } else {
        $('.drivers_download').hide();
    }
}

$('document').ready(function () {

    $('.drivers_title').html('<div class="status" style="font-size: 16px; margin-bottom: 1%"></div><div id="progressbar" style="width: 10%; float: left; margin-right: 10px"></div>' +
        '<div class="driver_percents" style="margin-left: 3%"></div>' +
        '<div class="speed" style="margin-left: 3%; margin-top: 1%"></div>');

    //Checkboxes event. Recalculation of the total size
    $('#driver_online').on('click', 'input:checkbox', function () {
        /*if($('.install').css('display') == 'none' || $('.install').css('visibility') == 'none'){
         $('.install').show();
         }*/
        var parent_tr = $(this).parent().parent();
        if (parent_tr.hasClass('driver_approved')) {
            parent_tr.removeClass('driver_approved');
            recalculate();
        } else {
            parent_tr.addClass('driver_approved');
            recalculate();
        }
    });

    /*  $('#driver_online').on('click', '.check', function () {
     $('#driver_online input:checkbox').attr('checked', true);
     recalculate();
     });*/

    $('.drivers_title').on('click', '.all_drivers_download', function () {
        $('#driver_online input:checkbox').attr('checked', true);
        try{
        $('.drivers_download').click();
        } catch (Ex){
            debugger;
        }

    });
    /*
     $('#driver_online').on('click', '.uncheck', function () {
     $('#driver_online input:checkbox').attr('checked', false);
     recalculate();
     });*/

    /*
     Event to be triggered by the "Download the drivers" href
     */
    $('#driver_online').on('click', '.drivers_download', function(){
        try {
            var drivers_to_launch = [];
            var drivers_number = $('.driver_approved').length;
            //Change the title, add the progress bar
            $('.drivers_title').html('<div class="status" style="font-size: 16px; margin-bottom: 1%"></div><div id="progressbar" style="width: 10%; float: left; margin-right: 10px"></div>' +
                '<div class="driver_percents" style="margin-left: 3%"></div>' +
                '<div class="speed" style="margin-left: 3%; margin-top: 1%"></div>');

            //Default value for the progress bars
            $("#progressbar").progressbar({
                value: 0
            });
            //Setting the background, etc of the progressbar
            $('.ui-progressbar-value').css('background', "#4AFF40");
            $('.ui-progressbar').css('height', "0.7em");
            var infobar_color = document.getElementById('infobar_color');
            var infobar_img = document.getElementById('infobar_img');
            //Setting the background color of the element to the downloaded state
            infobar_color.style.backgroundColor = "#c4fb9c";
            infobar_color.style.backgroundImage = "url(./tools/ico/infobar/green.png)";
            infobar_img.src = "./tools/ico/infobar/install.png";
            //Not a magic. Just a first driver for the "Driver 1 of N" string
            var number = 1;
            $('.driver_url').each(function (index, element) {
                if ($(element).parent().hasClass('driver_approved') && !driver_exists($(element).attr('id'), driversPath)) {
                    //"Driver N of M" string former
                    $('.status').html(about_connecting + " " + number + " / " + drivers_number);
                    //Getting the names of the downloaded drivers
                    drivers_to_launch.push(wget_driver($(element).attr('id'), driversPath));
                    //Removing the TR's of the drivers that were downloaded.
                    $(element).parent().remove();
                    number += 1;

                }
            });

            //Changing the title - removing the progtressbar, changing the text for "Installing drivers"
            $('.drivers_title').html('<div class="status" style="font-size: 16px; margin-bottom: 1%">' + infobar_tabInstall + '</div>');

            //If there is no more drivers needs to be installed - just removing the download href, adding the label.
            /*if (!$('.driver_approved').length > 0) {
             $('.install').remove();
             $('#driver_online table').after("<h4>" + drivers_all_ok + "</h4>");
             }*/

            //Launching the downloaded drivers
            for (var counter = 0; counter < drivers_to_launch.length; counter++) {
                if (drivers_to_launch[counter] != null) {
                    if (fso.FileExists(driversPath +'\\' + drivers_to_launch[counter])) {
                        WshShell.Exec('"'+driversPath+ '\\' + drivers_to_launch[counter] + '"');
                    }
                }
            }
            recalculate();
        } catch (Ex) {

        }
    });

});

/*
 A function that downloads the drivers by the string.
 */
function wget_driver(downloadURI, targetFolder, size) {
    if (fso.FileExists('tools\\wget.exe')) {
        if (!driver_exists(downloadURI, targetFolder)) {
            var parsed_url = downloadURI.split("/");
            //Function to be run during the downloading to check the progress.
            setInterval(getPercents, 150);
            var wsShellObj = WshShell.run('"tools\\wget.exe" -P "' + targetFolder + '" ' + downloadURI + " -o "+logFolder+"DRP-Lite-Status.txt", 0, true);
            var downloudedFileDest = targetFolder + (targetFolder ? '\\' : '') + fso.GetFileName(downloadURI);
            return parsed_url[parsed_url.length - 1];
        } else {
            return null;
        }
    }
    else {
        yaCounter.reachGoal('OpenCandyError', { 'Error': 'WGET: not found' });
    }
}
/*
 Function that reads the file with the status of the file that is being downloaded.
 */
function getPercents() {
    //File that is being used as a temp storage.
    try {
        objFile = fso.openTextFile(logFolder+"DRP-Lite-Status.txt", 1);
        var reader = objFile.ReadAll();
        //getting all of the percents in the file.
        var percents = reader.match(/(\d+)\%/gi);
        if (percents !== null) {
            var num = percents[percents.length - 1].slice(0, -1);
            $('.driver_percents').html(num + "%");
            $("#progressbar").progressbar({
                value: parseInt(num)
            });
            var speed = reader.match(/(% +\d+\.*\d+.{1})/gi);
            var last_speed = speed[speed.length - 1].slice(2);
            $('.speed').html(last_speed + "/s");
        }
    } catch (Ex) {

    } finally {
        return 1;
    }
}

/*
 Checking the driver in the folder. NOT in tha system, but only in the folder
 */
function driver_exists(downloadURI, targetFolder) {
    var parsed_url = downloadURI.split("/");
    var downloaded_driver = targetFolder + "//" + parsed_url[parsed_url.length - 1];
    if (fso.FileExists(downloaded_driver)) {
        return true;
    } else {
        return false;
    }
}