var ajax = new sack();

function getStateList (sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('state').options.length = 0;
	
	if(countryCode.length>0)
	{
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'library/getDealerOptions.php?countryCode='+countryCode;
		ajax[index].onCompletion = function() { createStates(index) };
		ajax[index].runAJAX();
	}
}

function createStates(index)
{
	var obj = document.getElementById('state');
	eval(ajax[index].response);
}

function getCityList (sel)
{
	var stateCode = sel.options[sel.selectedIndex].value;
	document.getElementById('city').options.length = 0;
	
	if(stateCode.length>0)
	{
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'library/getDealerOptions.php?stateCode='+stateCode;
		ajax[index].onCompletion = function() { createCity(index) };
		ajax[index].runAJAX();
	}
}

function createCity(index)
{
	var obj = document.getElementById('city');
	eval(ajax[index].response);
}

function searchDealers()
{
	ajax.method = 'POST';

	ajax.setVar( "city", document.forms["dealerForm"].city.value );
	ajax.setVar( "state", document.forms["dealerForm"].state.value );
	ajax.setVar( "country", document.forms["dealerForm"].country.value );
	ajax.setVar( "cmd", "dealerSearch" );
	processAjax();
}

function searchZip()
{
	ajax.method = 'POST';

	ajax.setVar( "postal", document.forms["dealerForm"].postal.value );
	ajax.setVar( "distance", document.forms["dealerForm"].distance.value );
	ajax.setVar( "cmd", "dealerSearchZip" );
	processAjax();
}

function newSearch()
{
	ajax.method = 'POST';

	ajax.setVar( "cmd", "newSearch" );
	processAjax();
}

function processAjax()
{
	ajax.requestFile = 'library/getDealerOptions.php';
	ajax.onCompletion = showData;
	ajax.runAJAX();
}

function showData()
{
	eval(ajax.response);
}

