/* NOVACTVE */
function getLeft(l, id)
{
	if (l.offsetParent) {
		if (id && l.id && l.id == id) return (0);
		return (l.offsetLeft + getLeft(l.offsetParent, id));
	}
	else return (l.offsetLeft);
}

function getTop(l, id)
{
	if (l.offsetParent) {
		if (id && l.id && l.id == id) return (0);
		return (l.offsetTop + getTop(l.offsetParent, id));
	}
	else return (l.offsetTop);
}

function $()
{
	  var elements = new Array();
	  for (var i = 0; i < arguments.length; i++) 
	  {
	    var element = arguments[i];
	    if (typeof element == 'string')
	    	element = document.getElementById(element);
	
	    if (arguments.length == 1) return element;
	    elements.push(element);
	  }
  return elements;
}

/* alias pour la fonction getElementsByTagName */
function $$TN(tag, id) {
	if (id) return $(id).getElementsByTagName(tag);
	else return document.getElementsByTagName(tag);
}

function getElementsByClassName(needle, tag, idlimit)
{
	if (!tag || !document.getElementsByTagName(tag))
	tag = '*';
	if (!idlimit || !document.getElementById(idlimit))
		var my_array = document.getElementsByTagName(tag);
	else
		var my_array = document.getElementById(idlimit).getElementsByTagName(tag);
	var retvalue = new Array();
	var ii, jj;
	for (ii = 0, jj = 0; ii < my_array.length; ii++)
	{
		var c = " " + my_array[ii].className + " ";
		if (c.indexOf(" " + needle + " ") != -1)
			retvalue[jj++] = my_array[ii];
	}
	return retvalue;
}
/* alias pour la fonction getElementsByClassName */
function $$CN(needle, tag, idlimit) {
	return getElementsByClassName(needle, tag, idlimit);
}

function getAncestorByTagName(obj,tag,depth)
{
	if (!depth||depth<1) depth=1;
	obj=obj.parentNode;
	if ((obj.tagName!=tag)&&(obj.tagName!="BODY") )
		return getAncestorByTagName(obj,tag,depth);
	else
	{
		if ((obj.tagName==tag)&&(depth!=1))
			return getAncestorByTagName(obj,tag,(depth-1));
	  else if ((obj.tagName==tag)&&(depth==1))
			return obj;
		else
			return false;
	}
}
/* alias pour la fonction getAncestorByTagName */
function $$A(obj,tag,depth) {
	return getAncestorByTagName(obj,tag,depth);
}

/** 
	Verifie si un des radio button correspondant a l'objet est bien checked
*/
function isRadioChecked(radioObj) 
{
	for (var i = 0; i < radioObj.length; i++)
		if (radioObj[i].checked) return true ;
	return false ;
}

/** 
	Verifie si la checkbox est checked
*/
function isCheckBoxChecked(cBoxObj) {
	return cBoxObj.checked;
}

/** 
	Verifie la validite syntaxique d'un mail (c'est l'objet qu'il faut envoyer)
*/
function isEmail(eml)
{
	a = eml.search(/^[-a-z0-9_]+([-._]+[-a-z0-9_]+)*@[a-z0-9]([.-]?[a-z0-9])*\.[a-z]{2,4}$/i);
	if(a!=-1)
		return true
	else
		return false
}

/** 
	Verifie qu'un integer est bien interger
*/
function isInteger(inputObj)
{
	var exp = new RegExp("^[0-9]*$");
	 
	if(exp.test(inputObj.value))
		return true
	else
		return false
}


/** 
	Verifie qu'un input n'est pas vide
*/
function isInputEmpty(inputObj) 
{
	return (inputObj.value.length == 0) ;
}

