<!--

function PlaceObject( a, co, ci, f, document  ) {

    this.areaName = a;
    this.countryName = co;
    this.cityName = ci;
    this.formName = f;

    this.document = document;
    this.initialArea = initialArea;
    this.initialCountry = initialCountry;
    this.initialCity = initialCity;
    this.setArea = setArea;
    this.changeArea = changeArea;
    this.changeCountry = changeCountry;
    this.setData = setData;
}


function setArea() {
    var f = this.document.forms[this.formName];

    f[this.areaName].options[0] = new Option( "都道府県を選択", "",true,true );
    for( i=0 ; i<area1.length ; i++ ) {
        f[this.areaName].options[i+1] = new Option( area1[i].name, area1[i].code );
    }
}

function initialCountry() {
    var f = this.document.forms[this.formName];
    f[this.countryName].options[0] = new Option( "地域を選択", "",true,true );
}

function initialCity() {
    var     f = this.document.forms[this.formName];
    f[this.cityName].options[0] = new Option( "指定なし", "", true, true);
}

function initialArea() {
    this.setArea();
    this.initialCountry();
    this.initialCity();
}

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

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

    if( f[this.areaName].options[idx].value == "" ) {
        this.initialCountry();
    }
    else {
        for( i=1 ; i<f[this.countryName].options.length ; i++ ) {
            f[this.countryName].options[i].value = "";
            f[this.countryName].options[i].text = "";
        }
        f[this.countryName].options[0].selected = true;
        f[this.countryName].options[0] = new Option( "地域を選択", "", true, true );
        for( i=0,j=1 ; i<country1.length ; i++ ) {
            if( country1[i].area == f[this.areaName].options[idx].value ) {
                f[this.countryName].options[j] = new Option( country1[i].name, country1[i].code );
                j++;
            }
        }
    }
    this.initialCity();
}

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

    f[this.cityName].options.length = 1;
    f[this.cityName].options[0].selected = true;
    if( f[this.countryName].options[idx].value == "" ) {
        this.initialCity();
    }
    else {
        f[this.cityName].options[0] = new Option( "指定なし", "",true,true );
        j = 1;
        for( i=0 ; i<city1.length ; i++ ) {
            if( city1[i].country == f[this.countryName].options[idx].value ) {
                f[this.cityName].options[j] = new Option( city1[i].name, city1[i].code );
                j++;
            }
        }
    }
}

function setData(area_cd, country_cd, city_cd){
    var area_index = 0;
    var country_index = 0;
    var city_index = 0;
    var f = this.document.forms[this.formName];

    if(area_cd != ""){
        for( i=0; i<f[this.areaName].length; i++){
            if(area_cd == f[this.areaName][i].value){
                area_index = i;
            }
        }
        f[this.areaName].options[area_index].selected = true;
        place.changeArea(area_index);

        if(country_cd != ""){
            for( i=0; i<f[this.countryName].length; i++){
                if(country_cd == f[this.countryName][i].value){
                    country_index = i;
                }
            }
            f[this.countryName].options[country_index].selected = true;
            place.changeCountry(country_index, 1);

            if(city_cd != ""){
                for( i=0; i<f[this.cityName].length; i++){
                    if(city_cd == f[this.cityName][i].value){
                        city_index = i;
                    }
                }
                f[this.cityName].options[city_index].selected = true;
            }
        }
    }
}


var place;

function area_initialize(area_cd, country_cd, city_cd) {

//    place = new PlaceObject("area","country","city","form",document);
    place = new PlaceObject("TODOFUKEN_CODE","SHIGUN_CODE","KUCHOSON_CODE","form",document);
    place.initialArea();
    place.setData(area_cd, country_cd, city_cd);
}


function call_changeArea_1( obj, idx ) {
    obj.changeArea(idx);
}


function call_changeCountry( obj, idx ) {
    obj.changeCountry(idx)
}

function Selected_Check() {
    var f = this.document.forms[place.formName];
    var areaCodeOK = "NG";
    var countryCodeOK = "NG";
    var cityCodeOK = "NG";

    if (f[place.areaName].value != "") {
        areaCodeOK = "OK";
    }
    if (f[place.countryName].value != "") {
        countryCodeOK = "OK";
    }
    if (f[place.cityName].value != "") {
        cityCodeOK = "OK";
    }
    if (areaCodeOK == "OK" && countryCodeOK == "OK") {
        return true;
    } else {
        alert("都道府県と地域は必ず選択してください");
        return false;
    }
}


-->

