var chargeFichier_fonction_retour="";

var chargeFichier_zoneCible="";

var XHR_CHARGER_FICHIER=null;
function chargeFichier(url,zoneCible,fonction_retour) {
	// Création de l'objet

  if (document.getElementById(zoneCible)){
    document.getElementById(zoneCible).innerHTML="";
//	alert('k');
  }

  change_anim_souris("block");
  document.body.style.cursor="wait";
  if (document.getElementById("div_loader"))
      document.getElementById("div_loader").style.display="block";

	this.chargeFichier_zoneCible="";
	this.chargeFichier_fonction_retour="";

	this.chargeFichier_fonction_retour='document.location.href="#ANCRE_HAUT";'+fonction_retour;
  this.chargeFichier_zoneCible=zoneCible;

  if (document.getElementById('popup_aide_navigationID')){
    affiche_popup_aide_navigation(false);
  }
  
  var retour=url.split('?');
  if (retour.length==2){
    url=url+'&PHPSESSID='+recup_session_id();
  }else {
    url=url+'?PHPSESSID='+recup_session_id();
  }
  //if (XHR_CHARGER_FICHIER==null){
	  var XHR_CHARGER_FICHIER = new XHRConnection();
 	/*}else {
    XHR_CHARGER_FICHIER.xhr_annule();
  }*/
  XHR_CHARGER_FICHIER.appendData("", "");
  XHR_CHARGER_FICHIER.overrideMimeType("text/plain");
//  XHR_CHARGER_FICHIER.setAsync(false);
  XHR_CHARGER_FICHIER.sendAndLoad(url, "POST",chargeFichier_rep);
}

function chargeFichier_rep(obj){
  if (document.getElementById(chargeFichier_zoneCible)){
    document.getElementById(chargeFichier_zoneCible).innerHTML=obj.responseText;
  }
  if (this.chargeFichier_fonction_retour!="")
    eval(this.chargeFichier_fonction_retour);
    

  document.body.style.cursor="auto";
  setTimeout("document.getElementById('div_loader').style.display='none';change_anim_souris('none');",1000);
}

function resize_masque(){
  var hauteur=0;
	if(document.all)
		{
		  hauteur = document.body.clientHeight;	
		}
	else
		{
	    hauteur = screen.height+window.pageYOffset;
		}
  
  document.getElementById('masque_IFRAME_ID').style.height=hauteur+"px";
  document.getElementById('masque_DIV_ID').style.height=hauteur+"px";
}
function afficher_masquer_masque(){
  resize_masque();
  var retour=afficher_masquer('masque_IFRAME_ID');
  afficher_masquer('masque_DIV_ID');
/*
  if (retour=="hidden")
    document.getElementById("html_ID").className="overflow_visible";
  else
    document.getElementById("html_ID").className="overflow_hidden";*/
    
}
function afficher_popup_attente(descriptif){
  var texte_affiche="";
  texte_affiche+="<div style='text-align:center;padding:20px'><img src='/images/ajax-loader2.gif'/><br/><br/><b>"+descriptif+"</b></div>";
  document.getElementById("popupID").innerHTML=texte_affiche;
  afficher_masquer('popupID');
  document.getElementById('popupID').style.top="140px";
  afficher_masquer_masque();
}
function masquer_popup(){
    try{
      document.getElementById('popupID').style.display='none';
      document.getElementById('masque_DIV_ID').style.display='none';
      document.getElementById('masque_IFRAME_ID').style.display='none';
    }catch(error){
    
    }
    try{
       Modalbox.hide();
    }catch(error){
    
    }
}
function afficher_masquer_popup(){
  afficher_masquer('popupID');
  if (document.getElementById('popupID').style.display!="none"){
      var position_verticale=position_ver_souris-document.getElementById('popupID').offsetHeight+30;
      if(position_verticale<200){
        position_verticale=200;
      }
      //position_verticale=position_ver_souris-document.getElementById('popupID').offsetHeight;
      document.getElementById('popupID').style.top=position_verticale+"px";
  }
  afficher_masquer_masque();
}

var timer_popup_aide_navigation;
function affiche_popup_aide_navigation(affiche){
    var anim=true;
    if (document.getElementById('popup_aide_navigationID')){
        
        if (affiche){
          document.getElementById('popup_aide_navigationID').style.display="block";
        }else {
          document.getElementById('popup_aide_navigationID').style.display="none";
          clearTimeout(timer_popup_aide_navigation);
        }
        if (document.getElementById('popup_aide_navigationID').style.display=="block"){
          var position_verticale=position_ver_souris-parseInt(document.getElementById('popup_aide_navigationID').offsetHeight)-20;
          if(position_verticale<160){
            position_verticale=160;
          }
          
          var zone_cible_y_mini=parseInt(document.getElementById('popup_aide_navigationID').style.top)-30;
          var zone_cible_y_maxi=parseInt(document.getElementById('popup_aide_navigationID').style.top)+parseInt(document.getElementById('popup_aide_navigationID').offsetHeight)+30;
    
          if (zone_cible_y_mini!="" && zone_cible_y_maxi!="" && position_ver_souris!=0){
            if (position_ver_souris>=zone_cible_y_mini && position_ver_souris<=zone_cible_y_maxi){
              //alert(position_ver_souris+">="+zone_cible_y_mini+" && "+position_ver_souris+"<="+zone_cible_y_maxi);
              anim=false;
            }
          }
          if (anim)
            document.getElementById('popup_aide_navigationID').style.top=position_verticale+"px";
          timer_popup_aide_navigation=setTimeout("affiche_popup_aide_navigation(true)",500);
        }

    }else {
      clearTimeout(timer_popup_aide_navigation);
    }
}

