// JavaScript Document
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function affiche_livre_comm(_mode){
	if(_mode=='ON'){
	document.getElementById('livre_fond').style.display="block";
	document.getElementById('livre_contenu').style.display="block";
	}else{
		document.getElementById('livre_fond').style.display="none";
		document.getElementById('livre_contenu').style.display="none";	
	}
	
}

function change_livre(lelivre,url){
	document.getElementById('image_livre').src ="medias_siteblanc/rencontrer/"+lelivre;
	document.getElementById('livre_fond').style.display="none";
	document.getElementById('livre_contenu').style.display="none";
	mapage(ABS+"rencontrer/04_livres/"+url,'livre_contenu') ;	
}


/**************************/
/* DEBUT SCRIPT PAGINATION*/
/**************************/
var actu_page="p_1";

function change_vignette(LID){

	document.getElementById(LID).src = "images/"+LID+"_act.gif";
	document.getElementById(actu_page).src = "images/"+actu_page+"_ina.gif";
	actu_page = LID;
}

/**************************/
/* FIN SCRIPT PAGINATION*/
/**************************/

/**************************/
/* DEBUT SCRIPT GLOSSAIRE*/
/**************************/
var actu_lettre="a";
function change_lettres(LID){
	document.getElementById(actu_lettre).src = "images/lettres/"+actu_lettre+"_ina.gif";
	document.getElementById(LID).src = "images/lettres/"+LID+"_act.gif";
	actu_lettre = LID;
	actu_page="p_1";
	mapage(ABS+"savoir/glossaire/"+LID+".php","scroll_mask")
	mapage(ABS+"savoir/glossaire/"+LID+"_pagination.php","pagination")
	
	
}
/**************************/
/* FIN SCRIPT GLOSSAIRE*/
/**************************/

/**************************/
/* DEBUT SCRIPT GOURMANDISES*/
/**************************/
function gourmandises(qui){
	
	mapage(ABS+"savoir/recettes_gourmandises/"+qui,"gourmandises_contenu")
}

/**************************/
/* FIN SCRIPT GOURMANDISES*/
/**************************/


function swap_img(LID,path,end){
	document.getElementById(LID).src = path+LID+end;
}

/**************************/
/*DEBUT SCRIPT NAV GAUCHE*/
/**************************/

// stockage des arboréscene ouverte
var actu_rub_lvl0="";
var actu_rub_lvl1="";
var actu_rub_lvl2="";


// aiguillage et gestion des variables en fontion du niveau d'arboréscence
function test(LID,leniveau,url){

	var act_style;
	var ina_style;
	var old_id;

	switch(leniveau)
	{
	case "lvl0":
		act_style="nav_lvl_big_puce_act";
	  	ina_style="nav_lvl_big_puce_ina";
		old_id=actu_rub_lvl0;
		actu_rub_lvl0=LID;
		check_nav(LID,old_id,act_style,ina_style);
		
		if(actu_rub_lvl1 != ""){
			act_style="nav_lvl_big_puce_act";
	  		ina_style="nav_lvl_big_puce_ina";
			old_id=actu_rub_lvl1;
			actu_rub_lvl1="";
			check_nav(actu_rub_lvl1,old_id,act_style,ina_style);
		}
		
		if(actu_rub_lvl2 != ""){
			act_style="nav_lvl_small_puce_act";
	  		ina_style="nav_lvl_small_puce_ina";
			old_id=actu_rub_lvl2;
			actu_rub_lvl2="";
			check_nav(actu_rub_lvl2,old_id,act_style,ina_style);
		}
		
	  break;    
	case "lvl1":
		act_style="nav_lvl_big_puce_act";
	  	ina_style="nav_lvl_big_puce_ina";
		old_id=actu_rub_lvl1;
		actu_rub_lvl1=LID;
		check_nav(LID,old_id,act_style,ina_style);
		
		if(actu_rub_lvl2 != ""){
			act_style="nav_lvl_small_puce_act";
	  		ina_style="nav_lvl_small_puce_ina";
			old_id=actu_rub_lvl2;
			actu_rub_lvl2="";
			check_nav(actu_rub_lvl2,old_id,act_style,ina_style);
		}
	  break;
	case "lvl2":
		act_style="nav_lvl_small_puce_act";
	  	ina_style="nav_lvl_small_puce_ina";
		old_id=actu_rub_lvl2;
		actu_rub_lvl2=LID;
		check_nav(LID,old_id,act_style,ina_style);
	  break;
	}
	
	//appelle AJAX 
	if(url != "NONE"){
		mapage(url,'maincontent');
		actu_page="p_1";	
	}
	
}

// getsion de l'affichage de la bar de nav
function check_nav(LID,old_id,act_style,ina_style){	
	if( old_id!="" && old_id!=LID){
		affiche(old_id,"none");
		set_class(old_id,ina_style);
	}
	
	if(LID != ""){
		affiche(LID,"block");
		set_class(LID,act_style);
	}
}


