<!--

// --- Fonction pour creation de l'objet XMLRequest AJAX --- //
function createRequestObject() {
    
    var xhr;
    
    try {
    	xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (err) {
    	try {
    		xhr = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch(err) {
    		xhr = false;
    	}
    }
    
    if(!xhr && typeof XMLHttpRequest != 'undefined') {
    	xhr = new XMLHttpRequest();
    }
    
    return xhr;
}
var http = createRequestObject();

function annuler_recherche(mode, init_carte, id_provenance) {
    if(id_provenance == '') {        
        var champs_region = document.getElementById('liste_region');                
    } else {               
        var champs_region = document.getElementById('liste_region_' + id_provenance);        
    }

    switch(mode) {
        case 'visite' :
            init_champs_formulaire('criteres_' + id_provenance + '[]');
            if(init_carte == 'O') { 
                gestion_carte('', '', 'VISITE', id_provenance); 
                champs_region.selectedIndex = 0;
            }
            
            gestion_resultat_visite(id_provenance)
            break;
        case 'guide' :            
            init_champs_formulaire('criteres_' + id_provenance + '[]');
            if(init_carte == 'O') { 
                gestion_carte('', '', 'GUIDE', id_provenance); 
                champs_region.selectedIndex = 0;
            }
            document.getElementById('date_visite_' + id_provenance + '_ID').value = '';
            gestion_resultat_guide(id_provenance)
            break;
    }     
    
       
}

function gestionClasseMenu(nb_menu, menu_actif) {
    for(i_menu = 0; i_menu < nb_menu; i_menu++) {
        if ((i_menu + 1) == menu_actif) {
            document.getElementById('button' + (i_menu+1)).className = 'lien_bloc_nav_niv1_ON';
        } else {
            document.getElementById('button' + (i_menu+1)).className = 'lien_bloc_nav_niv1';
        }
    }
}

function choix_image_carousel(cle_origine, cle_destination) {    
    var image_origine = document.getElementById('photo_carousel_' + cle_origine);
    var lien_image_origine = document.getElementById('lien_carousel_' + cle_origine);
    var image_destination = document.getElementById('photo_fiche_detail_' + cle_destination); 
    var lien_image_destination = document.getElementById('lien_photo_fiche_detail_' + cle_destination);
    var lien_image_destination_compteur = document.getElementById('lien_photo_fiche_detail_' + cle_destination + '_' + cle_origine);
    //alert(lien_image_destination_compteur);
    lien_image_destination_compteur.href = lien_image_destination.href;
    lien_image_destination.href = image_origine.src;
    image_destination.src = image_origine.src;
    
    lien_image_destination.title = lien_image_origine.title;
    lien_image_destination.alt = lien_image_origine.alt;
    
    image_destination.title = image_origine.title;
    image_destination.alt = image_origine.alt;
    
}

function init_champs_formulaire(liste_champs_name) {
    
    tableau_champs_name = liste_champs_name.split('|');
    for(i_champ_name = 0; i_champ_name < tableau_champs_name.length; i_champ_name++) {
        name_champs_en_cours = tableau_champs_name[i_champ_name];        
        liste_champs = document.getElementsByName(name_champs_en_cours); 
        
        for(i_champ = 0; i_champ < liste_champs.length; i_champ++) {
            champs_en_cours = liste_champs[i_champ];
                                    
            switch(champs_en_cours.type) {
                case 'checkbox' :
                    champs_en_cours.checked = false;        
                    break;
                case 'select-one' :                    
                    champs_en_cours.value = '';
                    break;
            }                        
        }
        
    }
    
}

// --- Gestion des onglets --- //
function gestion_onglets(onglet_select) {

    var tableau_onglet = new Array('descriptif', 'localisation', 'avis', 'dispo_resa');
    
    /*for each(onglet_en_cours in tableau_onglet) {*/
    for(i_onglet = 0; i_onglet < tableau_onglet.length; i_onglet++) {
        onglet_en_cours = tableau_onglet[i_onglet];
        if(document.getElementById('onglet_' + onglet_en_cours) != null) {
            if(onglet_en_cours == onglet_select) {
                document.getElementById('bouton_' + onglet_en_cours).className='lien_onglet_infos_detail_presta_ON';
                document.getElementById('onglet_' + onglet_en_cours).style.display = 'block';    
            } else {
                document.getElementById('bouton_' + onglet_en_cours).className='lien_onglet_infos_detail_presta';
                document.getElementById('onglet_' + onglet_en_cours).style.display = 'none';
            }
        }
    }    
}
        
// --- Gestion du survole de la carte --- //
function gestion_carte(id, mode, provenance, id_provenance) {
                   
    if(id_provenance == '') {         
        var img_carte = document.getElementById('carte');
        var champs_region = document.getElementById('liste_region');                
    } else {        
        var img_carte = document.getElementById('carte_' + id_provenance);
        var champs_region = document.getElementById('liste_region_' + id_provenance);        
    }    
    
    if(mode == 'LISTE_DEROULANTE') {
        tab_id = id.split('[');
        id = tab_id[1];        
    }
    if(typeof(id) == 'undefined' || id == '') { id = 'INDIFFERENT'; }    
                               
    // --- Changement d'image de la carte --- //
    lien_carte = 'http://new.akopso.com/images/cartes/' + id + '.png';            
    img_carte.src = lien_carte;
         
    
    // --- Sélection de la région dans la liste déroulante --- //    
    for(i_region = 0; i_region < champs_region.length; i_region++) {
        cle_region = 'REGIONTOU[' + id + '[V';
        if(champs_region[i_region].value == cle_region) { champs_region[i_region].selected = true; }
    }         
        
    // --- Chargement des résultats --- //
    if(provenance == 'VISITE') { gestion_resultat_visite(id_provenance); }
    if(provenance == 'GUIDE') { gestion_resultat_guide(id_provenance); }        
                       
}

function gestion_ajax(lien, action_eval, action_js_fin) {
    var html = new String();    
	// Ouverture de la requete GET
	http.open('get', lien);              
	// Recupération du retour de la fonction	
	http.onreadystatechange = function() {
         if(http.readyState == 4){         	
	        var response = http.responseText;	        	        
	        // Récupération du code HTML (echo)
	        if(action_eval != undefined && action_eval == 'O' && response != '') {                          	           
               eval(response);                              	           
	        } else {
	        
	           // Si on a une action JS a executer, on la lance ici
               if(action_js_fin != undefined && action_js_fin != '') {		           
                   eval(action_js_fin);  
               }
	           
	           return response;	                                                                                                                 	           	           
            }                           
	    }
    }    
	http.send(null);		
}

// --- Gestion dynamique des résultat des visites --- //
function gestion_resultat_visite(id_provenance) {
                
    var formulaire = document.forms['recherche_visite_' + id_provenance];       	    
    var champs_criteres = formulaire.elements['criteres_' + id_provenance + '[]'];
    var champs_date_visite = document.getElementById('date_visite_' + id_provenance + '_ID');                     
    var chaine_criteres = '';        
	var passage = 0;		
	                   
	// --- Boucle de recupération des criteres --- //
	for(i = 0; i < champs_criteres.length; i++) {        		
		if(champs_criteres[i].type == "checkbox") {
			if(champs_criteres[i].checked == true) {					
				if(passage > 0) { chaine_criteres += '&'; }
                chaine_criteres += 'criteres_prestation[]=' + champs_criteres[i].value;
				passage++;
			}			
		} else if(champs_criteres.type == 'select-one' && champs_criteres[i].selected && champs_criteres[i].value != '') {						  	
			if(passage > 0) { chaine_criteres += '&'; }
            chaine_criteres += 'criteres_prestation[]=' + champs_criteres[i].value;
			passage++;						
		} else {
		      
		    if(id_provenance == 'VISITE_GUIDEES' && champs_criteres[i].value != '') {
		        if(passage > 0 && champs_criteres[i].value != '') { chaine_criteres += '&'; }  
                chaine_criteres += 'criteres_prestation[]=' + champs_criteres[i].value;
                passage++;
            }			
        }		
	}
    
    lien_ajax = 'ajax.php?action=nb-resultats-visite&' + chaine_criteres;
    lien_ajax += '&provenance=' + id_provenance;     
    if(champs_date_visite != null) {
        lien_ajax += '&date_visite=' + champs_date_visite.value;
    }         
    
    // --- Affichage message attente pendant calcul --- //
	document.getElementById('nb-resultat-visite-' + id_provenance).innerHTML = '<img src="/images/loading_ajax.gif"  alt="" border="0" />';	
	// --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			  
	        document.getElementById('nb-resultat-visite-' + id_provenance).innerHTML = html;
	    }
    }
	http.send(null);        
}

