//      lib_annonces.js
//      
//      Auteur : Marc FREREBEAU <marc.frerebeau@agama.fr>
//      Société : AGAMA, www.agama.fr
//      Licence : GPL
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//      
//      
//      Application : Monplannnig
//      Version : 2.0 
//      
//      Nom module : annonces
//      Description :
//      	Gère les appels du module annonce	
//      Nécessite : 
//      	prototype.js	
//      Date : 06/05/2010
//      Version : 0.1

Event.observe( window, 'load', init_accueil_annonces, false );

/*
* Fonction init_accueil_annonces
* 
* 	
* Description :
* 
* 
* Entrées :
* @Néant
* 
* Sorties :
* @Néant
* 
* Valeur de retour :
* 0 : pas d'erreur
* 1 : une erreur s'est produite
* 
* Auteurs : Marc FREREBEAU
* Date dernière modification : 30/03/2011
* Commentaires :
*		
*/
function init_accueil_annonces(  )
{
	afficher_div_du_groupe( '', 'inter_' );
}
//////////////////////////////////////////////////////////////////////
// Fonction annonce_contacter
//
// Description :
//		Envoi la demande d'affichage du formulaire de contact relatif 
//		à l'annonce.
// Entrées :
//		@reference (string) : référence de l'annonce
// Sorties :
//		@Néant
// Valeur de retour :
//		@Néant
// Auteurs : Marc FREREBEAU
// Date dernière modification : 06/05/2010
// Commentaires :
//		
//////////////////////////////////////////////////////////////////////
function annonce_contacter( reference )
{
	var form = document.createElement('form');
	form.action = '/annonces/contacter.php';
	form.method = 'post';
	var champ = document.createElement('input');
	champ.type = 'hidden';
	champ.name = 'reference';
	champ.value = reference;
	form.appendChild( champ );
	// Ajoute le formulaire à la page
	document.getElementsByTagName('body')[0].appendChild( form );
	// Soumet le formulaire
	form.submit();	
}

//////////////////////////////////////////////////////////////////////
// Fonction envoyer_formulaire_contact
//
// Description :
//		Valide le formulaire et l'envoie le cas échéant.
// Entrées :
//		@Néant
// Sorties :
//		@Néant
// Valeur de retour :
//		*Néant
// Auteurs : Marc FREREBEAU
// Date dernière modification : 06/04/2010
// Commentaires :
//		
//////////////////////////////////////////////////////////////////////
function envoyer_formulaire_contact_annonce()
{
	var form = $('formulaire_contact_annonce');
	if( valider_formulaire_contact_annonce( form ) )
		// envoie le formulaire
		form.submit();
}

//////////////////////////////////////////////////////////////////////
// Fonction valider_formulaire_contact
//
// Description :
//		Valide le formulaire
// Entrées :
//		@form (objet) : formulaire
// Sorties :
//		@Néant
// Valeur de retour :
//		* true : le formulaire peut être envoyé
//		* false : formulaire ne doit pas être envoyé
// Auteurs : Marc FREREBEAU
// Date dernière modification : 06/04/2010
// Commentaires :
//		
//////////////////////////////////////////////////////////////////////
function valider_formulaire_contact_annonce( form )
{
	var notification_format = false;
	
	if( $F('reference') == '' ) 
	{
		notification_format = true;
		$('reference').className = 'erreur';
	}
	else
		$('reference').className = '';
		
	if( ( $F('nom') == '' ) || !lib_validation_est_nom( $F('nom') ) )
	{
		notification_format = true;
		$('nom').className = 'erreur';
	}
	else
		$('nom').className = '';
		
	if( ( $F('prenom') != '' ) && !lib_validation_est_nom( $F('prenom') ) )
	{
		notification_format = true;
		$('prenom').className = 'erreur';
	}
	else
		$('prenom').className = '';
		
	if( ( $F('telephone') != '' ) && !lib_validation_est_telephone( $F('telephone') ) )
	{
		notification_format = true;
		$('telephone').className = 'erreur';
	}
	else
		$('telephone').className = '';
		
	if( ( $F('email') == '' ) || !lib_validation_est_email( $F('email') ) )
	{
		notification_format = true;
		$('email').className = 'erreur';
	}
	else
		$('email').className = '';

	if( $F('message') == '' ) 
	{
		notification_format = true;
		$('message').className = 'erreur';
	}
	else
		$('message').className = '';
		
	if( notification_format )
		Element.show('notification_format');
	else
		Element.hide('notification_format');

	if( notification_format )
		return false;
		
	return true;
}

