﻿var isMobile = false;
var names = [];
var categoriesIds = [];
var firstTime = true;
var activeAjaxLoaders = 0;

$(document).ready(function () {


    defaultValuesSite();
    clickEventsSite();
    //retrieveNumber();
});

// returns object with request params from URL as lowered case fields
function getRequestParams() {
    var params = {};
    if (window.location.search.length > 1) {
        for (var aItKey, nKeyId = 0, aCouples = window.location.search.substr(1).split("&") ; nKeyId < aCouples.length; nKeyId++) {
            aItKey = aCouples[nKeyId].split("=");
            params[unescape(aItKey[0]).toLowerCase()] = aItKey.length > 1 ? unescape(aItKey[1]) : "";
        }
    }
    return params;
}

// returns an empty string if parameter doesn't exist
function tryGetRequestParam(paramName) {
    return (getRequestParams()[paramName.toLowerCase()] ? getRequestParams()[paramName.toLowerCase()] : "");
}

function defaultValuesSite() {
    // device detection
    if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
        || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) {
        isMobile = true;
    }
    
    if (isMobile) {
        $(".carousel-for-desktop").addClass("hide");
        $(".carousel-for-mobile").removeClass("hide");

        $(".IDlogoHeader").addClass("hide");
        $(".IDlogoMobileHeader").removeClass("hide");

        $(".btnLeggiTutto").addClass("text-center");
        $(".btnLeggiTutto").removeClass("float-right");
        $("h3.text-center.containerForTextMobile").removeClass("hide");

        $(".mainHead.mainHeadDesktop").removeClass("mainHeadDesktop");

    } else {
        $(".carousel-for-mobile").addClass("hide");
        $(".carousel-for-desktop").removeClass("hide");

        $(".IDlogoMobileHeader").addClass("hide");
        $(".IDlogoHeader").removeClass("hide");

        $(".btnLeggiTutto").removeClass("text-center");
        $("h2.text-center.containerForTextDesktop").removeClass("hide");

        $(".mainHead").addClass("mainHeadDesktop");

    }

    loadBlogPosts();
    loadBlogDiconoPosts();

    //$(".IDlogoHeader img").attr("src", realPath + "public/images/logo_mundamundis_completo.png");

    var headerHeight = $(".mainHead").outerHeight() + $(".bottomHeaderSite").outerHeight();
    var footerHeight = $("#siteFooter").outerHeight();
    var viewport = $(window).height();
    console.log(viewport - headerHeight - footerHeight);
    $(".mainContentBody").css("min-height", (viewport - headerHeight - footerHeight) + "px");

    //$('.counter').counterUp();


    var page = tryGetRequestParam("content");
    if (page == "il_progetto" || page == "strumenti" || page == "selezioni" || page == "protezione_dati" || page == "contatti") {
        $(".menu li").removeClass("active");
        $(".sublistContainer.chiSiamo").addClass("active");
    }

    if (page == "offerte_di_lavoro" || page == "candidati" || page == "corsi_e_stage") {
        $(".menu li").removeClass("active");
        $(".sublistContainer.cerca").addClass("active");
    }

    if (page == "i_nostri_partner" || page == "diventa_partner") {
        $(".menu li").removeClass("active");
        $(".sublistContainer.partners").addClass("active");
    }

    if (page == "to do") { //to do letture
        $(".menu li").removeClass("active");
        $(".sublistContainer.letture").addClass("active");
    }

    if (page == "") {
        $(".menu li").removeClass("active");
        $(".headerLinks .home").addClass("active");
    }

    $(".IDusername").html($(".IDhfUserName").val());
    if ($(".IDhfLogged").val() != "" && $(".IDhfLogged").val() != "0") {
        $(".IDuserInfo").show();
    }
    else {
        $(".IDuserInfo").hide();
    }

}

