
function getMakes(target) {
	/* 
	  ami megjelenik, egyedi select elemek, select input
	 Findbox:   mySelectText0,optionsDiv0,MakeSelect,0
	 Filterbox: 
	*/
	switch(target) {
		case 1: var target2 = 'mySelectText6,optionsDiv6,MakeSelect2,6'; break;
		default: var target2 = 'mySelectText0,optionsDiv0,MakeSelect,0';
	}
	/* --- */
	var commercial = /^.*?product_list_comm.php.*$/.test(document.location.href)*1;
	var target_send = target2;
	target2 = target2.split(',');
	getModel(false);
	jQuery("#"+target2[0]).html('Loading...');
	jQuery.ajax({
      url: "find_box_ajax.php",
      type: "GET",
      data: ({action: 'getMakes', type: jQuery("#type_new").attr('checked')?'new':'used' , rand : Math.random() , target: target_send , commercial:commercial }),
      dataType: "json",
      success: function(obj){
		var target2 = obj.target.split(',');
		var obj = obj.data; 
		
		jQuery("#"+target2[0]).html('** Select make **');
		jQuery("#"+target2[1]).html('');
		jQuery("#"+target2[1]).append("<p><a href=\"javascript:showOptions("+target2[3]+"); selectMe('"+target2[2]+"',0,"+target2[3]+");\">** Any make **</a></p>");
		if(obj.length > 0) {
			for(var i=0;i<obj.length;i++) {
				jQuery("#"+target2[1]).append("<p><a href=\"javascript:showOptions("+target2[3]+"); selectMe('"+target2[2]+"',"+(i+1)+","+target2[3]+");\">"+obj[i].text+"</a></p>");	
			} // end for
				
		} // end if 
		
		jQuery("#"+target2[2]).html('');
		jQuery("#"+target2[2]).append("<option value=\"-1\">** Any make **</option>");
		if(obj.length > 0) {
			for(var i=0;i<obj.length;i++) {
				jQuery("#"+target2[2]).append("<option "+((nowmodel==obj[i].id)?'selected="selected"':'')+" value=\""+obj[i].id+"\">"+obj[i].text+"</option>");	
				if(nowmodel==obj[i].id) jQuery("#"+target2[0]).html(obj[i].text);
			} // end for
				
		} // end if 
        
      } // end success
 	  } // end ajax {} object 
	); // end ajax function
} // end function

function getModel(id,target) {
	switch(target) {
		case 1: var target2 = 'mySelectText7,optionsDiv7,ModelSelect2,7'; break;
		default: var target2 = 'mySelectText1,optionsDiv1,ModelSelect,1';
	}
	var target_send = target2;
	target2 = target2.split(',');
	jQuery("#"+target2[0]).html('Loading...');
	if(id==false) {
		jQuery("#"+target2[0]).html('----');
		jQuery("#"+target2[2]).html('----');
		jQuery("#"+target2[1]).html('----');
		return;
	}
	var commercial = /^.*?product_list_comm.php.*$/.test(document.location.href)*1;
	
	jQuery.ajax({
      url: "find_box_ajax.php",
      type: "GET",
      data: ({action: 'getModels', id : id ,cv: jQuery("#type_cv").attr('value') , type: jQuery("#type_new").attr('checked')?'new':'used' , rand : Math.random() , target: target_send , commercial: commercial }),
      dataType: "json",
      success: function(obj){
		var target2 = obj.target.split(',');
		var obj = obj.data; 
		
		jQuery("#"+target2[0]).html('** Select model **');
		jQuery("#"+target2[1]).html('');
		jQuery("#"+target2[1]).append("<p><a href=\"javascript:showOptions("+target2[3]+"); selectMe('"+target2[2]+"',0,"+target2[3]+");\">** Any model **</a></p>");
		
		if(obj.length > 0) {
			for(var i=0;i<obj.length;i++) {
				jQuery("#"+target2[1]).append("<p><a href=\"javascript:showOptions("+target2[3]+"); selectMe('"+target2[2]+"',"+(i+1)+","+target2[3]+");\">"+obj[i].text+"</a></p>");	
			} // end for
				
		} // end if 
		
		jQuery("#"+target2[2]).html('');
		jQuery("#"+target2[2]).append("<option value=\"-1\">** Any model **</option>");
		if(obj.length > 0) {
			for(var i=0;i<obj.length;i++) {
				jQuery("#"+target2[2]).append("<option "+((nowmodel==obj[i].id)?'selected="selected"':'')+" value=\""+obj[i].id+"\">"+obj[i].text+"</option>");	
				if(nowmodel==obj[i].id) jQuery("#"+target2[0]).html(obj[i].text);
			} // end for
				
		} // end if 
        
      } // end success
 	  } // end ajax {} object 
	); // end ajax function
} // end function

function renewModel(type) {
	if(type == null || type == 'undefined') type = jQuery("input[name=type]:checked").attr('value');
	getMakes(0);
	getModel(false,0);
}	
function renewMakeModel(type) {
	if(type == null || type == 'undefined') type = jQuery("input[name=type]:checked").attr('value');
	getMakes(0);
	getModel(-1,0);
}
function clearSelections() {
	jQuery.ajax({
		url: 'find_box_ajax.php',
		type: 'GET',
		data: ({action: 'clearSelections', rand : Math.random() }),
        success: function(obj){
			document.location.href = document.location.href;
		}
	})	
}