function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function PreLoad_Img()
{
}

function compactsp(x) { // compacter les "espaces" contigus
	var r = '';
	var cprec=''
	for (var i=0; i<x.length; i++) {
		var c = x.charAt(i);
    	if (c != ' ') {r+=c; cprec=c;}
		else if (cprec!=' '){r+=c; cprec=c;}
    }
    return r;
}

function rmleadtrail(x) {// enlever les "espaces" EN DEBUT et en FIN de la chaine
	var i = 0;
	var iFirst = 0;
	var iLast = 0;
	var r='';
	while (i<x.length && x.charAt(i)==' ')	i++; // premier non espace
    iFirst = i;
	if (i==x.length) return r;  // il n'y a que des espaces!
	iLast = x.length-1;
    while (i<iLast && x.charAt(iLast)==' ')	iLast--; // dernier non espace
	for (i=iFirst; i<iLast+1; i++)	
		r += x.charAt(i);
    return r;
}

function RemplaceAccents(x)
{	iLast = x.length;
	var r="";
	for (i=0; i<iLast; i++)
	{	c = x.charAt(i);
		if (c=="à") { r += "a"; }
		else if (c=="ç") { r += "c"; }
		else if (c=="é") { r += "e"; }
		else if (c=="è") { r += "e"; }
		else if (c=="ê") { r += "e"; }
		else if (c=="ï") { r += "i"; }
		else if (c=="î") { r += "i"; }
		else if (c=="ô") { r += "o"; }
		else { r += x.charAt(i); }
	}
    return r;
}

// liste des caractères espaçant
//var liste_espace = " '-"; // espace, apostrophe, tiret; ajouter le 0xA0
var liste_espace = " "; // espace, apostrophe, tiret; ajouter le 0xA0

// liste des caractères à conserver: chiffres, lettres min/MAJ
// et tous les accentués:  C0-CF, D1-D6, D8-DD, E0-EF, F1-F6, F8-FD
var liste_ok = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	+ String.fromCharCode(39,45,47,192,193,194,195,196,197,199,200,201,202,203,204,205,206,207,
		209,210,211,212,213,214,216,217,218,219,220,221,
		224,225,226,227,228,229,230,231,232,233,234,235,236,237,239,239,
		241,242,243,244,245,246,248,249,250,251,252,253); // ' - /

function Compactage(val){
	var r1="";
	for (i=0; i<val.length; i++){
		c = val.charAt(i);
		if (liste_espace.indexOf(c)!=-1) // caractère assimilé à un espace
			r1 += " ";
		else if (liste_ok.indexOf(c)!=-1) // caractère à conserver
			r1 += c;
		// else traitement des ligatures, si on décide de le faire
		else if (val.charCodeAt(i)==198) // ligature AE
			r1 += "AE";
		else if (val.charCodeAt(i)==230) // ligature ae
			r1 += "ae";
		else if (val.charCodeAt(i)==140) // ligature OE
			r1 += "OE";
		else if (val.charCodeAt(i)==156) // ligature oe
			r1 += "oe";
	}
	var r2 = compactsp(r1); // compacter les espaces contigus
	return rmleadtrail(r2); // puis suppression des espaces en tete et queue
}

function PrepareSaisie(x)
{	var x2 = Compactage(x);
	var x3 = RemplaceAccents(x2);
	return x3;
}

function ShowText(strText)
{	window.status=strText;
}

/*
function ssetCurrentTool(toolindex)
{	setNivZoom(toolindex);
}
*/

function Is()
{	var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}

var is = new Is();

function DoAction(strAction)
{ var frm=frames['iframemap'].document.forms['formMap'];
	if (frm != null)
	{	frm.cmd.value=strAction;
		frm.submit();
	}
}

function majEmprise(w,niv,xmin, ymin, xmax, ymax)
{	var f=xGetElementById('Formulaire');

	// Changement d'outil
	var bln = 0;

	// maj de la distance
/*
	eval("t=xGetElementById('distance');");
	if (t!=null)
	{	t.src = "getimgdist.php?width="+w+"&xmin="+xmin+"&ymin="+ymin+"&xmax="+xmax+"&ymax="+ymax;
	}
*/

	f.XMIN.value=xmin;
	f.YMIN.value=ymin;
	f.XMAX.value=xmax;
	f.YMAX.value=ymax;
}

function fullScreen()
{	var f=xGetElementById('Formulaire');
	xmin=f.XMIN.value;
	ymin=f.YMIN.value;
	xmax=f.XMAX.value;
	ymax=f.YMAX.value;
  c=f.cible.value;
	cx=f.cx.value;
	cy=f.cy.value;

	var strURL="index_fs.php?cmd=zoom&op=locate&XMIN="+xmin+"&YMIN="+ymin+"&XMAX="+xmax+"&YMAX="+ymax+"&cible="+c+"&cx="+cx+"&cy="+cy;
	xWinOpen(strURL, 800, 600);
}

function doPrint()
{	frm2=xGetElementById("Formulaire");
	var cmd=frm2.cmd.value;
	var op=frm2.op.value;
	var blnCible=frm2.cible.value;
	var cibleX=frm2.cx.value;
	var cibleY=frm2.cy.value;
	var cibleY=frm2.cy.value;
	var datevisu=frm2.date.value;
	var blnLines=frm2.lines.value;
	var mode=frm2.mode.value;
	var date1=frm2.d1.value;
	var date2=frm2.d2.value;
	var nbpos=frm2.np.value;
	var lang=frm2.lang.value;

	var frm=frames['iframemap'].document.forms['formMap'];
	if (frm == null)
	{	alert("Une erreur est survenue");
		return;
	}
	var lngXmin=frm.XMIN.value;
	var lngYmin=frm.YMIN.value;
	var lngXmax=frm.XMAX.value;
	var lngYmax=frm.YMAX.value;
	var mobilesId=frm.mobiles.value;
	var vents=frm.vent.value;
	var blnAlertes=frm.alerte.value;

	var strURL = "localisation_print.php?cmd="+cmd+"&op="+op+"&XMIN="+lngXmin+"&YMIN="+lngYmin+"&XMAX="+lngXmax+"&YMAX="+lngYmax+"&cible="+blnCible+"&cx="+cibleX+"&cy="+cibleY+"&mobiles="+mobilesId+"&vent="+vents+"&alerte="+blnAlertes+"&date="+datevisu+"&lines="+blnLines+"&mode="+mode+"&d1="+date1+"&d2="+date2+"&np="+nbpos+"&lang="+lang;
	xWinOpen(strURL, 800, 600);
}

