
	 		function getXhr(){
	 
               var xhr = null; 
				if(window.XMLHttpRequest) // Firefox et autres
				   xhr = new XMLHttpRequest(); 
				else if(window.ActiveXObject){ // Internet Explorer 
				   try {
			                xhr = new ActiveXObject("Msxml2.XMLHTTP");
			            } catch (e) {
			                xhr = new ActiveXObject("Microsoft.XMLHTTP");
			            }
				}
				else { // XMLHttpRequest non supporté par le navigateur 
				   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhr = false; 
				} 
               return xhr
			}
			

			/**
			* Méthode qui sera appelée sur le click du bouton
			*/
			function updateContainer(path, actiontodo, dest_container){
				var xhr = getXhr()
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function(){
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200){
						resulthtml = xhr.responseText;
						// On se sert de innerHTML pour rajouter les options a la liste
						document.getElementById(dest_container).innerHTML = resulthtml;
						
					}
				}

				// Ici on va voir comment faire du post
				xhr.open("POST",path,true);
				// ne pas oublier ça pour le post
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				// ne pas oublier de poster les arguments
				// ici, l'id de l'auteur
				xhr.send("actionToDo="+actiontodo);
			}

			function updateImgContainer(path, imgId, dest_container, categoryId, viewFrom){
			    document.getElementById(dest_container).innerHTML = '<img src="./images/loading.gif" border="0">';
			    
				var xhr = getXhr()
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function(){
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200){
						resulthtml = xhr.responseText;
						// On se sert de innerHTML pour rajouter les options a la liste
						
						document.getElementById(dest_container).innerHTML = resulthtml;
						
					}
				}

				// Ici on va voir comment faire du post
				xhr.open("POST",path,true);
				// ne pas oublier ça pour le post
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				// ne pas oublier de poster les arguments
				// ici, l'id de l'auteur
				xhr.send("documentId="+imgId+"&categoryId="+categoryId+"&viewFrom="+viewFrom);
			}
 
    function Remplace(expr,a,b) {
    // chercher tout les occurence a dans expr et remplacer par b
	   var i=0
	   while (i!=-1) {
	   i=expr.indexOf(a,i);
	   if (i>=0) {
	     expr=expr.substring(0,i)+b+expr.substring(i+a.length);
	     i+=b.length;
	    }
	    }
	   return expr
	  }

		function isDate(sDate){
			  
			   var sSeparator = '-';
			   if(!sDate.match("^[0-9]{2}-[0-9]{2}-[0-9]{4}$"))
			   {
			     return false;
			   }

		    var arDate = sDate.split(sSeparator);
			var iDay = parseInt(arDate[0]);
			var iMonth = parseInt(arDate[1]);
			var iYear = parseInt(arDate[2]);
			var arDayPerMonth = [31,(isLeapYear(iYear))?29:28,31,30,31,30,31,31,30,31,30,31];
			if(!arDayPerMonth[iMonth-1]) return false;
			return (iDay <= arDayPerMonth[iMonth-1] && iDay > 0);
		}
		
		function isHour(sHour){
			var sSeparator = ':';
			var withSeconds = false;
			if(sHour.match("^[0-9]{2}:[0-9]{2}:[0-9]{2}$")) var withSeconds = true;
			else if(!sHour.match("^[0-9]{2}:[0-9]{2}$")) return false;
			var arHour = sHour.split(sSeparator);
			var iHour = parseInt(arHour[0]);
			var iMinute = parseInt(arHour[1]);
			if(withSeconds)	var iSecs = parseInt(arHour[2]);
			else 						var iSecs = 0;
			return 	(iHour >= 0 && iHour < 24) && (iMinute >= 0 && iMinute < 60) && (iSecs >= 0 && iSecs < 60);
		}
		
		function isLeapYear(iYear){
			return ((iYear%4==0 && iYear%100!=0) || iYear%400==0);
		}
		
		function isDateHour(sDateHour){
			var sSeparator = ' ';
			var arDateHour = sDateHour.split(sSeparator);
			return (arDateHour[0] && arDateHour[1] && isDate(arDateHour[0]) && isHour(arDateHour[1]));
		}

function CompareDates(datefrom, dateto) 
{
   if(datefrom == 'today')
   {
      Today = new Date;
      Jour = Today.getDate();
      Mois = (Today.getMonth())+1;
      Annee = Today.getFullYear(); 

      if(Jour < 10)
      {
        Jour = "0".concat(Jour);
      } 
      
      if(Mois < 10)
      {
        Mois = "0".concat(Mois);
      } 
      
      var str1  = Jour+"-"+Mois+"-"+Annee;
      var str2  = dateto;
    }
   else
   {
     var str1  = datefrom;
     var str2  = dateto;
   }

   var dt1   = str1.substring(0,2); 
   var mon1  = str1.substring(3,5);
   var yr1   = str1.substring(6,10); 
   
   var dt2   = str2.substring(0,2); 
   var mon2  = str2.substring(3,5); 
   var yr2   = str2.substring(6,10); 
   
   var date1 = yr1.concat(mon1.concat(dt1)); 
   var date2 = yr2.concat(mon2.concat(dt2)); 
   
   if(date2 < date1)
   {   
      return 1; 
   } 
   else 
   { 
      if(date2 > date1)
      {
         return 2;
      }
      else
      {
      return 0;
      }
   } 
} 


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


		