// JavaScript Document

var once=0;
function goEtape(etape){
	switch (etape) {
		case 1:
			 $('a[@href$="#Etape_1"]').click();
			window.location.href = "#Etape_1";	
			break;
		case 2:
			checkEtape1();
			break;
		
		case 3:
			checkEtape2();
			
			break;
		case 4:
			checkEtape3();
			
			break;
		case 5:
			checkEtape4();
			
			break;
		case 6:
		 	$('a[@href$="#Etape_6"]').click();
			window.location.href = "#Etape_6";
			//window.location.href = "http://fr.sitestat.com/gdf/test/s?formulaire-PJ-etape6&ns_type=clickin";
			//if($.browser.msie)$.ajaxHistory.initialize();
			break;
		default: break;
	}
	//if($.browser.msie)$.ajaxHistory.initialize();
}

function returnEtape(etape){
	
	switch (parseInt(etape)) {
		case 0:
			$('a[@href$="#Etape_0"]').click();
			 window.location.href = "#Etape_0";
			 break;
		case 1:
			$('a[@href$="#Etape_1"]').click();
			window.location.href = "#Etape_1";
			break;
		case 2:
			$('a[@href$="#Etape_2"]').click();
			window.location.href = "#Etape_2";
			break;
		case 3:
			$('a[@href$="#Etape_3"]').click();
			window.location.href = "#Etape_3";break;
		case 4:
			$('a[@href$="#Etape_4"]').click();
			window.location.href = "#Etape_4";
			break;
		default: break;
	}
	//if($.browser.msie)$.ajaxHistory.initialize();
}



function initEtape(etape){
	document.title="Pack Jeunes - Je choisis en ligne"
	var i;var j;
	for(i=0;i<=(etape);i++)
	{
		$("#etape"+(i-1)).html('<a href="#Etape_'+(i-1)+'" title="Etape '+(i-1)+'" class="remote" id="link'+(i-1)+'" ><img src="img/etapes/etape'+(i-1)+'.png" alt="etapes" title="etapes" width="32" height="32" id="pictoEtape'+(i-1)+'IMG" ></a>');
	}
	
	if($("#pictoEtape"+etape+"IMG")){
		$("#etape"+etape).html('<a><img src="img/etapes/etape'+etape+'_on.png" alt="" width="32" height="32" id="pictoEtape'+etape+'IMG" ></a>');
	}
	
	for(j=(etape);j<=5;j++) 
	{
		$("#etape"+(j+1)).html('<a><img src="img/etapes/etape'+(j+1)+'_off.png" alt="" width="32" height="32" id="pictoEtape'+(j+1)+'IMG" ></a>');
	}
	
	$("div.error").html("");
	
	$(".help").popupwindow(POPUP);
	
	$(".helpIMG").attr({src:"img/pictoQuestion.gif",width:"16",height:"16",alt:""});
	$(document).pngFix(); 
	$(document).scrollTop(0);
	UnTip();
}



function data_flash(resultats)
{
	elements=resultats.split("&");
	
	$(elements).each(function() {
		elt=this.split("="); 
		VARIABLES[elt[0]]=elt[1];
	});
	makeDataInit();
	goEtape(3);
}

function makeDataInit(){	
	var data_equipements={four_elec:""};
	jQuery.each(liste_equipements, function(i, equipement){
		data_equipements[equipement]=VARIABLES[equipement];
	});
	/* & devient . */
	/* = devient % */
	var stringDataInitTemp=jQuery.param(data_equipements);
	var expression=new RegExp('&', "g");
	stringDataInitTemp= stringDataInitTemp.replace(expression,"."); 
	expression=new RegExp('=', "g");
	stringDataInitTemp= stringDataInitTemp.replace(expression,":"); 
	stringDataInit=stringDataInitTemp;
}

function envoyerMail()
{
	setVariables();
	
	
	VARIABLES['recapitulatif']=$("#recapitulatif").html();
	VARIABLES['listeEquipements']=$("#listEquipements").html();
	
	$.ajax({
		type: "POST",
		url: "envoiMail.php",
		 data: VARIABLES,
		dataType: "xml",
		success: function(xml) {
			
				if ($(xml).find('success').text()=="1") goEtape(6);
			
		}
	}); 

}



