

    // Script permettant de déclencher l ouverture
    // d une popup au bout de x secondes

   var secondes = 150
    var y = 1
    
    function startClock(page)
    {
    	secondes = secondes-y
    	//document.frm.clock.value = secondes
    	setTimeout("startClock()", 1000)
    	if(secondes==0)
    	{
    		newWindow(page, 'SessionTimeOut', 200, 250, 'no');
       	}
	
    }
	
	function putFocus(formInst, elementInst) 
 	{
  		if (document.forms.length > 0) 
  		{
  			 document.forms[formInst].elements[elementInst].focus();
  		}
 	}
 	
 	function newWindow(mypage, myname, w, h, scroll) 
 	{
		winprops = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable=yes'+',menubar=yes' 
		win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) 
		{ 
			win.window.focus(); 
		}
		return false;
		
	}
	
	function startClockAndPutFocus(formInst, elementInst, page)
	{
		putFocus(formInst, elementInst);		
		startClock(page);
	}
	
	
/*************************************************************\
 *	DYNIFS - Dynamic IFrame Auto Size v1.0.0
 *
 *	Copyright (C) 2006, Markus (phpMiX)
 *	This script is released under GPL License.
 *	http://www.phpmix.org
 *
 \*************************************************************/

var DYNIFS = {
	// Storage for known IFrames.
	iframes: {},
	// Here we save any previously installed onresize handler.
	oldresize: null,
	// Flag that tell us if we have already installed our onresize handler.
	ready: false,
	// The document dimensions last time onresize was executed.
	dim: [-1,-1],
	// Timer ID used to defer the actual resize action.
	timerID: 0,
	// Obtain the dimensions (width,height) of the given document.
	getDim: function(d) {
		var w=200, h=200, scr_h, off_h;
		var tailleMin = 100;
		
		if( d.height ) { 

			/*if (d.height < tailleMin)
				return [d.width,tailleMin]; 
			else*/
				return [d.width,d.height]; 
		}
		with( d.body ) {
			if( scrollHeight ) { h=scr_h=scrollHeight; w=scrollWidth; }
			if( offsetHeight ) { h=off_h=offsetHeight; w=offsetWidth; } 
			if( scr_h && off_h ) h=Math.max(scr_h, off_h);
			if ( h == 0 ) {h=tailleMin;};
			/*if ( h < tailleMin ) {h=tailleMin;};*/
		}
		return [w,h];
	},
	// This is our window.onresize handler.
	onresize: function() {
		// Invoke any previously installed onresize handler.
		if( typeof this.oldresize == 'function' ) { this.oldresize(); }
		// Check if the document dimensions really changed.
		var dim = this.getDim(document);
		if( this.dim[0] == dim[0] && this.dim[1] == dim[1] ) return;
		// Defer the resize action to prevent endless loop in quirksmode.
		if( this.timerID ) return;
		this.timerID = setTimeout('DYNIFS.deferred_resize();', 10);
	},
	// This is where the actual IFrame resize is invoked.
	deferred_resize: function() {
		// Walk the list of known IFrames to see if they need to be resized.
		for( var id in this.iframes ) this.resize(id);
		// Store resulting document dimensions.
		this.dim = this.getDim(document);
		// Clear the timer flag.
		this.timerID = 0;
	},
	// This is invoked when the IFrame is loaded or when the main window is resized.
	resize: function(id) {
		// Browser compatibility check.
		if( !window.frames || !window.frames[id] || !document.getElementById || !document.body )
			return;
		// Get references to the IFrame window and layer.
		var iframe = window.frames[id];
		var div = document.getElementById(id);
		if( !div ) return;
		// Save the IFrame id for later use in our onresize handler.
		if( !this.iframes[id] ) {
			this.iframes[id] = true;
		}
		// Should we inject our onresize event handler?
		if( !this.ready ) {
			this.ready = true;
			this.oldresize = window.onresize;
			window.onresize = new Function('DYNIFS.onresize();');
		}
		
		div.style.height = '0px';
		var dim;
		if (iframe && iframe.location && iframe.location.href) {
			var reg = ".pdf";
			var s = iframe.location.href;
			if (s.indexOf("?") != -1) {
				s = s.substr(0, s.indexOf("?"));
			}
			if (s.length >= reg.length && s.substr(s.length - reg.length) == reg) {
				// si on charge un pdf dans l'IFRAME
				var heightMin = 500;
				var sideNav = document.getElementById("sideNav");
				if (sideNav && sideNav.offsetHeight && heightMin < sideNav.offsetHeight) {
					heightMin = sideNav.offsetHeight - 70;
				}
				dim = [200, heightMin];
			} else {
				// sinon
				dim = this.getDim(iframe.document);
				// permet de resoudre le probleme du onload qui ne s'execute pas lorsqu'on charge un PDF dans l'IFRAME pour FF et IE
				iframe.onunload = function() { DYNIFS.timerID = setTimeout("DYNIFS.resize_def('" + id + "', '" + s + "');", 200); }; // FF
				iframe.document.body.onunload = function() { DYNIFS.timerID = setTimeout("DYNIFS.resize_def('" + id + "', '" + s + "');", 200); }; // IE
			}
			div.style.height = (dim[1]+30) + 'px';
		}
	},
	resize_def: function(id, oldHref) {	/* Util pour FF et IE lorsque l'on charge un PDF dans l'IFRAME car le onload n'est pas appele. */	
		var iframe = window.frames[id];
		if (iframe && iframe.location && iframe.location.href) {
			var reg = ".pdf";
			var s = iframe.location.href;
			if (s.indexOf("?") != -1) {
				s = s.substr(0, s.indexOf("?"));
			}
			if (s != oldHref) { // le chargement de l'iframe est termine
				if (s.length >= reg.length && s.substr(s.length - reg.length) == reg) {
					// si on charge un pdf
					DYNIFS.resize(id);
				}
				clearTimeout(DYNIFS.timerID);
				DYNIFS.timerID = 0;
			} else { // le chargement de l'iframe n'est pas termine
				clearTimeout(DYNIFS.timerID);
				DYNIFS.timerID = 0;
				DYNIFS.timerID = setTimeout("DYNIFS.resize_def('" + id + "', '" + oldHref + "');", 200);
			}
		}
	}
};