// --- Gestion dynamique des résultat des guides --- //
function gestion_resultat_guide(id_provenance) {


    var formulaire = document.forms['recherche-guide-' + id_provenance];
    var champs_criteres = formulaire.elements['criteres_' + id_provenance + '[]'];
    var champs_date_visite = document.getElementById('date_visite_' + id_provenance + '_ID');
    var chaine_criteres = '';        
	var passage = 0;
	
	// --- Boucle de recupération des criteres --- //
	for(i = 0; i < champs_criteres.length; i++) {
        if(passage > 0) { chaine_criteres += '&';}		
		if(champs_criteres[i].type == "checkbox") {
			if(champs_criteres[i].checked == true) {					
				chaine_criteres += 'criteres_prestataire[]=' + champs_criteres[i].value;
				passage++;
			}			
		} else if(champs_criteres[i].value != '') {						  	
			chaine_criteres += 'criteres_prestataire[]=' + champs_criteres[i].value;
			passage++;						
		}		
	}
    
    lien_ajax = 'ajax.php?action=nb-resultats-guide&' + chaine_criteres; 
    if(champs_date_visite != null) {
        lien_ajax += '&date_visite=' + champs_date_visite.value;
    }     
    
    // --- Affichage message attente pendant calcul --- //
	document.getElementById('nb-resultat-guide-' + id_provenance).innerHTML = '<img src="/images/loading_ajax.gif"  alt="" border="0" />';	
	// --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			  
	        document.getElementById('nb-resultat-guide-' + id_provenance).innerHTML = html;
	    }
    }
	http.send(null);        
}

