//
//Maffo Search Module Plugin
//For use with 68Classifieds v4 + Maffo Location Module
//Written by Andy Mathieson 
//Email maffo@classified-software.co.uk
//Online manaual available at
//http://www.classified-software.co.uk
//
function displaySec(id){
	display_element='ajxresponse';
	var url="modules/maffo_search/includes/ajax/extra_fields.php?";
	var query="f=1&i="+id;
	sendRequested(query,url,true);
	document.getElementById('optResponse').innerHTML = '';
}

function displayNewSec(opt){
	display_element='optResponse';
	var url="modules/maffo_search/includes/ajax/extra_fields.php?";
	var query="f=2&i="+opt;
	document.getElementById('optResponse').innerHTML = '';
	sendRequested(query,url,true);
}
function process_cats(id,element){
	clear_excess_cats(element);
	if(document.getElementById(element)){
		if(id==0){
			document.getElementById(element).innerHTML = '';
		}
		else{
			display_element=element;
			var url="modules/maffo_search/includes/ajax/ajax_drilldown.php?";
			var query="i="+id+"&e="+element;
			sendRequested(query,url,true);
		}
	}
}

function clear_excess_cats(element){
		var id =parseFloat(element.substr(8));
		id++;
		while (id<100){
			if(document.getElementById('results_'+id)){
				document.getElementById('results_'+id).innerHTML = '';
			}
			else{
				break;
			}
			id++;
		}
}
function country_change(id){
	remove_states();
	remove_cities();
	// Lets see if there are any states
	if(id>0){
		display_element='state_dropdown_td';
		var url="modules/maffo_search/includes/ajax/get_locations.php?";
		var query="l=states&i="+id;
		sendRequested(query,url,false);
		if  (document.getElementById('state_dropdown_td').innerHTML)
		{
			if  (document.getElementById('state_text_td').innerHTML)
			{
				document.getElementById('state_text_td').innerHTML = 'State:';
			}
		}
	}
}

function state_change(id){
	remove_cities();
	// Lets see if there are any cities
	if(id>0){
		display_element='city_dropdown_td';
		var url="modules/maffo_search/includes/ajax/get_locations.php?";
		var query="l=cities&i="+id;
		sendRequested(query,url,false);
		if  (document.getElementById('city_dropdown_td').innerHTML)
		{
			if  (document.getElementById('city_text_td').innerHTML)
			{
				document.getElementById('city_text_td').innerHTML = 'Town/City:';
			}
			
		}
	}
}

function remove_states(){
	if  (document.getElementById('state_dropdown_td'))
	{
		document.getElementById('state_dropdown_td').innerHTML = '';
	}
	if  (document.getElementById('state_text_td'))
	{
		document.getElementById('state_text_td').innerHTML = '';
	}
}

function remove_cities(){
	if  (document.getElementById('city_dropdown_td'))
	{
		document.getElementById('city_dropdown_td').innerHTML = '';
	}
	if  (document.getElementById('city_text_td'))
	{
		document.getElementById('city_text_td').innerHTML = '';
	}
}