function loadBlogPosts() {
    //var path = realPath + "blog/wp-json/wp/v2/posts?categories=3,4,8&_embed&per_page=3";
    ////var path = "https://www.mundamundis.com/" + "blog/wp-json/wp/v2/posts?categories=3,4,8&_embed&per_page=3";
    var path = realPath + "blog/wp-json/wp/v2/posts?categories=58&_embed&per_page=3";
    //var path = "https://www.mundamundis.com/" + "blog/wp-json/wp/v2/posts?categories=58&_embed&per_page=3";

    var datex = new Date();



    jQuery.ajax({
        dataType: "json",
        url: path, //realPath + "mod_mumu/ajax/AjMumu.aspx?op=GreatRetriever&data=" + datex.getMilliseconds(),
        //data: "jsonobj=" + str,
        method: "GET",
        type: "GET",
        success: function (data) {
            var row = "";
            console.log(data);

            jQuery.each(data, function (e, v) {
                getName(v.categories[0]).then(function (obj) {
                    var d = moment(v.date).format("DD-MM-YYYY");
                    var img = v._embedded["wp:featuredmedia"][0].source_url;
                    console.log(img);
                    row +="<div class='col-md-4'>"+
                        "<div class='articleContainer'>"+
                            "<div class='bgImg bgImg1'><img src='" + img + "' /></div>" +
                            "<a href='" + v.link + "'><h3 class='bold'>" + v.title.rendered + "</h3></a>" +
                            "<small>" + d + "</small><small class='ml-4 bold fs1' data-category='" + v.categories[0] + "'>" + "| " + obj[0].name + "</small>" +
                            "<div class='articleBlogTextExc'><p>" + v.excerpt.rendered + "</p></div>" +
                            "<a href='" + v.link + "'><span class='text-right'>[Leggi...]</span></a>" +
                        "</div>" +
                        "</div>";
                }).then(function () {
                    jQuery(".blogArticlesContainer").html(row);
                });
                
            });
            
        }, complete: function () {
            //hideAjaxLoader();
        }
    });

}


