function include(fichier)
	{
	  // Si notre variable globale (rattachée à l'objet window) 
	  // n'existe pas, on la créée.
	if(window.includeFiles == undefined)
	  {
	    window.includeFiles = new Array();
	  }

	try
	  {
	    SCRIPT = document.createElement("script");
	    SCRIPT.type = "text/javascript";
	    SCRIPT.src  = fichier;
	    HEAD = document.getElementsByTagName("head");
	    HEAD[0].appendChild(SCRIPT);
	    window.includeFiles.push(fichier);
	  }
	catch(e)
	  {
	    document.write('<script type="text/javascript" src="' + fichier + '"><\/script>');
	    window.includeFiles.push(fichier);
	  }
	}

function include_once(fichier)
	{
	if(window.includeFiles == undefined)
	  {
	    window.includeFiles = new Array();
	  }
	else
	  {
	    nbr = window.includeFiles.length
	    for(i=0; i < nbr; i++)
	    {
	      if(window.includeFiles[i] == fichier)
	        return false;
	    }
	  }

	  include(fichier);
	  return true;
	}

function medPreviewError(im, ext)
	{
	stage = im.getAttribute("stage");
	if (stage)
		{
		if (stage == '1')
			{
			im.setAttribute("stage",'2');
			im.src=staticRoot+'ui/icons/ext128/_.png';
			}
		else if (stage == '2')
			{
			im.setAttribute("stage",'3');
			im.src=staticRoot+'nothumb.gif';
			}
		}
	else
		{
		im.setAttribute("stage",'1');
		im.src=staticRoot+'ui/icons/ext128/'+ext+'.png';
		}
	
	}
	
function setSize(img, newSize)
	{
    var w = img.width;
    var h = img.height;

	if (h==0 && w==0)
		{
		//img.alt += " ("+w+"x"+h+")";
		//img.alt += " ("+img.id+")";
		if (img.id)
			window.setTimeout( "document.getElementById('"+img.id+"').src='"+img.src+"';", 200 );
		else if (img.name)
			window.setTimeout( "document.images['"+img.id+"'].src='"+img.src+"';", 200 );
		return;
		}
	
//img.alt += " A("+w+"x"+h+")";
	if (img.naturalHeight)
		{
		w = img.naturalWidth;
		h = img.naturalHeight;
		}
	else
		{
		img.removeAttribute("width");
		img.removeAttribute("height");
		w = img.width;
		h = img.height;
		}
	
	//utile?
	if (h == 0) h =1;
	if (w == 0) w =1;
//img.alt += " B("+w+"x"+h+")";
	
	if (w > h)
		{
		img.width = newSize;
		img.height = newSize * h / w;
		}
	else
		{
		img.height = newSize;
		img.width = newSize * w / h;
		}
	}

function openDialog(pUrl, pWidth, pHeight, pOptions)
	{
	if (pOptions && pOptions.length > 0)
		pOptions += ",";
	else
		pOptions = "";

	var w=window.open(pUrl,"_" + pWidth + "_" + pHeight + "_",pOptions + "width=" + pWidth + ",height=" + pHeight);
	}
	
function openDialogBox(pUrl, pWidth, pHeight)
	{
	var w=window.open(pUrl,"_" + pWidth + "_" + pHeight + "_","toolbar=0,location=0,directories=0,status=yes,scrollbars=yes,menubar=0,width=" + pWidth + ",height=" + pHeight);
	}
	
function openWindow(pUrl)
	{
	var w=window.open(pUrl,"");
	}

	function str_replace (search, replace, subject, count) {
		// Replaces all occurrences of search in haystack with replace  
		// 
		// version: 908.406
		// discuss at: http://phpjs.org/functions/str_replace
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Gabriel Paderni
		// +   improved by: Philip Peterson
		// +   improved by: Simon Willison (http://simonwillison.net)
		// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
		// +   bugfixed by: Anton Ongson
		// +      input by: Onno Marsman
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +    tweaked by: Onno Marsman
		// +      input by: Brett Zamir (http://brett-zamir.me)
		// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   input by: Oleg Eremeev
		// +   improved by: Brett Zamir (http://brett-zamir.me)
		// +   bugfixed by: Oleg Eremeev
		// %          note 1: The count parameter must be passed as a string in order
		// %          note 1:  to find a global variable in which the result will be given
		// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
		// *     returns 1: 'Kevin.van.Zonneveld'
		// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
		// *     returns 2: 'hemmo, mars'
		var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
				f = [].concat(search),
				r = [].concat(replace),
				s = subject,
				ra = r instanceof Array, sa = s instanceof Array;
		s = [].concat(s);
		if (count) {
			this.window[count] = 0;
		}

		for (i=0, sl=s.length; i < sl; i++) {
			if (s[i] === '') {
				continue;
			}
			for (j=0, fl=f.length; j < fl; j++) {
				temp = s[i]+'';
				repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
				s[i] = (temp).split(f[j]).join(repl);
				if (count && s[i] !== temp) {
					this.window[count] += (temp.length-s[i].length)/f[j].length;}
			}
		}
		return sa ? s : s[0];
	}