//Bookmark function works on IE, FF & Opera as well
function createBookmarkLink(url, title) {
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return window.sidebar.addPanel(title, url, "");
		} else if( window.external ) { // IE Favorite
			return window.external.AddFavorite( url, title); 
		} else if(window.opera && window.print) { // Opera Hotlist
			return true; 
		}
	} catch(err) {
		// do nothing
	}
	alert('Vous devez ajouter manuellement un favori pour revenir à cette page.');
}

function writeBookmarkLink(title, url) {
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return document.write('&nbsp;|&nbsp;<a href="javascript:createBookmarkLink(\'' + url + '\', \'' + title + '\')");" class="footer">Ajouter aux favoris</a>'); 
		} else if (window.external) { // IE Favorite
			return document.write('&nbsp;|&nbsp;<a href="javascript:createBookmarkLink(\'' + url + '\', \'' + title + '\')");" class="footer">Ajouter aux favoris</a>'); 
		} else if (window.opera && window.print) { // Opera Hotlist
			return document.write('&nbsp;|&nbsp;<a rel="sidebar" href="' + url + '" title="' + title + '" class="footer">Ajouter aux favoris</a>');
		} 
	} catch(err) {
		// do nothing
	}
}


// Fonctions pour les bornes
// Fonction d'ajout et de suppresion de chiffre pour les pages de signatures des bornes	
function afficheChiffre(num,formInst,champ,maxLength) {
	
	numAlloc = document.forms[formInst].elements[champ]
	if (numAlloc.value.length < maxLength)
	 	document.forms[formInst].elements[champ].value = numAlloc.value + num
}

	
function supprimeChiffre(formInst,champ) { 
	
	var numAlloc = document.forms[formInst].elements[champ].value;
	if (numAlloc.length > 0)
	 	document.forms[formInst].elements[champ].value = numAlloc.substring(0,numAlloc.length-1);
}
// Fonctions pour changer d'images
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function changeImage(imageField, imageNameNew)
{
	document[imageField].src = imageNameNew;
}

////////////////////////////////////////////////////////////////////////////
//
//Fonction permettant de désactiver certains champs d'un form si le checkbox est cochée
//
////////////////////////////////////////////////////////////////////////////