function loadBlogDiconoPosts() {
    //var path = realPath + "blog/wp-json/wp/v2/posts?categories=9&_embed&per_page=3";
    //var path = realPath + "/blog/wp-json/wp/v2/posts?categories=10&_embed&per_page=1";
    var path = realPath + "blog/wp-json/wp/v2/posts?categories=8&_embed&per_page=3";
    //var path = "https://www.mundamundis.com/" + "/blog/wp-json/wp/v2/posts?categories=8&_embed&per_page=3";
    var datex = new Date();
    jQuery.ajax({
        dataType: "json",
        url: path, //realPath + "mod_mumu/ajax/AjMumu.aspx?op=GreatRetriever&data=" + datex.getMilliseconds(),
        //data: "jsonobj=" + str,
        method: "GET",
        type: "GET",
        success: function (data) {
            var row = "";
            console.log(data);

            jQuery.each(data, function (e, v) {
                var d = moment(v.date).format("DD-MM-YYYY");
                var img = v._embedded["wp:featuredmedia"][0].source_url;

                console.log(img);
                getName(v.categories[0]).then(function (obj) {
                    row = "<div class='col-xs-12 col-sm-12 col-lg-4'><div class='row'><div class='col-12 articleOutContainer'>" +
                        "<div class='articleContainer'>" +
                            "<div class='bgImg bgImg1'><img src='" + img + "' /></div>" +
                            "<a href='" + v.link + "'><h3 class='bold'>" + v.title.rendered + "</h3></a>" +
                            "<small>" + d + "</small><small class='ml-4 bold fs1' data-category='" + v.categories[0] + "'>" + "| " + obj[0].name + "</small>" +
                            "<div class='articleBlogTextExc'><p>" + v.excerpt.rendered + "</p></div>" +
                            "<a class='pull-right' href='" + v.link + "'><span class='btnLeggiTutto btn btn-light'>LEGGI TUTTO</span></a>" +
                        "</div>" +
                        "</div></div></div>";
                }).then(function () {
                    jQuery(".blogDiconoNoiContainer").append(row);
                    if (isMobile) {
                        $(".btnLeggiTutto").addClass("text-center");
                        $("a.pull-right").removeClass("pull-right");
                    }
                    else {
                        $(".btnLeggiTutto").removeClass("text-center");
                        $("a.pull-right").addClass("pull-right");

                    }

                });
            });


        }, complete: function () {
            //hideAjaxLoader();
        }
    });


    //path = realPath + "/blog/wp-json/wp/v2/posts?categories=11&_embed&per_page=1";
    //path = "https://www.mundamundis.com/" + "/blog/wp-json/wp/v2/posts?categories=11&_embed&per_page=1";

    //datex = new Date();
    //jQuery.ajax({
    //    dataType: "json",
    //    url: path, //realPath + "mod_mumu/ajax/AjMumu.aspx?op=GreatRetriever&data=" + datex.getMilliseconds(),
    //    //data: "jsonobj=" + str,
    //    method: "GET",
    //    type: "GET",
    //    success: function (data) {
    //        var row = "";
    //        console.log(data);

    //        jQuery.each(data, function (e, v) {
    //            var d = moment(v.date).format("DD-MM-YYYY");
    //            var img = v._embedded["wp:featuredmedia"][0].source_url;

    //            console.log(img);
    //            getName(v.categories[0]).then(function (obj) {
    //                row = "<div class='col-xs-12 col-sm-12 col-lg-4'><div class='row'><div class='col-12 articleOutContainer'>" +
    //                    "<div class='articleContainer'>" +
    //                        "<div class='bgImg bgImg1'><img src='" + img + "' /></div>" +
    //                        "<a href='" + v.link + "'><h3 class='bold'>" + v.title.rendered + "</h3></a>" +
    //                        "<small>" + d + "</small><small class='ml-4 bold fs1' data-category='" + v.categories[0] + "'>" + "| " + obj[0].name + "</small>" +
    //                        "<div class='articleBlogTextExc'><p>" + v.excerpt.rendered + "</p></div>" +
    //                        "<a class='pull-right' href='" + v.link + "'><span class='btnLeggiTutto btn btn-light'>LEGGI TUTTO</span></a>" +
    //                    "</div>" +
    //                    "</div></div></div>";
    //            }).then(function () {
    //                jQuery(".blogDiconoNoiContainer").append(row);
    //                if (isMobile) {
    //                    $(".btnLeggiTutto").addClass("text-center");
    //                    $("a.pull-right").removeClass("pull-right");
    //                }
    //                else {
    //                    $(".btnLeggiTutto").removeClass("text-center");
    //                    $("a.pull-right").addClass("pull-right");

    //                }
    //            });
    //        });

    //        //jQuery(".blogDiconoNoiContainer").html(jQuery(".blogDiconoNoiContainer").html() + row);

    //    }, complete: function () {
    //        //hideAjaxLoader();
    //    }
    //});

    //path = realPath + "/blog/wp-json/wp/v2/posts?categories=9&_embed&per_page=1";
    //path = "https://www.mundamundis.com/" + "/blog/wp-json/wp/v2/posts?categories=9&_embed&per_page=1";

    //datex = new Date();
    //jQuery.ajax({
    //    dataType: "json",
    //    url: path, //realPath + "mod_mumu/ajax/AjMumu.aspx?op=GreatRetriever&data=" + datex.getMilliseconds(),
    //    //data: "jsonobj=" + str,
    //    method: "GET",
    //    type: "GET",
    //    success: function (data) {
    //        var row = "";
    //        console.log(data);

    //        jQuery.each(data, function (e, v) {
    //            var d = moment(v.date).format("DD-MM-YYYY");
    //            var img = v._embedded["wp:featuredmedia"][0].source_url;

    //            console.log(img);
    //            getName(v.categories[0]).then(function (obj) {
    //                row = "<div class='col-xs-12 col-sm-12 col-lg-4'><div class='row'><div class='col-12 articleOutContainer'>" +
    //                    "<div class='articleContainer'>" +
    //                        "<div class='bgImg bgImg1'><img src='" + img + "' /></div>" +
    //                        "<a href='" + v.link + "'><h3 class='bold'>" + v.title.rendered + "</h3></a>" +
    //                        "<small>" + d + "</small><small class='ml-4 bold fs1' data-category='" + v.categories[0] + "'>" + "| " + obj[0].name + "</small>" +
    //                        "<div class='articleBlogTextExc'><p>" + v.excerpt.rendered + "</p></div>" +
    //                        "<a  class='pull-right' href='" + v.link + "'><span class='btnLeggiTutto btn btn-light'>LEGGI TUTTO</span></a>" +
    //                    "</div>" +
    //                    "</div></div></div>";
    //            }).then(function () {
    //                jQuery(".blogDiconoNoiContainer").append(row);
    //                if (isMobile) {
    //                    $(".btnLeggiTutto").addClass("text-center");
    //                    $("a.pull-right").removeClass("pull-right");
    //                }
    //                else {
    //                    $(".btnLeggiTutto").removeClass("text-center");
    //                    $("a.pull-right").addClass("pull-right");

    //                }
    //            });
    //        });

    //        //jQuery(".blogDiconoNoiContainer").html(jQuery(".blogDiconoNoiContainer").html()+row);

    //    }, complete: function () {
    //        //hideAjaxLoader();
    //    }
    //});

} 

