
	/* Modified by Alex Spooner, 2008-09-02 */
	
	function changeState(s){
		var country = $("#" + s + "Country").val();
		if (country=="US"){
			$("#" + s + "State").replaceWith('<select id="' + s + 'State" name="Usr' + s + 'State" />');
			$("#States option").clone().appendTo( $("#" + s + "State") );
		} else {
			$("#" + s + "State").replaceWith('<input id="' + s + 'State" name="Usr' + s + 'State" type="text" />');
		}
	}

	$(document).ready(function(){
	
		// SameAsBilling
		$("#SameAsBilling").click(function(event){
			event.preventDefault();
			$("#ShipFirstName").val($("#BillFirstName").val());
			$("#ShipLastName").val($("#BillLastName").val());
			$("#ShipAddr").val($("#BillAddr").val());
			$("#ShipCity").val($("#BillCity").val());
			$("#ShipCountry").val($("#BillCountry").val());
			changeState("Ship");
			$("#ShipState").val($("#BillState").val());
			$("#ShipZip").val($("#BillZip").val());
			$("#ShipPhone").val($("#BillPhone").val());
		});
		
		// changeState
		$("#BillCountry").change(function(){
			changeState("Bill");
		});
		$("#ShipCountry").change(function(){
			changeState("Ship");
		});
	
	});