function ajaxCiter(id,type,data){
	var XHR = new XHRConnection();
    XHR.appendData("id", id);
    XHR.appendData("type", type);
    XHR.appendData("data", data);
	XHR.sendAndLoad("../../citer.php", "POST", afficherAction);
}
function ajaxEnvoyer(id,type,data){
	var XHR = new XHRConnection();
    XHR.appendData("id", id);
    XHR.appendData("type", type);
    XHR.appendData("data", data);
	XHR.sendAndLoad("../../envoyer.php", "POST", afficherAction);
}
function ajaxEnvoyerSubmit(id,type,data, exp, dest, commentaire){
	var XHR = new XHRConnection();
    XHR.appendData("id", id);
    XHR.appendData("type", type);
    XHR.appendData("data", data);
    XHR.appendData("expediteur", exp);
    XHR.appendData("destinataire", dest);
    XHR.appendData("commentaire", commentaire);
	XHR.sendAndLoad("../../envoyerSubmit.php", "POST", afficherAction);
}
function afficherAction(obj){
	 tabResult = obj.responseXML.getElementsByTagName('html');
	 type = obj.responseXML.getElementsByTagName('type');
	 id = obj.responseXML.getElementsByTagName('id');
	 data = obj.responseXML.getElementsByTagName('data');
	 if(data[0].firstChild.data!="vide")
		 donnee = data[0].firstChild.data;
	 else
		 donnee = "";
	 nomCalque = 'actionsDiverses_'+type[0].firstChild.data+"_"+id[0].firstChild.data+donnee;
	 document.getElementById(nomCalque).style.display = "block";
	 document.getElementById(nomCalque).innerHTML = "";
	 document.getElementById(nomCalque).innerHTML = tabResult[0].firstChild.data;
	 document.location.href='#actionsModifs'+donnee;
}
function popPrint(id,type,data){
	var largeur	= 560;
	var hauteur	= screen.availHeight;
	var top		= (screen.height-hauteur)/2;
	var left	= (screen.width-largeur)/2;
	var fenetre = window.open("../../print.php?id="+id+"&type="+type+"&data="+data,"imprrmer_article","top="+top+",left="+left+",width="+largeur+", height="+hauteur+", resizable=no,scrollbars=yes,menubar=yes");
	fenetre.focus;
}

function ajaxEnvoyerContact(nom, prenom, societe, adresse, cp, ville, mail, message){
	var XHR = new XHRConnection();
    XHR.appendData("mail", mail);
    XHR.appendData("message", message);
    XHR.appendData("nom", nom);
    XHR.appendData("prenom", prenom);
    XHR.appendData("societe", societe);
    XHR.appendData("adresse", adresse);
    XHR.appendData("cp", cp);
    XHR.appendData("ville", ville);
	XHR.sendAndLoad("../../envoyerContact.php", "POST", afficherMessage);
}


function ajaxEnvoyerAnnonceur(nom, prenom, societe, fonction, adresse, cp, ville, mail, telephone, message){
	var XHR = new XHRConnection();
    XHR.appendData("mail", mail);
    XHR.appendData("message", message);
    XHR.appendData("nom", nom);
    XHR.appendData("prenom", prenom);
    XHR.appendData("fonction", fonction);
    XHR.appendData("telephone", telephone);
    XHR.appendData("societe", societe);
    XHR.appendData("adresse", adresse);
    XHR.appendData("cp", cp);
    XHR.appendData("ville", ville);
	XHR.sendAndLoad("../../envoyerAnnonceurs.php", "POST", afficherMessage);
}

function afficherMessage(obj){
	 tabResult = obj.responseXML.getElementsByTagName('html');
	 document.getElementById('messageRetour').innerHTML = "";
	 document.getElementById('messageRetour').innerHTML = tabResult[0].firstChild.data;
}

