/**
* ANTAREA
*
* @version 0.1
* @author BLR
* @date 10/10/2007 - version initiale
* @version 0.2
* @author BLR
* @date 30/10/2007 - menu admin, tri dans les listes
* @version 0.3
* @author BLR
* @date 17/11/2007 - gestion dynamique des cartes de répartition des espèces
* @version 0.4
* @author BLR
* @date 21/11/2007 - nbre d'identification par departement
* @version 0.5
* @author BLR
* @date 01/05/2008 - image plus grande, classement des ssfamille
* @version 0.6
* @author BLR
* @date 03/05/2008 - affiche les consignes, optimisation du code
* @version 0.7
* @author BLR
* @date 13/05/2008 - changement d'affichage des consignes, bug dans addNode
* @version 0.8
* @author BLR
* @date 20/05/2008 - dans consigne possibilité de téléchager des fichiers PDF
* @version 0.9
* @author BLR
* @date 26/05/2008 - retrait des consignes
* @version 0.10
* @author BLR
* @date 28/05/2008 - autres listes
* @version 0.11
* @author BLR
* @date 29/05/2008 - compteurs sur les listes
* @version 0.12
* @author BLR
* @date 29/05/2008 - liste des news
* @version 0.13
* @author BLR
* @date 31/05/2008 - fautes d'orthographe
* @version 0.14
* @author BLR
* @date 01/06/2008 - fautes d'orthographe
* @version 0.15
* @author BLR
* @date 01/06/2008 - numéro de département dans l'arborescence
* @version 0.16
* @author BLR
* @date 01/06/2008 - numéro de département dans page identification
* @version 0.17
* @author BLR
* @date 07/06/2008 - ajout du menu du navigateur dans le forum
* @version 0.18
* @author BLR
* @date 08/06/2008 - amélioration de la liste des dernières saisies
* @version 0.19
* @author BLR
* @date 11/06/2008 - ajout de métadata dans les pages html
* @version 0.20
* @author BLR
* @date 15/06/2008 - changement du logo
* @version 0.21
* @author BLR
* @date 15/06/2008 - logo plus grand
* @version 0.22
* @author BLR
* @date 02/07/2008 - mise à jour carte en temps réel (identification)
* @version 0.23
* @author BLR
* @date 06/07/2008 - gestion des lettres accentuées(partiel)
* @version 0.24
* @author BLR
* @date 06/07/2008 - changement de couleur pour les localisations
* @version 0.25
* @author BLR
* @date 12/07/2008 - dernières saisies sur 1 mois
* @version 0.26
* @author BLR
* @date 12/07/2008 - mise à jour carte en temps réel (nombre identification par département )
* @version 0.27
* @author BLR
* @date 12/07/2008 - nombre identification par département : liste détail 
* @version 0.28
* @author BLR
* @date 16/07/2008 - fautes d'orthographe 
* @version 0.29
* @author BLR
* @date 12/08/2008 - accents 
* @version 0.30
* @author BLR
* @date 14/08/2008 - lot et garonne 
* @version 0.31
* @author BLR
* @date 20/08/2008 - ajout des liens 
* @version 0.32
* @author BLR
* @date 25/08/2010 - changement échelle, libelle du menu 
*
*/

var versionAntarea = 'antarea v0.32';
var siteAntarea = 'projet';


/**
* Classe du programme de demo
* @constructor
*/
function antarea()
{
 this.centerWin = null;
 this.leftWin = null;
 this.winMain = null;
 this.tabFolder = null;
 this.famille_i = null;
 this.espece_i = null;
 this.famille_g = null;
 this.espece_g = null;
 this.famille_b = null;
 this.espece_b = null;
 this.famille_p = null;
 this.espece_p = null;
 this.aucun_i = null;
 this.info_i = null;
 this.tabItemBio = null;
 this.tabItemMap = null;
 this.parentRoadmap = null;
 this.SVGDocument = null;
 this.total_i = null;
 this.nbre_i = null;
 this.funcColorIdentification = null;
 this.funcColorNbDep = null;
 this.data = null;
}


