
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var popupImage;
function ImageMax(chemin)
   {
   if ((popupImage) && (!popupImage.closed)){
	popupImage.close();
   }

   i1 = new Image;
   i1.src = chemin;

   html = '<html><head><title>Zoom sur image</title></head><body leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0"><table border="0" CELLPADDING=0 CELLSPACING=0 width="100%" height="100%"><tr><td background="images/anim_charg.gif"><IMG src="'+chemin+'" BORDER=0 NAME=ImageMax onLoad="window.resizeTo(document.ImageMax.width+10,document.ImageMax.height+50)"></td></tr></table></body></html>';
   popupImage = window.open('','popupImage','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=no,resizable=no, width=0, height=0, top=50, left=100, minimize=no, maximize=no');
   popupImage.document.open();
   popupImage.document.write(html);
   popupImage.document.close();
}
/**
 *
 * @access public
 * @return void
 **/
function verif_email(){
    if (document.form_newsletter.email.value == '') {
		alert("Veuillez bien remplir l'email.");
		document.form_newsletter.email.focus();
		return false;
	}
	var email   = document.form_newsletter.email.value;
    var verif   = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
    if (verif.exec(email) == null){
       	alert("Votre email est incorrect.");
        document.form_newsletter.email.focus();
		return false;
    }
	return;
}
function validCgv(){
	if(document.form_conditions.valid_cgv.checked==false){
		alert("Vous devez accepter les Conditions Générales de Vente");
		return false;
	}
  }
