function getAddressFromZipcode()
{
	var zipcode = $('#ContactsUserPost').val();

	if (! zipcode.match(/[0-9]{3}-[0-9]{4}/g)) {
		alert("郵便番号は123-4567形式でお願いします");
		return;
	}
	
	zipcode = zipcode.replace('-', '');

	var url = '/zipcodes/contact';
	var token = $('#contact_form_token').val();	

	var postData = new Object();
	postData.zipcode = zipcode;
	postData.contact_form_token = token;
		

	$.ajax({
					 dataType: 'json',
					 type: "POST",
					 url: url,
					 data: postData,
					 success: function(data, dataType) {
						 if (data.result_code == 200) {
							 $('#ContactsUserPrefectureId').val(data.pref_id);
							 if (data.town && data.town.length) {
								 $('#ContactUserAddress1').val(data.city + data.town);
							 }
							 else {
								 $('#ContactsUserAddress1').val(data.city);
							 }
							 $('#ContactsUserAddress2').val('');
						 }
						 else if (data.result_code == 400) {
							 alert('住所が見つかりませんでした。');
						 }
						 else {
							 alert('住所の取得に失敗しました。');
							 alert(data.result_code);							 
						 }
					 },
					 error:  function(obj, status, errorThrown) {
						 alert('エラーが発生しました。');
					 }
				 });
}

