/* Minification failed. Returning unminified contents.
(1,10): run-time error CSS1031: Expected selector, found '='
(1,10): run-time error CSS1025: Expected comma or open brace, found '='
(2,11): run-time error CSS1031: Expected selector, found '='
(2,11): run-time error CSS1025: Expected comma or open brace, found '='
(3,7): run-time error CSS1030: Expected identifier, found 'config('
(3,7): run-time error CSS1031: Expected selector, found 'config('
(3,7): run-time error CSS1025: Expected comma or open brace, found 'config('
(11,7): run-time error CSS1030: Expected identifier, found 'service('
(11,7): run-time error CSS1031: Expected selector, found 'service('
(11,7): run-time error CSS1025: Expected comma or open brace, found 'service('
(29,2): run-time error CSS1019: Unexpected token, found ')'
(31,7): run-time error CSS1030: Expected identifier, found 'controller('
(31,7): run-time error CSS1031: Expected selector, found 'controller('
(31,7): run-time error CSS1025: Expected comma or open brace, found 'controller('
(243,7): run-time error CSS1030: Expected identifier, found 'filter('
(243,7): run-time error CSS1031: Expected selector, found 'filter('
(243,7): run-time error CSS1025: Expected comma or open brace, found 'filter('
(251,2): run-time error CSS1019: Unexpected token, found ')'
(253,7): run-time error CSS1030: Expected identifier, found 'directive('
(253,7): run-time error CSS1031: Expected selector, found 'directive('
(253,7): run-time error CSS1025: Expected comma or open brace, found 'directive('
(257,2): run-time error CSS1019: Unexpected token, found ')'
(259,1): run-time error CSS1019: Unexpected token, found 'setInterval('
(259,13): run-time error CSS1019: Unexpected token, found '"$('.blink').fadeOut().fadeIn();"'
(259,46): run-time error CSS1019: Unexpected token, found ','
(259,48): run-time error CSS1019: Unexpected token, found '1500'
(259,52): run-time error CSS1019: Unexpected token, found ')'
(261,1): run-time error CSS1019: Unexpected token, found '$'
(261,2): run-time error CSS1019: Unexpected token, found '('
(261,3): run-time error CSS1019: Unexpected token, found ''body''
(261,9): run-time error CSS1019: Unexpected token, found ')'
(261,11): run-time error CSS1030: Expected identifier, found 'on('
(261,11): run-time error CSS1019: Unexpected token, found 'on('
(261,14): run-time error CSS1019: Unexpected token, found ''click''
(261,21): run-time error CSS1019: Unexpected token, found ','
(261,32): run-time error CSS1031: Expected selector, found '('
(261,32): run-time error CSS1025: Expected comma or open brace, found '('
(267,2): run-time error CSS1019: Unexpected token, found ')'
(269,10): run-time error CSS1031: Expected selector, found 'toggleSearch('
(269,10): run-time error CSS1025: Expected comma or open brace, found 'toggleSearch('
(277,10): run-time error CSS1031: Expected selector, found 'toggleSpeedFilter('
(277,10): run-time error CSS1025: Expected comma or open brace, found 'toggleSpeedFilter('
(282,10): run-time error CSS1031: Expected selector, found 'startDictation('
(282,10): run-time error CSS1025: Expected comma or open brace, found 'startDictation('
(325,10): run-time error CSS1031: Expected selector, found 'checkSeasonAllInv('
(325,10): run-time error CSS1025: Expected comma or open brace, found 'checkSeasonAllInv('
(330,10): run-time error CSS1031: Expected selector, found 'checkSeasonAllEst('
(330,10): run-time error CSS1025: Expected comma or open brace, found 'checkSeasonAllEst('
(335,10): run-time error CSS1031: Expected selector, found 'checkSeasonAllAll('
(335,10): run-time error CSS1025: Expected comma or open brace, found 'checkSeasonAllAll('
 */
var time = 0;
var myApp = angular.module('myApp', ['ui.filters', 'ui.bootstrap']);
myApp.config(['$httpProvider', function ($httpProvider) {
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};
    }
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);
myApp.service("myService", function ($http) {

    return {
        GetResult: function (x) {
            var typeSearch = baseUrl;
            if (x == 0) {
                typeSearch += 'article/GetAll';
            }
            else if (x == 1) {
                typeSearch += 'article/GetBike';
            }
            else if (x == 2) {
                typeSearch += 'article/GetAdv';
            }
            return $http.post(typeSearch, $('#searchForm').serializeFormJSON());
        }
    }

});