antarea.prototype={

myutf8 : function ( str)    
{
 str = str.replace( new RegExp(String.fromCharCode(195,169), "g"), "é");   
 str = str.replace( new RegExp(String.fromCharCode(195,168), "g"), "è");   
 str = str.replace( new RegExp(String.fromCharCode(195,170), "g"), "ê");   
 str = str.replace( new RegExp(String.fromCharCode(195,171), "g"), "ë");   
 str = str.replace( new RegExp(String.fromCharCode(195,174), "g"), "î");   
 str = str.replace( new RegExp(String.fromCharCode(195,175), "g"), "ï");   
 str = str.replace( new RegExp(String.fromCharCode(195,180), "g"), "ô");   
 str = str.replace( new RegExp(String.fromCharCode(195,187), "g"), "û");   
 str = str.replace( new RegExp(String.fromCharCode(195,167), "g"), "ç");   
 str = str.replace( new RegExp(String.fromCharCode(195,162), "g"), "â");   
 str = str.replace( new RegExp(String.fromCharCode(195,160), "g"), "à");   
 return str;
},
getUrl : function ()
{
 return window.location.protocol+'//'+window.location.host+'/'+siteAntarea+'/';
},

ajaxRequest : function( oParent, page, param, object, callBack)
{
 if ( oParent != null)   
    this.parent = oParent;
 var remote=new rialto.io.AjaxRequest(
 {
 url:this.getUrl()+page,
 method: 'get',
 withWaitWindow:false,
 callBackObjectOnSuccess:object,
 onSuccess : callBack
 }) ;
 remote.load( param);

},

windowSimple: function( titre, folder, largeurFolder)
{
 if ( this.tabFolder != null)
 {
 this.tabFolder.remove();
 this.tabFolder = null;
 }
 if ( this.winMain != null)
 {

 this.winMain.closeWindow();
 this.winMain = null;
 }

 //Fenêtre simple
 this.winMain=new rialto.widget.SimpleWindow(
 {
 icone:"images/imgFenSimple/picto-gr_default.gif",
 title:titre,
 position:"absolute",
 name:"simpleWindow0",
 withCloseButon:false,
 parent:this.centerWin
 });
 if ( folder)
 {
 this.tabFolder=new rialto.widget.TabFolder(
 {
 orientation:"t",
 draggableItem:false,
 isClosable:false,
 position:"absolute",
 width:"'100%'",
 widthTabName:largeurFolder,
 autoRedimTab:false,
 name:"tabfolder3",
 height:"'100%'",
 parent:this.winMain
 });
 }
},

/**
* Création du de l'arbre
* @return aucun
*/
createIHM : function (){
 var splitPG = new rialto.widget.Splitter(
 {
 top:0,
 left:0,
 height:'100%',
 width:'100%',
 prop:0.20,
 orientation:'h',
 name:'splitPG',
 parent:document.body,
 style:'3D',
 limInf:0,
 limSup:1,
 withImg:true,
 reverseClose:false
 }
 );
 this.split = splitPG;
 this.centerWin = splitPG.div2;
 this.leftWin = splitPG.div2;
 new rialto.widget.Label("lab1",10,10,splitPG.div1,versionAntarea,"libelle1");
 var cadreIntro = new rialto.widget.Frame(
 {name:'cadreintro',top:'50',left:'50',width:'900',height:'610',title:'',open:true,dynamic:false,position:'relative',draggable:false,parent:this.leftWin});
 var divHTML=document.createElement('DIV');
 divHTML.innerHTML='<table width="100%"><tr><td><h1>&nbsp;</h1><br></td><td align="center"><img id="imgintro1" src="image/antarealogo.jpg"/></td></tr></table>';
 cadreIntro.add(divHTML);
 //Shadow('#c00',"antarea");
 var treeDossier = new rialto.widget.Tree(
 {
 name:'treeDossier',
 top:'40',
 left:'10',
 width:'93%',
 height:'95%',
 parent:splitPG.div1,
 boolSelActive:false,
 rootOpen:true,
 withRoot:true,
 withT:true,
 draggableNode:false
 }
 );
 var nodeRoot = treeDossier.createAndAddNode(treeDossier.id,
 {
 name:'root',
 text:'AntArea',
 icon:'images/imTreeview/icone_agenda_ferme.gif',
 icon2:'images/imTreeview/icone_agenda_ouvert.gif',
 onclick:"",
 open:true,
 reload:false,
 url:""
 }
 );
 if ( nodeRoot.hasChild())
 return;
 this.ajaxRequest( nodeRoot, "php/tree.php", 'name='+nodeRoot.name, this, this.onsuccesLoadNode);
 },

onsuccesLoadNode : function ( request)
 {
 var parent = this.parent;
 if (parent.hasChild())
 return;
 try{
 var str = request.responseText.substring(request.responseText.indexOf('{',0));
 var colNode = eval("(" + str+ ")");
 } catch (e) {
if (e instanceof Error) {
alert(e.name + ': ' + e.message);
}}
 var child = colNode.arrNode;
 var childProjet = colNode.arrNode1;
 for (var i = 0, nb = colNode.arrNode.length; i < nb; i++)
 {
 if ( child[i].objPar.text == 'PROJET')
 {
 child[i].objPar.open = true;
 var node = new rialto.widget.TreeNode(child[i].objPar);
 this.parent.addNode(node );
 for (var ii = 0, nbProjet = colNode.arrNode1.length; ii < nbProjet; ii++)
 {
 node.addNode(new rialto.widget.TreeNode(childProjet[ii].objPar));
 }

 }
 else
 {
 this.parent.addNode(new rialto.widget.TreeNode(child[i].objPar));
 }
 }
 },

onsuccesLoadData : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 var nb = data.length;
 this.parent.fillGrid( data);
 var parent = this.parent;
 var style = {'color':'red'};
 var nbre = 0;
 for (var i = 0; i < nb; i++)
 {
 data[i][1]=this.myutf8(unescape(data[i][1]));
 if ( data[i][2] > 0)
 {
 nbre++;
 parent.setStyle(i,-1,style);
 }
 }
 this.nbre_i.setText('Nombre d\'espèce identifiée : '+nbre);
 this.total_i.setText(' Nombre d\'espèce probable : '+nb);
 this.parent.refreshGrid();
},

