<!--

// place -> train
// PlaceObject -> TrainObject
// setData -> setTrainData
// selected_Check -> selected_Train_Check

// from -> train__pulldown_form

var train;

var company_data = new Array();
var line_data = new Array();
var station_data = new Array();

var select_rule;

//プルダウン初回表示時の初期化
function train_data_initialize(select_rule_tmp, company_id, line_id, station_id) {
    select_rule = select_rule_tmp;
    train = new TrainObject("company_id", "line_id", "station_id", "train_pulldown_form", document);
    train.initialCompany();
    train.setTrainData(company_id, line_id, station_id);
}

function TrainObject( company, line, station, f, document  ) {

    this.companyName = company;
    this.lineName = line;
    this.stationName = station;
    this.formName = f;

    this.document = document;
    this.initialCompany = initialCompany;
    this.initialLine = initialLine;
    this.initialStation = initialStation;
    this.setCompany = setCompany;
    this.changeCompany = changeCompany;
    this.changeLine = changeLine;
    this.changeStation = changeStation;
    this.setTrainData = setTrainData;
}

function initialCompany() {
    this.setCompany();
    this.initialLine();
    this.initialStation();
}

function setTrainData(company_id, line_id, station_id){
    var company_index = 0;
    var line_index = 0;
    var station_index = 0;
    var f = this.document.forms[this.formName];

    if(company_id != ""){
        for( i=0; i<f[this.companyName].length; i++){
            if(company_id == f[this.companyName][i].value){
                company_index = i;
            }
        }
        f[this.companyName].options[company_index].selected = true;
        train.changeCompany(company_index);

        if(line_id != ""){
            for( i=0; i<f[this.lineName].length; i++){
                if(line_id == f[this.lineName][i].value){
                    line_index = i;
                }
            }
            f[this.lineName].options[line_index].selected = true;
            train.changeLine(line_index);

            if(station_id != ""){
                for( i=0; i<f[this.stationName].length; i++){
                    if(station_id == f[this.stationName][i].value){
                        station_index = i;
                    }
                }
                f[this.stationName].options[station_index].selected = true;
		train.changeStation(station_index);//★追加★

            }
        }
    }
}


function setCompany() {
    var f = this.document.forms[this.formName];
    f[this.companyName].options[0] = new Option( "路線・駅の選択", "",true,true );
    for( i=0 ; i<company_data.length ; i++ ) {
        f[this.companyName].options[i+1] = new Option( company_data[i].name, company_data[i].id );
    }
}

function initialLine() {
    var f = this.document.forms[this.formName];
    f[this.lineName].options[0] = new Option( "----", "",true,true );
}

function initialStation() {
    var     f = this.document.forms[this.formName];
    f[this.stationName].options[0] = new Option( "----", "", true, true);
}


function call_changeCompany( obj, idx ) {
    obj.changeCompany(idx);
}

function call_changeLine( obj, idx ) {
    obj.changeLine(idx)
}

function call_changeStation( obj, idx ) {
    obj.changeStation(idx)
}

function changeCompany( idx ) {
    var     i,j;
    var     f = this.document.forms[this.formName];

    f[this.lineName].options[0].selected = true;
    f[this.lineName].options.length = 1;
    f[this.stationName].options.length = 1;

    if( f[this.companyName].options[idx].value == "" ) {
        this.initialLine();
    }
    else {
        for( i=1 ; i<f[this.lineName].options.length ; i++ ) {
            f[this.lineName].options[i].value = "";
            f[this.lineName].options[i].text = "";
        }
        f[this.lineName].options[0].selected = true;
        f[this.lineName].options[0] = new Option( "----", "", true, true );
        for( i=0,j=1 ; i<line_data.length ; i++ ) {
            if( line_data[i].company == f[this.companyName].options[idx].value ) {
                f[this.lineName].options[j] = new Option( line_data[i].name, line_data[i].id );
                j++;
            }
        }
    }
    this.initialStation();

    //htmlとhiddenの値を変更
    document.getElementById("form_company_id").value        = f[this.companyName].options[idx].value;
    document.getElementById("form_line_id").value        = "";
    document.getElementById("form_station_id").value        = "";
}


function changeLine( idx ) {
    var     i,j;
    var     f = this.document.forms[this.formName];

    f[this.stationName].options.length = 1;
    f[this.stationName].options[0].selected = true;

    if( f[this.lineName].options[idx].value == "" ) { //シティのプルダウンで「----」を選択した場合

        this.initialStation();

    }

    else {

        f[this.stationName].options[0] = new Option( "----", "",true,true );
        j = 1;
        for( i=0 ; i<station_data.length ; i++ ) {
            if( station_data[i].line == f[this.lineName].options[idx].value ) {
                f[this.stationName].options[j] = new Option( station_data[i].name, station_data[i].id );
                j++;
            }
        }

    }

    //htmlとhiddenの値を変更
    document.getElementById("form_line_id").value        = f[this.lineName].options[idx].value;
    document.getElementById("form_station_id").value        = "";
}

function changeStation( idx ) {

    var f = this.document.forms[this.formName];
 
    //htmlとhiddenの値を変更
    document.getElementById("form_station_id").value        = f[this.stationName].options[idx].value;

}




