var Page_DSFControlVer = "2";

var CO_LANG_FR = "fr-CA";
var CO_LANG_AN = "en-CA";

// Formatter la valeur d'un controle
function FormatControlValue( vId )
{
	var control = GetById( vId );
	
	if( control.formatingEnabled == "False" || ! control.formatingEnabled )
	{
		return;
	}

	if( control.isValid == false )
	{
		return;
	}
	
	var controlValue = GetControlValue( control );

	if( control == null || control.name == "" || controlValue == null || controlValue == "" )
	{
		return;
	}
	else
	{
		var formatType = dsf_getAttribute( control, "formattype" );
		var charsAllowed = dsf_getAttribute( control, "allowedcharacters" );
		var validationExpression = dsf_getAttribute(control, "validationexpression");
		var decimalCharacter = dsf_getAttribute(control, "decimalseparator");
		var thousandCharacter = dsf_getAttribute(control, "thousandseparator");
		var numberOfDecimals = dsf_getAttribute( control, "numberofdecimals" );
		var negativeCurrencyPattern = dsf_getAttribute( control, "negativecurrencypattern" );
		var positiveCurrencyPattern = dsf_getAttribute( control, "positivecurrencypattern" );
		var currentCulture = dsf_getAttribute(control, "culture");

		if( typeof(formatType) != "undefined" && formatType != null )
		{
			var valueToFormat = RemoveGoodChars(controlValue, charsAllowed);

			var rx = new RegExp(validationExpression);
			var matches = rx.exec(valueToFormat);
			
			if( validationExpression == "" || ( matches != null && valueToFormat == matches[0] ) )
			{
				control.value = FormatValue( valueToFormat, formatType, decimalCharacter, thousandCharacter, numberOfDecimals, currentCulture, positiveCurrencyPattern, negativeCurrencyPattern );
			}
		}
	}
}

