
// Transmet le redimensionnement au flash
function resize(){

	var actimap = document.getElementById('actimap');

	var larg = (document.body.clientWidth);
	var haut = (document.body.clientHeight);

	actimap.SetZoomRect(0,0,larg*20,haut*20);
}

// Ramène le nom du flash
function getMovieName(movieName) {
    
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
   }
   else {
       return document[movieName]
   }
}

// Envoie un mail à l'assistance Netagis
function mailAssistance(){

	window.location.replace("mailto:assistance@netagis.com");

}

// Lance la popup de recherche
function recherche(id_recherche,geolim){
	window.open('../module.php?module=fiche&page=index_recherche&fiche[id_fiche]='+id_recherche+'&fiche[flash]=1&fiche[geolim]='+geolim,'','resizable=yes, scrollbars=yes, width=100, height=100, toolbar=no, location=no, status=no, menubar=no');
}

// Lance la popup d'analyse
function analyse(id_analyse,geolim){
	window.open('../module.php?module=fiche&page=index_analyse&fiche[id_fiche]='+id_analyse+'&fiche[flash]=1&fiche[geolim]='+geolim,'','resizable=yes, scrollbars=yes, width=100, height=100, toolbar=no, location=no, status=no, menubar=no');
}

// Lance la popup d'analyse spatiale
function spatial(url,geolim){
	window.open(url,'','resizable=yes, scrollbars=yes, width=400, height=550, toolbar=no, location=no, status=no, menubar=no');
}

// Lance la popup d'affichage de la séléction
function selection(url){
	window.open(url,'','resizable=yes, scrollbars=yes, width=400, height=550, toolbar=no, location=no, status=no, menubar=no');
}

// Lance la popup d'affichage de la séléction
function recherche_parcelle(){
  url='../module.php?module=cadastre&page=rechercheParcelle&flash=1';
	window.open(url,'','resizable=yes, scrollbars=yes, width=400, height=550, toolbar=no, location=no, status=no, menubar=no');
}

// Lance la popup d'affichage de la séléction
function lieu_dit(){
  url='../module.php?module=cadastre&page=listelieudit&flash=1';
	window.open(url,'','resizable=yes, scrollbars=yes, width=400, height=550, toolbar=no, location=no, status=no, menubar=no');
}
// Lance la popup d'affichage de la séléction
function proprietaire(nom){
  url='../module.php?module=cadastre&flash=1&page=listepropr&let='+nom;
	window.open(url,'','resizable=yes, scrollbars=yes, width=400, height=550, toolbar=no, location=no, status=no, menubar=no');
}

function retour_parcelle(clausew){
	req = "resultatRecherche('cad_parcelle,elemgraph','"+clausew+"','cad_parcelle_req')";
	eval(req+";");
}

// retourne le résultat à Flash
function resultatRecherche(from, where, id_couche, effacer){
  if (effacer==undefined) effacer = true;
  getMovieName("actimap").effacer_recherche();
	getMovieName("actimap").resultat_recherche(from, where, id_couche);
}

// retourne le résultat à Flash
function resultatRechercheNoClear(from, where, id_couche, effacer){
  if (effacer==undefined) effacer = true;
  if (effacer) getMovieName("actimap").effacer_recherche();
	getMovieName("actimap").resultat_recherche_noclear(from, where, id_couche);
}

// efface une recherche
function effacerRecherche(){
	getMovieName("actimap").effacer_recherche();
}

// Sélectionne des éléments de la carto passés dans le tableau tab
function selectElements(tab){
	getMovieName("actimap").select_elements(tab);
}

// Désélectionne tous les éléments de la carto
function deselectAll(){
	getMovieName("actimap").deselectionneTout();
}


// retourne le résultat à Flash
function resultatAnalyse(from, where, id_couche, tabClause, tabCouleur, valeurs,titre,unite){
  getMovieName("actimap").resultat_analyse(from, where, id_couche, tabClause, tabCouleur, valeurs, titre, unite);
}

//Mets à jour le tableau dans Flash à partir du tableau global MaSelection
function majSelection() {
    var actimap=getMovieName("actimap");
    if (actimap!=null && actimap!='undefined' && actimap.majMaSelection) {
      actimap.majMaSelection(MaSelection['sel_valeur']);
    }
}

// Enleve le contrôle de Microsft Internet Explorer sur les ActiveX
function ieupdate(){

	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}

//conversion degre decimaux vers degre DMS
function dec2dms2(dec){
  deg=parseInt(dec);
  tmp=(parseFloat(dec)-parseFloat(deg))*60;
  min=parseInt(tmp);
  sec=(tmp-min)*60
  sec=sec.toFixed(2)
  return deg+"°"+min+"'"+sec+'"';
}