function confirmEmail(data){
//alert("Data Loaded: " + data.success);
	goEtape(6);
}


function setVariables(){
		//var txt="";
		$(document, "form").each(function() {
			$(':input', this).each(function() {
											
			var tag = this.tagName.toLowerCase();
				if (this.type == 'text' )
				{
						VARIABLES[this.name]= this.value;
				}
				else if (this.type == 'radio')
				{
					if(this.checked){
						VARIABLES[this.name]= this.value;
					}
					/*if(this.checked) VARIABLES[this.name]= "oui";
					else  VARIABLES[this.name]= "non";*/
				}
				else if (this.type == 'checkbox')
				{
					if(this.checked) VARIABLES[this.name]= "oui";
					else  VARIABLES[this.name]= "non";
					
				}
				else if (tag == 'select'){
					VARIABLES[this.name]= this.value;
				}

			});
			
		});
}


function setRecapitulatif(){
		var recapitulatif="";
		//var test_array="";
		
		$Situation='<br/>Situation<br/>';
		$Offre='<br/>Offre<br/>';
		$ModePaiement="<br/>Mode paiement<br/>";
		$AdresseFacturation="<br/>Adresse Facturation<br/>";
		
		var i=0;
		jQuery.each(VARIABLES, function(name, variable){
			if (jQuery.inArray(name,NOLIBELLES)==-1){
				recapitulatif+='<tr class="style'+(i%2)+'" ><td class="libelle"  >'+LIBELLES[name]+'</td><td class="resultat" >'+variable+'</td></tr>';
				i++;//test_array+=name+':"",<br/>';
				
				
			}
		});
$debut_infos='<div  style="border : 1px solid #d1dba3;margin-top:10px;padding:5px;color:#6F6966;" ><div style="font-size:15px;color : #7f9607;width : 90%;margin: 0px 0px 0px 0px;padding: 0px;line-height : 15px;" >Vos Infos</div><div style="padding : 10px;" >';
$fin_infos='</div></div>';
/***VOTRE IDENTITES***/
$identite='<div  style="width:100%;display:block;" ><span  style="font-weight:bold;" >Vous</span></div>';
$identite+='<div  >'+VARIABLES['civilite']+' '+VARIABLES['nom']+' '+VARIABLES['prenom']+'';
if(VARIABLES['nom2']!=""){

	$identite+=' - '+VARIABLES['nom2']+' '+VARIABLES['prenom2']+'';
	
}
$identite+='</div>';
$identite+='<div  style="width:100%;display:block;" >Ann&eacute;e de naissance : '+VARIABLES['anneeDeNaissance']+' </div>';



$identite+='<div  style="width:100%;display:block;" >E-mail : '+VARIABLES['email']+'</div>';
$identite+='<div  style="width:100%;display:block;" >';
if(VARIABLES['telephoneFixe']!=""){$identite+='T&eacute;l&eacute;phone fixe : '+VARIABLES['telephoneFixe'];+' &nbsp; '}
else{$identite+='T&eacute;l&eacute;phone fixe : Non renseign&eacute; &nbsp;';}
if(VARIABLES['telephonePortable']!=""){$identite+='&nbsp; T&eacute;l&eacute;phone portable : '+VARIABLES['telephonePortable']+' ';}
else{$identite+='&nbsp;T&eacute;l&eacute;phone portable : Non renseign&eacute;';}




$identite+='</div>';

/******/

/***VOTRE ANCIEN LOGEMENT***/

$ancien_Logement='<div  style="font-weight:bold;"  >Votre ancien logement</div>';
$ancien_Logement+='<div  style="width:100%;display:block;"  >'+VARIABLES['ancienAdresse']+'</div>';
$ancien_Logement+='<div  style="width:100%;display:block;"  >'+VARIABLES['ancienComplementAdresse']+'</div>';
$ancien_Logement+='<div  style="width:100%;display:block;"  >'+VARIABLES['ancienCodePostal']+' '+VARIABLES['ancienVille']+' </div>';
$ancien_Logement+='<div  style="font-weight:bold;"  >Contrat</div>'
$ancien_Logement+='<div  style="width:100%;display:block;"  >R&eacute;f&eacute;rence client : '+VARIABLES['referenceClient']+' </div>';
$ancien_Logement+='<div  style="width:100%;display:block;"  >Date souhait&eacute;e pour la r&eacute;siliation du contrat : '+VARIABLES['dateResiliation']+'</div>';
if(VARIABLES['clientGazDeFranceGaz']=="oui"){
	$ancien_Logement+='<div  style="font-weight:bold;"  >R&eacute;siliation du contrat gaz</div>';
	$ancien_Logement+='<div  style="width:100%;display:block;"  ><span style="background-color:#eaf5b1;">N&deg; Point De Livraison gaz naturel </span>: '+VARIABLES['PdlGaz']+'</div>';
	$ancien_Logement+='<div  style="width:100%;display:block;"  >Compteur gaz naturel accessible sans votre pr&eacute;sence '+VARIABLES['accessibilite']+'</div>';
	$ancien_Logement+='<div  style="width:100%;display:block;"  >Date d\'intervention : '+VARIABLES['dateIntervention']+'</div>';
}
if(VARIABLES['clientGazDeFranceElec']=="oui"){
	$ancien_Logement+='<div  style="font-weight:bold;"  >R&eacute;siliation du contrat &eacute;lectricit&eacute;</div>';
	$ancien_Logement+='<div  style="width:100%;display:block;" ><span style="background-color:#eaf5b1;">N&deg; Point De Livraison gaz &eacute;lectricit&eacute; </span>: '+VARIABLES['PdlElec']+'</div>';
	switch(VARIABLES['typeComptage'])
	{
	case "optionBase": 	
		$ancien_Logement+='<div  style="width:100%;display:block;" >Relev&eacute; Option base : '+VARIABLES['ancienReleveElecOptionBase']+'</div>';
		break;
	case "heuresPHeuresC":
		$ancien_Logement+='<div  style="width:100%;display:block;" >Relev&eacute; Heures Pleines : '+VARIABLES['ancienReleveElecHeurePleine']+' kWh</div>';
		$ancien_Logement+='<div  style="width:100%;display:block;" >Relev&eacute; Heures Creuses : '+VARIABLES['ancienReleveElecHeureCreuse']+' kWh</div>';
		break;
	}
}
/******/

/***VOTRE NOUVEAU LOGEMENT***/
$nouveauLogement='<div  style="font-weight:bold;"   >Votre nouveau logement</div>';
$nouveauLogement+='<div  style="width:100%;display:block;"  >Date pr&eacute;vue d\'emm&eacute;nagement :  '+VARIABLES['dateEmmenagement']+'</div>';
$nouveauLogement+='<div  style="width:100%;display:block;"  >'+VARIABLES['futurAdresse']+'</div>';
$nouveauLogement+='<div  style="width:100%;display:block;"  >'+VARIABLES['futurComplementAdresseFacture']+'</div>';
$nouveauLogement+='<div  style="width:100%;display:block;"  >'+VARIABLES['futurCodePostal']+' '+VARIABLES['futurVille']+' </div>';
if((VARIABLES['futurEtage']!="")||(VARIABLES['futurAppartement']!="")) $nouveauLogement+='<div  style="width:100%;display:block;"  >';
if(VARIABLES['futurEtage']!="") $nouveauLogement+='Etage : '+VARIABLES['futurEtage'];
if(VARIABLES['futurAppartement']!="") $nouveauLogement+=' N&deg; apt : '+VARIABLES['futurAppartement'];  
if((VARIABLES['futurEtage']!="")||(VARIABLES['futurAppartement']!="")) $nouveauLogement+='</div>';
if(VARIABLES['nomAncienOccupant']!="") $nouveauLogement+='<div  style="width:100%;display:block;"  >Nom de l\'ancien occupant : '+VARIABLES['nomAncienOccupant']+' </div>';
/******/

/***VOTRE ADRESSE***/
$votreAdresse='<div   style="font-weight:bold;"   >Votre adresse </div>';
$votreAdresse+='<div  style="width:100%;display:block;"  >'+VARIABLES['actuelAdresse']+'</div>';
$votreAdresse+='<div  style="width:100%;display:block;"  >'+VARIABLES['actuelComplementAdresse']+'</div>';
$votreAdresse+='<div  style="width:100%;display:block;"  >'+VARIABLES['actuelCodePostal']+' '+VARIABLES['actuelVille']+' </div>';
/******/



/***VOTRE CONSOMMATION***/
$vos_consos='<div  style="border : 1px solid #d1dba3;margin-top:10px;padding:5px;color:#6F6966;" ><div style="font-size:15px;color : #7f9607;width : 90%;margin: 0px 0px 0px 0px;padding: 0px;line-height : 15px;" >Vos consos</div><div style="padding : 10px;" >';
if (VARIABLES["situation"]=="logementActuel")
{	
	if(consommationPdlGazChecked)
	{
		$vos_consos+='<div  style="font-weight:bold;"   >Consommation gaz naturel</div>'
		$vos_consos+='<div  style="width:100%;display:block;"  >Plage de consommation annuelle gaz naturel : '+LIBELLES[VARIABLES['consommationAnnuelle']]+' kWh  </div>'
		$vos_consos+='<div  style="width:100%;display:block;"  >N&deg; Point De Livraison gaz naturel:  '+VARIABLES['consommationPdlGaz']+' </div>';
	}
	if(consommationPdlElecChecked)
	{
		$vos_consos+='<div  style="font-weight:bold;"  >Consommation &eacute;lectricit&eacute;</div>';
		$vos_consos+='<div  style="width:100%;display:block;"  >Puissance souscrite &eacute;lectricit&eacute; : '+VARIABLES['puissanceSouscrite']+' kW </div>'
		$vos_consos+='<div  style="width:100%;display:block;"  >N&deg; Point De Livraison &eacute;lectricit&eacute;  :  '+VARIABLES['consommationPdlElec']+' </div>';
	}
}
else
{
	$vos_consos+='<div  style="width:100%;display:block;"  >Nombre de personnes qui vivent dans le logement : '+VARIABLES['nbPersonnes']+' </div>';
	$vos_consos+='<div  style="width:100%;display:block;"  >Nombre de pi&egrave;ces  : '+VARIABLES['nbPieces']+' </div>';
  	$vos_consos+='<div  style="width:100%;display:block;"  >Surface chauff&eacute;e  : '+VARIABLES['surfaceChauffee']+' </div>';
	$vos_consos+='<div  style="width:100%;display:block;"  >Type de chauffage : '+LIBELLES[VARIABLES['typeDeChauffage']]+' </div>';
	$vos_consos+='<div  style="width:100%;display:block;"  >Type de production d\'eau chaude : '+LIBELLES[VARIABLES['typeProductionEauChaude']]+' </div>';
	$vos_consos+='<div  style="width:100%;display:block;"  >Climatisation  : '+LIBELLES[VARIABLES['climatisation']]+' </div>';
	
	VARIABLES['consommationAnnuelle']=VARIABLES['puissanceSouscrite']=VARIABLES['consommationPdlGaz']=VARIABLES['consommationPdlElec']="";
	
	$vos_consos+='<div  style="width:100%;display:block;"  >&Eacute;quipements : <span id="listEquipements" >';
	jQuery.each(liste_equipements, function(i, equipement){
		if (VARIABLES[equipement]!=0){
			$vos_consos+=VARIABLES[equipement] +' '+ LIBELLES[equipement];
			if (VARIABLES[equipement]>1)$vos_consos+='(s)';
			$vos_consos+=', ';
		}
	});
	$vos_consos= $vos_consos.substring(0, ($vos_consos.length-2) )
	$vos_consos+='</span></div>';
}


$vos_consos+='</div></div>';
/******/

/***VOTRE CONTRAT***/
$votreContrat='<div  style="border : 1px solid #d1dba3;margin-top:10px;padding:5px;color:#6F6966;"  ><div style="font-size:15px;color : #7f9607;width : 90%;margin: 0px 0px 0px 0px;padding: 0px;line-height : 15px;" >Votre contrat</div><div style="padding : 10px;" >';
//$votreContrat+='  <div  style="width:100%;display:block;"  > Energie(s) choisie(s) :'+LIBELLES[VARIABLES['energie']]+' </div>  ';
$votreContrat+='<div  style="width:100%;display:block;"  >  Offre choisie :  '+LIBELLES[VARIABLES['offre']]+'</div>';

switch(VARIABLES['energie'])
{
	case "elec_et_gaz":
		$votreContrat+='<div  style="font-weight:bold;"  >Relev&eacute; gaz</div>';
		$votreContrat+='<div  style="width:100%;display:block;" ><span style="background-color:#eaf5b1;">Relev&eacute; gaz </span> : '+VARIABLES['releveGaz']+' m&sup3;</div>';
		$votreContrat+='<div  style="font-weight:bold;"  >Relev&eacute; &eacute;lectricit&eacute;</div>';
		break;
	case "elec":
		$votreContrat+='<div  style="font-weight:bold;"  >Relev&eacute; &eacute;lectricit&eacute;</div>';
		break;
	case "gaz":
		$votreContrat+='<div  style="font-weight:bold;"  >Relev&eacute; gaz</div>';
		$votreContrat+='<div  style="width:100%;display:block;" ><span style="background-color:#eaf5b1;">Relev&eacute; gaz </span>: '+VARIABLES['releveGaz']+' m&sup3;</div>';
		break;
}

if ((VARIABLES['energie']=="elec_et_gaz") || (VARIABLES['energie']=="elec")){
	switch(VARIABLES['typeComptageLogement'])
	{
	case "optionBase": 
		$votreContrat+='<div  style="width:100%;display:block;" >Relev&eacute; Option base : '+VARIABLES['releveElecOptionBase']+' kWh</div>';
		break;
	case "heuresPHeuresC":
		$votreContrat+='<div  style="width:100%;display:block;" > <span style="background-color:#eaf5b1;">Relev&eacute; Heures Pleines </span>:'+VARIABLES['releveElecHeurePleine']+' kWh</div>';
		$votreContrat+='<div  style="width:100%;display:block;" ><span style="background-color:#eaf5b1;">Relev&eacute; Heures Creuses </span>: '+VARIABLES['releveElecHeureCreuse']+' kWh</div>';
		break;
	}
	
	if (VARIABLES["situation"]=="demenagement")
	{	
	//$votreContrat+='<div  ><span   >Type de comptage souhait&eacute; </span>: '+LIBELLES[VARIABLES['futurTypeComptageLogement']]+' </div>';
	}
}


$votreContrat+='</div></div>';
/*******/

/****VOTRE PAIEMENT***/
$votrePaiement='<div  style="border : 1px solid #d1dba3;margin-top:10px;padding:5px;color:#6F6966;"  ><div style="font-size:15px;color : #7f9607;width : 90%;margin: 0px 0px 0px 0px;padding: 0px;line-height : 15px;" >Votre paiement</div><div style="padding : 10px;" >';
$votrePaiement+='<div  style="width:100%;display:block;"  > '+LIBELLES[VARIABLES['modePaiement']]+' </div>';
if(VARIABLES['modePaiement']!="autreModePaiement")
{
	$votrePaiement+='<div  style="width:100%;display:block;"  >Nom du titulaire : '+VARIABLES['nomTitulaire']+' </div>';
	$votrePaiement+='<div  style="width:100%;display:block;"  >Nom de la banque : '+VARIABLES['nomBanque']+' </div>';
	
}
if(VARIABLES['adresseFacturation']=="autreAdresse")
{
	$votrePaiement+='<div  style="font-weight:bold;"  >Adresse de facturation</div>';
	$votrePaiement+='<div  style="width:100%;display:block;"  >'+VARIABLES['civiliteFacture']+' '+VARIABLES['nomFacture']+' '+VARIABLES['prenomFacture']+'</div>';
	$votrePaiement+='<div  style="width:100%;display:block;"  >'+VARIABLES['adresseFacture']+'</div>';
	$votrePaiement+='<div  style="width:100%;display:block;"  >'+VARIABLES['complementAdresseFacture']+'</div>';
	$votrePaiement+='<div  style="width:100%;display:block;"  >'+VARIABLES['codePostalFacture']+' '+VARIABLES['villeFacture']+' </div>';
}
$votrePaiement+='</div></div>';
/******/
		
		if (VARIABLES["situation"]=="demenagement")
		{
			if ((VARIABLES["clientGazDeFrance"]=="client") && (VARIABLES['resiliation']=="resiliationNon"))
			{
				$recapitulatif=$debut_infos+$identite+$ancien_Logement+$nouveauLogement+$fin_infos+$vos_consos+$votreContrat+$votrePaiement;
			}
			else
			{
				
				$recapitulatif=$debut_infos+$identite+$nouveauLogement+$fin_infos+$vos_consos+$votreContrat+$votrePaiement;
			}
		}
		else
		{
			$recapitulatif=$debut_infos+$identite+$votreAdresse+$fin_infos+$vos_consos+$votreContrat+$votrePaiement;
		}
		
		$("#recapitulatif").html($recapitulatif);
		
}





