﻿$(document).ready(function() {

    $('#btnUpdate').click(function() {

        $('#spLoading').show();
        var objDetails = {};
        $('input[type=text]').each(function() {
            objDetails[this.name] = this.value;
        });

        var jsObj = { 'obj': objDetails };

        $.ajax({
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(jsObj),
            dataType: "json",
            type: "POST",
            url: "EmbedJS.asmx/fnUpdateDetails",
            success: fnSuccess,
            error: function(xhr, status, errorThrown) {
                alert('Error' + errorThrown);
            }
        });

        function fnSuccess(response) {
            var obj = response.d;
            $('#spLoading').hide();
            $('#divMessage').html(obj);
        }
    });


    //Fetch Details
    $('#btnFetch').click(function() {

    $('#spLoadingFetch').show();

        $.ajax({
            contentType: "application/json; charset=utf-8",
            data: "{}",
            dataType: "json",
            type: "POST",
            url: "EmbedJS.asmx/fnFetchDetails",
            success: fnSuccess,
            error: function(xhr, status, errorThrown) {
                alert('Error' + errorThrown);
            }
        });

        function fnSuccess(response) {
            $('#spLoadingFetch').hide();
            var obj = response.d;
            $('#lblFirstName').html(obj.fname);
            $('#lblLastName').html(obj.lname);
            $('#lblCity').html(obj.city);
            $('#lblState').html(obj.state);
            $('#lblCountry').html(obj.country);
        }
    });
});