onsuccesEspExist : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 var nb = data.length;
 var i;
 for( i = 0; i < nb; i++)
 {
  data[i][1]=this.myutf8(unescape(data[i][1]));
 }
 this.nbre_i.setText('Nombre d\'espèce identifiée : '+nb);
 this.parent.fillGrid( data);
 this.parent.refreshGrid();
},

onsuccesloadDataNews : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 var len = data.length;
 var i;
 for( i = 0; i < len; i++)
 {
  data[i][2]= this.myutf8(unescape(data[i][2]));
 }
 this.info_i.fillGrid( data);
 this.info_i.refreshGrid();
},

onsuccesloadDataDepNbre : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 var nb = data.length;
 this.nbre_i.setText('Nombre de département ayant au moins une espèce recencée : '+nb);
 this.detail.fillGrid( data);
 this.detail.refreshGrid();
},

onsuccesloadDataEsp : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 this.famille_i.setText( data[0]['SSF']);
 this.espece_i.setText(data[0]['ESP']);
 this.famille_g.setText( data[0]['SSF']);
 this.espece_g.setText(data[0]['ESP']);
 this.famille_c.setText( data[0]['SSF']);
 this.espece_c.setText(data[0]['ESP']);
 var ii = data['IDENT'].length;
 if ( data['IDENT'].length > 0)
 {
 var i;    
 var tab = data['IDENT'];
 var len = tab.length;
 for ( i = 0; i < len; i++)
 { 
    tab[i][1] = this.myutf8(unescape(tab[i][1]));
 }
 this.nbre_i.setText('Nombre d\'identification : '+data['IDENT'].length);
 this.info_i.fillGrid( data['IDENT']);
 this.info_i.setVisible( true);
 this.aucun_i.setVisible( false);

 }
 else
 {
 this.info_i.setVisible( false);
 this.aucun_i.setVisible( true);
 }
},

