
/**
* VARIABLES
*/

var _NEWS_SCROLLING 		= false;
var _NEWS_SCROLLING_PAS		= 1;
var _NEWS_SCROLLING_Y		= 0;
var _NEWS_SCROLLING_Y_MIN	= 100;
var _NEWS_SCROLLING_TIME	= 100;



/**
* SCROLL DES NEWS
*/

function scroll_news( state )
  {
	if( state == "stop" )
	  {
		_NEWS_SCROLLING = false;
	  }
	else if( state == "start" )
	  {
		_NEWS_SCROLLING = true;
	  }


	if( _NEWS_SCROLLING == true )
	  {
		var hauteur_bloc_news = dimensions_element( "news_content" , "h" );

		if( (_NEWS_SCROLLING_Y - _NEWS_SCROLLING_PAS) < -(hauteur_bloc_news - _NEWS_SCROLLING_Y_MIN) )
		  {
			_NEWS_SCROLLING_Y = _NEWS_SCROLLING_Y_MIN;
			opacity( "news_content" , 100, 0 , 400 );
			setTimeout( "document.getElementById( 'news_content' ).style.marginTop = '" + _NEWS_SCROLLING_Y + "' + 'px';" , 400 );
			setTimeout( "opacity( 'news_content' , 0, 100 , 400 );" , 400 );
			setTimeout( "scroll_news();" , 400 );
		  }
		else
		  {
			_NEWS_SCROLLING_Y = _NEWS_SCROLLING_Y - _NEWS_SCROLLING_PAS;
			document.getElementById( "news_content" ).style.marginTop = _NEWS_SCROLLING_Y + "px";
			setTimeout( "scroll_news();" , _NEWS_SCROLLING_TIME );
		  }

	  }
  };


/**
* CHANGEMENT DES SOUS MENU
*/

function change_ss_menu( nb , current )
  {
	for( i=1 ; i<nb+1 ; i++ )
	  {
		document.getElementById( "ss_menu_" + i ).style.display = ( i == current ? "" : "none" );
	  }
  };

function verif_mail( mail )
  {
	var arobase = mail.indexOf("@");
	var point = mail.lastIndexOf(".");
	if((arobase < 2)||(point + 2 > mail.length) || (point < arobase+3))
	  {
		return false;
	  }
	return true;
  };

/**
* CONTROLE DU FORMULAIRE DE CONTACT
*/
	
function contact_form()
  {
	if( document.getElementById( "nom_prenom" ).value=="" )
	  { 
		alert('Attention : le champ "Nom" est vide!')
		document.getElementById( "nom_prenom" ).focus();
		return false;
	  }
	if( !verif_mail( document.getElementById( "email_contacts" ).value ) )
	  { 
		alert('Attention : email invalide !')
		document.getElementById( "email_contacts" ).focus();
		return false;
	  }
	if( document.getElementById( "message" ).value=="" )
	  { 
		alert('Vous n\'avez pas écrit de message...')
		document.getElementById( "message" ).focus();
		return false;
	  }			

	document.getElementById( "contact_form" ).submit();
  };

/**
* CONTROLE DU FORMULAIRE DU DEVIS
*/

function formulaire_devis()
  {
	if( document.getElementById( "nom" ).value=="" )
	  { 
		alert('Attention : le champ "Nom" est vide!')
		document.getElementById( "nom" ).focus();
		return false;
	  }
	if( document.getElementById( "prenom" ).value=="" )
	  { 
		alert('Attention : le champ "Prénom" est vide!')
		document.getElementById( "prenom" ).focus();
		return false;
	  }
	if( !verif_mail( document.getElementById( "email" ).value ) )
	  { 
		alert('Attention : email invalide !')
		document.getElementById( "email" ).focus();
		return false;
	  }			

	document.getElementById( "devis_form" ).submit();
  };



/**
* ===========================================================================================================================================================================
*/


/**
* AFFICHE UN POPUP DE CONFIRMATION ET RETOURNE "TRUE" OU "FALSE"
*/

function confirmer( commentaire )
  {
	if( confirm( commentaire ) )
	  {
		return true;
	  }
	else
	  {
		return false;
	  }
  };

/**
* AFFICHE OU CACHE UN ELEMENT PAR SON ID
*/

function hide_element( id_element )
  {
	element = document.getElementById( id_element );

	if( element.style.display == "none")
	   {
		element.style.display	= "";
	   }
	else
	   {
		element.style.display	= "none";
	   }
  };

/**
* RENVOYE LES DIMENSIONS D'UN ELEMENT
*/

function dimensions_element( id_element , wat )
  {
	var element = document.getElementById( id_element );

	largeur = element.offsetWidth;
	hauteur = element.offsetHeight;

	if( largeur==0 )
	  {
		largeur = element.offsetWidth;
	  }
	if( hauteur==0 )
	  {
		hauteur = element.offsetHeight;
	  }

	if( wat == "l" )
	  {
		return largeur;
	  }
	else if( wat == "h" )
	  {
		return hauteur;
	  }
	else if( wat == "lh" )
	  {
		return new Array( largeur , hauteur );
	  }
  };

/**
* SLIDESHOW
*/

