function init_country_select() {
	$("#dealer-country").change(init_country_select);
	if($("#dealer-country").val() == "USA") {
		place_state_select();
	} else {
		place_state_input();
	}
}

function place_state_select() {
	$("#dealer-state-container")
	.empty()
	.append(
		$("<select/>")
		.attr({
			"id":"dealer-state",
			"name":"dealer[state]"
		})
		.append($("<option/>").text("Loading..."))
		.load("/tpl/stateoptions.php")
	);
}

function place_state_input() {
	$("#dealer-state-container")
	.empty()
	.append(
		$("<input/>")
		.attr({
			"id":"dealer-state",
			"name":"dealer[state]"
		})
	);
}

function show_errors() {
	$("#errors li").each(function() {
		var field_id = "#"+$(this).attr("rel");
		$(field_id).parents("li").addClass("error");
	});
}

jQuery(function() {
	init_country_select();
	show_errors();
});
