//AnoS-AnoE 利用区間設定--------------------------------------------------------------------------------------
//北海道〜九州の順
var arraySelectArea = [
                        [1],
                        [2, 3, 4, 5, 6],
                        [2, 3, 4, 5, 6, 7, 8],
                        [2, 3, 4, 5, 6, 7, 8],
                        [2, 3, 4, 6],
                        [2, 3, 4, 5, 6, 7, 8, 9],
                        [3, 4, 6, 8, 9],
                        [3, 4, 6, 7, 9],
                        [6, 7, 8]
                      ];

var arrayAreaName = [ '北海道', '東北', '関東', '東海・甲信越', '北陸', '近畿', '中国', '四国', '九州'];
//-----------------------------------------------------------------------------------------------------------

function Change_AnoS(Anos) {

    var i = 0;
    var SelectValue;
    for (i = 0; i < Anos.length; i++) {
        if (Anos[i].selected) {
            SelectValue = Anos[i].value - 1;
        }
    }


    var optioncnt = document.getElementById('AnoE').options.length;

    for (i = optioncnt - 1; i >= 0; i--) {
        document.getElementById('AnoE').options[i] = null;
    }

    for (i = 0; i < arraySelectArea[SelectValue].length; i++) {
        document.getElementById('AnoE').options[i] = new Option(arrayAreaName[arraySelectArea[SelectValue][i] - 1], arraySelectArea[SelectValue][i]);
    }


}


function SearchBus() {

    var AnoS = document.getElementById('AnoS').options[document.getElementById('AnoS').selectedIndex].value;
    var AnoE = document.getElementById('AnoE').options[document.getElementById('AnoE').selectedIndex].value;

    var ErrFlg = 0;

    ErrFlg = CheckSelectValue(AnoS);

    if (ErrFlg != 0) {
        return false;
    }
        
    
    ErrFlg = CheckSelectValue(AnoE);

    if (ErrFlg != 0) {
        return false;
    }

    if (ErrFlg == 0) {
        window.open('http://www.jtb.co.jp/bus_tkt3/registfrom.aspx?registfrom=RC01&redirecturl=http://www.jtb.co.jp/bus/list/listArea.asp?AnoS=' + AnoS + '%26AnoE=' + AnoE, "", "");
    } else {
        return false;
    }
}

function CheckSelectValue(Value) {

    if (Value.length == 0) {
        return 1;
    } else if (isNaN(Value)) {
        return 1;
    } else if (!(Value >= 1 && Value <= 9)) {
        return 1;
    }
    
    return 0;

}
