function kspace(x){
while((x.length>0) && (x.charAt(0)==' '))
x = x.substring(1,x.length)
while((x.length>0) && (x.charAt(x.length-1)==' '))
x = x.substring(0,x.length-1)
return x
}
 function validate()
    {
        formObj = document.formdevis;
        if ((formObj.entreprise.value == "") ||
			(formObj.ville.value  == "") ||
			(formObj.nomcontact.value  == "") ||
            (formObj.devismail.value  == ""))
        {
            alert("Vous n'avez pas renseigné tous les champs obligatoires.");
            return false;
        }
		if ((formObj.teldirec.value  == "") &&
            (formObj.telmobil.value  == ""))
		{
            alert("Vous n'avez saisi aucun numéro de téléphone");
            return false;
        }
		formObj.entreprise.value=kspace(formObj.entreprise.value);
		if(formObj.entreprise.value.length == 0)
		{
			alert('Le nom de l\'entreprise est incorrect');
			return false;
		}
		formObj.ville.value=kspace(formObj.ville.value);
		if(formObj.ville.value.length == 0)
		{
			alert('La ville est incorrecte');
			return false;
		}
		formObj.nomcontact.value=kspace(formObj.nomcontact.value);
		if(formObj.nomcontact.value.length == 0)
		{
			alert('Le nom est incorrect');
			return false;
		}
		if (formObj.teldirec.value != "")
		{
		formObj.teldirec.value=kspace(formObj.teldirec.value);
		if(formObj.teldirec.value.length == 0)
		{
			alert('Le téléphone saisi est incorrect');
			return false;
		}
		}
		if (formObj.telmobil.value != "")
		{
		formObj.telmobil.value=kspace(formObj.telmobil.value);
		if(formObj.telmobil.value.length == 0)
		{
			alert('Le téléphone saisi est incorrect');
			return false;
		}
		}
            return true;
    }
function bloque(formdevis,champ) {
	var controle = eval('document.' + formdevis + '.' + champ);
	controle.focus();
	controle.select();
	}
var mess = "Vous n'avez pas renseigné tous les champs obligatoires. :\n";
var mess_init = "Vous n'avez pas renseigné tous les champs obligatoires. :\n";
var necessaire = 0;

function vide(formdevis,champ,alerte) {
	var controle = eval('document.' + formdevis + '.' + champ);
	if ( controle.type == 'text' ) {
		if ( controle.value.length < 1 ) {
			mess += alerte;
			mess += "\n";
			necessaire = 1;
			}
		}
	if ( controle.type == 'password' ) {
		if ( controle.value.length < 1 ) {
			mess += alerte;
			mess += "\n";
			necessaire = 1;
			}
		}
	if ( controle.type == 'textarea' ) {
		if ( controle.value.length < 1 ) {
			mess += alerte;
			mess += "\n";
			necessaire = 1;
			}
		}
	if ( controle.type == 'select-one' ) {
		if ( controle.options[0].selected ) {
			mess += alerte;
			mess += "\n";
			necessaire = 1;
			}
		}
	if ( controle.type == 'checkbox' ) {
		if (!controle.status) {
			mess += alerte;
			mess += "\n";
			necessaire = 1;
			}
		}
	}
	
function vide_radio(formdevis,champ,alerte) {
	var controle = eval('document.' + formdevis + '.' + champ);
	var non = "hs";
	for ( i = 0; i < controle.length; i++ ) {
		if (controle[i].status) {
			non = "ok";
			}
		}
	if ( non != "ok" ) {
		mess += alerte;
		mess += "\n";
		necessaire = 1;
		}
	}
	
function resultat(formdevis) {
	if ( necessaire == 1 ) {
		alert(mess);
		}
	if ( necessaire == 0 ) {
		var formu = eval('document.' + formdevis);
		formu.submit();
		}
	mess = mess_init;
	necessaire = 0;
	}

var probleme = 0;

function tvalid(formdevis,champ,format,mini,maxi) {
	probleme = 0;
	if ( format == "A" ) { RE = /^([A-Za-z]+[ ]*[-]*[A-Za-z]*)+$/;}
	if ( format == "AN" ) { RE = /^[A-Za-zàâäéèêëîïôùûç\s,'0-9\-]+$/;}
	if ( format == "N" ) { RE = /^\d+$/;}
	if ( format == "CP" ) { RE = /^\d{5}$/;}
	if ( format == "D" ) { RE = /^\d{2}([\/]|[\-])+\d{2}([\/]|[\-])+\d{2}(\d{2})*$/;}
	if ( format == "EMAIL" ) { RE = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z][A-Za-z][A-Za-z]?$/;}
	var controle = eval('document.' + formdevis + '.' + champ);
	if (controle.value.length > 0) {
		if (!RE.test(controle.value)) {
			alert('Votre saisie est incorrecte.');
			probleme = 1;
			}
		if ( mini != 0 ) {
			if ( controle.value.length < mini ) {
				alert('Vous devez saisir au moins ' + mini + ' caracteres.');
				probleme = 1;
				}
			}
		if ( maxi != 0 ) {
			if ( controle.value.length > maxi ) {
				alert('Vous ne devez pas saisir plus de ' + maxi + ' caracteres.');
				probleme = 1;
				}
			}
		if ( probleme == 1 ) {
			bloque(formdevis,champ);
			}
		}
	}

function check_num(formdevis,champ,plancher,plafond) {
	var controle = eval('document.' + formdevis + '.' + champ);
	if ( controle.value < plancher ) {
		alert('Votre saisie ne doit pas etre inferieure a ' + plancher + '.');
		bloque(formdevis,champ);
		}
	if ( controle.value > plafond ) {
		alert('Votre saisie ne doit pas etre superieure a ' + plafond + '.');
		bloque(formdevis,champ);
		}
	}

function check_pw(formdevis,champ1,champ2) {
	var prems = eval('document.' + formdevis + '.' + champ1);
	var deuze = eval('document.' + formdevis + '.' + champ2);
	if (!prems.value) {
		alert('Vous n\'avez pas saisi votre mot de passe');
		bloque(formdevis,champ1);
		}
	else {
		if ( prems.value != deuze.value ) {
			alert('La confirmation de votre mot de passe n\'est pas exacte.');
			deuze.value = "";
			prems.value = "";
			bloque(formdevis,champ1);
			}
		}
	}