// JavaScript Document

	function ajouterFavoris() {
		if ( navigator.appName != 'Microsoft Internet Explorer' )
		{ window.sidebar.addPanel("Mairie de Montauban","http://www.montauban.com",""); }
		else { window.external.AddFavorite("http://www.montauban.com/","Mairie de Montauban"); }
		}
		
		function recommander()
		{
		mail_str = "mailto:?subject=%C0 voir sur le site www.montauban.com"
		mail_str += "&body=Bonjour, le site internet de la Mairie de Montauban pourrait t'int%E9resser.Voici le lien pour le visiter  "+window.location;
		
		location.href = mail_str;
	}
		function confirmer(texte){
		return confirm(texte);
	}
	


	function message(html, fermetureAuto, delai){
	Shadowbox.open({
        player:     'html',
        content:    '<div class="shadowbox_message">'+html+'</div>',
        height:     125,
        width:      250
    });
	if(fermetureAuto == undefined){
		fermetureAuto = false;
	}
	if(delai == undefined){
		delai = 5000;
	}
	if(fermetureAuto == true){
		setTimeout(fermerShadowBox, delai);
	}
}

	function ouvrirVideo(url){
		Shadowbox.open({
			player:     'iframe',
			content:    '/videoEdito.php?video='+url,
			height:     380,
			width:      480
		});
		if(fermetureAuto == undefined){
			fermetureAuto = false;
		}
		if(delai == undefined){
			delai = 5000;
		}
		if(fermetureAuto == true){
			setTimeout(fermerShadowBox, delai);
		}
	}


function fermerShadowBox(){
	Shadowbox.close();
}


	
	function ajaxWaiting(){
	$('#carouselRSS').html('<div id="ajaxWainting"> </div>');

}
	
	function doInscrireNewsletter(){
		/*civilite =   $('#civilite').attr("value");
		nom =   $('#nom').attr("value");
		prenom = $('#prenom').attr("value");
		adresse = $('#adresse').attr("value");
		cp =     $('#cp').attr("value");
		ville =   $('#ville').attr("value");
		email = $('#email').attr("value");*/
		
		recupData = $("form").serialize();
		 var myAjax = $.ajax({
		   type: "POST",
		   url: "/../../php/doInscrireNewsletter.php",
		   data: recupData,
		   waiting: ajaxWaiting(),
		   success: function(html){
			$('#ajaxContent').html(html);
		  }
		});
	
		return false;
	}
	
	function doEnvoyerArticleAmi(){
	
		recupData = $("form").serialize();
		 var myAjax = $.ajax({
		   type: "POST",
		   url: "/../../php/doEnvoyerLienArticle.php",
		   data: recupData,
		   waiting: ajaxWaiting(),
		   success: function(html){
			$('#ajaxContent').html(html);
		  }
		});
	
		return false;
	}
	
	function doAjouterCommentaire(){
		commentaire =   $('#commentaire').val();
		idArticle =   $('#idArticle').attr("value");
		idUtilisateur =   $('#idUtilisateur').attr("value");
		 var myAjax = $.ajax({
		   type: "POST",
		   url: "/php/doAjouterCommentaire.php",
		   async: false, 
		   data: "commentaire="+commentaire+"&idArticle="+idArticle+"&idUtilisateur="+idUtilisateur+"",
		   success: function(html){
			$("#ajaxContent").html(html);
		  }
		});
		return false;
	}

	function doInscrireCompte(){
		civilite =   $('#civilite').attr("value");
		nom =   $('#nom').attr("value");
		prenom = $('#prenom').attr("value");
		ville =   $('#ville').attr("value");
		email = $('#email').attr("value");
		password = $('#password').attr("value");
		password2 = $('#password2').attr("value");
		pseudo = $('#pseudo').attr("value");
	
		 var myAjax = $.ajax({
		   type: "POST",
		   url: "/php/doInscrireCompte.php",
		   data: "civilite="+civilite+"&nom="+nom+"&prenom="+prenom+"&ville="+ville+"&email="+email+"&password="+password+"&password2="+password2+"&pseudo="+pseudo+"",
		   waiting: ajaxWaiting(),
		   success: function(html){
			$("#ajaxContent").html(html);
		  }
		});
	
		return false;
	}

	function doLoginCompte(){
		return true;
		email =   $('#email').attr("value");
		pass =   $('#pass').attr("value");
		page =   $('#page').attr("value");
		alert("email="+email+"&pass="+pass+"&page="+page);
		var myAjax = $.ajax({
		   type: "POST",
		   dataType:"html",
		   url: "/php/doLoginCompte.php",
		   data: "email="+email+"&pass="+pass+"&page="+page,
		   waiting: ajaxWaiting(),
		   error:function (xhr, ajaxOptions, thrownError){
					alert("xhr.status : "+xhr.status);
					alert("thrownError : "+thrownError);
			},
		  
		   success: function(data, html){
			//alert('Yes I can'+data+html);
			
			$("#ajaxContent").html(html);
			
			//parent.window.location.reload(true); 
			//window.open(window.parent.location.reload(true),"_parent","")
		  }
		  
		});
		return false;
	}
	
	function apresLogin(addr){
		if(addr == "" ){
			setTimeout( function() { window.location.reload(true);  },1500);	
		}else{
			//setTimeout( function() { window.location.reload(true);  },1500);
			window.location = addr;
		}
	}
	
	function doEnvoyerPass(){
		email =   $('#email').attr("value");
		 var myAjax = $.ajax({
		   type: "POST",
		   url: "/php/doEnvoyerPass.php",
		   data: "email="+email,
		   waiting: ajaxWaiting(),
		   success: function(html){
			$("#ajaxContent").html(html);
		  }
		});
		return false;
	}


