@model KendoDateSample.Models.UserModel

@{
    ViewBag.Title = "About";
}


@using (Html.BeginForm("UpdateProfile", "Home", FormMethod.Post, new { id = "patientedit-form" }))
{    
    @Html.Partial("_UserEdit", @Model)
    
    
    <button class="k-button k-button-icon" type="submit" title="save changes"><span class="k-icon k-update"></span>Update</button>
}



<script type="text/kendo-template" id="message">
    <div class="k-widget k-tooltip k-tooltip-validation k-invalid-msg field-validation-error" style="margin: 0.5em; display: block; " data-for="#=field#" data-valmsg-for="#=field#" id="#=field#_validationMessage">
            <span class="k-icon k-warning"> </span>#=message#<div class="k-callout k-callout-n"></div></div>
</script>


<script type="text/javascript">
    <!--//

    var validationMessageTmpl = kendo.template($("#message").html());


    function onUserTypeChanged(e) {
        var userTypeId = $("#UserTypeId").data("kendoComboBox").value();
        ShowContainersByUserTypeId(userTypeId);
    }

    function ShowContainersByUserTypeId(userTypeId) {
        if (userTypeId == 4)
            $("#SalesManagerContainer").show();
        else
            $("#SalesManagerContainer").hide();

        if (userTypeId == 5)
            $("#SalesRepContainer").show();
        else
            $("#SalesRepContainer").hide();

        if (userTypeId == 6)
            $("#DoctorContainer").show();
        else
            $("#DoctorContainer").hide();
    }

    $('#patientedit-form').submit(function (e) {

        e.preventDefault();
        var validator = $("#patientedit-form").kendoValidator().data("kendoValidator");

        if (validator.validate() == false) {
            return;
        }

        var submit = $("#patientedit-form").find(':submit');
        submit.html(submit.html().replace("Submit", "Please Wait..."));
        submit.attr('disabled', 'disabled');

        var data = $(this).serialize();

        //debugger;

        $.post(this.action, data, function (result) {
            
            submit.html(submit.html().replace("Please Wait...", "Submit"));
            submit.removeAttr('disabled');

            if (result.success) {
                alert('Saved successfully!')
            }
            else {
                if (result.isEmailValid == false)
                    showErrorMessage('patientedit-form', 'Email', 'Email already in use');

                if (result.isPasswordValid == false)
                    showErrorMessage('patientedit-form', 'PasswordUnEncrypted', 'Passwords must be at least 8 characters & 1 digit.');

                if (result.isPasswordConfirmValid == false)
                    showErrorMessage('patientedit-form', 'PasswordConfirm', 'Password and Confirm PW do not match.');
            }
        });
    });

    function showErrorMessage(form, field, message) {
        //add the validation message to the form
        $("#" + form).find("[data-valmsg-for=" + field + "],[data-val-msg-for=" + field + "]")
            .replaceWith(validationMessageTmpl({ field: field, message: message }));
    }

    

    //-->
</script>