//Class represents a dropdown list that changes the value and the target dropdowns that mirror that value

function dropDownTarget_AddTargetDrownDownChild(dropDownTargetChildName)
{
    //Simple check to insure that we do not try to add the name to the change list
    if (this.targetDropDownID != dropDownTargetChildName)
    {
        if (this.targetDropDownChildrenIDs == null)
        {
            //This is the first addition into the collection, initialize the
            //collection and add the value
            this.targetDropDownChildrenIDs = new Array(1);
            this.targetDropDownChildrenIDs[0] = dropDownTargetChildName;
        }
        else  
        {
            var ddlNameTarget = null;
            var ddlName=null;
            
            //Search for the target name            
	        for (i = 0; i < this.targetDropDownChildrenIDs.length; i++)
	        {
	            ddlName = this.targetDropDownChildrenIDs[i];
	            
                if (ddlName == dropDownTargetChildName)
                {
                    ddlNameTarget = ddlName
                }
            }
            
            //Did not find the name, so we add the child target name.
            if (ddlNameTarget ==null)
            {
                this.targetDropDownChildrenIDs.push(dropDownTargetChildName);
            }
            
        }
	    
	    //alert(this.targetDropDownChildrenIDs.length);
    }
            
}

function dropDownTarget_SetDropDownsToSelectedIndex(sender, selectedIndex)
{
    //alert("dropDownTarget_SetDropDownsToSelectedIndex");
    if (this.targetDropDownChildrenIDs != null)
    {
        for (i = 0; i < this.targetDropDownChildrenIDs.length; i++)
        {
            //Set the name of the drop down control to be updated
            ddlName = this.targetDropDownChildrenIDs[i];
            //alert(i + " - " + ddlName);            
            //alert(this.targetDropDownID);
            
            //Final check to make sure we do not update the value we 
            //are listening to a different value, causing an in advertant
            //circular reference
            if( this.targetDropDownID != ddlName)
            {	        
                //Calls the common method to change a drop down.
                setDropDownList(sender, ddlName, selectedIndex);
            }
        }
    }
        
}


//Constructor
function dropDownTarget(targetKeyItem)
{
    //alert("Constructor - targetKeyItem: " + targetKeyItem);
    this.targetKey = targetKeyItem; //Property is the key that relates the drop downs
    //alert("Constructor - this.targetKey: " + this.targetKey);
    this.targetDropDownID = ""; //ID of the dropdown whose value is to be monitored
    this.targetDropDownChildrenIDs = null;  //collection of children ids to update
    this.AddTargetDrownDownChild = dropDownTarget_AddTargetDrownDownChild; //
    this.SetDropDownsToSelectedIndex = dropDownTarget_SetDropDownsToSelectedIndex;
}
