var provinces = [];
provinces['us'] = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'ID',
	'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE',
	'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN',
	'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'];
	
provinces['ca'] = ['AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'NU', 'ON', 'PE', 'QC', 'SK', 'YT'];

//Replaces the first child of the given element with a new text node containing new_text,
//or adds a new text node if there are no children
function set_node_text(elt_id, new_text)
{
	elt = document.getElementById(elt_id);
	
	if(!elt)
	{
//		Logger.info("set_node_text failed to find element " + elt_id);
		return;
	}
	
	newTextNode = document.createTextNode(new_text);
	
	if(elt.childNodes[0])
		elt.replaceChild(newTextNode, elt.childNodes[0]);
	else
		elt.appendChild(newTextNode);
}

//Populates the "Province" drop-down menu based on the country
function populate_provinces(country_select_elt, province_elt_id, selected)
{
	var cur_country = country_select_elt.options[country_select_elt.selectedIndex].value;
	var province_select_elt = document.getElementById(province_elt_id);
	
	while(province_select_elt.firstChild) 
	{
		//The list is LIVE so it will re-index each call
		province_select_elt.removeChild(province_select_elt.firstChild);
	}

	var newOption = document.createElement('option');
	var newTextNode = document.createTextNode("Select a state/province");
	newOption.appendChild(newTextNode);
	province_select_elt.appendChild(newOption);
	
	if(cur_country == "US")
	{
		for(i=0; i<provinces['us'].length; i++)
		{
			newOption = document.createElement('option');
			newTextNode = document.createTextNode(provinces['us'][i]);
			newOption.appendChild(newTextNode);
			province_select_elt.appendChild(newOption);
			
			if(provinces['us'][i] == selected)
				province_select_elt.selectedIndex = i+1;
		}
	}
	else if(cur_country == "CA")
	{
		for(i=0; i<provinces['ca'].length; i++)
		{
			newOption = document.createElement('option');
			newTextNode = document.createTextNode(provinces['ca'][i]);
			newOption.appendChild(newTextNode);
			province_select_elt.appendChild(newOption);
			
			if(provinces['ca'][i] == selected)
				province_select_elt.selectedIndex = i+1;
		}
	}
	else
	{
		newOption = document.createElement('option');
		newTextNode = document.createTextNode("All states/provinces");
		newOption.appendChild(newTextNode);
		province_select_elt.appendChild(newOption);
		province_select_elt.selectedIndex = 1;
	}
}