//<![CDATA[

function httpHandler_area() {
	if (xmlhttp_area.readyState == 4 && xmlhttp_area.status== 200) {
		document.getElementById("pref").innerHTML = xmlhttp_area.responseText;
		var eSource2 = document.getElementById("pref_list");
		addListener(eSource2, "change", askCity, false);
	}
}

function httpHandler_pref() {
	if (xmlhttp_pref.readyState == 4 && xmlhttp_pref.status== 200) {
		document.getElementById("city").innerHTML = xmlhttp_pref.responseText;
		var eSource3 = document.getElementById("city_list");
		addListener(eSource3, "change", askShisetsu_woptions, false);
	}
}

function httpHandler_pref_init() {
	if (xmlhttp_pref.readyState == 4 && xmlhttp_pref.status== 200) {
		var eSource4 = document.getElementById("city_list");
		addListener(eSource4, "change", askShisetsu_woptions, false);
	}
}

function httpHandler_city() {
	if (xmlhttp_city.readyState == 4 && xmlhttp_city.status== 200) {
		var mainareaBottom = document.getElementById('mainarea_bottom');
		var nodeList_bottom = mainareaBottom.childNodes;
		for (var h=0; h<nodeList_bottom.length; h++) {
			if (nodeList_bottom.item(h).id == "newcomer") {
				/*	初回の処理	*/
				newComer = document.getElementById("newcomer");
				newComer.id = "list";
				break;
			} else {
				if (nodeList_bottom.item(h).id == "list0") {
					// 地域ページの初期状態
					listzero = document.getElementById("list0");
					listzero.id = "list";
					makeRoomtype();
					makeOptiontable();
					break;
				}
			}
		}
		document.getElementById("list").innerHTML = xmlhttp_city.responseText;
	}

	/*	レイアウトを変更する処理	*/
	var parent_div = document.getElementById('mainarea_top');
	var mainareaRight = document.getElementById('right_in_top1');
	var mainareaCenter = document.getElementById('center_in_top1');
	var mainareaLeft = document.getElementById('left_in_top1');
	var recommends = document.getElementById('recommends');

	/*	div要素のIDが1かどうか確認する	*/
	var nodeList = parent_div.childNodes;
	for (var j=0; j<nodeList.length; j++) {
		if (nodeList.item(j).id == "right_in_top1") {
			/*	recommendを削除	*/
			mainareaRight.removeChild(recommends);
			mainareaRight.id = "right_in_top2";
			mainareaCenter.id = "center_in_top2";
			mainareaLeft.id = "left_in_top2";
			makeRoomtype();
			makeOptiontable();
			break;
		}
	}
}

function askPref(e) {
	/* 該当するエリアIDを持つデータをDBに問い合わせる */
	var area_name = document.getElementById("area_list").value;
	var url_1 = "php/response_pref.php";
	var data_get = "";
	var data_post = "aid=" + area_name;
	var senddata_by_get = url_1 + data_get;
	var by_post = url_1;

	if (document.uniqueID ) {
		xmlhttp_area = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp_area = new XMLHttpRequest();
	}
	xmlhttp_area.onreadystatechange = httpHandler_area;
	xmlhttp_area.open("POST", by_post);
	xmlhttp_area.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp_area.send(data_post);
}

function askCity(e) {
	/* 該当する都道府県名を持つ市区町村名をDBに問い合わせる */
	var pref_name = document.getElementById("pref_list").value;
	var url_2 = "php/response_city.php";
	var data_post2 = "pname=" + pref_name;
	var by_post2 = url_2;

	if (document.uniqueID ) {
		xmlhttp_pref = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp_pref = new XMLHttpRequest();
	}
	xmlhttp_pref.onreadystatechange = httpHandler_pref;
	xmlhttp_pref.open("POST", by_post2);
	xmlhttp_pref.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp_pref.send(data_post2);
}

function askShisetsu_woptions(e) {
	var pname = document.getElementById("pref_list").value;
	var city_name = document.getElementById("city_list").value;
	var url_4 = "php/response_shis.php";
	var data_post4 = "";
	data_post4 += "cname=" + city_name;
	data_post4 += "&pname=" + pname;
	data_post4 += "&rt01_f=" + rt01_f;
	data_post4 += "&rt02_f=" + rt02_f;
	data_post4 += "&rt03_f=" + rt03_f;
	data_post4 += "&rt04_f=" + rt04_f;
	data_post4 += "&op01_f=" + op01_f;
	data_post4 += "&op02_f=" + op02_f;
	data_post4 += "&op03_f=" + op03_f;
	data_post4 += "&op04_f=" + op04_f;
	data_post4 += "&op05_f=" + op05_f;
	data_post4 += "&op06_f=" + op06_f;
	data_post4 += "&op07_f=" + op07_f;
	data_post4 += "&op08_f=" + op08_f;
	data_post4 += "&op09_f=" + op09_f;
	data_post4 += "&op10_f=" + op10_f;
	data_post4 += "&op11_f=" + op11_f;
	data_post4 += "&op12_f=" + op12_f;
	data_post4 += "&op13_f=" + op13_f;
	data_post4 += "&op14_f=" + op14_f;
	data_post4 += "&op15_f=" + op15_f;
	data_post4 += "&op16_f=" + op16_f;
	data_post4 += "&op17_f=" + op17_f;
	data_post4 += "&op18_f=" + op18_f;
	var by_post4 = url_4;

	if (document.uniqueID ) {
		xmlhttp_city = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp_city = new XMLHttpRequest();
	}
	xmlhttp_city.onreadystatechange = httpHandler_city;
	xmlhttp_city.open("POST", by_post4);
	xmlhttp_city.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp_city.send(data_post4);
}

