<?php

global $user;

if (isset($user->uid) && $user->uid == 103) {
  define('QLA', TRUE);
} else {
  define('QLA', FALSE);
}

	require_once ('soap/AsgardWSClient.php');
	setlocale(LC_MONETARY, 'fr_FR.UTF-8');
	//session_start();


if (isset($_POST)) {

// if (isset($_POST['code_insee'])) echo "<br>bis : ".$_POST['code_insee'];



$_SESSION['inscription'] = "";
									$_SESSION['params'] = array();
									$_SESSION['params'] = $_POST;

									foreach ($_SESSION['offres']->SOffre as $key => $value) {

										if ($_SESSION['params']['id_offre'] == $value->id_offre) {
											// on recupere l'offre selectionnée
											$_SESSION['inscription']['offre'] = $value;
										}
									}

									$_SESSION['inscription']['type'] = $_POST['type'];
									$_SESSION['inscription']['code_insee'] = $_POST['code_insee'];
									$_SESSION['inscription']['latitude'] = $_POST['lat'];
									$_SESSION['inscription']['longitude'] = $_POST['lng'];


									$_SESSION['inscription']['nra_prevu'] = $_SESSION['inscription']['offre']->nra->reference;

									$string_nras = '';
									foreach ($_SESSION['inscription']['offre']->nras->SNra as $key => $value) {
										if ($string_nras != '') {
											$string_nras = $string_nras.';';
										}
										$string_nras = $string_nras.$value->reference;
									}
									$_SESSION['inscription']['nras'] = $string_nras;

									$asgard_client = new AsgardWSClient();

									//$_SESSION['inscription']['offre'] = $asgard_client->GetOffreDetails($_GET['id_offre']);

									if (isset($_SESSION['params']['promo']) && $_SESSION['params']['promo'] != "") {
										try {
											$_SESSION['promotion'] = $asgard_client->GetPromotion($_SESSION['params']['promo']);

										}
										catch (Exception $e) {
											//$_SESSION['promotion'] = $e;
											$_SESSION['promotion'] = null;
										}
									}
									else{
										$_SESSION['promotion'] = null;
									}
}
?>

 <header class="small">
  	<div class="content">
  		<h1 class="big">
  			</h1>
  	</div>
  </header>

<div class="menu-tunnel">
  <div class="content">
    <ul>
      <li><a onclick="window.location.href='javascript:history.go(-1)';"><span>1</span>Ma formule</a></li>
      <li class="active"><span>2</span>Mes options</li>
      <li><span>3</span>Mes coordonnées</li>
      <li><span>4</span>Validation</li>
    </ul>
  </div>
</div>

<?php
    if(isset($_COOKIE['partner'])) {
        if($_COOKIE['partner'] == 11) {
        ?>
<h3>
	ARIASE</h3>
<?php
        }
        elseif($_COOKIE['partner'] == 15) {
        ?>
<h3>
	DEGROUPTEST</h3>
<?php
        }
    }
?>

<div class="cadre-map" id="conteneur_content_page">
<div class="content">



