﻿isiPad = navigator.userAgent.match(/iPad/i) != null;


/////////////////////////
/////INIT FUNCTION///////
/////////////////////////
function InitMainSearch(options) {
    if (gup("category") != "") {
        SetCarType(gup("category"));
    }
    else {
        if (gup("sz") == "suv") {
            SetCarType(25);
            SetSeason(10);
        }
    }

    if (gup("season") != "") {
        SetSeason(gup("season"));
    }
    else {
        if (gup("sz") == "winter") {
            SetSeason(11);
        }
        else if (gup("sz") == "zomer") {
            SetSeason(10);
        }
        else if (gup("sz") == "4seasons") {
            SetSeason(9);
        }
        else if (gup("sz") == "runflat") {
            SetSeason(10);
        }
    }

    var selectedTab = 2;
    if (gup("tab") == "1") {
        selectedTab = 2;
        $('#tabBanden').attr("class", "SearchTabSelected");
        $('#tabAuto').attr("class", "SearchTab");
        $('#tabKenteken').attr("class", "SearchTab");
    }
    if (gup("tab") == "2") {
        selectedTab = 1;
        $('#tabBanden').attr("class", "SearchTab");
        $('#tabAuto').attr("class", "SearchTabSelected");
        $('#tabKenteken').attr("class", "SearchTab");
    }
    if (gup("tab") == "3") {
        selectedTab = 0;
        $('#tabBanden').attr("class", "SearchTab");
        $('#tabAuto').attr("class", "SearchTab");
        $('#tabKenteken').attr("class", "SearchTabSelected");
    }

    var $tabs = $("#tabs").tabs({ selected: selectedTab, fx: { opacity: 'toggle', duration: 'fast' }, show: function (event, ui) {
        $("#MainSearch_Loader").css("display", "none");
    }
    });
    $('#tabBanden').click(function () { // bind click event to link
        //$tabs.tabs("select", 2); // switch to third tab 
        $('#fragment-1').attr("class", "");
        $('#fragment-1').customFadeIn('fast');
        $('#fragment-2').css("display", "none")
        $('#fragment-3').css("display", "none")
        $('#tabBanden').attr("class", "SearchTabSelected");
        $('#tabAuto').attr("class", "SearchTab");
        $('#tabKenteken').attr("class", "SearchTab");
        //            ShopSearch_Collapse();
        return false;
    });
    $('#tabAuto').click(function () { // bind click event to link
        //$tabs.tabs("select", 1); // switch to third tab
        $('#fragment-2').attr("class", "");
        $('#fragment-1').css("display", "none")
        $('#fragment-2').customFadeIn('fast');
        $('#fragment-3').css("display", "none")
        $('#tabBanden').attr("class", "SearchTab");
        $('#tabAuto').attr("class", "SearchTabSelected");
        $('#tabKenteken').attr("class", "SearchTab");
        //          ShopSearch_Collapse();
        return false;
    });
    $('#tabKenteken').click(function () { // bind click event to link
        //$tabs.tabs("select", 0); // switch to third tab
        $('#fragment-3').attr("class", "");
        $('#fragment-1').css("display", "none")
        $('#fragment-2').css("display", "none")
        $('#fragment-3').customFadeIn('fast');
        $('#tabBanden').attr("class", "SearchTab");
        $('#tabAuto').attr("class", "SearchTab");
        $('#tabKenteken').attr("class", "SearchTabSelected");
        //        ShopSearch_Collapse();
        return false;
    });

    //    var dimensions = $('#ddlTyreWidth').val() + " / " + $('#ddlTyreHeight').val() + " R" + $('#ddlWheelSize').val() + " " + $('#ddlSpeedIndex').val() + " " + $('#ddlLoadIndex').val();
    //    $("#lblDimensions").val(dimensions);


    //$('#ddlTyreWidth, #ddlTyreHeight, #ddlWheelSize, #ddlSpeedIndex,#ddlLoadIndex, #ddlCarBrand, #ddlCarModel,#ddlCarEngine,#ddlCarYear').sSelect();

    //set max height
    if (!isiPad) {
        $('#ddlTyreWidth').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameSizes', textClass: 'stylishTextFrameSizes', popupClass: 'stylishPopupFrameSizes', hoverClass: 'stylishHoverFrameSizes' });
        $('#ddlTyreHeight').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameSizes', textClass: 'stylishTextFrameSizes', popupClass: 'stylishPopupFrameSizes', hoverClass: 'stylishHoverFrameSizes' });
        $('#ddlWheelSize').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameSizes', textClass: 'stylishTextFrameSizes', popupClass: 'stylishPopupFrameSizes', hoverClass: 'stylishHoverFrameSizes' });
        $('#ddlSpeedIndex').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameSizes', textClass: 'stylishTextFrameSizes', popupClass: 'stylishPopupFrameSizes', hoverClass: 'stylishHoverFrameSizes' });
        $('#ddlLoadIndex').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameSizes', textClass: 'stylishTextFrameSizes', popupClass: 'stylishPopupFrameSizes', hoverClass: 'stylishHoverFrameSizes' });

        $('#ddlCarBrand').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameCar', textClass: 'stylishTextFrameCar', popupClass: 'stylishPopupFrameCar', hoverClass: 'stylishHoverFrameCar' });
        $('#ddlCarModel').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameCar', textClass: 'stylishTextFrameCar', popupClass: 'stylishPopupFrameCar', hoverClass: 'stylishHoverFrameCar' });
        $('#ddlCarEngine').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameCar', textClass: 'stylishTextFrameCar', popupClass: 'stylishPopupFrameCar', hoverClass: 'stylishHoverFrameCar' });
        $('#ddlCarYear').sSelect({ ddMaxHeight: '170px', containerClass: 'stylishItemFrameCar', textClass: 'stylishTextFrameCar', popupClass: 'stylishPopupFrameCar', hoverClass: 'stylishHoverFrameCar' });
    }
    else {
        //	alert('ipad');
        $('#ddlTyreWidth, #ddlTyreHeight, #ddlWheelSize, #ddlSpeedIndex,#ddlLoadIndex, #ddlCarBrand, #ddlCarModel,#ddlCarEngine,#ddlCarYear').removeClass("InputStyle1").removeClass("InputBackground");
    }

    // cascading tyre sizes
    $('#ddlTyreWidth').change(getTyreHeight);
    $('#ddlTyreHeight').change(getTyreWheelSize);
    $('#ddlWheelSize').change(getTyreSpeedIndex);
    $('#ddlSpeedIndex').change(getTyreLoadIndex);

    //cascading cars
    //getCarBrands();
    $('#ddlCarBrand').change(getCarModel);
    $('#ddlCarModel').change(getCarEngine);
    $('#ddlCarEngine').change(getCarYear);
}
/////////////////////////
///END INIT FUNCTION/////
/////////////////////////

