//=============================================================================


function SubmitFormNormal() {
	document.myForm.submit();
}

var gflg_ajax;

//=============================================================================
// XMLHttpRequest
//=============================================================================

var XMLHTTP_LOAD_COMPLETE = 4;
var XMLHTTP_HTTP_STATUS = 200;
var MSXMLHTTP = false;
var xmlhttp = createXmlHttp();

function createXmlHttp() {

	var xo = false;
	
	try {
		xo = new ActiveXObject("Msxml2.XMLHTTP");
		MSXMLHTTP = true;
	} catch (e) {
		try {
			xo = new ActiveXObject("Microsoft.XMLHTTP");
			MSXMLHTTP = true;
		}
		catch (e) {
			xo = false;
		}
	}
	
	if (!xo && typeof XMLHttpRequest != 'undefined') {
		xo = new XMLHttpRequest();
	}
	
	if (!xo) {
		// Ajax未対応の場合
		gflg_ajax = "0";
	}
	
	return xo;

}


//=============================================================================
// フォーム内容の送信
//=============================================================================

function SubmitForm( vstr_action, vstr_prefcode, vstr_school_zoneid ) {

	//------------------------------------
	
	if (gflg_ajax == "0") {
		// Ajax未対応の場合
		SubmitFormNormal();
	}
	
	//------------------------------------
	
	var vbool;
	var vstr_input_value;
	var vstr_select_value;
	
	//------------------------------------
	// 送信データの取得
	//------------------------------------
	
	var vobj_input = document.getElementsByTagName("select");
//	vstr_select_value = vobj_input[0].value;
	vstr_select_value = "";
	
	//------------------------------------
	// 送信データの整形
	//------------------------------------
	
	try {
//			vstr_select_value = vstr_select_value.substr(vtemp, -1);
		vstr_select_value = vstr_select_value.replace(/undefined/, "");
		vstr_select_value = vstr_select_value.replace(/ /, "");
		vstr_select_value = vstr_select_value.replace(/\,$/, "");
	}
	catch (e) {
	
	}
	
	//------------------------------------
	// POST処理
	//------------------------------------
	
	var postdata;
	postdata = 'prefcode=' + encodeURIComponent(vstr_prefcode);
	postdata += '&' + 'school_zoneid='       + encodeURIComponent(vstr_school_zoneid);
	postdata += '&' + 'mode=' + encodeURIComponent(vstr_action);
	
//	alert(postdata);
	
	try {
	
		if (xmlhttp.readyState != 0) {
			xmlhttp.abort();
		}
		
		xmlhttp.open("POST", SUBMIT_PAGE, true);
		
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4 && xmlhttp.responseText) {
				onloaded(xmlhttp.responseText);
			}
		}
		
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(postdata);
	
	} catch (e) {
	
		alert(e);
	
	}
	
	//------------------------------------
}


//=============================================================================
// サーバーからデータを受け取った後の処理
//=============================================================================

function onloaded(res) {

	//----------------------------------
	// サーバーからのデータの受け取り
	//----------------------------------
	
	vstr_html = res;
	
	vastr_html = vstr_html.split("\t");
	
	// 都道府県 select
	try {
		var vstr_select = document.getElementById("prefcode");
		vstr_select.innerHTML = vastr_html[1];
//		alert(vastr_html);
	} catch (e) {
	}
	
	// 校区 select
	try {
		var vstr_select = document.getElementById("school_zoneid");
		vstr_select.innerHTML = vastr_html[0];
	} catch (e) {
	}
	
	
//	var debug = document.getElementById("debug");
//	debug.innerHTML = vstr_html;
	
	//----------------------------------

}


//=============================================================================