// <![CDATA[

function Display (id)
{ 

if(document.getElementById(id).style.display == 'block')
	document.getElementById(id).style.display = 'none';
else
	document.getElementById(id).style.display = 'block'

}

function Hide(id)
{
if(document.getElementById(id))
{
document.getElementById(id).style.display = 'none';
}}

function Display_Periode (TheClass)
{ 

var list_of_div = document.getElementById('list_of_periode').getElementsByTagName('div');
var nb_div = list_of_div.length;
for (i=0; i<nb_div; i++)
{

	if(list_of_div[i].className == TheClass)
	{
		list_of_div[i].style.display = 'block';
		var list_of_select = list_of_div[i].getElementsByTagName('option');
		list_of_select[0].selected = "selected";
		
	}
	else
	{
		list_of_div[i].style.display = 'none';
	}
}

}


function verif_RC(value_periode)
{

	if(value_periode.match(/HIDE/i))
	{
		document.getElementById('garantie_rc').disabled = true;
		document.getElementById('garantie_rc').checked = false;
		document.getElementById('message_rc').style.display = 'inline';
	}
	else
	{
		document.getElementById('garantie_rc').disabled = false;
		document.getElementById('message_rc').style.display = 'none';
	}
}


function verif_date_valide (d, m, y)
{
   if (d < 1 || m < 1 || y < 1 || d > 31 || m > 12) {
      return false;
   }
   var lastDay = new Date (y, m, 0);
   if (d > lastDay.getDate()) {
      return false;
   }
   return true;
}

function disable_Num_Identifiant_Input ()
{
  if (document.ACCUEIL.prorata.value == 'non')
  {
    var label = '';
    
    
    label = '<input class="field" type="text" id="num_identifiant" name="num_identifiant" maxlength="9" disabled="disabled" style="width: 80px; background-color: #d1cfd0;" tabindex="2" />';
    
    document.getElementById('inner_num_identifiant').innerHTML = label;
    
    return false;
  }
  else if (document.ACCUEIL.prorata.value == 'oui')
  {
    var label = '';
    
    
    label = '<input class="field" type="text" id="num_identifiant" name="num_identifiant" maxlength="9" style="width: 80px;" tabindex="2" />';
    
    document.getElementById('inner_num_identifiant').innerHTML = label;
    
    return false;
  }

  return true;
}