onsuccesloadDataEspDep : function ( request)
{
 var data = eval("(" + request.responseText + ")");
 var dep = data['DEP'][0];    
 var len = data['IDENT'].length;
 this.dep_i.setText( dep[0]+'('+dep[1]+')');
 this.dep_i.setVisible( true);
 if ( len > 0)
 {
   var i;    
   var tab = data['IDENT'];
   for ( i = 0; i < len; i++)
   { 
      tab[i][1] = this.myutf8(unescape(tab[i][1]));
      tab[i][2] = this.myutf8(unescape(tab[i][2]));
   }
   this.nbre_i.setText('Nombre d\'identification : '+len);
   this.info_i.fillGrid( data['IDENT']);
   this.info_i.setVisible( true);
   this.aucun_i.setVisible( false);
 }
 else
 {
  this.info_i.setVisible( false);
  this.aucun_i.setVisible( true);
 }
},

loadMap : function ( oParent)
{

 var remote=new rialto.io.AjaxRequest(
 {
 url:this.getUrl()+"php/infoesp.php",
 method: 'get',
 withWaitWindow:false,
 callBackObjectOnSuccess:this,
 onSuccess : onsucces
 }) ;
 remote.load('name='+oParent.name+'&param=map');

 function onsucces( request)
 {
 var data = eval("(" + request.responseText + ")");
 this.data = data['MAP'];
 if (this.funcColorIdentification != null && this.data != null)
     this.funcColorIdentification( );
 }
},
loadMapNbDep : function ( oParent)
{

 var remote=new rialto.io.AjaxRequest(
 {
 url:this.getUrl()+"php/infoesp.php",
 method: 'get',
 withWaitWindow:false,
 callBackObjectOnSuccess:this,
 onSuccess : onsucces
 }) ;
 remote.load('name=nbdep&param=nbdep');

 function onsucces( request)
 {
 var data = eval("(" + request.responseText + ")");
 this.data = data['MAP'];
 if (this.funcColorNbDep != null && this.data != null)
     this.funcColorNbDep( );
 }

},
loadNode : function ( oParent)
{
 this.ajaxRequest( oParent, "php/tree.php", 'name='+oParent.name, this, this.onsuccesLoadNode);
},
especesExist : function (oParent)
{
 this.windowSimple( "Espèces recensées en France", true,200);
 var tabItem=this.tabFolder.addTabItem("Espèces recensées",true);
 this.tabFolder.activeTab(0);
 this.winMain.setVisible(true);
 this.nbre_i = new rialto.widget.Label("esp_i",5,30, tabItem,'',"libelle1");
 var oTableau = new rialto.widget.Grid(
 {
 top:50,
 left:5,
 height:650,
 parent:tabItem,
 TabEntete:["Famille","Espèce","Nombre de département"],
 tabTypeCol:[["string",200],["string",400],["number",150]],
 name:'exist',
 bNavig:false,
 rang:30,
 cellActive:false,
 sortable:true,
 multiSelect:false,
 lineHeight:15,
 boolPrint:true,
 switchable:false,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });
 this.ajaxRequest( oTableau,"php/allesp.php", 'name='+oTableau.name, this, this.onsuccesEspExist);
},
especesProbables : function (oParent)
{
 this.windowSimple( "Espèces problables en France", true,200);
 var tabItem=this.tabFolder.addTabItem("Espèces probables",true);
 this.tabFolder.activeTab(0);
 this.winMain.setVisible(true);
 this.nbre_i = new rialto.widget.Label("esp_i",5,30, tabItem,'',"libelleRVSel");
 this.total_i = new rialto.widget.Label("total_i",5,250, tabItem,'',"libelle1");
 var oTableau = new rialto.widget.Grid(
 {
 top:50,
 left:5,
 height:650,
 parent:tabItem,
 TabEntete:["Famille","Espèce","Nombre"],
 tabTypeCol:[["string",200],["string",400],["number",100]],
 name:'probable',
 bNavig:false,
 rang:30,
 cellActive:false,
 sortable:false,
 multiSelect:false,
 lineHeight:15,
 boolPrint:true,
 switchable:false,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });
 this.ajaxRequest( oTableau,"php/allesp.php", 'name='+oTableau.name, this, this.onsuccesLoadData);
},


