/*
Fonction qui change l'état d'un enregistrement dans une table donnée
	PARAM : 
			table 	: table concernée par le changement
			id 		: identifiant de l'enregistrement à changer
			etat 	: état du champ etat avant le changement

	SORTIE :
			Résultat de la page AJAX
*/
function changeEtat(table,id,etat)
{
//	alert(" ajax_change_table_etat.php?table=" + table +" & id = " + id + "& etat=" + etat);
	var str = file("ajax_change_table_etat.php?table="+table+"&id="+id+"&etat="+etat);
//	alert(str);
	document.getElementById(table+"_etat_"+id).innerHTML = str;
}

/*
Fonction qui change le mode automatique ou manuel
	PARAM : 
			id 		: identifiant de l'enregistrement à changer
			auto 	: mode du champ etat avant le changement

	SORTIE :
			Résultat de la page AJAX
*/
function changePointInteretAuto(id,auto)
{
	var str = file("ajax_change_point_interet_auto.php?id="+id+"&auto="+auto);
	document.getElementById("auto_"+id).innerHTML = str;
}

/*
Fonction qui met la value du select à 0
	PARAM : 
			id 		: id du champ à mettre la valeur à 0
*/
function resetSelectValue(id)
{
	document.getElementById(id).value=0;
}

/*
Fonction qui met la value du input à vide
	PARAM : 
			id 		: id du champ à mettre la valeur vide
*/
function resetInputValue(id)
{
	document.getElementById(id).value='';
}
/*
Fonction qui permet de tri par nom de la recherche encours
	PARAM : 
			name_form 		: nom du formulaire
			name_value		: nom du champ tri
*/
function triRechercheNom(name_form,name_value)
{
	var tri_valeur=parseInt(document.getElementById(name_value+"_nom").value);
	document.getElementById(name_value+"_nom").value=1-tri_valeur;
	document.getElementById(name_value).value=1-tri_valeur;
	document.getElementById(name_form).submit();
}
/*
Fonction qui permet de tri par etat de la recherche encours
	PARAM : 
			name_form 		: nom du formulaire
			name_value		: nom du champ tri
*/
function triRechercheEtat(name_form,name_value)
{
	var tri_valeur=parseInt(document.getElementById(name_value+"_etat").value);
	document.getElementById(name_value+"_etat").value=1-tri_valeur;
	document.getElementById(name_value).value=3-tri_valeur;
	document.getElementById(name_form).submit();
}

/*
Fonction qui supprime un point d'interet
	PARAM : 
			id						: identifiant du point d'interet à supprimer
			name_form 		: nom du formulaire
*/
function supprimerPointInteret(id,name_form)
{
	var str=file('ajax_supprimer_point_interet.php?pin_id='+id);
	document.getElementById(name_form).submit();
}

/*
Fonction qui supprime une thematique
	PARAM : 
			id						: identifiant de la thematique à supprimer
			name_form 		: nom du formulaire
*/
function supprimerThematique(id,name_form)
{
	var str=file('ajax_supprimer_thematique.php?thq_id='+id);
	document.getElementById(name_form).submit();
}

