// calcul pour les frais des fai
function CheckDate(d) {
      var amin=1983; // ann&eacute;e mini
      var amax=2500; // ann&eacute;e maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
         alert("Le jour n'est pas correct."); ok=0; return false;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
         alert("Le mois n'est pas correct."); ok=0; return false;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
         alert("L'ann&eacute;e n'est pas correcte."); ok=0; return false;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
         alert("Les s&eacute;parateurs doivent &ecirc;tre des "+separateur); ok=0; return false;
      }
      if (ok==1) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getYear();
         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            //alert("La date "+d+" n'existe pas !");
            ok=0;
         }
		 ok=d2;
      }
      return ok;
   }
function nbr_annee(dt) {
	var d=CheckDate(dt)
	var m=new Date()
	var annee=""; var annee_a=0;var annee_m=0;
	if (d!=0) {
		if (d.getTime()>m.getTime()) {
			annee="La date de souscription est sup&eacute;rieure &agrave; la date du jour !";
			document.resiliationLigne.dated.focus();
		}
		annee_a = m.getFullYear()-d.getFullYear();
		m.setYear(d.getYear());
		if ((d.getTime()>m.getTime())&&(d.getMonth()-m.getMonth()!=0)) {annee_a--;}
		if (d.getMonth() >= m.getMonth()) {
			annee_m = 12 - (d.getMonth()-m.getMonth())
		} else {
			annee_m = (m.getMonth()-d.getMonth())
		}
		if (annee_m==12) {annee_m=0;}
		if (annee_a==1) { annee=annee_a+" an"; var temps=1;}
		if (annee_a>1) { annee=annee_a+" ans";}
		if ((annee_a>0)&&(annee_m>0)) {annee+=" et ";}
		if (annee_m>0) {annee+=annee_m+" mois";}
		if (annee=="") { annee="moins de 1 mois";}
		
		for (var n=0;n<document.resiliationLigne.provideridnow.length; n++ )
		{    
			var fraisfree = 0;
			if (annee_a == -1){
				fraisfree = 96 - (3 * annee_m);
			}
			else 
			{
				fraisfree = 96 - (3 *(annee_a*12 + annee_m ));
			}

			if ( document.resiliationLigne.provideridnow[n].checked == true )
			{    
				var fai = document.resiliationLigne.provideridnow[n].value;
				switch(fai) {
			   	case '1':
				case '28':
					if (annee_a==-1){
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont le montant de votre facture multipli&eacute; par "+annee_m;
						document.getElementById('frais').value = "Montant de votre facture *"+annee_m;
					}else{
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont gratuits";
						document.getElementById('frais').value = "Gratuit";
					}
					break;
			  	case '15':
					if (annee_a==-1){
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont de 40 &euro; additionn&eacute; au montant de votre facture multipli&eacute; par "+annee_m;
						document.getElementById('frais').value = "40 € plus le montant de votre facture *"+annee_m;
					}else{
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont de 40 &euro;";
						document.getElementById('frais').value = "40 €";
					}
					break;
			   	case '16':
					if (fraisfree > 0){
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont de "+fraisfree+" &euro;";
						document.getElementById('frais').value = fraisfree+" €";
					}else{
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont gratuits";
						document.getElementById('frais').value = "Gratuit";
					}
					break;
			   	
				case '24':
				case '26':	
					document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont de 45 &euro;";
					document.getElementById('frais').value = "45 €";
					break;
				case '27':
						document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation sont de 49 euros";
						document.getElementById('frais').value = "49 €";
					break;
			   	default:
					document.getElementById('fraisresiliation').innerHTML = "Les frais de r&eacute;siliation ne sont communiqu&eacute;s";
					document.getElementById('frais').value = "NC";
					break;
				}
			}
		}
				
	} else {
		document.formage.dated.focus();
	}

	return annee;
}



