/*
	FONCTIONS DIVERSES, UTILES 
*/

// fonction permettant de remplacer toutes les occurences d'un caractère par un autre dans une chaine
	String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
    } 
// écritures et lecture des cookies	
	function ecrireCookie(nom, valeur)
	{
		var argv=ecrireCookie.arguments;
		var argc=ecrireCookie.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path=(argc > 3) ? argv[3] : null;
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		document.cookie=nom+"="+escape(valeur)+((expires==null) ? "" : ("; expires="+expires.toGMTString()))+((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))+((secure==true) ? "; secure" : "");
	}
	function arguments_cookie(offset)
	{
	  var endstr=document.cookie.indexOf (";", offset);
	  if (endstr==-1) endstr=document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr)); 
	}
	function lire_cookie(nom)
	{
	  var arg=nom+"=";
	  var alen=arg.length;
	  var clen=document.cookie.length;
	  var i=0;
	  while (i<clen){
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
		   return arguments_cookie(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	  }
	  return null; 
	}

		
// fonction de validité d'une date	
		function isValidDate(d) {
			var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
			return d.match(dateRegEx);
		} 
		
		
//fonction de vérification de validité du mail
function verifMail(elm)
{
	var email = elm;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) 
	{
	return false;
	}
	else {
	return true; }
}
 
 //fonction executée au chargement complet de l'application
 $(document).ready(function(){  

		/*
			VARIABLES 
		*/				
		var nom = $("input[name=nom]").val();	
		var prenom = $("input[name=prenom]").val();
		var jr =  $("input[name=jour]").val();
		var ms =  $("input[name=mois]").val();
		var ae =  $("input[name=annee]").val();
		var tel1 =  $("input[name=tel1]").val();
		var tel2 =  $("input[name=tel2]").val();
		var tel3 =  $("input[name=tel3]").val();
		var tel4 =  $("input[name=tel4]").val();
		var tel5 =  $("input[name=tel5]").val();
		var mail =  $("input[name=mail]").val();	
		var date = jr +"/"+ms+"/" + ae;
		var tel = tel1 + tel2 + tel3 + tel4 + tel5 ;
		if (isNaN(tel) || tel.length <10 || nom=='' || prenom=='' || jr=='' || isNaN(jr) || ae < 1900 || isNaN (ms) || isNaN(ae)|| ms=='' || ae=='' || !isValidDate(date) ||  tel1=='' || tel2=='' || tel3=='' || tel4==''|| tel5=='' ||mail=='' || !verifMail(mail))
		{
			$('input[id=val1]').css('display','none');	
		}
		else
		{
			$('input[id=val1]').css('display','block');
		}
		
		
		// efface les textes d'aide lors du focus
		$('input[name=jour]').focus(function(){ if($(this).val() == 'jj') $(this).val('');});
		$('input[name=mois]').focus(function(){ if($(this).val() == 'mm') $(this).val('');});
		$('input[name=annee]').focus(function(){ if($(this).val() == 'aaaa') $(this).val('');});
		$('input[name=jourC]').focus(function(){ if($(this).val() == 'jj') $(this).val('');});
		$('input[name=moisC]').focus(function(){ if($(this).val() == 'mm') $(this).val('');});
		$('input[name=anneeC]').focus(function(){ if($(this).val() == 'aaaa') $(this).val('');});
	
/*
	PARTIE VERIFICATION DU FORMULAIRE
*/
	// gère l'affichage du bouton de validation
	$("input").change(function()
	{
		var nom = $("input[name=nom]").val();
		var prenom = $("input[name=prenom]").val();
		var jr =  $("input[name=jour]").val();
		var ms =  $("input[name=mois]").val();
		var ae =  $("input[name=annee]").val();
		var tel1 =  $("input[name=tel1]").val();
		var tel2 =  $("input[name=tel2]").val();
		var tel3 =  $("input[name=tel3]").val();
		var tel4 =  $("input[name=tel4]").val();
		var tel5 =  $("input[name=tel5]").val();
		var mail =  $("input[name=mail]").val();	
		var date = jr +"/"+ms+"/" + ae;
		var tel = tel1 + tel2 + tel3 + tel4 + tel5 ;
		if (isNaN(tel) || tel.length <10 || nom=='' || prenom=='' || jr=='' || ae < 1900 || isNaN(jr) || isNaN (ms) || isNaN(ae)|| ms=='' || ae=='' || !isValidDate(date) ||  tel1=='' || tel2=='' || tel3=='' || tel4==''|| tel5=='' ||mail=='' || !verifMail(mail))
		{
			$('input[id=val1]').css('display','none');	
		}
		else
		{
			$('input[id=val1]').css('display','block');
		}
	});

	// met en majusculte le contenu du champ nom
	$('input[name=nom]').keydown(function()
	{
		$(this).val($(this).val().toUpperCase());
	});	
	// met en majuscule le contenu du champ prénom
	$('input[name=prenom]').keydown(function()
	{
		$(this).val($(this).val().toUpperCase());
	});	
	// met en minuscule le contenu du champ mail
	$('input[name=mail]').keydown(function()
	{
		$(this).val($(this).val().toLowerCase());
	});	
	
	$("input").focus(function(){
		
		var info_form = $(this).next(".info");
		info_form.empty();
		if ($(this).val() == 'Champ obligatoire' || $(this).val() == "")
		{
			$(this).css({border:"1px solid #6e6e6e",color:"black"});
			$(this).val("");	
		}
	}); 
	
	// vérifie le champs nom et prénoms
    $("input[class=first]").blur(function(){  
		
        var name=($(this).attr("name"));
		var value=($(this).attr("value"));
		var info_form=$(this).next(".info");
		var final = value.ReplaceAll(" ","");	
		if(final==undefined || final=="")	
		{
			$(this).val("Champ obligatoire"); 
			 $(this).css({border:"1px solid red",color:"red"});
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
		} 
		else
		{
			$(this).css({border:"1px solid #6e6e6e",color:"black"});
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");
		}
  
	}); 
	
	//vérification du mail
	$("input[name=mail]").blur(function(){
		var value=($(this).attr("value"));
		var info_form=$(this).next(".info");
		var final = value.ReplaceAll(" ","");
		if(!verifMail(final))	
		{
			if (final == '')
			$(this).val("Champ obligatoire"); 
			 $(this).css({border:"1px solid red",color:"red"});
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
		} 
		else
		{
			$(this).css({border:"1px solid #6e6e6e",color:"black"});
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");
		}
	});
	// vérifie le champ date de "vous"
	$("input[class=date]").blur(function(){ 
		var valJr0 = $("input[name=jour]").val();
			var valJr = valJr0.ReplaceAll(" ","");
		var valMs0 = $("input[name=mois]").val();
			var valMs = valMs0.ReplaceAll(" ","");
		var valAe0 = $("input[name=annee]").val();
			var valAe = valAe0.ReplaceAll(" ","");
		var info_form=$("input[name=annee]").next(".info");
		// prépare la date au format jj/mm/aaaa pour vérifier la validité
		if (valJr.length ==1) { valJr = '0' + valJr ; }
		if (valMs.length == 1) {valMs = '0' + valMs; }
		var dateEntiere = valJr + '/' + valMs + '/' + valAe ;
		// vérification du jour
		if (valJr != "" || valJr != undefined )
		{
			$("input[name=jour]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if (valJr == "" || valJr == undefined || !isValidDate(dateEntiere) )
		{
			$("input[name=jour]").css({border:"1px solid red",color:"red"});
		}
		// vérification du mois
		if (valMs != "" || valMs != undefined )
		{
			$("input[name=mois]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if (valMs == "" || valMs == undefined || !isValidDate(dateEntiere)  )
		{
			$("input[name=mois]").css({border:"1px solid red",color:"red"});
		}		
		// vérification de l'année
		if (valAe != "" || valAe != undefined || valAe > 1900 )
		{
			$("input[name=annee]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if (valAe == "" || valAe == undefined || !isValidDate(dateEntiere) || valAe < 1900  )
		{
			$("input[name=annee]").css({border:"1px solid red",color:"red"});
		}		
				
		if (valJr == "" || valJr== undefined || valMs ==undefined || valMs =="" || valAe == undefined || valAe =="" || valAe <1900 || !isValidDate(dateEntiere) ) 
		{
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
		}
		else
		{
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");
			
			var date = new Date();
			var year = date.getFullYear();
			var ae = $("input[name=annee]").val();
			if ( (year - ae) -1 >= 72 || (year - ae) -1 < 17 ) {
				$('span[id=redir]').show();	
				$('#redir a').nyroModal({
					closeSelector: '#close_mlR',
					bgColor: '#168793',
					minWidth: 770 ,
					minHeight: 120 ,
				});
				$('#redir a').click();
			}
		 } 
	}); 
	// vérifie le champs date du conjoint
	$("input[class=date1]").blur(function(){ 
		var valJr0 = $("input[name=jourC]").val();
			var valJr = valJr0.ReplaceAll(" ","");
		var valMs0 = $("input[name=moisC]").val();
			var valMs = valMs0.ReplaceAll(" ","");
		var valAe0 = $("input[name=anneeC]").val();
			var valAe = valAe0.ReplaceAll(" ","");
		var info_form=$("input[name=anneeC]").next(".info");
		// prépare la date au format jj/mm/aaaa pour vérifier la validité
		if (valJr.length ==1) { valJr = '0' + valJr ; }
		if (valMs.length == 1) {valMs = '0' + valMs; }
		var dateEntiere = valJr + '/' + valMs + '/' + valAe ;
	
		if (valJr !='' || valMs !='' || valAe != '')
		{
			// vérification du jour
			if (valJr != "" || valJr != undefined )
			{
				$("input[name=jourC]").css({border:"1px solid #6e6e6e",color:"black"});
			}
			if (valJr == "" || valJr == undefined || !isValidDate(dateEntiere) )
			{
				$("input[name=jourC]").css({border:"1px solid red",color:"red"});
			}
			// vérification du mois
			if (valMs != "" || valMs != undefined )
			{
				$("input[name=moisC]").css({border:"1px solid #6e6e6e",color:"black"});
			}
			if (valMs == "" || valMs == undefined || !isValidDate(dateEntiere)  )
			{
				$("input[name=moisC]").css({border:"1px solid red",color:"red"});
			}		
			// vérification de l'année
			if (valAe != "" || valAe != undefined || valAe > 1900 )
			{
				$("input[name=anneeC]").css({border:"1px solid #6e6e6e",color:"black"});
			}
			if (valAe == "" || valAe == undefined || !isValidDate(dateEntiere) || valAe < 1900  )
			{
				$("input[name=anneeC]").css({border:"1px solid red",color:"red"});
			}		
					
			if (valJr == "" || valMs =="" || valAe =="" || !isValidDate(dateEntiere) || valAe <1900) 
			{
				info_form.empty();
				info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			}
			else
			{
				info_form.empty();
				info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");
				// Vérification limite age du conjoint (idem Assuré)
    			var date = new Date();
    			var year = date.getFullYear();
    			var ae = $("input[name=anneeC]").val();
    			if ( (year - ae) -1 >= 72) {
    				$('span[id=redir]').show();	
    				$('#redir a').nyroModal({
					closeSelector: '#close_mlR',
					bgColor: '#168793',
					minWidth: 770 ,
					minHeight: 120 ,
    				});
    				$('#redir a').click();
    			}			
			}
		}	
		else
		{
			info_form.empty();
			$('input[class=date1]').css({border:"1px solid #6e6e6e",color:"black"});	
		}
	}); 

	// vérifie le champ téléphone
	$("input[class=Inputtel]").blur(function(){ 
											  
		var info_form = $("input[name=tel5]").next(".info");	
		info_form.empty();
		var val1a = $("input[name=tel1]").val();
			var val1 = val1a.ReplaceAll(" ","");
		var val2a = $("input[name=tel2]").val();
			var val2 = val2a.ReplaceAll(" ","");
		var val3a = $("input[name=tel3]").val();
			var val3 = val3a.ReplaceAll(" ","");
		var val4a = $("input[name=tel4]").val();
			var val4 = val4a.ReplaceAll(" ","");
		var val5a = $("input[name=tel5]").val();
			var val5 = val5a.ReplaceAll(" ","");
		//cas ou aucun des champs n'est remplis
		if ( (val1=="" || val1==undefined || val1.length < 2 || isNaN(val1) ) || (val2=="" || val2==undefined || val2.length < 2 || isNaN(val2) ) || (val3=="" || val3==undefined || val3.length < 2 || isNaN(val3) ) || (val4=="" || val4==undefined || val4.length < 2 || isNaN(val4)) || (val5=="" || val5==undefined || val5.length < 2 || isNaN(val5))) 
		{
			$("input[name=tel1]").css({border:"1px solid red",color:"red"});
			$("input[name=tel2]").css({border:"1px solid red",color:"red"});
			$("input[name=tel3]").css({border:"1px solid red",color:"red"});
			$("input[name=tel4]").css({border:"1px solid red",color:"red"});
			$("input[name=tel5]").css({border:"1px solid red",color:"red"});
		}
		if ( (val1!="" && val1!=undefined && val1.length == 2 && !isNaN(val1)))
		{ 
			$("input[name=tel1]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if ( (val2!="" && val2!=undefined && val2.length == 2 && !isNaN(val2)))
		{ 
			$("input[name=tel2]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if ( (val3!="" && val3!=undefined && val3.length == 2 && !isNaN(val3)))
		{ 
			$("input[name=tel3]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if ( (val4!="" && val4!=undefined && val4.length == 2 && !isNaN(val4)))
		{ 
			$("input[name=tel4]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if ( (val5!="" && val5!=undefined && val5.length == 2 && !isNaN(val5)))
		{ 
			$("input[name=tel5]").css({border:"1px solid #6e6e6e",color:"black"});
		}
		if (!isNaN(val1) && !isNaN(val2) && !isNaN(val3) && !isNaN(val4) && !isNaN(val5) && val1!="" && val1.length == 2 && val2 !="" && val2.length == 2 && val3 != "" && val3.length ==2 && val4 != "" && val4.length == 2 && val5 != "" && val5.length == 2)
		{
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");
		}
		else
		{
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");	
		}
	});
	//controle du champs enfants
	//$("input[name=enfant]").blur( function() {
	$("input[class=enfants]").blur( function() {
		var enfant = $('input[name=enfant-]').val();
		var enfant1 = $('input[name=enfant+]').val();
		
		var value = $(this).val();
		var info_form=$('input[name=enfant+]').next(".info");
		// cas ou l'un des deux n'est pas valide
		if (isNaN(enfant) || isNaN(enfant1)) {
			$(this).css({border:"1px solid red",color:"red"});
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
		}
		// cas ou ils sont tout les deux valides
		if (!isNaN(value) && value != '' && !isNaN(enfant) && !isNaN(enfant1))
		{
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_ok.png' />");	
			$(this).css({border:"1px solid #6e6e6e",color:"black"});
		}
		
		if (value =='') {
			$(this).css({border:"1px solid #6e6e6e",color:"black"});		
		}
	});
	// gère le passage au champ suivant pour le téléphone
	// met en majusculte le contenu du champ nom
	$('input[class=Inputtel]').keyup(function() {	
		var name=($(this).attr("name"));
		var indice = name[3];
		indice++ ;
		var value=($(this).attr("value"));
		var stg = "input[name=tel" + (indice) + "]";
		if (value.length == 2 && indice < 6) {$(stg).focus(); }
	});	
	// gere le passage au champs suivant pour le champ date
	$('input[class=date]').keyup(function() {	
		var name=($(this).attr("name"));
		var value=($(this).attr("value"));
		var stg ="";
		if (value.length == 2){
		switch (name) {
			case 'jour': stg = "input[name=mois]"; break;
			case 'mois' : stg = "input[name=annee]"; break;
			}
		}
		$(stg).focus();
	});
	$('input[class=date1]').keyup(function() {	
		var name=($(this).attr("name"));
		var value=($(this).attr("value"));
		var stg ="";
		if (value.length == 2){
		switch (name) {
			case 'jourC': stg = "input[name=moisC]"; break;
			case 'moisC' : stg = "input[name=anneeC]"; break;
			}
		}
		$(stg).focus();
	});
	// controle lors du submit
	$("#formInfo").submit( function() {
   		var res = true ;
		var nom = $("input[name=nom]").val().ReplaceAll(" ","");
		var prenom = $("input[name=prenom]").val();
		var jr =  $("input[name=jour]").val();
		var ms =  $("input[name=mois]").val();
		var ae =  $("input[name=annee]").val();
		var tel1 =  $("input[name=tel1]").val();
		var tel2 =  $("input[name=tel2]").val();
		var tel3 =  $("input[name=tel3]").val();
		var tel4 =  $("input[name=tel4]").val();
		var tel5 =  $("input[name=tel5]").val();
		var mail =  $("input[name=mail]").val();
		var enfant = $('input[name=enfant-]').val();
		var enfant1 = $('input[name=enfant+]').val();
		var jrC =  $("input[name=jourC]").val();
		var msC =  $("input[name=moisC]").val();
		var aeC =  $("input[name=anneeC]").val();
		//vérification du nom
		if (nom == '' || nom == undefined || nom =='Champ obligatoire') {
			var info_form = $("input[name=nom]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=nom]").css({border:"1px solid red",color:"red"});
			$("input[name=nom]").val("Champ obligatoire");
			res = false;
		}
		//verification du prenom
		if (prenom == '' || prenom == undefined) {
			var info_form = $("input[name=prenom]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=prenom]").css({border:"1px solid red",color:"red"});
			$("input[name=prenom]").val("Champ obligatoire");
			res = false;	
		}
		// verification date
		if (jr =='' || ms =='' || ae == '' || !isValidDate(jr + "/"+ms +"/" + ae)) {
			var info_form = $("input[name=annee]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=jour]").css({border:"1px solid red",color:"red"});
			$("input[name=mois]").css({border:"1px solid red",color:"red"});
			$("input[name=annee]").css({border:"1px solid red",color:"red"});
			res = false;	
		}
		// verification date conjoint
		if (((jrC !='' && jrC!='jj') || (msC !='' && msC != 'mm') || (aeC != '' && msC != 'mm')) && (!isValidDate(jrC + "/"+msC +"/" + aeC) || aeC < 1900)) {
			var info_form = $("input[name=anneeC]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=jourC]").css({border:"1px solid red",color:"red"});
			$("input[name=moisC]").css({border:"1px solid red",color:"red"});
			$("input[name=anneeC]").css({border:"1px solid red",color:"red"});
			res = false;	
		}
		//vérification téléphone
		if (tel1 =='' || tel1.length != 2 || tel2 == '' || tel2.length != 2|| tel3 == '' || tel3.length != 2|| tel4 == '' || tel4.length != 2|| tel5 == '' || tel5.length != 2) {
			var info_form = $("input[name=tel5]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=tel1]").css({border:"1px solid red",color:"red"});
			$("input[name=tel2]").css({border:"1px solid red",color:"red"});
			$("input[name=tel3]").css({border:"1px solid red",color:"red"});
			$("input[name=tel4]").css({border:"1px solid red",color:"red"});
			$("input[name=tel5]").css({border:"1px solid red",color:"red"});
			res = false;	
		}
		//vérification mail
		if (mail =='' || !verifMail(mail)) {
			var info_form = $("input[name=mail]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=mail]").css({border:"1px solid red",color:"red"});
			if (mail =="") {
			$("input[name=mail]").val("Champ obligatoire"); }
			res = false;
		}
		// vérification enfants 
		if (isNaN(enfant) || isNaN(enfant1)) {
			var info_form = $("input[name=enfant+]").next(".info");	
			info_form.empty();
			info_form.append("<img style='float:left;margin-left:4px;' src='img/form_pasok.png' />");
			$("input[name=enfant]").css({border:"1px solid red",color:"red"});
			res = false;
		}
		/* Handler d'appel Caméléon pour récupération tarifs
		   paramétre d'appel :
		        P1 : Age du prospect	
		        P2 : Age du conjoint	
		        P3 : Nombre enfant+1
		*/
//		alert("submit activé");
		tPrix = new Array();
//		alert("submit activé");
        tPrix[0] = new charge_prix(ae,aeC,enfant1);
//		alert("prix se1="+tPrix[0].PrixSe1);
//		alert("prix se2="+tPrix[0].PrixSe2);
//		alert("prix se3="+tPrix[0].PrixSe3);
//		alert("prix se4="+tPrix[0].PrixSe4);

        var rPrix1 = tPrix[0].PrixSe1.toFixed(2);
        var rPrix2 = tPrix[0].PrixSe2.toFixed(2);
        var rPrix3 = tPrix[0].PrixSe3.toFixed(2);
        var rPrix4 = tPrix[0].PrixSe4.toFixed(2);
		prix1 = rPrix1+' €';
		prix2 = rPrix2+' €';
		prix3 = rPrix3+' €';
		prix4 = rPrix4+' €';

//		alert("Prix1="+prix1+" Prix2="+prix2+" Prix3="+prix3+" Prix4="+prix4);
	
		$('div[id=devis2]').text(prix1); // initialisation prix*/
		// affiche le deuxieme bloc	
		if (res) {
			var date = new Date();
			var year = date.getFullYear();
			if ( (year - ae) -1 < 72)
			{
				$("div[id=cps_b2]").fadeIn(2000);
			}
			else
			{
				$('span[id=redir]').show();	
				$('#redir a').nyroModal({
				closeSelector: '#close_mlR',
				bgColor: '#168793',
				minWidth: 770 ,
				minHeight: 120 ,
				});
				$('#redir a').click();
			}			
			//récupère l'adresse de la page courante
			var adr = new String(window.location);
			// modifie l'adresse pour obtenir l'adresse du dossier des images
			var debut = adr.lastIndexOf('/');
			var adrF = adr.substr(0,debut);
			adrF = adrF + '/img/' ;
			var adrF = adrF.ReplaceAll(" ","%20");
			adrF = adrF + 'valide1_valide.jpg' ;
			$("input[id=val1]").css('background-image','url('+adrF+')');
			$("input[id=val1]").css('border','0');
            if ( ((enfant != '') || (enfant1 != '')) && ((parseInt(enfant) > 0) || parseInt(enfant1) > 0) || (((jrC != '') && (msC != '') && (aeC != '')) && ((jrC != 'jj') && (msC != 'mm') && (aeC != 'aaaa'))))
			{
					$("div[id=devis1_txt]").text('Pour vous et votre famille');
			}
			else
			{
					$("div[id=devis1_txt]").text('Pour vous');
			}
			res = false;
		}
		return res ;
	});
/*
	PARTIE SLIDER
*/
var lastVal = 1 ;
$("#slider_bar").slider({
	handle: '.slider_handle',
	min: 1,
	max: 4,
	steps:3,
	start: function (e, ui) {

	},
	change: function (e, ui) {
		$("div.bulle_info").hide();
		$("div.bulle_info").css({top: "38px", left: "0px"});
		switch (ui.value)
		{
			case 1: $('div[id=bul_text]').text('Pour couvrir les gros frais d\'hospitalisation et les soins de ville');
					$('div[id=bul_titre]').text('L\'indispensable'); break;
			case 2: $('div[id=bul_text]').text('Une protection santé pour un budget minimum');
					$('div[id=bul_titre]').text('L\'essentiel'); break;
			case 3: $('div[id=bul_text]').text('Pour des remboursements renforcés des dépenses importantes');
					$('div[id=bul_titre]').text('La sécurité '); break;
			case 4: $('div[id=bul_text]').text('Pour être tranquille, même en optique et dentaire');
					$('div[id=bul_titre]').text('La confortable'); break;
		}
		$("div.bulle_info").css({top: "76px", left: "0px"}).animate({top: "38px", opacity: "show"}, 1000);
		
	},
	slide: function(e, ui) {
		//récupère l'adresse de la page courante
		var adr = new String(window.location);
		// modifie l'adresse pour obtenir l'adresse du dossier des images
		var debut = adr.lastIndexOf('/');
		var adrF = adr.substr(0,debut);
		adrF = adrF + '/img/' ;
		var val = ui.value;
	   lastVal = val;
		var adrF = adrF.ReplaceAll(" ","%20");
		if (val == 1)  {
			$('div[id=etiquette1]').text('');
			$('div[id=etiquette2]').text('N2');
			$('div[id=etiquette3]').text('N3');
			$('div[id=etiquette4]').text('N4');
			$('div[id=etiquette1]').removeClass('etiquette1');
			$('div[id=etiquette1]').addClass('etiquette1_over');
			$('div[id=etiquette4]').removeClass('etiquette4_over');
			$('div[id=etiquette4]').addClass('etiquette4');			
			$('div[id=etiquette2]').removeClass('etiquette2_over');
			$('div[id=etiquette2]').addClass('etiquette2');	
			$('div[id=etiquette3]').removeClass('etiquette3_over');
			$('div[id=etiquette3]').addClass('etiquette3');
			$('div[id=gar_mil1]').css('background-image','url(' +adrF +'BARRE_1.jpg)');
			$('div[id=devis2]').text(prix1);
			$('div[id=param]').text("1");
		}
		if (val == 2) {
			//$('div[id=bul_text]').text('popo');
			$('div[id=etiquette1]').text('N1');
			$('div[id=etiquette2]').text('');
			$('div[id=etiquette3]').text('N3');
			$('div[id=etiquette4]').text('N4');
			$('div[id=etiquette2]').removeClass('etiquette2');
			$('div[id=etiquette2]').addClass('etiquette2_over');
			$('div[id=etiquette1]').removeClass('etiquette1_over');
			$('div[id=etiquette1]').addClass('etiquette1');			
			$('div[id=etiquette3]').removeClass('etiquette3_over');
			$('div[id=etiquette3]').addClass('etiquette3');	
			$('div[id=etiquette4]').removeClass('etiquette4_over');
			$('div[id=etiquette4]').addClass('etiquette4');		
			$('div[id=gar_mil1]').css('background-image','url(' +adrF +'BARRE_2.jpg)');
			$('div[id=devis2]').text(prix2);
			$('div[id=param]').text("2");
		}
		if (val == 3) {
			$('div[id=etiquette1]').text('N1');
			$('div[id=etiquette2]').text('N2');
			$('div[id=etiquette3]').text('');
			$('div[id=etiquette4]').text('N4');
			$('div[id=param]').text("3");
			$('div[id=etiquette3]').removeClass('etiquette3');
			$('div[id=etiquette3]').addClass('etiquette3_over');
			$('div[id=etiquette1]').removeClass('etiquette1_over');
			$('div[id=etiquette1]').addClass('etiquette1');			
			$('div[id=etiquette2]').removeClass('etiquette2_over');
			$('div[id=etiquette2]').addClass('etiquette2');	
			$('div[id=etiquette4]').removeClass('etiquette4_over');
			$('div[id=etiquette4]').addClass('etiquette4');
			$('div[id=gar_mil1]').css('background-image','url(' +adrF +'BARRE_3.jpg)');
			$('div[id=devis2]').text(prix3);
		}
		if (val == 4) {
			$('div[id=etiquette1]').text('N1');
			$('div[id=etiquette2]').text('N2');
			$('div[id=etiquette3]').text('N3');
			$('div[id=etiquette4]').text('');
			$('div[id=param]').text("4");
			$('div[id=etiquette4]').removeClass('etiquette4');
			$('div[id=etiquette4]').addClass('etiquette4_over');
			$('div[id=etiquette1]').removeClass('etiquette1_over');
			$('div[id=etiquette1]').addClass('etiquette1');			
			$('div[id=etiquette2]').removeClass('etiquette2_over');
			$('div[id=etiquette2]').addClass('etiquette2');	
			$('div[id=etiquette3]').removeClass('etiquette3_over');
			$('div[id=etiquette3]').addClass('etiquette3');
			$('div[id=gar_mil1]').css('background-image','url(' +adrF +'BARRE_4.jpg)');
			$('div[id=devis2]').text(prix4);				
		}
	}
});
//
///*
//	FENETRE MODALE
//
// */
//$('#gar_mil2 a.modal').click ( function() {
//	$('div.bulle_info').hide();								  
//});
//$('#mentions a.mentions').click ( function() {
//	$('div.bulle_info').hide();								  
//});
//$('#gar_mil2 a').nyroModal({
//	closeSelector: '#close',
//	bgColor: '#168793',
//	minWidth: 850 ,
//	minHeight: 550,
//	endShowContent: function () {
//		var lastVal = $('div[id=param]').text();
//		$("div[id=slider_barA]").slider("moveTo","+="+ (lastVal));
//		$('div[id=devisa_txt]').text($('div[id=devis1_txt]').text());
//	},
//	endRemove: function () {
//		var val = $('div[id=param]').text();
//		$("div[id=slider_bar]").slider("moveTo","-="+ (val));
//		$("div[id=slider_bar]").slider("moveTo","+="+ (val - 1));
//	},	
//});
//
//$('#cps_bb a.lien1').nyroModal({
//	closeSelector: '#fermer_ct',
//	bgColor: '#168793',
//	minWidth: 214 ,
//	minHeight: 346 ,
//	
//});
//
//$('#mentions a.mentions').nyroModal({
//	closeSelector: '#close_ml',
//	bgColor: '#168793',
//	minWidth: 905 ,
//	minHeight: 310 ,
//	endRemove: function () {
//		$('div.bulle_info').show();	
//	}	,
//});

/*
	PARTIE STOCKAGE DES INFORMATIONS
*/

// au clic sur la validation 2 on sauvegarde les donnée dans un cookie
$('div[id=val2]').click ( function () {
	// récupération des données
	var civilite = $('input[name=civilite][checked]').val();
	//var res = true ;
	var nom = $("input[name=nom]").val();
	var prenom = $("input[name=prenom]").val();
	var jr =  $("input[name=jour]").val();
	var ms =  $("input[name=mois]").val();
	var ae =  $("input[name=annee]").val();
	var dateN = jr +"/"+ ms + "/" + ae ;
	var tel1 =  $("input[name=tel1]").val();
	var tel2 =  $("input[name=tel2]").val();
	var tel3 =  $("input[name=tel3]").val();
	var tel4 =  $("input[name=tel4]").val();
	var tel5 =  $("input[name=tel5]").val();
	var tel = tel1+tel2+tel3+tel4+tel5 ;
	var mail =  $("input[name=mail]").val();

	var enfant = $('input[name=enfant-]').val();
	var enfant2 =  $('input[name=enfant+]').val();
	
	var jrC =  $("input[name=jourC]").val();
	var msC =  $("input[name=moisC]").val();
	var aeC =  $("input[name=anneeC]").val();
	var regime = $("select[name=regime]").val();
	var total = civilite +"_"+nom+ "_" +prenom+ "_" +dateN+ "_" +tel+ "_" +mail + "_"+ regime ;
	var totalPrix = prix1+"_"+prix2+"_"+prix3+"_"+prix4;
	var totalDevis = null;
    var AsPrix = Sellprix[lastVal-1][0].toFixed(2);
    var CJPrix = Sellprix[lastVal-1][1].toFixed(2);
    var EnfPrix = Sellprix[lastVal-1][2].toFixed(2);
		
	if (enfant != "" && enfant2 != "") {
		Sell_enfant_moins1an = enfant;
        Sell_enfant = enfant2;
		total = total + "_" + (enfant + "%" + enfant2);
	}
	else if (enfant != "") {
		Sell_enfant_moins1an = enfant;
		total = total + "_" + enfant + "%0" ;			
	}
	else if (enfant2 !="") {
        Sell_enfant = enfant2;	
		total = total + "_0%" + enfant2;	
	}

	if (jrC !="" && jrC !='jj' && msC != "" && msC!= 'mm'  && aeC != "" && aeC != 'aaaa')
	{
		var dateNC = jrC +"/"+msC+"/"+aeC ;
		Sell_conjoint = dateNC;
		total = total + "_" + dateNC;
	}
		
    switch(lastVal)
    {
    case 1 :
        totalDevis = prix1.substring(0,prix1.length-2);
        break;
    case 2 :
        totalDevis = prix2.substring(0,prix2.length-2);
        break;
    case 3 :
        totalDevis = prix3.substring(0,prix3.length-2);
        break;
    case 4 :
        totalDevis = prix4.substring(0,prix4.length-2);
        break;
    default :
        alert("Erreur prix - contactez SVP notre service client");
    } 
    Devis_prix = totalDevis;
	Ref_NumDevis = Num_Devis();
	totalDevis = Ref_NumDevis+"_"+totalDevis+"_"+AsPrix+"_"+CJPrix+"_"+EnfPrix;

	ecrireCookie("slider",lastVal);
	ecrireCookie("infoVous",total);
	ecrireCookie("ConfTarif",totalPrix);
	ecrireCookie("DevisPrix",totalDevis);	

   	// Génération Flux JasperReport
    Sell_garantie = lastVal;
    AS_prix = AsPrix;       
    CJ_prix = CJPrix;
    ENF_prix = EnfPrix;
	Sell_civilite = civilite;
    Sell_nom = nom;
    Sell_prenom = prenom;
    Sell_dateAs = dateN;
    Sell_telephone = tel;
    Sell_email = mail;
    Sell_regime = regime;
    Sell_dateDevis = dateN.split("/");
    Id_Devis = Ref_NumDevis+Sell_nom+Sell_dateDevis[0]+Sell_dateDevis[1]+Sell_dateDevis[2];
    Sell_datejourdevis = Ref_NumDevis.substring(6, 8) + "/" + Ref_NumDevis.substring(4, 6) + "/" + Ref_NumDevis.substring(0, 4);
    //alert("valeur conjoint : "+Sell_conjoint+" valeur enfant moins1an : "+Sell_enfant_moins1an+" valeur enfant : "+Sell_enfant);
    ok = ParamSelligentHandler("jasper", "", "");
        if(ok) {
        AppelSelligentHandler();
        }
        else {
        alert("Erreur chargement du récapitulatif devis - merci de contacter notre service client");      
        }  

   	// traçabilité suspect
    /*
	1ère phase de test
    Sell_garantie = lastVal;
    AS_prix = AsPrix;       
    CJ_prix = CJPrix;
    ENF_prix = EnfPrix;
	Sell_civilite = civilite;
    Sell_nom = nom;
    Sell_prenom = prenom;
    Sell_dateAs = dateN;
    Sell_telephone = tel;
    Sell_email = mail;
    Sell_regime = regime;
    Sell_dateDevis = dateN.split("/");
	Sell_enfant_moins1an = enfant;
    Sell_enfant = enfant2;
	Sell_conjoint = dateNC;	
    Ref_NumDevis = Num_Devis();
    Id_Devis = Ref_NumDevis+Sell_nom+Sell_dateDevis[0]+Sell_dateDevis[1]+Sell_dateDevis[2];
    Sell_datejourdevis = Ref_NumDevis.substring(6, 8) + "/" + Ref_NumDevis.substring(4, 6) + "/" + Ref_NumDevis.substring(0, 4);
    ok = ParamSelligentHandler("suspect", "", "");
        if(ok) {
        AppelSelligentHandler();      
        }
        else {
        alert("Erreur chargement du récapitulatif devis - merci de contacter notre service client");      
        }
*/     
   });   
});

