
function handleAddrssHttpResponse() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var prefCd   = document.getElementById('PREF_CODE');
		var cityKan  = document.getElementById('CITY_KANJI');
		var townKan  = document.getElementById('TOWN_KANJI');
		var blockKan = document.getElementById('BLOCK_KANJI');
		var jigyoKan = document.getElementById('JIGYO_KANJI');
		var cnt      = document.getElementById('count');

		prefCd.value	= '';
		cityKan.value	= '';
		townKan.value	= '';
		blockKan.value	= '';
		jigyoKan.value	= '';

		cnt.innerHTML = '';

		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var pref  = xmlDoc.getElementsByTagName('pref').item(0).firstChild;
			var city  = xmlDoc.getElementsByTagName('city').item(0).firstChild;
			var town  = xmlDoc.getElementsByTagName('town').item(0).firstChild;
			var block = xmlDoc.getElementsByTagName('block').item(0).firstChild;
			var jigyo = xmlDoc.getElementsByTagName('jigyo').item(0).firstChild;
			var count = xmlDoc.getElementsByTagName('count').item(0).firstChild;
			if (pref  != null) { prefCd.value	= pref.data; }
			if (city  != null) { cityKan.value	= city.data; }
			if (town  != null) { townKan.value	= town.data; }
			if (block != null) { blockKan.value	= block.data; }
			if (jigyo != null) { jigyoKan.value	= jigyo.data; }
			if (count != null) { cnt.innerHTML = count.data; }
		}
	}
}

function getAddrss() {
	var zip = document.getElementById('POSTCODE').value;
	if( zip.length > 3 ) {
		xmlHttp.open('GET', 'zip.jsp?POSTCODE=' + escape(zip), true);
		xmlHttp.onreadystatechange = handleAddrssHttpResponse;
		xmlHttp.send(null);
	}
}

function handleChangeHttpResponse() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var xmlDoc = xmlHttp.responseXML;

		if (xmlDoc.documentElement) {
			var oOldTag = document.getElementById('CITY_KANJI');
			var oNewDiv = document.createElement("DIV");
			oNewDiv.innerHTML = xmlHttp.responseText;

			oOldTag.parentNode.insertBefore(oNewDiv, oOldTag);
			oOldTag.style.display = "none";
			oNewDiv = null;
		}
	}
	else if(xmlHttp.readyState == 4 && xmlHttp.status != 200) {
		alert( xmlHttp.responseText );
	}
}

function changeAddress() {
	var postcd = document.getElementById('PREF_CODE');
	var val = null;
	for( i=0; i<postcd.options.length; i++ ) {
		if( postcd.options[i].selected ) {
			val = postcd.options[i].value;
			break;
		}
	}

	xmlHttp.open('GET', 'zip2.jsp?CNT=50&PREF_CODE=' + escape(val), true);
	xmlHttp.onreadystatechange = handleChangeHttpResponse;
	xmlHttp.send(null);
}
