function Agence(id) {
  this.id = id;
  this.departements = new Array();
  this.addDepartement = function(dep) {
    this.departements[this.departements.length] = dep;
  }
  this.match = function(dep) {
    for(var i=0;i<this.departements.length;i++) {
      if(this.departements[i].indexOf(dep)==0) {
        return true;
      }
    }
  }
}

function hide() {
  var comp = document.getElementById('agencies_cp').value;
  if(comp.length>2) {
    comp = comp.substring(0,2);
  }
  var tabStyle = new Array("agenciesItem first","agenciesItem","agenciesItem grey first","agenciesItem grey");
  
  hideError();
  for(var i=0;i<agences.length;i++) {
    document.getElementById('agence' + agences[i].id).style.display = 'none';
  }
  
  var n = 0,mydiv;
  
  for(var i=0;i<agences.length;i++) {
    if(agences[i].match(comp)) {
      mydiv = document.getElementById('agence' + agences[i].id);
      mydiv.className = tabStyle[n%4];
      mydiv.style.display = 'block';
      n++;
    }
  }
  if(n==0) {
    showError();
  }
}

function hideError(){
  document.getElementById("notFound").style.display="none";
}

function showError(){
  document.getElementById("notFound").style.display="block";
}