/*
Fonction qui Modifie le tableau pour effectuer une modification d'un champ dans un table type:INPUT
	PARAM : 
			table 		: table concernée par le changement
			champ_id	: nom du champ id dans la table
			valeur_id 	: valeur de id
			champ 		: nom du champ de la table à modifier
			valeur 		: valeur du champ à modifier

	SORTIE :
			Résultat de la page AJAX
*/
function modifierAffichageTableauInput(table,champ_id,valeur_id,champ,valeur,size)
{
	var reg=new RegExp("'", "g");
	var str='<input id="'+valeur_id+'_'+table+'_'+champ+'" size="'+size+'" name="'+valeur_id+'_'+table+'_'+champ+'" value="'+valeur.replace(reg, "\'")+'" \/>&nbsp;<input type="image" src="images/bt_modifier.png" onclick="changeEnregistrementTableInput(\''+table+'\',\''+champ_id+'\',\''+valeur_id+'\',\''+champ+'\',\''+size+'\');" \/>&nbsp;<input type="image" src="images/bt_arriere.png" onclick="annuleEnregistrementTableInput(\''+table+'\',\''+champ_id+'\',\''+valeur_id+'\',\''+champ+'\',\''+valeur.replace(reg,"\\'")+'\',\''+size+'\');" \/>';
	document.getElementById(table+'_'+valeur_id+'_'+champ).innerHTML = str;
}
/*
Fonction qui change un champ dans un table
	PARAM : 
			table 		: table concernée par le changement
			champ_id	: nom du champ id dans la table
			valeur_id 	: valeur de id
			champ 		: nom du champ de la table à modifier

	SORTIE :
			Résultat de la page AJAX
*/
function changeEnregistrementTableInput(table,champ_id,valeur_id,champ,size)
{
	var valeur=document.getElementById(valeur_id+"_"+table+"_"+champ).value;
	var str = file('ajax_change_enregistrement_table_input.php?table='+table+'&champ_id='+champ_id+'&valeur_id='+valeur_id+'&champ='+champ+'&valeur='+valeur+'&size='+size);
	document.getElementById(table+"_"+valeur_id+"_"+champ).innerHTML = str;
}

/*
Fonction qui annule la modification du champ dans un table
	PARAM : 
			table 		: table concernée par l'annulation
			champ_id	: nom du champ id dans la table
			valeur_id : valeur de id
			champ 		: nom du champ de la table à recupérer

	SORTIE :
			Résultat de la page AJAX
*/
function annuleEnregistrementTableInput(table,champ_id,valeur_id,champ,valeur,size)
{
	var str = file('ajax_annule_enregistrement_table_input.php?table='+table+'&champ_id='+champ_id+'&valeur_id='+valeur_id+'&champ='+champ+'&valeur='+valeur+'&size='+size);
	document.getElementById(table+"_"+valeur_id+"_"+champ).innerHTML = str;
}

/*
fonction qui affiche une div
	PARAM : 
			id 		: identifiant de la div à afficher
*/
function afficheDiv(id)
{
	document.getElementById(id).style.visibility="visible";
	document.getElementById(id).style.display="block";
}

/*
fonction qui cache une div
	PARAM : 
			id 		: identifiant de la div à cacher
*/
function cacheDiv(id)
{
	document.getElementById(id).style.visibility="hidden";
	document.getElementById(id).style.display="none";
}

function afficheCacheDiv(id)
{
	if(document.getElementById(id).style.visibility == "hidden")
	{
		afficheDiv(id);
	}
	else
	{
		cacheDiv(id);
	}
}

/*
Fonction qui supprime un message
	PARAM : 
			id						: identifiant du message
*/
function supprimerMessage(id)
{
	var str=file('ajax_supprimer_message.php?mes_id='+id);
	window.location.reload();
}

/*
Fonction qui affiche la liste de images chargées
	PARAM : 
			annee		: annee de l'archive
			mois		: mois de l'archive
*/
function afficheListeImage(annee,mois)
{
	var str=file('ajax_liste_images.php?annee='+annee+'&mois='+mois);
	document.getElementById('image_liste').innerHTML=str;
}

/*
Fonction qui recupere les valeurs saisies pour afficher les images
	PARAM : 
*/
function changeListeImage()
{
	var mois = document.getElementById('mois_image').options[document.getElementById('mois_image').selectedIndex].value;
	var annee = document.getElementById('annee_image').options[document.getElementById('annee_image').selectedIndex].value;
	afficheListeImage(annee,mois);
}

/*
Fonction qui supprime une image
	PARAM : 
			nom_image	: url de l'imge à supprimer
*/
function supprimerImage(nom_image)
{
	var str=file('ajax_supprimer_image.php?nom_image='+nom_image);
	changeListeImage();
}

/*
Fonction qui supprime une relation commerciale
	PARAM : 
			id						: identifiant de la relation commerciale
*/
function supprimerRelationCommerciale(id)
{
	var str=file('ajax_supprimer_relation_commerciale.php?rco_id='+id);
	window.location.reload();
}

