
/***************************************************
 * ouvre une pop-up (scrolling optionnel 0 ou 1)
 ***************************************************/
function pop(page, width, height, scroll)
{ win = window.open(page, "", 'scrollbars='+scroll+', width='+width+', height='+height+', top=100, left=350'); }

/****************************************************
 * vérifie une adresse e-mail et retourne un boolean
 ****************************************************/
function verifMail(email)
{ var b = true;
  if (!email) b = false;
  var filtre  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
  if(!filtre.test(email)) b = false;
  return b;
}


/**************************
 * vérifie la commande
 **************************/
function verifComm(form)
{
  tab = form.modif.value.split("@")
  for(y=0 ; y<tab.length ; y++)
  {

	  id = tab[y];
	  var quant = eval("form.quant"+id);
	  var oldQuant = eval("form.oldQuant"+id);
	  var idProd = eval("form.idProd"+id);
	  var libre = eval("form.libre"+id);
	  if(libre.value == "1") var prixlibre = eval("form.prixlibre"+id);
	
	  if(isNaN(quant.value)) { alert("Quantité incorrecte !"); return false; }

	if(libre.value == "1") 
	  {
		 if(prixlibre.value == "?") prixlibre.value = 0;
		   /*if(prixlibre.value) replace(",", ".", prixlibre.value);*/
		  //if(isNaN(prixlibre.value) || !prixlibre.value) {alert("Prix libre incorrect !"); return false;}
			
		  var pri = prixlibre.value;
		  var CharPri;

		    for(i = 0; i < pri.length; i++)
		  {
			CharPri = pri.charAt(i);
			if(CharPri == "-" || CharPri == "x" || CharPri == " ")
			{
				alert("Prix libre incorrect !"); return false;
			}
		  }
	  }

	  var Char;
	  bool = 0;
	  cpt = 0;
	  var chaine = quant.value;
	  
	  if(chaine.length == "0" && libre.value != "1") quant.value = "1";
	  else if(chaine.length == "0" && libre.value == "1") quant.value = "0";

	  for(i = 0; i < chaine.length; i++)
	  {
		Char = chaine.charAt(i);
		if(Char == "-" || Char == "x" || Char == " " || Char == ".")
		{
			alert("Quantité incorrecte !"); return false;
		}
		if(Char == "0" && bool == "0")
		{
			cpt += 1;
		}
		else
		{
			bool = 1;
		}
	  }
	  if(bool == "1") quant.value = quant.value.substring(cpt, quant.value.length);
	  quant.value = parseInt(quant.value);
	  if(quant.value == "0" && oldQuant.value == "0" && libre.value != "1") quant.value = 1;
	  //if(form.quant.value == form.oldQuant.value) return false;
	  if(quant.value == "0" && oldQuant.value != "0" && libre.value != "1")
	  { if(confirm("Voulez-vous supprimer ce produit du panier ?"))
		{
		  form.action = "gestPanier.php5?act=delPanier&idProd="+idProd.value;
		  return true;
		}
		else
		{ quant.value = oldQuant.value;
		  return false;
		}
	  }	
  }
  return true;
}

function addPanier(form)
{
	var chaine = form.quant.value;
	if(chaine.length == "0") form.quant.value = "1";
	if(chaine == "0") form.quant.value = "1";
}

function recharge()
{ 
	document.formTri.submit();
}

function dvdSupp(id, prix)
{
	document.getElementById(id).style.display = '';
	document.getElementById("dvdSuppl" + id).style.display = "none";
	document.getElementById("quant" + id).value = 1;
	document.getElementById("textDiv" + id).innerHTML = prix + "&nbsp;&euro;";
}

function confirmDel(idProd)
{
  if (confirm("Vous êtes sur le point de supprimer un DVD de la commande !\n Voulez-vous continuer ?"))
  {
    document.location = "gestPanier.php5?act=delPanier&idProd="+idProd;
  }
}

function confirmDelDvdSupp(idProd)
{
  if (confirm("Vous êtes sur le point de supprimer un DVD supplémentaire de la commande !\n Voulez-vous continuer ?"))
  {
    document.location = "gestPanier.php5?act=delPanierDvdSupp&idProd="+idProd;
  }
}

function afficheBlocCnx(idBlock, idNone)
{
	if(document.getElementById(idBlock)) document.getElementById(idBlock).style.display = "block";
	if(document.getElementById(idNone)) document.getElementById(idNone).style.display = "none";	
}