window.addEvent("domready", function() {
			
	if ($("USA_County")) {
		
		$("CountryID").addEvent("change", function(){
			toggleUSStates();
			toggleNYCounties();
		});
		
		$("USA_County").addEvent("change", function(){
			toggleNYCounties();
		});
		
		toggleUSStates();
		toggleNYCounties();
		
	}
	
});

function toggleUSStates(){
	
	var countryField = $("CountryID");
	
	if (countryField.options[countryField.selectedIndex].text == "United States of America") {
		$("label_PostCode").setHTML("Zip Code *");
		$("fieldwrapper_Canada_County").setStyle("display", "none");
		$("fieldwrapper_USA_County").setStyle("display", "block");
		$("Canada_County").selectedIndex = 0;
		if ($("fieldwrapper_County")){
			$("fieldwrapper_County").setStyle("display", "none");
			$("County").setProperty("value", "");
		}
	} else if (countryField.options[countryField.selectedIndex].text == "Canada") {
		$("label_PostCode").setHTML("Postal Code *");
		$("fieldwrapper_Canada_County").setStyle("display", "block");
		$("fieldwrapper_USA_County").setStyle("display", "none");
		$("USA_County").selectedIndex = 0;
		if ($("fieldwrapper_County")){
			$("fieldwrapper_County").setStyle("display", "none");
			$("County").setProperty("value", "");
		}
	} else {
		$("label_PostCode").setHTML("Postal / Zip Code *");
		$("fieldwrapper_Canada_County").setStyle("display", "none");
		$("fieldwrapper_USA_County").setStyle("display", "none");
		if ($("fieldwrapper_County")){$("fieldwrapper_County").setStyle("display", "block");}			
	}
	
}

function toggleNYCounties(){
	
	var stateField = $("USA_County");
	
	if (stateField) {
	
		if (stateField.options[stateField.selectedIndex].text == "New York") {
			$("fieldwrapper_NewYork_Town").setStyle("display", "block");
			$("fieldwrapper_Town").setStyle("display", "none");
			$("Town").setProperty("value", "");
		} else {
			$("fieldwrapper_NewYork_Town").setStyle("display", "none");
			$("fieldwrapper_Town").setStyle("display", "block");
			$("NewYork_Town").selectedIndex = 0;		
		}
		
	}
	
}
