var IEOnly = false;

var ecranGestion = null;
var dialog = null;

var fenOpener = null;
if (window.dialogArguments != null)
	fenOpener = window.dialogArguments;

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de déterminer si on a un broswer internet explorer
 */
function isIE()
{
	return (navigator.userAgent.indexOf("MSIE") != -1);
}

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*	showDialog(url, [width = 400, height = 300 [, isResisable], [nomDialog]])
 *	
 *	Affiche une boîte de dialogue au centre de l'écran. Si on est en netscape on utilise pas le showModalDialog
 *	mais un windows.open ordinaire.
 * isRefresh -> rafraichir la page 
 */
function showDialog(url, width, height, isResizable, nomDialog, isClose, isRefresh, isAttente, isScroll)
{
	if (isRefresh == null)
		isRefresh = true;
	if (width == null)
		width = 400;
	
	if(nomDialog == null)
		nomDialog = 'dialog';
	
	if (height == null)
		height = 335;
	
	if (isResizable == null)
		isResizable = false;
	
	if (isClose == null)
		isClose = true
	
	var lLeft = (window.screen.width /2) - width /2;
	var lTop = (window.screen.height /2) - height /2;
	
	if (isClose)
	{
		try
		{
			if (dialog.name == nomDialog)
				dialog.close();
		} catch (err) {
			//Bon ici on veut pas vraiment que ca plante.
		}
	}
	
	if (!IEOnly)
	{
		
		dialog = window.open(url, nomDialog, 'toolbar=no,scrollbars='+ (isScroll? "yes": "no") +',resizable='+ (isResizable? "yes": "no") +',location=no,menubar=no,status=no,height='+ height +'px,width='+ width +'px,top='+ lTop +'px,left='+ lLeft +'px')
		dialog.focus();
	
	
	} else {
		window.showModalDialog(	"/gestion/UIGen/FrameDialog.asp?url="+ URLEncode(url), 
								window,
								"dialogHeight: "+height+"px; " +
								"dialogWidth: "+width+"px; " +
								"edge: Raised; " +
								"center: Yes; " +
								"help: No; " +
								"resizable: "+ (isResizable ? "Yes": "No") +"; " +
								"status: No;");
								
		if (isRefresh)
		{
			
		/*
		alert("url "+ URLEncode(url))
			try
			{
				document.location.reload();
			} catch (e) {
				//alert('window.reload(); marche pas')
			}
		*/
			try
			{
				window.location.assign(window.location.href +'');
			} catch (err) {
			}
	
		}
	}
	
/*
	dialog = window.open("/gestion/UIGen/FrameDialog.asp?url="+ URLEncode(url), nomDialog, 'toolbar=no,scrollbars=no,resizable='+ (isResizable? "yes": "no") +',location=no,menubar=no,status=no,height='+ height +'px,width='+ width +'px,top='+ lTop +'px,left='+ lLeft +'px')
	dialog.focus();
	
	window.showModalDialog(	"/gestion/UIGen/FrameDialog.asp?url="+ URLEncode(url), 
							window,
							"dialogHeight: "+height+"px; " +
							"dialogWidth: "+width+"px; " +
							"edge: Raised; " +
							"center: Yes; " +
							"help: No; " +
							"resizable: "+ (isResizable ? "Yes": "No") +"; " +
							"status: No;");
	*/
/*
	if (isAttente)
	{
		for (var i = 0; i < 100; i++)
		{
			;
		}
	}
	*/

}//showDialog

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de faire afficher la page de gestion
 */
function showGestion(url)
{
	ecranGestion = window.open(url, "gestion", "resizable=yes,toolbar=no,status=no");
}


/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	showDialog(url, [width = 400, height = 300 [, isResisable]])
 *	
 *	Affiche une boîte de dialogue au centre de l'écran. Si on est en netscape on utilise pas le showModalDialog
 *	mais un windows.open ordinaire.
 */
function showWindow(url)
{
	var height = window.screen.height-100;
	var width = window.screen.width-60;
	
	var lLeft = (window.screen.width /2) - width /2;
	var lTop = (window.screen.height /2) - height /2;
	
	window.open(url, null, 'height='+ height +'px,width='+ width +'px,top=5px,left='+ lLeft +'px')
}//showWindow
 
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	MouseOver pour le dictionnaire
 */
