function trimAll(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function isExtension(nomFichier, extension){
	if(nomFichier.length == 0)
		return false;
	
	var i = nomFichier.lastIndexOf('.');
	if(i == -1){
		return false;
	}else{
		var extensionFichier = nomFichier.substring(i + 1, nomFichier.length);
		if(extensionFichier.toLowerCase() != extension.toLowerCase()){
			return false;
		}else{
			return true;
		}
	}
}

function getIconeEspace(){
	var icone = new GIcon();
	icone.image = "../images/gmap/icone_espace.png";
	icone.iconSize = new GSize(16.00,18.5);
	icone.iconAnchor = new GPoint(8.0,18.5);
	icone.infoWindowAnchor = new GPoint(8.0,9.25);
	
	return icone;
}

function getIconeRegion(){
	var icone = new GIcon();
	icone.image = "../images/gmap/icone_region.png";
	icone.iconSize = new GSize(24.00,24.00);
	icone.iconAnchor = new GPoint(12.0,24.0);
	icone.infoWindowAnchor = new GPoint(12.0,12.0);
	
	return icone;
}

function getIconeRegionNetPublic(){
	var icone = new GIcon();
	icone.image = "../images/gmap/icone_region_netpublic.png";
	icone.iconSize = new GSize(24.00,24.00);
	icone.iconAnchor = new GPoint(12.0,24.0);
	icone.infoWindowAnchor = new GPoint(12.0,12.0);
	
	return icone;
}

function getIconeDepartement(){
	var icone = new GIcon();
	icone.image = "../images/gmap/icone_departement.png";
	icone.iconSize = new GSize(32.00,32.00);
	icone.iconAnchor = new GPoint(16.0,32.0);
	icone.infoWindowAnchor = new GPoint(16.0,16.0);
	
	return icone;
}

function getIconeDepartementNetPublic(){
	var icone = new GIcon();
	icone.image = "../images/gmap/icone_departement_netpublic.png";
	icone.iconSize = new GSize(32.00,32.00);
	icone.iconAnchor = new GPoint(16.0,32.0);
	icone.infoWindowAnchor = new GPoint(16.0,16.0);
	
	return icone;
}

function placerMarkerDepartementNetPublic(map, point, titre, icone, idRegion, idDepartement){
	var marker = new GMarker(point,{icon: icone, title: titre});
	marker.set
	GEvent.addListener(marker,"click", function() {
		document.location.href = 'index.php?commande=choix&IdRegion=' + idRegion + '&IdDepartement=' + idDepartement;
	});
	map.addOverlay(marker);
}

function placerMarkerDepartement(map, point, titre, icone, idRegion, idDepartement){
	var marker = new GMarker(point,{icon: icone, title: titre});
	marker.set
	GEvent.addListener(marker,"click", function() {
		document.location.href = 'index.php?commande=liste_map&IdRegion=' + idRegion + '&IdDepartement=' + idDepartement;
	});
	map.addOverlay(marker);
}

function placerMarkerRegion(map, point, titre, icone, id){
	var marker = new GMarker(point,{icon: icone, title: titre});
	marker.set
	GEvent.addListener(marker,"click", function() {
		document.location.href = 'index.php?commande=liste_map&IdRegion=' + id;
	});
	map.addOverlay(marker);
}

function placerMarkerRegionNetPublic(map, point, titre, icone, id){
	var marker = new GMarker(point,{icon: icone, title: titre});
	marker.set
	GEvent.addListener(marker,"click", function() {
		document.location.href = 'index.php?commande=choix&IdRegion=' + id;
	});
	map.addOverlay(marker);
}

function placerMarkerEspace(map, point, html, icone, titre){
	var marker = new GMarker(point,{icon: icone, title: titre});
	marker.set
	GEvent.addListener(marker,"click", function() {
		map.openInfoWindowHtml(point, html);
	});
	map.addOverlay(marker);
}

function printit() {
    VER = parseInt(navigator.appVersion);
   if (VER < 4) {
   alert ("pour imprimer : CTRL + P");
   }
   else if (navigator.platform == "MacPPC") {
   alert ("pour imprimer : POMME + P");
   }
   else {
   window.print();
   }
}

function previewForm( newFormAction ){
    newFormTarget = "_blank";
    lastFormAction = document.form.action;
	lastFormTarget = document.form.target;
    document.form.action = newFormAction;
	document.form.target = newFormTarget;
    document.form.submit();
    document.form.action = lastFormAction;
    document.form.target = lastFormTarget;
}

// ------ Classe fenestre -----------

function fenestre(url,nom,optdef,lardef,haudef) {
  this.url=url;
  this.nom=nom;
  if (! this.nom ) this.nom = "nomdef";
  this.optdef = optdef;

  if (! this.optdef) // options par defaut, sauf hauteur et largeur et redim définies séparément
        this.optdef = "toolbar=0,menuBar=1,scrollbars=1,resizable=1,status=1,location=0,left=1,top=50" ;
  if (lardef)
       this.opts = this.optdef + ',width=' + lardef + ',height=' + haudef;
  else
       this.opts = this.optdef + ',width=620,height=420';
  this.fen;
  this.ouvrir = ouvrir_fen;
  this.fermer = fermer_fen;
  this.ouverte = fen_ouverte
}

function ouvrir_fen(url,largeur,hauteur) {
    // nurl indique s'il s'agit d'une nouvelle url;
        var nf;
        if (url && (url != this.url)) nurl = this.url = url;
        if (! this.url)  return 0;
        if (largeur){
          this.opts = this.optdef + ',width=' + largeur + ',height=' + hauteur;
          this.fermer();// obligatoire pour forcer la fenêtre à s'ouvrir avec la nouvelle taille
        }
        if (! this.ouverte()|| nurl)this.fen = window.open (this.url,this.nom,this.opts);
        this.fen.focus();
        return false;
  }

function fermer_fen() {
    if (this.ouverte()) this.fen.close()
}

  function fen_ouverte() {
    return this.fen && ! this.fen.closed
}

// instanciations par défaut (noms de variable réservés )
var objfen= new fenestre('','nomdef2');

// -------- fin de la classe fenestre------------------

// Detecte le navigateur utilisé et renvoit son nom 
// Renvoit "Unknown" si le navigateur n'est pas Netscape ou Explorer
function Navigateur(){
  if (navigator.appName.indexOf("Netscape") > -1) {return "Netscape";}
  if (navigator.appName.indexOf("Explorer") > -1) {return "Explorer";}
  return "Unknown";
}

// Affiche/Efface l'element dont l'id est passé en paramètre
function switchVisibility( elementId ) {
	if (Navigateur() == "Netscape") {
		vis = document.getElementById(elementId).style.visibility;
		document.getElementById(elementId).style.visibility= ( vis=='hidden' )?'visible':'hidden';
	} else {
		vis = document.getElementById(elementId).style.visibility;
		document.getElementById(elementId).style.visibility= ( vis=='hidden' )?'visible':'hidden';
	}
}

// ------ Classe FenetreGalerie-----------

function FenetreGalerie(url,nom,optdef,lardef,haudef) {
	this.url=url;
	this.nom=nom;
	if (! this.nom ) this.nom = "nomdef2";
	this.optdef = optdef;

	if (! this.optdef) // options par defaut, sauf hauteur et largeur et redim définies séparément
		this.optdef = "toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no" ;
	if (lardef)
	   this.opts = this.optdef + ',width=' + lardef + ',height=' + haudef;
	else
	   this.opts = this.optdef + ',width=610,height=510';
	this.fen2;
	this.ouvrir = ouvrirFenetreGalerie;
	this.fermer = fermerFenetreGalerie;
	this.ouverte = fenetreGalerieOuverte;
}

function ouvrirFenetreGalerie(url,largeur,hauteur) {
    // nurl indique s'il s'agit d'une nouvelle url;
        var nf;
        if (url && (url != this.url)) nurl = this.url = url;
        if (! this.url)  return 0;
        if (largeur){
          this.opts = this.optdef + ',width=' + largeur + ',height=' + hauteur;
          this.fermer();// obligatoire pour forcer la fenêtre à s'ouvrir avec la nouvelle taille
        }
        if (! this.ouverte()|| nurl)this.fen2 = window.open (this.url,this.nom,this.opts);
        this.fen2.focus();
        return false;
  }

function fermerFenetreGalerie() {
    if (this.ouverte()) this.fen2.close()
}

  function fenetreGalerieOuverte() {
    return this.fen2 && ! this.fen2.closed
}

// instanciations par défaut (noms de variable réservés )
var fenetreGalerie = new FenetreGalerie('','nomdef2');

// -------- fin de la classe fenestre------------------

