<!--  Place Associate List script written entirely in JavaScript  -->
<!--  Written by WenWei, 2001-2004. E-mail: wenwei(AT)blueidea.com  -->
// 地区选项列表
var ALOptions = new Array()

// 城市选项列表
var CLOptions = new Array()

GeneratePlaceList()

// 生成地区和城市选项列表
function GeneratePlaceList()
{
    var ii = 0
    var jj = 0
	
    ALOptions[ii++] = "萧山-|萧山"
    ALOptions[ii++] = "其他-|其他"
   
    
    
    ii = 0
    
    jj = 0
    // ii = 0
    CLOptions[ii] = new Array()
    CLOptions[ii][jj++] = "萧山-楼塔|├-楼塔"
    CLOptions[ii][jj++] = "萧山-河上|├-河上"
    CLOptions[ii][jj++] = "萧山-戴村|├-戴村"
    CLOptions[ii][jj++] = "萧山-临浦|├-临浦"
    CLOptions[ii][jj++] = "萧山-浦阳|├-浦阳"
    CLOptions[ii][jj++] = "萧山-进化|├-进化"
    CLOptions[ii][jj++] = "萧山-所前|├-所前"
    CLOptions[ii][jj++] = "萧山-义桥|├-义桥"
    CLOptions[ii][jj++] = "萧山-闻堰|├-闻堰"
    CLOptions[ii][jj++] = "萧山-宁围|├-宁围"
    CLOptions[ii][jj++] = "萧山-新街|├-新街"
    CLOptions[ii][jj++] = "萧山-衙前|├-衙前"
    CLOptions[ii][jj++] = "萧山-瓜沥|├-瓜沥"
    CLOptions[ii][jj++] = "萧山-坎山|├-坎山"
    CLOptions[ii][jj++] = "萧山-党山|├-党山"
    CLOptions[ii][jj++] = "萧山-益农|├-益农"
    CLOptions[ii][jj++] = "萧山-义蓬|├-义蓬"
    CLOptions[ii][jj++] = "萧山-靖江|├-靖江"
    CLOptions[ii][jj++] = "萧山-南阳|├-南阳"
    CLOptions[ii][jj++] = "萧山-河庄|├-河庄"
    CLOptions[ii][jj++] = "萧山-党湾|├-党湾"
    CLOptions[ii][jj++] = "萧山-新湾|├-新湾"
    CLOptions[ii][jj++] = "萧山-城厢|├-城厢"
    CLOptions[ii][jj++] = "萧山-北干|├-北干"
    CLOptions[ii][jj++] = "萧山-蜀山|├-蜀山"
    CLOptions[ii][jj++] = "萧山-新塘|├-新塘"
	
    
    ii = 0
    jj = 0
}

// Place Associate List Object
function PlaceAssociateList(instance, parent, child, optionList)
{
    this.parent          = parent;              // 父选择框
    this.child           = child;               // 子选择框

    this.instance        = instance;            // 与对象关联的选择框实例

    this.optionList      = optionList;          // 选择框选项列表
    this.initValue       = null;                // 选择框初始值
    
    this.addedOptions    = null;                // 附加选项

    this.incPValue       = false;               // 包含父值
    this.incPValueFormat = "%PText%";           // 包含父值的选项的文本格式

    this.allowEmpty      = false;               // 允许空选项列表

    this.init            = InitPlaceSelector;   // 初始化方法
    this.SetSelectedValue = SetSelectedValue;          // 设置选中值方法

    this.instance.associateObject = this;       // 关联对象与选择框
}

