
function displayPageInIt(url,id){
 var xhr_object = null;
 var position = id;
	if(window.XMLHttpRequest){
		xhr_object = new XMLHttpRequest();
	}
	else {
		if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
 // On ouvre la requete vers la page désirée
 xhr_object.open("GET", url, true);
 
 xhr_object.onreadystatechange = function(){
	if ( xhr_object.readyState == 4 ){
		// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
		document.getElementById(position).innerHTML = xhr_object.responseText;
	}
}
// dans le cas du get
xhr_object.send(null);
}


/**
Test if 2 values are same. It's possible to not pay attention to the case sensitive setting the third parameter to false
*/
function areSame(string1, string2, sensitive){
		if (string1!=null && string2!=null){
			if (sensitive){
				if (string1!=string2) return false;
			}
			else {
				str1 = string1.toLowerCase();
				str2 = string2.toLowerCase();
				if (str1 != str2) return false;
			}
			return true;
		}
		return false;
}

var regExpBeginning = /^\s+/;
var regExpEnd       = /\s+$/;
var regEmail		= 
// Supprime les espaces en début et fin de chaine
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, "");
} 

function checkEmailFormat(email) { // vérif validité email par REGEXP
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
   return (reg.exec(email)!=null)
}

function hideShowMe(id){
	if (document.getElementById(id)!=null){
		if (document.getElementById(id).style.display=="hidden") document.getElementById(id).style.display="block";
		else document.getElementById(id).style.display="hidden";
	}
}

function checkSelected(idCheck){
	var list = document.getElementsByTagName("input");
	var counterSelected=0;
		for (k=0;k<list.length;k++){
			if (list[k].type=='checkbox') {
				idChecking=""+list[k].id;
				var resultat = idChecking.indexOf(idCheck);
				if (resultat>-1){
					if (list[k].checked) {
						counterSelected=counterSelected+1;
					}
				}
			}
		}	
	return counterSelected;
}
function goto_confirm(msg, formulaire,url,elementToCheck){
   if(confirm(msg)) {
	if (formulaire!=null){
		document.forms[formulaire].action=url;
		document.forms[formulaire].submit();
	}
	else document.location.href = url;
   }
   if (elementToCheck!=null){
   if (""+elementToCheck.length>0) {
		document.getElementById(elementToCheck).checked=false;
	}
	}
   return false; //pour ne pas revenir au début de la page
}

/**
* idCheck :String  check id name beginning
* alone : boolean if false, check if the function check if there is at least 1 element, if true 1 only
* url string url to call if check of checbox is true
*/
function callFunction(msg,idCheck,alone,formulaire,url,alert1,alert2,elementToCheck){
	nbElementSelected = checkSelected(idCheck);
	err = -1;
	if (nbElementSelected==0) {
		err=1;
	}
	if (alone){
		if (nbElementSelected>1) {
			err=2;
		}
	}
	
	if (err==1) {
		alert(alert1);
		return false;
	}
	if (err==2) {
		alert(alert2);
		return false;
	}
	if (err==-1){
		return goto_confirm(msg,formulaire,url,elementToCheck);
	}	
}

function callBeforeFunction(msg,elementToCheck,idCheck,alone,formulaire,url){
	// invalid other selection
	var list = document.getElementsByTagName("input");
	var counterSelected=0;
	for (k=0;k<list.length;k++){
		if (list[k].type=='checkbox') {
			idChecking=""+list[k].id;
			var resultat = idChecking.indexOf(idCheck);
			if (resultat>-1){
				if (idChecking==elementToCheck){
					list[k].checked=true
				}
				else list[k].checked=false;
			}
		}
	}
	
	// call the real service
	callFunction(msg,idCheck,alone,formulaire,url,null,null,elementToCheck);
	
}
function insertImageInDiv(div,src){
	
  if (document.getElementById){
    if (src!=null){
		document.getElementById(div).innerHTML = "<img src='" + src + "'/>";
	}
	else document.getElementById(div).innerHTML = "";
   }
	else if (document.all){
		if (src!=null){
			document.all[div].innerHTML = "<img src='" + src + "'/>";
		}
		else document.all[div].innerHTML = "";
    }
  } 

function showOrHide(divId){
	theObject = document.getElementById(divId)
	if (theObject!=null){
		if (theObject.style.display=='none'){
			theObject.style.display='block';
			theObject.style.visibility='visible';
			
		}
		else {
			theObject.style.display='none';
			theObject.style.visibility='hidden';
		}
	}
}

function checkAllElement(id){
	var list = document.getElementsByTagName("input");
	var counterSelected=0;
	for (k=0;k<list.length;k++){
		if (list[k].type=='checkbox') {
			idChecking=""+list[k].id;
			var resultat = idChecking.indexOf(id);
			if (resultat>-1){
				if (list[k].checked) {
					list[k].checked=false;
				}
				else list[k].checked=true;
			}
		}
	}
	
}