function clickEventsSite() {
    $(".openBeatrixChat").click(function (e) {
        if (!isMobile) {
            e.preventDefault();
            $(".beatrixChatOverlay").show();
            $(".closeBeatrix").show(700);
            $(".beatrixChat").css("height", "100%");
        }
    });

    $(".closeBeatrix").click(function () {
        $(".beatrixChat").css("height", "0");
        $(".closeBeatrix").hide(300);
        $(".beatrixChatOverlay").hide();
    });

    $(".accediLink").click(function (e) {
        e.preventDefault();
        var profile = $(".IDhfProfile").val();
        if (profile == "326") {
            $(this).attr("href", realPath + "mod_mumu/area_riservata/user/dashboard.aspx");
            window.location = realPath + "mod_mumu/area_riservata/user/dashboard.aspx";
        }

        if (profile == "328") {
            $(this).attr("href", realPath + "mod_mumu/area_riservata/company/dashboard.aspx");
            window.location = realPath + "mod_mumu/area_riservata/company/dashboard.aspx";
        }
    });

    $(".logOut").click(function () {
        logout();
    });
    //$(".sublistContainer").click(function(){
    //    $(this).find(".sublist").fadeToggle("300");
    //});

    //$(".IDareaAzienda").click(function () {
    //    window.location = realPath + "public/IndexMundaContents.aspx?content=area_azienda";
    //});

    $(".menu > li").click(function () {
        $(".menu > li").removeClass("active");
        $(this).addClass("active");
        if ($(this).hasClass("sublistContainer") && $(this).find(".sublist").css("display") == "block") {
            $(".sublist").slideUp(100);
            $(this).find(".sublist").slideUp("300");
        }
        else {
            $(".sublist").slideUp(100);
            $(this).find(".sublist").slideDown("300");
        }
    });

    $(".IDuserInfo").click(function () {
        if ($(this).find(".sublist").css("display") == "block") {
            $(".sublist").slideUp(100);
            $(this).find(".sublist").slideUp("300");
        }
        else {
            $(".sublist").slideUp(100);
            $(this).find(".sublist").slideDown("300");
        }
    });

    $(".hamburger:not(.menu)").on("click", function(){
        $(".headerLinks").toggle();
    });

    $('#carouselExample').on('slide.bs.carousel', function (e) {
        var $e = $(e.relatedTarget);
        var idx = $e.index();
        var itemsPerSlide = 4;
        var totalItems = $('.carousel-item').length;

        if (idx >= totalItems - (itemsPerSlide - 1)) {
            var it = itemsPerSlide - (totalItems - idx);
            for (var i = 0; i < it; i++) {
                // append slides to end
                if (e.direction == "left") {
                    $('.carousel-item').eq(i).appendTo('.carousel-inner');
                }
                else {
                    $('.carousel-item').eq(0).appendTo('.carousel-inner');
                }
            }
        }
    });


    jQuery(".startUserSearch").on("click", function () {
        var prof = jQuery(".textUserSearch").val().trim();
        if (prof != "") {
            var datex = new Date();
            location.href = realPath + "public/DemoAreaUser.aspx?key=" + prof + "&t=" + datex.getMilliseconds();
        }
    });

    jQuery(".startCompanySearch").on("click", function () {
        var prof = jQuery(".textCompanySearch").val().trim();
        if (prof != "") {
            var datex = new Date();
            location.href = realPath + "public/DemoArea.aspx?key=" + prof + "&t=" + datex.getMilliseconds();
        }
    });

    jQuery(".startCodeSearch").on("click", function () {
        var codice = jQuery(".texCodeSearch").val().trim();
        if (codice != "" && parseInt(codice)!=NaN ) {
            var datex = new Date();
            location.href = realPath + "public/SchedaOfferta.aspx?offer=" + codice + "&t=" + datex.getMilliseconds();
        }
    });

    jQuery(".IDopenRegistarionPage").on("click", function () {
        location.href = realPath + "registrati_ora/";
    });

    jQuery(".IDsfogla").on("click", function () {
        location.href = realPath + "public/offerte.aspx";
    });

    jQuery(".dropdown-item-provincia-profili").on("click", function () {
        var id = jQuery(this).attr("data-id");
        if (id != "") {
            var datex = new Date();
            location.href = realPath + "public/DemoArea.aspx?province=" + id + "&t=" + datex.getMilliseconds();
        }
    });

    jQuery(".dropdown-item-provincia-offers").on("click", function () {
        var id = jQuery(this).attr("data-id");
        if (id != "") {
            var datex = new Date();
            location.href = realPath + "public/DemoAreaUser.aspx?province=" + id + "&t=" + datex.getMilliseconds();
        }
    });

    jQuery(".dropdown-item-provincia-courses").on("click", function () {
        var id = jQuery(this).attr("data-id");
        if (id != "") {
            var datex = new Date();
            location.href = realPath + "public/MundaCourses.aspx?province=" + id + "&t=" + datex.getMilliseconds();
        }
    }); 

    $(".IDareaOperatore").click(function () {
        window.location = realPath + "LoginSaas.aspx";
    });

    $(".IDareaAzienda").click(function () {
        //window.location = realPath + "public/IndexMundaContents.aspx?content=area_azienda";
        window.location = realPath + "mod_mumu/Login2.aspx";
    });

    $(".IDareaPersone").click(function () {
        window.location = realPath + "mod_mumu/Login2.aspx";
    });

    $(".IDregisterPersone").click(function () {
        $(this).find(".sublist").slideToggle(500);
        //window.location = realPath + "public/UserRegistration.aspx";
        //window.location = realPath + "public/CompanyRegistration.aspx";
    });

    $(".laStampa").click(function () {
        window.location = realPath + "blog/letture/la-stampa/";
    });

    $(".lePersone").click(function () {
        window.location = realPath + "blog/letture/le-persone/";
    });

    $(".leImprese").click(function () {
        window.location = realPath + "blog/letture/le-imprese/";
    });
}

