function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function setCookie(sNome, sValore, iGiorni) {
  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
  (dtOggi.getTime() + 24 * iGiorni * 3600000)
  document.cookie = sNome + "=" + escape(sValore) + "; expires=" + dtExpires.toGMTString();
}

// restituisce il valore del cookie sNome
function getCookie(sNome) {
  // genera un array di coppie "Nome = Valore"
  // NOTA: i cookies sono separati da ';'
  var asCookies = document.cookie.split("; ");
  // ciclo su tutti i cookies
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++){
    // leggo singolo cookie "Nome = Valore"
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    }
  }
}
function cart(pro, qty){
  if(!qty)
    qty="1";
  setCookie("cart_q", pro + ";" + qty, "30");
  window.location="/cart.php";
}
function okord(id) {
  frm = document.getElementById(id);
  var errore = '';
		var campo = 'tes_nome';  
		if(!document.getElementById(campo).value) {
		  errore += "\n- Il campo Nome è obbligatorio";
		  document.getElementById(campo).focus();
		}
		var campo = 'tes_mail';  
		if(!document.getElementById(campo).value) {
		  errore += "\n- Il campo Mail è obbligatorio";
		  document.getElementById(campo).focus();
		}else if(controllomail(document.getElementById(campo).value)){
		  errore += "\n- Indirizzo Mail non valido";
		  document.getElementById(campo).focus();
		}
  if(errore == '') {
	frm.submit();
  } else {
    alert("Attenzione:\n"+errore);
  }
}
function controllomail(mail){
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail))
	{
	    return "mail errata";
	}
}