function getHTTPObject() {
	var xmlhttp;
	if (navigator.appName=="Microsoft Internet Explorer")
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		//il faut remplacer "Microsoft.XMLHTTP" par "Msxml2.XMLHTTP.5.0" pour eviter l'erreur system : 1072896748 
		//pour les actentuées : test réussi est validé		
	else 	
		var xmlhttp = new XMLHttpRequest();  

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      	xmlhttp = false;
      }
    }
  return xmlhttp;
}

var http = getHTTPObject();


function new_xhr(){
	var xhr_object = null;
	if(window.XMLHttpRequest)
	   xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject){
	   try {
                xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else {
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr_object = false;
	}
	return xhr_object;
}

function load_page(select,container) {
	var xhr2 = new_xhr();
	xhr2.onreadystatechange = function(){
		if ( xhr2.readyState == 4 ){
			if(xhr2.status  != 200){
				document.getElementById(container).innerHTML ="Error code " + xhr2.status;
			} else {
				document.getElementById(container).innerHTML = xhr2.responseText;
			}
		} else {
			document.getElementById(container).innerHTML = "Chargement en cours ...<br /><img src='loading.gif' alt=''/>";
		}
	}
	xhr2.open("POST", select, true);
	xhr2.send(null);
}



function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	if (theAction=='over'){
		if (document.getElementById(theRow).className!=theMarkColor)
			document.getElementById(theRow).className=thePointerColor
	}
	if (theAction=='out'){
		if (document.getElementById(theRow).className!=theMarkColor)
			document.getElementById(theRow).className=theDefaultColor
	}
	if (theAction=='click'){
		if (document.getElementById(theRow).className!=theMarkColor){
			document.getElementById(theRow).className=theMarkColor
		}else{
			document.getElementById(theRow).className=thePointerColor			
		}
			
	}
	
	return true
} // end of the 'setPointer()' function

function combo_text(champs){
	return document.getElementById(champs).options[document.getElementById(champs).selectedIndex].text	
}

function combo_remove(champs){
    var x=document.getElementById(champs)
    x.remove(x.selectedIndex)	
}

function chawaib(chaine){
	var chawa=new RegExp("'", "g");
	return chaine.replace(chawa,"\'")
}

function obj(objet){
	return document.getElementById(objet)
}

function cacher(objet){
	document.getElementById(objet).style.visibility='hidden';	
	document.getElementById(objet).style.display='none';
}

function char_to_char(char1,char2,chaine){
	var reg=new RegExp(char1, "g");
	return chaine.replace(reg,char2)
}

function cible(page){
	document.location=page
}

function changeImages(name,image) {
	document.images[name].src=image
}
function afficher_message(message,container,etat){
	obj(container).innerHTML=message
	if (etat==1) {
		obj(container).style.visibility='visible'
		return false
	}else{
		obj(container).style.visibility='hidden'
		return true
	}
}

function verifier_champ_vide(champs,libelle,container){
	if (obj(champs).value==""){
		obj(container).style.visibility='visible'
		obj(container).innerHTML="<b>"+libelle+" :</b> ne doit pas être une chaine vide"
		obj(champs).focus()
		return false
	}else{		
		obj(container).style.visibility='hidden'
		return true
	}
}

function verifier_champ_numerique(champs,libelle,container){
	obj(champs).value=remplacer(',','.',champs)
	if (isNaN(obj(champs).value)){
		obj(container).style.visibility='visible'
		obj(container).innerHTML="<b>"+libelle+" :</b> n'est pas une valuer numérique"
		obj(champs).focus()
		return false
	}else{
		obj(container).style.visibility='hidden'
		return true
	}
}

var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
function verifier_champ_email(champs,libelle,container){
	if ( !filter.test(document.getElementById(champs).value) ){
		document.getElementById(container).style.visibility='visible'
		document.getElementById(container).innerHTML="L'email "+libelle+" n'est pas valide "
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById(container).style.visibility='hidden'
		return true
	}
}
function radioCliked(form,champ) { 
var r = false; 
var d = document.getElementById(form); 

for(var i=0; i<d.length; i++) { 

   for(var k=0; k<d.length; k++) { 
     if(d[k].type=='radio' && d[k].name==champ) { 
       for(var j=0; j<d[champ].length; j++) 
       if(d[champ][j].checked) 
          r = d[champ][j].value; 
       } 
     } 


} 
	return r?r:0; 
} 



function mailtooo(email,titre){
	chaine_mail = "mailto:"+email+"?subject=" + titre;      
	chaine_mail += "&body="; 
	chaine_mail += ""; location.href = chaine_mail;     
}


//FONCTION QUI PERMET DE TELECHARGER UN FICHIER
function download(form,page,chemin,fichier,filename){
	alert(1)
	obj('txtchemin').value=chemin
	obj('txtfichier').value=fichier
	alert(2)
	obj('txtfilename').value=filename	
	alert(3)
	obj('txtdownload').value="download"
	alert(3)
	obj(form).method="post"
	alert(4)
	obj(form).action=page
	obj(form).submit()
}