/************************************************************************
Description : Formatte la string 'vValueToFormat' selon le format choisi
************************************************************************/
function FormatValue( vValueToFormat, vFormatType, vDecimalCharacter, vThousandCharacter, vNumberOfDecimals, vCurrentCulture, vPositiveCurrencyPattern, vNegativeCurrencyPattern )
{
	var strValue = vValueToFormat;
	
	// MoneyType OU NumericType
	if( vFormatType == "Money" || vFormatType == "Numeric" || vFormatType == "Rate" )
	{
		// Ne pas remplacer par un point
		// si le format n'est pas bon, on ne formatte pas
		var replaceExp = new RegExp("\\" + vDecimalCharacter);
		strValue = strValue.replace( replaceExp, "." );

		var floatValue = parseFloat(strValue);

		if( floatValue == null )
		{
			return vValueToFormat;
		}
		
		// Formatter la valeur numérique
		strValue = FormatAmount( floatValue, vDecimalCharacter, vThousandCharacter, vNumberOfDecimals );
		
		if( strValue == null || strValue == "" )
		{
			return vValueToFormat;
		}
		
		if( vFormatType == "Money" )
		{
			// signe de dollars avant sans espace
			if( floatValue < 0 )
			{
				//var indexMinusSymbol = strValue.indexOf("-");
				//strValue = strValue.substring(0,indexMinusSymbol+1) + "$" + strValue.substring(indexMinusSymbol+1,strValue.length);
				strValue = vNegativeCurrencyPattern.replace( /n/, strValue );
			}
			else
			{
				//strValue = "$" + strValue;
				strValue = vPositiveCurrencyPattern.replace( /n/, strValue );
			}
		}
		else if( vFormatType == "Rate" )
		{
			strValue = strValue + " %";
			if( floatValue < 0 )
			{
				strValue = "-" + strValue;
			}
		}
		else // numeric
		{
			if( floatValue < 0 )
			{
				strValue = "-" + strValue;
			}
		}
	}
	else
	//RatesType
	/*
	if (vFormatType == "Rates")
	{
		strValue = FormatRate(strValue, vDecimalCharacter);
		
		if( strValue == null || strValue == "" )
		{
			return vValueToFormat;
		}
	}
	else
	*/
	//PostalCodeType	
	if (vFormatType == "PostalCode")
	{
		strValue = ReFormat(strValue.toUpperCase(), "", 3, " ", 3);
	}
	else
	//NASType		
	if (vFormatType == "NAS")
	{
		strValue = ReFormat(strValue.toUpperCase(), "", 3, " ", 3, " ", 3);
	}
	else
	//PhoneFrType				
	if (vFormatType == "PhoneFr")
	{
		strValue = ReFormat(strValue, "(", 3, ") ", 3, "-", 4);
	}
	else
	//PhoneEnType
	if (vFormatType == "PhoneEn")
	{
		strValue = ReFormat(strValue, "", 3, "-", 3, "-", 4);
	}
	else
	//PhoneByCultureType
	if (vFormatType == "PhoneByCulture")
	{
		if( vCurrentCulture == CO_LANG_AN )
		{
			strValue = ReFormat(strValue, "", 3, "-", 3, "-", 4);
		}
		else
		{
			strValue = ReFormat(strValue, "(", 3, ") ", 3, "-", 4);
		}
	}
	else
	//Phone800FrType				
	if (vFormatType == "Phone800Fr")
	{
		strValue = ReFormat(strValue, "",1," ", 3, " ", 3, "-", 4);
	}
	else
	//Phone800EnType
	if (vFormatType == "Phone800En")
	{
		strValue = ReFormat(strValue, "",1,"-", 3,"-", 3, "-", 4);
	}
	else
	//Phone800ByCultureType	
	if (vFormatType == "Phone800ByCulture")
	{
		if( vCurrentCulture == CO_LANG_AN )
		{
			strValue = ReFormat(strValue, "",1,"-", 3,"-", 3, "-", 4);
		}
		else
		{
			strValue = ReFormat(strValue, "",1," ", 3, " ", 3, "-", 4);
		}
	}
	else
	//ZipUS	
	if (vFormatType == "ZipUS")
	{
		// si c'est un code a 9 chiffres, ajouter un tiret apres le 5e chiffre
		if( strValue.length == 9 )
		{
			strValue = ReFormat(strValue, "", 5, "-", 4);
		}
	}
	else
	//IntegerWithZero
	//*** ce format n'existe plus, mais il faudrait le remettre pour enlever les décimales. Comme pour Integer ***
	if(vFormatType == "IntegerWithZero")
	{
// A activer si on decide d'appliquer un formattage pour ce type
// Pour que ca flush au moins les decimales
/*
		var replaceExp = new RegExp("\\" + vDecimalCharacter);
		strValue = strValue.replace( replaceExp, "." );

		var indexPoint = strValue.indexOf(".")
		if(indexPoint >= 0)
		{
			strValue = strValue.substring( 0, indexPoint );
		}
*/
	}
	else
	// Date operationnelle
	if( vFormatType == "DateOperational" )
	{
		if( vCurrentCulture == CO_LANG_AN )
		{
			strValue = ReFormat(strValue, "", 4, "/", 2, "/", 2);
		}
		else
		{
			strValue = ReFormat(strValue, "", 4, "-", 2, "-", 2);
		}
	}
	else
	// Telephone (1-800 ou normal francais)
	if( vFormatType == "PhoneAnyFR" )
	{
		if( strValue.length == 10 )
		{
			strValue = ReFormat(strValue, "(", 3, ") ", 3, "-", 4);
		}
		else if( strValue.length == 11 )
		{
			strValue = ReFormat(strValue, "",1," ", 3, " ", 3, "-", 4);
		}
	}
	else
	// Telephone (1-800 ou normal anglais)
	if (vFormatType == "PhoneAnyEN")
	{
		if( strValue.length == 10 )
		{
			strValue = ReFormat(strValue, "", 3, "-", 3, "-", 4);
		}
		else if( strValue.length == 11 )
		{
			strValue = ReFormat(strValue, "",1,"-", 3,"-", 3, "-", 4);
		}
	}
	else
	// Telephone (1-800 ou normal selon la culture en cours)
	if (vFormatType == "PhoneAnyByCulture")
	{
		if( vCurrentCulture == CO_LANG_AN )
		{
			if( strValue.length == 10 )
			{
				strValue = ReFormat(strValue, "", 3, "-", 3, "-", 4);
			}
			else if( strValue.length == 11 )
			{
				strValue = ReFormat(strValue, "",1,"-", 3,"-", 3, "-", 4);
			}
		}
		else
		{
			if( strValue.length == 10 )
			{
				strValue = ReFormat(strValue, "(", 3, ") ", 3, "-", 4);
			}
			else if( strValue.length == 11 )
			{
				strValue = ReFormat(strValue, "",1," ", 3, " ", 3, "-", 4);
			}
		}
	}
	else
	// ZipUS (12345 ou 12345-6789)
	if( vFormatType == "ZipUS" )
	{
		// si c'est un code a 9 chiffres, ajouter un tiret apres le 5e chiffre
		if( strValue.length == 9 )
		{
			strValue = ReFormat(strValue, "", 5, "-", 4);
		}
	}
	else
	// ZipAustralia (0003 ou 0025 ou 0369 ou 9856)
	if( vFormatType == "ZipAustralia" )
	{
		// Aucun formatage necessaire
	}
	else	
	// Date expiration
	if( vFormatType == "DateExpiration" )
	{
		if( vCurrentCulture == CO_LANG_AN )
		{
			strValue = ReFormat(strValue, "", 2, "/", 4);
		}
		else
		{
			strValue = ReFormat(strValue, "", 2, "-", 4);
		}
	}
	else
	{
		strValue = vValueToFormat;
	}
	
	return strValue;
}


