function AddressSearch( filename )
{
	xml	= createXmlHttp();
	if( xml == null )return;
	
   /* レスポンスデータ処理方法の設定 */
    xml.onreadystatechange = handleHttpEvent;
    
    /* HTTPリクエスト実行 */
    xml.open( "GET", filename, true);
	xml.send( null );
}

function createXmlHttp()
{
    if( window.XMLHttpRequest ) {             // Mozilla, Firefox, Safari, IE7
        return new XMLHttpRequest();
    }else if( window.ActiveXObject ) {       // IE5, IE6
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");    // MSXML3
        } catch(e) {
            return new ActiveXObject("Microsoft.XMLHTTP"); // MSXML2まで
        }
    } else {
        return null;
    }
}

/* レスポンスデータ処理用のコールバック関数を定義 */
function handleHttpEvent()
{
	if (xml.readyState == 4) {
		if (xml.status == 200) {

			/* 郵便番号記入欄から番号を取得 */
			var n	= String( document.form.POST00.value );
			n = n + String( document.form.POST01.value );
			
			if( n.length < 7 ){
				window.alert( "郵便番号をきちんと入力してください。" );
				return;
			}

			// 検索
			var ans = xml.responseText.lastIndexOf( n );
			if( ans == -1 )
			{
				window.alert( "各当する住所が見つかりませんでした。。" );
				
				document.form.ADDRESS00.selectedIndex	= 0;
				document.form.ADDRESS01.value			= "";
				
				return;
			}
			
			// データを分解する
			var data = xml.responseText.substring( ans ).split( "," );
			
			// selectメニューの中から位置を調べて変更する
			var max	= document.form.ADDRESS00.length;
			for( i = 0; i < max; i++ )
			{
				if( document.form.ADDRESS00.options[i].text.match( data[1] ) )
				{
					document.form.ADDRESS00.selectedIndex = i;
					break;
				}
			}
			
			document.form.ADDRESS01.value	= data[2];
//			document.form.ADDRESS00.option.text	= data[1];
			
		} else {
			window.alert("通信エラーが発生しました。");
		}
	}
}


