
function EstunChiffre(chiffre) {
  var n=0;
  var cpt=0;
  var tmp;
	for (n=0; n<chiffre.length; n++) {
    tmp=chiffre.substring(n,n+1);
    if ((tmp<"0") || (tmp>"9")) {
      cpt=cpt+1;
    }
	}
	if (cpt!=0) {
    return (false);
  } else { 
    return (true);
  }
}

 function IsFiness() {
    if (existFiness == false) {
       AlertMessage(document.choixGeo.finess,"Le numéro FINESS saisi ne correspond pas à un établissement !")
    } 
 }

function ValiderFiness() {
  if (document.choixGeo.finess.value !="") {
    if (EstunChiffre(document.choixGeo.finess.value)==false) {
      AlertMessage(document.choixGeo.finess,"Le numéro FINESS doit être numérique !")
      return false;
    }
    if (document.choixGeo.finess.value.length!=9) {
      AlertMessage(document.choixGeo.finess,"Le numéro FINESS doit contenir 9 chiffres!")
      return false;
    }
  }
  
  if (existCommune==true) {
    if ((document.choixGeo.commune.value =="0")&&(document.choixGeo.finess.value =="")){
      AlertMessage(document.choixGeo.commune,"Il faut choisir une commune ou un numéro finess!")
      return false;
    }
  }
  
  return true;
}

function ValiderCommune() {
  if ((document.choixGeo.commune.value =="0")&&(document.choixGeo.finess.value =="")) {
    AlertMessage(document.choixGeo.commune,"Il faut choisir une commune ou un numéro finess!")
    return false;
  }
  return true;
}

function InsererFiness() {
  if(ValiderFiness()) {
    if (document.choixGeo.finess.value !="") { 
      document.choixGeo.action="brex_etb.jsp";
      if (existCommune==true) { 
        document.choixGeo.commune.value =""; 
      }
      document.choixGeo.submit();
    }
  }
}

function InsererCommune() {
  if (ValiderCommune()) {
    if (document.choixGeo.commune.value !="0") { 
      document.choixGeo.action="brex_liste_etb.jsp";
      document.choixGeo.finess.value ="";
      document.choixGeo.submit();
    }
  }
}

function Insererdpt() {

    document.choixGeo.finess.value="";
    document.choixGeo.action="brex_selection.jsp";
    document.choixGeo.submit(); 
}

