	   var partner_id = '';
	   var provider = 'used_engines';
	   var url_make_xkey = '';
	   var url_model_xkey = '';
	   var url_year_xkey = '';
	   var hashFuncs = new Array();
	   var hashNR = new Array();
	   var partner_id="default";
       var ix_url = "http://autom"+"otix.net/usedautoparts-search.html?jsoncallback=?";
       var ix_class_name = "ix-form-data";
       var ix_class_name_bottom = "ix-form-data-bottom";
       var target_urls = {
          "used_engines":"http://www.auto"+"motix.net/usedengines/[year_key]-[make_key]-[model_key]-inventory.html",
          "default":"http://www.auto"+"motix.net/usedautoparts/[year_key]-[make_key]-[model_key]-[part_type_key]-inventory.html",
          "nopart":"http://www.auto"+"motix.net/usedautoparts/[year_key]-[make_key]-[model_key]-inventory.html" 
       };
	   
       function loadData(target_id,op_code, depend, class_name){		
          var values = {"target":target_id,"op_code": op_code};
		  if (class_name){
			$inputs = $("."+class_name);
		  } else{
            $inputs = $("."+ix_class_name);
		  }
          $inputs.each(function() {
    			values[this.name] = $(this).val(); 
          });
          clearDependencies(depend);
		  $.getJSON(ix_url,values, onLoad);									  
       }   
       
	   function changeArrow(filled_id, thisValue){	
		  var toChange = $("#"+filled_id).parent().prev().children(":first");		    
		  if (thisValue){
			toChange.removeClass("next");
			toChange.addClass("filled");
		  } else{
		    toChange.removeClass("filled");
			toChange.addClass("next");
		  }
	   }
	   
       function onLoad(json){
          if (json.target_id){
              target_id = json.target_id;
			  
              $("#"+target_id).empty();
              $("<option>Select..</option>").attr("value","").appendTo($("#"+target_id));
              $.each(json.items, function(key, val) {
                  var cOption = $("<option></option>") 
                  .attr("value", key) 
                  .html(val) 
                  .appendTo($("#"+target_id));
              });
              $("#" + target_id).removeAttr("disabled");
        	  $("#" + target_id).removeClass("disabled");	
			  $("#" + target_id).parent().prev().children(":first").addClass("next");
			  //set page's make_key and model_key selected
			  switch (target_id){
				case "make_key" :
					$("#"+target_id+" > option[value="+url_make_xkey+"]").attr("selected", "selected");
					break;
				case "make_keyb":
					$("#"+target_id+" > option[value="+url_make_xkey+"]").attr("selected", "selected");
					break;
				case "model_key" :
					$("#"+target_id+" > option[value="+url_model_xkey+"]").attr("selected", "selected");
					break;
				case "model_keyb":
					$("#"+target_id+" > option[value="+url_model_xkey+"]").attr("selected", "selected");
					break;
				case "year_key" :
					var temp = $("#"+target_id+" > option[value="+url_year_xkey+"]");
					if (temp.html() != null){
						temp.attr("selected", "selected");
						changeArrow('year_key', url_year_xkey);
					}
					break;
				case "year_keyb":
					var temp = $("#"+target_id+" > option[value="+url_year_xkey+"]");
					if (temp.html() != null){
						temp.attr("selected", "selected");
						changeArrow('year_keyb', url_year_xkey);
					}
					break;
			  }			  
          }		  
       }
       
       function completeSearch(part_type, class_name){
            var target_url;
			if (part_type != ''){
				target_url = target_urls[part_type];
				if (target_url==null) target_url = target_urls['default'];
			} else{
				target_url = target_urls['nopart'];
			}
            var $inputs;
			if (class_name){
				$inputs = $('.'+class_name);
			} else{
				$inputs = $('.'+ix_class_name);
			}
            $inputs.each(function() {
				var name= this.name;
				var value = $(this).val();
				while (target_url.indexOf("["+name+"]")>=0){
					if (value){
						target_url = target_url.replace("["+name+"]",value);
					} else{
						target_url = target_url.replace("["+name+"]-",'');
					}
				}                 
            }); 
			if (target_url == 'http://www.automotix.net/usedtransmissions/inventory.html'){
				target_url = "http://www.auto"+"motix.net/usedtransmissions/";
			}
			location=target_url+"?campaign="+partner_id;
        }
		
        function clearDependencies(depend){
           if (depend!='' && depend != null){
              var items = depend.split(" ");
              for (i=0; i<items.length; i++){
                 if (items[i]=='') continue;
				 
                 $("#"+items[i]).attr("disabled","true").addClass("disabled").parent().addClass("disabled");
                 $("#"+items[i]).empty();				 
                 $("<option>Select..</option>").attr("value","").appendTo($("#"+items[i]));						
				 $("#"+items[i]).parent().prev().children(":first").removeClass("next")
				 $("#"+items[i]).parent().prev().children(":first").removeClass("filled")
              }			  
           }	
        }