/***********************************************************************************
Nom de la fonction:		SSNValidation
Description:			Verifie que le TEXTFIELD forment un NAS valide
***********************************************************************************/
function SSNValidation( strValue )
{
	var intSomme = 0, intMultiple;
	
	for (intCpt=0; intCpt<8; intCpt++)
	{
		if ( (intCpt % 2) == 1)
		{
			intMultiple = parseInt(strValue.charAt(intCpt)) * 2;
			intMultiple = (intMultiple % 10) + Math.floor(intMultiple / 10);
		}
		else
		{
			intMultiple = parseInt(strValue.charAt(intCpt));
		}
		
		intSomme += intMultiple;
	}
	
	if( (intSomme % 10 != 0) || (parseInt(strValue.charAt(8)) != 0) )
	{
		if (10 - (intSomme % 10) != parseInt(strValue.charAt(8)))
		{
			return false;
		}
	}
	
	return true;
}

/***********************************************************************************
Nom de la fonction:		ReFormat
Description:			Insere des caracteres dans la string "s"
						prend 1 argument (string "s") et n'importe quel nombre 
						d'autres arguments (STRING ou INT) en commencant par un string...
						Ils specifient comment "s" sera reformatte
***********************************************************************************/ 
function ReFormat(s)
{
	var arg;
	var intPosition = 0;
	var strResultat = "";
	for( var i=1; i < ReFormat.arguments.length; i++ )
	{
		arg = ReFormat.arguments[i];
		if (i%2 == 1)
		{
			strResultat += arg;
		}
		else
		{
			strResultat += s.substring(intPosition, intPosition + arg);
			intPosition += arg;
		}
	}
	return strResultat;
}


