// ------------------------ Commentaires Avis de consommateurs -------------------------------

// ------ Effacement des commentaires -----------
function deleteCommentaireProduit(prmIdCommentaire) {
	if (confirm("Etes-vous sûr de vouloir supprimer cet avis de consommateurs ?")) {
		conn = new Ajax(true) ;
		conn.appendData("idComms",prmIdCommentaire) ;
		conn.sendAndLoad("/admin/scripts/deleteCommentaireProduit.php","POST",deleteCommentaireProduitHandler) ;
	}
	else alert("La suppression a été annulée !") ;
}

function deleteCommentaireProduitHandler(conn) {
	if (conn.responseText == "1") alert("La suppression a bien été effectuée !") ;	
	else {
		if (conn.responseText == "-1") alert("La suppression a échouée... Veuillez réessayer plus tard !") ;
	}
}

// ------ Effacement des commentaires -----------
function deleteCommentaireTProduit(prmIdCommentaire) {
	if (confirm("Etes-vous sûr de vouloir supprimer cet avis de consommateurs ?")) {
		conn = new Ajax(true) ;
		conn.appendData("idComms",prmIdCommentaire) ;
		conn.sendAndLoad("/admin/scripts/deleteCommentaireTProduit.php","POST",deleteCommentaireTProduitHandler) ;
	}
	else alert("La suppression a été annulée !") ;
}

function deleteCommentaireTProduitHandler(conn) {
	if (conn.responseText == "1") alert("La suppression a bien été effectuée !") ;	
	else {
		if (conn.responseText == "-1") alert("La suppression a échouée... Veuillez réessayer plus tard !") ;
	}
}

// ------------------ Activer un commentaire ---------------------
function activerCommentaireProduit(prmIdCommentaire) {
	if (confirm("Etes-vous sur de vouloir modifier l'état de cet avis de consommateurs ?")) {
		var ajax = new Ajax(true) ;
		ajax.appendData("idComms",prmIdCommentaire) ;
		ajax.sendAndLoad("/admin/scripts/commentaireActivateProduit.php","POST",activerCommentaireProduitHandler) ;
	}
	else {
		alert("Modification annulée !") ;	
	}
}

function activerCommentaireProduitHandler(conn) {
	eval(conn.responseText) ;	
}

/*------ gestion des produits ----- */
function deleteProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir supprimer ce produit ?")) {	
		var ajax = new	Ajax(true) ;
		ajax.appendData("idProduit",prmId) ;
		ajax.sendAndLoad("/admin/scripts/deleteProduit.php","POST", deleteProduitHandler) ;
		
	}
	else {
		alert("Suppression annulée !") ;	
	}
}

function deleteTProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir supprimer cet élément ?")) {	
		var ajax = new	Ajax(true) ;
		ajax.appendData("idTProduit",prmId) ;
		ajax.sendAndLoad("/admin/scripts/deleteTProduit.php","POST", deleteProduitHandler) ;
		
	}
	else {
		alert("Suppression annulée !") ;	
	}
}


function deleteProduitHandler(conn) {
	if (conn.responseText == "1") alert("La suppression a bien été effectuée !") ;	
	else {
		if (conn.responseText == "-1") alert("La suppression a échouée... Veuillez réessayer plus tard!") ;
	}
}

function activerProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir modifier l'état de ce produit ?")) {
		var ajax = new Ajax(true) ;
		ajax.appendData("idProduit",prmId) ;
		ajax.sendAndLoad("/admin/scripts/produitActivate.php","POST",activateProduitHandler) ;
	}
	else {
		alert("Modification annulée !") ;	
	}
}

function activerTProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir modifier l'état de ce produit ?")) {
		var ajax = new Ajax(true) ;
		ajax.appendData("idProduit",prmId) ;
		ajax.sendAndLoad("/admin/scripts/produitTActivate.php","POST",activateProduitHandler) ;
	}
	else {
		alert("Modification annulée !") ;	
	}
}


function activateProduitHandler(conn) {
	eval(conn.responseText) ;	
}


// ----- déplacer  un produit -------
var liste_deplacer_produit = new Array ;
var liste_deplacer_tproduit = new Array ;

