var re_cp = /^[0-9]+[0-9]*$/;
var re_email = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/;


//====================
function valide_email() {
    //====================
    with (document.pro) {
        t_email = re_email.test(email.value);
    }
    if (t_email) return true;
    else {
        if (!t_email) return false;
    }
}

//====================
function valide_cp() {
    //====================
    with (document.pro) {
        t_cp = re_cp.test(cp.value);
    }
    if (t_cp) return true;
    else {
        if (!t_cp) return false;
    }
}


function cocher() {
	test = false;
	if (! document.choix_paiement.cgv.checked) {
		alert ("Vous devez accepter les Conditons\nGénérales de Vente !");
	} else if (! document.choix_paiement.majeur.checked) {
		alert ("Vous devez attester avoir plus de 18 ans !");
	} else { 
		test = true;
	}
	return test;
}

function go_paiement() {
	//alert(document.choix_paiement.cgv.checked);
	if (cocher()) {
		document.choix_paiement.submit();
	}
}

function ajouter(id_prix) {
	document.liste_vin.id_vin.value = id_prix;
	document.liste_vin.action = "/new/pages/ajouter_vin.asp";
	liste_vin.submit();
}

function ouvrir_zoom(vin) {
	lien = "/new/pages/zoom_vin.asp?id_vin=" + vin;
	var fen =  open(lien, 'zoom', 'width=500,height=500,scrollbars=0,status=0');
}

function fiche_vin(vin) {
	document.liste_vin.id_vin.value = vin;
	document.liste_vin.action = "/new/pages/fiche_vin.asp?id_vin=" + vin;
	liste_vin.submit();
}

function verif_form(ind)
{
	var ok = 0;
	for (i=0; i<ind; i++)
	{
		str = "document.choix_vin.qte" + i + ".value";
		if ((eval(str) != "") && (eval(str) != 0))
		{
			ok = 1;
		}
	}
	if (! ok)
		alert("Vous n'avez saisi aucune quantité !");
	else
		document.choix_vin.submit();
}

function verif_form_bis(ind)
{
	var ok = 1;
	for (i=0; i<ind; i++)
	{
		str = "document.choix_vin.qte" + i + ".value";
		if (eval(str) == "") 
		{
			ok = -1;
		} else if (isNaN(eval(str))) {
			ok = -2;
		} else if (eval(str) <= 0) {
			ok = -3;
		}
	}
	if (ok == -1) {
		alert("Vous devez saisir une quantité !");
	} else if (ok == -2) {
		alert("Vous devez saisir une quantité numérique !");
	} else if (ok == -3) {
		alert("Vous devez saisir une quantité strictement positive !");
	} else {
		document.choix_vin.action="/new/pages/recalculer_vin.asp?nb="+ind;
		document.choix_vin.submit();
	}
}


function verif_form1()
{
	var ok = 0;
	str1 = "document.vos_infos1.c_email.value";
	str2 = "document.vos_infos1.c_password.value";
	if (eval(str1) != "" && eval(str2) != "") 
	{
	    with (document.vos_infos1) {
	        t_email = re_email.test(c_email.value);
	    }
	    if (t_email) ok = 1;
	    else {
	        if (!t_email) ok = 0;
	    }
	}
	if (! ok) {
		alert("Vous devez saisir un Email valide et mot de passe !");
		document.vos_infos1.c_email.focus();
	} else {
		document.vos_infos1.submit();
	}
}

function verif_form2()
{
	var ok = 0;
	str1 = "document.vos_infos2.c_nom.value";
	str2 = "document.vos_infos2.c_prenom.value";
	str3 = "document.vos_infos2.c_adresse.value";
	str4 = "document.vos_infos2.c_cp.value";
	str5 = "document.vos_infos2.c_ville.value";
	str6 = "document.vos_infos2.c_pays.value";
	str7 = "document.vos_infos2.c_email.value";
	str8 = "document.vos_infos2.c_password.value";
	if (eval(str1) != "" && eval(str2) != "" && eval(str3) != "" && eval(str4) != "" && eval(str5) != "" && eval(str6) != "" && eval(str7) != "" && eval(str8) != "")
	{
		ok = 1;
        with (document.vos_infos2) {
            t_email = re_email.test(c_email.value);
        }
        if (!t_email) ok = 2;
   }

    if (ok == 0) {
        alert("Vous devez renseigner les champs marqués d'une * !");
	} else if (ok == 2) {
	alert("Vous devez saisir un Email valide !"); 
    } else {
	    document.vos_infos2.action="/new/pages/validation_infos.asp";
	    document.vos_infos2.submit();
    }
}