function toggle_checkboxes(id) {
    if (!document.getElementById){ return; }
    if (!document.getElementsByTagName){ return; }
    var inputs = document.getElementById(id).getElementsByTagName("input");
    for(var x=0; x < inputs.length; x++) {
        if (inputs[x].type == 'checkbox'){
            inputs[x].checked = !inputs[x].checked;
        }
    }
}
 

function goSearchTheme(targ,selObj,restore){ //v3.0
  eval(targ+".location='/Agenda/Thematique/"+selObj.options[selObj.selectedIndex].value+".html'");
  if (restore) selObj.selectedIndex=0;
}
function goSearchLieu(targ,selObj,restore){ //v3.0
  eval(targ+".location='/Agenda/Lieu/"+selObj.options[selObj.selectedIndex].value+".html'");
  if (restore) selObj.selectedIndex=0;
}

function goSearchMois(targ,selObj,restore){ //v3.0
  eval(targ+".location='/Agenda/Mois/"+selObj.options[selObj.selectedIndex].value+".html'");
  if (restore) selObj.selectedIndex=0;
}

function goAssoSport(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// JavaScript Document

function menu(menu, parent){
	if($(menu) != undefined){
		if($(parent) != undefined){
			fermerOuvert(parent);
		}
		Effect.toggle(menu,'BLIND',{duration:0.3, queue:{scope:'myscope', position:'end'}});
		return false;
	}else{
		return true;	
	}
}
function fermerOuvert(parent){
	menus = document.getElementsByClassName('ssMenu',parent);
	for(i=0; i<menus.length ; i++){
		//$('message').innerHTML += menus[i]+"<br />\n";
		if(menus[i].style.display != 'none'){
			Effect.toggle(menus[i],'BLIND',{duration:0.3,  queue:{scope:'myscope', position:'end'}});
		}
	}
}
function ajouterFavoris() {
	if ( navigator.appName != 'Microsoft Internet Explorer')
		{ window.sidebar.addPanel("Site Officiel du Racing Métro 92","http://www.racing-metro92.com",""); }
	else { window.external.AddFavorite("http://www.racing-metro92.com","Site Officiel du Racing Métro 92"); }
}

function initAjaxBox(titre, classe){
	if(!classe){
		classe = '';
	}
	if(!$('ajaxContainer')){	
	html = '<div id="overlay"></div><div id="ajaxContainer" class="cadre noLogo '+classe+'"><div id="ajaxCloser" onclick="cacherOverlay();">Fermer</div><h2 id="ajaxTitre">'+titre+'</h2><div id="ajaxContent"></div><div class="finCadre">&nbsp;</div></div>';
	element = document.body;
	new Insertion.Top(element, html);
	}else{
		$('ajaxTitre').update(titre);	
	}
	hideSelectBoxes();
	hideFlash();
	// création de l'overlay et du conteneur
	
	ajaxWaiting();
	var arrayPageSize = getPageSize();
	Element.setWidth('overlay', arrayPageSize[0]);
	Element.setHeight('overlay', arrayPageSize[1]);
	Event.observe('overlay', 'click', cacherOverlay);
	// affichage des éléments
	new Effect.Appear('overlay', { duration: 0.1, from: 0.0, to: 0.8});
	new Effect.Appear('ajaxContainer', { duration: 0.1});
	new Draggable('ajaxContainer',{handle:'ajaxTitre'});
}


function recommander(){
	initAjaxBox('Recommander le site &agrave; un ami');
	// Ajax du formulaire
	var url = 'ajax/envoyer-ami.php';
	var target = 'ajaxContent';
	var myAjax = new Ajax.Updater(target, url);
	//new Draggable('ajaxContainer',{handle:'ajaxTitre'});
}
function doEnvoyerAmi(){
	
	nomFrom =   $F('nomSender');
	emailFrom = $F('emailSender');
	nomTo =     $F('nomReceiver');
	emailTo =   $F('emailReceiver');
	copie =   $F('copie');
	var url = 'ajax/do-envoyer-ami.php';
	var target = 'ajaxContent';
	var page = window.location;
	var pars = 'nomSender='+nomFrom+'&emailSender='+emailFrom+'&nomReceiver='+nomTo+'&emailReceiver='+emailTo+"&copie="+copie+"&page="+escape(page);
	//alert(pars);
	var myAjax = new Ajax.Updater(target, url, {method: 'POST', parameters: pars, onLoading : ajaxWaiting()});
	return false;
}
function newsletter(){
	initAjaxBox('Inscription à la newsletter');
	
	
	// Ajax du formulaire
	var url = 'ajax/newsletter.php';
	var target = 'ajaxContent';
	var myAjax = new Ajax.Updater(target, url);
	//new Draggable('ajaxContainer',{handle:'ajaxTitre'});
}
function doNewsletter(){
	
/*	nom =   $F($('nom'));
	prenom = $F($('prenom'));
	email =     $F($('email'));
	adresse =   $F($('adresse'));
	codePostal =   $F($('codePostal'));
	ville =   $F($('ville'));
	age =   $F($('age'));
	tel =   $F($('tel'));
	activite =   $F($('activite'));
	mobile =   $F($('mobile'));*/
	
	valeur = $('newsletter').serialize()
	
	var url = 'ajax/do-newsletter.php';
	var target = 'ajaxContent';
	var page = window.location;
	var pars = valeur+'&page='+page;
	//alert(pars);
	var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars, onLoading : ajaxWaiting()});
	return false;
}

