function ControleAllReservation(){
    var Controle = true;
    //Ajout d'une réservation
    if(validsaisieOblig(document.Reservation.formelement1.id,document.Reservation.formelement1.value)==false)	{ Controle = false; }
    if(validsaisieOblig(document.Reservation.formelement2.id,document.Reservation.formelement2.value)==false)	{ Controle = false; }
    if(validsaisieOblig(document.Reservation.formelement3.id,document.Reservation.formelement3.value)==false)	{ Controle = false; }
	if(verifCP(document.Reservation.formelement4.id,document.Reservation.formelement4.value)==false)			{ Controle = false; }
    if(validsaisieOblig(document.Reservation.formelement5.id,document.Reservation.formelement5.value)==false)	{ Controle = false; }	
	if(VerifEmail(document.Reservation.formelement8.id,document.Reservation.formelement8)==false)				{ Controle = false; }
	if (veriftel()==false) 																						{ Controle = false; }
    if(Controle == true){
        document.Reservation.submit();
		
    }else{
		alert('Des champs n\'ont pas été saisis');
		}
};

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function valid1MDP(id,mdp){
    if(trim(mdp)==''){
        document.getElementById(id).style.backgroundColor='#F93838';
    }else{
        document.getElementById(id).style.backgroundColor='';
    }
};

function valid2MDP(id1,mdp1,id2,mdp2){
    if(trim(mdp1)!='' && trim(mdp2)){
        if(mdp1==mdp2){
            document.getElementById(id1).style.backgroundColor='';
            document.getElementById(id2).style.backgroundColor='';
        }else{
            document.getElementById(id1).style.backgroundColor='#F93838';
            document.getElementById(id2).style.backgroundColor='#F93838';
        }
    }else{
        document.getElementById(id1).style.backgroundColor='#F93838';
        document.getElementById(id2).style.backgroundColor='#F93838';
    }
};

function verifNum(chaine){
    if(isNaN(chaine)){
        alert('false');
    }
    else{
        alert('true');
    }
};

function validsaisieOblig(id,valeur){
    if(trim(valeur)!='' && isNaN(valeur)){
        document.getElementById(id).style.backgroundColor='';
        return true
    }else{
        document.getElementById(id).style.backgroundColor='#F93838';
        return false
    }
};

function validsaisie(id,valeur){
    if(isNaN(valeur) || valeur==''){
        document.getElementById(id).style.backgroundColor='';
    }else{
        document.getElementById(id).style.backgroundColor='#F93838';
    }
};

function veriftel(){


	if(document.getElementById('idtelportpers').value.length==0 && document.getElementById('idteldompers').value.length==0){
		document.getElementById('idtelportpers').style.backgroundColor='#F93838';
		document.getElementById('idteldompers').style.backgroundColor='#F93838';
		return false;
			
	}else{
		if(document.getElementById('idtelportpers').value.length!=0 && document.getElementById('idteldompers').value.length==0){
			if(isNaN(document.getElementById('idtelportpers').value)==false && document.getElementById('idtelportpers').value.length===10){
				document.getElementById('idtelportpers').style.backgroundColor='';
				document.getElementById('idteldompers').style.backgroundColor='';
				return true;
			}else{
				document.getElementById('idtelportpers').style.backgroundColor='#F93838';
				document.getElementById('idteldompers').style.backgroundColor='#F93838';
				return false
				}			
		}else{
	
				if(document.getElementById('idteldompers').value.length!=0 && document.getElementById('idtelportpers').value.length==0){
					if(isNaN(document.getElementById('idteldompers').value)==false && document.getElementById('idteldompers').value.length===10){
						document.getElementById('idteldompers').style.backgroundColor='';
						document.getElementById('idtelportpers').style.backgroundColor='';
						return true;
					}else{
						document.getElementById('idteldompers').style.backgroundColor='#F93838';
						document.getElementById('idtelportpers').style.backgroundColor='#F93838';
						return false
						}			
				}
			}	
		}
};


function verifCP(id,valeur){
	if(document.getElementById('idcppers').value.length==''){
		document.getElementById('idcppers').style.backgroundColor='#F93838';
		}
    if(valeur.length!=0){
        if(isNaN(valeur)==false && valeur.length==5){
            document.getElementById(id).style.backgroundColor='';
            return true;
        }else{
            document.getElementById(id).style.backgroundColor='#F93838';
            return false;
        }
    }else{
        document.getElementById(id).style.backgroundColor='';
        return true;
    }
	
	
};

function verifadresse(id,valeur){
    if(valeur.value!=""){
           document.getElementById(id).style.backgroundColor='';
           return true;
	}else{
           document.getElementById(id).style.backgroundColor='#F93838';
           return false;
		}
};

function VerifEmail(id,name){
		var verif='';
		var regMail=new RegExp("^[0-9a-z._-]+@{1}[0-9a-z. -]{2,}[.]{1}[a-z]{2,5}$", "i");
		var result = regMail.test(name.value);
		if (result==false){
				document.getElementById(id).style.backgroundColor='#F93838';
				return false;
	        }else{
				document.getElementById(id).style.backgroundColor='';	
				return true;
		}
	
};


function IsNumberString(NumStr)
{var regEx=/^[0-9]+$/;
var ret=false;
if (regEx.test(NumStr)) ret=true;
return ret;
};

function IsAlphaNumString(id,NumStr)
{var regEx=/^[A-Za-z0-9]+$/;
if (regEx.test(NumStr)){
    document.getElementById(id).style.backgroundColor='';
}else{
    document.getElementById(id).style.backgroundColor='#F93838';
}
};

function IsAlphaString(id,NumStr){
    var regEx=/^[A-Za-z]+$/;
    if (regEx.test(NumStr)){
        document.getElementById(id).style.backgroundColor='';
    }else{
        document.getElementById(id).style.backgroundColor='#F93838';
    }
};

function verif_date(id,input){
    var regex = new RegExp("[/-]");
    var date = input.split(regex);
    var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
    var result = true;

    if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
    nbJours['2'] = 29;

    if( isNaN(date['2']) )
    result=false;

    if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
    result=false;

    if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
    result=false;

    if(result==true){
        document.getElementById(id).style.backgroundColor='';
        return result;
    }else{
        document.getElementById(id).style.backgroundColor='#F93838';
        return result;
    }
};

function validDate(id,ddate){
    if(isNaN(ddate)==false && trim(ddate).length==4){
        document.getElementById(id).style.backgroundColor='';
        return true;
    }else{
        document.getElementById(id).style.backgroundColor='#F93838';
        return false;
    }
};
