// ====== COPYRIGHT EVENIUM, 2001 - ALL RIGHTS RESERVED ======

//===== Détection de navigateur ===== Navig = "IE" | "N4" | "N6" | "W3"
navig = "W3";
navigVersion = 5.5;
// ++
function detectNavig()
{
 idxMSIE = navigator.userAgent.indexOf("MSIE");
 if (idxMSIE >= 0 || navigator.appName.indexOf("Microsoft") >= 0) 
 { 
   navig = "IE"; 
   navigVersion=parseFloat(navigator.userAgent.substring(idxMSIE+5, idxMSIE+8));
 }
 else if (navigator.appName.indexOf("etscape") >= 0)
 { 
   navigVersion = parseFloat(navigator.appVersion); 
   if ( navigVersion >= 5) navig="N6"; else navig="N4"; 
 }
 return;
}
detectNavig();  // Detect the navigator NOW


function detectNavig2() 
{
	var idxMSIE = navigator.userAgent.indexOf("MSIE");
	var navig = "";
	var navigVersion = 0;
	if (idxMSIE >= 0 || navigator.appName.indexOf("Microsoft") >= 0) { 
  	   navig = "IE"; 
		navigVersion = parseFloat(navigator.userAgent.substring(idxMSIE+5, idxMSIE+8));
	} else if (navigator.userAgent.indexOf("Firefox") >= 0) {
		var idx = navigator.userAgent.indexOf("Firefox");
		navig = "Firefox";
		navigVersion = parseFloat(navigator.userAgent.substring(idx+8, idx+9));
	} else { 
		navig = "W3";
		navigVersion = parseFloat(navigator.appVersion); 
	}
	return new Array(navig, navigVersion);
}

function canUseDojo() {
	var navigInfo = detectNavig2();
	var navig = navigInfo[0];
	var navigVersion = navigInfo[1];
	return ((navig == "IE" && navigVersion >= 6)
			|| (navig == "Firefox" && navigVersion >= 2));
}

function isset(variableName) {
	try {
		if (typeof(eval(variableName)) != 'undefined') {
			if (eval(variableName) != null) {
				return true;
			}
		}
	} catch(e) { }
	return false;
}

//===== Ouverture de pop-ups =====
function OpenWindow(theURL, wd, hg) 
{
  var url = encodeUrl(theURL,true);
  var ppp = window.open(url,"popup","width="+wd+",height="+hg+",scrollbars=1,resizable=1");
  ppp.focus(); if (ppp.setActive) ppp.setActive();
  // return ppp;   // Désactivé pour l'instant pour raison de code pourri dans le profile !!!!!!!!!!!!!
}
//===== Ouverture de pop-ups =====
function OpenWindowNg(theURL, wd, hg) 
{
  var url = encodeUrlNg(theURL,true);
  var ppp = window.open(url,"popup","width="+wd+",height="+hg+",scrollbars=1,resizable=1");
  ppp.focus(); if (ppp.setActive) ppp.setActive();
  // return ppp;   // Désactivé pour l'instant pour raison de code pourri dans le profile !!!!!!!!!!!!!
}
function OpenWindowStatus(theURL, wd, hg) 
{ 
  var url = encodeUrl(theURL,true);
  var ppp = window.open(url,"popup","width="+wd+",height="+hg+",scrollbars=1,resizable=1,status=1");
  ppp.focus(); if (ppp.setActive) ppp.setActive();
  return ppp;
}
function OpenNamedWindow(theURL, wd, hg, name) 
{
  var url = encodeUrl(theURL,true);
  var ppp = window.open(url,name,"width="+wd+",height="+hg+",scrollbars=1,resizable=1");
  ppp.focus(); if (ppp.setActive) ppp.setActive();
  return ppp;
}
function OpenNamedWindowStatus(theURL, wd, hg, name) 
{ 
  var url = encodeUrl(theURL,true);
  var ppp = window.open(url,name,"width="+wd+",height="+hg+",scrollbars=1,resizable=1,status=1");
  ppp.focus(); if (ppp.setActive) ppp.setActive();
  return ppp;
}

function OpenEncodedWindow(theURL, wd, hg, name) 
{
  if (!name) name="popup";
  OpenNamedWindow(theURL, wd, hg, name);
}
function OpenEncodedWindowStatus(theURL, wd, hg, name) 
{ 
  if (!name) name="popup";
  OpenNamedWindowStatus(theURL, wd, hg, name);
}

