
// JavaScript Document
//vars
nb_car=0;
duree_opacity=25;
nb_menu=0;
nb_smenu=0;
opa_black=0;

//reglages partie centrale
hauteur_affichage=379;
pas_whell=5;

//volume apercu video
bln_vol_apercu=true;

//timers
timer_menu=0;
timer_variable=0;
timer_actu=0;
timer_glossaire=0;


//booleans
bln_onscroll=false;
navi_IE=false;

timer_In = new Array(5);
timer_Out = new Array(5);


function volume()
{
	if (bln_vol_apercu==true)
	{
		getFlashObject().SetVariable("method:setVolume",0 );	
		bln_vol_apercu=false;
	}
	else
	{
		getFlashObject().SetVariable("method:setVolume", 100);
		bln_vol_apercu=true;
	}
	
}


function lien_consultation() {
	//alert('ok');
	document.getElementById("frm_consult").submit();

}


function fadeIn_element(id) {
		
		opa=$("#" + id).css("opacity");
		opa=parseFloat(opa);
		opa=opa + 0.1;
	
		$("#" + id).css("opacity",opa);
		if (opa==1)
		{
			clearTimeout(timer_In[num]);
		}
		else
		{
			timer_In[num]=setTimeout('fadeIn_element(' + id + ')',duree_opacity);
		}
}




function fadeIn_menu(num){
	
	opa=$("#smenu_" + num).css("opacity");
	opa=parseFloat(opa);
	opa=opa + 0.1;

	$("#smenu_" + num).css("opacity",opa);
	if (opa==1)
	{
		clearTimeout(timer_In[num]);
	}
	else
	{
		timer_In[num]=setTimeout('fadeIn_menu(' + num + ')',duree_opacity);
	}
}

function fadeOut_menu(num){
	opa=$("#smenu_" + num).css("opacity");
	opa=parseFloat(opa);
	opa=opa - 0.1;

	$("#smenu_" + num).css("opacity",opa);
	if (opa==0)
	{
		clearTimeout(timer_Out[num]);
		$("#smenu_" + num).css("visibility","hidden");
		
	}
	else
	{
		timer_Out[num]=setTimeout('fadeOut_menu(' + num + ')',duree_opacity);
	}
}




function affich_menu(num){
	
	if (navi_IE==false){
		$("#smenu_" + num).css("visibility","visible");
		clearTimeout(timer_Out[num]);
		fadeIn_menu(num);
	}
	else
	{

		$(".smenu").css("visibility","hidden");
		//$("#smenu_" + num).css("opacity","1");
		$("#smenu_" + num).css("visibility","visible");
		clearTimeout(timer_menu);
		
	}
}


function cache_menuIE(num){
	$("#smenu_" + num).css("visibility","hidden");
}

function cache_menu(num){
	if (navi_IE==false){
		clearTimeout(timer_In[num]);
		fadeOut_menu(num);
	}
	else
	{
		clearTimeout(timer_menu);
		timer_menu=setTimeout('cache_menuIE(' + num + ')' ,500);
	}
		//cacher les sous-menus
	//
}

function init_menu(){
	i=0;	
	num_smenu=0;
	//ON REPERTORIE LES ELEMENTS DU MENU ET CREATION DES TIMERS POUR CHACUN D'ENTRE EUX
	nb_menu=$(".smenu").length;
	nb_menu=parseInt(nb_menu);

	tab_menu= $(".smenu");
	
	
	//while (i<nb_menu){
//		num_smenu=i+1;
		
		//$("#smenu_" + num_smenu +" > .element_sousmenu").length;
	//	"tab_smenu_" + i = new Array(tab_menu[i].	
											  
//		i++;
//	}


	//alert (nb_smenu);
}


function afficher_message(){
//	$("#message_alert").show();
}
function cacher_message(){
	//$("#message_alert").hide();
}