identDep : function (oParent)
{
 this.windowSimple( "Identification d'espèce", true,200);
 var tabItem=this.tabFolder.addTabItem("Identification",true);
 this.famille_i = new rialto.widget.Label("fam_i",10,30, tabItem,'',"libelle1");
},

identEsp : function (oParent)
{
  this.funcColorIdentification = null;
  this.data = null;
  this.loadMap( oParent);

  
 this.windowSimple( "Espèce recensée", true, 210);

 this.tabItemMap=this.tabFolder.addTabItem("Carte",true);
 this.famille_g = new rialto.widget.Label("fam_g",10,30, this.tabItemMap,'',"libelle1");
 this.espece_g = new rialto.widget.Label("esp_g",30,30, this.tabItemMap,'',"libelle1");
 this.frameMap = new rialto.widget.Frame({name:'CADREMAP',top:'50',left:'10',width:'98%',height:'83%',title:'',open:true,dynamic:false,position:'relative',draggable:false,parent:this.tabItemMap});


 var tabItem=this.tabFolder.addTabItem("Recensement départemental",true);
 this.famille_i = new rialto.widget.Label("fam_i",10,30, tabItem,'',"libelle1");
 this.espece_i = new rialto.widget.Label("esp_i",30,30, tabItem,'',"libelle1");
 this.nbre_i = new rialto.widget.Label("esp_i",30,350, tabItem,'',"libelle1");
 this.aucun_i = new rialto.widget.Label("aucun_i",60,30, tabItem,'Aucune information pour cette espèce',"libelle1");
 this.aucun_i.setVisible( false);
 this.info_i = new rialto.widget.Grid(
 {
 top:60,
 left:30,
 height:500,
 parent:tabItem,
 TabEntete:["Département","Commune","Date", "Récoltant", "Identificateur"],
 tabTypeCol:[["string",150],["string",200],["string",70],["string",200],["string",200]],
 name:'info_i',
 bNavig:false,
 rang:20,
 cellActive:false,
 sortable:true,
 multiSelect:false,
 lineHeight:16,
 boolPrint:true,
 switchable:true,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });
 this.info_i.setVisible( false);


 this.tabItemCar=this.tabFolder.addTabItem("Caractéristiques d'identification",true);
 this.frameCar = new rialto.widget.Frame({name:'CADRECAR',top:'50',left:'10',width:'98%',height:'90%',title:'',open:true,dynamic:false,position:'relative',draggable:false,parent:this.tabItemCar});
 this.famille_c = new rialto.widget.Label("fam_c",10,30, this.tabItemBio,'',"libelle1");
 this.espece_c = new rialto.widget.Label("esp_c",30,30, this.tabItemBio,'',"libelle1");
  var divHTML=document.createElement('DIV');
 divHTML.innerHTML='<center><table bgcolor="#F3f3f3"><tr><td><embed id="carte" width="590" height="570" src="'+this.getUrl()+'fichier/_commun/carte.svg"></td><td><embed id="carte" width="200px" height="40px" src="'+this.getUrl()+'fichier/_commun/texte.svg"></td></tr></table></center>';
 this.frameMap.add(divHTML);

 this.tabFolder.activeTab(0);
 this.winMain.setVisible(true);

 this.ajaxRequest( oParent, "php/infoesp.php", 'name='+oParent.name+'&param=esp', this, this.onsuccesloadDataEsp);
},