/////////////////////
/////SIZES PANEL/////
/////////////////////
function getTyreWidths(selected) {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getwidths",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            for (var i = 0; i < response.length; i++) {
                if (response[i] == selected) {
                    $('#ddlTyreWidth').append("<option value='" + response[i] + "' selected='1'>" + response[i] + "</option>");
                }
                else {
                    $('#ddlTyreWidth').append("<option value='" + response[i] + "'>" + response[i] + "</option>");

                }
            }
            if (!isiPad) {
                $('#ddlTyreWidth').resetSS();
            }
        }
    });
}

function getTyreHeight() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getheights&width=" + $('#ddlTyreWidth').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#MainSearch_ddlHeight').attr('disabled', false).empty().change(getTyreWheelSize);
            $('#ddlWheelSize').empty().append("<option value='0'>Alle</option>");
            $('#ddlSpeedIndex').empty().append("<option value='0'>Alle</option>");
            $('#ddlLoadIndex').empty().append("<option value='0'>Alle</option>");
            $('#ddlTyreHeight').empty().append("<option value='0'>Alle</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlTyreHeight').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {
                $('#ddlTyreHeight').resetSS();
                $('#ddlWheelSize').resetSS();
                $('#ddlSpeedIndex').resetSS();
                $('#ddlLoadIndex').resetSS();
            }
        }
    });
}

function getTyreWheelSize() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getwheelsizes&width=" + $('#ddlTyreWidth').val() + "&height=" + $('#ddlTyreHeight').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlWheelSize').attr('disabled', false).empty().change(getTyreSpeedIndex);
            $('#ddlSpeedIndex').empty().append("<option value='0'>Alle</option>");
            $('#ddlLoadIndex').empty().append("<option value='0'>Alle</option>");
            $('#ddlWheelSize').append("<option value='0'>Alle</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlWheelSize').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {

                $('#ddlWheelSize').resetSS();
                $('#ddlSpeedIndex').resetSS();
                $('#ddlLoadIndex').resetSS();
            }
        }
    });
}

function getTyreSpeedIndex() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getspeedindexes&width=" + $('#ddlTyreWidth').val() + "&height=" + $('#ddlTyreHeight').val() + "&wheelsize=" + $('#ddlWheelSize').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlSpeedIndex').attr('disabled', false).empty().change(getTyreLoadIndex);
            $('#ddlLoadIndex').empty().append("<option value='0'>Alle</option>");
            $('#ddlSpeedIndex').append("<option value='0'>Alle</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlSpeedIndex').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {

                $('#ddlSpeedIndex').resetSS();
                $('#ddlLoadIndex').resetSS();
            }
        }
    });
}

function getTyreLoadIndex() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getloadindexes&width=" + $('#ddlTyreWidth').val() + "&height=" + $('#ddlTyreHeight').val() + "&wheelsize=" + $('#ddlWheelSize').val() + "&speedindex=" + $('#ddlSpeedIndex').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlLoadIndex').attr('disabled', false).empty();
            $('#ddlLoadIndex').append("<option value='0'>Alle</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlLoadIndex').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {
                $('#ddlLoadIndex').resetSS();
            }
        }
    });
}
/////////////////////
///END SIZES PANEL///
/////////////////////

///////////////////
/////CAR PANEL/////
///////////////////
function getCarBrands() {
    var ss = $('#ddlCarBrand option').length;
    if (ss <= 1) {
        $.ajax({
            type: "GET",
            url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbrands",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                for (var i = 0; i < response.length; i++) {
                    $('#ddlCarBrand').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
                }
                if (!isiPad) {
                    $('#ddlCarBrand').resetSS();
                }
            }
        });
    }
}

function getCarModel() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarmodel&brand=" + $('#ddlCarBrand').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarModel >option').remove();
            $('#ddlCarModel').append("<option value='Model'>Model</option>");
            $('#ddlCarEngine >option').remove();
            $('#ddlCarEngine').append("<option value='Uitvoering'>Uitvoering</option>");
            $('#ddlCarYear >option').remove();
            $('#ddlCarYear').append("<option value='Jaar'>Jaar</option>");
            for (var i = 0; i < response.length; i++) {

                //                var myCombo = $('#ddlCarModel');
                //                myCombo.append("< option value='Model'>Model</option>");
                $('#ddlCarModel').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {
                $('#ddlCarModel').resetSS();
                $('#ddlCarEngine').resetSS();
                $('#ddlCarYear').resetSS();
            }
        }
    });
}

function getCarEngine() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarengine&brand=" + $('#ddlCarBrand').val() + "&model=" + $('#ddlCarModel').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarYear >option').remove();
            $('#ddlCarYear').append("<option value='Jaar'>Jaar</option>");
            $('#ddlCarEngine >option').remove();
            $('#ddlCarEngine').append("<option value='Uitvoering'>Uitvoering</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlCarEngine').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {
                $('#ddlCarEngine').resetSS();
                $('#ddlCarYear').resetSS();
            }
        }
    });
}

function getCarYear() {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcaryear&brand=" + $('#ddlCarBrand').val() + "&model=" + $('#ddlCarModel').val() + "&engine=" + $('#ddlCarEngine').val() + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarYear >option').remove();
            $('#ddlCarYear').append("<option value='Jaar'>Jaar</option>");
            for (var i = 0; i < response.length; i++) {
                $('#ddlCarYear').append("<option value='" + response[i] + "'>" + response[i] + "</option>");
            }
            if (!isiPad) {
                $('#ddlCarYear').resetSS();
            }
        }
    });
}

function YearChangedUpdate() {
    var brand = $('#ddlCarBrand').val();
    var model = $('#ddlCarModel').val();
    var engine = $('#ddlCarEngine').val();
    var year = $('#ddlCarYear').val();
    var lblSizes = $("[id$='_lblDimensions']");
    var lblDimensions = $("[id$='_divTyreDimensions']");
    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbyspecs&brand=" + brand + "&model=" + model + "&engine=" + engine + "&year=" + year, function (result) {

        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var car = eval(q);
                var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;
                lblDimensions.css("display", "block");
                lblDimensions.html("<span id='lblResults' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><br /><span style='font-size: 11px; font-weight: normal;cursor:default; font-style:italic;' class='ProfileSubtitle1'  onmouseover='TipUwBandenMaatInfo();' onmouseout='UnTip();'>(volgens fabrieksopgave)</span><br /><span id='lblDimensions' style='font-size: 13px; font-weight: bold;'class='ProfileSubtitle2'>" + size + "</span>");
            } catch (e) {
            }
        }
    });
}
///////////////////
///END CAR PANEL///
///////////////////

