$(document).ready(function(){
	$("div#header a.search").after('<span id="headerselectbox"><span>Select by printer make, type & model:</span><br /><select style="margin-top: 3px; min-width: 100px; margin-right: 4px;" id="searchbox1"><option>Step 1</option></select><select style="min-width: 100px; margin-right: 4px;" disabled="disabled" id="searchbox2"><option>Step 2</option></select><select id="searchbox3" style="min-width: 100px;" disabled="disabled"><option>Step 3</option></select></span>');
				
	$("#searchbox1").change(function() {
		lastNumber = $(this).val();
		if($(this).val() != 'selectone')
		{
			getList($(this).val(), 2);
		}
	});
	$("#searchbox2").change(function() {
		lastNumber = $(this).val();
		if($(this).val() != 'selectone')
		{
			getList($(this).val(), 3);
		}
	});
	$("#searchbox3").change(function() {
		lastNumber = $(this).val();
		if($(this).val() != 'selectone')
		{
			getList($(this).val(), 4);
		}
	});	
getList(0, 1);
});

var lastNumber = -1;
function getList(id, box)
{
	$.getJSON("/ajax_selectboxsearch.php?id="+id,
        function(data) {
			if(data.length)
			{
				$("#searchbox" + box).html('');
				$("#searchbox" + box).append('<option value="selectone">Select</option>');
				jQuery.each(data, function() {
					$("#searchbox" + box).append('<option value="' + this[0] + '">' + this[1] + '</option>');
				});
				//if(box == 2)
				//{
				//	$("#searchbox3").attr('disabled', 'disabled');
				//	$("#searchbox3").html('<option>------</option>');
				//}
				if(lastNumber > 0)
					$("#searchbox"+box).attr('disabled', '');
			}
			else
			{
				top.location = "/home.php?cat="+lastNumber;
			}
			
    });
}
