// Procedures globales du projet
function PUTILS_COMBOACTIVESAISIE(VSCOMBO, VBCREATION, VNHAUTEUR){{if (VBCREATION===undefined) VBCREATION=true;if (VNHAUTEUR===undefined) VNHAUTEUR=25;{var VSNAVAGENT=eval("navigator").userAgent.toLowerCase();var VNPOSY=ComboPosY(Obj(VSCOMBO))
var VNPOSX=ComboPosX(Obj(VSCOMBO));if((VBCREATION==true)){CreateTextField(Obj(VSCOMBO),VNPOSX,VNPOSY,VNHAUTEUR);if(((Position(VSNAVAGENT,"opera",null)<1)&&(Position(VSNAVAGENT,"msie",null)>0))){CreateIFrame(Obj(VSCOMBO),VNPOSX,VNPOSY)}
if((Position(VSNAVAGENT,"msie",null)>0)){
eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'frame"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.top=eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'txt"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.top
eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'frame"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.left=eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'txt"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.left}
OnResize(VSCOMBO)}else {;eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'txt"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.top=(VNPOSY+"px")
eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'txt"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.left=(VNPOSX+"px");if((Position(VSNAVAGENT,"msie",null)>0)){
eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'frame"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.top=(VNPOSY+"px")
eval(((clWDEncode.sEncodeCharset(unescape("Obj(\'frame"))+VSCOMBO)+clWDEncode.sEncodeCharset(unescape("\')")))).style.left=(VNPOSX+"px")}}}}}
function PUTILS_UNL(event)
{
	
}
function Obj(szObjId) { 
	// Renvoie l'objet JS en fonction de son ID
	return document.getElementById(szObjId); 
}
function ObjStyle(szObjId, szStyleProp)
{
	// Récupère l'objet
	var o = Obj(szObjId);
	var s;
	
	// Si l'objet existe
	if (o) {
	
		// Si on peut récupérer le style courant
		if (o.currentStyle)
		
			// Récupère la propriété de style demandée
			s = o.currentStyle[szStyleProp];
			
		// Sinon si on peut récupérer le style interprété
		else if (window.getComputedStyle)
		
			// Récupère la propriété de style demandée
			s = document.defaultView.getComputedStyle(o, null).getPropertyValue(szStyleProp);
	}
	
	return s;
}
function ComboPosX(oCombo)
{	
		// Récupère le nom du navigateur
		var detect	= navigator.userAgent.toLowerCase();
	
		var curLeft = 0;
		
		// Si on peut lire l'offset du parent
		if (oCombo.offsetParent) {
		
				// Tant qu'on peut lire l'offset du parent
				while (oCombo.offsetParent) {
				
						// Si on est sous IE
						if (detect.indexOf("msie") + 1) {
								
								// Récupère le type de positionnement 
								var p;
								if (oCombo.currentStyle)
									p = oCombo.currentStyle["position"];
								else if (window.getComputedStyle)
									p = document.defaultView.getComputedStyle(oCombo,null).getPropertyValue("position");
								
								// Si la position est relative, on sort de la boucle
								if (p == "relative") break;
							}
						
						// Calcule la position
						curLeft += oCombo.offsetLeft;
						oCombo = oCombo.offsetParent;
					}
					
			// Si on peut directement lire la position
			} else if (oCombo.x) {
			
				// Récupère la position
				curLeft += oCombo.x;
			}
		
		return curLeft;
	}
function ComboPosY(oCombo)
{
	// Récupère le nom du navigateur
	var detect	= navigator.userAgent.toLowerCase();
	
	var curTop = 0;
	
	// Si on peut lire l'offset du parent
	if (oCombo.offsetParent) {
		
		// Tant qu'on peut lire l'offset du parent
		while (oCombo.offsetParent) {
			
			// Si on est sous IE
			if (detect.indexOf("msie") + 1) {
				
				// Récupère le type de positionnement 
				var p;
				if (oCombo.currentStyle)
					p = oCombo.currentStyle["position"];
				else if (window.getComputedStyle)
					p = document.defaultView.getComputedStyle(oCombo,null).getPropertyValue("position");
				
				// Si la position est relative, on sort de la boucle
				if (p == "relative") break;
				}
			
			// Calcule la position
			curTop += oCombo.offsetTop;
			oCombo = oCombo.offsetParent;
			}
		
		// Si on peut directement lire la position
		} else if (oCombo.y) {
		
			// Récupère la position
			curTop += oCombo.y;
		}
	
	return curTop;
}