function getName(id) {
    var datex = new Date();
    var obj = {};

    var str = JSON.stringify(obj);

    return jQuery.ajax({
        dataType: "json",
        url: "https://www.mundamundis.com/blog/wp-json/wp/v2/categories?include=" + id,
        //url: realPath + "blog/wp-json/wp/v2/categories?include=" + id,
        method: "GET",
        type: "GET",
        success: function (data) {
            return data[0].name;
        },
        complete: function (data) {
        }
    });
}

function logout() {
    var datex = new Date();
    var obj = {};

    var str = JSON.stringify(obj);

    jQuery.ajax({
        dataType: "json",
        url: realPath + "mod_mumu/ajax/AjMumu.aspx?op=logout&data=" + datex.getMilliseconds(),
        data: "jsonobj=" + str,
        type: "POST",
        success: function (data) {
            if (data == "1") {
                window.location = realPath;
            }
        },
        complete: function () {
            //hideAjaxLoader();
        }
    });
}

function retrieveNumber() {
    var datex = new Date();
    var obj =
    {
        'stored': 'Manage_Recruitment_Site',
        'parameters':
            [
            { 'name': 'proc', 'value': "total_matchings" }
            ]
    };
    var str = JSON.stringify(obj);
    str = encodeURIComponent(str);

    jQuery.ajax({
        dataType: "json",
        url: realPath + "mod_mumu/ajax/AjMumu.aspx?op=GreatRetriever&data=" + datex.getMilliseconds(),
        data: "jsonobj=" + str,
        method: "POST",
        success: function (data) {
            if (data == "sessionExpired")
            { window.location = realPath; }
            if (data != null && data != "" && data != null && data.data.Table != undefined) {
                scroll_pos = $(window).scrollTop() + $(window).height();
                element_pos = $(".bigNumber").offset().top + $(".bigNumber").height();
                if (scroll_pos > element_pos) {
                    if (firstTime) {
                        $({ countNum: 0 }).animate({ countNum: parseInt(data.data.Table[0]["total_matchings"]) }, {
                            duration: 1000,
                            easing: 'linear',
                            step: function () {
                                $(".bigNumber").html(Math.floor(this.countNum));
                            },
                            complete: function () {
                                firstTime = false;

                                if ($(".bigNumber").html() < parseInt(data.data.Table[0]["total_matchings"])) {
                                    $(".bigNumber").html(parseInt(data.data.Table[0]["total_matchings"]));
                                }
                            }
                        });
                    };
                }
                else {
                    $(window).on('scroll', function () {
                        if (firstTime) {
                            $({ countNum: 0 }).animate({ countNum: parseInt(data.data.Table[0]["total_matchings"]) }, {
                                duration: 1000,
                                easing: 'linear',
                                step: function () {
                                    $(".bigNumber").html(Math.floor(this.countNum));
                                },
                                complete: function () {
                                    firstTime = false;

                                    if ($(".bigNumber").html() < parseInt(data.data.Table[0]["total_matchings"])) {
                                        $(".bigNumber").html(parseInt(data.data.Table[0]["total_matchings"]));
                                    }
                                }
                            });
                        };
                    });
                }
            }
        }, complete: function () {
        }
    });
}


