function ChangeStatut(formulaire) { 
	if(formulaire.regagree.checked == true) {formulaire.validation.disabled = false } 
	if(formulaire.regagree.checked == false) {formulaire.validation.disabled = true } 
} 

function verifFormulaire() {

	if (document.form1.mail1.value == "" || document.form1.mail2.value == "") {
		alert('Veuillez indiquer votre email que l\' on puisse vous repondre');
		return false;
	}
	else if (document.form1.message.value == "") {
		alert('Veuillez indiquer votre message');
		return false;
	}
	else {
		return true;
	}

}

 
function verifmail(mail){
	if(mail==''){}else{
		adresse_email = mail;
		arobase = adresse_email.indexOf("@");
		point = adresse_email.indexOf(".",arobase);
		mauvais_endroit_point = arobase+1;
		double_point = adresse_email.indexOf("..",arobase);
		nbre_carac = adresse_email.length - point;
		double_arobase = adresse_email.indexOf("@",arobase+1);
		if ( (arobase < 1) ||
			(point <= mauvais_endroit_point) ||
			(adresse_email.length < 5) ||
			(double_point >= 0) ||
			(nbre_carac < 3) ||
			(double_arobase >= 0) )
		   {
			return false;
		 
			}else{
				return true;
			}
	}
}

function verifmail2(mail2){
	 if (mail2 != "") {
		 if(mail2==document.form1.mail1.value){
			document.getElementById('mail_valid2').innerHTML='<span style="color:green;font-weight:700">Ok</span>';
			erreur_mail2=false;
		 }else{
		 erreur_mail2=1;
			document.getElementById('mail_valid2').innerHTML='<span style="color:red;font-weight:700">Adresses non indentiques</span>';
		 }
	}
}

// Fonction appelée pour lancer une exécution d'un fichier php par javascript 
function file(fichier) {

     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}

// Fonction appelée lors de l'inscription à un concours
function callScript ( scriptName, args, divC ){
//alert(divC);
var xhr_object = null;

if(window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
return;
}

xhr_object.open("POST", scriptName, true);

xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4) {
//alert(xhr_object.responseText); // DEBUG MODE
//document.write(xhr_object.responseText);
var div = document.getElementById(divC);
div.innerHTML = xhr_object.responseText;

var x = div.getElementsByTagName("script");
for(var i=0;i<x.length;i++)
{
	eval(x[i].text);
}

}

//alert(xhr_object.readyState);
return xhr_object.readyState;
}

xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhr_object.send(args);

}


function newsletter() {

var email = document.getElementById('email').value;
if (verifmail(email)) {
	if (document.getElementById('desinscription').checked) {
	callScript('newsletters.php', 'action=desinscription&email='+email, 'mail');
	}
	else if(document.getElementById('inscription').checked) {
	callScript('newsletters.php', 'action=inscription&email='+email, 'mail');
	}
}
else {
	alert("Syntaxe de l'adresse email invalide");
}

}

$(document).ready(function() {     
     
    //Execute the slideShow, set 4 seconds for each images
    slideShow(4000);
 
});
 
function slideShow(speed) {
 
 
    //append a LI item to the UL list for displaying caption
    $('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
 
    //Set the opacity of all images to 0
    $('ul.slideshow li').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('ul.slideshow li:first').css({opacity: 1.0});
     
    //Get the caption of the first image from REL attribute and display it
    $('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
    $('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
         
    //Display the caption
    $('#slideshow-caption').css({opacity: 0.7, bottom:0});
     
    //Call the gallery function to run the slideshow   
    var timer = setInterval('gallery()',speed);
     
    //pause the slideshow on mouse over
    $('ul.slideshow').hover(
        function () {
            clearInterval(timer);  
        }, 
        function () {
            timer = setInterval('gallery()',speed);        
        }
    );
     
}
 
function gallery() {
 
 
    //if no IMGs have the show class, grab the first image
    var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
         
    //Get next image caption
    var title = next.find('img').attr('title');
    var desc = next.find('img').attr('alt');   
         
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
     
    //Hide the caption first, and then set and display the caption
    $('#slideshow-caption').slideToggle(300, function () {
        $('#slideshow-caption h3').html(title);
        $('#slideshow-caption p').html(desc);
        $('#slideshow-caption').slideToggle(500);
    });
 
    //Hide the current image
    current.animate({opacity: 0.0}, 1000).removeClass('show');
 
}