////////////////////////////
//////SEARCH FUNCTIONS//////
////////////////////////////

function MakeTyreSearchParams(isIFrame) {
    var params = "";
    var hidSeason = $("[id$='_hidSeason']").val();
    var hidCarTypes = $("[id$='_hidCarType']").val();
    var hidRunflat = $("[id$='_hidRunflat']").val();
    var hidXl = $("[id$='_hidXl']").val();
    var width = $('#ddlTyreWidth').val();
    var height = $('#ddlTyreHeight').val();
    var wheelsize = $('#ddlWheelSize').val();
    var speedindex = $('#ddlSpeedIndex').val();
    var loadindex = $('#ddlLoadIndex').val();

    if (width != 'Alle' && width != '0') {
        params += "width=" + width + "&";
    }
    if (height != 'Alle' && height != '0') {
        params += "height=" + height + "&";
    }
    if (wheelsize != 'Alle' && wheelsize != '0') {
        params += "wheelsize=" + wheelsize + "&";
    }
    if (speedindex != 'Alle' && speedindex != '0') {
        params += "speedindex=" + speedindex + "&";
    }
    if (loadindex != 'Alle' && loadindex != '0') {
        params += "loadindex=" + loadindex + "&";
    }

    if (hidSeason != null) {
        params += "season=" + hidSeason + "&";
    }

    if (hidCarTypes != null) {
        params += "category=" + hidCarTypes + "&";
    }

    if (hidRunflat != null) {
        params += "runflat=" + hidRunflat + "&";
    }
    if (hidXl != null) {
        params += "xl=" + hidXl + "&";
    }
    // propagate perf 
    if (gup("perf") != "") {
        params += "perf=" + gup("perf") + "&";
    }

    if (gup("qual") != "") {
        params += "qual=" + gup("qual") + "&";
    }
    if (gup("att") != "") {
        params += "att=" + gup("att") + "&";
    }
    params += "frompanel=true&reset=1&tab=1";

    //return params;
    if (isIFrame == 1) {
        DoTyreSearch(params, isIFrame);
    }
    else {
        DoTyreSearch(params, isIFrame);
    }
}

function MakeTyreSearchParamsForCarSpecs(isIFrame) {
    var params = "",
            width = "Alle",
            height = "Alle",
            wheelsize = "Alle",
            speedindex = "Alle",
            loadindex = "Alle",
            hidSeason = $("[id$='_hidSeason']").val(),
            hidCarTypes = $("[id$='_hidCarType']").val(),
            hidRunflat = $("[id$='_hidRunflat']").val(),
            hidXl = $("[id$='_hidXl']").val();

    var brand = $('#ddlCarBrand').val();
    var model = $('#ddlCarModel').val();
    var engine = $('#ddlCarEngine').val();
    var year = $('#ddlCarYear').val();

    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbyspecs&brand=" + brand + "&model=" + model + "&engine=" + engine + "&year=" + year, function (result) {

        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var car = eval(q);
                var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;

                //                UpdateTab1(car.TyreWidth, car.TyreHeight, car.WheelSize, car.SpeedIndex, car.LoadIndex);
                //                UpdateTab3(car);

                width = car.TyreWidth;
                height = car.TyreHeight;
                wheelsize = car.WheelSize;
                speedindex = car.SpeedIndex;
                loadindex = car.LoadIndex;

                params += "width=" + width + "&";

                params += "height=" + height + "&";
                params += "wheelsize=" + wheelsize + "&";
                params += "speedindex=" + speedindex + "&";
                params += "loadindex=" + loadindex + "&";
                if (hidSeason != null) {
                    params += "season=" + hidSeason + "&";
                }

                if (hidRunflat != null) {
                    params += "runflat=" + hidRunflat + "&";
                }
                if (hidXl != null) {
                    params += "xl=" + hidXl + "&";
                }
                /*if (hidCarTypes != null) {
                params += "category=" + hidCarTypes.value + "&";
                }*/
                // propagate perf 
                if (gup("perf") != "") {
                    params += "perf=" + gup("perf") + "&";
                }

                if (gup("qual") != "") {
                    params += "qual=" + gup("qual") + "&";
                }
                if (gup("att") != "") {
                    params += "att=" + gup("att") + "&";
                }
                params += "frompanel=true&reset=1&tab=2";
                if (isIFrame == 1) {
                    DoTyreSearch(params, isIFrame);
                }
                else {
                    DoTyreSearch(params, isIFrame);
                }

                //document.location = _siteRoot + 'TyreResults.aspx?' + params + '&tab=2';
            } catch (e) {
            }
        }
    });
}

function MakeTyreSearchParamsForCar(isIFrame) {

    var params = "";
    var hidSeason = $("[id$='_hidSeason']").val();
    var hidCarTypes = $("[id$='_hidCarType']").val();
    var hidRunflat = $("[id$='_hidRunflat']").val();
    var hidXl = $("[id$='_hidXl']").val();
    var width = "Alle",
            height = "Alle",
            wheelsize = "Alle",
            speedindex = "Alle",
            loadindex = "Alle";

    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcurrentcar", function (result) {
        if (result != "null") {
            var js = "var json=" + result + ";";
            try {
                var q = "(" + result + ")";
                var car = eval(q);
                var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;


                //                //Update tab 1 and 2
                //                UpdateTab1(car.TyreWidth, car.TyreHeight, car.WheelSize, car.SpeedIndex, car.LoadIndex);
                //                UpdateTab2(car.BrandName, car.Model, car.Details, car.Boujaar);
                //                LoadCarSizesTab2(car.TyreWidth, car.TyreHeight, car.WheelSize, car.SpeedIndex, car.LoadIndex);
                //                //End

                width = car.TyreWidth;
                height = car.TyreHeight;
                wheelsize = car.WheelSize;
                speedindex = car.SpeedIndex;
                loadindex = car.LoadIndex;
                //alert(size);
                params += "width=" + width + "&";
                params += "height=" + height + "&";
                params += "wheelsize=" + wheelsize + "&";
                params += "speedindex=" + speedindex + "&";
                params += "loadindex=" + loadindex + "&";
                if (hidSeason != null) {
                    params += "season=" + hidSeason + "&";
                }

                if (hidRunflat != null) {
                    params += "runflat=" + hidRunflat + "&";
                }
                if (hidXl != null) {
                    params += "xl=" + hidXl + "&";
                }
                /*if (hidCarTypes != null) {
                params += "category=" + hidCarTypes.value + "&";
                }*/
                // propagate perf 
                if (gup("perf") != "") {
                    params += "perf=" + gup("perf") + "&";
                }

                if (gup("qual") != "") {
                    params += "qual=" + gup("qual") + "&";
                }
                if (gup("att") != "") {
                    params += "att=" + gup("att") + "&";
                }
                params += "frompanel=true&reset=1&tab=3";

                if (isIFrame == 1) {
                    DoTyreSearch(params, isIFrame);
                }
                else {
                    DoTyreSearch(params, isIFrame);
                }
                //document.location = _siteRoot + 'TyreResults.aspx?' + params + '&tab=3';
            } catch (e) {
            }
        }
    });
}