$(document).ready(function () {
    var itemsMainDiv = ('.MultiCarousel');
    var itemsDiv = ('.MultiCarousel-inner');
    var itemWidth = "";

    $('.leftLst, .rightLst').click(function () {
        var condition = $(this).hasClass("leftLst");
        if (condition)
            click(0, this);
        else
            click(1, this)
    });

    ResCarouselSize();




    $(window).resize(function () {
        ResCarouselSize();
    });

    //this function define the size of the items
    function ResCarouselSize() {
        var incno = 0;
        var dataItems = ("data-items");
        var itemClass = ('.item');
        var id = 0;
        var btnParentSb = '';
        var itemsSplit = '';
        var sampwidth = $(itemsMainDiv).width();
        var bodyWidth = $('body').width();
        $(itemsDiv).each(function () {
            id = id + 1;
            var itemNumbers = $(this).find(itemClass).length;
            btnParentSb = $(this).parent().attr(dataItems);
            itemsSplit = btnParentSb.split(',');
            $(this).parent().attr("id", "MultiCarousel" + id);


            if (bodyWidth >= 1200) {
                incno = itemsSplit[3];
                itemWidth = sampwidth / incno;
            }
            else if (bodyWidth >= 992) {
                incno = itemsSplit[2];
                itemWidth = sampwidth / incno;
            }
            else if (bodyWidth >= 768) {
                incno = itemsSplit[1];
                itemWidth = sampwidth / incno;
            }
            else {
                incno = itemsSplit[0];
                itemWidth = sampwidth / incno;
            }
            $(this).css({ 'transform': 'translateX(0px)', 'width': itemWidth * itemNumbers });
            $(this).find(itemClass).each(function () {
                $(this).outerWidth(itemWidth);
            });

            $(".leftLst").addClass("over");
            $(".rightLst").removeClass("over");

        });
    }


    //this function used to move the items
    function ResCarousel(e, el, s) {
        var leftBtn = ('.leftLst');
        var rightBtn = ('.rightLst');
        var translateXval = '';
        var divStyle = $(el + ' ' + itemsDiv).css('transform');
        var values = divStyle.match(/-?[\d\.]+/g);
        var xds = Math.abs(values[4]);
        if (e == 0) {
            translateXval = parseInt(xds) - parseInt(itemWidth * s);
            $(el + ' ' + rightBtn).removeClass("over");

            if (translateXval <= itemWidth / 2) {
                translateXval = 0;
                $(el + ' ' + leftBtn).addClass("over");
            }
        }
        else if (e == 1) {
            var itemsCondition = $(el).find(itemsDiv).width() - $(el).width();
            translateXval = parseInt(xds) + parseInt(itemWidth * s);
            $(el + ' ' + leftBtn).removeClass("over");

            if (translateXval >= itemsCondition - itemWidth / 2) {
                translateXval = itemsCondition;
                $(el + ' ' + rightBtn).addClass("over");
            }
        }
        $(el + ' ' + itemsDiv).css('transform', 'translateX(' + -translateXval + 'px)');
    }

    //It is used to get some elements from btn
    function click(ell, ee) {
        var Parent = "#" + $(ee).parent().attr("id");
        var slide = $(Parent).attr("data-slide");
        ResCarousel(ell, Parent, slide);
    }

});

