$(document).ready(function(){

  $('.select-tags').select2();

  $('#assetname_groups').change(function () {
    var groupId = $(this);    
    // Request the neighborhoods of the selected city.
    $.ajax({
        url: $('#path_assetname_groups').data("href"),
        type: "GET",
        dataType: "JSON",   
        data: {
            groupId: groupId.val()
        },         
        success: function (subgroups) {

            var subgroupSelect = $("#assetname_subgroup");

            // Remove current options
            subgroupSelect.html('');
            
            // Empty value ...
            subgroupSelect.append('<option value> Select a Subgroup of ' + groupId.find("option:selected").text() + ' ...</option>');
            
            
            $.each(subgroups, function (key, subgroup) {
              subgroupSelect.append('<option value="' + subgroup.id + '">' + subgroup.name + '</option>');
            });
             
        
        },
        error: function (err) {
            alert(err.responseText);
        }
    });
});


$('#assetregister_groups').change(function () {
    var groupId = $(this);    
   
    // Request the neighborhoods of the selected city.
    $.ajax({
        url: $('#path_assetregister_groups').data("href"),
        type: "GET",
        dataType: "JSON",  
        data: {
            groupId: groupId.val()
        },         
        success: function (subgroups) {

            var subgroupSelect = $("#assetregister_subgroup");

            // Remove current options
            subgroupSelect.html('');
            
            // Empty value ...
            subgroupSelect.append('<option value> Select a Subgroup of ' + groupId.find("option:selected").text() + ' ...</option>');
                        
            $.each(subgroups, function (key, subgroup) {
              subgroupSelect.append('<option value="' + subgroup.id + '">' + subgroup.name + '</option>');
            });
                     
        },
        error: function (err) {
            alert(err.responseText);
        }
    });
});


$('#assetregister_subgroup').change(function () {
    var subGroupId = $(this);
    
    // Request the neighborhoods of the selected city.
    $.ajax({ 
        url: $('#path_assetregister_subgroup').data("href"),
        type: "GET",
        dataType: "JSON",  
        data: {
            subGroupId: subGroupId.val()
        },         
        success: function (assetnames) {

            var assetnameSelect = $("#assetregister_assetname");

            // Remove current options
            assetnameSelect.html('');
            
            // Empty value ...
            assetnameSelect.append('<option value> Select a Asset Name of ' + subGroupId.find("option:selected").text() + ' ...</option>');
            
            
            $.each(assetnames, function (key, assetname) {
                assetnameSelect.append('<option value="' + assetname.id + '">' + assetname.name + '</option>');
            });
             
        
        },
        error: function (err) {
            alert(err.responseText);
        }
    });
});


$('#assetregister_assetname').change(function () {
    var assetnameId = $(this);   
    // Request the neighborhoods of the selected city.
    $.ajax({
        url: $('#path_assetregister_assetname').data("href"), 
        type: "GET",
        dataType: "JSON",  
        data: {
            assetnameId: assetnameId.val()
        },         
        success: function (units) {

            var unitSelect = $("#assetregister_unit");

            // Remove current options
            unitSelect.html('');
            
            // Empty value ...
           // unitSelect.append('<option value> Select a Unit of ' + assetnameId.find("option:selected").text() + ' ...</option>');
            
            
            $.each(units, function (key, unit) {
                unitSelect.append('<option value="' + unit.id + '">' + unit.name + '</option>');
            });
             
        
        },
        error: function (err) {           
            alert(err.responseText);
        }
    });
});



//Reports Start Here


$('#form_groups').change(function () {
    var groupId = $(this);    
   
    // Request the neighborhoods of the selected city.
    $.ajax({
        url: $('#path_form_groups').data("href"),
        type: "GET",
        dataType: "JSON",  
        data: {
            groupId: groupId.val()
        },         
        success: function (subgroups) {

            var subgroupSelect = $("#form_subgroup");

            // Remove current options
            subgroupSelect.html('');
            
            // Empty value ...
            subgroupSelect.append('<option value> Select a Subgroup of ' + groupId.find("option:selected").text() + ' ...</option>');
            
            
            $.each(subgroups, function (key, subgroup) {
              subgroupSelect.append('<option value="' + subgroup.id + '">' + subgroup.name + '</option>');
            });
             
        
        },
        error: function (err) {
            alert(err.responseText);
        }
    });
});


$('#form_subgroup').change(function () {
    var subGroupId = $(this);
    
    // Request the neighborhoods of the selected city.
    $.ajax({
        url: $('#path_form_subgroup').data("href"),
        type: "GET",
        dataType: "JSON",  
        data: {
            subGroupId: subGroupId.val()
        },          
        success: function (assetnames) {

            var assetnameSelect = $("#form_assetname");

            // Remove current options
            assetnameSelect.html('');
            
            // Empty value ...
            assetnameSelect.append('<option value> Select a Asset Name of ' + subGroupId.find("option:selected").text() + ' ...</option>');
            
            
            $.each(assetnames, function (key, assetname) {
                assetnameSelect.append('<option value="' + assetname.id + '">' + assetname.name + '</option>');
            });
             
        
        },
        error: function (err) {
            alert(err.responseText);
        }
    });
});

//Reports End Here


});