function checkFormAbonnement(){
	if (document.getElementById('duree').value == ''){
		alert('La durÃªe doit Ãªtre renseignÃ©e');
		return(false);
	}
	if (document.getElementById('nombre').value == ''){
		alert('Le nombre d\'abonnements doit Ãªtre renseignÃ©');
		return(false);
	}
	if (document.getElementById('date_debut').value == ''){
		alert('');
		return(false);
	}
	if (document.getElementById('nom_facturation').value == ''){
		alert('Le nom doit Ãªtre renseignÃ©');
		return(false);
	}
	if (document.getElementById('prenom_facturation').value == ''){
		alert('Le prÃªnom doit Ãªtre renseignÃ©');
		return(false);
	}
	if (document.getElementById('adresse1_facturation').value == ''){
		alert('L\'adresse doit Ãªtre renseignÃ©e');
		return(false);
	}
	if (document.getElementById('codepostal_facturation').value == ''){
		alert('Le code postal doit Ãªtre renseignÃ©');
		return(false);
	}
	if (document.getElementById('ville_facturation').value == ''){
		alert('La ville doit Ãªtre renseignÃ©');
		return(false);
	}
	if (document.getElementById('pays_facturation').value == ''){
		alert('Le pays doit Ãªtre renseignÃ©');
		return(false);
	}

	if (document.getElementById('oui').checked){
		if (document.getElementById('nom_livraison').value == ''){
			alert('Le nom doit Ãªtre renseignÃ©');
			return(false);
		}
		if (document.getElementById('prenom_livraison').value == ''){
			alert('Le prÃªnom doit Ãªtre renseignÃ©');
			return(false);
		}
		if (document.getElementById('adresse1_livraison').value == ''){
			alert('L\'adresse doit Ãªtre renseignÃ©e');
			return(false);
		}
		if (document.getElementById('codepostal_livraison').value == ''){
			alert('Le code postal doit Ãªtre renseignÃ©');
			return(false);
		}
		if (document.getElementById('ville_livraison').value == ''){
			alert('La ville doit Ãªtre renseignÃ©');
			return(false);
		}
		if (document.getElementById('pays_livraison').value == ''){
			alert('Le pays doit Ãªtre renseignÃ©');
			return(false);
		}
	}

	return(true);
}

function showTarifsDegressifs(){
	if (document.getElementById('nombre').value > 1){
		document.getElementById('tarifsdegressifs').style.display = 'block';
	}
	else{
		document.getElementById('tarifsdegressifs').style.display = 'none';
	}
}

function checkCodeParrain(){
	if ($("#code_parrain").attr('value') != ''){
	     uri = $("#uri_parrain").attr('value')+'?code='+$("#code_parrain").attr('value');

	     $.get(uri ,  '', function(data) {
			if(data == '')
				document.getElementById('verifCodeParrain').innerHTML = 'Code inconnu';
			else
				document.getElementById('verifCodeParrain').innerHTML = data;
	     });
	}
	else{
		alert('Veuillez entrer un code valide');
	}
 }


 function checkCodePromo(){
	if ($("#code_promo").attr('value') != ''){
	     uri = $("#uri_promo").attr('value')+'?code='+$("#code_promo").attr('value');

	     $.get(uri ,  '', function(data) {
			switch(data){
				case '0':
					document.getElementById('verifCodePromo').innerHTML = 'Code inconnu';
				break;
				case '1':
					document.getElementById('verifCodePromo').innerHTML = 'Code promo valide';
				break;

				default:
					alert(data);
				break;
			}
	     });
	}
	else{
		alert('Veuillez entrer un code valide');
	}
 }

 function checkPrix(){
     uri = $("#uri_prix").attr('value')+'?type='+$("#formule").attr('value')+'&duree='+$("#duree").attr('value')+'&nombre='+$("#nombre").attr('value')+'&code='+$("#code_promo").attr('value');

     $.get(uri ,  '', function(data) {
		$("#calcul_prix").empty();
        $("#calcul_prix").append(data);
     });
 }

function selectChoix(id){
	$ok='web';


	if ($('#choix_'+id).attr('value') == $ok){
		//$('#quantite_'+id).attr('disabled', "disabled");
		$('#quantite_'+id).empty();
		for (var i=0; i<=1; i++){
			$('#quantite_'+id).append('<option value="'+i+'">'+i+'</option>');
		}
	}
	else{
		$('#quantite_'+id).empty();
		for (var i=0; i<=30; i++){
			$('#quantite_'+id).append('<option value="'+i+'">'+i+'</option>');
		}
	}
	totalCommande();

}
function totalCommande(){
	var nb_papier = 0;
	var nb_web = 0;
	var nb_mixte = 0;


	for(var i=0; i<nids.length; i++){

		switch($('#choix_'+nids[i]).attr('value')){
			case 'papier': nb_papier= parseInt($('#quantite_'+nids[i]).attr('value')) + parseInt(nb_papier);break;

			case 'web': nb_web= parseInt($('#quantite_'+nids[i]).attr('value')) + parseInt(nb_web);break;

			case 'mixte':nb_mixte= parseInt($('#quantite_'+nids[i]).attr('value')) + parseInt(nb_mixte);break;
		}


	}
	$('#nb_papier').empty();
	$('#nb_papier').append(nb_papier.toString());
	$('#nb_web').empty();
	$('#nb_web').append(nb_web.toString());
	$('#nb_mixte').empty();
	$('#nb_mixte').append(nb_mixte.toString());

	var total_papier = nb_papier * tarifs['P'];
	var total_web = nb_web * tarifs['W'];
	var total_mixte = nb_mixte * tarifs['M'];
	var total_commande= (parseInt(total_papier*100) + parseInt(total_web*100) + parseInt(total_mixte*100))/100;

	$('#total_papier').empty();
	$('#total_papier').append(total_papier.toString());
	$('#total_web').empty();
	$('#total_web').append(total_web.toString());
	$('#total_mixte').empty();
	$('#total_mixte').append(total_mixte.toString());

	$('#cout_papier').empty();
	$('#cout_papier').append(tarifs['P']);
	$('#cout_web').empty();
	$('#cout_web').append(tarifs['W']);
	$('#cout_mixte').empty();
	$('#cout_mixte').append(tarifs['M']);

	$('#total_commande').empty();
	$('#total_commande').append(total_commande.toString());
	document.getElementById('total').value=total_commande;

	if (nb_papier == 0 && nb_mixte == 0){
		$('#adresse_test').css('display', 'none');
	}
	else{
		$('#adresse_test').css('display', 'block');
	}
}