var utility = {
    getString: function (object, fallbackString) {
        return object ? object : fallbackString || "";
    },

    getMultilanguage: function (key) {
        if (key === "" || key === undefined || key == null || key == "null") return "";
        return utility.getString(_L[key]) || ((GetVar("machineName") != "") ? ("<span style='color:red;'>" + key.replace("lbl", "").replace(/([a-z])([A-Z])/g, '$1 $2') + "</span>") : (key.replace("lbl", "").replace(/([a-z])([A-Z])/g, '$1 $2')));
    },
    _L: function (key) {
        return utility.getMultilanguage(key);
    },
}

function showAjaxLoaderGroup() {
    if (activeAjaxLoaders == 0) {
        showAjaxLoader();
    }
    activeAjaxLoaders++;
}

function hideAjaxLoaderGroup() {
    if (activeAjaxLoaders == 1) {
        hideAjaxLoader();
    }
    activeAjaxLoaders--;
}

function showAjaxLoader() {

    var maxzIndex = 0;
    var visiblePopups = $(".popup, .fancyPopup").each(function () {
        var zindex = $(this).css("z-index");
        if (zindex > maxzIndex && $(this).attr("id") != "ajaxCover" && zindex != "auto") {
            maxzIndex = zindex;
        }
    });

    $("#ajaxCover").css("z-index", (parseInt(maxzIndex) + 1) + " !important");
    if ($("html").hasClass("ie7") == true || $("html").hasClass("ie8") == true) {
        $("#ajaxCover").css({ 'display': 'block' });
    } else {
        $("#ajaxCover").fadeIn(500, function () {
            $(this).css({ 'display': 'block' });
        });
    }
}

function hideAjaxLoader() {
    if ($("html").hasClass("ie7") == true || $("html").hasClass("ie8") == true) {
        $("#ajaxCover").css({ 'display': 'none' });
    } else {
        $("#ajaxCover").fadeOut(500, function () {
            $(this).css({ 'display': 'none' });
        });
    }
}


var utility = {
    getString: function (object, fallbackString) {
        return object ? object : fallbackString || "";
    },

    getMultilanguage: function (key) {
        if (key === "" || key === undefined || key == null || key == "null") return "";
        return utility.getString(_L[key]) || ((GetVar("machineName") != "") ? ("<span style='color:red;'>" + key.replace("lbl", "").replace(/([a-z])([A-Z])/g, '$1 $2') + "</span>") : (key.replace("lbl", "").replace(/([a-z])([A-Z])/g, '$1 $2')));
    },
    _L: function (key) {
        return utility.getMultilanguage(key);
    },
    // Create Url params for unload event handler. Accepts standard JSON object with properties and creates only properties which have values
    // Returns string like ?param1=value1&param2=value2
    createUrlParams: function (jsonObject) {
        var urlParams = "";
        $.each(jsonObject, function (e, v) {
            if (v) {
                if (urlParams) urlParams += "&";
                urlParams += e + "=" + v;
            }
        });
        if (urlParams) urlParams = "?" + urlParams;
        return urlParams;
    },
    // Create request params for GreatRetriever, from standard JSON object
    createRequestParamsArray: function (jsonObject) {
        var requestParams = [];
        $.each(jsonObject, function (e, v) {
            var param = { "name": e, "value": v };
            requestParams.push(param);
        });
        return requestParams;
    },
}