/**
 *
 *  Fonction permettant l'affichage d'information concernant une carte ou une photo
 *
 */
function afficheParametre(strId, booEtat) {
	
	with(document.getElementById(strId).style) {
		
		visibility = 'hidden';
		if (booEtat) {
			visibility = 'visible';
		} 
	
	}
	
}

/**
 *
 *  Fonction permettant l'affichage d'information du formulaire
 *
 */
function afficheForm(strId, booEtat) {
	
	with(document.getElementById(strId).style) {
		
		visibility = 'hidden';
		if (booEtat) {
			visibility = 'visible';
		} 
	
	}
	
}



// REDIRECTION ACCUEIL
function redirection_js() { 
	x=setTimeout("window.location.href='index.php'",1500); 
}


// SUBMIT LE FORMULAIRE POUR CONNAITRE NAVIGATEUR SANS RECHARGER LA PAGE
function navigateur(f, fichier, method) {
	
	var xhr_object = null;	
		
	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(method, fichier, true);
	
	xhr_object.onreadystatechange = function anonymous() {
		if(xhr_object.readyState == 4){
			eval(xhr_object.responseText);	
		}
	}
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = "form="+f;
	xhr_object.send(data);

}



// RECHARGER LA LISTE D'UN SELECT SANS RECHARGER LA PAGE
// exemple ('form_01','idCommune','commune/liste_commune.php', 'POST') 
function rechargeSelect(f, champ, fichier, method) {
	
	var xhr_object = null;	
		
	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(method, fichier, true);
	
	xhr_object.onreadystatechange = function anonymous() {
		if(xhr_object.readyState == 4){
			eval(xhr_object.responseText);	
		}
	}
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = "form="+f+"&select=" + champ;
	xhr_object.send(data);

}

// CHANGER LA VALEUR D'UN INPUT
// exemple ('form_01','idCommune','rep/change_input_uti_externe.php', 'POST')

// NON TESTEE
function rechargeValeurInput(f, champ, fichier, method) {
	
	var xhr_object = null;	
		
	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(method, fichier, true);
	
	xhr_object.onreadystatechange = function anonymous() {
		if(xhr_object.readyState == 4){
			eval(xhr_object.responseText);	
		}
	}
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = "form="+f+"&input=" + champ;
	xhr_object.send(data);

}


