// JavaScript Document



$(function(){

		   

		   



		   

	show_hide_bts()

	

	// CLICK SUR ENVOYER

	$('.envoyer').bind('click', function(){

		if(valide_etape(5)) $('FORM').submit();

	})

	

	// CLICK SUR ETAPE SUIVANTE

	$('.bouton_suivante').bind('click', function(){

										

		n=$('#etape_suivante').attr('rel');

		if(valide_etape(n-1)){

			

			$('.content').animate({height:'20px'},700, function(){

				$('TABLE#etape_'+(n-1)).hide();

				$('TABLE#etape_'+n).show();

				h=$('TABLE#etape_'+n).height();

				$('.content').animate({height:'20px'}).animate({height:h},750);

				m=Math.round(n)+1;

			

				$('#etape_precedente').attr('rel',(n-1));

				$('#etape_precedente').html((n-1));

				$('#etape_suivante').attr('rel',m);

				$('#etape_suivante').html(m);

				$('#etape_actuelle').html((n));

				show_hide_bts()

			})

		}

		

		

	})

	$('.bouton_precedente').bind('click', function(){



		n=$('#etape_precedente').attr('rel');

		

		m=Math.round(n)+1;

		

		$('.content').animate({height:'20px'},700, function(){

			$('TABLE#etape_'+(n)).show();

			$('TABLE#etape_'+m).hide();

			h=$('TABLE#etape_'+n).height();

			$('.content').animate({height:'20px'}).animate({height:h},750);

			j=Math.round(n)-1;

			$('#etape_precedente').attr('rel',j);

			$('#etape_precedente').html(j);

			$('#etape_suivante').attr('rel',m);

			$('#etape_suivante').html(m);

			$('#etape_actuelle').html(m-1);

			show_hide_bts()

		})

		

	

	})

	

	

		   

})



	function show_hide_bts(){

		

		

		if ($('#etape_precedente').attr('rel')=='0'){

			

			$('.bouton_precedente').hide();

		}

		else $('.bouton_precedente').show();

		

		if($('#etape_suivante').attr('rel')==$('.etape').length+1){

			$('.envoyer').show();

			$('.bouton_suivante').hide();

		}

		else {

			$('.envoyer').hide();

			$('.bouton_suivante').show();

		}

	}

	

	

	function valide_etape(n){

		

		errors=false

		$('TABLE#etape_'+(n)+ ' :input').each(function(){

			

				if(!_valide_($(this).attr('rel'), $(this).attr('class'))) {errors=true;	$('html').animate({scrollTop: $(this).offset().top},500);}

			

				

		})

		

		if(errors==false) { return true;}

		else {

			if ($.browser.msie || $.browser.opera) {

				alert($('.alert').text());

			}

			else{

				$('#ecran').css('opacity',0.9);

				$('.alert, #ecran').fadeIn(250)

				$('.alert, #ecran').bind('click', function(){$('.alert,#ecran').fadeOut(150)});

			}

			

		}

	}

	function exergue (_class_, _type_){

		

		if(_type_=='radio')	$('.'+_class_).parents('.etape TR').css({color:'red'})	;

		else $('.'+_class_).parents('TR:first').find('label').css({color:'red'});

	}

	

	function normal(_class_, _type_){

			if(_type_=='radio') $('.'+_class_).parents('.etape TR').css({color:'#5E5E5E'})	;

			else $('.'+_class_).parents('TR:first').find('label').css({color:'#5E5E5E'})

			

	}

	

	function _valide_(_type_,_class_){

	

		

		_class_=_class_.split(' ').pop();

		switch (_type_){ 

			case  'selected'  :

				

				

				if($('.'+_class_+':checked').length>0) {normal(_class_, 'radio'); return true; }

				else exergue(_class_,'radio')

				

					  

			break;

			

			case  'string'  :

				if($('.'+_class_).hasClass('null') && $('.'+_class_).val()=='') isNull = true

				else isNull = false

				if($('.'+_class_).val().match(/[a-zA-Z0-9-'çàâäéèëêïîöôüûù]{3,}/) || isNull) {normal(_class_,null); return true;}

				else exergue(_class_,null);

				

				

			break;

			

			case  'mail'  :

				if($('.'+_class_).hasClass('null') && $('.'+_class_).val()=='') isNull = true

				else isNull = false

				if($('.'+_class_).val().match(/[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-\._]+\.[a-zA-Z\.]{2,}/) || isNull) {normal(_class_,null); return true;}

				else exergue(_class_,null);

				

			break;

			

				break;

			

			case  'tel'  :

				if($('.'+_class_).hasClass('null') && $('.'+_class_).val()=='') isNull = true

				else isNull = false

				if($('.'+_class_).val().match(/[0-9+\.\s\-]{8,}/) || isNull) {normal(_class_,null); return true;}

				else exergue(_class_,null);

				

			break;

			case  'url'  :

				if($('.'+_class_).hasClass('null') && $('.'+_class_).val()=='') isNull = true

				else isNull = false

				if($('.'+_class_).val().match(/[a-zA-Z0-9\-\._]+\.[a-zA-Z\.]{2,}/) || isNull) {normal(_class_,null); return true;}

				else exergue(_class_,null);

				

			break;

			case  'num'  :

				if($('.'+_class_).hasClass('null') && $('.'+_class_).val()=='') isNull = true

				else isNull = false

				if($('.'+_class_).val().match(/^[0-9]{1,2}$/) || isNull) {normal(_class_,null); return true;}

				else exergue(_class_,null);

				

			break;

			

			default : return true;

		}

	}

	

	function load(){

	}

	

	