function DoTyreSearch(params, isIFrame) {
    if (isIFrame == 1) {
        document.location = _siteRoot + 'IFrameTyreResults.aspx?' + params;
    }
    else {
        document.location = _siteRoot + 'TyreResults.aspx?' + params;
    }
}
////////////////////////////
////END SEARCH FUNCTIONS////
////////////////////////////

///////////////////////////////////
///SEASONS,TYPES,RUNFLAT,XL,SETS///
///////////////////////////////////
function UpdateSeasonImages(type) {

    if (type == '10') {
        $("[sid=imgSummer]").attr("id", "zomerRed");
        $("[sid=imgWinter]").attr("id", "winter");
        $("[sid=imgAllSeasons]").attr("id", "AS");

        $("[sid=imgSummer2]").attr("id", "zomerRed");
        $("[sid=imgWinter2]").attr("id", "winter");
        $("[sid=imgAllSeasons2]").attr("id", "AS");

        $("[sid=imgSummer3]").attr("id", "zomerRed");
        $("[sid=imgWinter3]").attr("id", "winter");
        $("[sid=imgAllSeasons3]").attr("id", "AS");

    }
    else if (type == '11') {

        $("[sid=imgSummer]").attr("id", "zomer");
        $("[sid=imgWinter]").attr("id", "WinterRed");
        $("[sid=imgAllSeasons]").attr("id", "AS");

        $("[sid=imgSummer2]").attr("id", "zomer");
        $("[sid=imgWinter2]").attr("id", "WinterRed");
        $("[sid=imgAllSeasons2]").attr("id", "AS");

        $("[sid=imgSummer3]").attr("id", "zomer");
        $("[sid=imgWinter3]").attr("id", "WinterRed");
        $("[sid=imgAllSeasons3]").attr("id", "AS");

    }
    else if (type == '9') {

        $("[sid=imgSummer]").attr("id", "zomer");
        $("[sid=imgWinter]").attr("id", "winter");
        $("[sid=imgAllSeasons]").attr("id", "ASRed");

        $("[sid=imgSummer2]").attr("id", "zomer");
        $("[sid=imgWinter2]").attr("id", "winter");
        $("[sid=imgAllSeasons2]").attr("id", "ASRed");

        $("[sid=imgSummer3]").attr("id", "zomer");
        $("[sid=imgWinter3]").attr("id", "winter");
        $("[sid=imgAllSeasons3]").attr("id", "ASRed");

    }
}

function UpdateCarTypeImages(type) {

    if (type == '20') {
        $("[sid=Personnen]").attr("id", "PersonnenRed");
        $("[sid=a4]").attr("id", "a4x4");
        $("[sid=Bestel]").attr("id", "Bestel");

    }
    else if (type == '25') {

        $("[sid=Personnen]").attr("id", "Personnen");
        $("[sid=a4]").attr("id", "a4x4Red");
        $("[sid=Bestel]").attr("id", "Bestel");
    }
    else if (type == '30') {

        $("[sid=Personnen]").attr("id", "Personnen");
        $("[sid=a4]").attr("id", "a4x4");
        $("[sid=Bestel]").attr("id", "BestelRed");

    }
}

function SetRunflat(cb) {
    var hidRunflat = $("[id$='_hidRunflat']");
    var cbRunflat1 = $("[id$='_cbRunflat1']");
    var cbRunflat2 = $("[id$='_cbRunflat2']");
    var cbRunflat3 = $("[id$='_cbRunflat3']");
    hidRunflat.val(cb.checked);
    cbRunflat1.attr('checked', cb.checked);
    cbRunflat2.attr('checked', cb.checked);
    cbRunflat3.attr('checked', cb.checked);
}

function SetXl(cb) {
    var hidXl = $("[id$='_hidXl']");
    var cbXl1 = $("[id$='_cbXl1']");
    var cbXl2 = $("[id$='_cbXl2']");
    var cbXl3 = $("[id$='_cbXl3']");
    hidXl.val(cb.checked);
    cbXl1.attr('checked', cb.checked);
    cbXl2.attr('checked', cb.checked);
    cbXl3.attr('checked', cb.checked);
}

function Set2Sets(cb) {
    var hid2Sets = $("[id$='_hid2Sets']");
    var hid4Sets = $("[id$='_hid4Sets']");
    var cb2Set1 = $("[id$='_cb2Set1']");
    var cb2Set2 = $("[id$='_cb2Set2']");
    var cb2Set3 = $("[id$='_cb2Set3']");
    var cb4Set1 = $("[id$='_cb4Set1']");
    var cb4Set2 = $("[id$='_cb4Set2']");
    var cb4Set3 = $("[id$='_cb4Set3']");
    hid2Sets.val(cb.checked);
    if (cb.checked) {
        cb4Set1.attr('checked', false);
        cb4Set2.attr('checked', false);
        cb4Set3.attr('checked', false);
        hid4Sets.val(false);
    }
    cb2Set1.attr('checked', cb.checked);
    cb2Set2.attr('checked', cb.checked);
    cb2Set3.attr('checked', cb.checked);
}

function Set4Sets(cb) {
    var hid2Sets = $("[id$='_hid2Sets']");
    var hid4Sets = $("[id$='_hid4Sets']");
    var cb2Set1 = $("[id$='_cb2Set1']");
    var cb2Set2 = $("[id$='_cb2Set2']");
    var cb2Set3 = $("[id$='_cb2Set3']");
    var cb4Set1 = $("[id$='_cb4Set1']");
    var cb4Set2 = $("[id$='_cb4Set2']");
    var cb4Set3 = $("[id$='_cb4Set3']");
    hid4Sets.val(cb.checked);
    if (cb.checked) {
        cb2Set1.attr('checked', false);
        cb2Set2.attr('checked', false);
        cb2Set3.attr('checked', false);
        hid2Sets.val(false);
    }
    cb4Set1.attr('checked', cb.checked);
    cb4Set2.attr('checked', cb.checked);
    cb4Set3.attr('checked', cb.checked);
}

function SetSeason(type) {
    var hidSeason = $("[id$='_hidSeason']");
    hidSeason.val(type);
    UpdateSeasonImages(type);
}

