
function getObj(name){
	
	if (document.getElementById){
		return document.getElementById(name);
	}
	else if (document.all){
		return document.all[name];
	}
	else if (document.layers){
		return document.layers[name];
	}
	else return false;
}

function getObjName(name){
	
	if (document.getElementsByName){
		return document.getElementsByName(name)[0];
	}
	else if (document.all){
		return document.all[name];
	}
	else if (document.layers){
		return document.layers[name];
	}
	else return false;
}

function date_sans_annee(s){
	// Utilisée dans la liste des actus sur Espinf 4/02/2009
 return(s.substr(0,s.lastIndexOf("/")));
}

function maj_categorie(site){

	var selection=element_selectionne_option(getObj("categorie"))

	
	var destinataire=getObj("destinataire_"+selection).value
	var nb_destinataires=getObj("nb_destinataires").value
	getObjName("destinataire").value=destinataire
	
	getObj("trace_destinataire").innerHTML=destinataire
	getObj("formulaire_contact").style.display=(destinataire==""?"none":"block")
	
	// alert(destinataire+" "+selection)
	
	for(var i=0;i<nb_destinataires;i++){
		
		getObj("precisions_contact_"+(i+1)).style.display=(selection==i+1?"block":"none")
		
	}
}

function element_selectionne_value(l){
	if(typeof(l)=="undefined"){
		var s=-1
	}
	else{
		if(l.options.length==0){
			var s=-1
		}
		else{
			var s=(l.selectedIndex==-1?-1:l.selectedIndex)
		}
	}
	return(s)
}

 function element_selectionne_libelle(l){
	if(typeof(l)=="undefined"){
		var s=""
	}
	else{
		if(l.options.length==0){
			var s=""
		}
		else{
			var s=(l.selectedIndex==-1?l.options[0].text:l.options[l.selectedIndex].value)
		}
	}
return(s)
}

function element_selectionne_option(l){
	if(typeof(l)=="undefined"){
		var s=""
	}
	else{
		if(l.options.length==0){
			var s=""
		}
		else{
			var s=(l.selectedIndex==-1?"":l.options[l.selectedIndex].value)
		}
	}
	return(s)
}

function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }
		 
function ComparerDates(LeParam1,LeParam2){

// Compare 2 dates au format jj/mm/aaaa
// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2

var LeParam1 = DateAnglaise(LeParam1,"/");// Ne pas oublier d'utiliser cette fonction
// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript

var LeParam2 = DateAnglaise(LeParam2,"/");
LeParam1 = Date.parse(LeParam1);
LeParam2 = Date.parse(LeParam2);

if (LeParam1 == LeParam2) { 
return 0;
}

if (LeParam1 > LeParam2){
return 1;
}else{
return 2;
}
}


// Renvoye une date en format anglais avec le séparateur choisi "02/03/1981" -> "1981-3-2"
// Le premier paramètre est la date a convertir, le second est le caractère de séparation choisi
function DateAnglaise(LeParam1,LeParam2){

LaDate = new Array(3);
LaDate = DecomposeDate(LeParam1);

LeRetour = LaDate[2]+LeParam2+LaDate[1]+LeParam2+LaDate[0];
return LeRetour;
}

function DecomposeDate(LeParam1){ 

// Sépare les jours, les mois et les années dans une date de type "22/05/1981"
// Renvoye le tout dans un tableau de taille 3

LeRetour = new Array(3);
LeJour="";
LeMois="";
LeAnnee="";

// Extraction du jour
i=0;
while((LeParam1.charAt(i)!="/")&&(i<10)){
LeJour+=LeParam1.charAt(i);
i++;
}
if(LeJour.charAt(0)=="0"){
LeJour=LeJour.charAt(1);
}
LeParam1=LeParam1.substring(i+1,LeParam1.length);

// Extraction du mois
i=0;
while((LeParam1.charAt(i)!="/")&&(i<10)){
LeMois+=LeParam1.charAt(i);
i++;
}
if(LeMois.charAt(0)=="0"){
LeMois=LeMois.charAt(1);
}
LeParam1=LeParam1.substring(i+1,LeParam1.length);


// Extraction de l'année
LeAnnee=LeParam1;
LeRetour[0]=LeJour;
LeRetour[1]=LeMois;
LeRetour[2]=LeAnnee;
return LeRetour;
}