//===== Fermeture de pop-ups ! =====
function reloadOpener() {
	if (top && top.opener && top.opener.window && top.opener.window.customReloadPage) {
    top.opener.window.customReloadPage();
  } else if (parent && parent.window && parent.window.customReloadPage) {
    parent.window.customReloadPage();
  } else if (top && top.opener && top.opener.window && top.opener.window.reloadPage) {
    top.opener.window.reloadPage();
  } else if (parent && parent.window && parent.window.reloadPage) {
    parent.window.reloadPage();
  } else if (top && top.opener && top.opener.window && top.opener.window.location.reload) {
    top.opener.window.location.reload();
  } else if (parent && parent.window && parent.window.location.reload) {
    parent.window.location.reload();
  }  
}

function reloadOpenerThenClose()
{
	
	if (top && top.opener && top.opener.window && top.opener.window.customReloadPage)
		top.opener.window.customReloadPage();
	else if (parent && parent.window && parent.window.customReloadPage)
		parent.window.customReloadPage();
	else if (top && top.opener && top.opener.window && top.opener.window.reloadPage)
		top.opener.window.reloadPage();
	else if (parent && parent.window && parent.window.reloadPage)
		parent.window.reloadPage();
	/** reload NG page */
	else if (top && top.opener && top.opener.document && top.opener.document.conversationParameter)
	{
		
		var openerCID = top.opener.document.conversationParameter;
		var openerOnCloseAction = top.opener.document.onCloseAction;
		var openerLocation = top.opener.location;
		
		var newOpenerLocation = openerLocation.href;
		
		if (!newOpenerLocation.match(openerCID))
			newOpenerLocation = insertParameter(newOpenerLocation, openerCID);
		
		if (openerOnCloseAction)
			newOpenerLocation = insertParameter(newOpenerLocation, openerOnCloseAction);
		
		openerLocation.replace(newOpenerLocation);
		
		top.opener.document.conversationParameter = null;
		top.opener.document.onCloseAction = null;
		
	}	
		
	window.close();
}

function insertParameter(url, param)
{
	var idxA   = url.indexOf("#");
	var idxQ   = url.indexOf("?");
	
	if (idxQ >= 0 && idxA < 0)
		return url + "&" + param;
	else if (idxQ >= 0 && idxA >= 0)
		return url.substring(0, idxA) + "&" + param + url.substring(idxA);
	else if (idxQ < 0 && idxA >= 0)
		return url.substring(0, idxA) + "?" + param + url.substring(idxA);
	else
		return url + "?" + param;
	 	  
}

//===== Layers =====
function Div(ii,x,y,z,on,w,h, extraParams)
{
 if(navig!="N4") {
  document.write('<div id="',ii,'" style="position:absolute; left:',x,'; top:',y,
   '; z-index:',z,'; visibility:', (on!=0 ? "visible" : "hidden"),';',
    (w>0?("width:"+w+";"):""),(h>0?("height:"+h+";"):""), (extraParams?extraParams:""),
   '">');
 } else {
  document.write('<LAYER id="',ii,'" pageX="',x,'" pageY="',y,'" z-index="',z,
    '" visibility="', (on!=0 ? "show" : "hide"),'">');
 }
}
function EndDiv() {
  document.write((navig!="N4")? '</div>': '</layer>');
}

// ++ WARNING: Set alternatively to on and off
function ToggleDisplay(eltId, inlin)
{
  if (navig=="N4") return;
  var elt = getElement(eltId);
  if (elt)
  {
    elt.style.display = ( elt.style.display=='none' ? (inlin ? 'inline' : 'block') : 'none' );
  }
  return;
}

// ++ WARNING: Set alternatively to on and off on row table
function toggleTrDisplay(eltId) {
	if (navig == "IE") {
		ToggleDisplay(eltId);
	} else {
		var elt = getElement(eltId);
		if (elt) {
			elt.style.display = ( elt.style.display=='none' ? 'table-row' : 'none' );
		}
	}
}

function toggleTrDisplayByName(name) {
	var elem = document.getElementsByTagName('tr');
	if (elem) {
		var display = null;
		for (var k = 0; k < elem.length; k++) {
			if (elem[k].getAttribute("name") == name) {
				if (display == null) {
					display = 'none';
					// get current display of first TR only to define the new display
					if (elem[k].style.display == 'none') {
						display = navig == "IE" ? 'block' : 'table-row';
					}
				}
				elem[k].style.display = display;
			}
		}
	}
}

