$(document).ready(function () {

    
    $('#MainContent_lblError').hide();
    try {
        $("#MainContent_Panel1").css('height', $(window).height() - 20);
    } catch (err) { }



    $('#txt_repassword').on('input', function (event) {
      
        let password = $('#txt_password').val();
        let repassword = $('#txt_repassword').val();

        if(password!=repassword)
        {
            $('#MainContent_lblError').html("Information password is not match.");
            $('#MainContent_lblError').show();

        }
        else
        {
            $('#MainContent_lblError').html("");
            $('#MainContent_lblError').hide();

        }

    });


    getdata();


});

function save()
{
    let password = $('#txt_password').val();
    let repassword = $('#txt_repassword').val();

    if (password != repassword) {
        $('#MainContent_lblError').html("Information password is not match.");
        $('#MainContent_lblError').show();

    }
    else
    {
        $('#MainContent_lblError').html("");
        $('#MainContent_lblError').hide();
        
        if($('#MainContent_txt_email').val().indexOf('@')==-1)
        {
            alert('Is wrong format.');
            $('#MainContent_txt_email').focus();
        }
        else
        {
            let docno = $('#MainContent_txt_docnostart').val();
            let hostip = $('#MainContent_txt_hostip').val();
            let smtp = $('#MainContent_txt_smtpaddress').val();
            let email = $('#MainContent_txt_email').val();
            let port = $('#MainContent_txt_port').val();
            let password = $('#txt_password').val();


            $.ajax({
                type: "POST",
                url: "Setup.aspx/save",
                data: '{docno:"' + docno + '",hostip:"'+hostip+'",smtp:"'+smtp+'",email:"'+email+'",password:"'+password+'",port:"'+port+'"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {

                    if (response.d == "") {

                        alert("Successfully recorded.");

                    }
                    else
                    {
                        alert(response.d);

                    }

                  




                },
                failure: function (response) {

                },
                error: function (response) {

                }
            });



        }

    }


}


function getdata() {
    $('#MainContent_txt_docnostart').val("");
    $('#MainContent_txt_hostip').val("");
    $('#MainContent_txt_smtpaddress').val("");
    $('#MainContent_txt_email').val("");
    $('#MainContent_txt_port').val("");
    $('#txt_password').val("");
    $('#txt_repassword').val("");


    $.ajax({
        type: "POST",
        url: "Setup.aspx/getdata",        
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {

            if (response.d.indexOf('|') != -1)
            {
                let arr = response.d.split('|');

                $('#MainContent_txt_docnostart').val(arr[0]);
                $('#MainContent_txt_hostip').val(arr[1]);
                $('#MainContent_txt_smtpaddress').val(arr[2]);
                $('#MainContent_txt_email').val(arr[3]);
                $('#MainContent_txt_port').val(arr[5]);
                $('#txt_password').val(arr[4]);
                $('#txt_repassword').val(arr[4]);
            }
           




        },
        failure: function (response) {

        },
        error: function (response) {

        }
    });


}