
var ajax = new Array();

function showCountryDiv(pref){
	var prefrctureId = pref.options[pref.selectedIndex].value;
	if(prefrctureId=='Not in Japan')
document.getElementById('countrylist').style.display="block"; // Show  the state list box	
	else
	document.getElementById('countrylist').style.display="none"; // Hide  the state list box	
}

function getCountryList(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;

	document.getElementById('n_country').options.length = 0;	// Empty country select box
	document.getElementById('n_state').options.length = 0;      // Empty state select box
	document.getElementById('n_city').options.length = 0;       // Empty city select box
    document.getElementById('statelist').style.display="none";  // Hide  the state list box
    document.getElementById('citylist').style.display="none";   // Hide  the city list box
	if(countryCode<0)
		document.getElementById('countrylist').style.display="none"; // Hide  the state list box
	
	//if(countryCode.length>0){
	if(countryCode>0){

		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'getLocation.php?countryCode='+countryCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCountries(index) };	// Specify function that will be executed after file has been found		
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createCountries(index)
{
	var obj = document.getElementById('n_country');	
	
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
	
	// show the city list when 		
	var countrylist = document.getElementById('n_country').value;

	if(countrylist.length == '')
	  document.getElementById('countrylist').style.display="none";
	else
	  document.getElementById('countrylist').style.display="";
}
function getStateList(state)
{
	var stateCode = state.options[state.selectedIndex].value;	
	document.getElementById('n_state').options.length = 0;   // Empty town select box
	document.getElementById('n_city').options.length = 0;   // Empty town select box
	document.getElementById('statelist').style.display="none"; // Hide  the state list box
	document.getElementById('citylist').style.display="none"; // Hide  the state list box
		
	if(stateCode>0){

		var index = ajax.length;
		ajax[index] = new sack();
		
	//alert(cityCode);
		ajax[index].requestFile = 'getLocation.php?stateCode='+stateCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createStates(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createStates(index)
{

	var obj = document.getElementById('n_state');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
	
	// show the city list when 		
	var statelist = document.getElementById('n_state').value;
	
	if(statelist == '')
	  document.getElementById('statelist').style.display="none";
	else
	 document.getElementById('statelist').style.display="";
}	
function getCityList(city)
{

	var cityCode = city.options[city.selectedIndex].value;	
	document.getElementById('n_city').options.length = 0;   // Empty town select box	
	document.getElementById('citylist').style.display="none"; // Hide  the state list box

	if(cityCode>0){

		var index = ajax.length;
		ajax[index] = new sack();
		
	//alert(cityCode);
		ajax[index].requestFile = 'getLocation.php?cityCode='+cityCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}
function createCities(index)
{

	var obj = document.getElementById('n_city');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
	
	// show the city list when 		
	var citylist = document.getElementById('n_city').value;
	
	if(citylist == '')
	  document.getElementById('citylist').style.display="none";
	else
	 document.getElementById('citylist').style.display="";
}
