﻿$(document).ready(function () {
    $("#sendRegistrationButton").click(function () {
        CustomerInfoWSProxy.registerMember(
            $("#firstname").val(),
            $("#lastname").val(),
            $("#username").val(),
            $("#password").val(),
            $("#password2").val(),
            $("#email").val(),
            $("#address").val(),
            $("#postCode").val(),
            $("#postCity").val(),
            $("#birthyear").val(),
            $("#birthmonth").val(),
            $("#birthday").val(),
            ($("#ssn").val() == undefined) ? "" : $("#ssn").val(),
            $("#telephoneCountryCode").val(),
            $("#telephone").val(),
            $("#acceptnewsletter").is(":checked"),
            $("#country").val(),
            $("#tipcode").val(),
            function (errors) {
                if (errors.length == 0) {
                    LoadingIndicator.show();
                    location.href = CustomerInfoWSProxy.registrationCompleteUri;
                } else {
                    ValidationHandler.generateErrorHtml(errors, "#errorMsgContainer");
                }
            }
        );
    });

    $("#country").change(function () {
        MemberRegistrationCheckCountry();
        /*CustomerInfoWSProxy.getSsnInfo($(this).val(), function (html) {
        $("#ssnInput").html(html);
        });*/
    });

    setInterval(MemberRegistrationCheckCountry, 250);
});

function MemberRegistrationCheckCountry() {
    if ($("#country").val() == 1) {
        $("#ssnExtraField").show();
    } else {
        $("#ssn").val("");
        $("#ssnExtraField").hide();
    }
}