//fermeture,ouverture d'un noeud de la navigation
function affiche(id,mode){
	noeud_element = document.getElementById(id);
	if(noeud_element.parentNode.childNodes[2] != null ){
		noeud_element.parentNode.childNodes[2].style.display=mode;
	}	
}

// changement de class de la class
function set_class(id,classname){

	if(	isIE== true){
		document.getElementById(id).setAttribute('className', classname);	
	}else{
		document.getElementById(id).setAttribute('class', classname);	
	}
	
}
/**************************/
/*FIN SCRIPT NAV GAUCHE*/
/**************************/




/**************************/
/* DEBUT AJAX*/
/**************************/

var req0 = false;

function makeRequest(req,url,qui)
{
	
	var xhr_object = null;
	if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
	else
	if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	
	// On ouvre la requete vers la page désirée
	xhr_object.open("GET", url, true);
	xhr_object.onreadystatechange = function(){
		if ( xhr_object.readyState == 4 )
		{
			var outMsg = (xhr_object.responseXML && xhr_object.responseXML.contentType=="text/xml") ? xhr_object.responseXML.getElementByTagName("choices")[0].textContent : xhr_object.responseText;
		
			// j'affiche dans la DIV spécifiées le contenu retourné par le fichier
			//document.getElementById(qui).innerHTML = xhr_object.responseText;
			document.getElementById(qui).innerHTML=outMsg;
		}
	}
	// dans le cas du get
	xhr_object.send(null);

}


function mapage(str,qui) {

	var currentTime = new Date();
	if(str.indexOf("?")!=-1){
	makeRequest(req0,str+"&qui="+currentTime,qui);
	}else{
	
	makeRequest(req0,str+"?qui="+currentTime,qui);
	}
}


/**************************/
/* FIN AJAX*/
/**************************/


function testenvoi() 
{ 
form=document.forms["resa"];
if (form.email.value&&form.tel.value){

                                mail = form.email.value;
								arobase = mail.indexOf("@");
								espace = mail.indexOf(" ");
                                doublarob = mail.indexOf("@",arobase+1);
                                right = mail.substring(arobase + 1,mail.length);
                                point = right.lastIndexOf(".");
                                test = right.length-point;
								

                                                if ((espace==-1)&&(doublarob==-1)&&(arobase>1)&&(point>1)&&(test<6)&&(test>2)) {
                                                      														 form.submit();
                                                        } 
                                                else {
                                                                alert("Vous n'avez pas saisie corectement votre e-mail.");
                                                        }
  }           

                                
        else { 
                        alert("Merci de bien vouloir saisir un email et un numéro de téléphone. Si vous ne disposez pas d'email imprimez cette page et envoyez la par fax au (33) 05 65 48 47 02."); 
                }
    
   } 
function testnews() 
{ 
form=document.forms["resa"];



if ( (form.email.value) ){

                                mail = form.email.value;
								arobase = mail.indexOf("@");
								espace = mail.indexOf(" ");
                                doublarob = mail.indexOf("@",arobase+1);
                                right = mail.substring(arobase + 1,mail.length);
                                point = right.lastIndexOf(".");
                                test = right.length-point;
								

                                                if ((espace==-1)&&(doublarob==-1)&&(arobase>1)&&(point>1)&&(test<6)&&(test>2)) {
                                                      														 form.submit();
                                                        } 
                                                else {
                                                                alert("Vous n'avez pas saisie corectement votre e-mail.");
                                                        }
                    } 

                                
        else { 
                        alert("Merci de bien vouloir saisir un email."); 
                }
}
function testenvoien() 
{ 
form=document.forms["resa"];



if (form.email.value&&form.tel.value) {

                                mail = form.email.value;
								arobase = mail.indexOf("@");
								espace = mail.indexOf(" ");
                                doublarob = mail.indexOf("@",arobase+1);
                                right = mail.substring(arobase + 1,mail.length);
                                point = right.lastIndexOf(".");
                                test = right.length-point;
								

                                                if ((espace==-1)&&(doublarob==-1)&&(arobase>1)&&(point>1)&&(test<6)&&(test>2)) {
                                                      														 form.submit();
                                                        } 
                                                else {
                                                                alert("You did not fill correctly your e-mail (without spaces).");
                                                        }
                    } 

                                
        else { 
                        alert("You did not filled your e-mail and a phone number. If you don't have an e-mail, print this page and send it by fax : (33) 05 65 48 47 02."); 
                }
}
function testnewsen() 
{ 
form=document.forms["resa"];



if ( (form.email.value) ){

                                mail = form.email.value;
								arobase = mail.indexOf("@");
								espace = mail.indexOf(" ");
                                doublarob = mail.indexOf("@",arobase+1);
                                right = mail.substring(arobase + 1,mail.length);
                                point = right.lastIndexOf(".");
                                test = right.length-point;
								

                                                if ((espace==-1)&&(doublarob==-1)&&(arobase>1)&&(point>1)&&(test<6)&&(test>2)) {
                                                      														 form.submit();
                                                        } 
                                                else {
                                                                alert("You did not fill correctly your e-mail (without spaces).");
                                                        }
                    } 

                                
        else { 
                        alert("You did not fill your email."); 
                }
}