﻿$(document).ready(function() {

    // ---------------------------------------------------------
    // behaviour
    // ---------------------------------------------------------
    // Bepaal welk producttype is geselecteerd.
    // Toon vervolgens de bijbehorende productkeuze en product tarieven.
    // Rounded corners
    $("#stappenMiddle").corner("round 5px");
    $("#subText").corner("round 5px");
    // Maak een click event aan voor de producttype.
    // Dit voor het tonen van de bijbehorende productkeuze en product tarieven.
    $("input[name*='ProductTypeRadioButtonList']").click(function() {
        for (var i = 0; i < 3; i++) {
            var productTypeValue = this.value.split(',')
            if (i == productTypeValue[0]) {
                $("." + i).show();
                var productChoiceValue = $("input[name*='ProductChoice0RadioButtonList']:checked").val().split(',');
                ShowSelectedProductChoice(productChoiceValue[0], false);
            }
            else {
                if ($("." + i).length > 0) {
                    $("." + i).hide();
                }
            }
        }
    });
    // Bepaal welk productkeuze is geselecteerd.
    // Toon vervolgens stroom en/of gas.
    var value = $("input[name*='ProductChoice0RadioButtonList']:checked").val();
    ShowSelectedProductChoice(value, false);

    // Maak een click event aan voor de aanwezige productkeuze.
    // Dit voor het tonen van stroom en/of gas. 
    // Ook voor het clonen van de geselecteerde waarde.
    for (var i = 0; i < 3; i++) {
        var id = "ProductChoice" + i + "RadioButtonList";
        if ($("input[name*=" + id + "]").length > 0) {
            $("input[name*=" + id + "]").click(function() {
                var productChoiceValue = this.value.split(',');
                ShowSelectedProductChoice(productChoiceValue[0], true);
                CloneSelectedProductChoice(this);
            });
        }
    }

    // ---------------------------------------------------------
    // meterstandenDoorgeven
    if ($("#MeterstandenDoorgeven2RadioButton").is(':checked')) {
        $("#meterstandenDoorgeven").hide();
        $("#meterstandenDoorgevenVervolg").hide();
    }
    $("#MeterstandenDoorgeven1RadioButton").click(function() {
        $("#meterstandenDoorgeven").slideDown();
        $("#meterstandenDoorgevenVervolg").slideDown();
    });
    $("#MeterstandenDoorgeven2RadioButton").click(function() {
        $("#meterstandenDoorgeven").slideUp();
        $("#meterstandenDoorgevenVervolg").slideUp();
    });
    // SoortMeter
    if ($("#SoortMeter1RadioButton").is(':checked')) {
        $("#soortMeterStandDubbel").hide();
    }
    else {
        $("#soortMeterStandEnkel").hide();
    }
    $("#SoortMeter1RadioButton").click(function() {
        $("#soortMeterStandDubbel").slideUp();
        $("#soortMeterStandEnkel").slideDown();
    });
    $("#SoortMeter2RadioButton").click(function() {
        $("#soortMeterStandDubbel").slideDown();
        $("#soortMeterStandEnkel").slideUp();
    });

    // ---------------------------------------------------------
    // behaviour
    // ---------------------------------------------------------
    // CorrespondentieAdres
    if ($("#CorrespondentieAdres2RadioButton").is(':checked')) {
        $("#CorrespondentieAdres").hide();
    }
    $("#CorrespondentieAdres2RadioButton").click(function() {
        $("#CorrespondentieAdres").slideUp();
    });
    $("#CorrespondentieAdres1RadioButton").click(function() {
        $("#CorrespondentieAdres").slideDown();
    });
    // EanCodeDoorgeven
    if ($("#EanCodeDoorgeven2RadioButton").is(':checked')) {
        $("#EanCodeDoorgeven").hide();
        $("#EanCodeDoorgevenVervolg").hide();
    }
    $("#EanCodeDoorgeven1RadioButton").click(function() {
        $("#EanCodeDoorgeven").slideDown();
    });
    $("#EanCodeDoorgeven2RadioButton").click(function() {
        $("#EanCodeDoorgeven").slideUp();
    });

    // ---------------------------------------------------------
    // behaviour
    // ---------------------------------------------------------
    // nieuweBewoner

    $("#NieuweBewoner1RadioButtonList").click(function() {
        $("#Ingangsdatum1RadioButton").attr('checked', true);
        $("#Ingangsdatum").slideDown();
    });

    // ingangsdatum
    if ($("#Ingangsdatum2RadioButton").is(':checked')) {
        $("#Ingangsdatum").hide();
    }

    $("#Ingangsdatum1RadioButton").click(function() {
        $("#Ingangsdatum").slideDown();
    });
    $("#Ingangsdatum2RadioButton").click(function() {
        $("#Ingangsdatum").slideUp();
    });

    // ---------------------------------------------------------
    // masked input
    // ---------------------------------------------------------
    $("#TelefoonnummerTextBox").numeric();
    $("#GeboortedatumTextBox").mask("99-99-9999");
    $("#RekeningnummerTextBox").numeric();
    $("#KlantnummerTextBox").numeric();
    $("#OmzetDatumTextBox").mask("99-99-9999");
    $("#IngangsdatumTextBox").mask("99-99-9999");
    $("#tooltipVragen").tooltip();
    $("#LeveringPostcodeTextBox").mask("9999aa");
    $("#LeveringHuisnummerTextBox").numeric();
    $("#FactuurPostcodeTextBox").mask("9999aa");
    $("#FactuurHuisnummerTextBox").numeric();
    $("#EanCodeStroomTextBox").numeric();
    $("#EanCodeGasTextBox").numeric();
    $("#tooltipVragen").tooltip();
    $("#OpnameDatumTextBox").mask("99-99-9999");
    $("#StandMeterHoogTextBox").numeric();
    $("#StandMeterLaagTextBox").numeric();
    $("#StandEnkeleMeterTextBox").numeric();
    $("#StandGasMeterTextBox").numeric();
    // ------------------------------------------------------
    // Tooltips
    // ------------------------------------------------------
    $("#tooltipVragen").tooltip();
    $("#tooltipNieuweBewoner").tooltip();
    $("#tooltipIngangsdatum").tooltip();
    $("#tooltipVragen").tooltip();
    $("#tooltipStroomtarieven").tooltip();
    $("#tooltipGastarieven").tooltip();
    $("#tooltipVragen").tooltip();
    $("#tooltipStroomtarieven0").tooltip();
    $("#tooltipStroomtarieven1").tooltip();
    $("#tooltipStroomtarieven2").tooltip();
    $("#tooltipStroomVastrecht").tooltip();
    $("#tooltipGastarieven0").tooltip();
    $("#tooltipGastarieven1").tooltip();
    $("#tooltipGastarieven2").tooltip();
    $("#tooltipGasVastrecht").tooltip();
    $("#tooltipOpzegvoorwaarden0").tooltip();
    $("#tooltipOpzegvoorwaarden1").tooltip();
    $("#tooltipOpzegvoorwaarden2").tooltip();
    $("#tooltipMeterstanden").tooltip();

    // ValidationSummary
    if ($("#validationBox ul").children().length > 0) {
        ShowValidation();
    }
    else {
        HideValidation()
    }

    if ($("input[name*='ProductTypeRadioButtonList']:checked").length != 0) {
        var productTypeValue = $("input[name*='ProductTypeRadioButtonList']:checked").val().split(',');
        for (var i = 0; i < 3; i++) {
            if (i == productTypeValue[0]) {
                $("." + i).show();
            }
            else {
                if ($("." + i).length > 0) {
                    $("." + i).hide();
                }
            }
        }
    }
});

