// javascript for accesstown

// populate select list
/*

var countries = new Array(1);
countries["Canada"] = new Array(3);
countries["Canada"][0] = "BC";
countries["Canada"][1] = "Ontario";
countries["Canada"][2] = "Pacific Ocean";

var regions = new Array(3);
regions["BC"] = new Array(2);
regions["BC"][0] = "Vancouver";
regions["BC"][1] = "Victoria";
regions["Ontario"] = new Array(1);
regions["Ontario"][0] = "Toronto";
regions["Pacific Ocean"] = new Array(1);
regions["Pacific Ocean"][0] = "Atlantis";

*/

function initRegion()
{
	var showSubmit=0;

	t = document.getElementById('_my_region');
	t.style.display='none';
	t = document.getElementById('_my_city');
	t.style.display='none';
	if(t.selectedIndex>0)
	{
		showSubmit=1;
	}
	t=document.getElementById('_my_country');
	if(t.selectedIndex>0)
	{
		populateRegion();
		t = document.getElementById('_my_region');
		if(t.selectedIndex>0)
		{
			populateCity();
		}
	}

	t = document.getElementById('region_submit');
	if(t != null && !showSubmit) t.style.display='none';
}

function populateRegion()
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById('_my_country');
	var t = document.getElementById('_my_region');
	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;


	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	for(x=0; x < countries[ i ].length; x++)
	{
		t.length++;
		t.options[t.length-1].value = countries[i][x];
		t.options[t.length-1].text = countries[i][x];
	}
	if(tsel != null)
	{
		for(x=0; x < t.length; x++)
		{
			if(t.options[x].value==tsel)
			{
				t.selectedIndex=x;
				break;
			}
		}
	}
}

function populateCity()
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById('_my_region');
	var t = document.getElementById('_my_city');
	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;

	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	for(x=0; x < regions[ i ].length; x++)
	{
		t.length++;
		t.options[t.length-1].value = regions[i][x];
		t.options[t.length-1].text = regions[i][x];
	}
	if(tsel != null)
	{
		for(x=0; x < t.length; x++)
		{
			if(t.options[x].value==tsel)
			{
				t.selectedIndex=x;
				break;
			}
		}
	}
}

function getLocationID(myForm)
{
	var country = document.getElementById('_my_country')[document.getElementById('_my_country').selectedIndex].value;
	var region = document.getElementById('_my_region')[document.getElementById('_my_region').selectedIndex].value;
	var city = document.getElementById('_my_city')[document.getElementById('_my_city').selectedIndex].value;

	for(i in location2id)
	{
		// alert( i );
		if(location2id[i]['country']==country && location2id[i]['region']==region && location2id[i]['city']==city)
		{
			document.getElementById('_my_region')[document.getElementById('_my_region').selectedIndex].value=location2id[i]['id'];
			break;
		}
	}

}

function populateSubCategory(myID,myTarget)
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById(myID);
	var t = document.getElementById(myTarget);

	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;

	if(f.selectedIndex==0)
	{
		t.style.display='none';
	}
	else
	{
		t.style.display='';

		var tsel = null;
		if(t.selectedIndex>0)
		{
			tsel = t.options[t.selectedIndex].value;
		}


		t.length=1;
		for(x=0; x < branch[ i ].length; x++)
		{
			t.length++;
			t.options[t.length-1].value = branch[i][x];
			t.options[t.length-1].text = branch_title[i][x];
		}
		if(tsel != null)
		{
			for(x=0; x < t.length; x++)
			{
				if(t.options[x].value==tsel)
				{
					t.selectedIndex=x;
					break;
				}
			}
		}
	}
}

function initRegion2()
{
	t = document.getElementById('_my_region2');
	t.style.display='none';
	t = document.getElementById('_my_city2');
	t.style.display='none';
	t=document.getElementById('_my_country2');
	if(t.selectedIndex>0)
	{
		populateRegion2();
		t = document.getElementById('_my_region2');
		if(t.selectedIndex>0)
		{
			populateCity2();
		}

	}
}

function populateRegion2()
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById('_my_country2');
	var t = document.getElementById('_my_region2');
	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;


	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	for(x=0; x < countries2[ i ].length; x++)
	{
		t.length++;
		t.options[t.length-1].value = countries2[i][x];
		t.options[t.length-1].text = countries2[i][x];
	}
	if(tsel != null)
	{
		for(x=0; x < t.length; x++)
		{
			if(t.options[x].value==tsel)
			{
				t.selectedIndex=x;
				break;
			}
		}
	}
}

function populateCity2()
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById('_my_region2');
	var t = document.getElementById('_my_city2');
	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;

	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	for(x=0; x < regions[ i ].length; x++)
	{
		t.length++;
		t.options[t.length-1].value = regions2[i][x];
		t.options[t.length-1].text = regions2[i][x];
	}
	if(tsel != null)
	{
		for(x=0; x < t.length; x++)
		{
			if(t.options[x].value==tsel)
			{
				t.selectedIndex=x;
				break;
			}
		}
	}
}

function populateRegionX(suffix)
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	//alert('_my_region' + suffix);

	var f = document.getElementById('_my_country' + suffix);
	var t = document.getElementById('_my_region' + suffix);
	var x = 0;

	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	//alert ( i ) ;


	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	if(countries[ i ] != null)
	{
		for(x=0; x < countries[ i ].length; x++)
		{
			t.length++;
			t.options[t.length-1].value = countries[i][x];
			t.options[t.length-1].text = countries[i][x];
		}
		if(tsel != null)
		{
			for(x=0; x < t.length; x++)
			{
				if(t.options[x].value==tsel)
				{
					t.selectedIndex=x;
					break;
				}
			}
		}
	}
}

function populateCityX(suffix)
{
	//for(x=0; x < document.forms[myForm].length; x++)
	//{
	//	alert(document.forms[myForm][x].name);
	//}

	var f = document.getElementById('_my_region' + suffix);
	var t = document.getElementById('_my_city' + suffix);
	var x = 0;

	t.style.display='';
	// alert ( f.selectedIndex );
	var i = f[f.selectedIndex].value;
	// alert ( i ) ;

	var tsel = null;
	if(t.selectedIndex>0)
	{
		tsel = t.options[t.selectedIndex].value;
	}


	t.length=1;
	if(i != null)
	if(regions[ i ] != null)
	{
		for(x=0; x < regions[ i ].length; x++)
		{
			t.length++;
			t.options[t.length-1].value = regions[i][x];
			t.options[t.length-1].text = regions[i][x];
		}
		if(tsel != null)
		{
			for(x=0; x < t.length; x++)
			{
				if(t.options[x].value==tsel)
				{
					t.selectedIndex=x;
					break;
				}
			}
		}
	}
}