function deplacerProduit(prmId) {
	
	if (liste_deplacer_produit[prmId] != true) {
		var ajax = new Ajax(true) ;
		ajax.sendAndLoad("/admin/scripts/showConsoArborescence.php?id_produit=" + prmId + "&" + Math.random(),"GET",deplacerProduitHandler) ;
		liste_deplacer_produit[prmId] = true ;
	}
	else {
		document.getElementById('deplacer_' + prmId).style.display = 'none' ;		
		liste_deplacer_produit[prmId] = false ;
	}
}

function deplacerTProduit(prmId) {
	
	if (liste_deplacer_tproduit[prmId] != true) {
		var ajax = new Ajax(true) ;
		ajax.sendAndLoad("/admin/scripts/showTouristeArborescence.php?id_produit=" + prmId + "&" + Math.random(),"GET",deplacerProduitHandler) ;
		liste_deplacer_tproduit[prmId] = true ;
	}
	else {
		document.getElementById('deplacerT_' + prmId).style.display = 'none' ;		
		liste_deplacer_tproduit[prmId] = false ;
	}
}



function deplacerProduitHandler(conn) {
	eval(conn.responseText) ;	
}

function moveProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir déplacer ce produit ?")) {	
		var ajax = new	Ajax(true) ;	
		the_select = document.getElementById("produit_arbo_" + prmId) ;
		
		ajax.appendData("id_produit",prmId) ;
		ajax.appendData("rubrique_id",the_select.options[the_select.selectedIndex].value) ;
		
		ajax.sendAndLoad("/admin/scripts/updateProduitCategorie.php","POST", moveProduitHandler) ;
	}
	else alert("Déplacement du produit annulé !") ;
}

function moveTProduit(prmId) {
	if (confirm("Etes-vous sur de vouloir déplacer ce produit ?")) {	
		var ajax = new	Ajax(true) ;	
		the_select = document.getElementById("tproduit_arbo_" + prmId) ;
		
		ajax.appendData("id_produit",prmId) ;
		ajax.appendData("rubrique_id",the_select.options[the_select.selectedIndex].value) ;
		
		ajax.sendAndLoad("/admin/scripts/updateTProduitCategorie.php","POST", moveProduitHandler) ;
	}
	else alert("Déplacement du produit annulé !") ;
}


function moveProduitHandler(conn) {
	eval(conn.responseText) ;	
}




/* ------ gestion des rubriques ------ */

var liste_rubrique_description = new Array ;

