$(document).ready(function() {
	
	$("#region").change(function() {
	
		var x = $(this).val();
				
		if(x=="US"||x=="CA"||x=="JP"||x=="MX"||x=="PH") {
			// set to US vendorid
			$("#price").attr("src","/images/price.png");
		} else if (x=="AU"||x=="ME"||x=="NZ"||x=="AS"||x=="SA") {
			// set to AU vendorid
			$("#price").attr("src","/images/price.png");
		} else if (x=='EU') {
			// set to Euro vendorid
			$("#price").attr("src","/images/price_euro.png");
		}

	});

	$("#billprovince").hide();
	$("#billstate optgroup").hide();
	$("#billstate optgroup.us").show();
	$("#billstate optgroup").attr("disabled", "disabled");
	$("#billstate optgroup.us").attr("disabled", "");
	$("#lblbillstate").text("State/Zip:");
	
	$("#block-shipping").hide();
	
	$("#shipprovince").hide();
	$("#shipstate optgroup").hide();
	$("#shipstate optgroup.us").show();
	$("#shipstate optgroup").attr("disabled", "disabled");
	$("#shipstate optgroup.us").attr("disabled", "");
	$("#lblshipstate").text("State/Zip:");
	
	$("#chksamebilling").click(function(){
		if (this.checked)
			$("#block-shipping").slideUp("slow");
		else
			$("#block-shipping").slideDown("slow");
	});

	$("select.country").change(function(){
		var whichone = $(this).attr("id").substr(0,4);
		var country = "#" + whichone + "country";
		var items = "#" + whichone + "items";
		var state = "#" + whichone + "state";
		var province = "#" + whichone + "province";
		var lblstate = "#lbl" + whichone + "state";
		
		switch ($(country).val()) {
		case "US":
			$(items).slideUp("slow", function(){
				$(state).show();
				$(state + " optgroup").hide();
				$(state + " optgroup.us").show();
				$(state + " optgroup").attr("disabled", "disabled");
				$(state + " optgroup.us").attr("disabled", "");
				$(state).attr('selectedIndex', '0').children("option:selected").removeAttr("selected");
				$(province).hide();
				$(province).val("");
				$(lblstate).text("State/Zip:");
			});
			break;
		case "CA":
			$(items).slideUp("slow", function(){
				$(state).show();
				$(state + " optgroup").hide();
				$(state + " optgroup.ca").show();
				$(state + " optgroup").attr("disabled", "disabled");
				$(state + " optgroup.ca").attr("disabled", "");
				$(state).attr('selectedIndex', '0').children("option:selected").removeAttr("selected");
				$(province).hide();
				$(province).val("");
				$(lblstate).text("Province/Postal:");
			});
			break;
		case "MX":
			$(items).slideUp("slow", function(){
				$(state).show();
				$(state + " optgroup").hide();
				$(state + " optgroup.mx").show();
				$(state + " optgroup").attr("disabled", "disabled");
				$(state + " optgroup.mx").attr("disabled", "");
				$(state).attr('selectedIndex', '0').children("option:selected").removeAttr("selected");
				$(province).hide();
				$(province).val("");
				$(lblstate).text("State/Zip:");
			});
			break;
		default:
			$(items).slideUp("slow", function(){
				$(state).hide();
				$(state).attr('selectedIndex', '0').children("option:selected").removeAttr("selected");
				$(province).show();
				$(province).val("");
				$(lblstate).text("Province/Postal:");
			});
			break;
		}
		$(items).slideDown("slow");
	});
});