function changeCheckBoxValue(formulaire,checkBoxElement,listOfIds)
{
	var o = formulaire.elements[checkBoxElement];
	if (o.checked)
		enable(formulaire,listOfIds, false);
	else
		enable(formulaire,listOfIds, true);
}
////////////////////////////////////////////////////////////////////////////
//Fonction permettant de switcher de "enabled" en "disabled" les objets passés en entrée
//Exemple : enable(formulaire,'BtBloc1,BtBloc2', true);
//Exemple : enable(formulaire,'BtBloc1,BtBloc2', false);
//
//Parametres:
//	- listOfIds : Liste d'identifiant a switcher séparé par des ',' et prefixé par '+' ou '-'
////////////////////////////////////////////////////////////////////////////
function enable(formulaire,listOfIds, enable)
{
	var tb = new Array();// Tableau a Disabler
	parseList(listOfIds, tb);// Maj des Tableaux
	setDisabled(formulaire, tb, !enable);// Disable
}
////////////////////////////////////////////////////////////////////////////
//Fonction permettant de parser une liste d'id et de les ranger dans les tableaux adequat
//
//Parametres:
//	- listOfIds : Liste d'identifiant a switcher séparé par des ',' et prefixé par '+' ou '-'
//	- tbIdUp : Tableau avec les identifiants prefixés par '+'
//	- tbIdDown : Tableau avec les identifiants prefixés par '-'
////////////////////////////////////////////////////////////////////////////
function parseList(listOfIds, tb){
	var idTokens = listOfIds.split(",");// Tableau d'identifiant
	// On separe les identifiants prefixés par + et -
	for (i=0;i<idTokens.length;i++){
		tb[i]=idTokens[i]; 		//il n'y a que l'id
	}
}
////////////////////////////////////////////////////////////////////////////
//Fonction permettant de mettre a jour l'attribut "disable" dans 
// une liste d'id de composant HTML (Input, BUTTON, TEXTAREA et SELECT)
//Si le composant est un noeud TABLE, DIV, TR ou TD, on "disable" tous les composants
//a l'interieur de ce noeud
//
//Parametres:
//	- tbId : Liste d'identifiant a "disabler"
//	- valeur : true ou false
////////////////////////////////////////////////////////////////////////////
var contextLocation=window.location.pathname.substring(1); // /WEBAPP/Action.do
var contextPath = "/" + contextLocation.substring(0,contextLocation.indexOf('/')+1);// /WEBAPP/
var IMG_PATH		= contextPath+"images/"; // Path du repertoire des images

function setDisabled(formulaire, tbId, valeur)
{	// Parcours du tableau d'identifiant
	for (i=0;i<tbId.length;i++){
		var o = formulaire.elements[tbId[i]];

		if (o.tagName=="DIV" || o.tagName=="TABLE" || o.tagName=="TR" || o.tagName=="TD") {// Type de Noeud ou il faut parcourir son contenu
			var tbElements=getInputChild(o);// Recuperation d'une liste de noeud composant le contenu du Noeud Pere
			for (j=0;j<tbElements.length;j++) {
			   tbElements[j].disabled=valeur;
			}
		} else {
			if (o != null) {
				o.disabled=valeur;
				//cas du champ date
				if(isCnafDate(o)){
					var imgCalendrier = o.nextSibling.firstChild;
					if (valeur){
						imgCalendrier.src = IMG_PATH+"calendarDisabled.gif";
					}else{
						imgCalendrier.src = IMG_PATH+"calendar.gif";
					}
				}
			}
		}
	}
}


///////////////////////////////////////////////////////////////////////////////
//detecte si le noeud est un champ date
//
//Parametre:
//	- champ : Noeud HTML à tester
///////////////////////////////////////////////////////////////////////////////
function isCnafDate(champ){
	var nextChamp = champ.nextSibling;
	if(nextChamp!=null && nextChamp.tagName=="SPAN" && nextChamp.childNodes.length==1 && nextChamp.firstChild.id=='FrmwkCalendrier'){
		return true;
	}
	return false;
}

////////////////////////////////////////////////////////////////////////////
//Fonction permettant de parcourir le contenu d'un Noeud pour recuperer dans une liste 
//tous les Noeuds de type Input, BUTTON, TEXTAREA et SELECT.
//
//Parametres:
//	- node : Noeud HTML
////////////////////////////////////////////////////////////////////////////
function getInputChild(node){
	var tbElements = new Array();
	ajouterElements(tbElements, node.getElementsByTagName("INPUT"));
	ajouterElements(tbElements, node.getElementsByTagName("BUTTON"));
	ajouterElements(tbElements, node.getElementsByTagName("TEXTAREA"));
	ajouterElements(tbElements, node.getElementsByTagName("SELECT"));
	return tbElements;
}