/** 
	Verifie la date au format jj-mm-aaa
*/
function isDateValid(dateObj) 
{
	str = dateObj.value ;
	format = "jj-mm-aaaa" ;
	posj=format.search(/jj/i)
	posm=format.search(/mm/i)
	posa=format.search(/aaaa/i)
	poss=format.search(/\W/)
	poss2=format.substring(poss+1, format.length).search(/\W/)+poss+1
	s1=format.substring(poss, poss+1)
	s2=format.substring(poss2, poss2+1)

	s_jj=str.substring(posj, posj+2)
	s_mm=str.substring(posm, posm+2)
	s_aaaa=str.substring(posa, posa+4)
	jj=parseInt(s_jj*1)
	mm=parseInt(s_mm*1)
	aaaa=parseInt(s_aaaa*1)
	sep1=str.substring(poss, poss+1)
	sep2=str.substring(poss2, poss2+1)

	if(
		(
			isNaN(jj) || isNaN(mm) || isNaN(aaaa)
			|| jj<1 || jj>31 || mm<1 || mm>12 || aaaa<1900 || aaaa>3000
			|| s1!=sep1 || s2!=sep2
			|| s_jj.indexOf(" ")!="-1" || s_mm.indexOf(" ")!="-1" || s_aaaa.indexOf(" ")!="-1"
		)
	)
		return false ;
return true ;
}

// change dynamiquement les propriétés d'une class définie dans la css styleSheetname (pb sous Opéra)
// celle ci doit avoir été incluse dans le doc html à l'aide de balise <link rel="stylesheet" href="styleSheetname" type="text/css">
// changes = new Array('classname###propriété###valeu', ...);
// ex: Array('.classbg1###background###yellow', '.classbg2###background###yellow');
function modifyCssClassDefinition(styleSheetname, changes) {

		var tabCss = document.styleSheets;
		var couleurCss;
		var nbCss=tabCss.length;
		for(var i=0;i<nbCss;i++) {
				if(tabCss[i].href.match(styleSheetname)) {
					couleurCss = tabCss[i];			
					break;
				}
		}
		var rules = couleurCss.rules||couleurCss.cssRules;
		var nbChanges=changes.length;
		for(var i=0;i<nbChanges;i++) {
				var res=changes[i].split('###');
				var nbRules=rules.length;
				for(var r=0;r<nbRules;r++) {
					if(rules[r].selectorText==res[0]) 
						rules[r].style[res[1]] = res[2];
				}		
		}
}

function novAlert(mess,classDiv,temps,left,top,arrondi,idVouluForBgColor)
{
	var tempsPlein=temps;
	var alertDiv=document.createElement("div");
	var idUnique=Math.round(Math.random(0)*500)+1;
	alertDiv.style.display='none';
	alertDiv.setAttribute('id',"novaLert_"+idUnique);
	alertDiv.innerHTML=mess;
	alertDiv.className=classDiv;
	if ( (idVouluForBgColor) && (idVouluForBgColor.length>0))
		$(idVouluForBgColor).appendChild(alertDiv);
	else
		document.body.appendChild(alertDiv);
	if (arrondi==1)
		Nifty("div."+classDiv,"transparent");
	// Si left==droite alors le top est la largeur et top vaut 0
	if (left=="droite")
	{
		left=((window.innerWidth||document.body.clientWidth)-top)+"px";
		alertDiv.style.width=(top-5)+"px";
		top="0px";
	}
	// Si left==id alors le top = id:+left:+top
	if (left=="id")
	{
		var champs=top.split(':');
		left=(parseInt(getLeft($(champs[0])))+parseInt(champs[1]))+"px";
		top=(parseInt(getTop($(champs[0])))+parseInt(champs[2]))+"px";
	}
	
	faitFondre("novaLert_"+idUnique,left,top,0,100,5,2,tempsPlein,1);
	faitFondre("novaLert_"+idUnique,left,top,100,0,5,-2,tempsPlein,0);
}

function preload(listenomimage, chemin) {
 if (listenomimage.length > 0) {
  var taille=listenomimage.length;
  for(i=0; i<taille; i++) {
   document.image_chargee = new Image();
   document.image_chargee.src = chemin + listenomimage[i];
  }
 }
}