var contin = new Array();
var numincont = new Array(0,53,45,15,53,28,14);

for( var z = 1; z < numincont.length; z++ )
{
	contin[z] = new Array();
}

window.onload = prepare_menus;

function prepare_menus()
{
	if(document.mainform.Country) country_menu_prep();
	if(document.mainform.Home_Country) home_country_menu_prep();
}

function country_menu_prep()
{
	if( document.mainform.Country.options.length < 60 )
	{
		self.location.reload();
	}

	var y = 0;
	
	for( var z = 1; z < numincont.length; z++ )
	{
		for( x = 1; x <= numincont[z]; x++ )
		{
			contin[z][x] = new Option(document.mainform.Country.options[x+y].text,document.mainform.Country.options[x+y].value);
		}

		y += numincont[z];
	}
	
	country_menu_refill();
	
	select_country();
}

function country_menu_refill()
{
	while( document.mainform.Country.options.length )
	{
		document.mainform.Country.options[0] = null;
	}
	
	if( document.mainform.Continent.selectedIndex )
	{
		document.mainform.Country.options[0] = new Option("Please select one","");
		
		for( var z = 1; z < contin[document.mainform.Continent.selectedIndex].length; z++ )
		{
			document.mainform.Country.options[z] = contin[document.mainform.Continent.selectedIndex][z];
		}
		
		document.mainform.Country.disabled = false;
	}
	else
	{
		document.mainform.Country.options[0] = new Option("Please select continent first","");
		document.mainform.Country.disabled = true;
	}
	
	document.mainform.Country.options[0].selected = true;
}

function select_country()
{
	document.mainform.Country.value = selected_country_id;
}

function home_country_menu_prep()
{
	if( document.mainform.Home_Country.options.length < 60 )
	{
		self.location.reload();
	}

	var y = 0;
	
	for( var z = 1; z < numincont.length; z++ )
	{
		for( x = 1; x <= numincont[z]; x++ )
		{
			contin[z][x] = new Option(document.mainform.Home_Country.options[x+y].text,document.mainform.Home_Country.options[x+y].value);
		}

		y += numincont[z];
	}
	
	home_country_menu_refill();
	
	select_home_country();
}

function home_country_menu_refill()
{
	while( document.mainform.Home_Country.options.length )
	{
		document.mainform.Home_Country.options[0] = null;
	}
	
	if( document.mainform.Home_Continent.selectedIndex )
	{
		document.mainform.Home_Country.options[0] = new Option("Please select one","");
		
		for( var z = 1; z < contin[document.mainform.Home_Continent.selectedIndex].length; z++ )
		{
			document.mainform.Home_Country.options[z] = contin[document.mainform.Home_Continent.selectedIndex][z];
		}
		
		document.mainform.Home_Country.disabled = false;
	}
	else
	{
		document.mainform.Home_Country.options[0] = new Option("Please select continent first","");
		document.mainform.Home_Country.disabled = true;
	}
	
	document.mainform.Home_Country.options[0].selected = true;
}

function select_home_country()
{
	document.mainform.Home_Country.value = selected_home_country_id;
}

