var continent = 0;
var continentObj = '';
var country = 0;
var countryObj = '';
var city = 0;
var cityObj = '';
var region = 0;
var regionObj = '';



function resetOptionList( obj ) { while( obj.options.length != 0 ) obj.options[0] = null; }


function loadContinents( obj )
{
	continentObj = obj;
	ajax_Module.updateContinents( 0, updateContinents_cb );
}

function updateContinents_cb( response )
{
	var obj = document.getElementById( continentObj );

	if( obj )
	{
		resetOptionList( obj );
		if( document.all ) response = '<option>truncatethis</option>' + response;

		obj.innerHTML = response;
		if (document.all) {
			obj.outerHTML = obj.outerHTML;
		}
		else {
			for (var i = 0; i < obj.options.length; i++) {
				if (continent == obj.options[i].value) {
					//obj.selectedIndex = i;
					obj.options[i].selected = true;
				    obj.options[i].setAttribute( 'selected', true );
				}
			}
		}
	}
}

function setContinent( id )
{
	continent = id;

	country = 0;
	region = 0;
	city = 0;

	ajax_Module.updateCountries( continent, 0, updateCountries_cb );
	ajax_Module.updateRegions( city, country, continent, updateRegions_cb );
	ajax_Module.updateCities( country, continent, region, updateCities_cb );
}


function loadCountries( obj )
{
	countryObj = obj;
	ajax_Module.updateCountries( continent, 0, updateCountries_cb );
}

function updateCountries_cb( response )
{
	var obj = document.getElementById( countryObj );

	if( obj )
	{
		resetOptionList( obj );
		if( document.all ) response = '<option>truncatethis</option>' + response;

		obj.innerHTML = response;
		if (document.all) {
			obj.outerHTML = obj.outerHTML;
		}
		else {
			for (var i = 0; i < obj.options.length; i++) {
				if (country == obj.options[i].value) {
					obj.options[i].selected = true;
					obj.options[i].setAttribute( 'selected', true );
				} 
			}
		}
	}
}

function setCountry( id )
{
	country = id;

	region = 0;
	city = 0;

	ajax_Module.updateRegions( city, country, continent, updateRegions_cb );
	ajax_Module.updateCities( country, continent, region, updateCities_cb );
}


function loadCities( obj )
{
	cityObj = obj;
	ajax_Module.updateCities( country, continent, region, updateCities_cb );
}

function updateCities_cb( response )
{
	var obj = document.getElementById( cityObj );

	if( obj )
	{
		resetOptionList( obj );
		if( document.all ) response = '<option>truncatethis</option>' + response;

		obj.innerHTML = response;
		if( document.all ) {
			obj.outerHTML = obj.outerHTML;
		}
		else
		{
			for( var i=0; i<obj.options.length; i++ )
			{
				if( city == obj.options[i].value ) {
					obj.options[i].selected = true;
					obj.options[i].setAttribute( 'selected', true );
				}
			}
		}
	}
}

function setCity( id )
{
	city = id;
	//ajax_Module.updateRegions( city, country, continent, updateRegions_cb );
}


function loadRegions( obj )
{
	regionObj = obj;
	ajax_Module.updateRegions( city, country, continent, updateRegions_cb );
}

function updateRegions_cb( response )
{
	var obj = document.getElementById( regionObj );

	if( obj )
	{
		resetOptionList( obj );
		if( document.all ) response = '<option>truncatethis</option>' + response;

		obj.innerHTML = response;
		if( document.all ) {
			obj.outerHTML = obj.outerHTML;
		}
		else
		{
			for( var i=0; i<obj.options.length; i++ )
			{
				if( region == obj.options[i].value ) {
					obj.options[i].selected = true;
					obj.options[i].setAttribute( 'selected', true );
				}
			}
		}
	}
}

function setRegion( id )
{
	region = id;

	city = 0;

	ajax_Module.updateCities( country, continent, region, updateCities_cb );
}
