// JavaScript Document

<!--
//サーバサイドのメソッド名を呼び出した戻り値の処理

//市区町村リストを取得した場合のコールバック処理
function GetSchoolCityList_callback() {};
GetSchoolCityList_callback.prototype = {
  execute: function(result) {
    //検索結果をHTML表示する
    document.getElementById('searchCityList').innerHTML = result['html'];
  }
}
//路線リストを取得した場合のコールバック処理
function GetSchoolLineList_callback() {};
GetSchoolLineList_callback.prototype = {
  execute: function(result) {
    //検索結果をHTML表示する
    document.getElementById('searchLineList').innerHTML = result['html'];
    document.getElementById('searchStationList').innerHTML = "<select name=searchStationId id=searchStationId ><option value='' selected>ご選択ください</option></select>";
  }
}
//駅リストを取得した場合のコールバック処理
function GetSchoolStationList_callback() {};
GetSchoolStationList_callback.prototype = {
  execute: function(result) {
    //検索結果をHTML表示する
    document.getElementById('searchStationList').innerHTML = result['html'];
  }
}

//非同期タイプの関数を呼び出す
//newするクラスはPHP側では大文字でもここではすべて小文字にする。
var GetSchoolCityList = new getschoolcitylist(new GetSchoolCityList_callback());
var GetSchoolLineList = new getschoollinelist(new GetSchoolLineList_callback());
var GetSchoolStationList = new getschoolstationlist(new GetSchoolStationList_callback());

//イベント処理のJs関数
function ChangePrefId() {
  //選択された都道府県IDをパラメータに設定してサーバに渡す
  var param = {};
  var index = document.getElementById('prefId').selectedIndex;
  param['prefId'] = document.getElementById('prefId').options[index].value;
  param['schoolFlg'] = document.getElementById('schoolFlg').value;
  document.getElementById('cityId').value = "";
  GetSchoolCityList.execute(param);
}

function ChangeCityId() {
  //選択された市区町村IDを記憶する
  var index = document.getElementById('searchCityId').selectedIndex;
  document.getElementById('cityId').value = document.getElementById('searchCityId').options[index].value;
}

function ChangeAreaId() {
  //選択されたエリアIDをパラメータに設定してサーバに渡す
  var param = {};
  var index = document.getElementById('areaId').selectedIndex;
  param['areaId'] = document.getElementById('areaId').options[index].value;
  param['schoolFlg'] = document.getElementById('schoolFlg').value;
  document.getElementById('lineId').value = null
  document.getElementById('stationId').value = null
  GetSchoolLineList.execute(param);
}

function ChangeLineId() {
  //選択された路線IDをパラメータに設定してサーバに渡す
	var param = {};
  var index = document.getElementById('searchLineId').selectedIndex;
  param['lineId'] = document.getElementById('searchLineId').options[index].value;
  param['schoolFlg'] = document.getElementById('schoolFlg').value;
  document.getElementById('lineId').value = document.getElementById('searchLineId').options[index].value;
  $areaObj = document.getElementById('areaId');
  if($areaObj.type == "hidden"){
    param['areaId'] = document.getElementById('areaId').value;
  }else{
    var index2 = document.getElementById('areaId').selectedIndex;
    param['areaId'] = document.getElementById('areaId').options[index2].value;
  }
  document.getElementById('stationId').value = null
	GetSchoolStationList.execute(param);
}

function ChangeStationId() {
  //選択された駅IDを記憶する
  var index = document.getElementById('searchStationId').selectedIndex;
  document.getElementById('stationId').value = document.getElementById('searchStationId').options[index].value;
}

//-->
