if( !new Array().push ) {
  Array.prototype.push = function(o) { this[this.length] = o; }
}

Array.prototype.contains = function(o) {
  for( var i = 0; i < this.length; i++ ) {
    if( this[i] == o ) {
      return true;
    }
  }
  
  return false;
}

function SiteGroupManager() {
  this.parentArray = new Array();
  this.addPair = SiteGroupManager_addPair;
  this.getChildren = SiteGroupManager_getChildren;
  this.cache = new Array();
}

function SiteGroupManager_addPair( parentId, childId ) {
  var childArray = this.parentArray[parentId];
  if( !childArray ) {
    childArray = new Array();
    this.parentArray[parentId] = childArray;
  }
  
  childArray.push( childId );
  this.cache[parentId] = false;
}

function SiteGroupManager_getChildren( parentId ) {
  var childArray = this.parentArray[parentId];
  if( !childArray ) {
    return new Array();
  }
  
  return childArray;
}

function synchronizeGroups( siteGroupManager, parentSelect, childSelect ) {
  for( var p = 0; p < parentSelect.options.length; p++ ) {
    if( parentSelect.options[p].selected != siteGroupManager.cache[p] ) {
      siteGroupManager.cache[p] = parentSelect.options[p].selected;
    
      var childArray = siteGroupManager.getChildren( parentSelect.options[p].value );

      for( var c = 0; c < childSelect.options.length; c++ ) {
        if( childArray.contains( childSelect.options[c].value ) ) {
          childSelect.options[c].selected = siteGroupManager.cache[p];
        }
      }
    }
  }
}