function affiche_menu_popup_aide_navigation(visible){
  if (document.getElementById('menu_popup_aide_navigationID')){
    alert ("ok");
    if (visible){ 
      //document.getElementById('menu_popup_aide_navigationID').style.display="block";
      document.getElementById('menu_popup_aide_navigationID').style.display="none";
    }else{
      document.getElementById('menu_popup_aide_navigationID').style.display="none";
    }
  }
}
function init_popup_aide_navigation(){
  if (document.getElementById('desc_popup_aide_navigID')){
    texte=document.getElementById('desc_popup_aide_navigID').value;
    if (texte==""){
        affiche_popup_aide_navigation(false);
    }else {
      if (document.getElementById('menu_popup_aide_navigationID')){
          document.getElementById('menu_popup_aide_navigationID').innerHTML=texte;
      }
    }
  }else {
    affiche_popup_aide_navigation(false);
  }
}
function initialise_chp(id){
  if (document.getElementById(id)){
    if (document.getElementById(id).getAttribute("init")==0){
      document.getElementById(id).value="";
      document.getElementById(id).setAttribute("init",1);
    }
  }
}
function afficher_masquer(id){
  if (!document.getElementById(id))
    return;

  if (document.getElementById(id).style.display=="none"){
    document.getElementById(id).style.display="block";
  }else {
    document.getElementById(id).style.display="none";
  }
  return document.getElementById(id).style.display;
}
function openWindow(theURL,winName,features) {
  w = window.open(theURL,winName,features);
}
function recup_session_id(){
  var PHPSESSID=""
  if (document.getElementById("PHPSESSID"))
    PHPSESSID=document.getElementById("PHPSESSID").value;
  return(PHPSESSID);
}
function isNotEmailAdress(valeur) {
	regExpEmailAdress = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/g;
	resultat = valeur.match(regExpEmailAdress);
	if (resultat != null && resultat.length == 1) {
		return false;
	} else {
		return true;
	}
}
function is_int(event){
	if(event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;
	if (event.which ==8 || event.which ==0){
	}else if(event.which < 48 || event.which > 57) return false;
}
function is_num_tel(event, pos){
	if (pos==0){
		if((event.keyCode !=43 && event.keyCode < 48) || event.keyCode > 57) 
			event.returnValue = false;
		else event.returnValue = true;
		if (event.which ==8 || event.which ==0){
		}else if((event.which !=43 && event.which < 48) || event.which > 57) {
				return false;
			}
		
	}else{
		return is_int (event);		
	}
}
function is_int_or_char(event){
	if((event.keyCode < 65 && event.keyCode > 57) || event.keyCode<48) event.returnValue = false;
	if (event.which ==8 || event.which ==0){
	}else if((event.which < 65 && event.which > 57) || event.which <48) return false;
}
function imprimer(){
  window.print();
}

function sortSelect(id){
  Liste= new Array();
  Obj= document.getElementById(id);
  
  for(i=0;i<Obj.options.length;i++){
    Liste[i]=new Array();
    Liste[i][0]=Obj.options[i].text;
    Liste[i][1]=Obj.options[i].value;
    Liste[i][3]=Obj.options[i].selected;
  }
  Liste=Liste.sort()
   
  for(i=0;i<Obj.options.length;i++){
    Obj.options[i].text=Liste[i][0];
    Obj.options[i].value=Liste[i][1];
    Obj.options[i].selected=Liste[i][3];
  }
}


//*******************************************
//            FONCTION TRIM ET DERIVE
//*******************************************
  
var regExpBeginning = /^\s+/;  
var regExpEnd       = /\s+$/;

 // Supprime les espaces inutiles en début et fin de la chaîne passée en paramètre.
//********************************************************************************
function trim(aString) {
     return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

 // Supprime les espaces inutiles en début de la chaîne passée en paramètre.
//********************************************************************************
function ltrim(aString) {
     return aString.replace(regExpBeginning, "");
}

 // Supprime les espaces inutiles en fin de la chaîne passée en paramètre.
//********************************************************************************
function rtrim(aString) {
     return aString.replace(regExpEnd, ""); 
} 
