var filename = location.href;
	
var Compt = 0;
var Deb = filename.indexOf('/');
while (Compt != 3) {
  Compt++;
  var url = filename.slice(0,Deb);
  Deb = filename.indexOf('/',++Deb);
}

var baseUrl		=	url+'/';

//Fonction pour la concervation des donnée de pub
function startSession(gad,type){
	var XHR = new XHRConnection();
	XHR.appendData("gad", gad);
	XHR.appendData("type", type);
	
	XHR.sendAndLoad(baseUrl+"js/startSession.php","POST", nothing);
}

function nothing(){
	//alert("creation Session");
}

function hitsTopTen(idarticle){
	var XHR = new XHRConnection();
	XHR.appendData("id", idarticle);
	
	XHR.sendAndLoad(baseUrl+"js/hitsTopTen.php","POST", afficheHitsTopTen);
}

function afficheHitsTopTen(obj){
	tabResult	=	obj.responseXML.getElementsByTagName('id');
	id			=	tabResult[0].firstChild.data;

	if (id!=""){
		 tabResult = obj.responseXML.getElementsByTagName('html');
		 document.getElementById("hits_"+id).innerHTML = "";
		 document.getElementById("hits_"+id).innerHTML = tabResult[0].firstChild.data;
	}
}

function addHitsArticle(article,page){
	var XHR = new XHRConnection();
	XHR.appendData("id", article);
	XHR.appendData("page", page);
	XHR.sendAndLoad(baseUrl+"js/add_hits.php","POST", affichePage);
}

function affichePage(obj){
	tabResult	=	obj.responseXML.getElementsByTagName('msg');
	msg			=	tabResult[0].firstChild.data;

	if (msg==1){
		 tabResult = obj.responseXML.getElementsByTagName('html');
		 //document.getElementById("id_sond").innerHTML = "";
		 //document.getElementById("id_sond").innerHTML = tabResult[0].firstChild.data;
	}
}

//AJAX SONDAGE
function checkSondage(page){
	var XHR = new XHRConnection();
	XHR.appendData("page", page);

	XHR.sendAndLoad(baseUrl+"js/mod_sondage.php","POST", '');
}

function validSondage(form){
	//valider le sondage
	var XHR = new XHRConnection();
	XHR.appendData("valid", form);
	
	XHR.sendAndLoad(baseUrl+"js/mod_sondage.php","POST", afficheSondage);
}

function afficheSondage(obj){
	tabResult	=	obj.responseXML.getElementsByTagName('msg');
	msg			=	tabResult[0].firstChild.data;

	if (msg==1){
		 tabResult = obj.responseXML.getElementsByTagName('html');
		 document.getElementById("id_sond").innerHTML = "";
		 document.getElementById("id_sond").innerHTML = tabResult[0].firstChild.data;
	}
}

//AJAX NEWSLETTER


function checkNewsletter(page,type){
	var XHR = new XHRConnection();
	XHR.appendData("page", page);

	if (type == 3){
		XHR.appendData("type", 3);
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletterHome);
	}
	if (type == 1){
		XHR.appendData("type", 1);
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletter);
	}
	if (type == 2){
		XHR.appendData("type", 2);
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletterArticle);
	}
}

function afficheNewsletter(obj){
	alert(obj.responseXML); // [object XMLHttpRequest]
	if(obj&&obj.responseXML){
		tabResult	=	obj.responseXML.getElementsByTagName('msg');
		if(tabResult[0].firstChild && tabResult[0].firstChild.data){
			msg	= tabResult[0].firstChild.data;
		}else{
			msg = '';
		}
		nom			=	obj.responseXML.getElementsByTagName('nom');
		mail		=	obj.responseXML.getElementsByTagName('mail');
		if (msg=='ok'){
			document.location.replace(baseUrl+'misc/coreg_nl.php?nom='+nom[0].firstChild.data+'&mail='+mail[0].firstChild.data);
		}
		else {
			 tabResult = obj.responseXML.getElementsByTagName('html');
			 document.getElementById("id_news").innerHTML = "";
			 document.getElementById("id_news").innerHTML = tabResult[0].firstChild.data;
		}
	}else{
		return false;
	}
}


function afficheNewsletterHome(obj){
	tabResult	=	obj.responseXML.getElementsByTagName('msg');
	msg			=	tabResult[0].firstChild.data;
	nom			=	obj.responseXML.getElementsByTagName('nom');
	mail		=	obj.responseXML.getElementsByTagName('mail');
	if (msg=='ok'){
		document.location.replace(baseUrl+'misc/coreg_nl.php?nom='+nom[0].firstChild.data+'&mail='+mail[0].firstChild.data);
	}
	else {
		 tabResult = obj.responseXML.getElementsByTagName('html');
		 document.getElementById("id_news").innerHTML = "";
		 document.getElementById("id_news").innerHTML = tabResult[0].firstChild.data;
	}
}


function afficheNewsletterArticle(obj){
	tabResult	=	obj.responseXML.getElementsByTagName('msg');
	msg			=	tabResult[0].firstChild.data;
	nom			=	obj.responseXML.getElementsByTagName('nom');
	mail		=	obj.responseXML.getElementsByTagName('mail');
	if (msg=='ok'){
		document.location.replace(baseUrl+'misc/coreg_nl.php?nom='+nom[0].firstChild.data+'&mail='+mail[0].firstChild.data);
	}
	else {
		 tabResult = obj.responseXML.getElementsByTagName('html');
		 document.getElementById("id_news_art").innerHTML = "";
		 document.getElementById("id_news_art").innerHTML = tabResult[0].firstChild.data;
	}
}


function validNewsletter(nom,mail,type){
	var XHR = new XHRConnection();
	XHR.appendData("mail", mail);
	XHR.appendData("nom", nom);

	if (type == 3){
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletterHome);
	}
	if (type == 1){
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletter);
	}
	if (type == 2){
		XHR.sendAndLoad(baseUrl+"js/mod_newsletter.php","POST", afficheNewsletterArticle);
	}
}

