//////////////////////// FORMUALIRE  //////////////////////////////

var invalidaddress=new Array()

var testresults

function checkemail(iid){
var invalidcheck=0;
var str=document.getElementById(iid).value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
if (invalidcheck!=1)
{
	document.getElementById(iid).style.backgroundColor ='#efefef';
	testresults=true
}
else{
testresults=false
}
}
else{
document.getElementById(iid).style.backgroundColor ='#FFAEAE';
testresults=false
}
return (testresults)
}


function checkCivilite(){
	if (document.form1.c[0].checked || document.form1.c[1].checked || document.form1.c[2].checked)
	{
		document.getElementById('c1').style.color = '#000000'
		document.getElementById('c2').style.color = '#000000'
		document.getElementById('c3').style.color = '#000000'
		return true
	}
	else
	{
		document.getElementById('c1').style.color = '#FF0000'
		document.getElementById('c2').style.color = '#FF0000'
		document.getElementById('c3').style.color = '#FF0000'
		return false
	}
}

function checkTxtEmpty(idElement){
	if (document.getElementById(idElement).value != "")
	{
		document.getElementById(idElement).style.backgroundColor = '#efefef';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#FFAEAE';
		return false
	}
}

function checkCodePostal(){
	nbr = document.getElementById('cp').value
	if (nbr.length == 5 && !isNaN(nbr))
	{
		document.getElementById('cp').style.backgroundColor = '#efefef';
		return true
	}
	else
	{
		document.getElementById('cp').style.backgroundColor = '#FFAEAE';
		return false
	}
}

function checkTel(idElement){
	nbr = document.getElementById(idElement).value
	if ((nbr.length == 10 || nbr.length == 9) && !isNaN(nbr))
	{
		document.getElementById(idElement).style.backgroundColor = '#efefef';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#FFAEAE';
		return false
	}
} 


function CheckDate() {
      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
	  var j=document.getElementById('jour').value
	  var m=document.getElementById('mois').value
	  var a=document.getElementById('annee').value
      var amin=1900; // année mini
      var amax=2020; // année maxi
      //var separateur="/"; // separateur entre jour/mois/annee
      /*var j=(j.substring(0,2));
      var m=(m.substring(0,2));
      var a=(a.substring(0,4));*/
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31))) { 
		 ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12))) {		
		 ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax))) {		
		 ok=0;
      }
      /*if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) ) { 
		 ok=0;
      }*/
	  
      if (ok==1) {
		 var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getFullYear();
         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            document.getElementById('jour').style.backgroundColor = '#FFAEAE';
			document.getElementById('mois').style.backgroundColor = '#FFAEAE';
			document.getElementById('annee').style.backgroundColor = '#FFAEAE';
		 
            ok=0;
         }
		  document.getElementById('jour').style.backgroundColor = '#efefef';
		  document.getElementById('mois').style.backgroundColor = '#efefef';
		  document.getElementById('annee').style.backgroundColor = '#efefef';
		  ok = true;
      }
	  else
	  {
	  	  document.getElementById('jour').style.backgroundColor = '#FFAEAE';
		  document.getElementById('mois').style.backgroundColor = '#FFAEAE';
		  document.getElementById('annee').style.backgroundColor = '#FFAEAE';
		  ok = false;
	  }
	 
      return ok;
	}


function checkall1(){
nom = checkTxtEmpty('nom')
prenom = checkTxtEmpty('prenom')
to = checkemail('to')
tel = checkTel('tel')
cv = checkTxtEmpty('cv')


if (!(nom && prenom && to && tel && cv))
{
	return false ;
}
else	
	return true;
}

function checkall2(){
nom = checkTxtEmpty('nom')
prenom = checkTxtEmpty('prenom')
tel = checkTel('tel')
societe = checkTxtEmpty('societe')
email = checkemail('to');
message = checkTxtEmpty('message');
if (!(nom && prenom && tel && societe && email && message))
{
	return false ;
}
else	
	return true;
}
