$(function () {

	$(".chosen-select").on('change', function(){
		$('#asset-filter-form').submit();
	});

	$(".select2").on('change', function(){
		$('#asset-filter-form').submit();
	});

	$('#data_1 .input-group.date').datepicker().on('changeDate',function(){
	    $('#asset-filter-form').submit();
	});

	$('#data_1 .input-group.date').datepicker().on('clearDate',function(){
	    $('#asset-filter-form').submit();
	});

	$('#asset_age').on('keyup change', function() {
		$('#asset-filter-form').submit();
	});

	$("#asset_age_unit").on('change', function(){
		$('#asset-filter-form').submit();
	});

	$(".filter-field").on('change', function(){
		$('#asset-filter-form').submit();
	});

	$(".filter-field-user").on('change', function(){
		$('#asset-filter-form').submit();
	});

	$(".filter-field-location").on('change', function(){
		$('#asset-filter-form').submit();
	});




	$("#asset_type").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:'it'},
	    	url: "/assets-filter/listHardware",
 	   		success: function(data) {
 	   			$('#make_and_model').empty();

				$.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.hardware);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('make_and_model').appendChild(option);
				});
        	}
 	 	});
	});

	$("#make_and_model").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:'it'},
	    	url: "/assets-filter/listtechnics",
 	   		success: function(data) {
 	   			$('#technical_spec').empty();

				$.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.details);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('technical_spec').appendChild(option);
				});
        	}
 	 	});
	});

	$("#asset_type_mobile").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:'mobile'},
	    	url: "/assets-filter/listHardware",
 	   		success: function(data) {
 	   			$('#make_and_model_mobile').empty();

				$.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.hardware);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('make_and_model_mobile').appendChild(option);
				});
        	}
 	 	});
	});

	$("#make_and_model_mobile").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:'mobile'},
	    	url: "/assets-filter/listtechnics",
 	   		success: function(data) {
 	   			$('#technical_spec_mobile').empty();

				$.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.details);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('technical_spec_mobile').appendChild(option);
				});
        	}
 	 	});
	});

})