identDep : function (oParent)
{
 this.windowSimple( "Recensement des espèces par département", true,200);

 var tabItem=this.tabFolder.addTabItem("Recensement départemental",true);
 this.dep_i = new rialto.widget.Label("dep_i",10,30, tabItem,'',"libNormal");
 this.nbre_i = new rialto.widget.Label("nbre_i",30,30, tabItem,'',"libelle1");
 this.aucun_i = new rialto.widget.Label("aucun_i",60,30, tabItem,'Aucune information pour ce département',"libelle1");
 this.aucun_i.setVisible( false);
 this.info_i = new rialto.widget.Grid(
 {
 top:60,
 left:30,
 height:500,
 parent:tabItem,
 TabEntete:["Famille","Espèce","Commune","Date", "Récoltant", "Identificateur"],
 tabTypeCol:[["string",90],["string",200],["string",200],["string",50],["string",150],["string",150]],
 name:'info_i',
 bNavig:false,
 rang:20,
 cellActive:false,
 sortable:true,
 multiSelect:false,
 lineHeight:16,
 boolPrint:true,
 switchable:true,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });
 this.info_i.setVisible( false);

 this.winMain.setVisible(true);
 this.ajaxRequest( oParent, "php/infoesp.php", 'name='+oParent.name+'&param=espdep', this, this.onsuccesloadDataEspDep);
},

showNews : function (oParent)
{
 this.windowSimple( "Dernières saisies", true,200);

 var tabItem=this.tabFolder.addTabItem("Dernières saisies",true);
 this.info_i = new rialto.widget.Grid(
 {
 top:30,
 left:5,
 height:500,
 parent:tabItem,
 TabEntete:["Espèce","Département","Commune","Date récolte", "Date saisie", "Récoltant", "Identificateur"],
 tabTypeCol:[["string",200],["string",150],["string",200],["string",80],["date",80],["string",150],["string",150]],
 name:'info_i',
 bNavig:false,
 rang:20,
 cellActive:false,
 sortable:false,
 multiSelect:false,
 lineHeight:16,
 boolPrint:true,
 switchable:false,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });

 this.winMain.setVisible(true);
 this.ajaxRequest( oParent, "php/infoesp.php", 'name='+oParent.name+'&param=news', this, this.onsuccesloadDataNews);
},

showMapDepNb : function (oParent)
{
  this.funcColorNbDep = null;
  this.data = null;
  this.loadMapNbDep( oParent);
 this.windowSimple( "Nombre d'espèces recencées par département", true,200);
 var tabItem=this.tabFolder.addTabItem("Répartition",true);
 this.frameMap = new rialto.widget.Frame({name:'CADREMAP',top:'50',left:'10',width:'98%',height:'83%',title:'',open:true,dynamic:false,position:'relative',draggable:false,parent:tabItem});
 var divHTML=document.createElement('DIV');
 divHTML.innerHTML='<center><table bgcolor="#F3f3f3"><tr><td><embed id="carte" width="590" height="570" src="'+this.getUrl()+'fichier/_commun/cartenb.svg"></td><td><embed id="carte" width="200px" height="200px" src="'+this.getUrl()+'fichier/_commun/legendedepnb.svg"></td></tr></table></center>';
 this.frameMap.add(divHTML);
 tabItem=this.tabFolder.addTabItem("Détail",true);
 this.nbre_i = new rialto.widget.Label("nbre_i",30,30, tabItem,'',"libelle1");
 this.detail = new rialto.widget.Grid(
 {
 top:60,
 left:30,
 height:500,
 parent:tabItem,
 TabEntete:["N° du département","Nom du département","Nombre d'esp. recencées"],
 tabTypeCol:[["number",140],["string",200],["number",180]],
 name:'detail',
 bNavig:false,
 rang:20,
 cellActive:false,
 sortable:true,
 multiSelect:false,
 lineHeight:16,
 boolPrint:true,
 switchable:true,
 actifClic:false,
 autoResizableW:false,
 writable:false
 });
 this.ajaxRequest( oParent, "php/infoesp.php", 'name='+this.detail.name+'&param='+this.detail.name, this, this.onsuccesloadDataDepNbre);

this.tabFolder.activeTab(0);
 this.winMain.setVisible(true);


}
}