function rememberVariables()
{
	$(document, "form").each(function() {
			$(':input', this).each(function() {
				var tag = this.tagName.toLowerCase();
				if (this.type == 'text')
				{
					$("#"+this.name).val(VARIABLES[this.name]);
				}
				else if (this.type == 'radio')
				{
					$("#"+VARIABLES[this.name]).attr({checked:'checked'});
				}
				else if (this.type == 'checkbox')
				{
					if(VARIABLES[this.name]=="oui")
					{
						this.checked = true;
					}
					if(VARIABLES[this.name]=="non")
					{
						this.checked = false;
					}
				}
				else if (tag == 'select'){
					$('#'+this.name+' option[@value='+VARIABLES[this.name]+']').attr("selected", "selected");
				}
			});
			
			
			
		});
}


function showMeVariables(){
    var data = jQuery.param(VARIABLES);
	
	//alert(data);
}




     function isRIBValid()
     {

	
	var bqe=$("#codeBanque").val();
	var gui=$("#codeAgence").val();
	var cpt=$("#numCompte").val().toUpperCase();
	var cleRIB=$("#cleRib").val();
	
     // Conversion du numero de compte en chiffres
    /* var tab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     var tab1="123456789123456789234567890123456789".split("");*/
	
	var expression;
	var alphanumeriques= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
	var numeriques="123456789123456789234567890123456789".split("");
	
	jQuery.each(alphanumeriques, function(i, alpha){
		var expression=new RegExp(alpha, "g");
		cpt= cpt.replace(expression,numeriques[i]); 
	});
	
	
	 	
    var cp=parseInt (cpt, 10);
		
     //Calcul clé RIB
     a=bqe%97;
     a=a*100000+parseInt(gui, 10);
     a=a%97;
     a=a*Math.pow(10, 11) + cp;
     a=a%97
     a=a*100;
     a=a%97
     a=97-a;
	
    if (cleRIB==a) return true;
	else return false
   }

function checkEquipements(){
	var verifEquipement=false;
	jQuery.each(liste_equipements, function(i, equipement){
		if (VARIABLES[equipement]>0){
			verifEquipement=true;
			
		}
	});
	return verifEquipement;
}



function  editGATRACKER(etape){
	/*switch (parseInt(etape)) {
		case 0:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-5');</script>");
			break;
		case 1:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-6');</script>");
			break;
		case 2:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-7');</script>");
			break;
		case 3:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-8');</script>");
			break;
		case 4:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-9');</script>");
			break;
		case 5:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-10');</script>");
			break;
		case 6:
			$("#GOOGLETRACKER").html("<script type=\"text/javascript\">$.gaTracker('UA-3190062-11');</script>");
			break;  
		default: break;
	}*/
}