function cacherOverlay(){
	new Effect.Fade('overlay', { duration: 0.3 });
	new Effect.Fade('ajaxContainer', { duration: 0.3 });
	showSelectBoxes();
	showFlash();
}

function ChargeActu(image, div, imagette){
	imagettes = $('#actuPhoto .imagette');
	for(i=0; i<imagettes.length; i++){
		makevisible(imagettes[i],1);
	}
	makevisible(imagette,0);
	//$('viewer').src = image;
	if (document.all){
		$('viewer').style.filter="blendTrans(duration=0.300)";
		//$('viewer').style.filter="blendTrans(duration=crossFadeDuration)";
		$('viewer').filters.blendTrans.Apply();
	}
	$('viewer').src = tab_image[image-1].src;
	if (document.all){
		$('viewer').filters.blendTrans.Play()
	}
	//textesActus = $('texteActu').immediateDescendants();
	$('#texteActu > *').hide();
	/*for ( keyVar in textesActus ) {
	  alert(textesActus[keyVar].name);
	  textesActus[keyVar].hide();
	}*/
	
	$(div).show();
}

function makevisible(cur,which){
	if(document.getElementById)
		{
		if (which==0)
			{
			if(document.all)
				cur.filters.alpha.opacity=100
			else
				cur.style.setProperty("-moz-opacity", 1, "");
			}
		else
			{
			if(document.all)
				cur.filters.alpha.opacity=30
			else
				cur.style.setProperty("-moz-opacity", .30, "");
			}
		}
	}
