﻿// JScript File
function fillAreaList(typeID,subBoxID)
{
    if (subBoxID!='')
    {
        subListBox=document.getElementById(subBoxID);
        subListBox.length=0;
        subListBox.visible = "true";
        var areaArr=new Array();
        areaArr = getAreaArr(typeID);
        if (areaArr.length>0)
        {
            subListBox.options[0] = new Option('选择地区','');
            for (i=0;i < areaArr.length; i++) 
            {
               subListBox.options[i+1] = new Option(areaArr[i][0],areaArr[i][1]);
            }
         }
         else
            disableBox(subBoxID);
    }    
}

function disableBox(listBox)
{
    var listbox = document.getElementById(listBox);
    listbox.selectedIndex=-1;
    listbox.length = 0;
    listbox.visible = "false";
}


//set area by areaID
function setTypeList(areaID,selectBoxID1,selectBoxID2,selectBoxID3)
{
            
    fillAreaList('',selectBoxID1);
    var typeID1='';
    var typeID2='';
    var typeID3='';
    switch(areaID.length)
    {
        case 2:
            fillAreaList(areaID,selectBoxID2);
            selectAreaOption(areaID,selectBoxID1); 
            break;
            
        case 4:
            typeID1 = areaID.substring(0,2);
            selectAreaOption(typeID1,selectBoxID1)
            fillAreaList(typeID1,selectBoxID2);
            selectAreaOption(areaID,selectBoxID2);
            fillAreaList(areaID,selectBoxID3);
             
            break;
        case 6:
            typeID1 = areaID.substring(0,2);
            
            selectAreaOption(typeID1,selectBoxID1)
            fillAreaList(typeID1,selectBoxID2);
            
            typeID2 = areaID.substring(0,4);
            selectAreaOption(typeID2,selectBoxID2)
            
            fillAreaList(typeID2,selectBoxID3);
            selectAreaOption(areaID,selectBoxID3); 
            break;
            
         case 8:
            typeID1 = areaID.substring(0,2);
            selectAreaOption(typeID1,selectBoxID1)
            fillAreaList(typeID1,selectBoxID2);
            
            typeID2 = areaID.substring(0,4);
            selectAreaOption(typeID2,selectBoxID2)
            fillAreaList(typeID2,selectBoxID3);
            
            typeID3 = areaID.substring(0,6);
            selectAreaOption(typeID3,selectBoxID3); 
            fillAreaList(typeID3,selectBoxID4);
            
            selectAreaOption(areaID,selectBoxID4); 
            break;
            
        default:break;
    }
}

function setAreaID(areaID,areaIDBox)
{
    var temp = document.getElementById(areaIDBox);
    temp.value = areaID;
}

function selectAreaOption(areaID,selectBoxID)
{
    var listBox=document.getElementById(selectBoxID);
    for (var i=0; i<listBox.length; i++)
    {
        if (listBox.options[i].value == areaID) listBox.selectedIndex = i;
    }
}
function loadCity(areaID,areaIDBox) { 
    var cityselect = document.getElementById(areaIDBox);
    if (cityselect!=null)
    {
        var cityArr = new Array();
        cityArr = getCityArr();
        cityselect.options[0] = new Option('所在地','');
        for (var i=0; i<cityArr.length; i++)
        {
            cityselect.options[i+1] = new Option(cityArr[i][0],cityArr[i][1]);
            if(areaID.substring(0,4)==cityArr[i][1]) cityselect.selectedIndex=i+1;
        }
    }
}