/*
Fonction qui supprime une typologie
	PARAM : 
			id						: identifiant de la typologie
*/
function supprimerTypologie(id)
{
	var str=file('ajax_supprimer_typologie.php?typ_id='+id);
	window.location.reload();
}

/*
Fonction qui supprime une typologie
	PARAM : 
			uni_id				: identifiant de l'univers
			ctx_id				: identifiant du contexte
*/
function supprimerUniversContexte(uni_id,ctx_id)
{
	var str=file('ajax_supprimer_univers_contexte.php?uct_uni_id='+uni_id+'&uct_ctx_id='+ctx_id);
	window.location.reload();
}

/*
Fonction qui affiche le formulaire d'ajout de parametres
	PARAM : 
*/
function afficheFormAjoutParametres()
{
	if(document.getElementById('nb_ajout').value.replace(/(^\s*)|(\s*$)/g,'').length > 0)// si le champ est saisie
	{
		if(document.getElementById('nb_ajout').value*0 == 0)//Vérification que le champ saisie est un nombre
		{
			var nb=document.getElementById('nb_ajout').value;
			if(confirm('Création de '+nb+' nouveau(x) paramètre(s) !'))
			{
				var str='<form name="form_ajout" action="index_liste_parametres.php" method="post">';
				for(var cpt=0;cpt<nb;cpt+=1)
				{
					str+='<b>Libellé<b> : <input type="text" name="par_libelle['+cpt+']" size="30" > <b>Valeur<b> : <input type="text" name="par_valeur['+cpt+']" size="60" ><br />';
				}
				str+='<input type="image" src="images/bt_ajouter.png" onclick="document.forms[\'form_ajout\'].submit();" /><input type="image" src="images/bt_arriere.png" onclick="afficheNombreAjoutParametres();" /></form>';
				document.getElementById('ajout_parametres').innerHTML=str;
			}
		}
		else
		{
			alert('Vous n\'avez pas saisie un nombre.\n Veuillez saisir un nombre !');
			document.getElementById('nb_ajout').value='';
		}
	}
	else
	{
		alert('Vous n\'avez rien saisie.\n Veuillez saisir un nombre !');
		document.getElementById('nb_ajout').value='';
	}
}

/*
Fonction qui affiche le nombre d'ajout de parametres
	PARAM : 
*/
function afficheNombreAjoutParametres()
{
	var str='Nombre de paramètres à ajouter : <input id="nb_ajout" name="nb_ajout" value="" size="1" /> <input type="image" src="images/bt_ajouter.png" onclick="afficheFormAjoutParametres();"/>';
	document.getElementById('ajout_parametres').innerHTML=str;
}

/*
Fonction qui supprime un type_information
	PARAM : 
			id						: identifiant de type_information à supprimer
			name_form 		: nom du formulaire
*/
function supprimerTypeInformation(id,name_form)
{
	var str=file('ajax_supprimer_type_information.php?tin_id='+id);
	if(str!="OK")
		alert(str);
	document.getElementById(name_form).submit();
}

/*
Fonction qui affiche un information
	PARAM : 
			id						: identifiant de information à afficher
*/
function afficheDocument(id)
{
	document.getElementById('doc').value=id;
	document.getElementById('vue_document').submit();
}

/*
Fonction qui affiche la liste des dernieres informations dans la page index_liste_theme
	PARAM : 
			id						: identifiant de theme 
*/
function afficherDerniersInformations(id)
{
	var str=file('ajax_lister_dernieres_informations.php?thm_id='+id);
	document.getElementById('liste_information_'+id).innerHTML=str;
}

/*
Fonction qui ajout ou supprimer un point_interet_contact
	PARAM : 
			ctc_id 		: identifiant du contact
			pin_id 		: identifiant du point_interet
			action	 	: 'true' pour ajouter, 'false' pour supprimer

	SORTIE :
			Résultat de la page AJAX
*/
function changePointInteretContact(ctc_id,pin_id,etat)
{
/*	alert(document.getElementById('contact_'+ctc_id+'_'+pin_id).checked);*/
	if(document.getElementById('contact_'+ctc_id+'_'+pin_id).checked)
		var str = file("ajax_point_interet_contact.php?ctc_id="+ctc_id+"&pin_id="+pin_id+"&action=ajouter");
	else
		var str = file("ajax_point_interet_contact.php?ctc_id="+ctc_id+"&pin_id="+pin_id+"&action=supprimer");
/*	alert(str);*/
}