$(document).ready(function() {

	//init_menu();
	//document.getElementById("header").innerHTML +="<a id='lien_consult' href='http://consultation.prenons-soin-de-leau.fr' target='_blank'>test</a>";
	//document.getElementById("header").innerHTML +="<form action='http://consultation.prenons-soin-de-leau.fr' method='post' name='frm_consult' target='_blank' id='frm_consult'></form>";
	//document.getElementById("header").innerHTML +="<span id='message_alert'>Attention, certains navigateurs assimilent l'ouverture du questionnaire &agrave; un popup, il faut autoriser l'ouverture de la nouvelle fen&ecirc;tre.</span>";

	
	//version navigateur
	 if (navigator.appName=="Microsoft Internet Explorer"){
		 navi_IE=true;
	 }
	
	//NAVIGATION DANS LE SITE 
	$("#lien_etapes").click(function(){
		document.location.href="etapes.php";
	});
	

	
	$("#lien_propositions").click(function(){
		document.location.href="propositions.php";
	});
	
	$("#lien_bassin").click(function(){
		document.location.href="bassin.php";
	});
	
	$("#lien_qui").click(function(){
		document.location.href="quifaitquoi.php";
	});
	
	$("#lien_objectifs").click(function(){
		document.location.href="objectifs.php";
	});
	
	$("#lien_emploi").click(function(){
		document.location.href="mode.php";
	});
	
	$("#lien_emploi").click(function(){
		document.location.href="mode.php";
	});

	$("#lien_chiffres").click(function(){
		document.location.href="chiffres.php";
	});	
	
	$("#lien_apres").click(function(){
		document.location.href="apres.php";
	});		
	$("#lien_calendrier").click(function(){
		document.location.href="calendrier.php";
	});
	
	$("#lien_glossaire").click(function(){
		document.location.href="glossaire.php";
	});	

	$("#retour_consult").click(function(){
		document.location.href="index.php";
	});	
	$("#lien_contact").click(function(){
		document.location.href="mailto:sdage@eau-loire-bretagne.fr";
	});	
		$("#lien_partenaires").click(function(){
		document.location.href="partenaires.html";
	});
	$("#lien_couts").click(function(){
		document.location.href="couts.php";
	});	
	$("#lien_gestes").click(function(){
		document.location.href="gestes.php";
	});		
	$("#lien_donner").click(function(){
		document.location.href="donner_son_avis.php";
	});	
	$("#ils_agissent").click(function(){
		document.location.href="ils_agissent.php";
	});	
		$("#lien_sinformer").click(function(){
		document.location.href="s_informer.php";
	});	
	
	
	$("#lien_acteurs").click(function(){
		document.location.href="acteurs.php";
	});		
	$("#lien_mentions").click(function(){
		document.location.href="mentions.php";
	});	
	$("#lien_2015").click(function(){
		document.location.href="objectifs2015.php";
	});
	$("#lien_presse").click(function(){
		document.location.href="presse.php";
	});
	$("#lien_plan").click(function(){
		document.location.href="plan.php";
	});	
	$("#lien_ressources").click(function(){
		document.location.href="liens.php";
	});
	$("#lien_questions").click(function(){
		document.location.href="FAQ.php";
	});
	$("#lien_rechercher").click(function(){
		document.location.href="recherche.php";
	});
	$("#lien_historique").click(function(){
		document.location.href="historique.php";
	});

	$("#div_acces_form").click(function(){
										
										
		$("#centre_message").hide();
		$("#centre_consult").show();
	});		
		
	
	
		$("#btn_id").click(function(){
		valid_mail();
	});		
	
	
	//FONCTIONS
	$("#valid_consult").click(function(){
			verif_partenaires();
	});
	
	//PRECHARGEMENT DES IMAGES
	prechargimg('images/fond_menu_gauche_roll.gif','images/fond_retour_roll.jpg','images/fond_sousmenu_roll.gif','images/fond_valider_roll.jpg','images/glossaire_roll.jpg','images/logo_print_roll.jpg','images/pause_roll.jpg','images/play_roll.jpg','images/questions_roll.jpg','images/rechercher_roll.jpg','images/ressources_roll.jpg','images/stop_roll.jpg','images/volume_roll.jpg', 'images/fleche_bas_roll.jpg','images/fleche_haut_roll.jpg','images/fleche_bas_var_roll.jpg','images/fleche_haut_var_roll.jpg','images/btn_ok_roll.jpg');
	


});