function selected_Train_Check() {
    var f = this.document.forms[train.formName];
    var companyIdOK = "NG";
    var lineIdOK = "NG";
    var stationIdOK = "NG";

    //移動の場合
    if(select_rule=="move"){

	if (f[train.companyName].value != "") {
            companyIdOK = "OK";
	}
	if (f[train.lineName].value != "") {
            lineIdOK = "OK";
	}
	
	if (f[train.stationName].value != "") {
            stationIdOK = "OK";
	}
	
	if (companyIdOK=="OK" && lineIdOK=="OK" && stationIdOK=="OK") {
	    
            return true;
	    
	} else {
            alert("すべて選択してください。");
            return false;
	}

    }

    //店舗登録・編集の場合（2010/04/22・今のところ使ってない）
    else{

	if (f[train.companyName].value != "") {
            companyIdOK = "OK";
	}
	if (f[train.lineName].value != "") {
            lineIdOK = "OK";
	}
	
	if (f[train.stationName].value != "") {
            stationIdOK = "OK";
	}
	
	if (companyIdOK=="OK" && lineIdOK=="OK" && stationIdOK=="OK") {
	    
            return true;
	    
	} else {
            alert("すべて選択してください。");
            return false;
	}

    }


}


//----------------------------- 以下はエリアデータ -----------------------------

function CompanyObject( id, name ) {
    this.id = id;
    this.name = name;
}

function LineObject( id, name, company_id ) {
    this.id = id;
    this.name = name;
    this.company = company_id;
}

function StationObject( id, name, line_id ) {
    this.id = id;
    this.name = name;
    this.line = line_id;
}


company_data[0] = new CompanyObject('18','シンガポールの路線');

line_data[0] = new LineObject('104','MRT東西線','18');
line_data[1] = new LineObject('105','MRT南北線','18');
line_data[2] = new LineObject('106','MRT北東線','18');
line_data[3] = new LineObject('107','MRTサークル線','18');
line_data[4] = new LineObject('108','セントーサ・エクスプレス','18');