myApp.controller('myAppList', ['$scope', 'filterFilter', 'myService', function myAppList($scope, filterFilter, myService) {

    $scope.GetAll = function (x) {
        $scope.showLoading();
        $('#sq_notfound').hide();
        $('#sq_Error').hide();
        $('#list').hide();
        $scope.result = [];
        $('#speedq').text('');
        time = new Date().getTime();
        var getData = myService.GetResult(x);
        getData.then(function successCallback(emp) {
            $scope.result = emp.data;
            $scope.update();
            time = (new Date().getTime() - time) / 1000;
            if ($scope.result.length == 0) {
                $('#sq_notfound').show();
            } else {
                $('#speedq').text('La ricerca ha impiegato ' + time.toFixed(1) + ' secondi');
                $('#list').show();
            }
            $scope.hideLoading();
        }, function errorCallback(emp) {
            $('#sq_Error').show();
            $scope.hideLoading();
        });
    }
    $scope.test = function (row) {
        var a = disp.checked;
        var res = (a ? row.stock1 > 0 || row.stock2 > 0 : true);
        return res;
    };
    $scope.clearDisp = function () {
        $scope.updateSearch();
        $scope.test.stock1 > 0 && $scope.test.stock2 > 0;
    }
    $scope.clearPromo = function (item) {
        $scope.updateSearch();
        if (item == null) {
            $scope.test.promo = undefined;
        }
    }
    $scope.clearSeason = function (item) {
        $scope.updateSearch();
        if (item == null) {
            $scope.test.ar_Season = undefined;
        }
    }
    $scope.clearBrand = function (item) {
        $scope.updateSearch();
        if (item == null) {
            $scope.test.ar_BrandDescription = undefined;
        }
    }
    $scope.order = function (predicate) {
        $scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
        $scope.predicate = predicate;
    };

    $scope.getOrder = function () {
        $scope.order($scope.selectedItem);
    }

    $scope.getOrderManual = function () {
        $scope.orderManual($scope.selectedItem);
    }

    $scope.orderManual = function (predicate) {
        if (predicate == "ar_Netprice_ASC") {
            $scope.reverse = false;
            predicateValue = "ar_Netprice";
        } else if (predicate == "ar_Netprice_DESC") {
            $scope.reverse = true;
            predicateValue = "ar_Netprice";
        } else {
            $scope.reverse = ($scope.predicate === predicateValue) ? !$scope.reverse : false;
        }
        $scope.predicate = predicateValue;
    };

    $("#find").click(function () {
        $('#orderby').removeAttr('disabled');
        $('#orderby').selectpicker('refresh');
        $scope.GetAll(0);
    });

    $("#findBike").click(function () {
        $('#orderby').removeAttr('disabled');
        $('#orderby').selectpicker('refresh');
        $scope.GetAll(1);
    });

    $("#findAdv").click(function () {
        $('#orderby').removeAttr('disabled');
        $('#orderby').selectpicker('refresh');
        $scope.GetAll(2);
    });

    $(document).keypress(function (e) {
        if (e.which == 13) {
            e.preventDefault();
            selectedTab = $("ul#searchTab li.active").text();

            if (selectedTab == " Tutto") {
                $scope.GetAll(0);
            }
            else if (selectedTab == " Moto") {
                $scope.GetAll(1);
            }
            else {
                $scope.GetAll(2);
            }
        }
    });

    $scope.SearchAndClear = function () {
        $scope.GetAll(0);
        $('#search').val("");
    }

    $scope.showLoading = function () {
        loadingJcModal.open();
        loadingJcModal.showLoading(true);
    }
    $scope.hideLoading = function () {
        loadingJcModal.close();
    }
    // pagination controls
    $scope.currentPage = 1;
    $scope.entryLimit = 50; // items per page
    $scope.noOfPages = 3;

    $scope.updateSearch = function () {
        var filtered = filterFilter($scope.result);
        $scope.totalItems = filtered.length;
        $scope.currentPage = 1;
    }

    $scope.update = function () {
        var filtered = filterFilter($scope.result);
        $scope.totalItems = filtered.length;
    }

    $scope.openZoom = openZoom;

    $scope.notifyMail = notifyMail;

    $scope.openModal = function (x) {
        $(this).css('display', 'block');

        var abc = "url('" + pathTyre + x + ".jpg')";
        $('#modalImageBody').css('background-image', abc);
        $('#modalImage').modal('toggle');
    }

    $scope.replaceSlash = function (string) {
        return string.replace("/", "_");
    }

    $scope.addCart = function (x) {
        var qty_id = '#cart' + x.ar_ArticleCode.replace("/", "_");
        var k = $(qty_id).val();

        if (!k || k == 0) {
            k = 1;
        }

        var json = {
            "cl_ID": "",
            "cl_ArticleCode": x.ar_ArticleCode,
            "cl_Description": x.ar_ArticleDescription,
            "cl_BrandCode": x.ar_BrandCode,
            "cl_BrandDescription": x.ar_BrandDescription,
            "cl_Price": x.ar_Netprice,
            "cl_Qty": k,
            "cl_Tax": iva,
            "cl_Pfu": x.ar_PfuValue,
            "cl_ShipmentCost": x.ar_ShipmentCost,
            "cl_DOI": ""
        };
        //var result = JSON.stringify(json);
        $.ajax({
            url: baseUrl + 'Cart/AddCartItem',
            type: "POST",
            data: JSON.stringify(json),
            contentType: "application/json",
            success: function (dataRet) {
                if (dataRet == "False") {
                    bootbox.alert(msgError);
                }
                else {
                    updateNavbar();
                    Example.show(x.ar_BrandDescription + " " + x.ar_ArticleDescription + " aggiunto al carrello");
                    $(qty_id).val('');
                }
            },
            error: function () {
                messageBox.show("Errore durante l'aggiunta dell' articolo al carrello!");
            }
        });
        loadingJcModal.close();
    }

    $scope.parseInt = parseInt;

    $scope.privacy = privacy;
    $scope.privacyMargin = parseInt(privacyMargin == "" ? "0" : privacyMargin);

    //$scope.SearchAndClear();

}]);