function dictioOver(id)
{
	document.getElementById(id+"").className = "dictio_txtOver";
}
function dictioOut(id)
{
	document.getElementById(id+"").className = "dictio_txtNormal";
}


/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permnet de soumettre un formulaire
 */
function submitForm(formName)
{
	document.getElementById(formName).submit();
}//submitForm

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de passer le focus à un autre champ lorsque le nombre de caractère est atteint
 */
function PasseFocus(donneur, receveur, maxCar)
{
	if(donneur.value.length == maxCar)
	{
		receveur.focus();
		receveur.select();
	}
}//submitForm

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de soumettre un formulaire en spécifiant l'action que l'on veut apporter
 *		nomChamp -> nom du champ à modifier
 */
function submitAction(formulaire, action, nomChamp)
{
	if (nomChamp == null)
		nomChamp = 'action';
	
	var form = document.getElementById(formulaire);
	form.elements[nomChamp].value = action;
	form.submit();
}//submitAction



/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de fermer la fenete parent
 */
function closeWindow(isReload)
{
	try
	{
		//On essai de donner le focus au parent
		window.opener.focus();
	} catch (e) {
		//Bon si ça n'a pas fonctionner on va essayer le top
		try
		{
			window.top.opener.focus();
		} catch (e) {}
	}


	//Si on est pas en mode IEOnly on veut toujours le faire.
	if (isReload || !IEOnly)
	{
		try
		{
			window.opener.document.location.reload();
		} catch (e) {
			try
			{
				window.top.opener.document.location.reload();
			} catch (e) {}
		}
	}
	
	//On ferme la fenetre courrante
	window.close();
}//closeWindow

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de fermer la fenêtre sur le clique du bouton escape
 */
function EscapeHandler(obj, evenement)
{
	if (evenement.keyCode+"" == "27")
	{
		try
		{
			window.opener.focus();
		} catch (e) {
			try
			{
				window.top.opener.focus();
			} catch (err) {}
		}
		window.close();
	}
}//EscapeHandler

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de fermer la fenêtre sur le clique du bouton escape
 */
function ModifStyle()
{
	var elem;
	for(var i=0; i<document.all.length; i++)
	{
		elem = document.all[i];
		if( elem.type != null && (elem.type.toLowerCase() == "radio" ||
			elem.type.toLowerCase() == "image" ||
			elem.type.toLowerCase() == "checkbox"))
		{
			elem.style.backgroundImage = "none";
			elem.style.borderWidth = "0";
		}//if
	}//for
}//DeleteStyleRadio


/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Empêche de submiter la page plus d'une fois et ainsi empêche certains doublons accidentels
 *  Utilise aussi la variable globale IsFormSubmitted pour garder le statut du formulaire
 */
var IsFormSubmitted = false;
function AntiDoubleSubmit(isSubmit)
{
	if(IsFormSubmitted)
	{
		//Le formulaire a déjà été soumis
		alert('Le formulaire a déjà été soumis. Veuillez patientez durant que votre demande est traitée.');
		return false;
	}
	
	if(isSubmit == 1)
	{
		IsFormSubmitted = true;
	}
}


/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	L'appelle de cette fonction permet d'empêcher la sélection du texte sur la page ! 
 */
function SetNoSelection()
{
	//if the browser is IE4+
	document.onselectstart=new Function ("return false");
	
	//if the browser is NS6
	if (window.sidebar){
		document.onmousedown=disableText;
		document.onclick=reEnable;
	}	
}
function disableText(e){ return false; }
function reEnable(){ return true; }


/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	L'appelle de cette méthode disable les clicks droit sur la page
 */
function DisableRightClick()
{
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	
	document.oncontextmenu=new Function("return false;");
}
function clickIE4(){if (event.button==2) return false;}
function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3)return false;}}










// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}//URLEncode

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *	Permet de décodé un URL en javascript
 */
function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
	
   return plaintext;
}//URLDecode