function radio(valeur){
if(valeur=="oui"){
document.getElementById('non').checked	="";
document.getElementById('nom_livraison').value="";
document.getElementById('prenom_livraison').value="";
document.getElementById('ville_livraison').value="";
document.getElementById('add1_livraison').value="";
document.getElementById('add2_livraison').value="";
document.getElementById('cp_livraison').value="";
document.getElementById('pays_livraison').value=1;
}
if(valeur=="non"){
document.getElementById('oui').checked	="";
document.getElementById('nom_livraison').value=document.getElementById('nom_facturation').value;
document.getElementById('prenom_livraison').value=document.getElementById('prenom_facturation').value;
document.getElementById('ville_livraison').value=document.getElementById('ville_facturation').value;
document.getElementById('add1_livraison').value=document.getElementById('add1_facturation').value;
document.getElementById('add2_livraison').value=document.getElementById('add2_facturation').value;
document.getElementById('cp_livraison').value=document.getElementById('cp_facturation').value;
document.getElementById('pays_livraison').value=document.getElementById('pays_facturation').value;
}
}

function radio2(valeur){
if(valeur=="oui"){
document.getElementById('non2').checked	="";
}
if(valeur=="non"){
document.getElementById('oui2').checked	="";
}
}
function radioabo(valeur){
if(valeur=="oui"){
document.getElementById('non').checked	="";
document.getElementById('nom_livraison').value="";
document.getElementById('prenom_livraison').value="";
document.getElementById('ville_livraison').value="";
document.getElementById('adresse1_livraison').value="";
document.getElementById('adresse2_livraison').value="";
document.getElementById('codepostal_livraison').value="";
document.getElementById('pays_livraison').value=1;
}
if(valeur=="non"){
document.getElementById('oui').checked	="";
document.getElementById('nom_livraison').value=document.getElementById('nom_facturation').value;
document.getElementById('prenom_livraison').value=document.getElementById('prenom_facturation').value;
document.getElementById('ville_livraison').value=document.getElementById('ville_facturation').value;
document.getElementById('adresse1_livraison').value=document.getElementById('adresse1_facturation').value;
document.getElementById('adresse2_livraison').value=document.getElementById('adresse2_facturation').value;
document.getElementById('codepostal_livraison').value=document.getElementById('codepostal_facturation').value;
document.getElementById('pays_livraison').value=document.getElementById('pays_facturation').value;
}
}



function checknumform_facturation(obj){
if(obj.value=="" ){
		obj.value="Ce champ est obligatoire!";
		}


}
/*****************************efface la value par defaut*********************************************/
function efface_mess(mot)
{
	if(mot.value=="Ce champ est obligatoire!")
mot.value='';
return mot.value;
}




function validform_num(){
	valide=true;
	if(document.getElementById('total').value==0){
		alert("Votre commande est vide");
	valide=false;
	}
	else{
		if(document.getElementById('nom_facturation').value=="" ||document.getElementById('prenom_facturation').value=="" ||document.getElementById('add1_facturation').value==""||document.getElementById('ville_facturation').value==""||document.getElementById('cp_facturation').value==""||document.getElementById('pays_facturation').value=="" ){
valide=false;
		}


					if(document.getElementById('nom_livraison').value=="" ||document.getElementById('prenom_livraison').value=="" ||document.getElementById('add1_livraison').value==""||document.getElementById('ville_livraison').value==""||document.getElementById('cp_livraison').value==""||document.getElementById('pays_livraison').value=="" ){
valide=false;
		}
		if(valide==false){
	alert("Veuillez vÃ©rifier l'exactitude de vos saisies.Un champ obligatoire n'a pas Ã©tÃ© renseignÃ©.");
	}

	}

	return valide;
}
/****************************verifie qu'un moyen de paiement a ete selectionnÃ©*********************************************/
function confirmpaiement(){
	valide=true;
	if((document.getElementById('moyen_paiement1').checked==false)&& (document.getElementById('moyen_paiement2').checked==false) &&(document.getElementById('moyen_paiement3').checked==false)){
	valide=false;
	alert("Merci de renseigner votre moyen de paiement.");
	}

 return valide;
}

/*****************************choix de l action*********************************************/

function actionForm()
{
	// Vérifie si les CGV sont cochées
	if ($('#cgv').is(":checked")) {
		if ((document.getElementById('moyen_paiement1').checked == true)) {
			document.getElementById('form_cic').submit();
		}
		else if ((document.getElementById('moyen_paiement2').checked == true)) {
			document.recap_num.action = "https://www.paypal.com/cgi-bin/webscr";
			document.recap_num.submit();
		}
		else if ((document.getElementById('moyen_paiement3').checked == true)) {
			document.recap_num.action = "redirect_paiement";
			document.recap_num.submit();
		}
	}
	else {
		alert('Veuillez cocher les Conditions GÃ©nÃ©rales de Vente');
	}
}