<?php if (isset($_POST) && isset($_SESSION['params']['id_offre'])) { ?>
<div class="right-price">
<h5><strong>MON OFFRE</strong> <br/>
PERSONNALISéE</h5>

						<?php
						        $equipement_achat_prix = FALSE;
						        $equipement_location_prix = FALSE;
						        foreach ($_SESSION['inscription']['offre']->equipements_disponibles->SEquipement as $key => $value) {
												if ($value->dispo_achat && $value->dispo_location) {
													if ($_SESSION['inscription']['type'] == 1) {
													  $equipement_achat_prix = $value->montant_achat_ttc;
													}
													else {
													  $equipement_achat_prix = $value->montant_achat_ht;
													}
												}
												elseif (!$value->dispo_achat && $value->dispo_location) {
													  if($value->montant_location_ttc > 0) {
														  if ($_SESSION['inscription']['type'] == 1) {
															  $equipement_location_prix = $value->montant_location_ttc;
														  }
														  else {
															  $equipement_location_prix = $value->montant_location_ht;
														  }
													  }
													  else {
														  $equipement_location_prix = 0;
													  }
												} elseif ($value->dispo_achat && !$value->dispo_location) {
												    $equipement_achat_prix = 0;
												} else {
													if($value->montant_location_ttc > 0) {
														if ($_SESSION['inscription']['type'] == 1) {
															$equipement_achat_prix = $value->montant_achat_ttc;
														}
														else {
															$equipement_achat_prix = $value->montant_achat_ht;
														}
													}
													else {
														$equipement_achat_prix = 0;
													}
											  }
											  break ;
											}
											//$equipement_achat_prix = FALSE;
											//$equipement_location_prix = FALSE;

						?>


<div class="content-wrapper">
						<div class="elm-wrapper">
                                                                <label class="ss-titre">Coût mensuel : </label>
								<?php
													if ($_SESSION['inscription']['type'] == 1) {
														$mensuel_prix = $_SESSION['inscription']['offre']->montant_ttc;
														if ($equipement_location_prix !== FALSE) {
														  $mensuel_prix += ($equipement_location_prix + 0);
                            }
														echo '<input type="hidden" id="price-offre-brut" name="price-offre-brut" value="'.$mensuel_prix.'"/><span class="txt-couleur">
														<span id="price-offre-options">'.number_format($mensuel_prix, 2, ',', ' ').'</span>
														&euro;</span> TTC';
													}
													else {
                            $mensuel_prix = $_SESSION['inscription']['offre']->montant_ht;
                            if ($equipement_location_prix !== FALSE) {
                              $mensuel_prix += ($equipement_location_prix + 0);
                            }
														echo '<input type="hidden" id="price-offre-brut" name="price-offre-brut" value="'.$mensuel_prix.'"/><span class="txt-couleur">
														<span id="price-offre-options">'.number_format($mensuel_prix, 2, ',', ' ').'</span>
														&euro;</span> HT';
													}
													 ?><br/>
						</div>
						<div class="elm-wrapper">
								<label class="ss-titre">Frais d'accès + équipements : </label>
								<?php
													if ($_SESSION['inscription']['offre']->fas_ht > 0 || ($equipement_achat_prix !== FALSE && $equipement_achat_prix != 0)) {
														if ($_SESSION['inscription']['type'] == 1) {
														  $acces_prix = ($_SESSION['inscription']['offre']->fas_ttc > 0 ? $_SESSION['inscription']['offre']->fas_ttc : 0) + ($equipement_achat_prix !== FALSE ? $equipement_achat_prix : 0);
														  echo '<input type="hidden" id="price-offre-commande-brut" name="price-offre-commande-brut" value="'.$acces_prix.'"/><span class="txt-couleur">
														  <span id="price-offre-commande-options">'.number_format($acces_prix, 2, ',', ' ').'</span>
														  &euro;</span> TTC';
														}
														else {
														  $acces_prix = ($_SESSION['inscription']['offre']->fas_ht > 0 ? $_SESSION['inscription']['offre']->fas_ht : 0) + ($equipement_achat_prix !== FALSE ? $equipement_achat_prix : 0);
														  echo '<input type="hidden" id="price-offre-commande-brut" name="price-offre-commande-brut" value="'.$acces_prix.'"/><span class="txt-couleur">
														  <span id="price-offre-commande-options">'.number_format($acces_prix, 2, ',', ' ').'</span>
														  &euro;</span> HT';
														}
													}
													else {
														echo "Offerts";
													}
												?><br/>
						</div>








						<div class="elm-wrapper">
								<label class="ss-titre">Mes options : </label>
								<ul style="" id="mon-offre-options">
<?php
									$have_option = FALSE;
									foreach ($_SESSION['inscription']['offre']->options_disponibles->SOption as $key => $value) {
										if ($value->obligatoire == 1) {
									                $have_option = TRUE;
											echo '<li>'.$value-> nom_externe.'</li>';
										}
									}
                                                                    if (!$have_option) {
                                                                           echo '<li>Pas d’options pour le moment</li>';
                                                                    }
?>

								</ul>
						</div>
</div>
</div> <?php /*/offre-right*/
}
?>
<div class="content-wrapper">

<button class="bt-prev" id="btn_retour" onclick="window.location.href='javascript:history.go(-1)';" type="button">Retour</button>

