/* リストボックスの中身を消す関数 */
Sel1 = "";//車両メーカー
Sel2 = "";//車両車種
PostagePref = "";//都道府県(送料計算)

LF  = String.fromCharCode(10);
TAB = String.fromCharCode(9);
 
function RemoveChildItem (node) {
	c = node.firstChild;
	while (c) {
		node.removeChild(node.firstChild);
		c = node.firstChild;
	}
}

/* 大分類が変更された時に呼ばれる関数 */
/* 大分類の選択内容を元に中分類の内容を書き換える */
function Change1 () {
	Sel1 = document.getElementById('sel1');
	Sel2 = document.getElementById('sel2');
	var n = Sel1.selectedIndex;
	getSelectValue("middle", Sel1.options[n].value);
}
function ReWrite1 (ReturnValue) {
	var ValueData = ReturnValue.split(LF);
	RemoveChildItem(Sel2);
	for (i=0; i<ValueData.length; i++) {
		if(ValueData[i] != "") {
			OptionData = ValueData[i].split(TAB);
			o = document.createElement('option');
			o.value = OptionData[0];
			o.innerHTML = OptionData[1];
			Sel2.appendChild(o);
		}
	}
//	Change2 ();
}

/* Ajax関数 HTTPクライアント生成 */
function createXmlHttpRequest() {
	var xmlhttp = null;
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				return null;
			}
		}
	}
	return xmlhttp;
}

/* Ajax関数 サーバから情報を取得 */
function getSelectValue(bunrui, id) {
	http1 = createXmlHttpRequest();
	if(http1) {
		http1.open("POST", "/js/carsearch.php", true);
		http1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http1.onreadystatechange = function() {
			/*  サーバーから応答があった時の処理  */
			if(http1.readyState == 4 && http1.status == 200) {
//	document.getElementById('er').innerHTML = http1.responseText;
				switch (bunrui) {
				case"middle":
					ReWrite1(http1.responseText);
					break;
				case"small":
					ReWrite2(http1.responseText);
					break;
				}
			}
		}
		http1.send(
			"bunrui=" + encodeURI(bunrui)
			+ "&id=" + encodeURI(id)
		);
	}
}