function SetCarType(type) {
    var hidCarTypes = $("[id$='_hidCarType']"); // $('#hidCarTypes');
    hidCarTypes.val(type);
    UpdateCarTypeImages(type);
}
/////////////////////////////////////
//END SEASONS,TYPES,RUNFLAT,XL,SETS//
/////////////////////////////////////

/////////////////////////
////UPDATE,LOAD TABS/////
/////////////////////////
function FillDropdown(ddl, data, selected) {
    var dropdown = $("#" + ddl);
    dropdown.empty();
    dropdown.append("<option value='0'>Alle</option>")
    for (var i = 0; i < data.length; i++) {
        if (data[i] != "" && data[i] != null) {
            if (data[i] == selected) {
                dropdown.append("<option value='" + data[i] + "' selected='1'>" + data[i] + "</option>");
            }
            else {
                dropdown.append("<option value='" + data[i] + "'>" + data[i] + "</option>");
            }
        }
    }
    if (!isiPad) {
        dropdown.resetSS();
    }
}

function LoadDefaultCar(callBackFunction) {
    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcurrentcar", function (json) {
        try {
            if (json != undefined) {
                try {
                    var q = "(" + json + ")";
                    var car = eval(q);
                    //alert(car);
                    //alert(car.Model);
                    var divApk = $("[id$='_divApk']");
                    divApk.css("display", "block");
                    divApk.html("<span id='Span1' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>APK datum:</span><span id='lblApkDate' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + car.APK + "</span>");
                    var divLicenceSizes = $("[id$='_divLicenceSizes']");
                    var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;
                    if (divLicenceSizes != null) {
                        divLicenceSizes.css("display", "block");
                        divLicenceSizes.html("<span id='Label13' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><span id='lblSizes' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + size + "</span><br /><span style='font-size: 11px; font-weight: normal;cursor:default; font-style:italic;' class='ProfileSubtitle1'  onmouseover='TipUwBandenMaatInfo();' onmouseout='UnTip();'>(volgens fabrieksopgave)</span>");
                    }

                    var auto = car.BrandName + ' ' + car.Model + ' ' + car.Details + ' ' + car.Boujaar;
                    var divAuto = $("[id$='_divAuto']");
                    if (divAuto != null) {
                        divAuto.css("display", "block");
                        divAuto.html("<span id='spanDivAuto' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw auto: </span><span id='lblAuto' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + auto + "</span>");

                    }
                }
                catch (e) {
                }
            }
            else {
                var divApk = $("[id$='_divApk']");
                divApk.css("display", "block");
                divApk.html("<span id='Span1' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>APK datum:</span><span id='lblApkDate' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A </span>");
                divLicenceSizes.css("display", "block");
                divLicenceSizes.htmlhtml("<span id='Label13' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><span id='lblSizes' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A</span>");
                divAuto.css("display", "block");
                divAuto.html("<span id='spanDivAuto' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw auto: </span><span id='lblAuto' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A</span>");
            }
        }
        catch (e) {
        }
    });
}

function LoadCarSizesTab2(TyreWidth, TyreHeight, WheelSize, SpeedIndex, LoadIndex) {
    var lblDimensions = $("[id$='_divTyreDimensions']");
    var size = TyreWidth + " / " + TyreHeight + " R" + WheelSize + " " + SpeedIndex + " " + LoadIndex;
    if (lblDimensions != null) {
        lblDimensions.css("display", "block");
        lblDimensions.html("<span id='lblResults' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><br /><span style='font-size: 11px; font-weight: normal;cursor:default; font-style:italic;' class='ProfileSubtitle1'  onmouseover='TipUwBandenMaatInfo();' onmouseout='UnTip();'>(volgens fabrieksopgave)</span><br /><span id='lblDimensions' style='font-size: 13px; font-weight: bold;'class='ProfileSubtitle2'>" + size + "</span>");
    }
}

function UpdateTab1(width, height, wheelsize, speed, load) {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getwidths",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlTyreWidth').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlTyreWidth', response, width);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getheights&width=" + width + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlTyreHeight').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlTyreHeight', response, height);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getwheelsizes&width=" + width + "&height=" + height + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlWheelSize').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlWheelSize', response, wheelsize);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getspeedindexes&width=" + width + "&height=" + height + "&wheelsize=" + wheelsize + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlSpeedIndex').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlSpeedIndex', response, speed);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getloadindexes&width=" + width + "&height=" + height + "&wheelsize=" + wheelsize + "&speedindex=" + speed + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlLoadIndex').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlLoadIndex', response, load);
        }
    });
}

function UpdateTab2(carbrand, carmodel, cardetails, caryear) {
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbrands",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarBrand').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlCarBrand', response, carbrand);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarmodel&brand=" + carbrand + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarModel').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlCarModel', response, carmodel);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcarengine&brand=" + carbrand + "&model=" + carmodel + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarEngine').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlCarEngine', response, cardetails);
        }
    });
    $.ajax({
        type: "GET",
        url: _siteRoot + "Ajax/TyreSearch.aspx?mode=getcaryear&brand=" + carbrand + "&model=" + carmodel + "&engine=" + cardetails + "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#ddlCarYear').empty().append("<option value='0'>Alle</option>");
            FillDropdown('ddlCarYear', response, caryear);
        }
    });
}

