
		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
		}

	  
	  function getSofiproXhr(){
	 
               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
	}

	function updateSofiproContainer(path, actiontodo, dest_container){
		var xhr = getSofiproXhr(); 

		// 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 checkAll(flag, thisform)
{
   if ( thisform.deleteById.length )
   {
      for (var x = 0; x < thisform.deleteById.length; x++)
      {
         if (flag == 1)
         {
            thisform.deleteById[x].checked = true;   
         }
         else 
         {
            thisform.deleteById[x].checked = false;
         }
         
      }
   }
   else
   {
      if (flag == 1)
      {
         thisform.deleteById.checked = true;            
      }
      else 
      {
         thisform.deleteById.checked = false;
      }
   }
}   
	  
function checkAllValues(flag, thisform)
{
	   if ( thisform.checkById.length )
	   {
	      for (var x = 0; x < thisform.checkById.length; x++)
	      {
	         if (flag == 1)
	         {
	            thisform.checkById[x].checked = true;   
	         }
	         else 
	         {
	            thisform.checkById[x].checked = false;
	         }
	         
	      }
	   }
	   else
	   {
	      if (flag == 1)
	      {
	         thisform.checkById.checked = true;            
	      }
	      else 
	      {
	         thisform.checkById.checked = false;
	      }
	   }
}   

function getSelectedRadioValue(radioBtn) {  
  for (i=0;i<radioBtn.length;i++) { 
    if (radioBtn[i].checked==true) {  
      return radioBtn[i].value;  
    } 
  } 
}	

    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, separator){
   var sSeparator = separator;
   if(!sDate.match("^[0-9]{2}"+sSeparator+"[0-9]{2}"+sSeparator+"[0-9]{4}$"))
   {
     return false;
   }

   var iDay   = sDate.substring(0,2); 
   var iMonth  = sDate.substring(3,5);
   var iYear   = sDate.substring(6,10); 

   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;
		}
	}
}

function hidediv(divid) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
	document.getElementById(divid).style.visibility = 'hidden'; 
	document.getElementById(divid).style.height = '0px'; 
	} 
	else { 
		if (document.layers) { // Netscape 4 
		document.divid.visibility = 'hidden'; 
		document.divid.height = '0px'; 
		} 
		else { // IE 4 
		document.all.divid.style.visibility = 'hidden';
		document.all.divid.style.height = '0px';
		} 
	} 
} 

function showdiv(divid) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
	document.getElementById(divid).style.visibility = 'visible'; 
	document.getElementById(divid).style.height = '100%'; 
	} 
	else { 
		if (document.layers) { // Netscape 4 
		document.divid.visibility = 'visible'; 
		document.divid.height = '100%'; 
		} 
		else { // IE 4 
		document.all.divid.style.visibility = 'visible'; 
		document.all.divid.style.height = '100%';
		} 
	} 
} 

function loadContent(sessionControl, path, dest_container){
	var xhr = getSofiproXhr()
	// 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
   			if(resulthtml.replace(/^\s+/g,'').replace(/\s+$/g,'') == 'TimeOut')
			{
				$("#dialog-login-form").dialog("open");
			}
   			else
   			{	
   			   $(dest_container).html('<center><img style=\"margin: 30px\" src=\"../commons/images/loading.gif\" border=\"0\"></center>');
    		   $(dest_container).load(path);
   			}
		}
	}

	// Ici on va voir comment faire du post
	xhr.open("GET",sessionControl,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();
   	}


function removeTmceInstace(){
          try
	      {
	      tinyMCE.execCommand( 'mceRemoveControl', true, "description");    
	      }
	      catch(err)
	      {}
    }

function tmceTiggerSave(){
		 try
	     {
	  	    tinyMCE.triggerSave(true, true);
	     }
	     catch(err)
	     { }
    }
 
function validateTrimUi(myString)
{
	if((myString.replace(/^\s+/g,'').replace(/\s+$/g,'') == '') || (myString == null))
	{
		return false;
	}
	else
	{
		return true;
	}	
}

function uncheckAll(field)
{
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function doResize(){
    var h = $(window).height() - ($('#headerInfo').height()) - ($('#footerInfo').height());
   
	if( (h > ($('#pageContent').height() - 10)) && ($('#mainContent').height() >= ($('#mainTableContent').height() )) )
	{
		$('#pageContent') .css({'height': (($(window).height())-10)+'px'});
	    
	    $(window).bind('resize', function(){
	        $('#pageContent') .css({'height': (($(window).height()) -10)+'px'});
	    });
	
	    $('#bodyContent') .css({'height': (($('#pageContent').height()) - ($('#headerInfo').height()) - ($('#footerInfo').height()))+'px'});
	    
	    $(window).bind('resize', function(){
	        $('#bodyContent') .css({'height': (($('#pageContent').height()) - ($('#headerInfo').height()) - ($('#footerInfo').height()))+'px'});
	    });
	    
	    $('#mainContent') .css({'height': (($('#bodyContent').height()) - ($('#headContent').height()) - 20 )+'px'});
	    
	    $(window).bind('resize', function(){
	        $('#mainContent') .css({'height': (($('#bodyContent').height()) - ($('#headContent').height()) - 20 )+'px'});
	    });

	    $('#mainTableContent') .css({'height': ($('#mainContent').height())+'px'});
	    
	    $(window).bind('resize', function(){
	        $('#mainTableContent') .css({'height': ($('#mainContent').height())+'px'});
	    });
	    
	}
}
