// JavaScript Document
function screenCenterDiv(maDiv){
	//On rcupre la taille la div
	var divWidth;
	var divHeight;

	//divWidth=document.getElementById(maDiv).offsetWidth;
	//divHeight=document.getElementById(maDiv).offsetHeight;
	divWidth=$('#'+maDiv).width();
	divHeight=$('#'+maDiv).height()+20;//hack pour les images sur certaines popups... c'est pas joli joli !!

	//On positionne la div au centre
	$('#'+ maDiv).css('left','50%');
	$('#'+ maDiv).css('top','50%');
	$('#'+maDiv).css('marginLeft' , '-'+divWidth/2+'px');
	$('#'+maDiv).css('marginTop' ,'-'+divHeight/2+'px');	
}
//POSITIONNEMENT DU FOOTER
<!--
function setFooterBottom(headerDiv,contentDiv,footerDiv) {
    if (document.getElementById) {
		var windowHeight=$(window).height();
        if (windowHeight>0) {
			var tetiereDivHeight = isNaN($('#'+headerDiv).height())?0:$('#'+headerDiv).height();
				var tetiereMarginTop=isNaN(parseInt($('#'+headerDiv).css('margin-top')))?0:parseInt($('#'+headerDiv).css('margin-top'));
				var tetiereMarginBottom=isNaN(parseInt($('#'+headerDiv).css('margin-bottom')))?0:parseInt($('#'+headerDiv).css('margin-bottom'));
				var tetierePaddingTop=isNaN(parseInt($('#'+headerDiv).css('padding-top')))?0:parseInt($('#'+headerDiv).css('padding-top'));
				var tetierePaddingBottom=isNaN(parseInt($('#'+headerDiv).css('padding-bottom')))?0:parseInt($('#'+headerDiv).css('padding-bottom'));
			var tetiereHeight=tetiereDivHeight+tetiereMarginTop+tetiereMarginBottom+tetierePaddingTop+tetierePaddingBottom;
			var contentDivHeight = isNaN($('#'+contentDiv).height())?0:$('#'+contentDiv).height();
				var contentMarginTop=isNaN(parseInt($('#'+contentDiv).css('margin-top')))?0:parseInt($('#'+contentDiv).css('margin-top'));
				var contentMarginBottom=isNaN(parseInt($('#'+contentDiv).css('margin-bottom')))?0:parseInt($('#'+contentDiv).css('margin-bottom'));
				var contentPaddingTop=isNaN(parseInt($('#'+contentDiv).css('padding-top')))?0:parseInt($('#'+contentDiv).css('padding-top'));
				var contentPaddingBottom=isNaN(parseInt($('#'+contentDiv).css('padding-bottom')))?0:parseInt($('#'+contentDiv).css('padding-bottom'));	
			var contentHeight=contentDivHeight+contentMarginTop+contentMarginBottom+contentPaddingTop+contentPaddingBottom;
			var footerDivHeight = isNaN($('#'+footerDiv).height())?0:$('#'+footerDiv).height();
				var footerMarginTop=isNaN(parseInt($('#'+footerDiv).css('margin-top')))?0:parseInt($('#'+footerDiv).css('margin-top'));
				var footerMarginBottom=isNaN(parseInt($('#'+footerDiv).css('margin-bottom')))?0:parseInt($('#'+footerDiv).css('margin-bottom'));
				var footerPaddingTop=isNaN(parseInt($('#'+footerDiv).css('padding-top')))?0:parseInt($('#'+footerDiv).css('padding-top'));
				var footerPaddingBottom=isNaN(parseInt($('#'+footerDiv).css('padding-bottom')))?0:parseInt($('#'+footerDiv).css('padding-bottom'));
			var footerHeight=footerDivHeight+footerMarginTop+footerMarginBottom+footerPaddingTop+footerPaddingBottom;
			//alert(tetiereHeight+" "+contentHeight+" "+footerHeight);
        if (windowHeight-(tetiereHeight + contentHeight+footerHeight)>=0) {
			$('#'+footerDiv).css('position','relative').css('top',windowHeight-(tetiereHeight + contentHeight + footerHeight));
        }
        else {
			$('#'+footerDiv).css('position','static')
        }
       }
      }
}
//-->

