       var url_make_xkey = '';
	   var x = '';
	   var partner_id="default";
       var ix_url = "http://autom"+"otix.net/usedautoparts-search.html?jsoncallback=?";
       var ix_class_name = "ix-form-data";
       var target_urls = {
          "used_transmissions":"http://www.auto"+"motix.net/usedtransmissions/[year_key]-[make_key]-[model_key]-inventory.html",
          "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"
       };
	   
       function loadData(target_id,op_code, depend){	      
          var values = {"target":target_id,"op_code": op_code};		  
          $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().siblings(":first").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().siblings(":first").children(":first").addClass("next");			  
          }
       }
       
       function completeSearch(part_type){
            var target_url = target_urls[part_type];
            if (target_url==null) target_url = target_urls['default'];
            var $inputs = $('.'+ix_class_name);
            $inputs.each(function() {
                 if ($(this).val()!=''){
                    var name= this.name;
                    var value = $(this).val();
                    while (target_url.indexOf("["+name+"]")>=0)
                        target_url = target_url.replace("["+name+"]",value);
                 }        
            }); 
            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().siblings(":first").children(":first").removeClass("next")
				 $("#"+items[i]).parent().siblings(":first").children(":first").removeClass("filled")
              }			  
           }	
        }
        
        function goToUrl(provider_key,make_key){
            if (provider_key==null || provider_key=='')
                location.href="http://www.auto"+"motix.net/?campaign="+partner_id;
            else if (make_key==null || make_key=='')
                location.href="http://www.auto"+"motix.net/"+provider_key+"/?campaign="+partner_id;
            else
                location.href="http://www.auto"+"motix.net/"+provider_key+"/"+make_key+"-inventory.html?campaign="+partner_id;
        }
        
        function goToPartLocator(make_key){
            location.href="http://info.auto"+"motix.net/partlocator.html?make="+make_key+"&campaign="+partner_id;
        }