function verif_form2_bis()
{
	var ok = 0;
	str1 = "document.vos_infos2.c_nom.value";
	str2 = "document.vos_infos2.c_prenom.value";
	str3 = "document.vos_infos2.c_adresse.value";
	str4 = "document.vos_infos2.c_cp.value";
	str5 = "document.vos_infos2.c_ville.value";
	str6 = "document.vos_infos2.c_pays.value";
	str7 = "document.vos_infos2.c_email.value";
	//if (eval(str1) != "" && eval(str2) != "" && eval(str3) != "" && eval(str4) != "" && eval(str5) != "" && eval(str6) != "" && eval(str7) != "")
	//{
	//	ok = 1;
	//}
	//if (! ok) {
	//	alert("Vous devez renseigner les champs marqués d'une * !");
	//} else {
	//	document.vos_infos2.action="/new/pages/mode_expe.asp";
	//	document.vos_infos2.submit();
	//}
	document.vos_infos2.action="/new/pages/validation_infos_expe.asp";
	document.vos_infos2.submit();
}


function go_panier()
{
	if (confirm ('Vous êtes sûr de vouloir retourner au panier ?')) {
		document.vos_infos2.action="/new/pages/panier.asp";
		document.vos_infos2.submit();
	}
}

function supprimer(id_vin)
{
	if (confirm ('Vous êtes sûr de vouloir supprimer cet article ?')) {
		document.choix_vin.action="/new/pages/supprimer_ligne_cde.asp?id_vin="+id_vin;
		document.choix_vin.submit();
	}
}

function changer_embal_old(i, ind)
{
	liste = 'liste_embal' + i;
	choix = document.getElementById(liste).selectedIndex;
	valeur = document.getElementById(liste).options[choix].value;
	cache = 'document.choix_vin.emb' + i + '.value';
	eval(cache) = valeur;
	alert(document.choix_vin.emb0.value);
	document.choix_vin.action="/new/pages/recalculer_vin.asp?nb="+ind;
	document.choix_vin.submit();
}

function changer_embal(id_prix,type_emballage)
{
	prix = id_prix;
	emballage = type_emballage;
	document.choix_vin.action="/new/pages/ajouter_emballage.asp?prix="+prix+"&emballage="+emballage;
	//alert(document.choix_vin.action);
	document.choix_vin.submit();
}

function ouvrir_fenetre(id) {
	lien = "/new/pages/fenetre.asp?id=" + id;
	var fen =  open(lien, 'news', 'width=500,height=300,scrollbars=1,status=0');
}

function ouvrir_newsletter() {
	lien = "/new/pages/newsletter.asp";
	var fen =  open(lien, 'newsletter', 'width=500,height=120,scrollbars=0,status=0');
}

function changeImages (id, image) {
	document.getElementById(id).src = image;
}

function newsletter() {
	var mail = document.form_email.n_email.value;
        var modele = /^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\-_]+\.[a-zA-Z]{2,5}$/i;
	if (modele.test(mail)) {
		ouvrir_valider_newsletter(mail);
	} else {
        	alert("Votre adresse email est invalide !");
	}
}

function ouvrir_valider_newsletter(mail) {
	lien = "/new/pages/add_news_letter.asp?mail="+mail;
	//var fen =  open(lien, '_self', 'width=300,height=100,scrollbars=1,status=0');
	var fen =  open(lien, '_self', 's');
}

function action (queFaire, id_cde) {
	lien = "/new/pages/mon_compte_fiche_commande.asp?id_cde=" + id_cde;
	var fen =  open(lien, '_self');
}

function verif_promo() {
	var ok = 0;
	str1 = "document.choix_vin.code_promo.value";
	if (eval(str1) != "")
	{
		ok = 1;
	}
	if (! ok) {
		alert("Vous devez saisir un code promo !");
		document.choix_vin.code_promo.focus();
	} else {
		document.choix_vin.action = "/new/pages/controle_promo.asp";
		document.choix_vin.submit();
	}
	
}

