/*------------------------------------------------------------------------------
	年令計算
					year			:		誕生年
					month			:		誕生月
					day				:		誕生日
------------------------------------------------------------------------------*/
function calcAge(year, month, day) { 
	var t, y, m, d, a;
	t = new Date();
    y = t.getFullYear();
    m = t.getMonth() + 1;
    d = t.getDate();
    a = y - year;
    if (m < month) {
      a--;
    } else if (m == month && d < day) { 
      a--;
    }
	return a;
}
/*------------------------------------------------------------------------------
	年令表示
					form			:		フォーム名
					year			:		誕生年コントロール名
					month			:		誕生月コントロール名
					day				:		誕生日コントロール名
					id				:		表示先ID
------------------------------------------------------------------------------*/
function showAge(form, year, month, day, id) {
	var y, m, d, a;
	y = document.forms[form].elements[year].selectedIndex + 1930;
	m = document.forms[form].elements[month].selectedIndex + 1;
	d = document.forms[form].elements[day].selectedIndex + 1;
	a = calcAge(y, m, d);
	if (document.all) {
		document.all.item(id).innerHTML = "（" + String(a) + "歳）";
	}
}
/*------------------------------------------------------------------------------
	郵便番号から検索
------------------------------------------------------------------------------*/
function searchAddr() {
	if (window.ActiveXObject) {
		try {
			xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				xmlReq = null;
			}
		}
	} else if (window.XMLHttpRequest) {
		xmlReq = new XMLHttpRequest();
	} else {
		xmlReq = null;
	}
	xmlReq.onreadystatechange = function() {
		if (xmlReq.readyState == 4) {
			if (xmlReq.status == 200) {
				var xmldoc = xmlReq.responseXML.documentElement;
				if (xmldoc) {
					/*
					var pref = xmldoc.getElementsByTagName("pref").item(0).firstChild.nodeValue;
					var city = xmldoc.getElementsByTagName("city").item(0).firstChild.nodeValue;
					var town = xmldoc.getElementsByTagName("town").item(0).firstChild.nodeValue;
					*/
					var pref = xmldoc.getElementsByTagName("pref");
					var city = xmldoc.getElementsByTagName("city");
					var town = xmldoc.getElementsByTagName("town");
					if (pref.item(0)) {
						document.forms[0].elements["pref"].selectedIndex = Number(pref.item(0).firstChild.nodeValue) - 1;
						document.forms[0].elements["city"].value = city.item(0).firstChild.nodeValue;
						if (document.forms[0].elements["town"]) {
							document.forms[0].elements["town"].value = town.item(0).firstChild.nodeValue;
						}
					}
				}
				document.getElementById("status").innerText = "";
			} else {
				document.getElementById("status").innerText = "通信に失敗しました";
			}
		} else {
			document.getElementById("status").innerText = "検索中...";
		}
	}
	xmlReq.open("GET", "../e6fun/common/earth607.php?number="
						+ encodeURI(document.forms[0].elements["postno[0]"].value +
									document.forms[0].elements["postno[1]"].value), true);
	xmlReq.send(null);
}
