/*********************************************************
（このファイルはUTF-8で保存すること）
*********************************************************/

function change_prefecture( prefecture, district )
{
	if ( prefecture.value ){
		sendData  = "prefecture=" + encodeURI( prefecture.value );
		sendData += "&district=" + encodeURI( district );
		httpObj = createXMLHttpRequest( fetch_district );
		if ( httpObj ){
			httpObj.open( "POST", "/ajax/fetch_district.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
		}
	}
	else{
		document.form.elements["city"].length = 0;
	}
}

function fetch_district()
{
	district_pulldown = document.form.elements["city"];
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.district_array ){
			district_pulldown.length = 0;
			for ( i = 0; i < data.district_array.length; i ++ ){
				idx = district_pulldown.length;
				district_pulldown.length ++;
				district_pulldown.options[idx].text = data.district_array[i].district_name;
				district_pulldown.options[idx].value = data.district_array[i].district_value;
			}
		}
		else{
			district_pulldown.length = 0;
		}
	}
}

function change_client_prefecture(prefecture)
{
	if ( prefecture.value ){
		sendData  = "prefecture=" + encodeURI(prefecture.value);
		httpObj = createXMLHttpRequest(fetch_client_district);
		if ( httpObj ){
			httpObj.open("POST", "/ajax/fetch_district.php", true);
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send(sendData);
		}
	}
	else{
		document.form.elements["client_district"].length = 0;
	}
}

function fetch_client_district()
{
	district_pulldown = document.form.elements["client_district"];
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.district_array ){
			district_pulldown.length = 0;
			for ( i = 0; i < data.district_array.length; i ++ ){
				idx = district_pulldown.length;
				district_pulldown.length ++;
				district_pulldown.options[idx].text = data.district_array[i].district_name;
				district_pulldown.options[idx].value = data.district_array[i].district_value;
			}
		}
		else{
			district_pulldown.length = 0;
		}
	}
}

function change_accountant_prefecture(prefecture)
{
	if ( prefecture.value ){
		sendData  = "prefecture=" + encodeURI(prefecture.value);
		httpObj = createXMLHttpRequest(fetch_accountant_district);
		if ( httpObj ){
			httpObj.open("POST", "/ajax/fetch_district.php", true);
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send(sendData);
		}
	}
	else{
		document.form.elements["accountant_district"].length = 0;
	}
}

function fetch_accountant_district()
{
	district_pulldown = document.form.elements["accountant_district"];
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.district_array ){
			district_pulldown.length = 0;
			for ( i = 0; i < data.district_array.length; i ++ ){
				idx = district_pulldown.length;
				district_pulldown.length ++;
				district_pulldown.options[idx].text = data.district_array[i].district_name;
				district_pulldown.options[idx].value = data.district_array[i].district_value;
			}
		}
		else{
			district_pulldown.length = 0;
		}
	}
}

function change_contact_prefecture(prefecture)
{
	if ( prefecture.value ){
		sendData  = "prefecture=" + encodeURI(prefecture.value);
		httpObj = createXMLHttpRequest(fetch_contact_district);
		if ( httpObj ){
			httpObj.open("POST", "/ajax/fetch_district.php", true);
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send(sendData);
		}
	}
	else{
		document.form.elements["contact_district"].length = 0;
	}
}

function fetch_contact_district()
{
	district_pulldown = document.form.elements["contact_address"];
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.district_array ){
			district_pulldown.length = 0;
			for ( i = 0; i < data.district_array.length; i ++ ){
				idx = district_pulldown.length;
				district_pulldown.length ++;
				district_pulldown.options[idx].text = data.district_array[i].district_name;
				district_pulldown.options[idx].value = data.district_array[i].district_value;
			}
		}
		else{
			district_pulldown.length = 0;
		}
	}
}
