function change_prefecture(prefecture_id, insert_select_name, init_select_names){

    var i;
    init_select_obj(insert_select_name);
    for(i=0; i<init_select_names.length; i++){
        init_select_obj(init_select_names[i]);
    }

    new Ajax.Request('/api/area/prefecture2city?prefecture_id=' + prefecture_id, {
        method: "get",
        onSuccess:function(httpObj){
            eval("var res =" + httpObj.responseText )

            for(i=0; i<res.length; i++){
                $(insert_select_name).options[i+1] = new Option(res[i].name, res[i].city_id);
            }
        },
        onFailure:function(httpObj){
        }
    });
}

function change_city(city_id, insert_select_name){

    var i;
    init_select_obj(insert_select_name);

    new Ajax.Request('/api/area/city2station?city_id=' + city_id, {
        method: "get",
        onSuccess:function(httpObj){
            var i;
            eval("var res =" + httpObj.responseText )

            for(var i=0; i<res.length; i++){
                $(insert_select_name).options[i+1] = new Option(res[i].name, res[i].station_id);
            }
        },
        onFailure:function(httpObj){
        }
    });
}

function init_select_obj(select_name){
    
    var option_length = $(select_name).options.length;
    for(i=0; i<option_length; i++){
        $(select_name).options[0] = null;
    }
    $(select_name).options[0] = new Option('指定しない','');

}

function load_select_obj(select_name, value){
    if(value != ''){
       var i;
        var select_obj = document.getElementById(select_name);
        for(i=0; i< select_obj.length; i++){
            if(select_obj.options[i].value == value){
                select_obj.selectedIndex = i;
                select_obj.onchange();
                break;
            }
        }
    }
}

function reset_select_obj(){
	document.forms[0].elements[0].value='';
	document.forms[0].elements[1].selectedIndex=0;
	change_prefecture('', 'city_id', ['station_id']);
}