if (language_js == "") var language_js = "";

function WindowVisu(url, titre, winStats){
    if (arguments.length < 3) winStats = "";
    if (arguments.length < 2) titre = "";
    if (navigator.appName.indexOf("Microsoft") < 0) {
    	winStats = winStats.replace(/width/i, 'innerWidth');
    	winStats = winStats.replace(/height/i, 'innerHeight');
    	winStats = winStats.replace(/left/i, 'screenX');
    	winStats = winStats.replace(/top/i, 'screenY');
    }
    eval('if (top.win' + titre + ' && !(top.win' + titre + '.closed)) top.win' + titre + '.close();');
	eval('win' + titre + ' = window.open(url, titre, winStats);');
	eval('if (win' + titre + ') win' + titre + '.focus();');
}


// ---------------------------------------------------------------
// Suppression des escapes au début ou à la fin d'une chaîne
function Trim(chaine) {
    var res = chaine;
    res = res.replace(/^\s+/, "");
    res = res.replace(/\s+$/, "");
    return res;
}
function LTrim(chaine) {
    var res = chaine;
    res = res.replace(/^\s+/, "");
    return res;
}
function RTrim(chaine) {
    var res = chaine;
    res = res.replace(/\s+$/, "");
    return res;
}


// ---------------------------------------------------------------
// Verification d'un champ chaine
function TesteChaine(champ, nom_champ, longueur, pas_vide) {
    if (nom_champ != "") {
        nom_champ = "'" + nom_champ + "' ";
    }

    if ((pas_vide) && (Trim(champ.value) == "")) {
        if (language_js == "uk") alert("Field " + nom_champ + "is empty.");
        else if (language_js == "de") alert("Das Feld " + nom_champ + "ist leer.");
        else alert("Le champ " + nom_champ + "est vide.");
        try {
            champ.focus();
            champ.select();
        } catch (e) {}
        return false;
    }

    if (longueur != 0) {
        if (champ.value.length > longueur) {
            if (language_js == "uk") alert("Field " + nom_champ + "must contain " + longueur + " characters to the maximum.");
            else if (language_js == "de") alert("Feld " + nom_champ + "muß " + longueur + " Charaktere enthalten höchstens.");
            else alert("Le champ " + nom_champ + "doit contenir " + longueur + " caractères au maximum.");
            try {
                champ.focus();
                champ.select();
            } catch (e) {}
            return false;
        }
    }

    return true;
}

// ---------------------------------------------------------------
function TesteNombre(champ, nom_champ, pas_vide) {
    if (nom_champ != "") {
        nom_champ = "'" + nom_champ + "' ";
    }
        
    if ((pas_vide) && (champ.value == "")) {
        if (language_js == "uk") alert("Field " + nom_champ + "is empty.");
        else if (language_js == "de") alert("Das Feld " + nom_champ + "ist leer.");
        else alert("Le champ " + nom_champ + "est vide.");
        champ.focus();
        champ.select();
        return false;
    }
    
    champ.value = champ.value.replace(/,/, '.');
        
    if (isNaN(champ.value)) {
        if (language_js == "uk") alert("Field " + nom_champ + "must contain figures.");
        else if (language_js == "de") alert("Feld " + nom_champ + "muß Zahlen enthalten.");
        else alert("Le champ " + nom_champ + "doit contenir des chiffres.");
        champ.focus();
        champ.select();
        return false;
    }
        
    return true;
}

// ---------------------------------------------------------------
// Verification d'un champ email
function TesteEMail(email, longueur, non_vide) {
    var retour = TesteEMailValeur(email.value, longueur, non_vide);
    if (retour != "") {
        alert(retour);
        email.focus();
        email.select();
        return(false);
    }
    return true;
}

// ---------------------------------------------------------------
// Verification d'un champ email
function TesteEMailValeur(email, longueur, non_vide) {
    if ((email == "") && (non_vide)) {
        if (language_js == "uk") return "The field of address email must be filled.";
        else if (language_js == "de") return "Das Feld der E-Mail Adresse muß gefüllt werden.";
        else return 'Le champ de l\'adresse email doit être rempli.';
    }

    if (email != "") {
        if (email.length <= longueur) {
			var At = email.indexOf(" ");
			if (At != -1) {
                if (language_js == "uk") return "Check address email,\nit contains spaces.";
                else if (language_js == "de") return "Prüfen Sie die E-Mail Adresse,\nsie enthält Räume.";
                else return 'Vérifiez l\'adresse email,\nelle contient des espaces.';
			}
			
			var OK = false;
			At = email.indexOf("@");
			if (At > 0 && At < (email.length - 4)) {
				var Point = email.indexOf(".", At + 1);
				if (Point > (At + 1) && Point < (email.length - 2)) {
					OK = true;
				}
			}
			if (!OK) {
                if (language_js == "uk") return "Check address email,\nit does not seem valid.";
                else if (language_js == "de") return "Prüfen Sie die E-Mail Adresse,\nsie scheint nicht gültig.";
                else return 'Vérifiez l\'adresse email,\nelle ne semble pas valide.';
			}
        } else {
            if (language_js == "uk") return 'The field of address email must contain to the maximum ' + longueur + ' characters.';
            else if (language_js == "de") return 'Das Feld der E-Mail Adresse muß ' + longueur + ' Charaktere auf ein Höchtsmaß enthalten.';
            else return 'Le champ de l\'adresse email doit contenir au maximum ' + longueur + ' caractères.';
        }
    }

    return "";
}

