//PHPよりデータの受信
// 駅選択時に駅名をセットする。Ajax 
function handleHttpResponseEkiname() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.p_nareacode_pref.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('station1st_code');
			var len = tagList.length;
			if(len > 0){
				for (i = 0; i < len; i++) {
					var name = tagList[i].getElementsByTagName('name')[0].firstChild.nodeValue;
					document.form1.station1st_code_text.value = name;
				}
				setTrafficInfo('line1st_code_text','station1st_code_text','walk_bus1st_flg','walk1st_time','bus1st_time','bus_stop1st_name','bus_stop1st_time','traffic1st_info');
			}
			tagList = xmlDoc.getElementsByTagName('station2nd_code');
			len = tagList.length;
			if(len > 0){
				for (i = 0; i < len; i++) {
					var name = tagList[i].getElementsByTagName('name')[0].firstChild.nodeValue;
					document.form1.station2nd_code_text.value = name;
				}
				setTrafficInfo('line2nd_code_text','station2nd_code_text','walk_bus2nd_flg','walk2nd_time','bus2nd_time','bus_stop2nd_name','bus_stop2nd_time','traffic2nd_info');
			}
			tagList = xmlDoc.getElementsByTagName('station3rd_code');
			len = tagList.length;
			if(len > 0){
				for (i = 0; i < len; i++) {
					var name = tagList[i].getElementsByTagName('name')[0].firstChild.nodeValue;
					document.form1.station3rd_code_text.value = name;
				}
				setTrafficInfo('line3rd_code_text','station3rd_code_text','walk_bus3rd_flg','walk3rd_time','bus3rd_time','bus_stop3rd_name','bus_stop3rd_time','traffic3rd_info');
			}
		}
	}
}

//PHPへのデータの送信
// 駅選択時に駅名をセットする。Ajax
function getEkiName(eki,f0,name)
{
	ensen = document.form1[f0].value;
	xmlHttp.open('GET','../phpinc/ekiname_ajax.php?eki=' + eki + '&ensen=' + ensen + '&name=' + name, true);
	xmlHttp.onreadystatechange = handleHttpResponseEkiname;
	xmlHttp.send("");
}


// 沿線1選択時に駅1from/toを動的にセットする。Ajax 
function handleHttpResponseEki_1() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.hope_ensen1.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('hope_ensen1');
			var len = tagList.length;
			//document.form1.areacode_city1.options.length=1;
			document.form1.hope_eki1.options.length=1;
			for (i = 0; i < len; i++) {
				var id   = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var name = tagList[i].getElementsByTagName('name')[0].firstChild.nodeValue;
				document.form1.hope_eki1.options[i+1] = new Option(name,id);
			}
		}
	}
}
// 沿線2選択時に駅2from/toを動的にセットする。Ajax 
function handleHttpResponseEki_2() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.hope_ensen2.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('hope_ensen2');
			var len = tagList.length;
			document.form1.hope_eki2.options.length=1;
			for (i = 0; i < len; i++) {
				var id   = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var name = tagList[i].getElementsByTagName('name')[0].firstChild.nodeValue;
				document.form1.hope_eki2.options[i+1] = new Option(name,id);
			}
		}
	}
}

//PHPへのデータの送信
// 沿線選択時に駅1,2,3を動的にセットする。Ajax
function getEki_Ajax_reins(name)
{
    var name;
    //alert(name);
    if(name == "hope_ensen1") { var ensen = document.form1.hope_ensen1.value; }
    if(name == "hope_ensen2") { var ensen = document.form1.hope_ensen2.value; }
	xmlHttp.open('GET','../phpinc/eki_ajax.php?ensen=' + ensen + '&name=' + name, true);
	if(name == "hope_ensen1") { xmlHttp.onreadystatechange = handleHttpResponseEki_1; }
	if(name == "hope_ensen2") { xmlHttp.onreadystatechange = handleHttpResponseEki_2; }
	xmlHttp.send("");
}

//PHPよりデータの受信
// 都道府県選択時に行政区を動的にセットする。Ajax 
function handleHttpResponseModel() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.m_nareacode_pref.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('city');
			var len = tagList.length;
			document.form1.m_nareacode_city.options.length=1;
			for (i = 0; i < len; i++) {
				var id     = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var areaname = tagList[i].getElementsByTagName('areaname')[0].firstChild.nodeValue;
				document.form1.m_nareacode_city.options[i+1] = new Option(areaname,id);
			}
		}
	}
}

//PHPへのデータの送信
// 都道府県選択時に行政区を動的にセットする。Ajax
function getCity_model()
{
	var pref = document.form1.m_nareacode_pref.value;
	var mode = '1';

	xmlHttp.open('GET','../phpinc/address_ajax.php?pref=' + pref + '&mode=' + mode, true);
	xmlHttp.onreadystatechange = handleHttpResponseModel;
	xmlHttp.send("");
}


// 都道府県1選択時に行政区1を動的にセットする。Ajax 
function handleHttpResponseAdr_1() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.areacode_pref1.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('city');
			var len = tagList.length;
			document.form1.areacode_city1.options.length=1;
			for (i = 0; i < len; i++) {
				var id     = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var areaname = tagList[i].getElementsByTagName('areaname')[0].firstChild.nodeValue;
				document.form1.areacode_city1.options[i+1] = new Option(areaname,id);
			}
		}
	}
}

// 都道府県2選択時に行政区2を動的にセットする。Ajax 
function handleHttpResponseAdr_2() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.areacode_pref2.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('city');
			var len = tagList.length;
			document.form1.areacode_city2.options.length=1;
			for (i = 0; i < len; i++) {
				var id     = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var areaname = tagList[i].getElementsByTagName('areaname')[0].firstChild.nodeValue;
				document.form1.areacode_city2.options[i+1] = new Option(areaname,id);
			}
		}
	}
}
// 都道府県3選択時に行政区3を動的にセットする。Ajax 
function handleHttpResponseAdr_3() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && document.form1.areacode_pref3.value != "") {
		var xmlDoc = xmlHttp.responseXML;
		if (xmlDoc.documentElement) {
			var tagList = xmlDoc.getElementsByTagName('city');
			var len = tagList.length;
			document.form1.areacode_city3.options.length=1;
			for (i = 0; i < len; i++) {
				var id     = tagList[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var areaname = tagList[i].getElementsByTagName('areaname')[0].firstChild.nodeValue;
				document.form1.areacode_city3.options[i+1] = new Option(areaname,id);
			}
		}
	}
}

//PHPへのデータの送信
// 都道府県選択時に行政区と沿線駅1,2,3を動的にセットする。Ajax
function getCity_Ajax_reins(flg)
{
    var flg ;
    //alert(flg);
    if(flg == "1") { var pref = document.form1.areacode_pref1.value; }
    if(flg == "2") { var pref = document.form1.areacode_pref2.value; }
    if(flg == "3") { var pref = document.form1.areacode_pref3.value; }
	var mode = '0';

	xmlHttp.open('GET','../phpinc/address_ajax.php?pref=' + pref + '&mode=' + mode, true);
    if(flg == "1") { xmlHttp.onreadystatechange = handleHttpResponseAdr_1; }
    if(flg == "2") { xmlHttp.onreadystatechange = handleHttpResponseAdr_2; }
    if(flg == "3") { xmlHttp.onreadystatechange = handleHttpResponseAdr_3; }
	xmlHttp.send("");
}

//オブジェクト
function getXmlHttpObject() {
    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;
    }
}
var xmlHttp = getXmlHttpObject();


