////////////////////////////
//                        //
//      FORMULAIRES       //
//                        //
////////////////////////////

// Fonction pour faire apparaitre une illustration.
function afficheBlock(pref,id){
	var elmt = document.getElementById(pref+'_'+id);
	if (elmt){
		elmt.style.display = 'block';
	}
}

// Fonction pour faire disparaitre une illustration.
function cacheBlock(pref,id){
	var elmt = document.getElementById(pref+'_'+id);
	if (elmt){
		elmt.style.display = 'none';
	}
}

// Fonction pour indiquer ce qu'il faut faire dans le champ de recherche de texte.
function onText(champ, text){
	if(champ.value == text){
		champ.value = '';
	}
}
function outText(champ, text){
	if(champ.value == ''){
		champ.value = text;
	}
}

// Fonction test de champ vide.
function testVide(champ){
	if (champ.value.length == 0){
		champ.focus();
		highlightChamp(champ); // on met le champ en avant.
		return 'non';
    }
    if (champ.value.length > 0){
        var tout_espaces='oui';
    	for (var i = 0; i < champ.value.length; i++){
        	if (champ.value.substring(i, i + 1) != ' '){ tout_espaces='non'; }
      	}
      	if (tout_espaces=='oui'){
			champ.focus();
			highlightChamp(champ); // on met le champ en avant.
			return 'non';
      	}
    } 
	shadowChamp(champ); // on remet le champ par défaut.
	return 'ok';
}

// Fonction de vérification de saisie d'email au bon format.
function verifMail(email){
	if (email.value != ''){
		var reg_mail = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
		if (!(reg_mail.exec(email.value)!=null)){
			email.focus(); // on selectionne le champ concerné.
			highlightChamp(email); // on met le champ en avant.
			return 'non';
		}
		else {
			shadowChamp(email); // on remet le champ par défaut.
			return 'ok';
		}
	}
	else {
		email.focus(); // on selectionne le champ concerné.
		highlightChamp(email); // on met le champ en avant.
		return 'non';
	}
}

// Fonction pour mettre en surbrillance un champ quand il n'est pas rempli.
function highlightChamp(champ){
	if (champ.tagName.toLowerCase() == 'select'){
		champ.className = 'selectOn';
	} else {
		champ.className = champ.type.toLowerCase()+'On';	
	}
}

// Fonction pour enlever la surbrillance a un champ.
function shadowChamp(champ){
	if (champ.tagName.toLowerCase() == 'select'){
		champ.className = 'select';
	} else {
		champ.className = champ.type.toLowerCase();	
	}
}

// Verification question.
function verifAmi(form){
	if (testVide(form.EmailE) != 'ok') {return 'non'}
	if (verifMail(form.EmailE) != 'ok') {return 'non'}
	if (testVide(form.EmailD) != 'ok') {return 'non'}
	if (verifMail(form.EmailD) != 'ok') {return 'non'}
	return 'ok';
} 
function valAmi(){
	if (verifAmi(document.ami)=='ok') {
		document.ami.submit();
	}
}

// Fonction pour mettre en bookmark
function bookmark(title, url){
	if (window.sidebar){ // Firefox 
		window.sidebar.addPanel(title,url,"");
	}
	else if (window.opera && window.print){ // Opera 
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if (document.all){ // IE 
		window.external.AddFavorite(url,title);
	}
	//else { alert("Browser not supported, so please add your bookmark manually (Ctrl+D)."); }
}