//GENERIC FUNCTIONS
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setAlpha(elementId,alpha)
{
    document.getElementById(elementId).style.opacity = alpha / 100;
    /** Test pour notre cher IE */
    if (document.body.filters != undefined)
    {
        document.getElementById(elementId).style.filter = 'alpha(opacity:' + alpha + ')';
    }
}
function isEmail(email) {
  var proto  = "(mailto:)?";
  var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
  var regex  = "^" + proto + "?" + usr + "\@" + domain + "$";

  var rgx    = new RegExp(regex);
  return rgx.exec(email) ? true : false;
}
function getRadioValue(myForm, objRadio){
	oRadio=document[myForm][objRadio];
	var returnValue='';
	for (i = 0; i < oRadio.length; i++) {
		if (oRadio[i].checked) {
			returnValue=oRadio[i].value;
			break;
		}
	}
	return returnValue;
}
function getRadioCount(myForm, objRadio){
	oRadio=document[myForm][objRadio];
	var returnValue=0;
	for (i = 0; i < oRadio.length; i++) {
		returnValue=returnValue+1;
	}
	return returnValue;
}

function getInputMultiValueList(objInput, separator){
	oMulti=document.getElementById(objInput);
	var returnValue='';
	var firstSelect=true;
	
	for (i = 0; i < oMulti.length; i++) {
		if(oMulti[i].selected){
			if(firstSelect==true){eltSeparator='';firstSelect=false}else{eltSeparator=separator;}
			returnValue=returnValue+separator+oMulti[i].value;
		}
	}
	return returnValue;
}
function getValuesOfSelectedInput(monEltId, separator) {
	var returnValue='';
	var firstSelect=true;
	var fields = $("#"+monEltId+" :input").serializeArray();
		jQuery.each(fields, function(i, field){
			if(firstSelect==true){firstEltSeparator=separator;firstSelect=false}else{firstEltSeparator='';}
				returnValue=returnValue+firstEltSeparator+field.value+separator;
		});
	return returnValue;
}
function putValuesOfSelectedCheckbox(monEltId, valueIn, separator) {
	var firstSelect=true;
	valueIn=valueIn.split(separator);
	var fields = $("#"+monEltId+" :checkbox");
	for(i=0;i<fields.length;i++){
		if(jQuery.inArray(fields[i].value, valueIn)>0){
			$('#'+fields[i].id).attr('checked', 'checked');  
		}
	}
}
function testFieldInput(objId){
	var obj=document.getElementById(objId);
	var objectType=obj.type;
	//alert(objectType);
	if(obj.value.trim()==''){
		obj.className='errorObj';
		return false;	
	} else {
		obj.className='';
		return true;
	}	
}
function getNextHighestZindex(obj){
   var highestIndex = 0;
   var currentIndex = 0;
   var elArray = Array();
   if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }
   for(var i=0; i < elArray.length; i++){
      if (elArray[i].currentStyle){
         currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
      }else if(window.getComputedStyle){
         currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
      }
      if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
   }
   return(highestIndex+1);
}
function chaineAleatoire(nbcar)
{
	var ListeCar = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J");
	var Chaine ='';
	for(i = 0; i < nbcar; i++)
	{
		Chaine = Chaine + ListeCar[Math.floor(Math.random()*ListeCar.length)];
	}
	return Chaine;
}
function addEltInJsArray(strElt, myArray, newIdx){
	 //alert("In "+newIdx);
 if(!newIdx){
 	var newIdx=myArray.length;
 }
 //alert("In array JS "+newIdx);
 myArray[newIdx]=strElt;
 return newIdx;
}

//Extension de classe string avec TRIM
String.prototype.trim = function(){return this.replace(/(?:^\s+|\s+$)/g, "");};
//Ajout de classe text br2nl
String.prototype.br2nl= String.prototype.br2nl =function() {return this.replace(/<br\s*\/?>/mg,"\n");};
String.prototype.nl2br= function(){return this.replace(/\n/g, "<br />");};