function selSecteurEntChange( ) {
	$('selTailleEnt').show();
}
function selVousEtesChange( ) {
	var choix = ( $('selVousEtes').value );
	$('fonction').value = '';
	if( "collectivite" == choix  )
	{
		$('selTailleCollectivite').show();
		$('selSecteur').hide();
		$('selFunctionCollectivite').hide();
		$('selTailleEnt').hide();
		$('selFunctionEnt').hide();
	}
	else if( "entreprise" == choix )
	{
		$('selTailleCollectivite').hide();
		$('selFunctionCollectivite').hide();
		$('selSecteur').show();
		$('selTailleEnt').hide();
		$('selFunctionEnt').hide();
	}
	else if( "etudiant" == choix || "particulier" == choix || "journaliste" == choix )
	{
		$('selSecteur').hide();
		$('selTailleCollectivite').hide();
		$('selFunctionCollectivite').hide();
		$('selTailleEnt').hide();
		$('selFunctionEnt').hide();
		$('fonction').value = document.getElementById('selVousEtes').options[document.getElementById('selVousEtes').selectedIndex].text;
		$('pfonction').show();
	}
	else if( "" != choix )
	{
		$('selTailleCollectivite').hide();
		$('selFunctionCollectivite').hide();
		$('selSecteur').hide();
		$('selTailleEnt').show();
		$('selFunctionEnt').hide();
	}
	else
	{
		$('selTailleCollectivite').hide();
		$('selFunctionCollectivite').hide();
		$('selSecteur').hide();
		$('selTailleEnt').hide();
		$('selFunctionEnt').hide();
	}
	$('selTailleCollectivite').selectedIndex = 0;
	$('selFunctionCollectivite').selectedIndex = 0;
	$('selSecteur').selectedIndex = 0;
	$('selTailleEnt').selectedIndex = 0;
	$('selFunctionEnt').selectedIndex = 0;
}
function selTailleColChange( ) {
	$('selFunctionCollectivite').show();
}
function selTailleEntChange( ) {
	if( $('selTailleEnt').value != 'travailleur independant' && $('selTailleEnt').value != '' )
		$('selFunctionEnt').show();
	else
	{
		$('selFunctionEnt').hide();
		$('fonction').value = 'travailleur independant';
		$('pfonction').show();
	}
}
function selFctEntChange( ) {
	$('fonction').value = $('selFunctionEnt').value;
	$('pfonction').show();
}
function selFctColChange( ) {
	$('fonction').value = $('selFunctionCollectivite').value;
	$('pfonction').show();
}
function affdiv( type ) {
	$('verifUser').hide();
	$('formulaireQuestion').hide();
	$('selTailleCollectivite').hide();
	$('selFunctionCollectivite').hide();
	$('selTailleEnt').hide();
	$('selFunctionEnt').hide();
	$('pfonction').hide();
	if( type == 1 )
	{
		$('firstQuestion').show();
		$('verifUser').show();
	}
	else
		$('formulaireQuestion').show();
}
function trim (str, chars) {
  return ltrim(rtrim(str, chars), chars);
}
function ltrim (str, chars){
    var car = (chars != undefined) ? chars : "\\s";
    return str.replace(new RegExp("^[" + car + "]*", "g"), "");
}
function rtrim (str, chars){
    var car = (chars != undefined) ? chars : "\\s";
    return str.replace(new RegExp("[" + car + "]*$", "g"), "");
}
var cptQuestion1 = 0;
function submitQuestionSecond(){
	var opt = {
  	method: 'post',
  	postBody: 'action=verifsecond&'+$('result').serialize(),
  	onSuccess: function(transport) {
  		cptQuestion1 = 0;
 			var rep 	= transport.responseText;
 			var bool 	= rep.substring(0,1);
 			var texte	=	rep.substring(1);
			( bool != 1 ) ? alert( texte ) : window.location = texte;
  	}
	};
	if( cptQuestion1 == 0 )
	{
		cptQuestion = 1;
		new Ajax.Request( "lib/dispatcher.php" , opt );
	}
}

//Evite double appel à la soumission
var cptQuestion = 0;
function submitQuestionFirst( e ) {
	Event.stop( e );
	var opt = {
  	method: 'post',
  	postBody: 'action=verifFirst&'+$('result').serialize(),
  	onSuccess: function(transport) {
  		cptQuestion = 0;
 			var rep 	= transport.responseText;
 			var bool 	= rep.substring(0,1);
 			var texte	=	rep.substring(1);
			if( bool != 1 )
				alert( texte )
			else
			{
				$('firstQuestion').hide();
				//Change l'image etape 2 vers etape 3
				if( $('imagetitre') )
					$('imagetitre').src = 'http://test.svp.fr/template/template1/titre3.png';
				$('input_supplementaire').show();
				Event.stopObserving('btFirst', 'click', submitQuestionFirst);
				Event.observe('btFirst1', 'click', submitQuestionSecond);
				new Effect.ScrollTo('input_supplementaire');
			}
  	}
	};
	if( cptQuestion == 0 )
	{
		cptQuestion = 1;
		new Ajax.Request( "lib/dispatcher.php" , opt );
	}
}
//Initialisation
function initApp( e ) {
	Event.stop(e);
	$('input_supplementaire').hide();
	$('selSecteur').hide();
	$('selTailleCollectivite').hide();
	$('selFunctionCollectivite').hide();
	$('selTailleEnt').hide();
	$('selFunctionEnt').hide();
	$('pfonction').hide();

	//Ecoute du boutton de soumission
	Event.observe( 'btFirst', 'click', submitQuestionFirst );
	//Ecoute le champ question
	Event.observe( 'question', 'click', function(){
		if( "Posez votre question dans cette zone." == $('question').value )
			$('question').value = "";
	}) ;
	/** Tooltips sur les liens */
	$$(".help").each( function(link) {
		new Tooltip(link, {mouseFollow: true, opacity: 1,backgroundColor: "#CBD7E7", textColor:"#304477"});
	});

	var dpck_fieldname = new DatePicker({
	relative:'daterappel',
	language:'fr',
	keepFieldEmpty:true,
	zindex :10,
	dateFilter:DatePickerUtils.noWeekends().append(DatePickerUtils.noDatesBefore(1)).append(DatePickerUtils.noDatesAfter(60))
});
}
Event.observe( window ,'load', initApp );