/*
FONCTIONS JAVASCRIPT pour gérer les ancrages de div
Alban BALLIEUX			- 17/03/2009 - Suppression des '_' dans les identifiants javascript
*/ 
function getLeftId(iO){
	var ret=iO.offsetLeft;
	while((iO=iO.offsetParent)!=null){
		if(iO.tagName!='HTML')ret+=iO.offsetLeft;
	}
	return ret;
}
function getTopId(iO){
	var ret=iO.offsetTop;
	while((iO=iO.offsetParent)!=null){
		if(iO.tagName!='HTML')ret+=iO.offsetTop;
	}
	return ret;
}

function setToAnchor(ID_Anchor,ID_Div){
	Elt=document.getElementById(ID_Div);
	X=getLeftId(Elt);
	Y=getTopId(Elt);
	if(X<0)Elt.style.left=0;
	if(Y<0)Elt.style.top=0;
	if(X+Elt.offsetWidth>window.innerWidth)Elt.style.left="0pt";
   	Elt.style.visibility='visible';
	if (obFocus!=null)obFocus.style.zIndex=1501;
	obFocus=Elt;
	Elt.style.zIndex=1600;
}

function getLeft(MyObject){
	if(MyObject.offsetParent)return (MyObject.offsetLeft+getLeft(MyObject.offsetParent));
	else return MyObject.offsetLeft;
}

function getTop(MyObject){
	if (MyObject.offsetParent)return (MyObject.offsetTop + getTop(MyObject.offsetParent));
	else return (MyObject.offsetTop);
}

function CacheElts(Radical){
	if(document.getElementById){
		if(document.getElementById(Radical)){
			document.getElementById(Radical).style.visibility='hidden';
		}
		NB=1;
		ID=Radical.concat(NB.toString());
		while(document.getElementById(ID)){
			document.getElementById(ID).style.visibility='hidden';
			NB++;
			ID=Radical.concat(NB.toString());
		}
	}
}
function Aff(ID_Cache,ID_Ancre,RAD){
	if (document.getElementById){
		if (document.getElementById(ID_Cache).style.visibility=='visible'){
			document.getElementById(ID_Cache).style.visibility='hidden';
		} else {
			CacheElts(RAD);
			setToAnchor(ID_Ancre,ID_Cache);
		}
	}
}
function SansRafraichir(SRID){
	PtID=document.getElementById(SRID);
	if (isset){
		PtID.href = PtID.href.replace(new RegExp('((xajax_[^;]*;)+[^;]*;)', 'gi'),'');
		PtID.href = PtID.href.replace('SansRafraichir(\''+SRID+'\');','');
	}
}


function Ferme(ID){
	if (document.getElementById){
		document.getElementById(ID).style.visibility='hidden';
	}
}
function Kill(ID){
	if (document.getElementById(ID)!=null){
		var IdSup=document.getElementById(ID);
		IdSup.parentNode.removeChild(IdSup);
	}
}
function FermeVide(ID,IDC,T){
	if (typeof window[T]=='undefined')T='Chargement...';
	if (document.getElementById){
		document.getElementById(ID).style.visibility='hidden';
		document.getElementById(IDC).innerHTML=T;
	}
}
function Visible(ID){
	if (document.getElementById){document.getElementById(ID).style.visibility='visible';}
}

function Submit(ID){
	if (O=document.getElementById(ID)){if (O.tagName.toLowerCase()=='form')O.submit();}
}

/*FCTS COMMUNES pr l'affichage d'1 sélecteur de couleur*/

// Fonction à utiliser avec la fonction PHP: Cree_Input_Avec_Selecteur
function Affecte(ID,Val){
 	Ferme('MVCCH'+ID);
	if(E=document.getElementById(ID)){E.value=Val;}
 }
 
function AffecteEtFerme(ID,Val){
	window.opener.document.getElementById(ID).value=Val;
	window.close();
}

function AffecteEtCache(IDInput,IDZone,Val){
	document.getElementById(IDInput).value=Val;
	Ferme(IDZone);
	LOCK_FORM=true;
}

function AffecteEtCache2(IDInput,IDZone,Val,NextChamp){
	document.getElementById(IDInput).value=Val;
	Ferme(IDZone);
	LOCK_FORM=true;
	if(NextChamp!=''&&document.getElementById(NextChamp))document.getElementById(NextChamp).focus();
}


function AffecteCouleur(ID, CoulFond, CoulTexte, dhtml){
	if(dhtml=='true'){
		document.getElementById(ID).style.background=CoulFond;
 		document.getElementById(ID).style.color=CoulTexte;
	}else{
		window.opener.document.getElementById(ID).style.background=CoulFond;
 		window.opener.document.getElementById(ID).style.color=CoulTexte;
	}
}

function Display(txt){document.write(txt);}

function PositionneAuDessus(IdDeb,IdToMove,Dlt){
	ODeb=document.getElementById(IdDeb);
	OMov=document.getElementById(IdToMove);
	x=getTopId(ODeb);
	off=OMov.offsetTop;
	if (Dlt==0)h=OMov.offsetHeight;else	h=Dlt;
	OMov.style.top=(off-(x-off)-h)+'px';
}

function AfficheSelecteurCouleur(objet,defaut,dhtml) {
	Display('<table style="width:90pt;border:1px solid #a7a7a7;">');
	var hexa=new Array('00','88','CC','FF');
	var colhexa="";
	for(var i=0;i<4;i++) {
		Display('<tr><td colspan="3"></td></tr>');
		for(var j=0;j<4;j++) {
			Display("<tr>");
			for(var k=0;k<4;k++) {
				colhexa="#"+hexa[i]+hexa[j]+hexa[k];
				if(colhexa=="#FFFFFF") {
					CoulBorder="#000000";
				}else{CoulBorder="#FFFFFF";}
				if(defaut==colhexa){
					if (dhtml=='true'){
						Display("<td style='border:4px solid "+CoulBorder+";width:30pt;' bgcolor='"+colhexa+"'><a style='color:"+colhexa+";'href='javascript:AffecteCouleur(\""+objet + "\",\""+colhexa+"\",\""+colhexa+"\", \""+dhtml+"\");Affecte(\""+objet+"\",\""+colhexa+"\")';'>"+colhexa+"</a></td>");
					}else{Display("<td style='border:4px solid "+CoulBorder+";width:30pt;' bgcolor='"+colhexa+"'><a style='color:"+colhexa+";'href='javascript:AffecteCouleur(\""+objet+"\",\""+colhexa+"\",\""+colhexa+"\", \""+dhtml+"\");AffecteEtFerme(\""+objet+"\",\""+colhexa+"\")';'>"+colhexa+"</a></td>");}
				}else{
					if (dhtml=='true'){
						Display("<td style='border:2px solid #888888;width:30pt;' bgcolor='"+colhexa+"'><a style='color:"+colhexa+";'href='javascript:AffecteCouleur(\""+objet+"\",\""+colhexa+"\",\""+colhexa+"\", \""+dhtml+"\");Affecte(\""+objet + "\",\""+colhexa+"\")';'>"+colhexa+"</a></td>");
					}else{Display("<td style='border:2px solid #888888;width:30pt;' bgcolor='"+colhexa+"'><a style='color:"+colhexa+";'href='javascript:AffecteCouleur(\""+objet+"\",\""+colhexa+"\",\""+colhexa+"\", \""+dhtml+"\");AffecteEtFerme(\""+objet+"\",\""+colhexa+"\")';'>"+colhexa+"</a></td>");}
				}
			}
			Display("</td>");
		}
	}
	Display("</table>");
}