// JavaScript Document

// on crée un objet pour requête asynchrone
function getXhr()
	{
	var xhr ;
	if (window.XMLHttpRequest)                 //  Objet de la fenêtre courant
		xhr = new XMLHttpRequest();     //  Firefox, Safari, ...
	else if (window.ActiveXObject)                    //  Version Active
  		xhr = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer 
	return xhr;
	}
	


/************* Tableau - Traitement *************/

/******* admin_add_cat ******/

function affiche_cat()
	{
	var xhr = getXhr();
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			document.getElementById('admin_add_cat_aff_cat_ajax').innerHTML = xhr.responseText;
			Effect.BlindDown('admin_add_cat_aff_cat_ajax');
			Effect.Fade('aff_cat_link');
			}
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('add_cat_aff_cat=');
	}

function supp_cat(id,nom)
	{
	if (confirm('Vous souhaiter supprimer la categorie ' + nom + ' ?\n\nAttention, toutes suppression est irreversible et entraine une suppression totale des donnees de cette categorie.')) 
		{
		document.getElementById('admin_add_cat_aff_cat_ajax').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		var xhr = getXhr();
	
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('admin_add_cat_aff_cat_ajax').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('supp_cat=' + id);
		}
	}

//Modification du nom d'une catégorie
function mod_name_cat(id,cat,div) 
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('admin_add_cat_aff_cat_ajax').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_name_cat=' + id + '&mod_name_cat=' + cat);
	}




/********* admin_mod_cat.php ************/
	
function mod_name_chp(id_cat,chmp,new_chmp,div,typ,type) 
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('mod_cat_tab').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_chp_cat=' + id_cat + '&mod_chp=' + chmp + '&new_chp=' + new_chmp + '&typ_chp=' + typ + '&old_typ_chp=' + type);
	}
	

function supp_chp(id,nom,typ)
	{
	if (confirm('Vous souhaiter supprimer le champ ' + nom + ' ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		document.getElementById('mod_cat_tab').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		var xhr = getXhr();
	
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('mod_cat_tab').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_supp_chp_cat=' + id + '&supp_chp=' + nom + '&supp_type_chp=' + typ);
		}
	}


	
/********** admin_aff_cat.php ***********/

function affiche_tableau(id_cat,pg,group)
	{
	var xhr = getXhr();
	document.getElementById('aff_donnees_load').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			document.getElementById('aff_cat_tab').innerHTML = xhr.responseText;
			document.getElementById('aff_donnees_load').innerHTML = "";
			}
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('aff_id_cat=' + id_cat + '&group=' + group + '&pg_tab=' + pg);	
	}



/*****Tri de cellule **/
function tri_cellule(id_cat,nom_champ,group,pg)
	{
	var xhr = getXhr();
	document.getElementById('aff_donnees_load').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			document.getElementById('aff_cat_tab').innerHTML = xhr.responseText;
			document.getElementById('aff_donnees_load').innerHTML = "";
			}
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('tri_cell_id_cat=' + id_cat + '&tri_cell_chmp=' + nom_champ + '&tri_cell_type=ASC&group=' + group + '&pg_tab=' + pg);	
	}
	
	
function tri_cellule_dec(id_cat,nom_champ,group,pg)
	{
	var xhr = getXhr();
	document.getElementById('aff_donnees_load').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			{
			document.getElementById('aff_cat_tab').innerHTML = xhr.responseText;
			document.getElementById('aff_donnees_load').innerHTML = "";
			}
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('tri_cell_id_cat=' + id_cat + '&tri_cell_chmp=' + nom_champ  + '&tri_cell_type=DESC&group=' + group + '&pg_tab=' + pg);	
	}
	
	



/*********** Données d'une catégorie - Traitement **********/

/*Modification d'une donnée d'une catégorie */
function mod_elt(id_cat,id_elt,elt,chp,div,tri,type_tri,group,pg) 
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_cat_tab').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_elt_cat=' + id_cat + '&mod_elt=' + id_elt + '&new_elt=' + elt + '&mod_elt_chp=' + chp + '&tri_chmp=' + tri + '&type_tri=' + type_tri + '&group=' + group + '&pg_tab=' + pg);
	}
	