/*
Fonction qui change dans le moteur de recherche le theme Pour le CREDIT
	PARAM : 
			objt 		: select de la page reporting

	SORTIE :
*/
function changeCreditRecherche(objt)
{
//	alert(document.getElementById('rech_theme_id').value+"="+objt.value);
	document.getElementById('rech_theme_id').value=objt.value;
	document.getElementById('form_recherche').submit();
}

/*
fonction qui affiche une info Bulle
	PARAM : 
			id 		: identifiant de la balise HTML appelant l'info bulle
			texte	:	texte à afficher
*/
function afficheInfoBulle(id,texte)
{
	document.getElementById("infoBulle").style.top=(getTop(document.getElementById(id))+30)+"px";
	document.getElementById("infoBulle").style.left=(getLeft(document.getElementById(id))+30)+"px";
	document.getElementById("infoBulle").innerHTML=texte;
	document.getElementById("infoBulle").style.visibility="visible";
	document.getElementById("infoBulle").style.zIndex=100;
}

/*
fonction qui cache une info Bulle
	PARAM : 
*/
function cacheInfoBulle()
{
	document.getElementById("infoBulle").style.visibility="hidden";
}

function getLeft(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord gauche de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else 
        return (MyObject.offsetLeft);
    } 
function getTop(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord haut de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }

/*
fonction qui affiche une div parmi la liste des div a afficher
	PARAM : 
			id 		: identifiant de la div à afficher
			rep		: repertoire de l'archive
*/
function afficheDivChoisi(id,rep)
{
	document.getElementById('liste_affiche').value=id;
	var tab_div = new Array("image_liste","pdf_liste","doc_liste","xls_liste","swf_liste","flv_liste");
	for (var i=0; i < tab_div.length; ++i)
	{
		if(tab_div[i]==id)
		{
			afficheDiv(tab_div[i]);
			changeListeImage(rep);
			document.getElementById(tab_div[i]+'_td').className="menu_select_type";
		}
		else
		{
			cacheDiv(tab_div[i]);
			document.getElementById(tab_div[i]+'_td').className="aucune";
		}
	}
}

/*
Fonction qui affiche la liste de images chargées
	PARAM : 
			rep			: repertoire de l'archive
			annee		: annee de l'archive
			mois		: mois de l'archive
*/
function afficheListeImage(rep,annee,mois)
{
	var div_affiche = document.getElementById('liste_affiche').value;
	var str=file('bibliotheque/html/ajax_liste_images.php?rep='+rep+'&annee='+annee+'&mois='+mois+'&div_affiche='+div_affiche);
	document.getElementById(div_affiche).innerHTML=str;
//	alert(div_affiche);
}

/*
Fonction qui recupere les valeurs saisies pour afficher les images
	PARAM : 
			rep			: repertoire de l'archive
*/
function changeListeImage(rep)
{
	var mois = document.getElementById('mois_image').options[document.getElementById('mois_image').selectedIndex].value;
	var annee = document.getElementById('annee_image').options[document.getElementById('annee_image').selectedIndex].value;
	afficheListeImage(rep,annee,mois);
}

/*
Fonction qui supprime une image
	PARAM : 
			nom_image	: url de l'imge à supprimer
			rep				: repertoire de l'archive
*/
function supprimerImage(nom_image,rep)
{
	var str=file('bibliotheque/html/ajax_supprimer_image.php?nom_image='+nom_image);
	//alert(str);
	changeListeImage(rep);
}

/* fonction qui recharge les années du formulaire de recherche en fonction du theme actif */
function changeAnneeTheme()
{
	var theme = document.getElementById('rech_theme_id').options[document.getElementById('rech_theme_id').selectedIndex].value;
	var str=file('ajax_change_annee.php?theme_id='+theme);
//		alert(str);
	document.getElementById('rech_annee').innerHTML=str;
}

