
function UpdateSelectedPolicies(SelectedElement) 
{ 
    //If turning an item on, all parents also need to be on
    if (SelectedElement.checked == true)
    {
        if (SelectedElement.parent != 0)
        {
            var ParentID = 'nodeidvalue' + SelectedElement.parent;
            if (document.getElementById(ParentID).checked == false)
            {
                //var ParentName = document.getElementById(ParentID).name;
                //alert (ParentName);
                //alert('Need to switch on parent');
                document.getElementById(ParentID).checked = true;
                UpdateSelectedPolicies(document.getElementById(ParentID));
            }
        }
    }
    else
    {
        //If turning an item off, all children need to be off
        UpdateChildrenPolicies(SelectedElement.idvalue);
    }
    
    //RN 18/12/2007 - If child nodes haven't yet been drawn then their state can't be correctly adjusted, so either EVERYTHING needs to happen in Javascript, or each click
    // needs to go back to the server so that the C# code can deal with updating children and parents of nodes that haven't been drawn yet
    document.policymanager.submit();
}

function UpdateChildrenPolicies(idvalue)
{
    var InputNodes = document.getElementsByTagName("input");
    for (var i=0;i<InputNodes.length;i++) 
    {
      if (InputNodes[i].parent == idvalue)
      {
        InputNodes[i].checked = false;
      }
    }
    //RN - If there are child items that do not exist in the tree because the nodes have not yet been drawn in ajax, they cannot be deselected by javascript
    //      however the save routine in C# will go through all items and set them correctly.  We could automatically de-select items in the ajax method of their 
    //      parent has been de-selected, however this would be dangerous because then it would appear to them that no child elements were selected, whereas 
    //      in the database they would be selected.
    
    //alert('Collapsed child navigation items may not be deselected');

}

function DeletePolicyItem()
{
    if(confirm('This action will Delete the selected item and ALL of its children'))
    {
        document.policymanager.deletepressed.value = 1;
        document.policymanager.submit();
    }
}

