$(document).ready(function()
{
	$(".countryDropDown").change(function(){onSelectCountry(this)});
	populateList("states")
});

function onSelectCountry(obj)
{
	switch(obj.value)
	{
		case "226":
			populateList("states");
			break;
		case "39":
			populateList("provinces");
			break;
		default:
			populateList("other");
			break;
	}
}

function populateList(listType)
{
	var listName, labelText, valueArray;

	switch(listType)
	{
		case "states":
			listName = "stateList";
			labelText = "State:";
			break;
		case "provinces":
			listName = "provinceList";
			labelText = "Province:"
			break;
		case "other":
			listName = "";
			labelText = "State:"
			break;        
	}

	//set label
	$("#stateLabel").html(labelText);

	//clear existing options
	$(".stateDropDown >option").remove();

	if (listName != "")
	{
		//Enable dropdown
		$(".stateDropDown").removeAttr("disabled");
		
		//get data for new options
		valueArray = $("." + listName).val().split(";");

		//populate list
		$(".stateDropDown").append($("<option></option>").val("").html("**Please Select**"));
		
		$.each(valueArray, function(idx, val)
		{
			arr = val.split("|");
			$(".stateDropDown").append($("<option></option>").val(arr[0]).html(arr[1]));
		});
	}
	else
	{
		//disable dropdown
		$(".stateDropDown").attr("disabled", "disabled");
		
		//populate list
		$(".stateDropDown").append($("<option></option>").val("").html("Outside North America"));
	}
}