function afficherClassement(afficher,masquer){
	if($(masquer+":visible")){
		$(masquer).slideUp(500, function(){$(afficher).slideDown( 500 )} );
		//Effect.BlindDown(afficher, { duration: 0.3, queue: 'end' });
	}
	return false;
}

function AfficherJoueur(id) {
	//alert("afficher joueur : "+id);
	new Effect.Fade('fiche',{duration:0.3, queue:"front"});
	setTimeout("getFiche('"+id+"')",200);
	new Effect.Appear('fiche',{duration:0.3, queue:"end"});
	new Effect.ScrollTo('finFiche',{duration:1});

}
function AfficherJoueurEn(id) {
	//alert("afficher joueur anglais : "+id);
	new Effect.Fade('fiche',{duration:0.3, queue:"front"});
	setTimeout("getFicheEn('"+id+"')",200);
	new Effect.Appear('fiche',{duration:0.3, queue:"end"});
	new Effect.ScrollTo('finFiche',{duration:1});

}

function getFiche(id){
	//alert("get fiche : "+id);
	var url = 'ajax/fiche-joueur.php';
	var pars = 'idJoueur='+id;
	var target = 'conteneurFiche';
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}

function getFicheEn(id){
	//alert("get fiche : "+id);
	var url = 'ajax/fiche-joueur_anglais.php';
	var pars = 'idJoueur='+id;
	var target = 'conteneurFiche';
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}