function verif_partenaires(){

	//($("#div_nom > #txt_nom").val());

	//$("#txt_adresse")
//	$("#txt_tel")
//	$("#txt_contact")
//	$("#txt_mail")
//
//	$("#txt_action")
//
//	$("#txt_date")

	
}

function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}


function valid_mail(){
	
	
	
	bln_valid=true;
	color="#FFAEAE";
	
	nom=$("#txt_nom").val();
	FAI=$("#txt_FAI").val();

if (FAI=="")
	{
		$("#txt_FAI").css("background-color",color);
		$("#txt_FAI").focus();
		setTimeout('$("#txt_FAI").css("background-color","#FFFFFF")',2000);
		bln_valid=false;
	}	
	else
	{
	if (FAI.indexOf(".") == "-1")
		{
			$("#txt_FAI").css("background-color",color);
			$("#txt_FAI").focus();
			setTimeout('$("#txt_FAI").css("background-color","#FFFFFF")',2000);
			bln_valid=false;
		}	
	}
if (nom=="")
	{
		$("#txt_nom").css("background-color",color);
		$("#txt_nom").focus();
		setTimeout('$("#txt_nom").css("background-color","#FFFFFF")',2000);
		bln_valid=false;
	}

if (bln_valid==true)
	{
		$("#btn_id").css("cursor","wait");
		$("#newsletter").hide();
		
		
		email=nom + "@" + FAI;
		xhr=createXHR();
		xhr.onreadystatechange = function()
			{
				 if(xhr.readyState == 4 && xhr.status == 200)
				{
					$("#btn_id").css("cursor","pointer");
					$("#txt_nom").val("");
					$("#txt_FAI").val("");
					//message
					
					setTimeout('$("#newsletter").show();',5000);
					
				}
			}
		var data= "txt_mail=" + email;
		xhr.open("POST","scripts/add_mail.php" ,false);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(data);
	}


}



function scrollblock_down(fleche_bas, fleche_haut, texte, timer,hauteur_block)
{
	if (bln_onscroll==false){
		
		hauteur_texte=document.getElementById(texte).offsetHeight;
		position_texte=document.getElementById(texte).offsetTop;
		reste_hauteur=hauteur_texte+position_texte;
		limite=position_texte-hauteur_block;
	
		if ((reste_hauteur-hauteur_block)<hauteur_block)
		{
			$("#" + fleche_bas).css("visibility","hidden");	
		}	
	
		clearTimeout(timer);
		block_down(texte, timer, limite);
		$("#" + fleche_haut).css("visibility","visible");
	}
			
	
}

function block_down(texte, timer, limite)
{
	bln_onscroll=true;
	position_texte=document.getElementById(texte).offsetTop;
	
	if (limite<position_texte)
	{
		position_texte=position_texte-10;
		$("#" + texte).css("top",position_texte + "px");
		timer=setTimeout("block_down('" + texte + "'," + timer + "," + limite + ");",5);
	}
	else
	{
		clearTimeout(timer);
		bln_onscroll=false;
	}
}

function scrollblock_up(fleche_bas, fleche_haut, texte, timer, hauteur_block)
{
	if (bln_onscroll==false){

		hauteur_texte=document.getElementById(texte).offsetHeight;
		position_texte=document.getElementById(texte).offsetTop;
		reste_hauteur=position_texte;
		limite=reste_hauteur+hauteur_block;
	
	
		if ((position_texte+hauteur_block)>=0)
		{
			$("#" + fleche_haut).css("visibility","hidden");	
		}	
	
		clearTimeout(timer);
		block_up(texte, timer, limite);
		$("#" + fleche_bas).css("visibility","visible");
	}
			
	
}

