	/**
    * Edit the getUrlMod function if you need to add anything to the beginning of the url's used in this
    * file. For instance if you want to load from another website you would set url_mod to "http://anothersite.com"
   **/
   function getUrlMod()
   {
      var url_mod = "/steahlyoffroad.com";
      return url_mod;
   }
   
   function reset() {
		
		//alert("reset");
		var f = document.getElementById('search');
		
		for (var i=0; i < f.elements.length; i++) {
  				var element = f.elements[i];
  		
  				//alert(element.id );
  			 	
  					//var  l = document.getElementById(element.id);
 					//for (i=0;i<l.options.length;i++){ 
					//	l.options[i].selected=false;  
					//}
  				
		}
		
	}	
	
	
	function getProducts(obj,catid) {
		
		//alert("get products " + obj.value);
		var f = document.getElementById('search');
		var searchVals="";
		for (var i=0; i < f.elements.length-1; i++) {
  				var element = f.elements[i];
  				searchVals+=element.value;
  				searchVals+=",";
  				//alert(element.value);
		}
		searchVals=searchVals.slice(0,-1);
		
		
		Ext.Ajax.request({
 			
    	url: this.getUrlMod()+'/index.php/search/index/getProductIds?q='+searchVals+'&c='+catid,
    	method:'GET', 
    	success : function(r){
    		
			var obj = Ext.decode(r.responseText);
			getResult(obj,catid);
        	
    	},
   			failure: function(response, opts) {
      		console.log('server-side failure with status code ' + response.status);
   		}
		});
		
		
	}	
	function getResult(obj,catid) {
	
			//alert(obj.prods.toString());
			
			window.location = this.getUrlMod()+'/search/index/result?ids='+obj.prods.toString()+'&cat='+catid;
			
			
			//Ext.Ajax.request({
 			
    		//url: 'index.php/search/index/result?'+obj.prods.toString(),
    		//method:'GET', 
    		//success : function(r){
    		
    			
    			//document.getElementById("main").innerHTML=r.responseText;
        	
        		
        	
    		//},
   				//failure: function(response, opts) {
      			//console.log('server-side failure with status code ' + response.status);
   			//}
			//});
			
	}
	
	function search1(fn,pos,catid) {
   
 		//alert("here " +fn);
 		//var fn="root";
 		//var val=document.search_form.root.options[document.search_form.root.selectedIndex].value;
 		//alert("try this " +document.getElementById(fn)[document.getElementById(fn).selectedIndex].value);
 		var val=document.getElementById(fn)[document.getElementById(fn).selectedIndex].value;
 		if(val==-1) {return;}
 		
 		Ext.Ajax.request({
 			
    	url: this.getUrlMod()+'/index.php/search/index/search?v='+val+'&p='+pos+'&c='+catid,
    	method:'GET', 
    	success : function(r){
    		
    		//alert("returned "+r.responseText);
    		if(r.responseText!='nodata') {

    			var obj = Ext.decode(r.responseText);	
    			//alert('parse json');
    			updateSelect(obj.list.toString());
    		}
        	
    	},
   			failure: function(response, opts) {
      		console.log('server-side failure with status code ' + response.status);
   		}
		});
 	
 	}	
	
	function search(selectobj,pos,catid) {
 	//alert("here");
 	
 		var val=document.search_form.root.options[document.search_form.root.selectedIndex].value;
 		if(val==-1) {return;}
 	
 
 		//alert("here " + val+" "+pos+" "+catid);
 		
 		
 		Ext.Ajax.request({
 			
    	url: this.getUrlMod()+'/index.php/search/index/search?v='+val+'&p='+pos+'&c='+catid,
    	method:'GET', 
    	success : function(r){
    		
    		//alert("returned "+r.responseText);
    		if(r.responseText!='nodata') {

    			var obj = Ext.decode(r.responseText);	
    			//alert('parse json');
    			updateSelect(obj.list.toString());
    		}
        	
    	},
   			failure: function(response, opts) {
      		console.log('server-side failure with status code ' + response.status);
   		}
		});
			
 	}
 	
 	function updateSelect(list) {
 	
 			
 			var allVals=list.split(";");
 			var tagVals=allVals[1];
 			tagVals=tagVals.substr(1);
 			tags=tagVals.split(',');
 			
 			for (i=0;i<tags.length;i++){ 
				//alert(tags[i]);
				var t = document.getElementById(tags[i]);
				for (var y=t.options.length -1;y>=0;y--){
					if(typeof(t.options[y]) != "undefined") {
						//alert("reset options " +t.id);
						t.options[y]=null;
					} 
				}
				
			}
 			
 			
 			var alllistVals=allVals[0];
 			listVals=alllistVals.split(",");
 			listVals=listVals.slice(0,-1);
 			
 			//alert('update select '+listVals);
 	
 			var  l = document.getElementById(listVals[0]);//root
 			for (i=0;i<l.options.length;i++){ 
				l.options[i].selected=false;  
			}
 			
 			//alert('update '+ l.value);
 			
 			for(i = 0; i < listVals.length; i++){
 			
 					//alert(listVals[i]);	
 					 var val=listVals[i].split('|');
 					 if(i==0){			
 					 	l.options[i]=new Option(val[0], -1, true, false);
 					 } else {
 					 	l.options[i]=new Option(val[0], val[1], true, false);
 					 }
 			}
 	}	 
 	Ext.onReady(function() {
		
    	Ext.select('div.spinner').hide();
    	
	});
 	
 	function spinnerOn() {
		
    	Ext.select('div.spinner').show();
		
	}
	function spinnerOff() {
		
    	Ext.select('div.spinner').hide();
    	
	}
	
	Ext.Ajax.on('beforerequest', function () {spinnerOn();});
	Ext.Ajax.on('requestcomplete', function () {spinnerOff();});
	Ext.Ajax.on('requestexception', function () {alert("request exception");});
	Ext.Ajax.on('requestexception', function () {spinnerOff();});
	