function slideshow( id , filename, filext, nb , current , precharge )
  {
	if( precharge == undefined )	/* 1er lancement, préchargement des images */
	  {
		var images	= new Array();
		var t		= 0;
		
		for( var n=1 ; n<nb+1 ; n++ )
		  {
			images[ t ] = filename + n + filext;
			t++;
		  }

		precharge_images( images );
		setTimeout( "slideshow( '" + id + "' , '" + filename + "', '" + filext + "', '" + nb + "' , '" + current + "' , false )" , 2000 );
	  }
	else
	  {
		var img		= id + "_img";
		var img_tmp		= id + "_img_tmp";


		if( current == nb )
		  {
			current = 1;
		  }
		else
		  {
			current++;
		  }

		document.getElementById( img_tmp ).src = filename + current + filext;

		setTimeout( "opacity( '" + img + "' , 100 , 0 , 500 );" , 300 );
		setTimeout( "opacity( '" + img_tmp + "' , 0 , 100 , 500 );" , 300 );

		setTimeout( "document.getElementById('" + img + "').src = document.getElementById('" + img_tmp + "').src;" , 1010 );

		setTimeout( "change_opacity( '" + img + "' , 100 );" , 1020 );
		setTimeout( "change_opacity( '" + img_tmp + "' , 0 );" , 1020 );

		setTimeout( "slideshow( '" + id + "' , '" + filename + "', '" + filext + "', '" + nb + "' , '" + current + "' , false );" , 4000 );
	  }
  };


/**
* PRECHARGE LES IMAGES
*/

function precharge_images( images )
  {
	if( document.images )
	  {
		if( !document.images_prechargees )
		  {
			document.images_prechargees = new Array();
		  }

		var l = document.images_prechargees.length;

		for( var i=0 ; i<images.length ; i++ )
		  {
			if( images[ i ].indexOf("#")!=0 )
			  {
				document.images_prechargees[ l ]		= new Image;
				document.images_prechargees[ l ].src	= images[ i ];
				l++;
			  }
		  }
	  }
  };


/**
* CHANGE L'OPACITÉ D'UN ÉLEMENT
*/

function change_opacity( id , opacity )
  {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
  };

/**
* CHANGE L'OPACITÉ D'UN ÉLEMENT AVEC ANNIMATION ET TIMER
*/

function opacity( id , opacity_start, opacity_end , millisec )
  {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(opacity_start > opacity_end)
	  {
		for( i=opacity_start ; i>=opacity_end ; i-- )
		  {
			setTimeout( "change_opacity( '" + id + "' , " + i + " )" , (timer * speed) );
			timer++;
		  }
	  }
	else if(opacity_start < opacity_end)
	  {
		for( i=opacity_start ; i<=opacity_end ; i++ )
		  {
			setTimeout( "change_opacity( '" + id + "' , " + i + " )" , (timer * speed) );
			timer++;
		  }
	  }
  };

/**
* EXECUTE UN SCRIPT (AJAX)
*/

function request( url , cadre )
  {
	var XHR = null;
	if(window.XMLHttpRequest) 		/* Firefox */
	  {
		XHR = new XMLHttpRequest();
	  }
	else if(window.ActiveXObject) 	/* Internet Explorer */
	  {
		XHR = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	  }

	XHR.open("GET",url, true);				/* Envoie de la requete, methode GET et de l'url */
	XHR.onreadystatechange = function attente()	/* On guette les changements d'etat de l'objet */
	  {
		if(XHR.readyState == 4)				/* L'etat est a 4, requete recu ! */
		  {
			document.getElementById( cadre ).innerHTML = XHR.responseText;	/* Ecriture de la reponse */
		  }
		else
		  {
		  }
	  };
	XHR.send(null);						/* Le travail est termine */
	return;
  };



/**
* LIMITE LE NOMBRE DE CARACTERE DANS UN CHAMP
*/

function limit_text_length( id_element , number )
  {
	if( document.getElementById( id_element ).value.length > number )
	  {
		document.getElementById( id_element ).value = document.getElementById( id_element ).value.substring( 0 , number );
	  }

	var argv = limit_text_length.arguments;

	if( argv[2] )
	  {
		document.getElementById( argv[2] ).innerHTML = ( number - document.getElementById( id_element ).value.length );
	  }
  };


/**
* CACHE TOUTES LES ANNIMATIONS FLASH
*/

function hide_flash_objects( action )
  {
	var objects	= document.getElementsByTagName( "object" );
	var embeds	= document.getElementsByTagName( "embed" );

	for(var i = 0; i < objects.length; i++)
	  {
		objects[ i ].style.visibility = action;
	  }

	for(var i = 0 ; i < embeds.length ; i++ )
	  {
		embeds[ i ].style.visibility = action;
	  }
  };



/**
* INTRO AVEC LE CALENDRIER
*/

var intro_en_cours = false;

function intro()
  {
	intro_en_cours = true;
	hide_flash_objects( "hidden" );

	setTimeout( "opacity( 'intro_splash' , 0 , 100 , 1000 );" , 1000 );
	setTimeout( "end_intro();" , 4000 );
  };

function skip_intro()
  {
	hide_flash_objects( "visible" );
	document.getElementById( "intro" ).style.display = "none";
	end_intro();
  };

function end_intro()
  {
	if( intro_en_cours == true )
	  {
		intro_en_cours = false;
		opacity( "intro" , 100 , 0 , 1000 );
		setTimeout( "document.getElementById( 'intro' ).style.visibility = 'hidden';" , 1000 );
		setTimeout( "hide_flash_objects( 'visible' );" , 200 );

		change_opacity( "slideshow_accueil" , 0 );
		setTimeout( "opacity( 'slideshow_accueil' , 0 , 100 , 2000 );" , 200 );
		setTimeout( "slideshow( 'slideshow_accueil' , '" + _ROOT + "/images/accueil_' , '.jpg' , 5 , 1 );" , 4000 );

	  }
  };


