


var empecher = 0;
var timer = setInterval(stat,60000);

function empecher_nv_requete (data) {
	if (data == 1) { empecher = 1; }
	else { empecher = 0; }
}

function stat () {
    $.get('stat_haut.php',function(data){
		//$("#stat").fadeOut(500,function(){
			$("#stat").empty();
			$("#stat").append(data);
			//$("#stat").fadeIn(500);
		//});
        });
}

function afficher(data){
	$(".googlemap").remove();
	$(".loader").remove(); // On supprime le loader
	//$("#contenu").fadeOut(500,function(){
		$("#contenu").empty();
		$("#contenu").append(data);
		// $("#contenu").fadeIn(500);
		stat ();
		//assignecontenue(data); // voila l'appel
		relance(data);
		$("title").empty();
		$("title").append(titre);
		if(typeof(vafficher_txt)=='defined'){ afficher_txt();};
		empecher_nv_requete(0);
		timer = setInterval(stat,60000);
	//})

}

function Xiti ()
{
	Xt_param = 's=377293&p=';
	try {Xt_r = top.document.referrer;}
	catch(e) {Xt_r = document.referrer; }
	Xt_h = new Date();
	if(parseFloat(navigator.appVersion)>=4)
	{Xt_s=screen;Xt_i+='&r='+Xt_s.width+'x'+Xt_s.height+'x'+Xt_s.pixelDepth+'x'+Xt_s.colorDepth;}
	$("#Xiti").empty();
	$("#Xiti").append('<a href="http://www.xiti.com/xiti.asp?s=377293" title="WebAnalytics"><img width="80" height="15" border="0" alt="" src="http://logv3.xiti.com/bcg.xiti?'+Xt_param+'&hl='+Xt_h.getHours()+'x'+Xt_h.getMinutes()+'x'+Xt_h.getSeconds()+'&ref='+Xt_r.replace(/[<>"]/g, '').replace(/&/g, '$')+'" title="Internet Audience" />');
}
	function pageload(hash) {
		// hash doesn't contain the first # character.
		if(hash) {
page=hash;
			// restore ajax loaded state
			//$("#contenu").load(hash);
				$("#top").append('<div class="loader"></div>'); // On ajoute le loader en haut
				clearInterval(timer)
					if (/[?]/.test(page)) {
						empecher_nv_requete(1);
						$.ajax({
							url: page+'&ajax=1',
							cache:false,
							success:function(html){
								afficher(html);Xiti();
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						})
						return false; }
					else {
						empecher_nv_requete();
						$.ajax({
							url: page+'?ajax=1',
							cache:false,
							success:function(html){
								afficher(html);Xiti();
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						})
					return false;
					}
		} else {
			// start page
			$("#contenu").load('index.php?ajax=1');
		$("title").empty();
		$("title").append(titre);
		}
	}

	function relance(data){

		// set onlick event for buttons
		$("#contenu a").click(function(){
			//
			var hash = $(this).attr("href");
				if ((hash.match(/http/i)) || (hash == '') || (hash == 'connexion.php?page=connexion') || (hash == 'connexion.php?mode=deconnexion')) {  }
				else {
			hash = hash.replace(/^.*#/, '');
			// moves to a new page.
			// pageload is called at once.
			$.historyLoad(hash);
			return false;
}
		});
}

	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash.
		$.historyInit(pageload);

		// set onlick event for buttons
		$("#contenu a").click(function(){
			//
					var hash = $(this).attr("href");
				if ((hash.match(/http/i)) || (hash == '') || (hash == 'connexion.php?page=connexion') || (hash == 'connexion.php?mode=deconnexion')) {  }
				else {
			hash = hash.replace(/^.*#/, '');
			// moves to a new page.
			// pageload is called at once.
			$.historyLoad(hash);
			return false;
				    }
		});
	});


function majsubdiv (data)
{
	$.ajax({
		url: 'subdivision.php?pays='+data,
		cache:false,
		success:function(html){
		$("#subdivision").empty();
		$("#subdivision").append(html);
		},
		error:function(XMLHttpRequest,textStatus, errorThrown){
			afficher("erreur lors du chagement de la page");
		}
	})
}


function connexion(){
						$.ajax({
							url: 'menu.php?page_nom=Connexion',
							cache:false,
							success:function(html){
							$("#menu").empty();
							$("#menu").append(html);
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
						$.ajax({
							url: 'connexion.php?page=connexion-AJAX&ajax=1',
							cache:false,
							success:function(html){

	//$("#contenu").fadeOut(500,function(){
		//$("#contenu").empty();
$("#corps").css({opacity:"0.5"});
		$("#contenu").append('<div class="surpage">'+html+'</div>');
		// $("#contenu").fadeIn(500);
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
						return false;
}

function supprimer_connexion()
{
						$.ajax({
							url: 'menu.php?page_nom='+page_url,
							cache:false,
							success:function(html){
							$("#menu").empty();
							$("#menu").append(html);
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
	$("#corps").css({opacity:"1.0"});
	$(".surpage").remove();
	return false;
}


function submit_connex() {
$(document).ready(function(){
$("#connex-ajax form").submit(function(){
        var pseudo = $("#pseudo").val();
        var mdp = $("#mdp").val();
        var auto = $("#auto").val();
	$.ajax({
		url: 'connexion.php?mode=connexion-AJAX&ajax=1',
		cache:false,
		type:'POST',
		data: {'pseudo':pseudo, 'mdp':mdp, 'auto':auto},
		success:function(html){
			if (html == "oui") { supprimer_connexion(); }
			else
			{
				clearInterval(timer2)
				function vider_erreur () { $("#erreur_connex").empty(); }
				var timer2 = setInterval(vider_erreur,6000);
				$("#erreur_connex").append('<b>Vous avez fait une erreur.<br />Veuillez recommencer.</b>');
			}
		},
		error:function(XMLHttpRequest,textStatus, errorThrown){
			afficher("erreur lors du chagement de la page");
		}
	});
	return false;
});
});
}

 function deconnexion(){
						$.ajax({
							url: 'connexion.php?mode=deconnexion-AJAX?ajax=1',
							cache:false,
							success:function(html){
						$.ajax({
							url: 'menu.php?page_nom='+page_url,
							cache:false,
							success:function(html){
							$("#menu").empty();
							$("#menu").append(html);
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
						return false;
}

function noter(id, operation){
						$.ajax({
							url: 'ajax.php',
		data: {'id':id, 'operation':operation, 'page':'note'},
							cache:false,
							success:function(html){
							$("#note"+id).empty();
							$("#note"+id).append(html);
							},
							error:function(XMLHttpRequest,textStatus, errorThrown){
								afficher("erreur lors du chagement de la page");
							}
						});
						return false;
}