myApp.filter('startFrom', function () {
    return function (input, start) {
        if (input) {
            start = +start;
            return input.slice(start);
        }
        return [];
    };
});

myApp.directive('bsPopover', function () {
    return function (scope, element, attrs) {
        element.find("a[rel=popover]").popover({ placement: 'left', html: 'true' });
    };
});

setInterval("$('.blink').fadeOut().fadeIn();", 1500);

$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });
});

function toggleSearch() {
    if ($("#searchPanelAdv").is(":hidden")) {
        $("#searchPanelAdv").slideDown("slow");
    } else {
        $("#searchPanelAdv").slideUp();
    }
}

function toggleSpeedFilter() {
    $('#list').toggleClass('col-sm-12 col-sm-10');
    $('#speedFilter').toggleClass('col-sm-2 col-sm-0');
}

function startDictation() {

    if (window.hasOwnProperty('webkitSpeechRecognition')) {

        var recognition = new webkitSpeechRecognition();

        recognition.continuous = false;
        recognition.interimResults = false;

        recognition.lang = "it-IT";
        recognition.start();

        $('#search').attr("placeholder", 'Sto Ascoltando...');

        $('#mic').addClass('blink');

        recognition.onresult = function (e) {
            document.getElementById('search').value
                                     = e.results[0][0].transcript;
            $('#search').attr("placeholder", 'Cerca uno pneumatico');
            $('#mic').removeClass('blink');
            recognition.stop();
            var recorded = document.getElementById('search');
            var recNoWhite = recorded.value.split(' ').join('');            
            if ($.isNumeric(recNoWhite))
            {
                $('#search').val(recNoWhite);
                angular.element(this).scope().GetAll();                
            }
            else {
                $('#search').val(recorded);
                angular.element(this).scope().GetAll();
            }
            
        };

        recognition.onerror = function (e) {
            recognition.stop();
        }

    }
}

function checkSeasonAllInv() {
    $("#checkest").prop("checked", false);
    $("#checkallseas").prop("checked", false);
}

function checkSeasonAllEst() {
    $("#checkinv").prop("checked", false);
    $("#checkallseas").prop("checked", false);
}

function checkSeasonAllAll() {
    $("#checkinv").prop("checked", false);
    $("#checkest").prop("checked", false);
}