// ++ WARNING: Set alternatively to on and off on cell table
function toggleTdDisplay(eltId) {
	if (navig=="IE") {
		ToggleDisplay(eltId);
	} else {
		var elt = getElement(eltId);
		if (elt) {
			elt.style.display = ( elt.style.display=='none' ? 'table-cell' : 'none' );
		}
	}
}

function swVisibility(eltId, val)
{
  if (navig=="N4") return;
  var elt = getElement(eltId);
  if (elt)
   elt.style.visibility = (val ? "visible" : "hidden");
  return;
}
function ToggleVisibility(eltId)
{
  if (navig=="N4") return;
  var elt = getElement(eltId);
  if (elt)
  {
    elt.style.visibility = ( elt.style.visibility=='hidden' ? 'visible' : 'hidden' );
  }
  return;
}


// ++ This set to the desired value. If not "inline" or "block", then it's none 
function swDisplay(eltId, val)
{
  if (navig=="N4") return;
  var elt = getElement(eltId);
  if (elt)
   elt.style.display = ((val=="inline" || val=="block") ? val : "none");
  return;
}

// ++ This set to the desired value to tr / th (in table). If not "table-row" or "block", then it's none 
function swTrDisplay(eltId, val)
{
  if (navig=="IE") {
  	// ???????????????????????????
   swTrDisplay(eltId, val)
  } else {
    var elt = getElement(eltId);
  	 if (elt)
   	elt.style.display = ((val=="table-row" || val=="block") ? val : "none");
  	 return;
  }
}


// ++ This set to the desired value to td (in table). If not "table-cell" or "block", then it's none 
function swTdDisplay(eltId, val)
{
  if (navig=="IE") {
   swTrDisplay(eltId, val)
  } else {
    var elt = getElement(eltId);
  	 if (elt)
   	elt.style.display = ((val=="table-cell" || val=="block") ? val : "none");
  	 return;
  }
}


function TogOnOff(ii,on) // Evite que deux RollOvers existent à cause des onMouseOut non captés
{
  if (navig == "IE") {
   if (document.all[ii]) 
     document.all[ii].style.visibility = (on ? 'visible' : 'hidden');
  } else if (navig == "N4") {
   if (document.layers[ii]) 
     document.layers[ii].visibility = (on ? 'show' : 'hide');
  } else {
    if (document.getElementById(ii)) 
     document.getElementById(ii).style.visibility = (on ? 'visible' : 'hidden');
  }
}
function TogOnOffFixedPos(ii,on, posX,posY)
{
 if (!on) { TogOnOff(ii,0); return; }
 // --- Repositionnement en haut à gauche (posX,posY)
 moveDiv(ii,posX,posY);
 TogOnOff(ii,1);
}

function moveDiv(ii,posX,posY)
{
 // --- Repositionnement en haut à gauche (posX,posY), scrolling compris : with AUTO FIXED POS !
 if (document.layers)   // N4
  { var dv = document.layers[ii];
    dv.pageX = posX + window.pageXOffset;
    dv.pageY = posY + window.pageYOffset; }
 else if (document.documentElement && document.documentElement.scrollTop)
 {  var dv = document.getElementById(ii);
    dv.style.left = posX + document.documentElement.scrollLeft + "px";
    dv.style.top  = posY + document.documentElement.scrollTop  + "px"; }
 else if (document.body)  // IE5
 {  var dv = (document.all ? document.all[ii] : document.getElementById(ii));
    dv.style.left = posX + document.body.scrollLeft + "px";
    dv.style.top  = posY + document.body.scrollTop  + "px"; }
}

function truncatePos(requiredCoord, requiredDim, minCoord, maxCoord)
{
//    alert('req:'+requiredCoord+' dim:'+requiredDim+' min:'+minCoord+' max:'+maxCoord);
  if (requiredCoord+requiredDim>maxCoord)
    return Math.max(minCoord,maxCoord-requiredDim);
  else if (requiredCoord<minCoord)
    return minCoord;
  else
    return requiredCoord;
}

//récupère l'élément de nom elt
function getElement(elt) 
{
 if (document.getElementById)
   return document.getElementById(elt);
 else if (document.all)
   return document.all[elt];
 else if (document.layers)   // N4
  return document.layers[elt]; 
 return null;
}


//===== Frames =====
function FrSet(rocol) 
{
  document.write('<frameset ', rocol, ' border="0" framespacing="0" frameborder="NO">');
}
function FrEnd() {
  document.write('</frameset>');
}
function Frm(src,nam,scrl) 
{
  if(navig=="N4" && src.lastIndexOf(".gif") > 0) 
  {
    src = "/pro/graphics/encapsule.htm?bg=" + src;
  }
  document.write( '<frame src="', src, '" name="', nam, '"  scrolling="', scrl,
                   '" noresize marginwidth="0" marginheight="0" frameborder="NO">');
}

