	   var partner_id = '';
	   var provider = 'used_engines';
	   var url_make_xkey = '';
	   var url_model_xkey = '';
	   var url_year_xkey = '';
	   var marvel;
	   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_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",
          "nopart":"http://www.auto"+"motix.net/usedautoparts/[year_key]-[make_key]-[model_key]-inventory.html" 
       };
	   
	   function Marvel(func_array_, non_rec_funcs_){
		//function keeps funcs, which should be called from onLoad recursively
		//after that calls nonrecursive array of functions
			this.non_rec_funcs = non_rec_funcs_;
			this.func_array = func_array_;			
			this.cnt = 0;
			this.next = function(){
				if (this.cnt < this.func_array.length){					
					eval(this.func_array[this.cnt]);
					this.cnt++;
				} else{
					if (this.non_rec_funcs != null){
						for (i=0; i<this.non_rec_funcs.length; i++){
							eval(this.non_rec_funcs[i]);
						}
					this.non_rec_funcs = null;
					}
				}
			}
		}
	   
       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;
			  }			  
          }
		  //continue loading data
		  if (marvel) marvel.next();
       }
       
       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")
              }			  
           }	
        }
        
		function gotoIX(sitename, dest){
				location.href = "http://www.auto"+"motix.net/"+sitename+"/"+dest+"-inventory.html?campaign="+partner_id;
		}
		
        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;
        }