// -------------------------------------------------------------
// functions
// -------------------------------------------------------------
function ShowSelectedProductChoice(text, animated) {
    if (animated == true) {
        switch (text) {
            case "StroomEnGas":
                $(".stroomtarieven").slideDown();
                $(".gastarieven").slideDown();
                break;
            case "Stroom":
                $(".stroomtarieven").slideDown();
                $(".gastarieven").slideUp();
                break;
            case "Gas":
                $(".stroomtarieven").slideUp();
                $(".gastarieven").slideDown();
                break;
        }
    }
    else {
        switch (text) {
            case "StroomEnGas":
                $(".stroomtarieven").show();
                $(".gastarieven").show();
                break;
            case "Stroom":
                $(".stroomtarieven").show();
                $(".gastarieven").hide();
                break;
            case "Gas":
                $(".stroomtarieven").hide();
                $(".gastarieven").show();
                break;
        }
    }
}
// Functie voor het clonen van de geselecteerde waarde van de productkeuze.
function CloneSelectedProductChoice(selectedRadio) {
    var selectedId = selectedRadio.id;
    var selectedTypeCounter = selectedRadio.id.substring(13, 14)
    var selectedChoiceCounter = selectedId.substring(15, 16);
    for (var i = 0; i < 3; i++) {
        if (i != selectedTypeCounter) {
            var listId = "ProductChoice" + i + "RadioButtonList";
            for (var j = 0; j < 3; j++) {
                var radio = $("input[name=" + listId + "]")[j]
                if (radio != null) {
                    if (j != selectedChoiceCounter) {
                        radio.checked = false;
                    }
                    else {
                        radio.checked = true;
                    }
                }
            }
        }
    }
}
function GetAdresByPostcode(obj, idStraat, idWoonplaats) {
    var postcode = obj.value;
    $.getJSON("/JSON/GetAdresByPostcode", { postcode: postcode },
            function(result) {
                $("#" + idStraat).val(result.straat);
                $("#" + idWoonplaats).val(result.woonplaats);
            });
}
function ShowValidation() {
    // Toon de validationBackground
    $("#validationBackground").css('display', 'block');
    $("#validationBackground").css('height', $(window).height())
    $("#validationBackground").css('width', $(window).width() + 30)

    // centreer de validationBox
    var o = $(window).height() / 2 - $('#validationBox').height() / 2 + $(window).scrollTop() + "px";
    var t = $(window).width() / 2 - $('#validationBox').width() / 2 + $(window).scrollLeft() + "px";
    $('#validationBox').css('display', 'block');
    $('#validationBox').css('top', o);
    $('#validationBox').css('left', t);

    // zet de scrollbar uit.
    // $('html, body').css('overflow-y', 'hidden');
}
function HideValidation() {
    // verberg de validationBackground
    $("#validationBackground").css('display', 'none');
    $("#validationBackground").css('height', 0)
    $("#validationBackground").css('width', 0)

    $("#validationBox").css('display', 'none');

    // zet de scrollbar aan.
    // $('html, body').css('overflow-y', 'auto');
}