function hide() {
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
}

function montre(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	if (d) {d.style.display = 'block';}
}


function ValidContact(){
	var msg  = "";
	var errors = 0;
	var form = document.forms['fcontact'];
	var email;
	var arobase;
	var point;

	// Verification du nom et prenom
	if( form.elements['nom'].value == "" ){
		msg += "- Votre nom et prenom.\n";
	};
	// Verification du nom et prenom
	if( form.elements['adresse'].value == "" ){
		msg += "- Votre adresse.\n";
	};
	// Verification du nom et prenom
	if( form.elements['code_postal'].value == "" ){
		msg += "- Votre code postal.\n";
	};
	// Verification du nom et prenom
	if( form.elements['ville'].value == "" ){
		msg += "- Votre vile.\n";
	};
	// Verification du nom et prenom
	if( form.elements['telephone'].value == "" ){
		msg += "- Votre téléphone.\n";
	};
	// Verification du nom et prenom
	var trouve = false;
	var nb_check = 5;
	for ( cpt = 0 ; cpt < nb_check ; cpt ++ )
	{
		if (document.getElementById('check_besoin_' + (cpt + 1)).checked)
		{
			trouve = true;
		}
	}
	if (!trouve)
	{
		msg += "- La nature de votre besoin.\n";
	}

	// Verification de l'email
	if( form.elements['email'].value == "" ){
		msg += "- Votre email.\n";
	}else{
		email = form.elements['email'].value;
		arobase = email.indexOf("@")
		point = email.lastIndexOf(".")
		if( (arobase < 3) || (point + 2 > email.length) || (point < arobase+3) ){
			msg += "- Une adresse e-mail valide.\n";
		}
	}

	// Verification du message
	if( form.elements['message'].value == "" ){
		msg += "- Un message.\n";
	}

	// Validation si pas d'erreur - sinon affichage message
	if( msg != "" ){
		var str = "Vous avez omis de remplir les champs suivants :\n\n" + msg;
		alert( str );
		return false;
	} else {
		return true;
	}
}


function ValidAvis()
{
	var msg  = "";
	var form = document.forms['favis'];

	// Verification de 'Qui êtes vous ?'
	if( form.elements['infos'].value == "" ){
		msg += "- Votre identite.\n";
	};
	
	// Verification du nom et prenom
	if( form.elements['message'].value == "" ){
		msg += "- Votre avis.\n";
	};
	
		// Validation si pas d'erreur - sinon affichage message
	if( msg != "" ){
		alert("Vous avez omis de remplir les champs suivants :\n\n" + msg);
		return false;
	} else {
		return true;
	}
}

function popup( file_name, file_width, file_height )
{
	var top    = (screen.height - file_height) / 2;
	var left   = (screen.width - file_width) / 2;
	var width  = parseInt(file_width) + 16;
	var height = parseInt(file_height) + 16;
	
	window.open( file_name, 'ets_fontaine', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', toolbar=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no');
	return false;
}

function affichFormEnPlus()
{
	var nb_check = 5;
	var affich = false;
	for (var cpt = 0 ; cpt < nb_check - 1 ; cpt ++)
	{
		//alert( document.getElementById('check_besoin_' + (cpt + 1)).checked );
		if (document.getElementById('check_besoin_' + (cpt + 1)).checked)
		{
			affich = true;
		}
	}
	if (affich)
	{
		document.getElementById('form_en_plus').style.display = 'block';
	}
	else
	{
		document.getElementById('form_en_plus').style.display = 'none';
	}
}


function utf8_decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {

		c = utftext.charCodeAt(i);

		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}

	}

	return string;
}

function utf8_encode(str)
{

	var utftext = "";
      if ( str ) {
         str = str.replace(/\r\n/g,"\n");
         for (var n = 0; n < str.length; n++) {
            var c = str.charCodeAt(n);
            if (c < 128) {
	            if ( c < 32 )
	            	utftext += ' ';
	            else
	            	utftext += String.fromCharCode(c);               
            }
            else if ((c > 127) && (c < 2048)) {
               utftext += String.fromCharCode((c >> 6) | 192);
               utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
               utftext += String.fromCharCode((c >> 12) | 224);
               utftext += String.fromCharCode(((c >> 6) & 63) | 128);
               utftext += String.fromCharCode((c & 63) | 128);
            }
         }
      }
      return utftext;
}