// vérification formulaire
function checkForm(resiliationLigne) {	
	
	var i=0;
	for (var n=0; n<document.resiliationLigne.civilite.length; n++ )
	{
		if (document.resiliationLigne.civilite[n].checked == true )
		{
			i++;
		} 
	}
	if (i==0){
		alert('Indiquez votre civilité, SVP.');
    	return(false);
	}
	
	if (document.resiliationLigne.mail.value == "") {
	alert('Indiquez votre adresse email, SVP.');
	document.resiliationLigne.mail.focus();
    return(false);
	}
	if (document.resiliationLigne.mail.value.search(/ /) != '-1') {
	alert('Une adresse e-mail ne peut contenir un espace !');
	document.resiliationLigne.mail.focus();
    return(false);
	}
	var s;
	s = document.resiliationLigne.mail.value.split(/@/);
	if((s.length != 2) || s[0] == '' || s[1] == '') {
    alert('Une adresse e-mail doit avoir le format "Utilisateur@Domain",\n' +'par ex.: "laurent.dupond@net.fr"');
	document.resiliationLigne.mail.focus();
    return(false);
	}
	
	if (document.resiliationLigne.nom.value == "") {
	alert('Indiquez votre nom, SVP.');
	document.resiliationLigne.nom.focus();
    return(false);
	}
	
	if (document.resiliationLigne.prenom.value == "") {
	alert('Indiquez votre prenom, SVP.');
	document.resiliationLigne.prenom.focus();
    return(false);
	}
	
	if (document.resiliationLigne.adresse.value == "") {
	alert('Indiquez votre adresse, SVP.');
	document.resiliationLigne.adresse.focus();
    return(false);
	}
	
	if (document.resiliationLigne.ville.value == "") {
	alert('Indiquez votre ville, SVP.');
	document.resiliationLigne.ville.focus();
    return(false);
	}
	
	if (document.resiliationLigne.cp.value == "") {
	alert('Indiquez votre code postal, SVP.');
	document.resiliationLigne.cp.focus();
    return(false);
	}
	
	if (document.resiliationLigne.tel.value == "") {
	alert('Indiquez votre telephone, SVP.');
	document.resiliationLigne.tel.focus();
    return(false);
	}
	var s;
	for(var i = 0; i < document.resiliationLigne.tel.value.length; i++) {
	s = document.resiliationLigne.tel.value.charAt(i);
		if( !((s >= 0) && (s <= 9))
		&& (s != ' ') && (s != '.') && (s != '-') && (s != '+')
		&& (s != '/') && (s != '(') && (s != ')')) {
		alert('Le numero de telephone ne peut comporter que des chiffres, '+ 'espaces, point, parentheses, "/", "-" et "+".');
		document.resiliationLigne.tel.focus();
		  return(false);
		}
	}
	
	if (document.resiliationLigne.dossier.value == "") {
	alert('Indiquez votre numero client, SVP.');
	document.resiliationLigne.dossier.focus();
    return(false);
	}
	
	if (document.resiliationLigne.motif.value == 0) {
	alert('Indiquez votre motif de résiliation, SVP.');
	document.resiliationLigne.motif.focus();
    return(false);
	}
	
	if (document.resiliationLigne.dated.value == "") {
	alert('Indiquez une date de souscription, SVP.');
	document.resiliationLigne.dated.focus();
    return(false);
	}

	document.getElementById("numtester").innerHTML = document.resiliationLigne.tel.value;
	document.getElementById('phone').value = document.resiliationLigne.tel.value; 
	document.getElementById('zip').value = document.resiliationLigne.cp.value;
  
  return(true);
}
function checkPack() {	
	
	var element = document.resiliationLigne.pack;
	if (element)
	{
		var j=0;
		for (var m=0; m<document.resiliationLigne.pack.length; m++ )
		{
			if (document.resiliationLigne.pack[m].checked == true )
			{
				j++;
			} 
		}
		if (j==0){
			alert('Indiquez votre offre, SVP.');
			return(false);
		}
	}else{
		alert('Veuillez selectionnée un autre FAI pour souscrire à une offre');
		return(false);
	}
}
//// ne mettre en évidence qu'un seul fai
function visufainow() {
	for (var n=0; n<document.resiliationLigne.provideridnow.length; n++ )
	{    
		if ( document.resiliationLigne.provideridnow[n].checked == true )
		{    
			YAHOO.util.Dom.setStyle('providerimgnow_'+document.resiliationLigne.provideridnow[n].value+'', 'border', '2px solid #99ccff');
			YAHOO.util.Dom.setStyle('providerimgnow_'+document.resiliationLigne.provideridnow[n].value+'', 'opacity', '1.0');
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'visibility', 'hidden');
			YAHOO.util.Dom.setStyle('logi_'+document.resiliationLigne.provideridnew[n].value+'', 'background', 'url(\'images/resiliation/fai-bg.gif\') 34px 34px repeat-x');
		}else{
			YAHOO.util.Dom.setStyle('providerimgnow_'+document.resiliationLigne.provideridnow[n].value+'', 'border', '2px solid #ffffff');
			YAHOO.util.Dom.setStyle('providerimgnow_'+document.resiliationLigne.provideridnow[n].value+'', 'opacity', '0.5');
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'visibility', 'visible');
			YAHOO.util.Dom.setStyle('logi_'+document.resiliationLigne.provideridnew[n].value+'', 'background', 'none');
		}
		
		if ( document.resiliationLigne.provideridnow[n].checked == true )
		{    
			YAHOO.util.Dom.setStyle('modalite_'+document.resiliationLigne.provideridnow[n].value+'', 'display', 'block');
		}else{
			YAHOO.util.Dom.setStyle('modalite_'+document.resiliationLigne.provideridnow[n].value+'', 'display', 'none');
		}
		
	}
}
function visufainew() {
	for (var n=0;n<document.resiliationLigne.provideridnew.length; n++ )
	{    
		if ( document.resiliationLigne.provideridnew[n].checked == true )
		{    
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'border', '2px solid #99ccff');
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'opacity', '1.0');
			YAHOO.util.Dom.setStyle('loginew_'+document.resiliationLigne.provideridnew[n].value+'', 'background', 'url(\'images/resiliation/fai-bg.gif\') 34px 34px repeat-x');
		}else{
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'border', '2px solid #ffffff');
			YAHOO.util.Dom.setStyle('providerimgnew_'+document.resiliationLigne.provideridnew[n].value+'', 'opacity', '0.5');
			YAHOO.util.Dom.setStyle('loginew_'+document.resiliationLigne.provideridnew[n].value+'', 'background', 'none');
		}
		
		if ( document.resiliationLigne.provideridnew[n].checked == true )
		{    
			YAHOO.util.Dom.setStyle('promo_'+document.resiliationLigne.provideridnew[n].value+'', 'display', 'block');
		}else{
			YAHOO.util.Dom.setStyle('promo_'+document.resiliationLigne.provideridnew[n].value+'', 'display', 'none');
		}
	}
}
	
/** Formulaire de contact **/
function verif(formcontact) {
		if (document.getElementById('nom').value == "" ) {
			alert ("Indiquez votre nom, SVP.");
			document.getElementById('nom').focus();
			return false;
		}
		
		if (document.getElementById('prenom').value == "" ) {
			alert ("Indiquez votre prÃ©nom, SVP.");
			document.getElementById('prenom').focus();
			return false;
		}
		
		if (document.getElementById('email').value == "" ) {
			alert ("Indiquez votre email, SVP.");
			document.getElementById('email').focus();
			return false;
		}
		
		if ((document.getElementById('email').value.search(/ /) != '-1')) {
			alert('Une adresse e-mail ne peut contenir un espace !');
			document.getElementById('email').focus();
			return false;
		}
		s = document.getElementById('email').value.split(/@/);
		if((s.length != 2) || s[0] == '' || s[1] == '') {
			alert('Une adresse e-mail doit avoir le format "Utilisateur@Domain",\n' +'par ex.: "laurent.dupond@net.fr"');
			document.getElementById('email').focus();
			return false ;
		}
	
		if (document.getElementById('information').value == "" ) {
			alert ("Indiquez votre message, SVP.");
			document.getElementById('information').focus();
			return false;
		}
return true;
}
