var prixUnJour = 110;
var prixForfaitComplet = 350;
var prixForfaitReduit  = 250;
var prixSouperReconnaissance = 85;
var prixSouperDegustation = (iA) ? 1 : 45;

prixUnJour = 125;
prixForfaitComplet = 400;
prixForfaitReduit  = 285;
prixSouperReconnaissance = 85;
prixSouperDegustation = (iA) ? 1 : 45;

$(document).ready(function(){
	calculTotal();
//	alert(iA);
	// administration

	$("div.required label").append("<span> *</span>");

	$("input#paynow").click(function() {
		$("#InscriptionHasConfirmed").val(1);
	});

	$("#tabs").tabs();
	$("#tabs").show();
	$(".autoclear").autoclear();

	$("#InscriptionForfait1Day1, #InscriptionForfait1Day2, #InscriptionForfait1Day3, #InscriptionForfaitComplet, #InscriptionSouperReconnaissance, #InscriptionSouperDegustation, #InscriptionForfaitReduit").change(function() {

		calculTotal();
	});

	$('div[title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				target: 'topRight',
				tooltip: 'bottomLeft'
			}
		},

		style: 'dark' // Give it some style
	});

});

function amountInCent(amount) {
	return amount.toFixed(2);
}


function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function calculTotal() {
	var total = 0;
	var subtotal = 0; 
	var fees = 0; 
	var total = 0; 

	if($("#InscriptionForfait1Day1").val() > 0) { subtotal += $("#InscriptionForfait1Day1").val() * prixUnJour; }
	if($("#InscriptionForfait1Day2").val() > 0) { subtotal += $("#InscriptionForfait1Day2").val() * prixUnJour; }
	if($("#InscriptionForfait1Day3").val() > 0) { subtotal += $("#InscriptionForfait1Day3").val() * prixUnJour; }
	if($("#InscriptionForfaitComplet").val() > 0) { subtotal += $("#InscriptionForfaitComplet").val() * prixForfaitComplet; }
	if($("#InscriptionForfaitReduit").val() > 0) { subtotal += $("#InscriptionForfaitReduit").val() * prixForfaitReduit; }

	if($("#InscriptionSouperReconnaissance").val() > 0) { subtotal += $("#InscriptionSouperReconnaissance").val() * prixSouperReconnaissance; }
	if($("#InscriptionSouperDegustation").val() > 0) { subtotal += $("#InscriptionSouperDegustation").val() * prixSouperDegustation; }


	// sous total
	subtotal = roundNumber(subtotal, 2);
	$("span#subtotal").text(amountInCent(subtotal));

	//  fees
	if(subtotal >= 1 ) {
		fees = (subtotal * 0.029) + 0.3;
	}
	fees = roundNumber(fees, 2);

	$("span#trxfees").text(amountInCent(fees));
	total = subtotal + fees;

	$("span#montant_total").text(amountInCent(total));
	//alert(total);
	$("#InscriptionTotalamount").val(total); // champs caché pour le post du formulaire

//	alert($("#InscriptionForfait1Day1").val());
}