function UpdateTab3(car) {
    var lblSizes = $("[id$='_lblDimensions']");
    var lblDimensions = $("[id$='_divTyreDimensions']");
    var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;
    lblDimensions.css("display", "block");
    lblDimensions.html("<span id='lblResults' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><br /><span id='lblDimensions' style='font-size: 13px; font-weight: bold;'class='ProfileSubtitle2'>" + size + "</span>");
    var divApk = $("[id$='_divApk']");
    divApk.css("display", "block");
    divApk.html("<span id='Span1' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>APK datum:</span><span id='lblApkDate' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + car.APK + "</span>");
    var divLicenceSizes = $("[id$='_divLicenceSizes']");
    var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;
    if (divLicenceSizes != null) {
        divLicenceSizes.css("display", "block");
        divLicenceSizes.html("<span id='Label13' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><span id='lblSizes' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + size + "</span>");
    }
    var auto = car.BrandName + ' ' + car.Model + ' ' + car.Details + ' ' + car.Boujaar;
    var divAuto = $("[id$='_divAuto']");
    if (divAuto != null) {
        divAuto.css("display", "block");
        divAuto.html("<span id='spanDivAuto' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw auto: </span><span id='lblAuto' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + auto + "</span>");
    }
}
/////////////////////////
//END UPDATE,LOAD TABS///
/////////////////////////

//**************************************
//**********LICENCE PLATE***************
//**************************************
function PopulateFields(result) {
    try {
        if (result != undefined && result != "null") {
            try {
                var q = "(" + result + ")";
                var car = eval(q);
                //alert(car);
                //alert(car.Model);
                var divApk = $("[id$='_divApk']");
                divApk.css("display", "block");
                divApk.html("<span id='Span1' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>APK datum:</span><span id='lblApkDate' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + car.APK + "</span>");
                var divLicenceSizes = $("[id$='_divLicenceSizes']");
                var size = car.TyreWidth + " / " + car.TyreHeight + " R" + car.WheelSize + " " + car.SpeedIndex + " " + car.LoadIndex;
                if (divLicenceSizes != null) {
                    divLicenceSizes.css("display", "block");
                    divLicenceSizes.html("<span id='Label13' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><span id='lblSizes' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + size + "</span><br /><span style='font-size: 11px;cursor:default; font-weight: normal; font-style:italic;' class='ProfileSubtitle1'  onmouseover='TipUwBandenMaatInfo();' onmouseout='UnTip();'>(volgens fabrieksopgave)</span>");
                }

                var auto = car.BrandName + ' ' + car.Model + ' ' + car.Details + ' ' + car.Boujaar;
                var divAuto = $("[id$='_divAuto']");
                if (divAuto != null) {
                    divAuto.css("display", "block");
                    divAuto.html("<span id='spanDivAuto' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw auto: </span><span id='lblAuto' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>" + auto + "</span>");
                }
            }
            catch (e) {
            }
        }
        else {
            var divApk = $("[id$='_divApk']");
            divApk.css("display", "block");
            divApk.html("<span id='Span1' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>APK datum:</span><span id='lblApkDate' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A </span>");
            var divLicenceSizes = $("[id$='_divLicenceSizes']");
            divLicenceSizes.css("display", "block");
            divLicenceSizes.html("<span id='Label13' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw bandenmaat: </span><span id='lblSizes' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A</span>");
            var divAuto = $("[id$='_divAuto']");
            divAuto.css("display", "block");
            divAuto.html("<span id='spanDivAuto' style='font-size: 13px;font-weight: normal' class='ProfileSubtitle1'>Uw auto: </span><span id='lblAuto' style='font-size: 13px; font-weight: bold;' class='ProfileSubtitle2'>N/A</span>");
        }
    }
    catch (e) {
    }
}

function PopulateFields2(result) {
    try {
        if (result != undefined && result != "null") {
            try {
                var q = "(" + result + ")";
                var car = eval(q);
                var auto = car.BrandName + ' ' + car.Model + ' ' + car.Details + ' ' + car.Boujaar;
                $("[id$='_CarInfo']").css("display", "block");
                $("[id$='_lblCarName']").text(auto);
                $("[id$='_imgTest']").attr("src", car.Image);
                $("[id$='_imgTest']").width(200);
                $("[id$='_CarData']").css("display", "block");
                $("[id$='_lblApkDate']").text(car.APK);
            }
            catch (e) {
            }
        }
    }
    catch (e) {
    }
}

function moveFocusTyreSearch(text1, callBackFunction, callBackFunctionParams, image, noPostback) {
    var textBox = text1;
    var letters = textBox.value.length + 1;
    var text;
    var start;

    if (letters <= 8) {
        if (letters >= 3) {
            text = textBox.value;
            for (start = 3; start <= letters; start = start + 1) {
                if (textBox.value.charAt(start - 2) != '-') {
                    if (((isNaN((textBox.value.charAt(start - 2)))) && (!isNaN(textBox.value.charAt(start - 3))) && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))
                    || ((!isNaN((textBox.value.charAt(start - 2)))) && (isNaN(textBox.value.charAt(start - 3))) && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))) {
                        text = textBox.value;
                        textBox.value = text.substring(0, start - 2) + "-" + text.substring(start - 2);
                        text = textBox.value;
                        textBox.focus();
                    }
                    if (((isNaN(textBox.value.charAt(start - 2))) && (isNaN(textBox.value.charAt(start - 3))) && (isNaN(textBox.value.charAt(start - 4))) && (isNaN(textBox.value.charAt(start - 5))) && (textBox.value.charAt(start - 5) != '-') && (textBox.value.charAt(start - 4) != '-') && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-'))
                        || ((!isNaN(textBox.value.charAt(start - 2))) && (!isNaN(textBox.value.charAt(start - 3))) && (!isNaN(textBox.value.charAt(start - 4))) && (!isNaN(textBox.value.charAt(start - 5))) && (textBox.value.charAt(start - 5) != '-') && (textBox.value.charAt(start - 4) != '-') && (textBox.value.charAt(start - 3) != '-') && (textBox.value.charAt(start - 2) != '-') && (textBox.value.charAt(start - 4) != '') && (textBox.value.charAt(start - 5) != ''))) {
                        textBox.value = text.substring(0, start - 3) + "-" + text.substring(start - 3);
                        textBox.focus();
                    }

                }
            }
            if (letters == 8) {
                var img = document.getElementById(image);
                if (img != null && !noPostback) {
                    img.style.display = "block";
                }
                if (callBackFunction == 'redirect') {
                    __doPostBack(callBackFunction, callBackFunctionParams);
                    return;
                }
                if (!noPostback) {
                    if (callBackFunction != "nosearch") {
                        $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbylicence&licence=" + textBox.value, function (json) {
                            //PageMethods.GetCarByLicencePlate(textBox.value, function(result) {
                            //alert(result);
                            try {

                                eval(callBackFunction + "(json)");
                                if (img != null) {
                                    img.style.display = "none";
                                }
                                //alert(json);
                            } catch (e) {
                                //alert(e);
                            }

                        });
                    }
                    else
                    { img.style.display = "none"; }
                }
                textBox.blur();
            }
        }
        else
            textBox.focus();
    }
    else {
        if (IsLicenceValid(text1)) {
            if (callBackFunction == 'redirect' && !noPostback) {
                __doPostBack(callBackFunction, callBackFunctionParams);
                return;
            }
            textBox.value.length = 8;
            if (!noPostback) {
                $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcarbylicence&licence=" + textBox.value, function (json) {
                    //PageMethods.GetCarByLicencePlate(textBox.value, function(result) {
                    //alert(result);

                    try {

                        eval(callBackFunction + "(json)");
                        //alert(json);
                    } catch (e) {
                        //alert(e);
                    }

                });
            }
            textBox.blur();
        }
    }
}

function EmptyBox(tb) {
    tb.value = "";
}

function IsLicenceValid(text1) {

    var licence1 = text1.value;

    if (licence1 == null) {
        return false;
    }

    if (licence1.length == 8) {
        return true;
    }
    else {
        return false;
    }
}
//**************************************
//*********END LICENCE PLATE************
//**************************************