station_data[0]  = new StationObject('974','パシ・リス駅','104');
station_data[1]  = new StationObject('975','タンピニス駅','104');
station_data[2]  = new StationObject('976','シメイ駅','104');
station_data[3]  = new StationObject('977','タナ・メラ駅','104');
station_data[4]  = new StationObject('978','ベドク駅','104');
station_data[5]  = new StationObject('979','クンバンガン駅','104');
station_data[6]  = new StationObject('980','ユーノス駅','104');
station_data[7]  = new StationObject('981','パヤ・レバ駅','104');
station_data[8]  = new StationObject('982','アルジュニード駅','104');
station_data[9]  = new StationObject('983','カラン駅','104');
station_data[10]  = new StationObject('984','ラヴェンダー駅','104');
station_data[11]  = new StationObject('985','ブギス駅','104');
station_data[12]  = new StationObject('986','シティ・ホール駅','104');
station_data[13]  = new StationObject('987','ラッフルズ・プレイス駅','104');
station_data[14]  = new StationObject('988','タンジョン・パガー駅','104');
station_data[15]  = new StationObject('989','アウトラム・パーク駅','104');
station_data[16]  = new StationObject('990','ティオン・バル駅','104');
station_data[17]  = new StationObject('991','レッドヒル駅','104');
station_data[18]  = new StationObject('992','クイーンズタウン駅','104');
station_data[19]  = new StationObject('993','コモンウェルス駅','104');
station_data[20]  = new StationObject('994','ブオナ・ヴィスタ駅','104');
station_data[21]  = new StationObject('995','ドーヴァー駅','104');
station_data[22]  = new StationObject('996','クレメンティ駅','104');
station_data[23]  = new StationObject('997','ジュロン・イースト駅','104');
station_data[24]  = new StationObject('998','チャイニーズ・ガーデン駅','104');
station_data[25]  = new StationObject('999','レイクサイド駅','104');
station_data[26]  = new StationObject('1000','ブーン・レイ駅','104');
station_data[27]  = new StationObject('1001','パイオニア駅','104');
station_data[28]  = new StationObject('1002','ジュー・クーン駅','104');
station_data[29]  = new StationObject('1003','エキスポ駅','104');
station_data[30]  = new StationObject('1004','チャンギ・エアポート駅','104');
station_data[31]  = new StationObject('997','ジュロン・イースト駅','105');
station_data[32]  = new StationObject('1005','ブキ・パトック駅','105');
station_data[33]  = new StationObject('1006','ブキ・ゴンバック駅','105');
station_data[34]  = new StationObject('1007','チョア・チュー・カン駅','105');
station_data[35]  = new StationObject('1008','ユー・ティー駅','105');
station_data[36]  = new StationObject('1009','スンガイ・カドゥ駅','105');
station_data[37]  = new StationObject('1010','クランジ駅','105');
station_data[38]  = new StationObject('1011','マーシリン駅','105');
station_data[39]  = new StationObject('1012','ウッドランズ駅','105');
station_data[40]  = new StationObject('1013','アドミラルティ駅','105');
station_data[41]  = new StationObject('1014','センバワン駅','105');
station_data[42]  = new StationObject('1015','キャンベラ駅','105');
station_data[43]  = new StationObject('1016','イーシュン駅','105');
station_data[44]  = new StationObject('1017','カティブ駅','105');
station_data[45]  = new StationObject('1018','ヨー・チュー・カン駅','105');
station_data[46]  = new StationObject('1019','アン・モ・キオ駅','105');
station_data[47]  = new StationObject('1020','ビシャン駅','105');
station_data[48]  = new StationObject('1021','ブラッデル駅','105');
station_data[49]  = new StationObject('1022','トア・パヨ駅','105');
station_data[50]  = new StationObject('1023','ノヴィナ駅','105');
station_data[51]  = new StationObject('1024','ニュートン駅','105');
station_data[52]  = new StationObject('1025','オーチャード駅','105');
station_data[53]  = new StationObject('1026','サマセット駅','105');
station_data[54]  = new StationObject('1027','ドービー・ゴート駅','105');
station_data[55]  = new StationObject('986','シティ・ホール駅','105');
station_data[56]  = new StationObject('987','ラッフルズ・プレイス駅','105');
station_data[57]  = new StationObject('1028','マリーナ・ベイ駅','105');
station_data[58]  = new StationObject('1029','ハーバー・フロント駅','106');
station_data[59]  = new StationObject('989','アウトラム・パーク駅','106');
station_data[60]  = new StationObject('1030','チャイナタウン駅','106');
station_data[61]  = new StationObject('1031','クラークキー駅','106');
station_data[62]  = new StationObject('1027','ドービー・ゴート駅','106');
station_data[63]  = new StationObject('1032','リトル・インディア駅','106');
station_data[64]  = new StationObject('1033','ファラー・パーク駅','106');
station_data[65]  = new StationObject('1034','ブーン・ケン駅','106');
station_data[66]  = new StationObject('1035','ポトン・パシール駅','106');
station_data[67]  = new StationObject('1036','ウッドレイ駅','106');
station_data[68]  = new StationObject('1037','セラングーン駅','106');
station_data[69]  = new StationObject('1038','コヴァン駅','106');
station_data[70]  = new StationObject('1039','ハウガン駅','106');
station_data[71]  = new StationObject('1040','ブアンコック駅','106');
station_data[72]  = new StationObject('1041','センカン駅','106');
station_data[73]  = new StationObject('1042','ポンゴル駅','106');
station_data[74]  = new StationObject('1027','ドービー・ゴート駅','107');
station_data[75]  = new StationObject('1043','ブラス・バサー駅','107');
station_data[76]  = new StationObject('1044','エスプラネード駅','107');
station_data[77]  = new StationObject('1045','プロムナード駅','107');
station_data[78]  = new StationObject('1046','ニコル・ハイウェイ駅','107');
station_data[79]  = new StationObject('1047','スタジアム駅','107');
station_data[80]  = new StationObject('1048','マウントバッテン駅','107');
station_data[81]  = new StationObject('1049','ダコタ駅','107');
station_data[82]  = new StationObject('981','パヤ・レバ駅','107');
station_data[83]  = new StationObject('1050','マクファーソン駅','107');
station_data[84]  = new StationObject('1051','タイ・セン駅','107');
station_data[85]  = new StationObject('1052','バートレイ駅','107');
station_data[86]  = new StationObject('1037','セラングーン駅','107');
station_data[87]  = new StationObject('1053','ロロン・チュアン駅','107');
station_data[88]  = new StationObject('1020','ビシャン駅','107');
station_data[89]  = new StationObject('1054','メアリーマウント駅','107');
station_data[90]  = new StationObject('1055','トムソン駅','107');
station_data[91]  = new StationObject('1056','ブキ・ブラウン駅','107');
station_data[92]  = new StationObject('1057','ボタニック・ガーデンズ駅','107');
station_data[93]  = new StationObject('1058','ファラー・ロード駅','107');
station_data[94]  = new StationObject('1059','ホランド・ビレッジ駅','107');
station_data[95]  = new StationObject('994','ブオナ・ヴィスタ駅','107');
station_data[96]  = new StationObject('1060','ワン・ノース駅','107');
station_data[97]  = new StationObject('1061','ケント・リッジ駅','107');
station_data[98]  = new StationObject('1062','ウエスト・コースト駅','107');
station_data[99]  = new StationObject('1063','パシ・パンジャン駅','107');
station_data[100]  = new StationObject('1064','ラブラドール・パーク駅','107');
station_data[101]  = new StationObject('1065','テロック・ブランガ駅','107');
station_data[102]  = new StationObject('1029','ハーバー・フロント駅','107');
station_data[103]  = new StationObject('1029','ハーバー・フロント駅','108');
station_data[104]  = new StationObject('1066','ウォーターフロント駅','108');
station_data[105]  = new StationObject('1067','インビア駅','108');
station_data[106]  = new StationObject('1068','ビーチ駅','108');
station_data[107]  = new StationObject('1069','ベイフロント駅','107');

-->