function texteDefile() {
   if (!defile) defile = document.getElementById('defile');
   if (defile) {
      if(pscrnt < ( - defile.offsetHeight) ){
         pscrnt = psinit;
                } else {
         pscrnt+= -1; // pixel par deplacement
      }
      defile.style.top = pscrnt+"px";
   }
}
function lancerFlash(){
	interval = setInterval("texteDefile()",30); // delai de deplacement 
}
function goPage(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function goPageQuizz(targ,selObj,restore){ //v3.0
  eval(targ+".location='quizz-71.html?categorie="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function goPageQuizz2(targ,selObj,restore){ //v3.0
  eval(targ+".location='questionnaireQuizz-64.html?id_quizz="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function goElection(targ,selObj,restore){ //v3.0
  eval(targ+".location='election-69.html?matchVote="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}




function changeCouleur(ligne){
	this.color = ligne.style.backgroundColor;
	ligne.style.backgroundColor ="#565656";
}

function rollTitre(ligne){
	this.color = ligne.style.backgroundColor;
	ligne.style.backgroundColor ="#2B1312";
}

function remetCouleur(ligne){
	//ligne.bgColor = '#FFFFFF';
	ligne.style.backgroundColor = this.color;
}


function creerCompte(){
	initAjaxBox('Créer un compte');
	
	// Ajax du formulaire
	var url = 'ajax/creerCompte.php';
	var target = 'ajaxContent';
	var myAjax = new Ajax.Updater(target, url);
}

function doCreerCompte(){
	valeur = $('creerCompte').serialize()
	
	var url = 'ajax/do-creer-compte.php';
	var target = 'ajaxContent';
	var page = window.location;
	var pars = valeur+'&page='+page;
	//alert(pars);
	var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars, onLoading : ajaxWaiting()});
	return false;
}

function verifForm(form){
	elements = $$('.obli');
	toto = true;
	elements.each(function(n){
		if($F(n) == ""){
			n.focus();
			
			alert("Certains champs sont obligatoires !")
			toto = false;
			throw $break;
			throw $break;
			
		}
	});
	
	return toto;
}

function afficherVideo(id){
	$("#texteVideo").hide("slide", { direction: "down" }, 200);
	$("#vidDyn").fadeTo(200, 0, function(){
		$.get("/ajax/afficherVideo.php", { idVideo: id } , function(data){
			//alert(data);
			$("#vidDyn").html(data);
			$("#vidDyn").fadeTo(200, 1);
			$("#texteVideo").show("slide", { direction: "up" }, 200);
		}, "script");
	});	
	return false;
}
function afficherLigne(num){
	//alert(num);	
	$(".joueurs").hide();
	$(".titreLigne").hide();
	$("#titreLigne_"+num).show();
	$("#tableauEffectif_"+num).show();
}

function mycarousel_initCallback(carousel, state)
{
    carousel.lock();

    jQuery.get(
        'special_textscroller.php',
        {
            'feed': 'http://94.23.61.137/actu.xml'
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

function mycarousel_initCallbackEquipePro(carousel, state)
{
    carousel.lock();

    jQuery.get(
        'special_textscroller.php',
        {
            'feed': 'http://94.23.61.137/actu_equipe_pro.xml'
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

function mycarousel_initCallbackClub(carousel, state)
{
    carousel.lock();

    jQuery.get(
        'special_textscroller.php',
        {
            'feed': 'http://94.23.61.137/actu_club.xml'
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

function mycarousel_initCallbackVideos(carousel, state)
{
    carousel.lock();

    jQuery.get(
        'special_textscroller.php',
        {
            'feed': 'http://94.23.61.137/actu_videos.xml'
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, xml)
{
    var $items = jQuery('item', xml);
	var boolLigne = 0;
    $items.each(function(i) {
        carousel.add(i + 1, mycarousel_getItemHTML(this, boolLigne));
		if(boolLigne == 0){
			boolLigne = 1;
		}else{
			boolLigne = 0;
		}
    });

    carousel.size($items.size());

    // Unlock and setup.
    carousel.unlock();
    carousel.setup();
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item, boolLigne)
{
	if(boolLigne == 0){
    	return '<p class="bleu filRSS '+$('classRss', item).text()+' '+$('classImportant', item).text()+'"><a href="'+$('link', item).text()+'">'+'<strong>'+$('pubDate', item).text()+'</strong> '+$('title', item).text()+'</a></p>';
	}else{
		return '<p class="filRSS '+$('classRss', item).text()+' '+$('classImportant', item).text()+'"><a href="'+$('link', item).text()+'">'+'<strong>'+$('pubDate', item).text()+'</strong> '+$('title', item).text()+'</a></p>';
	}
};

/**
 * Utility function for truncating a string without breaking words.
 */
function mycarousel_truncate(str, length, suffix) {
    if (str.length <= length) {
        return str;
    }

    if (suffix == undefined) {
        suffix = '...';
    }

    return str.substr(0, length).replace(/\s+?(\S+)?$/g, '') + suffix;
};

function inscriptionNewsletter(email){
	$.ajax({
	   type: "POST",
	   url: "php/doInscrireNewsletter.php",
	   data: "email="+email,
	    success: function(html){
			$('#contenu_newsletter').html(html);
		  }
	});
	return false;
}