// 选择列表初始化方法
function InitPlaceSelector()
{
    if( this.instance )                                         // 实例存在
    {
        var i, aIndex, aLength, aValueText;
        if( this.child || this.parent == null )                 // 子选择框存在, 则实例为父选择框;
        {
            this.instance.length = 0;                           // 清空实例
            if( this.addedOptions != null )                     // 附加选项
            {
                for( i = 0; i<this.addedOptions.length; i++ )
                {
                    aValueText = this.addedOptions[i].split("|");
                    if( aValueText.length > 0 )                 // 添加选项
                    {
                        this.instance.options[this.instance.length] = new Option(aValueText[1], aValueText[0]);
                        if( aValueText[0] == this.initValue )   // 选中初始值
                            this.instance.options[this.instance.length-1].selected = true;
                    }
                }
            }
            for( i = 0; i<this.optionList.length; i++ )
            {
                aValueText = this.optionList[i].split("|");
                if( aValueText.length > 0 )                     // 添加选项
                {
                    this.instance.options[this.instance.length] = new Option(aValueText[1], aValueText[0]);
                    if( aValueText[0] == this.initValue )       // 选中初始值
                        this.instance.options[this.instance.length-1].selected = true;
                }
            }
            if( this.child ) this.instance.onchange = areaChanged
        }
        else if( this.parent )                                  // 父选择框存在, 则实例为子选择框
        {
            this.parent.onchange();
        }
    }
}

// 父选择列表值改变事件方法
function areaChanged()
{
    if( this.associateObject )
    {
        var i, aLength, aObject, aChildObject, aIndex, aValueText;
        var aParentValue, aParentText;

        aObject = this.associateObject;
        aChildObject = aObject.child.associateObject;
        aParentValue = this.options[this.selectedIndex].value;
        aParentText  = this.options[this.selectedIndex].text;
        aLength = 0;

        aObject.child.length = 0;                               // 清空实例

        if( aObject.addedOptions )                              // 父选择框附加选项数
            aLength = aObject.addedOptions.length;

        if( this.selectedIndex >= aLength )                     // 父选择框选中项不在附加选项中
        {
            aIndex = this.selectedIndex - aLength;
            if( aChildObject.incPValue )                            // 包含父值
            {
                aObject.child.options[aObject.child.length] = new Option(
                    aChildObject.incPValueFormat.replace("%PText%", this.options[this.selectedIndex].text),
                    aParentValue);
                if( aParentValue == aChildObject.initValue )       // 选中初始值
                    aObject.child.options[aObject.child.length-1].selected = true;
            }

            for( i=0; i<aChildObject.optionList[aIndex].length; i++ )
            {
                aValueText = aChildObject.optionList[aIndex][i].split("|");
                if( aValueText.length > 0 && aValueText[0] != aParentValue)       // 添加选项
                {
                    aObject.child.options[aObject.child.length] = new Option(aValueText[1], aValueText[0]);
                    if( aValueText[0] == aChildObject.initValue )       // 选中初始值
                        aObject.child.options[aObject.child.length-1].selected = true;
                }
            }
            if( !aChildObject.allowEmpty && aObject.child.length == 0)
            {
                aObject.child.options[aObject.child.length] = new Option(aParentText, aParentValue);
            }
        }
        else
        {
            if( aChildObject.addedOptions != null )                  // 附加选项
            {
                for( i = 0;i<aChildObject.addedOptions.length; i++ )
                {
                    aValueText = aChildObject.addedOptions[i].split("|");
                    if( aValueText.length > 0 )                 // 添加选项
                    {
                        aObject.child.options[aObject.child.length] = new Option(aValueText[1], aValueText[0]);
                        if( aValueText[0] == aChildObject.initValue )   // 选中初始值
                            aObject.child.options[aObject.child.length-1].selected = true;
                    }
                }
            }
        }
    }
}

function SetSelectedValue(aValue, aWantProcessed)
{
    if( this.instance )
    {
        var optionValue = aValue;
        if( aWantProcessed )
        {
            var optionValues = optionValue.split("-");
            if( optionValues.length > 0 )
                optionValue = optionValues[0] + "-";
        }
       for( i = 0;i<this.instance.options.length; i++ )
        {
           if( this.instance.options[i].value == optionValue )
            {
                this.instance.options[i].selected = true;
                if( this.child )
                {
					this.instance.onchange();
                    this.child.associateObject.SetSelectedValue(aValue, false);
                }
                break;
            }
        }
    }
}