//Description: Formate un montant 	(ex 1000 donne 1,000.00 ou 1,000 selon pblnDecimal ou 1 000.00 ou 1 000 selon la langue)
function FormatAmount( vValueToFormat, vDecimalCharacter, vThousandCharacter, vNumberOfDecimals ) 
{
	var floatValue, integerValue, integerPart, decimalPart, integerPartLength, returnValue;
	
	if( isNaN( vValueToFormat ) )
	{
		return null;
	}
	if( vNumberOfDecimals == 0 ) 
	{
		floatValue = Math.round(vValueToFormat);
	}
	floatValue = "" + eval(vValueToFormat);  //evaluate (in case an expression sent)
	integerValue = parseInt(floatValue);  //isolate integer portion
	if( isNaN( integerValue ) ) 
	{
		integerPart = 0;
	}
	integerValue = Math.abs(integerValue);
	integerPart = "" + integerValue;
	
	//add comma in thousands place.
	var nbOfSeparators = Math.floor((integerPart.length - 1) / 3);
	
	var insertIndex = 3;
	var i = 0;
	for( i = 0; i < nbOfSeparators; i++ )
	{
		
		temp1 = integerPart.substring( 0, integerPart.length - insertIndex );	
		temp2 = integerPart.substring( integerPart.length - insertIndex, integerPart.length );	
		integerPart = temp1 + vThousandCharacter + temp2;
		insertIndex += 4;
	}
	
	
	if( vNumberOfDecimals == 0 || ( vNumberOfDecimals < 0 && Math.abs( floatValue ) == integerValue ) ) 
	{
		returnValue = integerPart;
	}
	else 
	{
		var indexDecimal = floatValue.indexOf(".");
		
		if( indexDecimal >= 0 )
		{
			//isolate decimal portion
			decimalPart = floatValue.substring( indexDecimal + 1, floatValue.length);
		}
		else
		{
			decimalPart = "";
		}
		
		if( decimalPart.length <= vNumberOfDecimals )
		{
			// ajouter des zeros a la fin des decimales pour atteindre
			// le nombre de decimales prevu dans le format
			var zerosToBeAdded = "";
			if( vNumberOfDecimals >= 0 )
			{
				var j = 0;
				for( j = 0; j < (vNumberOfDecimals - decimalPart.length); j++ )
				{
					zerosToBeAdded += "0";
				}
			}
			returnValue = integerPart + vDecimalCharacter + decimalPart + zerosToBeAdded;
		}
		else
		{
			if( vNumberOfDecimals >= 0 )
			{
				returnValue = integerPart + vDecimalCharacter + decimalPart.substring( 0, vNumberOfDecimals );
			}
			else
			{
				returnValue = integerPart + vDecimalCharacter + decimalPart;
			}
		}
	}

	// le formattage des valeurs negatives s'effectue maintenant au retour du formattage 
	// du nombre
	/*
	if( vValueToFormat < 0 )
	{
		returnValue = "-" + returnValue;
	}
	*/
	// pour phase 2, on va remplacer les - par des ( )
	// if (plngNum < 0) returnValue="("+returnValue+")"
//	if (isNS6 || isMac) 
	//{
		//returnValue = fgstrTrimString(returnValue);
//	}
	return returnValue;
}


//Description: Formate un taux (ex 50,0 en francais et 50.0 en anglais)
function FormatRate( plngNum, vDecimalCharacter ) 
{
	plngNum = ReturnRateFormat( plngNum.toString(), vDecimalCharacter );
	
	if( isNaN( plngNum ) )
	{
		return null;
	}
	plngNum = Math.round(plngNum * 10)/10;  // garder 1 decimale...
	plngNum = "" + eval(plngNum);  //evaluate (in case an expression sent)
	intnum = parseInt(plngNum);  //isolate integer portion
	if (isNaN(intnum)) 
	{
		intnum = 0;
	}
	intnum = Math.abs(intnum);
	intstr = "" + intnum;
    decnum = Math.abs(parseFloat(plngNum)-intnum); //isolate decimal portion
	decnum = decnum * 10; // multiply decimal portion by 10
	decstr = "" + Math.abs(Math.round(decnum));
	if (decstr.length>1) 
	{
		decstr=decstr.substring(0,1);
	}
	while (decstr.length < 1)
	 {
		decstr = "0" + decstr;
	}
	retval = intstr;
	if (!((retval == "0")&&(decstr == "0"))&&!((retval == "100")&&(decstr == "0"))) 
	{
		retval = retval + vDecimalCharacter + decstr;
	}
	if (plngNum < 0) 
	{
		retval = "-" + retval;
	}
	return retval + " %";
}


//Description: Retourne la valeur d'un taux  (ex "1,0" retourne 1.0)
function ReturnRateFormat(strTaux, vDecimalCharacter) 
{
	var replaceExp = new RegExp("\\" + vDecimalCharacter);
	strTaux = strTaux.replace(replaceExp, ".");

	strTaux = parseFloat(strTaux);
	
	if( isNaN( strTaux ) ) 
	{
		return null;
	}

	return strTaux;
}

// Prend la valeur d'un controle et la retourne
// convertie en Double
function GetValueAsDouble( vId )
{
	var control = GetById( vId );
	
	var allowedChars = dsf_getAttribute( control, "conversiontodoubleallowedcharacters" );
	var decimalChar = dsf_getAttribute( control, "decimalseparator" );
	
	if( allowedChars == null || decimalChar == null )
	{
		return null;
	}
	else
	{
		var currentValue = GetControlValueById( vId );
		
		var newValue = RemoveGoodChars( currentValue, allowedChars );
		
		var replaceExp = new RegExp("\\" + decimalChar);
		newValue = newValue.replace( replaceExp, "." );
		
		var doubleValue = parseFloat(newValue);
		
		if( typeof(doubleValue) == "undefined" || doubleValue == null )
		{
			return null;
		}
		else
		{
			return doubleValue;
		}
	}
}

