<div id="center">
<h1>COMMANDES DE PI&Eacute;CES</h1>
<div class="paragraph">
<table class="identite">
  <tr>
    <td width="30">&nbsp;</td>
    <td width="200" class="StyleInfoLib">
      Num&eacute;ro identifiant Siren
    </td>
    <td width="350" class="StyleInfoData">
      <?=$this->SirenTexte($this->siren)?>
    </td>
  </tr>
  <tr>
    <td width="30">&nbsp;</td>
    <td width="200" class="StyleInfoLib">Raison Sociale</td>
    <td width="350" class="StyleInfoData"><?=$this->raisonSociale?></td>
  </tr>
</table>
</div>

<h2>Extrait R.C.S</h2>
<div class="paragraph">
<?php
if(empty($this->message))
{
?>
<div id="result"><div id="progressbar"></div></div>
<script type="text/javascript">
var start = <?=$this->start?>;
var siren = <?=$this->siren?>;
var message = 'Le temps maximum d&quot;attente a été atteint. Merci de réssayez en cliquant <a href="<?=$this->url(array('controller'=>'pieces', 'action'=>'kbis', 'start'=>$start+1))?>">ici</a><br/>ou faire la demande pour recevoir le kbis par mail <input type="checkbox" name="sendmail" value="1"/>';

var pct = 0;
var prec = 0;
var checkInterval = 10;
var url = '';
	
function checkKbis(start)
{
	if(start>=1){
		$.post( '<?=$this->url(array('controller'=>'pieces', 'action'=>'kbis'))?>', 
			{ start: start, siret: siren },
			function (data, textStatus) { url = data; }
		);
	}else{
		$.post( '<?=$this->url(array('controller'=>'pieces', 'action'=>'kbis'))?>', 
			{ start: 0, url: url, siret: siren },
			function (data, textStatus) { 
				if( data!='' && data!='FALSE' ){ updateKbisInfo(data); } 
			}
		);
	}
}

function updateKbis(){
	$('#progressbar').reportprogress(++pct);
	if(pct==100){
		updateKbisInfo(message);
		pct=0;
	}
	if( Math.floor(pct/checkInterval)!=prec || pct==1 ){
		prec = Math.floor(pct/checkInterval);
		checkKbis(false);
	}
}

function updateKbisInfo(html){
	$('#result').html(html);
	clearInterval(holdTheInterval);
}

$(document).ready(function(){
	$('input[type=checkbox][name=sendmail]').on('click', function(){
		if($(this).prop('checked')){
			$('#formMail').css('display', 'block');
		}else{
			$('#formMail').css('display', 'none');
		}
	});

	 $('form[name=mailkbis]').submit(function(){
		var eMail = $('input[name=mail]').val();
		if(!checkEmail(eMail)){
			alert('Veuillez saisir une adresse email.');
			return false;
		} else { return true; }
	});	
});

checkKbis(start);
var holdTheInterval = setInterval(updateKbis, 1800);
$('#progressbar').reportprogress(0);
</script>
<div id="formMail" style="display:none">
<form name="mailkbis" method="post" action="<?=$this->url(array('controller'=>'pieces', 'action'=>'kbis', 'siret'=>$this->siren))?>">
<input type="hidden" name="op" value="mailkbis"/>
<label>Votre Email : </label>
<input type="text" name="mail" value="<?=$this->email?>"/>
<input type="submit" name="mailkbis" value="Ok"/>
</form>
</div>
<?php } else { ?>
<?=$this->message?>	
<?php }?>
</div>

</div>