// --- Gestion de l'affichage de la liste des guides réservables --- //
function gestion_guide_reservable(cle_visite) {   
   
    var champs_jour = document.getElementById('datedeb_ID');
    var champs_horaire = document.getElementById('horaire_visite');
    var div_liste_guide = 'affichage-liste-guide';
    var nb_participant = document.getElementById('participants').value;
    var langue_visite = document.getElementById('langue_visite').value; 			            
    var type_prestation = document.getElementById('type_prestation').value;
    var duree_horaire_visite = document.getElementById('duree_horaire_visite').value;    
    var html_loading = '';
    	
	lien_ajax = 'ajax.php?action=gestion-guide-disponible';
	lien_ajax += '&cle_visite=' + cle_visite;
	lien_ajax += '&personnes[ENFANTS]=0';
    lien_ajax += '&nb_participant=' + nb_participant;	    
    lien_ajax += '&date_visite=' + champs_jour.value;
    if(champs_horaire != null) {
        lien_ajax += '&horaire=' + champs_horaire.value;        
        lien_ajax += '&horaires=' + champs_horaire.value;
    }
    lien_ajax += '&duree=1';
    lien_ajax += '&duree_horaire_visite=' + duree_horaire_visite; 
    lien_ajax += '&action_resa=recherche-ajax';
    lien_ajax += '&langue_visite=' + langue_visite;
    lien_ajax += '&langue_guide=' + langue_visite;            
    lien_ajax += '&type_prestation=' + type_prestation;
            
    // --- Affichage message attente pendant calcul --- //
    html_loading = '<img src="/images/loading_ajax2.gif"  alt="" border="0" style="margin-left:50%"/>';    
    document.getElementById(div_liste_guide).innerHTML = html_loading;
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			            
	        document.getElementById(div_liste_guide).innerHTML = html;            
            	        	        
	    }
    }
	http.send(null);		
    
}