/**

	Envoi données (AJAX)
	Permet d'afficher des données dans une page sans la recharger!
	Exemple d'appel : 
	envoi_donnees('theme='+document.forms['form_01'].theme1.value, 'theme/description_theme.php', 'POST', 'descr_theme_1')
	decription_theme : fichier appelé si clic sur le lien avec en param theme.
	descr_theme_1 : endroit ou l'on affiche le resultat

**/
function envoi_donnees(data, page, method, affichage) {
	
	var xhr_object = null;	
	
	if(window.XMLHttpRequest) { 
	   ///////////////////////////////////// Firefox et autres
	   xhr_object = new XMLHttpRequest();
	} else if(window.ActiveXObject){ 
		/////////////////////////////////// Internet Explorer
	   try {
       		xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (e) {
            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
       }
	} else { 
	    /////////////////////////////////// XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr_object = false; 
	}
	
	//définition de l'endroit d'affichage:
	if (document.getElementById){
			
		var content = document.getElementById(affichage);
	
	} else if (document.all){
		
		var content = document.all[affichage].value;
	
	} else if (document.layers){
		
		var content = document.layers[affichage].value;
	
	}
	
	content.style.display = "block";
	
	if(data == 'null'){
		// Ouverture du fichier sélectionné:
		xhr_object.open(method, page, true);
	} else {
		// Ouverture du fichier
		xhr_object.open(method, page+"?"+data, true);
	}
	
	xhr_object.onreadystatechange = function anonymous() {
		if (xhr_object.readyState == 4 && xhr_object.status == 200){
			
			try {
			
				content.innerHTML = xhr_object.responseText ;
			
			} catch (error) {
			
				alert('Erreur de chargement de données!');
			
			}
			// Tout s'est bien passé, on sort
			return;
		
		}
		// Chargement...
		if(xhr_object.readyState == 1){
		
			content.innerHTML = '<img class="img_chargement" src="/core/images/lightbox/loading.gif" alt="Chargement en cours..." />';
		
		}
	}
	
	if(method == "GET"){
		xhr_object.send(null);
	} else if(method == "POST"){
		xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr_object.send(data);
	}//fin elseif

}





/**
	OUVERTURE POPUP VISIBLE 

**/
function ouvrirVisible(lien, nomPopup, parametres) {
    
	var w = window.open(lien, nomPopup, parametres);
    //w.document.close();
    w.focus();
    
}

/**
	ARBORESCENCE (pour les éléments des tables ayant des IdParent)
**/
function afficheArboEnfant(param, href, method, affichage){
	if (document.getElementById(affichage).style.visibility=='hidden'){
		document.getElementById(affichage).style.visibility='visible';
		envoi_donnees(param, href, method, affichage);
	} else {
		document.getElementById(affichage).style.visibility='hidden';
		document.getElementById(affichage).style.display='none';
	}
	
}


/**
	ARBORESCENCE (de fichiers)
**/
function afficheArboEnfantFichier(param, href, method, affichage, idImage, image){
	
	if (document.getElementById(affichage).style.visibility=='hidden'){
		document.getElementById(affichage).style.visibility	='visible';
		document.getElementById(idImage).src				= image + "ouvert.gif";
		
		envoi_donnees(param, href, method, affichage);
		
	} else {
		document.getElementById(affichage).style.visibility	= 'hidden';
		document.getElementById(affichage).style.display	= 'none';
		document.getElementById(idImage).src				= image + "ferme.gif";
	}
	
}

function fermeFenetre(fenetre){
    fenetre.style.display='none';
    fenetre.parentNode.removeChild(fenetre);
}
/**
 * ajouteScript 
 * 
 * Ajoute au document le fichier js spécifié en paramètre si le fichier n'est pas déjà présent.
 */
function ajouteScript(url){
	var scriptTrouve = scriptExist(url);
	if (!scriptTrouve){
		var ndScript = document.createElement("script");
		ndScript.type= "text/javascript";
		ndScript.src = url;
		document.getElementsByTagName("head")[0].appendChild(ndScript);
	}
}
function scriptExist(url){
	var listScript = document.getElementsByTagName("script");
	var scriptTrouve = false;
	var i = 0;

	while ((i < listScript.length)&&(!scriptTrouve)){
		var script = listScript[i];
		scriptTrouve = ((script.src == "http://"+ window.location.host + url)||(script.src == url));
		i++;
	}
		
	return scriptTrouve ;
}
/* Renvoi la position left en absolu de objElementHtml */
function getAbsoluteLeft(objElementHtml){
	var posLeft = 0;
	var ObjParent = objElementHtml;
	while ((ObjParent != null)&&(ObjParent.localName != "BODY")){
		posLeft += ObjParent.offsetLeft;
		ObjParent = ObjParent.offsetParent;
	}
	return posLeft;
}
/* Renvoi la position top en absolu de objElementHtml */
function getAbsoluteTop(objElementHtml){
	var posTop = 0;
	var ObjParent = objElementHtml;
	while ((ObjParent != null)&&(ObjParent.localName != "BODY")){
		//alert(ObjParent.scrollTop);
		posTop += ObjParent.offsetTop - ObjParent.scrollTop;
		ObjParent = ObjParent.offsetParent;
	}
	return posTop;
}
navigator.bIsNetscape = function(){
	return (navigator.appName=="Netscape" )
}
navigator.bIsExplorer = function(){
	return ( navigator.appName=="Microsoft Internet Explorer" )
}