function block_up(texte, timer, limite)
{
	bln_onscroll=true;
	position_texte=document.getElementById(texte).offsetTop;
	
	if (limite>position_texte)
	{
		position_texte=position_texte+10;
		$("#" + texte).css("top",position_texte + "px");
		timer=setTimeout("block_up('" + texte + "'," + timer + "," + limite + ");",5);
	}
	else
	{
		clearTimeout(timer);
		bln_onscroll=false;
	}
}


function prechargimg() {
var doc=document;
if(doc.images){ if(!doc.precharg) doc.precharg=new Array();
var i,j=doc.precharg.length,x=prechargimg.arguments; for(i=0; i<x.length; i++)
if (x[i].indexOf("#")!=0){ doc.precharg[j]=new Image; doc.precharg[j++].src=x[i];}}
}


function affich_lettre(lettre){
	position_cible=parseInt(document.getElementById(lettre).offsetTop);

	position_actuel=Math.abs(document.getElementById("text_centre").offsetTop);
	

	y=Math.floor((position_cible/scroll_zone)*316);

	
	$("#poignee").css("top",y + "px")
	
	//clearTimeout(timer_glossaire);
	if (position_cible!=0){
		if (position_cible>position_actuel)
		{	
			position_cible=position_cible-40;
			glossaire_down(position_cible);
		}
		else
		{
			position_cible=position_cible-40;
			glossaire_up(position_cible);
		}
	}
	else
	{
		$("#text_centre").css("top","0px");
	}
	

}

function glossaire_down(cible){
	position_texte=parseInt(document.getElementById("text_centre").offsetTop);
//	
//
//	if (cible>Math.abs(position_texte))
//	{
//		position_texte=position_texte-200;
//		$("#text_centre").css("top",position_texte + "px");
//		timer_glossaire=setTimeout("glossaire_down('" + cible + "');",1);
//	}
//	else
//	{
//		clearTimeout(timer_glossaire);
		$("#text_centre").css("top","-" + cible + "px");

//	}	
}

function glossaire_up(cible){
	position_texte=document.getElementById("text_centre").offsetTop;	
	position_texte=parseInt(position_texte);

//	if (position_texte<0){
//		
//		if (cible<Math.abs(position_texte))
//		{
//			position_texte=position_texte+200;
//			$("#text_centre").css("top",position_texte + "px");
//			timer_glossaire=setTimeout("glossaire_up('" + cible + "');",1);
//		}
//		else
//		{
//			clearTimeout(timer_glossaire);
//			$("#text_centre").css("top","-" + cible + "px");
//		}
//	}
//	else
//	{
//		clearTimeout(timer_glossaire);
		$("#text_centre").css("top","-" + cible + "px");
//	}
	
}

function message_attente(){
	
	verifier_date();
}

function verifier_date() { // procedure du bouton vérifier
	//alert("merd");
	maintenant = new Date();
	date_consult = new Date(2008,3,15,0,0,0);
	//alert(maintenant);
	if (date_consult>maintenant)
	{
		$("#div_attente").show();
	}
	else
	{
		window.open('http://consultation.prenons-soin-de-leau.fr','_blank');
	}
}

function affich_noir(){
	$("#fond_video").show();

	
	opa_black= opa_black + 0.1;
	if (opa_black>0.7){
		clearTimeout(timer_black);
		$("#div_video").show();

	}
	else
	{
		timer_black=setTimeout(function() {
			$("#fond_video").css("-moz-opacity",opa_black);
			$("#fond_video").css("opacity",opa_black);
			affich_noir();
			
		}, 20);	
	}
}
function cache_noir() {
	
	opa_black= opa_black - 0.1;
	if (opa_black<0){
		clearTimeout(timer_black);
		$("#fond_video").hide();

		
	}
	else
	{
		timer_black=setTimeout(function() {
			$("#black_center").css("-moz-opacity",opa_black);
			$("#black_center").css("opacity",opa_black);
			cache_noir();

			
		}, 20);	
	}
	
}