﻿function showMenu(m) {
	document.getElementById("menu_"+m).style.display = "block";
}

function hideMenu(m) {
	document.getElementById("menu_"+m).style.display = "none";
}

function clear_autre() {
	document.forms["donform"]["autre_montant"].value = "";
	updateReduction();
}

function clear_montant() {
	for(i=0;i<document.forms["donform"]["montant"].length-1;i++) document.forms["donform"]["montant"][i].checked = false;
	document.forms["donform"]["montant"][document.forms["donform"]["montant"].length-1].checked = true
}

function updateReduction() {
	var amount, reduction;
	amount = document.forms["donform"]["autre_montant"].value;
	for(i=0;i<document.forms["donform"]["montant"].length-1;i++) if (document.forms["donform"]["montant"][i].checked) amount = document.forms["donform"]["montant"][i].value;
	if (isNaN(amount)) amount = 0;
	reduction = parseInt(amount)*66/100;
	if (isNaN(reduction)) reduction = 0;
//	document.getElementById("info_montant").innerHTML = amount;
	document.getElementById("reduction").innerHTML = "Vous pourrez ainsi déduire "+reduction+" euros de ce don.";
}

function isDecimal(str) {
	return /^\d+(\,\d+)?$|^\,\d+$/.test(str);
}

function checkemail(n) {
	f = document.forms[n];
	if (f['email'] && f['email'].value=="") {
		alert("Vous devez saisir votre email.");
		return false;
	}
	if (f['email'] && f['email'].value &&
	!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(f['email'].value)) {
		alert("L'adresse email est incorrecte.");
		return false;
	}
}

function checkform_don() {
	f = document.forms["donform"];
	var Af = new Array();
	var r = false;
	if (f["montant"] && (!f['boutique'] && !f['edm'])) {
		for(i=0;i<f["montant"].length && !r;i++) if (f["montant"][i].checked) r = true;
		if (f["autre_montant"].value!='') r = true;
		if (!r) {
			alert("Vous n'avez pas sélectionné de montant.");
			return false;
		}
	}
	if (f["autre_montant"] && f["autre_montant"].value && !isDecimal(f["autre_montant"].value)) {
		alert("Le montant n'est pas numérique.");
		return false;
	}
/*	if (f["autre_montant"] && f["autre_montant"].value && parseInt(f["autre_montant"].value)*100<1200) {
		alert("En raison des coûts de traitements de votre don, nous vous remercions de bien vouloir saisir un montant supérieur à 12 euros. Merci de votre compréhension.");
		return false;
	}*/
	if (f["autre_montant"] && f["autre_montant"].value && parseInt(f["autre_montant"].value)*100<=0) {
		alert("Le montant ne peux pas être inférieur ou égal à 0.");
		return false;
	}

	if (f["qt_messe"]) {
		if (f["qt_messe"].value=="" && f["qt_neuvaine"].value=="" && f["qt_gregorien"].value=="") {
			alert("Merci de renseigner votre soutien : Messe, Neuvaine ou Trentain Grégorien.");
			return false;
		}
	}
	
	if (!f["civilite"][0].checked && !f["civilite"][1].checked &&
		!f["civilite"][2].checked) Af[Af.length] = "civilité";
	if (!f["nom"].value) Af[Af.length] = "nom";
	if (!f["prenom"].value) Af[Af.length] = "prénom";
	if (!f["email"].value) Af[Af.length] = "e-mail";
	if (!f["confirm_email"].value) Af[Af.length] = "confirmation e-mail";
	if (!f["adresse"].value) Af[Af.length] = "adresse";
	if (!f["cp"].value) Af[Af.length] = "code postal";
	if (!f["ville"].value) Af[Af.length] = "ville";
	
	if (f['email'] && f['email'].value &&
	!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(f['email'].value)) {
		alert("L'adresse email est incorrecte.");
		return false;
	}
	
	if (f["email"].value!=f["confirm_email"].value) {
		alert("La confirmation de votre email est incorrecte.");
		return false;
	}

	
	if (Af.length==0) {
		return true;
	} else {
		if (Af.length==1) p = "Le champ suivant est obligatoire : ";
		if (Af.length>1) p = "Les champs suivants sont obligatoires : ";
		fields = Af.join(", ");
		alert(p+fields+".");
		return false;
	}
	
}

function validationNombre(obj) {
        with (obj) {
                if (isNaN(obj.value)) {
            alert("Votre saisie n'est pas valide ! Vous devez taper un nombre.");
                        obj.value='';
            obj.focus();
            return false;
                }
        }
}

function inc(script_filename) {
	var html_doc = document.getElementsByTagName('head').item(0);
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', script_filename);
	html_doc.appendChild(js);
	return false;
}

function updatedoncomplementaire() {
inc('/nous-aider/boutique/mon-panier/updatedoncomplementaire.php?doncomplementaire='+document.forms.doncomplementaireform.doncomplementaire.value);
}


jQuery.noConflict();
/* base url */
var base_url = "http://www.aed-france.org";
var WPSC_URL = "http://www.aed-france.org/wp-content/plugins/wp-ma-e-boutique";

/* LightBox Configuration start*/
var fileLoadingImage = "http://www.aed-france.org/wp-content/plugins/wp-ma-e-boutique/images/loading.gif";    
var fileBottomNavCloseImage = "http://www.aed-france.org/wp-content/plugins/wp-ma-e-boutique/images/closelabel.gif";
var fileThickboxLoadingImage = "http://www.aed-france.org/wp-content/plugins/wp-ma-e-boutique/images/loadingAnimation.gif";    
var resizeSpeed = 9;  // controls the speed of the image resizing (1=slowest and 10=fastest)
var borderSize = 10;  //if you adjust the padding in the CSS, you will need to update this variable
jQuery(document).ready( function() {
  });