//===== get Parameters in JScript ! =====
function getParam(nam,defaut)
{
 var urlVal = window.location.toString();
 s = urlVal.lastIndexOf("?"+nam+"=");
 if (s<=0)  
  s = urlVal.lastIndexOf("&"+nam+"=");
 if (s>0)
 {
  t = urlVal.lastIndexOf("&");
  if (s > t) return unescape( urlVal.substring(s+nam.length+2) );
  else return unescape(urlVal.substring(s+nam.length+2, t) );
 }
 else return defaut;
}

//===== Rollovers =====
// WARNING: Numbers id of rollovers MUST BE CONTIGUOUS and from 1 to the max
maxRoll=0;   // Nombre exact de RollOvers, de 1 à maxRoll --%>
function SwOnOff(ii,on) // Evite que deux RollOvers existent à cause des onMouseOut non captés
{
  if (navig == "IE") {
    for(var i=1; i<= maxRoll; i++)  
      { tmp=document.all["ov"+i]; if (tmp) tmp.style.visibility = 'hidden'; }
    if (on) document.all["ov"+ii].style.visibility = 'visible';
  } else if (navig == "N4") {
    for(var i=1; i<= maxRoll; i++)  
      { tmp=document.layers["ov"+i]; if (tmp) tmp.visibility = 'hide'; }
    if (on) document.layers["ov"+ii].visibility = 'show';
  } else {
    for(var i=1; i<= maxRoll; i++)  
      { tmp=document.getElementById("ov"+i); if (tmp) tmp.style.visibility = 'hidden'; }
    if (on) document.getElementById("ov"+ii).style.visibility = 'visible';
  }
}
function AddRollOver(ii,x,y,z,imgsrc,urldest,targ)
{
  if (ii>maxRoll) maxRoll=ii;
  Div("ov"+ii,x,y,5,0);
  document.write('<a href="', urldest,'" onMouseOut="SwOnOff(',ii,',false)"',
   'target="',targ,'"><img src="', imgsrc,'" border="0"></a>');
  EndDiv();
}


var jsessionid;
var jsessionId;
var jSessionId;
var JSessionId;
var JSESSIONID;
var TWO_POWER_26_MINUS_ONE = ((1 << 26) - 1);
//===== Url encoding. You may not pass disableNoCache  =====
function encodeUrl(url, disableNoCache)
{
 // look for a variable named jsessionid (mostly case insensitive)
 if (! jsessionid)
 {
  if (jsessionId)
    jsessionid=jsessionId;
  else if (jSessionId)
    jsessionid=jSessionId;
  else if (JSessionId)
    jsessionid=JSessionId;
  else if (JSESSIONID)
    jsessionid=JSESSIONID;
 }
// alert('jsessionid: '+jsessionid);

  if (! jsessionid)
    return url;
  
  url = url.trim();
  // -- Pas d'encoding si javascript ou si ca ne finit pas par .jsp et que pas servlet CMS
  var urlLength = url.length;
    
  // if ( startsWith(url, "javascript:") || endsWith(url, ".htm") || endsWith(url, ".html") )
  if ( startsWith(url, "javascript:") || 
       !( endsWith(url, ".jsp") || url.indexOf(".jsp?")>=0 || url.indexOf(".jsp#")>=0 || url.indexOf("/mc/")>=0 || url.indexOf("/mctest/")>=0 ) )
    return url;
  // -- Pas d'encoding si déjà encodé (jsession avant '?' ou '#' si applicable)  
  var idxJId = url.indexOf("jsessionid=");
  var tmpS   = url.indexOf("#");
  var idxQ   = url.indexOf("?");
  var split  = idxQ;
  if (tmpS >= 0 && (idxQ < 0 || tmpS < idxQ))     // split doit contenir l'index du premier de '#' et '?'
    split = tmpS;
  if ( idxJId > 0 && (split < 0 || idxJId < split) )
    return url;
  // -- return response.encodeURL(url);
  nowMillis = ( disableNoCache ? "" 
              : (idxQ < 0 ? "?_TIM_=eb" : "&_TIM_=eb") + ( (new Date()).getTime() & TWO_POWER_26_MINUS_ONE ) );
  if ( split < 0 )
    return url + ";jsessionid=" + jsessionid + nowMillis;
  return url.substring(0, split) + ";jsessionid=" + jsessionid + url.substring(split, url.length) + nowMillis;
}