// ---------------------------------------------------------------

// fonction permettant l'affichage d'un nombre avec trois chiffres après la virgule
function AfficheCoeff(Nombre) {
        NombreInt = parseInt(Nombre, 10);
        // teste si on a un entier
        if (Nombre == NombreInt) {      // Entier
                Nombre = Nombre + '.000';
        }
        
        // teste si on a un seul chiffre après la virgule
        if (((Nombre - NombreInt) > 0) && ((Nombre - NombreInt) < 1)) {
                Nombre = Nombre + '000';
        }
        
        // variable contenant la troisième décimale pour un éventuel arrondi
        decimal3 = String(Nombre).replace(/((\.|,)\d\d\d\d).*$/, '$1');
        decimal3 = String(decimal3).substr(String(decimal3).length, 1);
        
        Nombre = String(Nombre).replace(/((\.|,)\d\d\d).*$/, '$1');
        
        if ((decimal3 >= 5.0) && (decimal3 <= 9.0)) {   // on arrondi à la valeur supérieure
                Nombre = Nombre * 1 + 0.001;
        }
        Nombre = String(Nombre)+'0000';
       	Nombre = Nombre.replace(/((\.|,)\d)$/, '$1'+'0');
        Nombre = String(Nombre).replace(/((\.|,)\d\d\d).*$/, '$1');
        
        return Nombre;
}

// ---------------------------------------------------------------

// fonction permettant l'affichage d'un nombre avec deux chiffres après la virgule
function AfficheFlottant(Nombre) {
        NombreInt = parseInt(Nombre, 10);

        // teste si on a un entier
        if (Nombre == NombreInt) {      // Entier
                Nombre = Nombre + '.00';
        }
        
        // teste si on a un seul chiffre après la virgule
        if (((Nombre - NombreInt) > 0) && ((Nombre - NombreInt) < 1)) {
                Nombre = Nombre + '0';
        }
        
        // variable contenant la troisième décimale pour un éventuel arrondi
        decimal3 = String(Nombre).replace(/((\.|,)\d\d\d).*$/, '$1');
        decimal3 = String(decimal3).substr(String(decimal3).length-1);

        Nombre = String(Nombre).replace(/((\.|,)\d\d).*$/, '$1');
        
        if ((decimal3 >= 5.0) && (decimal3 <= 9.0)) {   // on arrondi à la valeur supérieure
                Nombre = Nombre * 1 + 0.01;
        }
        Nombre = String(Nombre)+'000';
       	Nombre = Nombre.replace(/((\.|,)\d)$/, '$1'+'0');
        Nombre = String(Nombre).replace(/((\.|,)\d\d).*$/, '$1');
       
        return Nombre;
}

// ---------------------------------------------------------------
// Verification de la validite de la date
function CheckDate (theform, prefixe_champ, pas_vide) {
    Jour = eval("theform." + prefixe_champ + "_jour.options[theform." + prefixe_champ + "_jour.selectedIndex].value");
    Mois = eval("theform." + prefixe_champ + "_mois.options[theform." + prefixe_champ + "_mois.selectedIndex].value");
    champ_Annee = eval("theform." + prefixe_champ + "_annee");
    if (champ_Annee.type == 'text') Annee = eval("theform." + prefixe_champ + "_annee.value");
    else Annee = eval("theform." + prefixe_champ + "_annee.options[theform." + prefixe_champ + "_annee.selectedIndex].value");
	if ((Jour == "" || Jour == "0") && (Mois == "" || Mois == "0") && (Annee == "") && !pas_vide) {
		return true;
	}

	if ((Jour == "") || Jour == "0" || (Mois == "") || Mois == "0" || (Annee == "")) {
        if (language_js == "uk") alert("The date is incomplete.");
        else if (language_js == "de") alert("Das Datum ist unvollständig.");
        else alert("La date est incomplète.");
        eval("theform." + prefixe_champ + "_jour.focus();");
		return false;
	}
	ChkDate = new Date(Annee, Mois-1, Jour);
	if ((ChkDate.getDate() != Jour) ||
	    (ChkDate.getMonth() != Mois-1)) {
        if (language_js == "uk") alert("The date is not valid.");
        else if (language_js == "de") alert("Das Datum ist nicht gültig.");
        else alert("La date n'est pas valide.");
        eval("theform." + prefixe_champ + "_jour.focus();");
		return false;
	}
	return true;
}