// --- Gestion de la tarification des visites --- //
function gestion_tarification_visite(cle_visite) {   
   
    var champs_jour = document.getElementById('datedeb_ID');
    var champs_horaire = document.getElementById('horaire_visite');    
    var nb_participant = document.getElementById('participants').value;
    var langue_visite = document.getElementById('langue_visite').value;			                
    var duree_horaire_visite = document.getElementById('duree_horaire_visite').value;
    var div_liste_tarif = 'affichage-liste-tarif';    
    var html_loading = '';
    	
	lien_ajax = 'ajax.php?action=gestion-tarification-visite';
	lien_ajax += '&cle_visite=' + cle_visite;
	lien_ajax += '&personnes[ENFANTS]=0';
    lien_ajax += '&nb_participant=' + nb_participant;	    
    lien_ajax += '&date_visite=' + champs_jour.value;
    if(champs_horaire != null) {
        lien_ajax += '&horaire=' + champs_horaire.value;        
        lien_ajax += '&horaires=' + champs_horaire.value;
    }
    lien_ajax += '&duree=1';
    lien_ajax += '&duree_horaire_visite=' + duree_horaire_visite; 
    lien_ajax += '&action_resa=recherche-ajax';
    lien_ajax += '&langue_visite=' + langue_visite;    
            
    // --- Affichage message attente pendant calcul --- //
    html_loading = '<img src="/images/loading_ajax2.gif"  alt="" border="0" style="margin-left:50%"/>';    
    document.getElementById(div_liste_tarif).innerHTML = html_loading;
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			            
	        document.getElementById(div_liste_tarif).innerHTML = html;	        	        
	    }
    }
	http.send(null);		
    
}

// --- Gestion de l'affichage de la liste des tarifs de guidage --- //
function gestion_tarif_guidage(cle_guide) {   
   
    var champs_jour = document.getElementById('datedeb_ID');
    var champs_horaire = document.getElementById('horaire_guidage');
    var champs_duree = document.getElementById('duree_guidage');
    var div_liste_tarif = 'affichage-liste-tarif';    
    var langue_guide = document.getElementById('langue_guide').value;			                
    var nb_participant = document.getElementById('nb_participant').value;
    var html_loading = '';
    	
	lien_ajax = 'ajax.php?action=gestion-tarif-disponible';
	lien_ajax += '&cle_guide=' + cle_guide;
	lien_ajax += '&personnes[ENFANTS]=0';
    lien_ajax += '&nb_participant=' + nb_participant;	    
    lien_ajax += '&date_guidage=' + champs_jour.value;
    if(champs_horaire != null) {
        lien_ajax += '&horaire=' + champs_horaire.value;
    }
    if(champs_duree != null) {
        lien_ajax += '&duree_guidage=' + champs_duree.value;
    }        
    lien_ajax += '&action_resa=recherche-ajax';
    lien_ajax += '&langue_guide=' + langue_guide;           
         
    // --- Affichage message attente pendant calcul --- //
    html_loading = '<img src="/images/loading_ajax2.gif"  alt="" border="0" style="margin-left:50%"/>';    
    document.getElementById(div_liste_tarif).innerHTML = html_loading;
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			  
	        document.getElementById(div_liste_tarif).innerHTML = html;	        	        
	    }
    }
	http.send(null);		
    
}

/**
 * Conversion d'une date du format classique au format stock
 * @param time
 */
function date_classique_vers_date_stock(date_classique) {
    var jour = date_classique.substring(0,2);
    var mois = date_classique.substring(3,5);
    var annee = date_classique.substring(6,10);
    return annee + mois + jour;  
}