function initAreaList() {
	acSelec = new Array("", "", "", "", "", "", "", "", "", "", "", "", "");
	acSelec[areaCode] = " selected";
	var areaList = "";
	areaList += "<select id=\"area_list\">";
	areaList += "<option value=\"0\" id=\"area0\">エリア選択</option>";
	areaList += "<option value=\"1\" id=\"area1\"" + acSelec[1] + ">北海道</option>";
	areaList += "<option value=\"2\" id=\"area2\"" + acSelec[2] + ">東北</option>";
	areaList += "<option value=\"3\" id=\"area3\"" + acSelec[3] + ">関東</option>";
	areaList += "<option value=\"4\" id=\"area4\"" + acSelec[4] + ">北陸</option>";
	areaList += "<option value=\"5\" id=\"area5\"" + acSelec[5] + ">甲信越</option>";
	areaList += "<option value=\"6\" id=\"area6\"" + acSelec[6] + ">東海</option>";
	areaList += "<option value=\"7\" id=\"area7\"" + acSelec[7] + ">近畿</option>";
	areaList += "<option value=\"8\" id=\"area8\"" + acSelec[8] + ">山陰</option>";
	areaList += "<option value=\"9\" id=\"area9\"" + acSelec[9] + ">山陽</option>";
	areaList += "<option value=\"10\" id=\"area10\"" + acSelec[10] + ">四国</option>";
	areaList += "<option value=\"11\" id=\"area11\"" + acSelec[11] + ">九州</option>";
	areaList += "<option value=\"12\" id=\"area12\"" + acSelec[12] + ">沖縄</option>";
	areaList += "</select>";
	document.getElementById("area").innerHTML = areaList;
	var eSource2 = document.getElementById("pref_list");
	addListener(eSource2, "change", askCity, false);
	askCityInit();
}

function askCityInit() {
	/* 該当する都道府県名を持つ市区町村名をDBに問い合わせる */
	var pref_name = document.getElementById("pref_list").value;
	var url_2 = "php/response_city.php";
	var data_post2 = "pname=" + pref_name;
	var by_post2 = url_2;

	if (document.uniqueID ) {
		xmlhttp_pref = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp_pref = new XMLHttpRequest();
	}
	xmlhttp_pref.onreadystatechange = httpHandler_pref_init;
	xmlhttp_pref.open("POST", by_post2);
	xmlhttp_pref.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp_pref.send(data_post2);
}

function askShisInit() {
	var pname = document.getElementById("pref_list").value;
	var city_name = document.getElementById("city_list").value;
	var url_4 = "php/response_shis.php";
	var data_post4 = "";
	data_post4 += "cname=" + city_name;
	data_post4 += "&pname=" + pname;
	data_post4 += "&rt01_f=" + rt01_f;
	data_post4 += "&rt02_f=" + rt02_f;
	data_post4 += "&rt03_f=" + rt03_f;
	data_post4 += "&rt04_f=" + rt04_f;
	data_post4 += "&op01_f=" + op01_f;
	data_post4 += "&op02_f=" + op02_f;
	data_post4 += "&op03_f=" + op03_f;
	data_post4 += "&op04_f=" + op04_f;
	data_post4 += "&op05_f=" + op05_f;
	data_post4 += "&op06_f=" + op06_f;
	data_post4 += "&op07_f=" + op07_f;
	data_post4 += "&op08_f=" + op08_f;
	data_post4 += "&op09_f=" + op09_f;
	data_post4 += "&op10_f=" + op10_f;
	data_post4 += "&op11_f=" + op11_f;
	data_post4 += "&op12_f=" + op12_f;
	data_post4 += "&op13_f=" + op13_f;
	data_post4 += "&op14_f=" + op14_f;
	data_post4 += "&op15_f=" + op15_f;
	data_post4 += "&op16_f=" + op16_f;
	data_post4 += "&op17_f=" + op17_f;
	data_post4 += "&op18_f=" + op18_f;
	var by_post4 = url_4;

	if (document.uniqueID ) {
		xmlhttp_city = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp_city = new XMLHttpRequest();
	}
	xmlhttp_city.onreadystatechange = httpHandler_city;
	xmlhttp_city.open("POST", by_post4);
	xmlhttp_city.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp_city.send(data_post4);
}

function setListeners(e) {
	var eSource = document.getElementById("area_list");
	addListener(eSource, "change", askPref, false);
}

function initialize() {
	initRoomtype();
	initOption();
	initAreaList();
	setListeners();
	askShisInit();
}

addListener(window, "load", initialize, false);
//]]>