function GetControlValueById( vId )
{
	var controlDay = GetById( vId + "__Day" );
	var controlMonth = GetById( vId + "__Month" );
	var controlYear = GetById( vId + "__Year" );

	// DatePicker seulement
	if( controlDay != null && controlDay != "undefined"
		&& controlMonth != null && controlMonth != "undefined"
		&& controlYear != null && controlYear != "undefined" )
	{
		if(controlDay.value == "" || 
			controlMonth.value == "" ||
			controlYear.value == "" )
		{
			return "";			
		}
		else
		{
			var controlDate = controlYear.value + "/" + controlMonth.value + "/" + controlDay.value;
			return controlDate;
		}
	}
	else
	{
		return GetControlValue( GetById( vId ) );
	}
	
	return "";
}

// Obtient la valeur d'un controle à l'aide de son ID
function GetControlValue( vCtrl )
{
	if (vCtrl == null)
		return "";

	if (typeof(vCtrl.value) == "string")
		return vCtrl.value;
		
	if (typeof(vCtrl.tagName) == "undefined" && typeof(vCtrl.length) == "number")
	{
		var j;
		for (j=0; j < vCtrl.length; j++)
		{
			var inner = vCtrl[j];
	                    
			if (typeof(inner.value) == "string" && (inner.type != "radio" || inner.status == true))
			{
				return inner.value;
			}
		}
	}
	else
	{
		return GetControlValueRecursive(vCtrl);
	}
}

// Obtient la valeur d'un controle à l'aide de son ID
// va chercher la valeur dans un controle enfant si valeur inexistante
function GetControlValueRecursive( vCtrl )
{
    if (typeof(vCtrl.value) == "string" && (vCtrl.type != "radio" || vCtrl.status == true))
    {
        return vCtrl.value;
    }
    
    var i, val;
    for (i = 0; i < vCtrl.childNodes.length; i++)
    {
		if( vCtrl.childNodes[i].nodeType == 1 )
		{
			val = GetControlValueRecursive(vCtrl.children[i]);
			if (val != "")
			{
				return val;
			}
		}
    }
    return "";
}

//Enleve tous les caracteres contenu dans "bon" de la string "s"
function RemoveGoodChars(s, bon)
{
	var strResultat = "";

	for (var i=0;i<s.length;i++)
	{
		var c=s.charAt(i);
		if(bon.indexOf(c) == -1) strResultat+=c;
	}

	return strResultat;
}

// Fait afficher un message de confirmation lorsque l'utilisateur
// tente de fermer la fenêtre d'Internet Explorer
function HandleOnBeforeUnload()
{
	if( msgOnBeforeUnload.length > 0 )
	{
		if( window.event.clientY < 0 )
		{
			return msgOnBeforeUnload;
		}
	}
}

// Desactive l'autocomplete dans Internet Explorer
function DisableAutoComplete()
{
	var i;
	
	for( i = 0; i < document.forms.length; i++ )
	{
		document.forms[i].autocomplete = "off";
	}
}

// Setter le focus sur un controle
function SetFocus(id)
{
	var control = GetById(id);

	if ((typeof(control) == "undefined") )
		return;

	if( control.isDisabled == true )
		return;

	var controlType = control.type;
	var controlTagName = control.tagName;

	if( typeof(controlType) != "string")
		return;

	if( (controlType == "radio")
			|| (controlType == "checkbox")
			|| (controlType == "text")
			|| (controlType == "password") 
			|| (controlType == "textarea") 
			|| (controlType == "image")
			|| (controlTagName == "A") 
			|| (controlType.toString().charAt(0) == "s" && controlType != "select"))
	{
		control.focus();
	}
	
	if( (controlType == "text")
		|| (controlType == "password") )
	{
		control.select();
	}
}

// Obtenir une reference sur un controle par son ID
function GetById(vId)
{
	var element = document.getElementById(vId);
	return element;
}