// Envoie les coordonnées au format GPS à Flash
function GPS(x,y,type,format){
  var point = new gPoint();
  if (type=="lamb2E"){
    point.configlamb(600000, 2200000, 2.33723, 46.8, 45.89892, 47.69601);
  }else{
    point.configlamb(600000, 200000, 2.33723, 46.8, 45.89892, 47.69601);
  }
  point.lccEasting=x;
  point.lccNorthing=y;
  point.a = 6378249;
  point.e2 = 0.006803511;
  point.lamb2gps();
  
  if (format=="dec"){
          var lat=point.lat.toFixed(5)+' N';
        if (point.longi<0){
           var longi=Math.abs(point.longi.toFixed(5))+' W';
        }else{
          var longi=point.longi.toFixed(5)+' E';
        }
    }else{
      var lat=dec2dms2(point.lat)+' N';
      if (point.longi<0){
        var longi=dec2dms2(Math.abs(point.longi))+' W';
      }else{
        var longi=dec2dms2(point.longi)+' E';
      }
    }
  getMovieName("actimap").afficheCoordonnees(lat,longi);
}

function getFiche(url) {

  if (url!=''){
		if(window.XMLHttpRequest) // Firefox
		  xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
		  xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non support‚ par le navigateur
		  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		  return;
		}

		xhr_object.open("GET", url, true);

		xhr_object.onreadystatechange = function() {
		  if(xhr_object.readyState == 4){
  			//alert(xhr_object.responseText);
  			select=xhr_object.responseText;
  			if (select.length != 0) {
          dd.elements.masque.show();
    			dd.elements.fiche.show();
          dd.elements.fiche.write(select);
    		  //dd.elements.fiche.resizeTo(document.getElementById('tableau_fiche').offsetWidth+3,dd.elements.fiche.h);
    		  dd.elements.fiche.resizeTo(454,dd.elements.fiche.h-0);
          var matchAll = new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'img');
          var resultat;
          while ((resultat = matchAll.exec(select)) !=null) {
            eval(resultat[1]);
          }
          myOnload();
        }
      }
		}
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		var data = "";
		xhr_object.send(data);
	}
}

// Spécifique CODEL - Fonctions appelées à la conection de l'utilisateur sur le front office

// Fonction appelée à la fin du chargement par Flash
function finChargement() {
  afficheZACarte();
  var tab=calculeTaille();
 // getMovieName("actimap").resizeInterface(tab[0],tab[1]);
 getMovieName("actimap").chargePunaises();
 getMovieName("actimap").majMaSelection(MaSelection['sel_valeur']);
}

function isConnected() {
  
  if (GlobCliid>0)
    return 'ok';
  else
    return 'ko';

}

function flashConnect(cliid) {
    var actimap=getMovieName("actimap");
    if (actimap!=null && actimap!='undefined' && actimap.chargePunaises && isConnected()=='ok')
      actimap.chargePunaises();
}
function afficheZACarte() {
   getMovieName('actimap').razCarte();
   from=' elemgraph, vue_za_zone_carto_ponctuels ';
   where=' elemgraph.id_elemgraph=vue_za_zone_carto_ponctuels.id_elemgraph and vue_za_zone_carto_ponctuels.date_suppression=\'0000-00-00\' and vue_za_zone_carto_ponctuels.validation<>\'1\' ';
   id_couche='vue_za_zone_carto_ponctuels_req';
   resultatRecherche(from, where, id_couche,true);

}
// Positionnement de la liste des éléments à gauche sur l'élément dont l'id est passé en paramètre.
var id_selection=0;
function postionneListe(id) {
   var tab=id.split('-');
   
   var strChUserAgent = navigator.userAgent;
   var intSplitStart = strChUserAgent.indexOf("(",0);
   var intSplitEnd = strChUserAgent.indexOf(")",0);
   var strChStart = strChUserAgent.substring(0,intSplitStart);
   var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
   var strChEnd = strChUserAgent.substring(strChEnd); 
   
   var element=document.getElementById('id-'+tab[1]); 

   if (element!=null){
     var positionY=element.offsetTop;
     
     var liste=document.getElementById('affresultatcarte');

     if (liste!=null) {
      if(strChEnd.indexOf("Firefox") != -1) {
        var scrollpos=positionY-element.offsetHeight;
      } else
        var scrollpos=positionY-element.offsetHeight;

      liste.scrollTop=scrollpos;
      var fondoffre1=document.getElementById('titreresultat-'+id_selection);
      if (fondoffre1!=null)
        //fondoffre1.style.backgroundImage = "url(images/fond_offre.png)";
        fondoffre1.style.backgroundColor="#7acaee";
      var fondoffre2=document.getElementById('titreresultat-'+tab[1]);
      if (fondoffre2!=null) 
      //  fondoffre2.style.backgroundImage = "url(images/fond_offre_vert.png)";
      fondoffre2.style.backgroundColor="#33c300";
      //background-color:#7acaee;
      
      id_selection=tab[1];
     }
   }
}

// Action effectuée sur la liste sur un onRollOut d'un élément
function sorsListe(id) {
   /*
   var tab=id.split('-');

   var element=document.getElementById('id-'+tab[1]); 
   
   if (element!=null){
     var fondoffre=document.getElementById('titreresultat-'+tab[1]); 
     fondoffre.style.backgroundImage = "url(images/fond_offre.png)";
   }*/
}