/* Traitement Ajax pour la suppression d'un élément d'une catégorie */
function supp_elt(id,elt,tri,type_tri,group,pg)
	{
	if (confirm('Vous souhaiter supprimer cette donnee ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		document.getElementById('aff_cat_tab').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		var xhr = getXhr();
	
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('aff_cat_tab').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_supp_elt_cat=' + id + '&id_supp_elt=' + elt + '&tri_chmp=' + tri + '&type_tri=' + type_tri + '&group=' + group + '&pg_tab=' + pg);
		}
	}
	
	
	
	
/***************** Traitement pour les annonces **************/

function supp_annonce(id,page)
	{
	if (confirm('Vous souhaiter supprimer cette annonce ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		document.getElementById('annonce_container_ann').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		var xhr = getXhr();
	
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('annonce_container_ann').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_supp_annonce=' + id + '&id_supp_annonce_pg=' + page);
		}	
	}


//Modification d'une annonce
function mod_annonce(id,annonce,div,pg) 
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('annonce_container_ann').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_annonce=' + id + '&mod_annonce=' + annonce + '&mod_annonce_pg=' + pg);
	}
	
	
//Ajout d'une annonce
function add_annonce() 
	{
	var xhr = getXhr();
	var annonce = document.getElementById('new_annonce').value;
	document.getElementById('annonce_container_ann').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if (xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('annonce_container_ann').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('add_annonce=' + annonce);
	}
	
	
//Ajout d'une annonce
function affiche_annonce(pg) 
	{
	var xhr = getXhr();
	document.getElementById('pg_annonce').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('annonce_container_ann').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('pg_affiche_annonce=' + pg);
	}
	
	
	
/******* Galerie Photo  *********/

function add_galerie(gal)
	{
	var xhr = getXhr();
	document.getElementById('ajax_galerie').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('ajax_galerie').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('add_gallery=' + gal);	
	}
	
	
function affiche_mod_galerie(gal)
	{
	var xhr = getXhr();
	document.getElementById('aff_galerie').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_galerie').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('aff_mod_galerie=' + gal);	
	}
	
	
function supp_photo(img,gal)
	{
	if (confirm('Vous souhaiter supprimer cette photo ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		var xhr = getXhr();
		document.getElementById('aff_galerie').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('aff_galerie').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_supp_photo=' + img + '&supp_photo_galerie=' + gal);
		}
	}
	
	
function mod_title_photo(id,val,div,gal)
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_galerie').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_title_photo=' + id + '&val_mod_title_photo=' + val + '&gal_mod_title_photo=' + gal);
	}
	
	
function mod_desc_photo(id,val,div,gal)
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_galerie').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_desc_photo=' + id + '&val_mod_desc_photo=' + val + '&gal_mod_desc_photo=' + gal);
	}
	
	
	
	
/** ----------- Cartographie -------------------- **/

function add_table_color(id,color)
	{
	var xhr = getXhr();
	document.getElementById('old_tab_color').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('admin_cartographie').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('add_tab_color_id=' + id + '&add_tab_color=' + color);	
	}
	
	
function add_coord(id,cat,lat,long)
	{
	var xhr = getXhr();
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_coord').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('add_coord_id=' + id + '&add_coord_id_cat=' + cat + '&add_coord_id_lat=' + lat + '&add_coord_id_long=' + long);	
	}
	
	
function affiche_info_carte(ident)
	{
	var xhr = getXhr();
	document.getElementById('aff_info_carte').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_info_carte').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('info_carte_id=' + ident);	
	}
	
	
function mod_color_cat(id,color,div) 
	{
	var xhr = getXhr();
	document.getElementById(div).innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('old_tab_color').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_mod_color_cat=' + id + '&mod_color_cat=' + color);
	}
	
	
//Affiche la liste des colonnes d'un tableau pour la selection des données a afficher sur la carte
function affiche_select_col_carte(id)
	{
	var xhr = getXhr();
	document.getElementById('aff_select_col_carte').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('aff_select_col_carte').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_select_col_carte=' + id);	
	}
	
	
/** Admin **/
function supp_admin(id,nom)
	{
	if (confirm('Vous souhaiter supprimer l\'administrateur '+ nom + ' ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		var xhr = getXhr();
		document.getElementById('affiche_admin').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('affiche_admin').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_supp_admin=' + id);
		}	
	}
	
	
function supp_notif(id,notif)
	{
	if (confirm('Vous souhaiter supprimer cette notification ?\n\nAttention, toutes suppression est irreversible.')) 
		{
		var xhr = getXhr();
		document.getElementById('affiche_notif').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
		xhr.onreadystatechange = function() 
			{
			if(xhr.readyState == 4 && xhr.status == 200)
				document.getElementById('affiche_notif').innerHTML = xhr.responseText;
			}
		xhr.open('POST', '../ajax_admin.php', true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send('id_sup_admin=' + id + '&id_supp_notif=' + notif);
		}	
	}
	
	
function affiche_notif(id,cat)
	{
	var xhr = getXhr();
	document.getElementById('affiche_elt').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('affiche_elt').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_aff_notif=' + id + '&id_aff_notif_cat=' + cat);
	}	
	
	
	
	
//Accueil

function mod_photo_acc(photo)
	{
	var xhr = getXhr();
	document.getElementById('form_mod_photo_acc').innerHTML = "<img src='http://fichiers.relaisboisenergie49.fr/images/ajax-loader.gif' />";
	xhr.onreadystatechange = function() 
		{
		if(xhr.readyState == 4 && xhr.status == 200)
			document.getElementById('form_mod_photo_acc').innerHTML = xhr.responseText;
		}
	xhr.open('POST', '../ajax_admin.php', true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send('id_photo_acc=' + photo);
	}

