$(document).ready(function() {
	
	var submitSrc = $("#PreviewButton").attr("src", BASE_FOLDER + "/images/preview.gif").attr("value", "previewDevice").attr("name", "previewDevice");
	$("#Device-Form").attr("action",BASE_PATH + "/getrecycling");
	/**
	 * Select Type
	 */
	
	$("#GetRecycling_type").change(function () {
		var type = $(this).selectedValues()[0];
		
		if(type != ""){
			$.post(BASE_PATH + '/site/ajaxPopulateMake', {type: type}, function(response) {
				var options = '';
				var makes = $.evalJSON(response);
				for(i = 0; i < makes.length; i++) {
					options += '<option value="' + makes[i].make  + '">' + makes[i].name + '</option>';
				}
				$("#GetRecycling_make").html(options);
				$("#GetRecycling_make").removeAttr('disabled');
			});
		}
		else {
			$("#GetRecycling_make").attr('disabled', 'disabled')
			$("#GetRecycling_device").attr('disabled', 'disabled');
		}
	});
	
	/**
	 * Select Make
	 */
	$("#GetRecycling_make").change(function () {
		var make = $(this).selectedValues()[0];
		var type = $("#GetRecycling_type").selectedValues()[0];
		if(make != "" && type != ""){
			$.post(
				BASE_PATH + '/site/ajaxPopulateDevice', {
					type: type,
					make: make 
				},
				function(response) {
					var options = '';
					var devices = $.evalJSON(response);
					for(i = 0; i < devices.length; i++) {
						options += '<option value="' + devices[i].id  + '">' + devices[i].name + '</option>';
					}
					$("#GetRecycling_device").html(options);
					$("#GetRecycling_device").removeAttr('disabled');
				}
			);
		}
		else {
			$("#GetRecycling_device").attr('disabled', 'disabled');
		}
	});
	
});