//==============================================================================================
// IMAGE HANDLING
//==============================================================================================

function preloadImages() //v3.0
{
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function ReplaceImage() //v2.0
{
	j = 0;
	ImgArray = new Array;
	oldImgArray = document.OriginImage;

	for (i = 0; i < ReplaceImage.arguments.length; i += 2) {
		obj=ReplaceImage.arguments[i]
		ImgArray[j++] = obj;
		if (oldImgArray == null || oldImgArray[j-1] != obj)
			ImgArray[j++] = obj.src;
		else
			ImgArray[j++] = oldImgArray[j];
		obj.src = ReplaceImage.arguments[i + 1];
	}
	if (document.OriginImage == null)
		document.OriginImage = ImgArray;
}

//==============================================================================================
// FORMAT
//==============================================================================================


function popupinfo (url,x,y,w,h)
{
	wininf = window.open(url,'wininf','top='+x+',left='+y+',width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	wininf.resizeTo(w,h);
	wininf.moveTo(x,y)
	wininf.focus();
	this.focus;
	return wininf;
}

function postmsg (param)
{
	w = window.open('/postmsg.php?'+param,'wininf','top=10,left=10,width=640,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	w.focus();
	this.focus;
	return w;
}

	function roundNumber(nb,rlength) 
	{
		var newnumber = Math.round(nb*Math.pow(10,rlength))/Math.pow(10,rlength);
		return newnumber;
	}

	function affdec (val,nbchif)
	{
	  p = 1;
	  for (i = 0; i < nbchif; i++) p = p*10;
	  val = Math.round(val*p)/p;
	  valeur = val.toString();
	  if (valeur.indexOf('.')<0) 
	  {
		valeur += '.';
		for (i = 0; i < nbchif; i++) valeur += '0';
	  }
	  else
	  {
		pos = valeur.length - valeur.indexOf('.');
		if ( pos != nbchif+1 )
		{
			diff = valeur.length - valeur.indexOf('.');
			while (diff < nbchif+1)
			{
				valeur += '0';			
				diff = valeur.length - valeur.indexOf('.');
			}
		}
	  }
	  return valeur;
	}
	
	function trim(txt)
	{
		while (txt.indexOf (' ') == 0) { txt = txt.substr(1); }
		while (txt.substr(txt.length-1)==' ') { txt = txt.substr(0,txt.length-1); }
		return txt ;
	}
	
	function Postgeo(s,o)
	{
		if (s.value=='--') s.value='-'; 
		else if (s.value=='') o.value=s.options[1].text; 
		else 
		{
			if (s.value>'-' && o.value.indexOf(s.value+';')<0) 
			{
				re = new RegExp (s.options[1].text);
				if (o.value.match(re)) 
				{
					re2 = new RegExp (s.options[1].text+';');
					o.value = o.value.replace(re2,'');
					o.value = o.value.replace(re,'');
				}
				o.value += (!o.value || o.value.match(/;$/)) ? s.value+';' : ';'+s.value+';';s.value='-';
			}
		}
		o.focus();
	}