function getCookieVal(offset){
	var endstr=document.cookie.indexOf(";",offset);
	if(endstr==-1)
	endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
	}
function GetCookie(name){
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while(i<clen){
		var j=i+alen;
		if(document.cookie.substring(i,j)==arg)return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+ 1;
		if(i==0)break;
		}
	return ""; //null
	}
function plusEscape(str)
	{
	var strtmp = escape(str);
	var ret = "";
	for(i=0;i< strtmp.length;i++)
		{
		if(strtmp.charAt(i)=='+') {ret = ret + "%2B";}
		else if(strtmp.charAt(i)==' ') {ret = ret + "%20";}
		else if(strtmp.charAt(i)=='/') {ret = ret + "%2F";}
		else {ret = ret + strtmp.charAt(i);}
		}
	return ret;
	}
function SetCookie(name,value){
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc>2)?argv[2]:null;
	var path=(argc>3)?argv[3]:null; // ''/'';
	var domain=(argc>4)?argv[4]:null;
	var secure=(argc>5)?argv[5]:false;
	document.cookie=name+"="+plusEscape(value)+
		((expires==null)?"":("; expires="+expires.toGMTString()))+
		((path==null)?"":("; path="+path))+
		((domain==null)?"":("; domain="+domain))+
		((secure==true)?"; secure":"");
	}
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	// This cookie is history
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	document.cookie = name + "=" + cval + "; path=/; expires=" + exp.toGMTString();
	document.cookie = name + "=" + cval + "; path=..; expires=" + exp.toGMTString();
	}

	// DHTML Functions

 if (typeof(dhtmlObj) != 'function')
	{
	function dhtmlObj(objId)
		{
		if (typeof(objId) != "string")
			return objId;

		if(document.getElementById) //DOM IE5+, NS5+, GK, FF, OP, CA, ...
			return document.getElementById(objId);
		else if(document.all && document.all.ids) //IE
			return document.all.ids(objId);
		else if(document.all) //IE4+
			return document.all(objId);

		// NS4+
		return eval("document."+objId);
		}
		
	function show(objet)
		 {
		 obj = dhtmlObj(objet);
		 if (obj)
			obj.style.visibility = "visible";
		 }

	function showPos(objet,x,y)
		 {
		 obj = dhtmlObj(objet);
		 if (!obj) return false;
				
		obj.style.left = x;
		obj.style.top = y;
		obj.style.visibility = "visible";
		}

	function showRel(objet, ref, dir)
		{
		// dir : DOWN/RIGHT/OVER
		// todo later : LEFT/UP/(OVERUP?)
		if (!dir) dir='DOWN';
		obj = dhtmlObj(objet);
		objref = dhtmlObj(ref);
		if (!obj || !objref) return false;

		xy = absPos(objref);
		switch(dir)
			{
		case 'DOWN':
			xy.y += objref.height;
			break;
		case 'RIGHT':
			xy.x += objref.width;
			break;
			}
		return showPos(obj,xy.x,xy.y);
		}

	function hide(objet)
		 {
		 obj = dhtmlObj(objet);
		 if (!obj) return false;
		 obj.style.visibility = "hidden";
		 }

	function isVisible(objet)
		 {
		 obj = dhtmlObj(objet);
		 if (!obj) return false;
		 return obj.style.visibility != "hidden";
		 }

	function absLeft(objet)
		 {
		 obj = dhtmlObj(objet);
		 
		 if (obj.offsetParent)
				 return obj.offsetLeft+absLeft(obj.offsetParent);
		 else
				 return obj.offsetLeft;
		 }

	function absTop(objet)
		 {
		 obj = dhtmlObj(objet);
		 
		 if (obj.offsetParent)
				 return obj.offsetTop+absTop(obj.offsetParent);
		 else
				 return obj.offsetTop;
		 }
		
	function relLeft(objet, ref)
		 {
		 obj = dhtmlObj(objet);
		 
		if (obj.offsetParent)
			{
			if (obj.offsetParent!=ref)
				return obj.offsetLeft+relLeft(obj.offsetParent, ref);
			else
				return obj.offsetLeft;
			}
		else
			return obj.offsetLeft - relLeft(ref);
		 }

	function relTop(objet, ref)
		{
		obj = dhtmlObj(objet);

		if (obj.offsetParent)
			{
			if (obj.offsetParent!=ref)
				return obj.offsetTop+relTop(obj.offsetParent, ref);
			else
				return obj.offsetTop;
			}
		else
			return obj.offsetTop - absTop(ref);
		}
		
	function absPos(oElement)
		{
		if( typeof( oElement.offsetParent ) != 'undefined' )
			{
			for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent )
				{
				posX += oElement.offsetLeft;
				posY += oElement.offsetTop;
				}
			return {x:posX, y:posY};
			}
		else
			return {x:oElement.x, y:oElement.y};
		}

	function cancelEventChain(evt)
		 {
		 if (window.event)
				 window.event.cancelBubble = true;
		 else
				 evt.stopPropagation();
		 }
		 
	function blinkObj(v1, v2, o,i,t)//, i=6, t='CNT') // val1, val2, ref object, nb iteration, type
		{
		if (blinkObj.arguments.length<4)i=5;
		if (blinkObj.arguments.length<5)t='CNT';
		obj = dhtmlObj(o);
		if (obj.getAttribute("blinkid"))
			window.clearTimeout(obj.getAttribute("blinkid"));
		obj.setAttribute("blinkid","");
		
		obj.setAttribute("blinki",""+i);
		obj.setAttribute("blinkt",""+t);
		obj.setAttribute("blinkv1",v1);
		obj.setAttribute("blinkv2",v2);
		doBlinkObj(o);
		}
		
	function doBlinkObj(o)
		{
		obj = dhtmlObj(o);
		obj.setAttribute("blinkid","");
		
		i=obj.getAttribute("blinki");
		t=obj.getAttribute("blinkt");
		
		if ((i % 2) == 0) 
			v = obj.getAttribute("blinkv1");
		else
			v = obj.getAttribute("blinkv2");
		
		if (t=='CNT') // set the o elem content from v string
			obj.innerHTML = v;
		else if (t=='IMG') // set the o image url from v string
			obj.src = v;
		else if (t=='DIV') // set the o elem content from the v elem content
			obj.innerHTML = dhtmlObj(v).innerHTML;
		
		if(--i>=0)
			{
			obj.setAttribute("blinki",""+i);
			obj.setAttribute("blinkid",
				window.setTimeout(function () {doBlinkObj(o);},200)
				);
			}
		else
			{
			obj.setAttribute("blinki","");
			obj.setAttribute("blinkt","");
			obj.setAttribute("blinkv1","");
			obj.setAttribute("blinkv2","");
			}
		}
	
	function getHttpContents(proc)
		{
		/* Create a new XMLHttpRequest object to talk to the Web server */
		xmlHttp = false;
		
		/* ### ### BEWARE ### KEEP ALL FOLLOWING COMMENTS ### ### */
		
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try {
		  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (e2) {
		    xmlHttp = false;
		  }
		}
		@end @*/

		if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
			{
			xmlHttp = new XMLHttpRequest();
			}
		xmlHttp.open("GET", proc, false);
		// Send the request
		xmlHttp.send(null);
		if (xmlHttp.readyState == 4)
			{
			if (xmlHttp.status == 200)
				return xmlHttp.responseText;
			else if (xmlHttp.status == 404) return ("ERROR : Requested URL is not found.");
			else if (xmlHttp.status == 403) return ("ERROR : Access denied.");
			else return ("ERROR : The server could not answer your request (" + xmlHttp.status + " error)");
			}
				
		return "";
		}
		
	}
	
function clickOnce(obj)
   {
   if (obj.lockMe) return false;
   return obj.lockMe = true;
   }

function resetClickOnce(obj)
   {
   obj.lockMe = false;
   }

	