// --- Gestion des heures possibles en fonction d'une prestation et d'un jour --- //
function gestion_heure_visite(cle_visite, provenance) {        

    var champs_horaire_visite = document.getElementById('horaire_visite');
    var champs_jour = document.getElementById('datedeb_ID');
    var div_horaire = 'zone_horaire_visite';    
    var date_champs_jour_stock = date_classique_vers_date_stock(champs_jour.value);
    
    if(provenance == undefined) { provenance = 'VISITE_GUIDEES'; }        
    
    lien_ajax = 'ajax.php?action=gestion-horaire-visite';
    lien_ajax += '&cle_visite=' + cle_visite;
    lien_ajax += '&date_visite=' + champs_jour.value;      
    if(champs_horaire_visite != null) { lien_ajax += '&horaire_visite=' + champs_horaire_visite.value; }    
    
    document.getElementById('zone_date_visite').innerHTML = champs_jour.value;    
    if(date_champs_jour_stock <= document.getElementById('date_max_last_minute').value) {
         document.getElementById('alerteLastMinute').style.display = 'block';
    } else {
        document.getElementById('alerteLastMinute').style.display = 'none';
    }
    
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
                 	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;	        
			  
	        //document.getElementById(div_horaire).innerHTML = html;
	        document.getElementById(div_horaire).innerHTML = html;
	        
	        if(provenance == 'VISITE_GUIDEES') { gestion_guide_reservable(cle_visite); }
	        if(provenance == 'VISITES_COLLECTIVES') { gestion_tarification_visite(cle_visite); }
	    }
    }
	http.send(null);
    
}

// --- Gestion des durée de guidage --- //
function gestion_duree_guidage(cle_guide) {            
    
    var div_duree = 'zone_duree_guidage';
    
    lien_ajax = 'ajax.php?action=gestion-duree-guidage';
    lien_ajax += '&cle_guide=' + cle_guide;                 
    
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			  
	        document.getElementById(div_duree).innerHTML = html;
	        
	        gestion_heure_guidage(cle_guide);
	        
	    }
    }
	http.send(null);
   
}

// --- Gestion des heures possibles en fonction d'un guide, d'une durée et d'un jour --- //
function gestion_heure_guidage(cle_guide) {        

    var champ_horaire_guidage = document.getElementById('horaire_guidage');
    var champ_duree_guidage = document.getElementById('duree_guidage');
    var champs_jour = document.getElementById('datedeb_ID');
    var date_champs_jour_stock = date_classique_vers_date_stock(champs_jour.value);
    var div_horaire = 'zone_horaire_guidage';    
    
    lien_ajax = 'ajax.php?action=gestion-horaire-guidage';
    lien_ajax += '&cle_guide=' + cle_guide;
    lien_ajax += '&date_guidage=' + champs_jour.value;      
    if(champ_duree_guidage != null) { lien_ajax += '&duree_guidage=' + champ_duree_guidage.value; }    
    if(champ_horaire_guidage != null) { lien_ajax += '&horaire_guidage=' + champ_horaire_guidage.value; }
    
    document.getElementById('zone_date_guidage').innerHTML = champs_jour.value;
    if(date_champs_jour_stock <= document.getElementById('date_max_last_minute').value) {
         document.getElementById('alerteLastMinute').style.display = 'block';
    } else {
        document.getElementById('alerteLastMinute').style.display = 'none';
    }
             
    // --- Ouverture de la requete GET --- //
	http.open('get', lien_ajax);
	// --- Recupération du retour de la fonction --- //
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // --- Récupération du code HTML --- //
	        html = response;
			  
	        document.getElementById(div_horaire).innerHTML = html;
	        
	        gestion_tarif_guidage(cle_guide);
	    }
    }
	http.send(null);
    
}

function gestion_affichage(id, mode) {
  var element;
  var element_lien;  
  tableau_id = id.split('|');  
  for(i=0; i < tableau_id.length; i++) {    
		if(document.getElementById(tableau_id[i])){
			element = document.getElementById(tableau_id[i]);
			element_lien = document.getElementById("lien_" + tableau_id[i]); 
			if(mode == 'montrer') {  
			  element.style.display = 'block';
			  element_lien.className="lien_ON";
			}
			if(mode == 'cacher') {  
			  element.style.display = 'none';
			  element_lien.className="lien_OFF";
			} 
		} 
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



//-->