function CreateIFrame(oCombo, nPosX, nPosY)
{
	// Récupère le champ de saisie
	var textfield = document.getElementById("txt" + oCombo.id);

	// Récupère les dimensions du champ
	var textWidth = textfield.offsetWidth;
	var textHeight = textfield.offsetHeight;
	
	// Crée une IFRAME
	var hackFrame = document.createElement("iframe");
	
	// Paramètres
	hackFrame.setAttribute("src", "about:blank");
	hackFrame.setAttribute("scrolling", "0");
	hackFrame.setAttribute("tabindex", "-1");
	
	// Style
	hackFrame.id = "frame" + oCombo.id;
	hackFrame.style.position = "absolute";
	hackFrame.style.width = textWidth + "px";
	hackFrame.style.height = textHeight + "px";
	hackFrame.style.top = nPosX + "px";
	hackFrame.style.left = nPosY + "px";
	hackFrame.style.marginTop = "3px";
	hackFrame.style.marginLeft = "3px";
	
	// Ajoute l'IFRAME
	oCombo.parentNode.insertBefore(hackFrame, textfield);
}
function CreateTextField(oCombo, nPosX, nPosY, nHaut)
{
	if (!nHaut) { nHaut = 25; }
	var detect	= navigator.userAgent.toLowerCase();

	var selectButtonWidth;
	var selectWidth = oCombo.offsetWidth;
	
	// Création du champ de saisie
	var textfield = document.createElement("input");
	textfield.id 		= "txt" + oCombo.id;
	textfield.name		= "txt" + oCombo.name;
	textfield.className	= oCombo.className;
	textfield.style.zIndex = "99999";
		
	// Récupère la valeur sélectionnée dans la combo
	var inittextvalue = oCombo.options[oCombo.selectedIndex].text;
	if (inittextvalue == "") {
		textfield.style.color = "#cccccc";
	} else {
		textfield.value = oCombo.options[oCombo.selectedIndex].text;
	}
	
	// Positionne le champ de saisie
	textfield.style.position = "absolute";
	textfield.style.top = nPosY + "px";
	textfield.style.left = nPosX + "px";
	textfield.style.border = "none";
	
	// Calcule les marges de positionnement
	if ((detect.indexOf("safari") + 1)) {
		selectButtonWidth = 18;
		textfield.style.marginTop = "0px";
		textfield.style.marginLeft = "0px";
	} else if ((detect.indexOf("opera") + 1)) {
		selectButtonWidth = 27;
		textfield.style.marginTop = "4px";
		textfield.style.marginLeft = "4px";
	} else {
		selectButtonWidth = 23;
		textfield.style.marginTop = "2px";
		textfield.style.marginLeft = "3px";
	}
	
	if ((detect.indexOf("msie") + 1) || (detect.indexOf("firefox") + 1))
		textfield.style.height = (nHaut - 6) + "px";
	else 
		textfield.style.height = (nHaut - 2) + "px";
	
	// Définit la largeur du champ de saisie
	textfield.style.width = (selectWidth - selectButtonWidth) + "px";
	
	// Affiche le champ de saisie
	oCombo.parentNode.appendChild(textfield);
	
	// PCode : A chaque modification (combo)
	oCombo.onchange = function() {
	
		// Affiche la valeur sélectionnée dans le champ de saisie
		var val = this.options[this.selectedIndex].text;
		document.getElementById("txt" + this.id).value = val;
	}

	// PCode : Prise de focus (combo)
	oCombo.onfocus = function() {
	
		// Modifie la couleur du champ de saisie
		document.getElementById("txt" + this.id).style.color = "#333333";
	}
	
	// PCode : Prise de focus (champ de saisie)
	textfield.onfocus = function() {
	
		// Modifie la couleur du champ de saisie et vide le champ
		this.style.color = "#333333";
	}
	
	// PCode : Sortie de champ (champ de saisie)
	textfield.onblur = function() {
		// Restaure le texte par défaut si le champ est vide
		if (this.value == "") {
			this.style.color = "#cccccc";
		}
	}
	
	// PCode : A chaque modification (champ de saisie)
	textfield.onchange = function () {
	
		// Injecte dans la combo la valeur du champ de saisie
		oCombo.options[0].text = this.value;
		oCombo.selectedIndex = 0;
	}
}
function OnResize(sCombo)
{

	// Si on a accès aux objets de la page (IE)
	if (document.all) {		
	
		// déclare une fonction pour le redimensionnement
		window.onresize = function() { 
		
			// Récupère la liste des combos et listes
			var collection = document.getElementsByTagName("SELECT");
			
			// Parcourt cette liste
			for(i=0;i<collection.length;i++) {
			
				// Si on peut lire l'ID du champ
				if (collection[i].id) {
				
					// Si on a activé la saisie
					if (Obj("txt" + collection[i].id) != null) {
					
						// Replace la saisie
						PUTILS_COMBOACTIVESAISIE(collection[i].id, false); 
					}
				}
			}
		};
	} else {
	
		// Crée la fonction		
		var pFunc = new Function("PUTILS_COMBOACTIVESAISIE('" + sCombo + "', false);");
		addEventListener("resize", pFunc, false);
	}
}

