if (typeof js == 'undefined'){
	js = {};
}

toutou.require('toutou.js.object');
toutou.require('toutou.html.event');
toutou.require('toutou.event.manager');
toutou.require('toutou.html.dom');
toutou.require('toutou.html.layout');
toutou.require('toutou.utils.forms');
toutou.require('toutou.frame.defaultFrame');
toutou.require('toutou.effect.scroll');

js.saintandre = new function() {
	
	this.showSousMenu = function(id) {
		var elem = tt$(id);
		elem.style.display = 'block';
		if (id == 'sous_menu_visiter') {

			var select = tt$('civilite');

			if (select) {
				select.style.visibility = 'hidden';	
			}
		}
	}
	
	this.hideSousMenu = function(id) {
		var elem = tt$(id);
		elem.style.display = 'none';
		
		if (id == 'sous_menu_visiter') {

			var select = tt$('civilite');

			if (select) {
				select.style.visibility = 'visible';	
			}
		}
	}
	
	this.contact = function (input, mode){
		var ok = false;
		
		var value = null;
		if(mode == 'liste') {
			value = input.options[input.selectedIndex].value;
		} else {
			value = input.value;
		}

		if(mode == 'email') {
			//controle email			
			if (this.verifEmail(value)){
				ok = true;
			}
		}	
		
		if(mode == 'texte') {
			//controle nom
			if(value != ''){
				ok = true;
			}
		}
		
		if(mode == 'liste') {
			//controle la non nullité de l'element sélectionné
			if(value != 0){
				ok = true;
			}
		}
		
		if(mode == 'passwordconfirm') {
			//controle nom
			if(tt$('mot_de_passe').value == tt$('mot_de_passe_confirm').value){
				ok = true;
			}
		}
		
		if(ok) {
			tt$('para_' + input.id).className = 'warning_off';
			return true;
		} else {
			tt$('para_' + input.id).className = 'warning_on';
			
			return false;
			
		}
	}
	
	this.verifEmail = function(/* String */ inputEmail) {
		var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
	
		if (inputEmail == '') 
			return false;
	
		if (inputEmail != '' && !regex.test(inputEmail))
			return false;
	
	        return true;
	}
	
	this.submitContact = function() {
		var ok_mail 	= this.contact(tt$('email')		, 'email');
		var ok_nom 		= this.contact(tt$('nom')		, 'texte');
		var ok_prenom 	= this.contact(tt$('prenom')	, 'texte');
		var ok_demande 	= this.contact(tt$('demande')	, 'texte');
		if(!ok_mail || !ok_nom || !ok_prenom || !ok_demande) {
			return false;
		}
		
		return true;
	}
}