<h3><span>L’OFFRE CHOISIE</span></h3>






	<div class="contenu contenu-map" id="content_offre" style="display: block;">
		<?php
			if (isset($_POST)) {

									//print_r($_SESSION['promotion']);
									if($_SESSION['inscription']['offre'] != null) {


									if (isset($_SESSION['promotion']) && $_SESSION['promotion']!=null) {
										?><script type="text/javascript">
										jQuery(document).ready(function ($) {
											$('#content_offre').css('background', "transparent url('<?=$_SESSION['promotion']->url_image_promo?>') no-repeat right bottom");
										});
										</script>
		<div class="ui-corner-all ui-state-highlight" style="padding: 10px; font-weight: bold; font-size: 130%; text-align: center;">
			<?=$_SESSION['promotion']->description_web;?></div>
		<br />
		<?php
									}
/*
echo '<pre>';
									print_r($_SESSION['inscription']['offre']);
echo '</pre>';
*/
									?>
		<form action="./mes-coordonnees" method="post">
				<h4><span>
					Détail de <strong>l'offre</strong></span></h4>
								<label class="ss-titre">Intitulé : </label>
								<?=$_SESSION['inscription']['offre']->nom_externe ?><br/>



								<label class="ss-titre">Montant : </label></td>
								<?php
													if ($_SESSION['inscription']['type'] == 1) {
														echo "<span class='txt-couleur'>".money_format('%.2n', $_SESSION['inscription']['offre']->montant_ttc)."</span> TTC";
													}
													else {
														echo "<span class='txt-couleur'>".money_format('%.2n', $_SESSION['inscription']['offre']->montant_ht)."</span> HT";
													}
													?><br/>
								<label class="ss-titre">Frais d'accès : </label>
								<?php
													if ($_SESSION['inscription']['offre']->fas_ht > 0) {
														if ($_SESSION['inscription']['type'] == 1) {
															echo "<span class='txt-couleur'>".money_format('%.2n', $_SESSION['inscription']['offre']->fas_ttc)."</span> TTC";
														}
														else {
															echo "<span class='txt-couleur'>".money_format('%.2n', $_SESSION['inscription']['offre']->fas_ht)."</span> HT";
														}
													}
													else {
														echo "Offerts";
													}
												?><br/>
								<label class="ss-titre">Engagement : </label>
								<?php
													if ($_SESSION['inscription']['offre']->engagement > 0) {
														echo $_SESSION['inscription']['offre']->engagement." mois";
													}
													else {
														echo "Aucun";
													}
												?><br/>
								<label class="ss-titre">Services inclus : </label>
									<?php
														foreach ($_SESSION['inscription']['offre']->services_inclus->ServiceWeb as $key => $value) {
															echo "$value->nom_externe + ";
														}
														if ($_SESSION['inscription']['type'] == 1) {
															echo "5 Boites Mail";
														}
														else {
															echo "10 Boites Mail";
														}
                                                                          ?><br/>
<?php
											if (isset($_SESSION['inscription']['offre']->description_web_complementaire) && $_SESSION['inscription']['offre']->description_web_complementaire != '') {
								                              echo '<label class="ss-titre">Plus d\'information : </label>';
								                              echo '<div class="detail-offre">'.nl2br($_SESSION['inscription']['offre']->description_web_complementaire);

															  echo '</div>';
											}
											?>

				<h4><span>
					Pack de <strong>connexion</strong></span></h4>
				<?php
/*
if (QLA) {

											print'<pre>';
												print_r($_SESSION['inscription']['offre']->equipements_disponibles->SEquipement);
											print'</pre>';
}
*/
                      $equipements_js = array();
											foreach ($_SESSION['inscription']['offre']->equipements_disponibles->SEquipement as $key => $value) { ?>

											  <div class="kit-connextion"><label class="ss-titre"><?=$value->nom_externe;?>:</label><br/> <?php
								        $equipements_js[$value->id_equipement] = array(
								            'id_equipement' => $value->id_equipement,
								            'montant_location_ttc' => $value->montant_location_ttc,
								            'montant_location_ht' => $value->montant_location_ht,
								            'montant_achat_ht' => $value->montant_achat_ht,
                            'montant_achat_ttc' => $value->montant_achat_ttc,
                            'nom_externe' => $value->nom_externe,
								        );

												if ($value->dispo_achat && $value->dispo_location) {
													if ($_SESSION['inscription']['type'] == 1) { ?>
														<input checked="checked" name="equipements[]" type="radio" value="achat;<?=$value->id_equipement?>" />
														Achat : <span class="txt-couleur"> <?php  echo money_format('%.2n', $value->montant_achat_ttc); ?> </span>TTC<br />
														<input name="equipements[]" type="radio" value="location;<?=$value->id_equipement?>" />
														Location : <span class="txt-couleur"><?=money_format('%.2n', $value->montant_location_ttc) ?> </span>TTC / mois <?php
													}
													else { ?>
														<input checked="checked" name="equipements[]" type="radio" value="achat;<?=$value->id_equipement?>" />
														Achat : <span class="txt-couleur"> <?php echo money_format('%.2n', $value->montant_achat_ht); ?> </span>HT<br />
														<input name="equipements[]" type="radio" value="location;<?=$value->id_equipement?>" />
														Location : <span class="txt-couleur"><?=money_format('%.2n', $value->montant_location_ht) ?> </span>HT / mois <?php
													}
												}
												elseif (!$value->dispo_achat && $value->dispo_location) { ?>
													  <input checked="checked" name="equipements[]" type="radio" value="location;<?=$value->id_equipement?>" />
													  <?php
													  if($value->montant_location_ttc > 0) {
														  if ($_SESSION['inscription']['type'] == 1) {
															  echo " (location : ".money_format('%.2n', $value->montant_location_ttc)." TTC/mois)";
														  }
														  else {
															  echo " (location : ".money_format('%.2n', $value->montant_location_ht)." HT/mois)";
														  }
													  }
													  else {
														  echo " (Mis à disposition gratuitement)";
													  }
												} elseif ($value->dispo_achat && !$value->dispo_location) {
												    echo '<input name="equipements[]" type="radio" value="achat;'.$value->id_equipement.'" />';
 												    $add_style_web_desc = ';margin-top: -23px;';
												} else {
												?>
													<input checked="checked" name="equipements[]" type="radio" value="achat;<?=$value->id_equipement?>" />
													<?php
													if($value->montant_location_ttc > 0) {
														if ($_SESSION['inscription']['type'] == 1) {
															echo " (achat : ".money_format('%.2n', $value->montant_achat_ttc)." TTC)";
														}
														else {
															echo " (achat : ".money_format('%.2n', $value->montant_achat_ht)." HT)";
														}
													}
													else {
														$add_style_web_desc = ';margin-top: -23px;';
													}
											  }


											  if ($value->description_web_complementaire && $value->description_web_complementaire != '') { ?>
					                                                      <em style=" margin-left: 20px;display: block; <?php print (isset($add_style_web_desc) ? $add_style_web_desc : ''); ?>"><?php echo nl2br($value->description_web_complementaire); ?></em> <?php
											  }
											?></div>
				<?php
										}

										?>
										<script type="text/javascript">
										  var offres_equipements = '<?php echo str_replace('\'', '\\\'', json_encode($equipements_js)); ?>' ;
										</script>


			<?php
										if (count($_SESSION['inscription']['offre']->options_disponibles->SOption) > 0) {
										?>
			<h4><span>
				Options <strong>disponibles</strong></span></h3>
			<?php
										$optionmail=0;
										$optiontv=0;
										$optiontel=0;
/*
echo '<pre>';
print_r($_SESSION['inscription']['offre']->options_disponibles->SOption);
echo '</pre>';
*/
										$options_js = array();
										foreach ($_SESSION['inscription']['offre']->options_disponibles->SOption as $key => $value) {
											if ($value->obligatoire != 1) {
												$options_js[$value->id_option] = array(
													'id_option' => $value->id_option,
													'dependance' => $value->dependance,
													'montant_ht' => $value->montant_ht,
													'montant_ttc' => $value->montant_ttc,
													'nom_externe' => $value->nom_externe,
													'recurrent'  => $value->recurrent,
													'enfants' => array(),
												);

												if (!empty($value->dependance) && isset($options_js[$value->id_option])) {
													$options_js[$value->dependance]['enfants'][] = $value->id_option;
												}
											}

											if($value->categorie == "MAIL" && $optionmail==0){
												$optionmail=1;
												echo '<div class="txt-couleur"><label class="ss-titre">Mail :</label></div> ';
											}

											if($value->categorie == "IPTV" && $optiontv==0){
												$optiontv=1;
												echo '<div class="txt-couleur"><label class="ss-titre">TV :</label></div> ';
											}

											if($value->categorie == "TELEPHONIE" && $optiontel==0){
												$optiontel=1;
												echo '<div class="txt-couleur"><label class="ss-titre">Téléphonie :</label></div> ';
											}
										?>
			<p 3e--="" id="opt_<?=$value->id_option?>" <?php if ($value->dependance > 0) {echo ' style="display:none;"';} ?>> <label class=""> <?php
												if ($value->obligatoire == 1) {
													?><img alt="checked" src="sites/default/files/images/checkbox.png" style="height:15px; position: relative; left: -3px; top: -2px;" /> <input id="options_<?=$value->id_option?>" name="options[]" type="hidden" value="<?=$value->id_option?>" /> <?php
												}
												else {
													?><input id="options_<?=$value->id_option?>" name="options[]" type="checkbox" value="<?=$value->id_option?>" /> <?php
												}

												if ($_SESSION['inscription']['type'] == 1) {
													echo '<span class="option-name">'.$value->nom_externe.' :</span> <span class="option-price">'.money_format('%.2n', $value->montant_ttc).' TTC</span>';
												}
												else {
													echo '<span class="option-name">'.$value->nom_externe.' :</span> <span class="option-price">'.money_format('%.2n', $value->montant_ht)." HT</span>";
												}

												if ($value->recurrent == true) {
													echo ' / mois';
												}

												if ($value->obligatoire == 1) {
													echo " (inclus de base)";
												}

												if ($value->est_parent == 1) {
													echo " (+ options supplémentaires liées)";
												}
												?></label> <?php
											if ($value->description_web_complementaire && $value->description_web_complementaire != '') {
													?><br />
				<em style=" margin-left: 20px;display: block;"><?php echo nl2br($value->description_web_complementaire); ?></em> <?php
												}

											if ($value->montant_fas_ttc > 0) {
												if ($_SESSION['inscription']['type'] == 1) {
													echo "<li>Frais d'accès : ".money_format('%.2n', $value->montant_fas_ttc)." TTC";
												}
												else {
													echo "<li>Frais d'accès : ".money_format('%.2n', $value->montant_fashtc)." HT";
												}
											}
											?></p>
			<ul class="option-list-equipement" id="ept_opt_<?=$value->id_option?>" style="display: none; ">
				<?php
											if (count($value->equipements->SEquipement) > 0) {
												foreach ($value->equipements->SEquipement as $key2 => $value2) {
													echo "<li>Avec l'équipement '$value2->nom_externe'";
													if ($value2->dispo_achat && $value2->dispo_location) {
														if ($_SESSION['inscription']['type'] == 1) {
															?><br />
				<input checked="checked" name="opt_eqpt_reglement[]" type="radio" value="achat;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> Achat : <?=money_format('%.2n', $value2->montant_achat_ttc)?>TTC <input name="opt_eqpt_reglement[]" type="radio" value="location;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> Location : <?=money_format('%.2n', $value2->montant_location_ttc)?>TTC<br />
				<?php
														}
														else {
															//echo " (achat : ".money_format('%.2n', $value2->montant_achat_ht)." HT/ location : ".money_format('%.2n', $value2->montant_location_ht)." HT)</li>";
															?><br />
				<input checked="checked" name="opt_eqpt_reglement[]" type="radio" value="achat;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> Achat : <?=money_format('%.2n', $value2->montant_achat_ht)?>TTC <input name="opt_eqpt_reglement[]" type="radio" value="location;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> Location : <?=money_format('%.2n', $value2->montant_location_ht)?>TTC<br />
				<?php
														}
													}
													elseif(!$value2->dispo_achat && $value2->dispo_location) {
														if($value2->montant_location_ttc > 0) {
															if ($_SESSION['inscription']['type'] == 1) {
																echo " (location : ".money_format('%.2n', $value2->montant_location_ttc )." TTC</li>";
															}
															else {
																echo " (location : ".money_format('%.2n', $value2->montant_location_ht )." HT</li>";
															}
														}
														else {
															echo " (Mis à disposition gratuitement)</li>";
														}
														?><input name="opt_eqpt_reglement[]" type="hidden" value="location;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> <?php
													}
													elseif($value2->dispo_achat && !$value2->dispo_location) {
														//print_r($value2);
														if($value2->montant_location_ttc > 0) {
															if ($_SESSION['inscription']['type'] == 1) {
																echo " (achat : ".money_format('%.2n', $value2->montant_achat_ttc)." TTC)</li>";
															}
															else {
																echo " (achat : ".money_format('%.2n', $value2->montant_achat_ht)." HT)</li>";
															}
														}
														else {
															echo " (Offert)</li>";

														}
														?><input name="opt_eqpt_reglement[]" type="hidden" value="achat;<?=$value->id_option?>;<?=$value2->id_equipement?>" /> <?php
																}
															}
														}
														if ($value2->description_web_complementaire && $value2->description_web_complementaire != '') {
																?><br />
				<span style="position: relative; left:150px; font-size: 80%; font-style: italic;"><?php echo nl2br($value2->description_web_complementaire); ?></span> <?php
															}
													echo "</ul>";

													}
												}
												?>

				<div >
<?php
/*
echo '<pre>';
print_r($options_js);
echo json_encode($options_js);
echo '</pre>';
*/
?>
<script type="text/javascript">
  var offres_options = '<?php echo str_replace('\'', '\\\'', json_encode($options_js)); ?>' ;
