//Vérification de la taille du champ id et s'il est vide ou non
//Affichage ds le champ id_err du message correspondant
function verifVideEtTaille(id, id_err, msgVide, msgTailleMin, msgTailleMax, min, max)
{
    var lReturn = true;
	
	if(document.getElementById(id) != null && document.getElementById(id_err) != null)
	{
	    var SIZE_MIN = min;
	    var SIZE_MAX = max;
	    
	    champ_id = document.getElementById(id);
	    champ_id_err = document.getElementById(id_err);
	    
	    champ_id_err.innerHTML = "";
	    	
	    if (champ_id.value == "")
	    {
		    champ_id_err.innerHTML = msgVide;
		    lReturn=false;
	    }
	    else if (champ_id.value.length > SIZE_MAX)
	    {
		    champ_id_err.innerHTML = msgTailleMax;
		    lReturn=false;
	    }
	    else if (champ_id.value.length < SIZE_MIN)
	    {
		    champ_id_err.innerHTML = msgTailleMin;
		    lReturn=false;
	    }
	}
	
	return lReturn;
}


// Verifie si le format du champ est correct
function verifExpr(id, id_err, msg, expr)
{
    var lReturn = true;
    var Expr1 = new RegExp(expr);

	if(document.getElementById(id) != null && document.getElementById(id_err) != null)
	{
		    
	    champ_id = document.getElementById(id);
	    champ_id_err = document.getElementById(id_err);

	    champ_id_err.innerHTML = "";
	    	
	    if (champ_id.value.match(Expr1) == null && champ_id != "")
	    {
		    champ_id_err.innerHTML = msg;
		    lReturn=false;
	    }
	   
	
	return lReturn;
	}
}



//Vérifie si les champs id1 et id2 sont égaux
//Affichage ds le champ id_err du message correspondant
function verifConfirm(id1, id2, id_err, msg)
{
    var lReturn = true;

    if(document.getElementById(id1) != null && document.getElementById(id2) != null && document.getElementById(id_err) != null)
	{
	    champ_id1 = document.getElementById(id1);
	    champ_id2 = document.getElementById(id2);
	    champ_id_err = document.getElementById(id_err);
	    
	    champ_id_err.innerHTML = "";
	    
        if (champ_id1.value != champ_id2.value)
	    {
		    champ_id_err.innerHTML = msg;
		    lReturn=false;
	    }
	}
	
	return lReturn;
}






// Verification de la date denaissance
function verifDate(jour, mois, annee, id_err, msg)
{
    var lReturn = true;
    
	
	if (document.getElementById(jour) != null && document.getElementById(mois) != null && document.getElementById(annee) != null && document.getElementById(id_err) != null)
	{
	    j = document.getElementById(jour).options[document.getElementById(jour).selectedIndex].value;
	    m = document.getElementById(mois).options[document.getElementById(mois).selectedIndex].value;
	    a = document.getElementById(annee).options[document.getElementById(annee).selectedIndex].value;
	    champ_id_err = document.getElementById(id_err);
	    
	    champ_id_err.innerHTML = "";
	
	    var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	 
	    if ( (a%4 == 0 && a%100 != 0) || a%400 == 0 ) //annee bissextile
	    {
		    monthLength[1] = 29;
	    }
    	
	    if ( !j || !m || !a || j > monthLength[m-1] )
	    {
		    //On reinitialise le nb de jours de fevrier a 28
		    monthLength[1] = 28;
		    date_err.innerHTML = msg;
		    lReturn=false;
	    }
	    else
	    {
	        //On reinitialise le nb de jours de fevrier a 28
		    monthLength[1] = 28;
	    }
	}
	
	return lReturn;
}




// Vérifie qu'une checkbox est cochée
function verifCheck(id, id_err, msg)
{
    var lReturn = true;
    
    if (document.getElementById(id) != null && document.getElementById(id_err) != null)
    {
        check = document.getElementById(id);
        check_err = document.getElementById(id_err);
    	
	    check_err.innerHTML = "";

        if (!check.checked)
	    {
		    check_err.innerHTML = msg;
		    lReturn=false;
	    }
	}
	
	return lReturn;
}
	
	

//demande le submit du formulaire (id passé en param)
function demandeSubmit(iFormId, bDemandeAutorisation, sAutorisationStr){
    var bPost = true;
    if(bDemandeAutorisation){
        bPost=confirm(sAutorisationStr)        
    }
    if(bPost){
	    document.getElementById("frmMultimarquage").submit();
	}
}



//met la sélection à l endroit spécifiée pour un élément html passé en param
function setSelRange(inputEl, selStart, selEnd) { 
	if(inputEl!=null){
		if (inputEl.setSelectionRange) { 
			inputEl.focus(); 
			inputEl.setSelectionRange(selStart, selEnd); 
		} else if (inputEl.createTextRange) { 
			var range = inputEl.createTextRange(); 
			range.collapse(true); 
			range.moveEnd('character', selEnd); 
			range.moveStart('character', selStart); 
			range.select(); 
		} 
	}
}



	
/*
function verifMineur(jour, mois, annee, id)
{
    var j = document.getElementById("jour").options[document.getElementById("jour").selectedIndex].value;
	var m = document.getElementById("mois").options[document.getElementById("mois").selectedIndex].value;
	var a = document.getElementById("annee").options[document.getElementById("annee").selectedIndex].value;
	
	var now = new Date();
	
	if ( now.getFullYear()-a < 17 || (now.getFullYear()-a == 17 && (now.getMonth()+1)-m < 0) || (now.getFullYear()-a == 17 && (now.getMonth()+1)-m == 0 && now.getDate()-j < 0) )
	{
	    //alert("Vous êtes mineur : veuillez spécifier l'adresse email de votre responsable légal.");
	    document.getElementById(id).style.display='inline';
	}
	else
	{
	    document.getElementById(id).style.display='none';
	}
	
}
*/