function pass_perdu(){
	myWindow = window.open("modules/boutique/pass_perdu_accueil.php", "Preview", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=340,height=170,left=100,top=100");
}

function comparatif_tailles(){
	myWindow = window.open("modules/boutique/conversion_de_taille.php", "Preview", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width=590,height=500,left=100,top=50");
}
var form;
var quantite;
var id;
var num;


function inscription_test(action)
	{
	var paysEurope = document.inscription.paysEurope.value;
	var arrayEurope = paysEurope.split(';');
	var europeen = false;

	for(i = 0; i < arrayEurope.length; i++) {
		if (arrayEurope[i]==document.inscription.pays.options[document.inscription.pays.selectedIndex].value){
			europeen = true;
			break;
		}
	}
	if (document.inscription.societe.value != '' && document.inscription.tvaintracom.value == '' && europeen) {
		alert("Si vous êtes une société européenne, veuillez renseigner votre n° Intracommunautaire !");
		document.inscription.societe.focus();
		return false;
		}
	if (document.inscription.nom.value == '') {
		alert("Veuillez bien remplir le nom !");
		document.inscription.nom.focus();
		return false;
		}
	if (document.inscription.prenom.value == '') {
		alert("Veuillez bien remplir le champs Prénom !");
		document.inscription.prenom.focus();
		return false;
		}
	if (document.inscription.email.value == '') {
		alert("Veuillez bien remplir l'email.");
		document.inscription.email.focus();
		return false;
	}
	var email   = document.inscription.email.value;
    var verif   = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
    if (verif.exec(email) == null){
       	alert("Votre email est incorrect.");
        document.inscription.email.focus();
		return false;
    }
	if (document.inscription.adresse.value == '') {
		alert("Veuillez bien remplir l'adresse !");
		document.inscription.adresse.focus();
		return false;
		}
	if (document.inscription.ville.value == '') {
		alert("Veuillez bien remplir la Ville !");
		document.inscription.ville.focus();
		return false;
		}
	if (document.inscription.tel.value == '') {
		alert("Veuillez bien remplir le t\351l\351phone !");
		document.inscription.tel.focus();
		return false;
		}

	if(action=='insert'){
		if (document.inscription.pass.value.length < 6) {
			alert("Votre mot de passe doit contenir au moins 6 caractères !");
			document.inscription.pass.value='';
			document.inscription.pass2.value='';
			document.inscription.pass.focus();
			return false;
			}
		if (document.inscription.pass2.value != document.inscription.pass.value) {
			alert("La confirmation du Mot de passe ne convient pas !");
			document.inscription.pass.value = '';
			document.inscription.pass2.value = '';
			document.inscription.pass.focus();
			return false;
			}
	}
	return;
}


function panier_action(action){

	if(action=='update'){
		var test = confirm("Etes vous sur de vouloir modifier la quantité des produits ?");
		if(test==true){
			document.panier_produits.choix_action.value=action;
			document.panier_produits.submit();
		}
	}
    if(action=='apercu'){

		document.getElementById('tab_apercu').style.display = 'block';
		document.panier_produits.choix_action.value=action;
		document.panier_produits.action="modules/boutique/include/genere_apercu_liste_cadeaux.php";
		document.panier_produits.target="genere_apercu_liste_cadeaux";
		document.panier_produits.submit();

	}

	if(action=='delete'){
		
		var nb_checkbox = document.panier_produits.elements.length;
		var testSupp=false;
		for (i=0; i<nb_checkbox; i++){
			if (document.panier_produits.elements[i].type == 'checkbox' && document.panier_produits.elements[i].checked == true){
				testSupp=true;
				break;
			}
		}

		if(testSupp==false){
			alert("Vous devez cocher les Produits à supprimer");
		}else{
			var test = confirm("Etes vous sur de vouloir supprimer les produits sélectionnés ?");
			if(test==true){
				document.panier_produits.choix_action.value=action;
				document.panier_produits.submit();
			}
		}
	}

	

	if(action=='enreg_liste'){
		if (document.getElementById("nom_liste").value == ''){
			alert('Veuillez fournir un nom à votre liste de naissance.');
			document.getElementById("nom_liste").focus();
			return false;
		}
		if (!document.getElementsByName('groupage')[0].checked && !document.getElementsByName('groupage')[1].checked)
		{
			alert('Veuillez faire un choix pour le groupage.');
			return false;
		}
		var test = confirm("Enregistrer et envoyer votre liste de naissance à votre entourage ?");
        if(test==true){
            document.panier_produits.action="index.fr.php?page=include/gestion_panier_cadeaux&choix_action=enreg_liste";
            document.panier_produits.target="";
			document.panier_produits.choix_action.value=action;
			document.panier_produits.submit();
		}
	}
	if(action=='envoi_liste'){
		var test = confirm("Envoyer votre liste de naissance à votre entourage ?");
        if(test==true)
		{
            document.panier_produits.action="index.fr.php?page=include/gestion_panier_cadeaux&choix_action=envoi_liste";
            document.panier_produits.target="";
			document.panier_produits.choix_action.value=action;
			document.panier_produits.submit();
		}
	}
	
	if(action=='modif_liste'){
	
		if (document.panier_produits.nom_liste.value == ''){
			alert('Veuillez fournir un nom à votre liste de naissance.');
			document.panier_produits.nom_liste.focus();
			
			return false;
		}
		if (!document.getElementsByName('groupage')[0].checked && !document.getElementsByName('groupage')[1].checked)
		{
			alert('Veuillez faire un choix pour le groupage.');
			return false;
		}
		
		var test = confirm("Modifier votre liste de naissance ?");
		if(test==true){
			document.panier_produits.target = '';
			document.panier_produits.action = 'index.fr.php?page=include/gestion_panier_cadeaux&mod=boutique';
			document.panier_produits.choix_action.value=action;
			document.panier_produits.submit();
		}
	}

}

function focus_texte(texte, base, input){
	if (texte == base)
	{
		input.value = '';
	}
}

function debloque_options(id_prod, limite_stock){
	for (i=0; i<10; i++)
	{
		if (document.getElementById('option_' + id_prod + '_' + i)){
			document.getElementById('option_' + id_prod + '_' + i).disabled = false;
		}
		if (document.getElementById('option_' + id_prod + '_' + i)){
			if (document.getElementById('option_' + id_prod + '_' + i).type == "select-one"){
				if (document.getElementById('option_' + id_prod + '_' + i).selectedIndex == 0){
					alert("Options incomplètes: " + document.getElementById('option_' + id_prod + '_' + i).options[document.getElementById('option_' + id_prod + '_' + i).selectedIndex].text);
					return false;
				}
			}
		}
	}
	
	// On a pas retourné false et on est en mode "je commande pas plus de stock que ce qu'il y a"
	if (limite_stock == 1)
	{
		var s = parseInt(document.getElementsByName('stock')[0].value);
		var qte = parseInt(document.getElementsByName('qte')[0].value);

		if (qte > s)
		{
			alert('Il ne reste que '+s+' produit(s) en stock, veuillez diminuer la quantité souhaitée.');
			return false;
		}
	}
}

// Saisie temps réel, rempli un élément HTML avec le contenu d'un champ spécifié (à mettre sur le onkeyup)
function saisieTempsReel(id_champ, id_element)
{
	var val = document.getElementById(id_champ).value;
	if (val != "")
	{
		// On va remplacer les \n par des <br/>
		var tmp = val.split("\n");
		var val_clean = tmp.join("<br/>");
		document.getElementById(id_element).innerHTML = val_clean;
	} else {
		document.getElementById(id_element).innerHTML = "&nbsp;";	
	}
}

function add_email(id_liste)
{
	var email = document.getElementsByName('txt_ajout')[0].value;
	
	var verif   = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
    if (verif.exec(email) == null)
	{
       	alert("Votre email est incorrect.");
        document.contact.email.focus();
		return false;
    }else{
		document.getElementsByName('txt_ajout')[0].value = "";
		// Ajout dans la base de données en ajax
		http.open('GET', 'modules/boutique/include/ajax_gestion_contacts.php?op=add&id_liste='+id_liste+'&email='+email);
		http.onreadystatechange = do_add_email;
		http.send(null);
	}
}
function do_add_email()
{
	var tbody = document.getElementById('liste_email');
    if(http.readyState == 4)
	{
		var response = http.responseText;
		tbody.innerHTML = tbody.innerHTML + response;
	}
}

// Suppression d'un email dans la liste de contacts
function delete_email(id_contact)
{
	var noeud = document.getElementById('tr_mail_'+id_contact);
	document.getElementById('liste_email').removeChild(noeud);
	
	// Suppression dans la base de données en ajax
	http.open('GET', 'modules/boutique/include/ajax_gestion_contacts.php?op=del&id_contact='+id_contact);
    http.send(null);
}
function checked_email(id_contact)
{
	var chk = 0;
	if (document.getElementsByName('chk_mail_'+id_contact)[0].checked)
	{
		chk = 1;
	}
	http.open('GET', 'modules/boutique/include/ajax_gestion_contacts.php?op=chk&id_contact='+id_contact+'&chk='+chk);
    http.send(null);
}

function addFav() 
{ 
	if (document.all){ 
		window.external.AddFavorite(location.href, document.title); 
	}else{ 
		alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.') 
	} 
}

// Ouverture de la jolie bulle
function openBulle(id_div)
{
	var d = document.getElementById(id_div);
	if (d.style.display == "none")
	{
		d.style.display = "block";
	} else {
		d.style.display = "none";
	}
}

// Fonction de suppression générique
function _delete(type, question, id)
{
	if (confirm(question))
	{
	
		url = location.href;
		position = location.href.indexOf("?",0);
		
		if(position != -1){
			
			url = location.href.substring(0,position);
			
		}
	
		location.href = url + "?type="+type+"&id="+id;	
	}
}

// Fonction de calculette
function calculetteMensualite()
{
	var mbien = document.getElementById('calc_montant_bien');
	var mapport = document.getElementById('calc_montant_apport');
	var mpret = document.getElementById('calc_montant_pret');
	var minteret = document.getElementById('calc_montant_interet');
	var duree = document.getElementById('calc_duree');
	
	// 1 - Calcul du montant du prêt
	var int_mbien = parseFloat(mbien.value.replace(/ /, "").replace(/,/, "."));
	var int_mapport = parseFloat(mapport.value.replace(/ /, "").replace(/,/, "."));
	var int_minteret = parseFloat(minteret.value.replace(/ /, "").replace(/,/, "."));
	
	if (isNaN(int_mapport)) int_mapport = 0;
	if (isNaN(int_minteret)) int_minteret = 0;
	
	var in_mpret = (int_mbien-int_mapport);
	
	mpret.innerHTML = in_mpret;
	
	var int_duree = parseInt(duree.value);
	var annee = 1;
	var mensu = 0;
	var x = 0;
	var interets = 0;
	
	// 2 - Changement des libellés en fonction de la tranche
	for (var i=1 ; i<=10 ; i++)
	{
		annee = (i+(10*int_duree));
		
		// 3 - Calcul de la mensualite
		interets = (int_minteret/100/12);
		x = Math.pow((1 + interets), (annee*12));
		mensu = Math.round((in_mpret*x*interets)/(x-1));
		if (isNaN(mensu)) mensu = 0;
		
		document.getElementById('calc_td_duree_'+(i-1)).innerHTML = (i+(10*int_duree));	
		document.getElementById('calc_td_mensu_'+(i-1)).innerHTML = mensu;
	}
}