var ngsessionid;
var ngeventid;
function encodeUrlNg(url, disableNoCache)
{
  if (! ngsessionid)
    return url;
  
  url = url.trim();
  // -- Pas d'encoding si javascript ou si ca ne finit pas par .jsp et que pas servlet CMS
  var urlLength = url.length;
    
  // if ( startsWith(url, "javascript:") || endsWith(url, ".htm") || endsWith(url, ".html") )
  if ( startsWith(url, "javascript:") || 
       !( endsWith(url, ".jsp") || url.indexOf(".jsp?")>=0 || url.indexOf(".jsp#")>=0 || url.indexOf("/mc/")>=0  || url.indexOf("/mctest/")>=0 || url.indexOf("/ng/")>=0 ) )
    return url;
  // -- Pas d'encoding si déjà encodé (jsession avant '?' ou '#' si applicable)  
  var idxJId = url.indexOf("jsessionid=");
  var tmpS   = url.indexOf("#");
  var idxQ   = url.indexOf("?");
  var split  = idxQ;
  if (tmpS >= 0 && (idxQ < 0 || tmpS < idxQ))     // split doit contenir l'index du premier de '#' et '?'
    split = tmpS;
  if ( idxJId > 0 && (split < 0 || idxJId < split) )
    return url;
  // -- return response.encodeURL(url);
  nowMillis = ( disableNoCache ? "" 
              : (idxQ < 0 ? "?_TIM_=eb" : "&_TIM_=eb") + ( (new Date()).getTime() & TWO_POWER_26_MINUS_ONE ) );
  var eventIdString;
  if (! ngeventid || (url.indexOf("&eventId=") >=0) || (url.indexOf("?eventId=") >=0) ) {
		eventIdString=""
  } else {
		eventIdString = (nowMillis == "" && idxQ < 0 ? "?" : "&") + "eventId=" + ngeventid;
  }
  if ( split < 0 )
    return url + ";jsessionid=" + ngsessionid + nowMillis + eventIdString;
  return url.substring(0, split) + ";jsessionid=" + ngsessionid + url.substring(split, url.length) + nowMillis + eventIdString;
}