</script>

					<!-- <button class="bt-prev" id="btn_retour" onclick="window.location.href='javascript:history.go(-1)';" type="button">Revenir</button>-->
                                        <button class="bt-next" id="btn_submit" name="btn_submit" type="submit">valider <strong>les options</strong></button></div>
				<br />
				<?php if ($_SESSION['params']['id_offre'] == 811 || $_SESSION['params']['id_offre'] == 812 || $_SESSION['params']['id_offre'] == 813) echo "* Offres promotionnelles valables pour toute activation avant le 31/01/2015"; ?><script type="text/javascript">
									jQuery(document).ready(function ($) {

										offres_info_price = jQuery.parseJSON(offres_options);
										equipements_info_price = jQuery.parseJSON(offres_equipements);

										<?php
										foreach ($_SESSION['inscription']['offre']->options_disponibles->SOption as $key => $value) {
											if ($value->obligatoire == 1) {
											?>
											$('#options_<?=$value->id_option;?>').prop('checked', true);
											$('#ept_opt_<?=$value->id_option;?>').show();
											<?php
											}
										}
										?>


										$(function() {
											//$("input:submit, button").button();

											$('input[type="radio"][name="equipements[]"]').change(function() {
												console.log(equipements_info_price);
												// Update Price
												offre_price = $('#price-offre-brut').val();
												commande_price = $('#price-offre-commande-brut').val();

												eq_value = this.value;
												eq_values = eq_value.split(";");
												if (eq_values[0] == 'location') {
													console.log('location');
													equipement_location_price = equipements_info_price[eq_values[1]]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_location_ttc' : 'montant_location_ht'); ?>'];
													if (equipement_location_price == null)
													    equipement_location_price = 0;
													offre_total_price = parseFloat(offre_price) + parseFloat(equipement_location_price);
													equipement_achat_price = equipements_info_price[eq_values[1]]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_achat_ttc' : 'montant_achat_ht'); ?>'];
													if (equipement_achat_price == null)
													    equipement_achat_price = 0;
													offre_total_commande_price = parseFloat(commande_price) - parseFloat(equipement_achat_price);
												}
												else if (eq_values[0] == 'achat') {
													console.log('achat');
													equipement_location_price = equipements_info_price[eq_values[1]]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_location_ttc' : 'montant_location_ht'); ?>'];
													if (equipement_location_price == null)
													    equipement_location_price = 0;
													offre_total_price = parseFloat(offre_price) - parseFloat(equipement_location_price);
													equipement_achat_price = equipements_info_price[eq_values[1]]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_achat_ttc' : 'montant_achat_ht'); ?>'];
													if (equipement_achat_price == null)
													    equipement_achat_price = 0;
													offre_total_commande_price = parseFloat(commande_price) + parseFloat(equipement_achat_price);
												}
												else {
													offre_total_price = parseFloat(offre_price);
													offre_total_commande_price = parseFloat(commande_price);
												}

												console.log(this.value);
												console.log('new offre_total_commande_price', offre_total_commande_price);
												console.log('new offre_total_price', offre_total_price);

												$('#price-offre-brut').val(offre_total_price);
												$('#price-offre-options').text(offre_total_price.toFixed(2).toString().replace('.', ','));
												$('#price-offre-commande-brut').val(offre_total_commande_price);
												$('#price-offre-commande-options').text(offre_total_commande_price.toFixed(2).toString().replace('.', ','));
                      });

											$('input[type="checkbox"][name="options[]"]').change(function() {
												if (this.checked) {
													// Update options
													$("ul#mon-offre-options li:last").append("<li id=\"li-option-" + this.value + "\">" + offres_info_price[this.value]['nom_externe'] + "</li>");
													// Update Price
													offre_price = $('#price-offre-brut').val();
													commande_price = $('#price-offre-commande-brut').val();

													option_price = offres_info_price[this.value]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_ttc' : 'montant_ht'); ?>'];
													//console.log('price option: ' + option_price);
													if (offres_info_price[this.value]['recurrent'] == 1) {
														offre_total_price = parseFloat(offre_price) + parseFloat(option_price);
														$('#price-offre-brut').val(offre_total_price);
														$('#price-offre-options').text(offre_total_price.toFixed(2).toString().replace('.', ','));
													}
													else {
													  offre_total_commande_price = parseFloat(commande_price)  + parseFloat(option_price);
														$('#price-offre-commande-brut').val(offre_total_commande_price);
														$('#price-offre-commande-options').text(offre_total_commande_price.toFixed(2).toString().replace('.', ','));
													}


													// Dependencies
													$('#ept_opt_' + this.value).show();
													<?php
													foreach ($_SESSION['inscription']['offre']->options_disponibles->SOption as $key => $value) {
														?>
														if (this.value == '<?=$value->dependance?>') {
															$('#opt_' + '<?=$value->id_option?>').show();
														}
														<?php
													}
													?>
												} else {
                          $( "ul#mon-offre-options li#li-option-" + this.value ).remove();

													// Update Price
													offre_price = $('#price-offre-brut').val();
													commande_price = $('#price-offre-commande-brut').val();
													option_price = offres_info_price[this.value]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_ttc' : 'montant_ht'); ?>'];

													if (offres_info_price[this.value]['recurrent'] == 1) {
														offre_total_price = parseFloat(offre_price) - parseFloat(option_price);
													}
													else {
										        offre_total_commande_price = parseFloat(commande_price)  - parseFloat(option_price);
													}


													$('#ept_opt_' + this.value).hide();
													<?php
													foreach ($_SESSION['inscription']['offre']->options_disponibles->SOption as $key => $value) {
														?>
														if (this.value == '<?=$value->dependance?>') {
															$('#opt_' + '<?=$value->id_option?>').hide();
															$('#opt_' + '<?=$value->id_option?> input:checked').each(function() {
															    $(this).prop('checked', false);
															    option_price = offres_info_price[<?=$value->id_option?>]['<?php echo ($_SESSION['inscription']['type'] == 1 ? 'montant_ttc' : 'montant_ht'); ?>'];
															    offre_total_price = parseFloat(offre_total_price) - parseFloat(option_price);
															});
														}
														<?php
													}
													?>
													if (offres_info_price[this.value]['recurrent'] == 1) {
													  $('#price-offre-brut').val(offre_total_price);
													  $('#price-offre-options').text(offre_total_price.toFixed(2).toString().replace('.', ','));
													} else {
														$('#price-offre-commande-brut').val(offre_total_commande_price);
														$('#price-offre-commande-options').text(offre_total_commande_price.toFixed(2).toString().replace('.', ','));
														}
												}
											});

										});
									});
									</script><?php
}

}


						?></div>
		</form>
	</div>
	</div>
	</div>
</div>