function valide_accueil ()
{

	if (document.getElementById('prorata') && document.ACCUEIL.prorata.value.length == 0)
	{
		alert ("Vous avez oublié de définir si vous avez déjà une garantie T'as tout.");
		return false;
	}
	
	if (document.getElementById('prorata') && document.ACCUEIL.prorata.value == 'oui' && document.ACCUEIL.num_identifiant.value.length == 0)
	{
		alert ("Vous avez déjà une garantie T'as tout, vous devez indiquez votre numéro identifiant.");
		return false;
	}
	if (document.getElementById('prorata') && document.ACCUEIL.prorata.value == 'oui')
	{
	   var mep_ident=new String(document.ACCUEIL.num_identifiant.value);
	   var ok=0;
	   if (document.ACCUEIL.num_identifiant.value.length==9)
	   {
	     if (mep_ident.match( /^11/ )) ok=1;
	     if (mep_ident.match( /^13/ )) ok=1;
	     if (mep_ident.match( /^14/ )) ok=1;
	     if (mep_ident.match( /^15/ )) ok=1;
	     if (mep_ident.match( /^30/ )) ok=1;
	     if (mep_ident.match( /^34/ )) ok=1;
	     if (mep_ident.match( /^35/ )) ok=1;
	     if (mep_ident.match( /^66/ )) ok=1;
	     if (mep_ident.match( /^83/ )) ok=1;
	     if (mep_ident.match( /^84/ )) ok=1;
	     if (mep_ident.match( /^85/ )) ok=1;
	   }
	   if (document.ACCUEIL.num_identifiant.value.length==8)
	   {
	     if (mep_ident.match( /^6/ )) ok=1;
	   }
	   if (ok==0)
	   {
	     alert ("Ceci n'est pas un numéro identifiant valide, vous trouverez votre numéro identifiant sur toutes les correspondances MEP.");
	     return false;
	   }
	}

	if (document.getElementById('prorata') && document.ACCUEIL.prorata.value == 'oui' && document.ACCUEIL.MEP_NIVEAU.value == '5')
	{
		alert ("Vous avez déjà une garantie T'as tout, vous ne pouvez donc pas choisir ce niveau de garantie.");
		return false;
	}
  
  
   if (document.getElementById('garantie_rc').checked == false && document.getElementById('garantie_sc').checked == false && document.getElementById('garantie_gs').checked == false)
   {
      alert ("Vous n'avez choisi aucunne garantie");
      return false;
   }
	
	if (document.getElementById('garantie_gs').checked == true && !document.getElementById('GARANTIE_SANTE'))
	{
	   alert ("Vous n'avez choisi aucunne garantie santé");
      return false;
	}
 
  
   // if (document.ACCUEIL.MEP_NIVEAU.value.length == 0)
   // {
      // alert ("Vous avez oublié de choisir le niveau de garantie.");
      // return false;
   // }

	if(document.ACCUEIL.fractionnement.value == 'Fractionné')
	{
		if((document.getElementById('garantie_gs').checked == true && document.getElementById('GARANTIE_SANTE').value.indexOf('#3 mois#', 0) != -1) || (document.getElementById('garantie_gs').checked == false && (document.getElementById('garantie_rc').checked == true || document.getElementById('garantie_sc').checked == true)))
		{
			alert ("Vous ne pouvez pas choisir cette garantie et un paiement fractionné.\n\nMerci de corriger vos choix.");
			return false;
		}
	}
   
   var civil_ok = false;
   for (var i = 0; i < document.ACCUEIL.civil.length; i++)
   {
      if (document.ACCUEIL.civil[i].checked) {
         civil_ok = true;
	 break;
      }
   }
   if (civil_ok == false)
   {
     alert ("Vous devez choisir la civilité (M., Mme, Mlle)");
     return false;
   }

   if (document.ACCUEIL.last_name.value.length == 0)
   {
      alert ("Vous avez oublié de saisir le nom.");
      return false;
   }

   if (document.ACCUEIL.first_name.value.length == 0)
   {
      alert ("Vous avez oublié de saisir le prénom.");
      return false;
   }
   
   if (!document.ACCUEIL.CODE_POSTAL.value.match(/^(\d{2}|2A|2B)\d{3}$/i))
   {
     alert ("Vous avez oublié de saisir votre code postal.");
     return false;
   }
   
   if (document.ACCUEIL.VILLE.value.length == 0)
   {
     alert ("Vous avez oublié de saisir la ville.");
     return false;
   }
	
   if (document.ACCUEIL.VILLE.value.match(/[0-9]/i))
   {
     alert ("Merci de verifier votre ville");
     return false;
   }
	
   
   if (!document.ACCUEIL.email.value.match(/^[a-z0-9&\'\.\-_\+]*@[a-z0-9]+([\.\-][a-z0-9]+)*\.[a-z]{2,}$/i))
   {
      alert ("Vous devez saisir une adresse email valide (prenom.nom@monemail.com).");
      return false;
   }

   //document.ACCUEIL.phone.value = document.ACCUEIL.phone.value.replace (/[\s\.]/g, '');   // on vire les espaces et les points

if (G_ADVISOR_NAME == 'internet')
{

	if (document.ACCUEIL.phone.length == 0)
	{
		alert ("Vous devez indiquer votre numéro de téléphone");
		return false;
	}
	
}

   if (!document.ACCUEIL.birthday.value.match(/^\d{2}\/\d{2}\/\d{4}$/))
   {
      alert ("La date de naissance est invalide.");
      return false;
   }
   var strDate = document.ACCUEIL.birthday.value;
   var bDay = parseInt(strDate.substr(0, 2), 10);
   var bMonth = parseInt(strDate.substr(3, 2), 10);
   var bYear = parseInt(strDate.substr(6, 4), 10);

   if (verif_date_valide (bDay, bMonth, bYear) == false) {
      alert ("La date de naissance n'est pas possible :\nVérifiez la fin du mois...");
      return false;
   }
   
   return true;
}
//]]>