//===== HTML encoding  =====
function escapeHtmlString( text )
{
	if ( typeof( text ) != "string" )
		text = text.toString() ;
  if (! text) return "";
	text = text.replace(/&/g, "&amp;");
	text = text.replace(/"/g, "&quot;");
	text = text.replace(/</g, "&lt;");
	text = text.replace(/>/g, "&gt;");
	text = text.replace(/'/g, "&#39;"); //" 
	return text;
}


//===== String manipulations  =====

// A slick tip from Eric Lippert
String.prototype.ltrim = function () { return this.replace(/^ */,""); }
String.prototype.rtrim = function () { return this.replace(/ *$/,""); }
String.prototype.trim  = function () { return this.ltrim().rtrim(); }

    
// ++ Cette fonction renvoie true si la chaîne est vide ou est une suite d'espaces
function isEmptyTrimmed(chaine) 
{
 return ( chaine==null || chaine.search(/^[ ]*$/) >=0 );
}

function replaceEmpty(chaine, replaceEmpty) {
	return isEmptyTrimmed(chaine) ? replaceEmpty : chaine;
}


function startsWith(theString, startString)
{
// alert ('startswith('+theString+', '+startString+') lengths:'+theString.length+', '+startString.length);
// alert (''+(theString.substring(0,startString.length)==startString));
  if (!isEmptyTrimmed(startString) && !isEmptyTrimmed(theString) && (theString.length >= startString.length))
    return theString.substring(0,startString.length)==startString;
  else
    return false;
}
function endsWith(theString, endString)
{
// alert ('endswith('+theString+', '+endString+') lengths:'+theString.length+', '+endString.length);
// alert (''+(theString.substring(theString.length-endString.length,theString.length)==endString));
  if (!isEmptyTrimmed(endString) && !isEmptyTrimmed(theString) && (theString.length >= endString.length))
    return theString.substring(theString.length-endString.length,theString.length)==endString;
  else
    return false;
}

function bodyWidth()
{
  if (document.body.clientWidth)
    return document.body.clientWidth;
  else
    return window.innerWidth-16;  // Netscape
}
 
function bodyHeight()
{
  if (document.body.clientHeight)
    return document.body.clientHeight;
  else
    return window.innerHeight-16;  // Netscape
}

function goToAnchor(anchorName)
{
  if (anchorName.length>0)
    document.location.hash=anchorName;
}


/**
  * used to change an iFrame's src
  * this method should be put in the "onload" part of an iframe tag
  */
function setIFrameSrc(item, frameId, url, noresize, limitSize)
{
  if (!item && frameId)
    item = document.all ? window.frames[frameId] : getElement(frameId);
  if (!item)
    return;

  // change IFrame src if necessary, resize only if the src doesn't change
  if (url)
  {
    var oldUrl = item.src;
    var newUrl = encodeUrl(url);
    // check if old and new Url are the same
    var cleanOldUrl = cleanUpUrl(oldUrl);
    var cleanNewUrl = cleanUpUrl(newUrl);
//    alert('changing Url: \n'+cleanOldUrl+'\n'+cleanNewUrl+'\n->'+(cleanOldUrl!=cleanNewUrl));
    if (cleanOldUrl!=cleanNewUrl)
    {
//      alert('changing Url: now');
      item.src = newUrl;
    }
    else if (!noresize)
    { // url has not changed, resize now!
//      alert('resizing '+item.src);
      if (
           !item
        || !item.style 
    //    || !item.style.heigh 
    //    || !item.style.width
        || (document.all && (!item.document || !item.document.body || !item.document.body.scrollHeight || !item.document.body.scrollWidth) )
        || (!document.all && (!item.contentDocument || !item.contentDocument.body || !item.contentDocument.body.scrollHeight || !item.contentDocument.body.scrollWidth) )
        )
      {
    //    alert('frame not loaded:'
    //    +'\n!item '+(!item)
    //    +'\n!item.style '+(!item.style )
    //    );
        return; // frame not properly loaded
      }
      item.style.height = 180;
      item.style.width  = 180;
      maxWidth          = bodyWidth()-12;
      maxHeight         = bodyHeight()-10;
    
      //the_height = 30 + window.frames[frameId].document.body.scrollHeight; //find the height of the internal page
      var szfBody = (document.all ? window.frames[frameId].document.body 
                                  : getElement(frameId).contentDocument.body);
      the_height = 10 + szfBody.scrollHeight; //find the height of the internal page
      if (the_height > maxHeight && limitSize)
        if (50 > maxHeight )
          the_height = maxHeight;
        else
          the_height = maxHeight-50;
      the_width = 30 + szfBody.scrollWidth; //find the width of the internal page
      if (the_width > maxWidth && limitSize)
        if (50 > maxWidth)
          the_width = maxWidth;
        else
          the_width = maxWidth - 50;
      item.style.height = the_height;
      item.style.width  = the_width;
      // alert("posFilterX="+posFilterX + " , the_width="+the_width + " , maxWidth="+maxWidth );
    //  moveDiv('filterStat', truncatePos(posFilterX, the_width, 0, maxWidth), truncatePos(posFilterY, the_height, 0, maxHeight));
      //alert("X="+truncatePos(posFilterX, the_width, 0, maxWidth)+", Y="+truncatePos(posFilterY, the_height, 0, maxHeight) );
    }
  }
}
/**
  * Removes sessionId and extra evenium parameters from Url
  */
function cleanUpUrl(url)
{
  var resultUrl   = url;
  // remove sessionId
  var indexStart  = resultUrl.toLowerCase().indexOf('jsessionid');
  var indexEnd    = resultUrl.toLowerCase().indexOf('?', (indexStart>=0)?indexStart:0);
  if (indexStart>=0)
    resultUrl   = (indexStart>=0)?resultUrl.substring(0,indexStart):resultUrl+(indexEnd>=0)?resultUrl.substring(indexEnd+1):'';

  indexStart      = url.toLowerCase().indexOf('_TIM_');
  if (indexStart>=0)
  {
    indexEnd    = resultUrl.toLowerCase().indexOf('&', (indexStart>=0)?indexStart:0);
    resultUrl   = (indexStart>=0)?resultUrl.substring(0,indexStart):resultUrl+(indexEnd>=0)?resultUrl.substring(indexEnd+1):'';
  }
  indexStart      = resultUrl.toLowerCase().indexOf('&_TIM_');
  while (indexStart>=0)
  {
    indexEnd    = url.toLowerCase().indexOf('&', (indexStart>=0)?indexStart:0);
    resultUrl   = (indexStart>=0)?resultUrl.substring(0,indexStart):resultUrl+(indexEnd>=0)?resultUrl.substring(indexEnd+1):'';
    indexStart  = resultUrl.toLowerCase().indexOf('&_TIM_');
  }
//  alert('cleaned up '+url+ ' is '+resultUrl);
  return resultUrl;
}

// prints a form elemnt identified by its id, the form must have an input named "content"
// TODO: debug!!!
function printFormElement(frm, elementId, contentInputName, height)
{
  var element = getElement(elementId);
  if (isEmptyTrimmed(contentInputName))
    contentInputName = 'content';
  var contentInput = frm?frm.elements[contentInputName]:null;
  if (contentInput && element)
  {
    if (height <= 0)
      height = 650;
    oldTarget   = frm.target;
    oldAction   = frm.action;
    oldContent  = contentInput.value;
  
    ppp=window.open('/pro/common/wait.htm','_printSurveyElementPopup','width='+element.width+',height='+height+',scrollbars=1,resizable=1');
    ppp.focus();
    if (ppp.setActive) ppp.setActive();

    frm.action = encodeUrl('/pro/common/show.jsp?contentParam='+contentInputName);
    contentInput.value = '<body onload=\'window.print()\'>'+element.outerHTML+'</body>';
    frm.target = '_printSurveyElementPopup';
    frm.submit();
  
    frm.target = oldTarget ;
    frm.action = oldAction ;
    contentInput.value = oldContent ;
  }
  else 
  {
    if (!contentInput)
      alert('no contentInput with name '+contentInputName);
    if (!element)
      alert('no element found with id '+elementId);
  }
}

function reloadPageScroll()
{
  if (document.reloadForm)
  {
    if (document.reloadForm._scrollX)
      document.reloadForm._scrollX.value=(document.getElementById && !document.all)? window.pageXOffset : document.body.scrollLeft;
    if (document.reloadForm._scrollY)
      document.reloadForm._scrollY.value=(document.getElementById && !document.all)? window.pageYOffset : document.body.scrollTop;
//alert('moz: '+(document.getElementById && !document.all)+'X:'+document.reloadForm._scrollX.value+' Y: '+document.reloadForm._scrollY.value);
    document.reloadForm.submit();
    return true;
  }
  return false;
}
function onPageReloadScroll(scrollX, scrollY)
{
  if (window.scrollTo)
    window.scrollTo(scrollX,scrollY);
}

var blinkTimerId;
var blinkingList = new Array();
function addBlinking(eltId, period, inline)
{
  blinkingList[blinkingList.length] = eltId;
  // default period
  if (!period || period <=0)
    period = 500;
  // avoid undefined issues
  if (!inline)
    inline = false;

  blinkAll(false, period, inline)
}
function removeBlinking(eltId, hide)
{
  for (idx in blinkingList)
    if (blinkingList[idx] == eltId)
      blinkingList.splice(idx, 1);

  TogOnOff(eltId, !hide);
}
function setBlinking(period, stop )
{
  if (blinkTimerId)
    clearTimeout(blinkTimerId);
  if (!stop)
    blinkAll(false, period);
}
function blinkAll(show, period)
{
  if (blinkTimerId)
    clearTimeout(blinkTimerId);
  for (idx in blinkingList)
    TogOnOff(blinkingList[idx], show);
  var timerCall = "blinkAll("+(!show)+", "+period+")";
  blinkTimerId = setTimeout(timerCall, period);
}

/**
 * Return an array of
 *  0 => Days
 *  1 => Hours
 *  2 => Minutes
 *  3 => Seconds
 * contains in millseconds param
 */
function getDHMSFromMillisec(milliseconds) {
    
  var value = milliseconds / 1000;
  var days = 0;
  if (value >= 86400) {
    days = Math.floor(value / 86400);
  }
    
  value = value - (days*86400);
  var hours = 0;
  if (value >= 3600) {
    hours = Math.floor(value / 3600);
  }
  
  value = value - (hours*3600);
  var minutes = 0;
  if (value >= 60) {
    minutes = Math.floor(value / 60);
  }
  
  value = value - (minutes*60);
  var seconds = value;
  if (value > 0) {
    seconds = Math.floor(value);
  }

  return new Array(days, hours, minutes, seconds);
}

/**
 * Return the litteral string of size in current language
 * By example : 1.32 Mo
 *							23.1 Ko
 *							123 octets
 * NEED LANG defined by the with language
 */
function getSizeFromBytes(bytes, lge) {
	var BYTES = "bytes";
	var KB = "kB";	
	var MB = "MB";
	
	if (lge == "fr") {
		BYTES = "octets";
		KB = "Ko";
		MB = "Mo";
	}
	
	var str = "";
	if (bytes < 1000) {
		// < 1 Ko
		str = bytes+" "+BYTES;
	} else if (bytes > 1000000) {
		// > 1 Mo
		str = ""+(bytes/1000000);
		// si le nombre a des decimals, on affiche 2 décimal
		// sinon, on affiche le nombre entier (2 Mo)
		if (str.indexOf(".") > 0) {
			str = (bytes/1000000).toFixed(2);
		}
		str+= " "+MB;
	} else if (bytes > 1000) {
		// > 1 Ko
		str = ""+(bytes/1000);
		// si le nombre a des decimals, on affiche 1 décimal
		// sinon, on affiche le nombre entier (10 Ko)		
		if (str.indexOf(".") > 0) {
			str = (bytes/1000).toFixed(1);
		}
		str+= " "+KB;
	}

	if (lge == "fr") {
		str = str.replace("\.", ",");
	}
	return str;
}

function expand(divId, expandId) {
  var disp = "none";
  var inner = "+";
  if (document.getElementById(divId).style.display == "none") {
    disp = "block";
    inner = "-";
  }
  document.getElementById(divId).style.display = disp;
  document.getElementById(expandId).innerHTML = inner;
}

function getElementsByName_iefix(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var array = new Array();
	for(var k = 0; k < elem.length; k++) {
		if(elem[k].getAttribute("name") == name) {
			array.push(elem[k]);
		}
	}
	return array;
}

function showOverlay(id) {
	document.getElementById(id).style.display = 'block';
   /* PATCH IF IE < 7 FOR SELECT BOX */ 
   if ( (navig == 'Microsoft Internet Explorer') && (navigVersion >= 4) && (navigVersion <= 6) )  {
   	for (i = 0; i < document.getElementsByTagName('select').length; i++) {
      	document.getElementsByTagName('select')[i].style.display='none';
		}
	}
}

function hideOverlay(id) {
	document.getElementById(id).style.display = "none";
   /* PATCH IF IE < 7 FOR SELECT BOX */ 
   if ( (navig == 'Microsoft Internet Explorer') && (navigVersion >= 4) && (navigVersion <= 6) )  {
   	for (i = 0; i < document.getElementsByTagName('select').length; i++) {
      	document.getElementsByTagName('select')[i].style.display='inline';
		}
	}
}

function tooltip(val, maxLength) {
	if (!val) {
		return;
	}
	if (! maxLength) {
		maxLength = 10;
	}
	if (val.length <= 0) {
		document.write('&nbsp;');
	} else if (val.length <= maxLength) {
		document.write(val);
	} else {
		var title = val;
		title = title.replace(/"/g, '&quot;');
		title = title.replace(/'/g, "\\'");
		title = title.replace(/\r\n/g, "<br/>");
		title = title.replace(/\n/g, "<br/>");
    
		// var tooltip = "<div style=\\'float: left;\\'>&nbsp;</div><img onclick=\\'tt_HideInit()\\' src=\\'/pro/graphics/gp_zic/zicon/close.gif\\' style=\\'float: right;\\'/><div style=\\'float: left;\\'>" + title + "</div>";
		var sticky = title + "<br/><div style=\\'float: right; margin-top: 3px;\\'><a style=\\'font-size: 7pt; cursor: pointer;\\' onclick=\\'tt_HideInit()\\'>fermer</a></div>";
		
		var html = "<a href=\"javascript:void(0);\"";
		html+= " onclick=\"Tip('" + sticky + "', DELAY, 0, WIDTH, -240, BALLOON, true, ABOVE, true, OFFSETX, -17, FADEIN, 0, FADEOUT, 100, PADDING, 8, STICKY, true)\"";
		html+= " onmouseover=\"Tip('" + title + "', DELAY, 200, WIDTH, -240, BALLOON, true, ABOVE, true, OFFSETX, -17, FADEIN, 100, FADEOUT, 0, PADDING, 8, STICKY, false)\""; 
		html+= " onmouseout=\"UnTip()\">";
		html+= val.substring(0, maxLength) + '...</a>';
		// alert(html);
		document.write(html);
		
		/* boxover bof ...
		html = '<a title="header[] body=[' + title + '] fixedrelx=[10] fixedrely=[10] singleclickstop=[on]" href="javascript:void(0);">';
	 	html+= val.substring(0, maxLength) + '...</a>';
	 	document.write(html);*/
	}
}

function setInnerHtml(idToUse, srcToSet)	{ 
	if (document.getElementById(idToUse)) { 
		document.getElementById(idToUse).innerHTML = srcToSet;
	 } 
}