function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}
function checkemail(em) {
	re1=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	re2=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	emok=re1.test(em) || re2.test(em);
	return emok;
}

function SelezionaProdotto(nomecampo,id_negozio_ricerca,id_categoria_ricerca,sottocategorie) {
  toppos=(screen.height-600)/2
  leftpos=(screen.width-400)/2
  w=window.open("/index.aspx?m=CatalogoProdotti&f=popupricercaprodotti&nc="+nomecampo+"&nr="+id_negozio_ricerca+"&cr="+id_categoria_ricerca+"&sc="+sottocategorie,"ricercaprodotti","top="+toppos+",left="+leftpos+",height=600,width=400,scrollbars=Yes");
  w.focus();
}

function Aggiorna(campoid,valoreid,valoretxt) {
  pid=MM_findObj(campoid,window.opener.document);
  pdiv=MM_findObj(campoid+"_divprodotto",window.opener.document);
  if (pid!=null) {
    pid.value=valoreid;
    pdiv.innerHTML=valoretxt;
  }
  window.close();
}
function in_array(a,v) {
  found=false;
  for (ia=0; ia<a.length && !found; ia++) {
    found=(a[ia]==v);
  }
  return found;
}
function Fill(c) {
  o=MM_findObj("cp_c"+c);
  if (o) {
    for (x=1;x<o.options.length;x++) o.options[x]=null;
    o.length=1;
    o.selectedIndex=0;
    var cass=new Array();
    cassidx=0
    for (xd=0;xd<mdati.length;xd++) {
      ok=true
      for (xm=0; xm<c; xm++) {
        ok=ok && (MM_findObj("cp_c"+xm).value==mdati[xd][xm])
      }
      if (ok) {
        if (!in_array(cass,mdati[xd][c])) {
          o.options.add(new Option(mdati[xd][c],mdati[xd][c]));
          cass[cassidx]=mdati[xd][c];
          cassidx++;
        }
      }
    }
    Fill(c+1);
    return true;
  }
  return false;
}

function GoToCP(base) {
  for (xd=0;xd<mdati.length;xd++) {
    ok=false
    for (xm=0; xm<3 && !ok; xm++) {
      if (MM_findObj("cp_c"+xm))
        ok=(MM_findObj("cp_c"+xm).value==mdati[xd][xm])
    }
    if (ok) {
      location.href=base+mdati[xd]['cp'];
    }
  }
}

function ApriPaginaFinestra(url,nomefinestra,dimensionex,dimensioney,scrolla) {
  var specs="toolbars=no,width="+dimensionex+",height="+dimensioney;
  if (scrolla) specs+=",scrollbars=yes"
  win=window.open(url,nomefinestra,specs);
  win.focus();
  return false;
}
function ApriImmagineFinestra(url,titolo,dimensionex,dimensioney) {
  var specs="toolbars=no,width="+dimensionex+",height="+dimensioney;
  win=window.open('','cmpopup',specs);
  
  if(!MM_findObj("idIMG",win.document)) {
	win.document.write("<html><head><title>"+titolo+"</title></head><body topmargin=0 leftmargin=0 rightmargin=0 bottommargine=0>");
	win.document.write("<img id=\"idIMG\" src='"+url+"' width="+dimensionex+" height="+dimensioney+" border=0></body></html>");
  } else {
	win.document.title = titolo;
	win.resizeTo(dimensionex+10,dimensioney+60);
	MM_findObj("idIMG",win.document).src = url;
	MM_findObj("idIMG",win.document).width = dimensionex;
	MM_findObj("idIMG",win.document).height = dimensioney;
  }
  win.focus();
  return false;
}