//************************
//*********BRANDS*********
//************************
function GetBrands() {
    var params = "";
    var list = document.getElementsByTagName("input");
    var total = 0;
    var checked = 0;
    for (var i = 0; i < list.length; i++) {
        if (list[i].type == 'checkbox') {
            if (list[i].attributes['brandid'] != undefined) {
                total++;
                if (list[i].checked) {
                    checked++;
                    params += list[i].attributes['brandid'].nodeValue + ',';
                }
            }
        }
    }
    if (params.length > 0)
        params = params.substring(0, params.length - 1);
    if (checked == total || checked == 0) {
        params = "";
    }
    else {
        params = '&brands=' + params;
    }
    return params;
}
//************************
//*******END BRANDS*******
//************************

/////////////////////////
///////POSTAL CODE///////
/////////////////////////
function CustomPostcodeSearch_DoSearchTyreSearch(text1, image, cityTB) {
    var whiteSpace = false;

    var textBox = document.getElementById(text1);
    var img = document.getElementById(image);
    var city = document.getElementById(city);
    var letters = textBox.value.length + 1;
    if (textBox.value.substring(4, 5) == " ") {
        whiteSpace = true;
    }

    if (((letters <= 6) && (whiteSpace == false)) || ((letters <= 7) && (whiteSpace == true))) {
        /*if (letters <= 4) {
        if (hasNumbers(textBox.value)) {
        textBox.style.backgroundColor = "red";
        }
        else {
        textBox.style.backgroundColor = "white";
        }
        }*/
        textBox.focus();
    }
    else {
        if (img != null) {
            img.src = _appTheme + "Images/ShopSearch/loading.gif";
        }
        textBox.blur();
        var post = textBox.value;
        $(".PostCodeSelector").attr("value", post);

        $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getcityfrompostcode&postcode=" + textBox.value, function (result) {

            //        PageMethods.GetCityFromPostcode(textBox.value, function(result) {
            if (city != null) {
                city.value = result;
                // SiteProperties.SelectedPostcode = textBox.value;
            }
            if (result != "null") {
                img.src = _appTheme + "Images/ShopSearch/bifa.jpg";

                var js = "var json=" + result + ";";
                try {
                    var q = "(" + result + ")";
                    var json = eval(q);

                    //$("[id$='_SmallShop_ShopName']").html(json.ShopName);
                    $("#SmallShop_ShopName").html(json.ShopName);
                    // $("#SmallShop_ShopName").attr("href", _siteRoot + "DisplayShop.aspx?shopId=" + json.ShopId);
                    $("#SmallShop_OwnerName").html(json.OwnerName);
                    $("#SmallShop_Street").html(json.Street);
                    $("#SmallShop_City").html(json.Postcode + " " + json.City);
                    $("#SmallShop_Phone").html(json.Phone);
                    $("#SmallShop_Email").html("Mail");
                    $("#SmallShop_Email").attr("href", 'mailto:' + json.Email);

                    $("#SmallShop_Image").css("background-image", "url('" + json.Image + "')");
                    $("#SmallShop_Image").attr("onmouseover", "TipSimpleImage('" + json.OwnerPictureLarge + "&width=200');");
                    $("#SmallShop_Image").attr("onmouseout", "UnTip();");

                    $("#SmallShop_Loader").css("display", "none");

                    OpenSmallShopDetails();
                    FillShopDetails(json.ShopId);
                } catch (e) {
                    //alert(e);
                }

            }
            else {
                img.src = _appTheme + "Images/ShopSearch/bifa_not.jpg";
            }
        });


    }
}

function CustomPostcodeSearch_DoSearch(textBox) {
    var whiteSpace = false;

    var letters = textBox.value.length + 1;
    if (textBox.value.substring(4, 5) == " ") {
        whiteSpace = true;
    }

    if (((letters <= 6) && (whiteSpace == false)) || ((letters <= 7) && (whiteSpace == true))) {
        textBox.focus();
    }
    else {
        textBox.blur();
        var post = textBox.value;
        $(".PostCodeSelector").attr("value", post);

        var imgBifa = $(".Bifa");
        imgBifa.attr("src", _siteRoot + "Styles/Images/ShopSearch/loading.gif");

        $.getJSON(_siteRoot + "Ajax/ShopSearch.aspx?mode=getshopbypostal&postal=" + textBox.value, function (json) {
            try {
                if (json != "null") {
                    imgBifa.attr("src", _siteRoot + "Styles/Images/ShopSearch/bifa.jpg");
                }
                else {
                    imgBifa.attr("src", _siteRoot + "Styles/Images/ShopSearch/bifa_not.jpg");
                }
            } catch (e) {
            }

        });
    }
}
/////////////////////////
/////END POSTAL CODE/////
/////////////////////////


function GetTyrePerformance(bacs) {
    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=gettyreperformances&baclist=" + bacs, function (result) {
        if (result != "null") {
            for (var i = 0; i < result.length; i++) {
                var divPerf = document.getElementById('divPerf_' + result[i].Bac);
                var divAttitude = "";
                var divQuality = "";
                var divPerformance = "";
                if (result[i].AttitudeTip != null && result[i].AttitudeTip != "" && result[i].AttitudeTip != "null") {
                    divAttitude = '<div onmouseover="' + result[i].AttitudeTip + '" onmouseout="UnTip();" class="' + result[i].AttitudeClass + '">' + result[i].AttitudeText + '</div>';
                }
                if (result[i].QualityTip != null && result[i].QualityTip != "" && result[i].QualityTip != "null") {
                    divQuality = '<div onmouseover="' + result[i].QualityTip + '" onmouseout="UnTip();" class="' + result[i].QualityClass + '">' + result[i].QualityText + '</div>';
                }
                if (result[i].PerformanceTip != null && result[i].PerformanceTip != "" && result[i].PerformanceTip != "null") {
                    divPerformance = '<div onmouseover="' + result[i].PerformanceTip + '" onmouseout="UnTip();" class="' + result[i].PerformanceClass + '">' + result[i].PerformanceText + '</div>';
                }
                divPerf.innerHTML = divAttitude + divQuality + divPerformance;
            }
        }
    });
}


