Event.observe(window,'load',function(e){
	gestionPage = new Contact();	
});

var Contact = Class.create(); 
Contact.prototype = { 
				
	initialize: function() {
		this.orderField = $$('.orderField');
		this.orderFieldClass = 'labelOrderField';
		this.form = $('form_contact');
		this.information = $$('#form_contact select');
		this.textarea = 'description' ;
		this.init();
	},	
	
	init: function() {
		this.orderField.each(this.initField.bindAsEventListener(this));
		this.information.each(this.initSelect.bindAsEventListener(this));
		Event.observe(this.form,'submit',this.submit.bindAsEventListener(this));
	},
	
	initField: function(elt){
		Event.observe(elt,'blur',this.isEmptyField.bindAsEventListener(this));
  	},
	
	initSelect: function(elt){
		Event.observe(elt,'change',this.isEmptyField.bindAsEventListener(this));
	},
  	
  	isEmptyField: function(e){
  		elt = e.element();
  		if(elt.value == '' || elt.value== 0){
  			$(elt.id+'_label').addClassName(this.orderFieldClass);
  		} else {
  			$(elt.id+'_label').removeClassName(this.orderFieldClass);
  		}
  	},

	submit: function(e){
		var liste = $$('#form_contact .labelOrderField');
		var total = liste.length - 1;
		var valid = true ;
		liste.each(function(elt){			
			if(elt.value == "")
				valid = false ;			
		})
		
		if(total>0 && !valid){
			Event.stop(e);
			new Alert('<p class="failed">Merci de remplir tous les champs obligatoire afin que nous puissions traiter votre demande. Il vous reste '+total+' champ(s) à remplir.');
		} else if (this.textarea.value == ''){
			Event.stop(e);
			new Alert('<p class="failed">Merci de bien vouloir entrer un message afin que nous puissions traiter votre demande.');
		}
		
	}
	


	
	
		
};	