function editRubriqueDescription(prmId) {
	//déclaration des variables locales
	var textarea, obj, texte, p ;
	
	if (liste_rubrique_description[prmId] != true ) {
		obj = document.getElementById(prmId + '_rubr') ;	// on récupère le texte 
		textarea = document.createElement('textarea') ; //on crée un noeud
		
		textarea.style.width = '450px';
		textarea.style.height = '75px';
		textarea.style.border= "1px gray solid" ;
		textarea.style.fontSize = "10pt";
		textarea.style.fontFamily = "tahoma" ;
		textarea.onkeyup = function() {
			document.getElementById(prmId + '_descNbCars').firstChild.nodeValue = textarea.value.length ;
		}
		
		texte = document.createTextNode(obj.firstChild.firstChild.nodeValue) ;
		textarea.appendChild(texte) ;

		obj.replaceChild(textarea,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_rubrique_description[prmId] = true ;
	
	}
	else {
		obj = document.getElementById(prmId + '_rubr') ;	// on récupère le texte 
		p = document.createElement('p') ; //on crée un noeud
		
		texte = document.createTextNode(obj.firstChild.value) ;
		the_texte = obj.firstChild.value ;
		p.appendChild(texte) ;
			
	
		obj.replaceChild(p,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_rubrique_description[prmId] = false ;
		
		if (window.confirm("Voulez-vous enregistrer les modifications ?")) {
			conn = new Ajax(true) ;
			conn.appendData("idRubr",prmId) ;
			conn.appendData("description",the_texte) ;
			conn.sendAndLoad("/admin/scripts/updateRubrDesc.php","POST",updateRubrDescHandler) ;
		}
		else alert("L'enregistrement de la réponse a été annulé.") ;
	}
}


function updateRubrDescHandler(conn) {
	eval(conn.responseText) ;
}

// --- suprresion des rubriques shopping ----
function deleteRubr(prmId) {
	if (confirm("Etes-vous sur de vouloir supprimer cette rubrique ?\nTous les produits qu'elle contient seront désactivés")) {
		var ajax = new Ajax(true); 
		
		ajax.appendData("idRubrique",prmId) ;
		ajax.sendAndLoad("/admin/scripts/deleteRubr.php","POST", deleteRubrHandler) ;	
		
	}
}

function deleteRubrHandler(conn) {
	if (conn.responseText == "1") alert("La suppression a bien été effectuée !") ;	
	else {
		if (conn.responseText == "-1") alert("La suppression a échouée... Veuillez réessayer plus tard!") ;
	}
}


function activerRubr(prmId) {
	if (confirm("Etes-vous sur de vouloir modifier l'état de cette rubrique ?")) {
		var ajax = new Ajax(true) ;
		ajax.appendData("idRubrique",prmId) ;
		ajax.sendAndLoad("/admin/scripts/rubrActivate.php","POST",activateRubrHandler) ;
	}
	else {
		alert("Modification annulée !") ;	
	}
}

function activateRubrHandler(conn) {
	eval(conn.responseText) ;	
}

// ---- drop monument ----
function dropMonument(id) {
	if (confirm("Etes-vous sur de vouloir surpprimer définitivement ce monument ?")) {
		var ajax = new Ajax(true) ;
		ajax.sendAndLoad("/admin/scripts/deleteMonument.php?id=" + id,"GET", dropMonumentHandler) ;
	}
	else alert("Suppression annulée ! ") ;
}

function dropMonumentHandler(conn) {
	eval(conn.responseText) ;	
}


function changeProduitUrl(form) {
	
	var ajax = new Ajax(true) ;
	ajax.appendData("id", form.id.value) ;
	ajax.appendData("url",form.url.value) ;
	
	ajax.sendAndLoad("/ajax/changeUrl.php","POST", changeUrlHandler) ;
}

function changeUrlHandler(conn) {
	eval(conn.responseText) ;	
}


var liste_desc_tourisme = new Array ;
function editTourismeDesc(prmId) {
	//déclaration des variables locales
	var textarea, obj, texte, p ;
	
	if (liste_desc_tourisme[prmId] != true ) {
		obj = document.getElementById(prmId + '_descT') ;	// on récupère le texte 
		textarea = document.createElement('textarea') ; //on crée un noeud
		
		textarea.style.width = '450px';
		textarea.style.height = '75px';
		textarea.style.border= "1px gray solid" ;
		textarea.style.fontSize = "10pt";
		textarea.style.fontFamily = "tahoma" ;
		
		texte = document.createTextNode(obj.firstChild.firstChild.nodeValue) ;
		textarea.appendChild(texte) ;

		obj.replaceChild(textarea,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_desc_tourisme[prmId] = true ;
	
	}
	else {
		obj = document.getElementById(prmId + '_descT') ;	// on récupère le texte 
		p = document.createElement('p') ; //on crée un noeud
		
		texte = document.createTextNode(obj.firstChild.value) ;
		the_texte = obj.firstChild.value ;
		p.appendChild(texte) ;
			
	
		obj.replaceChild(p,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_desc_tourisme[prmId] = false ;
		
		if (window.confirm("Voulez-vous enregistrer les modifications ?")) {
			conn = new Ajax(true) ;
			conn.appendData("idProduit",prmId) ;
			conn.appendData("description",the_texte) ;
			conn.sendAndLoad("/ajax/updateTourismeDesc.php","POST",updateConsommateursDescHandler) ;
		}
		else alert("L'enregistrement de la description a été annulé.") ;
	}
}

function updateConsommateursDescHandler(conn) {
	eval(conn.responseText) ;	
}


var liste_acces_tourisme = new Array ;
function editTourismeAcces(prmId) {
	//déclaration des variables locales
	var textarea, obj, texte, p ;
	
	if (liste_acces_tourisme[prmId] != true ) {
		obj = document.getElementById(prmId + '_acces') ;	// on récupère le texte 
		textarea = document.createElement('textarea') ; //on crée un noeud
		
		textarea.style.width = '450px';
		textarea.style.height = '75px';
		textarea.style.border= "1px gray solid" ;
		textarea.style.fontSize = "10pt";
		textarea.style.fontFamily = "tahoma" ;
		
		texte = document.createTextNode(obj.firstChild.firstChild.nodeValue) ;
		textarea.appendChild(texte) ;

		obj.replaceChild(textarea,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_acces_tourisme[prmId] = true ;
	
	}
	else {
		obj = document.getElementById(prmId + '_acces') ;	// on récupère le texte 
		p = document.createElement('p') ; //on crée un noeud
		
		texte = document.createTextNode(obj.firstChild.value) ;
		the_texte = obj.firstChild.value ;
		p.appendChild(texte) ;
			
	
		obj.replaceChild(p,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_acces_tourisme[prmId] = false ;
		
		if (window.confirm("Voulez-vous enregistrer les modifications ?")) {
			conn = new Ajax(true) ;
			conn.appendData("idProduit",prmId) ;
			conn.appendData("description",the_texte) ;
			conn.sendAndLoad("/ajax/updateTourismeAcces.php","POST",updateConsommateursDescHandler) ;
		}
		else alert("L'enregistrement de la description a été annulé.") ;
	}
}


var liste_horaire_tourisme = new Array ;
function editTourismeHoraire(prmId) {
	//déclaration des variables locales
	var textarea, obj, texte, p ;
	
	if (liste_horaire_tourisme[prmId] != true ) {
		obj = document.getElementById(prmId + '_horaire') ;	// on récupère le texte 
		textarea = document.createElement('textarea') ; //on crée un noeud
		
		textarea.style.width = '450px';
		textarea.style.height = '75px';
		textarea.style.border= "1px gray solid" ;
		textarea.style.fontSize = "10pt";
		textarea.style.fontFamily = "tahoma" ;
		
		texte = document.createTextNode(obj.firstChild.firstChild.nodeValue) ;
		textarea.appendChild(texte) ;

		obj.replaceChild(textarea,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_horaire_tourisme[prmId] = true ;
	
	}
	else {
		obj = document.getElementById(prmId + '_horaire') ;	// on récupère le texte 
		p = document.createElement('p') ; //on crée un noeud
		
		texte = document.createTextNode(obj.firstChild.value) ;
		the_texte = obj.firstChild.value ;
		p.appendChild(texte) ;
			
	
		obj.replaceChild(p,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_horaire_tourisme[prmId] = false ;
		
		if (window.confirm("Voulez-vous enregistrer les modifications ?")) {
			conn = new Ajax(true) ;
			conn.appendData("idProduit",prmId) ;
			conn.appendData("description",the_texte) ;
			conn.sendAndLoad("/ajax/updateTourismeHoraire.php","POST",updateConsommateursDescHandler) ;
		}
		else alert("L'enregistrement de la description a été annulé.") ;
	}
}


function deletePhoto(id) {
	var ajax = new Ajax(true) ;
	ajax.sendAndLoad('/ajax/deletePhoto.php?id=' + id,"GET",deletePhotoHandler) ;
}

function deletePhotoHandler(conn) {
	eval(conn.responseText) ;	
}



// ********* editin des com's *********************

var liste_commentaires = new Array ;

function editCommentaire(prmId) {
	//déclaration des variables locales
	var textarea, obj, texte, p ;
	
	if (liste_commentaires[prmId] != true ) {
		obj = document.getElementById(prmId + '_comm') ;	// on récupère le texte 
		textarea = document.createElement('textarea') ; //on crée un noeud
		
		textarea.style.width = '450px';
		textarea.style.height = '75px';
		textarea.style.border= "1px gray solid" ;
		textarea.style.fontSize = "10pt";
		textarea.style.fontFamily = "tahoma" ;

		textarea.value = obj.firstChild.innerHTML ;
		
		while (textarea.value.indexOf("<br>") != -1) {
			textarea.value = textarea.value.replace(/<br>/,"\n") ;
		}

		obj.replaceChild(textarea,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_commentaires[prmId] = true ;
	
	}
	else {
		obj = document.getElementById(prmId + '_comm') ;	// on récupère le texte 
		p = document.createElement('p') ; //on crée un noeud
		
		texte = document.createTextNode(obj.firstChild.value) ;
		the_texte = obj.firstChild.value ;
		p.appendChild(texte) ;
			
	
		obj.replaceChild(p,obj.firstChild) ; //on remplace le texte figé par un textarea
		liste_commentaires[prmId] = false ;
		
		if (window.confirm("Voulez-vous enregistrer les modifications ?")) {
			conn = new Ajax(true) ;
			conn.appendData("idComm",prmId) ;
			conn.appendData("avis",the_texte) ;
			conn.sendAndLoad("/admin/scripts/updateComm.php","POST",updateCommHandler) ;
		}
		else alert("L'enregistrement de la réponse a été annulé.") ;
	}
}


function updateCommHandler(conn) {
	eval(conn.responseText) ;
}