// Afficher une definition
function ShowDefinition(vEvt, vCtrl)
{	
	//Permet de valider si le tableau existe deja
	if (typeof(Page_Definition) == "undefined") 
        return;
	//Recoit les tableux de parametres
	var livePageWidth = getWindowWidth();
	var divDef = Page_Definition[0];
	var tdDefTexte = Page_Definition[1];
	var tdDefTitre = Page_Definition[2];
	var tdDefTab = Page_Definition[3];
	//On obtient la TD qui doit recevoir le texte de la definition

	if (vCtrl==null || divDef==null || tdDefTexte==null) return;
	//Assigner le texte de la definition a la TD
	{
		if(tdDefTitre != null)
		{
			//var titre = vCtrl.innerHTML;
			
			//tdDefTitre.innerHTML = titre;
			tdDefTitre.innerHTML = dsf_getAttribute(vCtrl, "titre");
		}
		
		if(tdDefTexte != null)
		{
			tdDefTexte.innerHTML = dsf_getAttribute(vCtrl, "definition");
		}
		
		topVal = getElemTop( vCtrl ) + getElemHeight( vCtrl ) + 5;
		leftVal = getElemLeft( vCtrl );
	}
	
	
	 var elemWidth = divDef.style.width;

	//Positionner a droite de l'element s'il y a de la place
	if ((leftVal + elemWidth) > livePageWidth)
	{
		leftVal = livePageWidth - elemWidth;
	}
		
		
	//Obtenir le style de la DIV
	divDefStyle = divDef.style;
	divDefStyle.top = topVal; // Positions the element from the top
	divDefStyle.left = leftVal; // Positions the element from the left
	divDefStyle.visibility = "visible"; // Makes the element visable 
	
	// On cache les select potentiellement clippe...
	scanSelectForClip(tdDefTab,vCtrl);
}


/* Cache la definition sur onmouseout ou onblur */
function HideDefinition()
{
	//Permet de valider si le tableau existe deja
	if (typeof(Page_Definition) == "undefined") 
        return;
	//On obtient le style de la DIV servant a afficher la definition sous forme de PopUp
	var divDefStyle = Page_Definition[0].style;
	if (divDefStyle==null)
		return;
	divDefStyle.visibility = "hidden";
	AfficherSelect( Page_Definition[3].id);
}

/* Determine la largeur de la portion interne du browser */
function getWindowWidth()
{  
	if (document.body.clientWidth != null)
		return document.body.clientWidth;
	if (window.innerWidth != null)
		return window.innerWidth;
	return 0;
}

/* Determine la largeur de la portion entre l'ecran et la gauche du browser */
function getWindowLeft()
{
	if (window.screenLeft != null)
		return window.screenLeft;
	if (window.screenX != null)
		return window.screenX;
	return 0;
}

