
//***********************************************//
//************Place Of Birth*********************//
//***********************************************//
$(document).on('change', '#p_province',function(){
    var province_id = $(this).val();
    $('#main-spinner').show();
    $.ajax({
        type: 'GET',
        url: '/realty/find-district-code/'+province_id,
        dataType:'json',
        data: {'province_id': province_id},
        success: function (data) {
            $("#p_district").empty();
            $.each(data, function (index, element) {
				$("#p_district").append('<option value="' + element.district_id + '">' + element.district_id+ " " + element.district_en + " " +element.district_km + '</option>');
            });
            $("#p_district").trigger("chosen:updated");
            $('#main-spinner').hide();

        }
    });
});
$(document).on('change', '#p_district',function(){
    var district_id = $(this).val();
    $('#main-spinner').show();
    $.ajax({
        type: 'GET',
        url: '/realty/find-commune-code/'+district_id,
        dataType:'json',
        data: {'district_id': district_id},
        success: function (data) {
            $("#p_commune").empty();
            $.each(data, function (index, element) {
				$("#p_commune").append('<option value="' + element.commune_id + '">' + element.commune_id+ " " + element.commune_en + " " +element.commune_km + '</option>');
            });
            $("#p_commune").trigger("chosen:updated");
            $('#main-spinner').hide();
        }
    });
});
$(document).on('change', '#p_commune',function(){
    var commune_id = $(this).val();
    $('#main-spinner').show();
    $.ajax({
        type: 'GET',
        url: '/realty/find-village-code/'+commune_id,
        dataType:'json',
        data: {'commune_id': commune_id},
        success: function (data) {
            $("#p_village").empty();
            $.each(data, function (index, element) {
				$("#p_village").append('<option value="' + element.village_id + '">' + element.village_id+ " " + element.village_en + " " +element.village_km + '</option>');
            });
            $("#p_village").trigger("chosen:updated");
            $('#main-spinner').hide();
        }
    });
});

	


$('.change_prefix_address').change(function(){
    var prefix_province = 'A';
    var prefix_district = 'S';
    var prefix_commune = 'D';
    var prefix_village = 'D';
    // var prefix_append = prefix_province +' /'+ prefix_district+' /'+ prefix_commune+' /'+ prefix_village+' ';
    //         $("input[name='address']").val(prefix_append);
    var p_village = $("select[name='p_village']").val();
    var p_commune = $("select[name='p_commune']").val();
    var p_district = $("select[name='p_district']").val();
    var p_province = $("select[name='p_province']").val();
    $.ajax({
        type: 'GET',
        url: '/realty/clients-prefix-address',
        dataType:'json',
        data: {
            'p_village': p_village,
            'p_commune': p_commune,
            'p_district': p_district,
            'p_province': p_province
        },
        success: function (data) {
          
            prefix_province = data.province[0].province_km;
            prefix_district = data.district[0].district_km;
            prefix_commune = data.commune[0].commune_km;
            prefix_village = data.village[0].village_km;

            var prefix_append = prefix_province +' /'+ prefix_district+' /'+ prefix_commune+' /'+ prefix_village+' ';
            $("input[name='client_address']").val(prefix_append);
        }

    });
    

});

