$(document).ready(function() {
		var $restricted_tech_codes = "/technology/01/technology/02/technology/10/technology/12/technology/13/technology/25/technology/36/technology/38/technology/51/technology/44/restricted/true";
		var $type = "/type/M";

		$obj_part = $('#part_search');
		$obj_brand = $('#printer_brand');
		$obj_type = $('#printer_type');
		$obj_model = $('#printer_model');
		$obj_find = $('#find_part_no');
		$consumable_form = $('#consumable_search');
		
		reset_selectors();
		
		
		// First Instance
		$url = "brand" + $restricted_tech_codes + $type;
		advanced_search_update($obj_brand, $url);
		
		$obj_brand.change(function() {
			if ($(this).val() != "") {
				// Update technology selector
				$url = "technology/brand/" + $(this).val() + $restricted_tech_codes + $type;
				advanced_search_update($obj_type, $url);
				if ($obj_model.parent().css('display') != 'none') {
					$obj_model.parent().hide();
				}
				if ($obj_type.parent().css('display') == 'none') {
					toggle_selector($obj_type);
				}
			}
		});
					
		$obj_type.change(function() {
			if ($(this).val() != "") {
				// Update the models.
				$url = "all/brand/"+ $obj_brand.val() +"/technology/" + $(this).val() + $type;
				advanced_search_update($obj_model, $url);
				toggle_selector($obj_model);
			}
		});
			
		$obj_model.change(function() {
			if ($(this).val() != "") {
				$consumable_form.attr('action', $consumable_form.attr('action') + "/" + $(this).val());
				$consumable_form.submit();
			}
		});	
			
		$obj_find.click(function(){
			$consumable_form.attr('action', $consumable_form.attr('action') + "/" + $obj_part.val());
			$consumable_form.submit();
			return false;
		});
		
		$obj_part.keydown(function(event){
			if (event.keyCode == 13) {
				//$consumable_form.attr('action', $consumable_form.attr('action') + "/" + $obj_part.val());
				$consumable_form.submit();
			}

		});
		
		function reset_selectors() {
			$obj_type.parent().hide();
			$obj_model.parent().hide();	
		}	
			
		function toggle_selector($obj) {				
			$obj.parent().slideToggle('slow');
		}
});