function ajaxEnvoyerCommentaire(idArticle, pseudo, mail, commentaire, as){
	var XHR = new XHRConnection();
    XHR.appendData("idArticle", idArticle);
    XHR.appendData("pseudo", pseudo);
    XHR.appendData("mail", mail);
    XHR.appendData("commentaire", commentaire);
    XHR.appendData("as", as);
	XHR.sendAndLoad("../../envoyerCommentaire.php", "POST", afficherCommentaire);
}
function afficherCommentaire(obj){
	 tabResult = obj.responseXML.getElementsByTagName('retour');
	 switch(tabResult[0].firstChild.data){
		 case"0":
			 alert("Votre commentaire n'a pu être ajouté, veuillez modifier vos paramètres de navigateur pour accepter les cookies.");
			 break;
		 case"1":
			tabResult1 = obj.responseXML.getElementsByTagName('idArticle');
			ajaxListeCommentaire(tabResult1[0].firstChild.data);
			alert("Votre commentaire a correctement été ajouté.");
			break;
		 case"2":
			 alert("Votre commentaire n'a pu être ajouté, un des champs obligatoires manquait.");
			 break;
		 case"3":
			 alert("Votre commentaire n'a pu être ajouté, vous n'avez pas correctement recopié l'anti-spam.");
			 break;
		 case"4":
			 alert("Votre commentaire n'a pu être ajouté, veuillez contacter le webmaster pour plus d'information.");
			 break;
		 case"5":
			 alert("Votre commentaire n'a pu être ajouté, le serveur semble être saturé.");
			 break;
	 }
	document.getElementById('antiSPAM').src='../../anti-spam.php?r='+Math.round((Math.random()*10000000000000));
}
function ajaxListeCommentaire(idArticle){
	var XHR = new XHRConnection();
    XHR.appendData("idArticle", idArticle);
	XHR.sendAndLoad("../../listeCommentaire.php", "POST", afficherListeCommentaire);
}
function afficherListeCommentaire(obj){
	 tabResult = obj.responseXML.getElementsByTagName('html');
	 document.getElementById('listeCommentaire').innerHTML = "";
	 document.getElementById('listeCommentaire').innerHTML = tabResult[0].firstChild.data;
}
function loadNewsletter(mail){
	var XHR = new XHRConnection();
    XHR.appendData("mail", mail);
	XHR.sendAndLoad("../../ajouterNewsletter.php", "POST", afficherNewsletter);
}
function afficherNewsletter(obj){
	 tabResult = obj.responseXML.getElementsByTagName('retour');
	 switch(tabResult[0].firstChild.data){
		 case"0":
			alert("Votre inscription à la newsletter n'a pas été prise en compte.");
			 break;
		 case"1":
			 alert("Votre inscription à la newsletter a bien été effectuée.");
			break;
		 case"2":
			alert("Votre inscription à la newsletter n'a pas été prise en compte, vous n'avez pas entré un email valide.");
			break;
		 case"3":
			alert("Votre inscription à la newsletter n'a pas été prise en compte, vous êtes déjà inscrit.");
			break;
		 case"4":
			alert("Votre inscription à la newsletter n'a pas été prise en compte, le serveur semble être saturé (ré-essayez un peu plus tard).");
			break;
	 }
}

function validMail(emailStr){
	var myAtSymbolAt = emailStr.indexOf('@');
	var myLastDotAt = emailStr.lastIndexOf('.');
	var mySpaceAt = emailStr.indexOf(' ');
	var myLength = emailStr.length;
	if (myAtSymbolAt < 1 || myLastDotAt < myAtSymbolAt || myLength - myLastDotAt <= 2 || mySpaceAt != -1)
		return false
	return true;
}
function valid_form(id, type, data){
	var msg = "";
	if(!validMail(document.form_envoi.email_exp.value) || document.form_envoi.email_exp.value=='')
		msg += "vous devez renseigner une adresse d'envoie valide\n";
	if(document.form_envoi.email_dest.value=='')
		msg += "vous devez renseigner un ou plusieurs expéditeurs\n";
	if(msg!="")
		alert("Envoi du formulaire annulé :\n"+msg);
	else
		ajaxEnvoyerSubmit(id,type,data, document.form_envoi.email_exp.value, document.form_envoi.email_dest.value, document.form_envoi.commentaire.value);
	return false;
}