function GetTyreResearch(bacs) {
    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=gettyreresearches&baclist=" + bacs, function (result) {
        if (result != "null") {
            for (var i = 0; i < result.length; i++) {
                var div = document.createElement("div");
                div.setAttribute("id", "div_" + result[i].Bac);
                div.style.display = "none";
                var table = "<table style='width:100%;'>";
                var researchNr = result[i].Research.length;
                if (researchNr > 0) {
                    table += "<tr><td colspan='2' align='right'><img src='" + _appTheme + "images/TyreSearch/delete.png' style='cursor:pointer;' alt='Sluit' onclick='UnTip();'/></td></tr>";
                }
                for (var j = 0; j < researchNr; j++) {
                    var s = "<div class='ProfileLinkSubtitle1'>" + result[i].Research[j].Source + "</div><div class='textTyre' style='color:#f30d0d;'>" + result[i].Research[j].Date + "</div><div class='textTyre' style='padding-top:5px;'><b>Bandenmaat: </b>" + result[i].Research[j].Dimensions + "</div><div class='textTyre'><b>Testresultaten: </b>" + result[i].Research[j].Result + "</div>";
                    if (result[i].Research[j].Link != "")
                        s += "<div style='padding-top:6px;'><a class='linkTyreSmall' target='_blank' href='" + link + "'>ga naar test website</a></div>";
                    s += "<br/>";
                    if (j % 2 == 0) {
                        table += "<tr><td style='width:50%;'>" + s + "</td>";
                    }
                    else {
                        table += "<td style='padding-left:10px;width:50%;'>" + s + "</td></tr>";
                    }
                }
                if (researchNr % 2 != 0)
                    table += "<td></td></tr>";
                table += "</table>";
                div.innerHTML = table;
                var muie = '<span style=\"color:red;\">kkt</span>';
                document.getElementById('research_' + result[i].Bac).innerHTML = '<span style="cursor:pointer;text-decoration:underline;" onmouseover="TagToTip(\'' + "div_" + result[i].Bac + '\', BALLOON, true, CLICKCLOSE, true, CLICKSTICKY, true, STICKY, true, FOLLOWMOUSE, false, WIDTH, 460, BORDERWIDTH, 1, PADDING, 10, BGCOLOR, \'#ffffff\', BORDERCOLOR, \'#e2e2e2\', DELAY, 0);">Tests beschikbaar</span>';
                document.getElementById('research_' + result[i].Bac).appendChild(div);
            }
        }
    });
}

function GetBrandsInfo(ids) {

    $.getJSON(_siteRoot + "Ajax/TyreSearch.aspx?mode=getbrandsinfo&idlist=" + ids, function (result) {
        if (result != null) {
            for (var i = 0; i < result.length; i++) {
                var div = document.createElement("div");
                div.setAttribute("id", "divBrand_" + result[i].BrandId);
                div.style.display = "none";
                var table = "<table cellpadding='0' cellspaceing='0' style='width:100%;'>";
                table += "<tr><td align='left'><img src='" + result[i].ImageUrl + "' style='cursor:pointer;' alt='" + result[i].BrandName + "''/></td>";
                table += "<td align='right' valign='top'><img src='" + _appTheme + "images/TyreSearch/delete.png' style='cursor:pointer;' alt='Sluit' onclick='UnTip();'/></td></tr>";
                table += "<tr><td colspan='2' align='left'><span>" + result[i].Text + "</span></td></tr>";
                table += "<tr><td colspan='2' align='left'><a class='ProfileLink1' href='" + _siteRoot + result[i].Link + "'>Meer informatie</a></td></tr>";
                table += "</table>";
                div.innerHTML = table;
                $("[sid=brand_" + result[i].BrandId + "]").html('<span onmouseover="TagToTip(\'' + "divBrand_" + result[i].BrandId + '\', BALLOON, true, CLICKCLOSE, true, CLICKSTICKY, true, STICKY, true, FOLLOWMOUSE, false, WIDTH, 300, BORDERWIDTH, 1, PADDING, 10, BGCOLOR, \'#ffffff\', BORDERCOLOR, \'#e2e2e2\', DELAY, 0);">' + result[i].BrandName + '</span>');
                document.body.appendChild(div);
            }
        }
    });
}

function ShowPopUpOffer(x) {
    $("#popUpWinterOffer").overlay({
        speed: 0,
        closeSpeed: 0,
        onClose: function () {
            var bac = x;
//            $.get(_siteRoot + "Ajax/TyreSearch.aspx?mode=addtiretosc&bac=" + bac, function (result) {
//             //   document.location = _siteRoot + "/Shoppingcart.aspx";
//            });
        },
        closeOnClick: false,
        load: false
    });
    $("#popUpWinterOffer").overlay().load();
}

function ShowPopUpKopen(x) {
    $("#popUpWinterKopen").overlay({
        closeSpeed: 0,
        speed: 0,
        closeOnClick: false,
        load: false
    });
    $("#popUpWinterKopen").overlay().load();
}

// return 'name' parameter from url
function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function InitResultTableSorter() {
    try {
        $(".tablesorter").tablesorter({
            headers: {
                0: {
                    sorter: false
                },
                5: {
                    sorter: false
                },
                6: {
                    sorter: false
                },
                8: {
                    sorter: false
                }
            },
            // define a custom text extraction function 
            textExtraction: function (node) {
                // extract data from markup and return it
                var s;
                try {
                    var selNode = node.childNodes[0];
                    if (selNode.nodeType == 3) {
                        selNode = node.childNodes[1];
                    }
                    if (selNode == undefined)
                        selNode = node;

                    if (selNode.tagName == "IMG") {
                        s = selNode.attributes["src"].value;
                    }
                    else {
                        if (selNode.tagName == "TABLE") {
                            var tblBody = selNode.childNodes[0];
                            if (tblBody.nodeType == 3)
                                tblBody = selNode.childNodes[1];
                            var tblTr = tblBody.childNodes[0];
                            if (tblTr.nodeType == 3)
                                tblTr = tblBody.childNodes[1];
                            var tblTd = tblTr.childNodes[0];
                            if (tblTd.nodeType == 3)
                                tblTd = tblTr.childNodes[1];
                            var tblAhref = tblTd.childNodes[0];
                            if (tblAhref.nodeType == 3)
                                tblAhref = tblTd.childNodes[1];
                            s = tblAhref.innerHTML
                        }
                        else {
                            s = selNode.innerHTML;
                        }
                    }
                }
                catch (e) {
                    s = node.innerHTML;
                }
                if (s == undefined)
                    s = node.innerHTML;
                return s;
            }
        });   //.tablesorterPager({ container: $("#pager"), size: 5 });
    }
    catch (e) { }
}
function TipAutoMessage() {
    var content = "<span>JAMES Auto & Service zorgt voor<br/> alle particuliere en zakelijke rijders.</span>";
 Tip(content, BALLOON, true, PADDING, 8, BGCOLOR, '#78C253', BORDERCOLOR, '#696969');
}
function TipLeaseMessage() {
    var content = "<span>JAMES Lease Service zorgt voor<br/>alle zakelijke rijders.</span>";
    Tip(content, BALLOON, true, PADDING, 8, BGCOLOR, '#78C253', BORDERCOLOR, '#696969');
}
function SaveShop(ddlcarType, hidcarType) {
    $('#' + hidcarType).val($('#' + ddlcarType).val());
}
