function calculer(a,p){
var f=0;
var b = 0;
var d = '<table id="content"><tr><td id="ctl"></td><td id="ctm-payer2"></td><td id="ctr"></td></tr><tr><td id="cml"></td><td id="cmm"><div align="center"><h1>CALCUL</h1><table id="calcul"><tr><th width="70%" class="cl">Facture #</th><th width="30%" class="cr">Montant $</th></tr>';
var listfact='';
for (i=1;i<=a;i++){
	if(i!=2 && !isNaN(document.getElementById('paiement'+i).value) && document.getElementById('paiement'+i).value!=''){
var c = Number(document.getElementById('paiement'+i).value+'.'+document.getElementById('paiementdec'+i).value);
b = (b + c);
d = d+'<tr><td width="70%" class="cl">'+document.getElementById('nofacture'+i).value+'</td><td width="30%" class="cr">'+c.toFixed(2)+'</td></tr>';
listfact = listfact+','+document.getElementById('nofacture'+i).value
	}
}
if (p=='fact'){
var soustotal = b;
var tps = b*0.05;
var tvq = (b+tps)*0.075;
var total = b+tps+tvq;
d = d+'<tr><th width="70%" class="cl">Sous total</th><th width="30%" class="cr">'+b.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">TPS 5%</th><th width="30%" class="cr">+ '+tps.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">TVQ 7,5%</th><th width="30%" class="cr">+ '+tvq.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">Total</th><th width="30%" class="cr">'+total.toFixed(2)+'</th></tr>';
}
if (p=='carte'){
var tps = b*0.05;
var soustotal = b;
var tvq = (b+tps)*0.075;
var total = b+tps+tvq;
d = d+'<tr><th width="70%" class="cl">Sous total</th><th width="30%" class="cr">'+b.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">TPS 5%</th><th width="30%" class="cr">+ '+tps.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">TVQ 7,5%</th><th width="30%" class="cr">+ '+tvq.toFixed(2)+'</th></tr>';
d = d+'<tr><th width="70%" class="cl">Total</th><th width="30%" class="cr">'+total.toFixed(2)+'</th></tr>';
document.getElementById('custom').value=document.forms[f].elements['username1'].value+'&'+document.forms[f].elements['pwd1'].value+'&'+document.forms[f].elements['entreprise1'].value+'&'+document.forms[f].elements['find'].value+'.'+document.forms[f].elements['freg'].value+'.'+document.forms[f].elements['ftel'].value;
}
d= d+'</table><br><p><p>Cliquez sur "<strong>Fermer la fenêtre" pour annuler</strong> le paiement.</p></p><p>Cliquez sur le bouton "<strong>Payer</strong>" pour être redirigé vers le site de paiement sécurisé de PayPal et <strong>terminer le paiement</strong>.</p><input type="image" src="images/payer-en-ligne/payer.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypal.com/fr_XC/i/scr/pixel.gif" width="1" height="1"></div><br></td><td id="cmr"></td></tr><tr><td id="cbl"></td><td id="cbm"></td><td id="cbr"></td></tr></table>';
document.getElementById('address1').value=document.forms[f].elements['adresse1'].value;
document.getElementById('city').value=document.forms[f].elements['ville1'].value;
document.getElementById('first_name').value=document.forms[f].elements['prenom1'].value;
document.getElementById('last_name').value=document.forms[f].elements['nom1'].value;
document.getElementById('night_phone_a').value=document.forms[f].elements['ind1'].value;
document.getElementById('night_phone_b').value=document.forms[f].elements['reg1'].value;
document.getElementById('night_phone_c').value=document.forms[f].elements['tel1'].value;
document.getElementById('zip').value=document.forms[f].elements['cp1'].value;
document.getElementById('email').value=document.forms[f].elements['mail1'].value;
document.getElementById('fact').value=listfact;
document.getElementById('total').value=soustotal.toFixed(2);
display_erreur('erreur', 'payer', d);
}