/*********************************************************
（このファイルはUTF-8で保存すること）
*********************************************************/


function get_address(zip1, zip2)
{
	var TOP_URL = (("https:" == document.location.protocol) ? "https://www.cityindex.co.jp" : "http://www.cityindex.co.jp");
	if ( "" != zip1 && "" != zip2 ){
		sendData  = "zip1=" + encodeURI( zip1 );
		sendData += "&zip2=" + encodeURI( zip2 );
		httpObj = createXMLHttpRequest( fetch_address );
		if ( httpObj ){
			httpObj.open( "POST", TOP_URL+"/get_address.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
			document.getElementById("address_search").value = "検索中...";
			document.getElementById("address_search").style.color = "red";
		}
	}
}

function fetch_address()
{
	document.getElementById("address_search").value = "住所入力";
	document.getElementById("address_search").style.color = "";
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( 0 == data.count ){
			alert("入力された郵便番号に該当する住所がありません");
		}
		else{
			for ( i = 0; i < document.frm.m_pref_cd.length; i ++ ){
				if ( document.frm.m_pref_cd.options[i].text == data.pref ){
					document.frm.m_pref_cd.selectedIndex = i;
					break;
				}
			}
			document.frm.addr1.value = data.city + data.town;
			alert("市区町村名の後の番地などは、キーボードからご記入ください");
			// カーソルを住所入力欄の末尾へ移動
			var elm = document.frm.addr1;
			elm.focus();
			if (elm.createTextRange) {
				var range = elm.createTextRange();
				range.move('character', elm.value.length);
				range.select();
			}
			else if (elm.setSelectionRange) {
				elm.setSelectionRange(elm.value.length, elm.value.length);
			}
		}
	}
}


function get_tochi_address(zip1, zip2)
{
	var TOP_URL = (("https:" == document.location.protocol) ? "https://www.cityindex.co.jp" : "http://www.cityindex.co.jp");

	if ( "" != zip1 && "" != zip2 ){
		sendData  = "zip1=" + encodeURI( zip1 );
		sendData += "&zip2=" + encodeURI( zip2 );
		httpObj = createXMLHttpRequest( fetch_tochi_address );
		if ( httpObj ){
			httpObj.open( "POST", TOP_URL+"/get_address.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
			document.getElementById("tochi_address_search").value = "検索中...";
			document.getElementById("tochi_address_search").style.color = "red";
		}
	}
}

function fetch_tochi_address()
{
	document.getElementById("tochi_address_search").value = "住所入力";
	document.getElementById("tochi_address_search").style.color = "";
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( 0 == data.count ){
			alert("入力された郵便番号に該当する住所がありません");
		}
		else{
			for ( i = 0; i < document.frm.tochi_pre_cd.length; i ++ ){
				if ( document.frm.tochi_pre_cd.options[i].text == data.pref ){
					document.frm.tochi_pre_cd.selectedIndex = i;
					break;
				}
			}
			document.frm.tochi_addr1.value = data.city + data.town;
			alert("市区町村名の後の番地などは、キーボードからご記入ください");
			// カーソルを住所入力欄の末尾へ移動
			var elm = document.frm.tochi_addr1;
			elm.focus();
			if (elm.createTextRange) {
				var range = elm.createTextRange();
				range.move('character', elm.value.length);
				range.select();
			}
			else if (elm.setSelectionRange) {
				elm.setSelectionRange(elm.value.length, elm.value.length);
			}
		}
	}
}

function get_mansion_address(zip1, zip2)
{
	var TOP_URL = (("https:" == document.location.protocol) ? "https://www.cityindex.co.jp" : "http://www.cityindex.co.jp");
	if ( "" != zip1 && "" != zip2 ){
		sendData  = "zip1=" + encodeURI( zip1 );
		sendData += "&zip2=" + encodeURI( zip2 );
		httpObj = createXMLHttpRequest( fetch_mansion_address );
		if ( httpObj ){
			httpObj.open( "POST", TOP_URL+"/get_address.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
			document.getElementById("mansion_address_search").value = "検索中...";
			document.getElementById("mansion_address_search").style.color = "red";
		}
	}
}

function fetch_mansion_address()
{
	document.getElementById("mansion_address_search").value = "住所入力";
	document.getElementById("mansion_address_search").style.color = "";
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( 0 == data.count ){
			alert("入力された郵便番号に該当する住所がありません");
		}
		else{
			for ( i = 0; i < document.frm.mansion_m_pref_cd.length; i ++ ){
				if ( document.frm.mansion_m_pref_cd.options[i].text == data.pref ){
					document.frm.mansion_m_pref_cd.selectedIndex = i;
					break;
				}
			}
			document.frm.mansion_addr1.value = data.city + data.town;
			alert("市区町村名の後の番地などは、キーボードからご記入ください");
			// カーソルを住所入力欄の末尾へ移動
			var elm = document.frm.mansion_addr1;
			elm.focus();
			if (elm.createTextRange) {
				var range = elm.createTextRange();
				range.move('character', elm.value.length);
				range.select();
			}
			else if (elm.setSelectionRange) {
				elm.setSelectionRange(elm.value.length, elm.value.length);
			}
		}
	}
}