/* Determine la coordonee x d'un element par rapport au Document */
function getElemLeft(vObj) 
{
	xPos = eval(vObj).offsetLeft;
	tempEl = eval(vObj).offsetParent;
  	while (tempEl != null)
  	{
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

/* Determine la coordonee y d'un element par rapport au Document */
function getElemTop(vObj)
{
	yPos = eval(vObj).offsetTop;
	tempEl = eval(vObj).offsetParent;
	while (tempEl != null)
	{
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

/* Determine la hauteur d'un element */
function getElemHeight(vObj)
{
	return eval(vObj).offsetHeight;
}

/* Determine la largeur d'un element */
function getElemWidth(vObj)
{
	return eval(vObj).offsetWidth;
}

function scanSelectForClip(vDiv, vCtl)
{
	var listSelect = document.getElementsByTagName("select");
	var select;
	var ax, bx, cx, dx, ay, by, cy, dy, c0, c1, c2, c3;
	var i;
	
	// On re-affiche tout les selects avant de les caches.
	// Pourquoi? A cause du delai du afficherErreur dans ValidatorChange de WebUI qui peut
	// entrer en conflit avec AfficherInfoAPriori precedent lors
	// d'une meme sequence i.e OnChange(a),OnBlur(a),OnFocus(b),OnBlur(b),OnFocus(a)
	for(i=0; i<listSelect.length;i++)
	{
		select = listSelect[i];
		if (typeof(select.divCache) != "undefined")
		{
			select.style.left = "";
			select.divCache = "";
		}
	}
	
	ax = cx = getElemLeft(vDiv);
	ay = by = getElemTop(vDiv);
	bx = dx = ax + vDiv.offsetWidth;
	cy = dy = ay + vDiv.offsetHeight;

	// Test de Cohen-Sutherland (modifier & abregee)
	for(i = 0; i < listSelect.length; i++)
	{
		select = listSelect[i];
		// ligne A-B
		c0 = getCode(ax,ay,myrect(select));
		c1 = getCode(bx,by,myrect(select));	
		if (isClipping(c0,c1)) CacherSelect(select,vDiv.id,vCtl);
		// ligne A-C
		c2 = getCode(cx,cy,myrect(select));	
		if (isClipping(c0,c2)) CacherSelect(select,vDiv.id,vCtl);
		// ligne B-D
		c3 = getCode(dx,dy,myrect(select));	
		if (isClipping(c1,c3)) CacherSelect(select,vDiv.id,vCtl);
		// ligne C-D
		if (isClipping(c2,c3)) CacherSelect(select,vDiv.id,vCtl);
		
		// Dernier test non couvert par Cohen-Sutherland (parce qu'un rectangle!)
		if ((c0 | c1 | c2 | c3) == 15) CacherSelect(select,vDiv.id,vCtl);
	}
}

/* Determine la valeur binaire d'une coordonner	pour l'algo. Cohen-Sutherland */
function getCode(vX,vY,vRect)
{
	var code = 0;
	
	if ( vX < vRect.x) code |= 0x1;
	else if ( vX > vRect.xmax) code |= 0x2;
	
	if ( vY < vRect.y ) code |= 0x8;
	else if ( vY > vRect.ymax ) code |= 0x4; 
	
	return code;
}

/* Retourne un objet de coordonnee de type rectangle */
function myrect(vObj)
{
	myrect.x = getElemLeft(vObj);
	myrect.y = getElemTop(vObj);
	myrect.xmax = myrect.x + vObj.offsetWidth;
	myrect.ymax = myrect.y + vObj.offsetHeight;
	return(myrect);
} 

/* Test de Cohen-Sutherland qui determine si nous avons du clipping */
function isClipping(vC0,vC1)
{
	if (vC0 == 0 && vC1 == 0 ) return true; // Completement inclus
	if ((vC0 & vC1) == 0 ) return true; // Coupe d'un facon...
	return false; 
}

// Cacher les SELECT qui sont totalement ou partiellement caches par le DIV (erreur ou definition)
// On ne cache pas le select si c'est lui qui a fait apparaitre le DIV
function CacherSelect(vSelect,vIdDiv,vCtl)
{
	if (vSelect.name != vCtl.name)
	{
		vSelect.style.visibility = "hidden";
		//vSelect.style.left = "-1600px";
		vSelect.divCache = vIdDiv;
	}
}

// On reaffiche les SELECT qui etaient sous le DIV
function AfficherSelect(vIdDiv)
{
	var listSelects = document.getElementsByTagName("select");
	var select;
	
	for(var i=0; i<listSelects.length;i++)
	{
		select = listSelects[i];

		if (select.divCache == vIdDiv)
		{
			//select.style.left = "";
			select.style.visibility = "visible";
			select.divCache = "";
		}
	}
}

function dsf_getAttribute( control, attribute )
{
	var attrib = control.getAttribute(attribute, false);
		
	return attrib;
}

// Ouvre une fenetre unique et re-utilisable
function OuvrirNIF(vURL, vInstance, vParam, vWidth, vHeight, vTop, vLeft)
{
	var isMac = (navigator.appVersion.indexOf("Mac") != -1);

	if (vWidth == "max")
	{
		vWidth = screen.availWidth - vLeft;		
	}
	else
	{
		if (screen.availWidth - vWidth < vLeft )
		{
			if (screen.availWidth - vWidth > 0)
			{
				vLeft = screen.availWidth - vWidth;
			}
			else
			{
				vLeft = 0;
			}
		}
	}
	
	if (vHeight == "max")
	{
		vHeight = screen.availHeight - 28;
		vTop = 0;
	} 

	if (vLeft == "droite")
	{
		vLeft = screen.availWidth - vWidth - 10;
	} 
	
	// Ajustement specifique au Mac...
	isMac = (navigator.appVersion.indexOf("Mac") != -1);
	if (isMac)
	{
		vLeft -= 10;
		vHeight -=40;
	}
	
	// On ne peut pas manipuler (resize, move, ...) une fenetre dont l'URL
	// pointe sur un serveur different d'ou ce script est lance!
	// Donc si la fenetre est ouverte, on ne peut plus la manipuler!
	// C'est pourquoi un ajuste la fenetre avant d'assigner son URL.
	
	//if vParam contains something, add a coma for the rest of the parameter to be concatened
	if(vParam != "")
		vParam += ',';
	
	// Verifier si c'est une fenetre transactionnel qu'on veut ouvrir
	//mghWnd = window.open(vURL, vInstance, vParam + 'width=' + vWidth + ',height=' + vHeight+ ',left=' + vLeft + ',top=' + vTop);
	//mghWnd.focus();
	/*if(navigator.appName == "Netscape")
	{
		alert('NN:width=' + vWidth + ',height=' + vHeight + ',left=' + vLeft + ',top=' + vTop)
		mghWnd = window.open(vURL, vInstance, vParam);
		mghWnd.resizeTo(ParseInt(vWidth),ParseInt(vHeight));
		mghWnd.moveTo(ParseInt(vLeft),ParseInt(vTop));
	}
	else*/
	{
		//vParam += 'width=' + 800 + ',height=' + 600 + ',left=' + 0 + ',top=' + 0;
		//alert('IE:width=' + vWidth + ',height=' + vHeight + ',left=' + vLeft + ',top=' + vTop)
		vParam += 'width=' + vWidth + ',height=' + vHeight + ',left=' + vLeft + ',top=' + vTop;
		mghWnd = window.open(vURL, vInstance, vParam);	
		//mghWnd = window.open(vURL, vInstance, vParam + 'width=' + vWidth + ',height=' + vHeight + ',left=' + vLeft + ',top=' + vTop);	
	}
	mghWnd.focus();
}
//**************************************************************************************
//fonction pour la classe c#
//**************************************************************************************
function RowSelectorColumnSelectAll( parentCheckBox ) {
    if ( typeof( document.getElementById ) == "undefined" ) return;
    if ( parentCheckBox == null || typeof( parentCheckBox.participants ) == "undefined" ) {
        return;
    }
    var participants = parentCheckBox.participants;
    for ( var i=0; i < participants.length; i++ ) {
        var participant = participants[i];
        if ( participant != null ) {
            participant.checked = parentCheckBox.checked;
        }
    }
}
function RowSelectorColumnRegister( parentName, childName ) {
    if ( typeof( document.getElementById ) == "undefined" ) return;
    var parent = document.getElementById( parentName );
    var child = document.getElementById( childName );
    if ( parent == null || child == null ) {
        return;
    }
    if ( typeof( parent.participants ) == "undefined" ) {
        parent.participants = new Array();
    }
    parent.participants[parent.participants.length] = child;
}
function RowSelectorColumnCheckChildren( parentName ) {
	if ( typeof( document.getElementById ) == "undefined" ) return;
    var parent = document.getElementById( parentName );
    if ( parent == null || typeof( parent.participants ) == "undefined" ) return;
    var participants = parent.participants;
    for ( var i=0; i < participants.length; i++ ) {
        var participant = participants[i];
        if ( participant != null && !participant.checked ) {
				parent.checked = false;
				return;
        }
    }
    parent.checked = true;
}


   /***************************************************************************/
	/* Selon la longueur de caractère saisi dans le champ courant, la          */
	/* fonction détermine s'il faut passer au champ suivant.                   */
	/*                                                                         */
	/* Les paramètres doivent avoir la structure suivante:                     */
	/*    vobjChampCourant: l'objet champs courant                             */
	/*    vintMaxCar: le nombre de caractère nécessaire pour changer de champ  */
	/*    vobjChampSuivant: l'objet champs où le focus est désiré.             */
   /***************************************************************************/
	function ChangerChamp( vobjChampCourant, vintMaxCar, vIdChampSuivant )
	{
	   var champSuivant;
	   var nbCar;
	   
	   nbCar = vobjChampCourant.value.length;
	   if (nbCar == vintMaxCar) {
	      document.getElementById(vIdChampSuivant).focus();
	   }
		return true;
	}

