function openrim(url)
{
 a=window.open("","openrim","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=618,height=500")
 setTimeout('a.focus()',100);
}
function openwnp()
{
 a=window.open("","openwnp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=350,height=280")
 setTimeout('a.focus()',100);
}
function openwnmai()
{
 a=window.open("","openwnmai","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=400,height=400")
 setTimeout('a.focus()',100);
}
function openprin()
{
 a=window.open("","openprin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=500,height=500")
 setTimeout('a.focus()',100);
}
function openprint()
{
 a=window.open("","openprint","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=635,height=530")
 setTimeout('a.focus()',100);
}
function opendecr()
{
 a=window.open("","opendecr","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=565,height=530")
 setTimeout('a.focus()',100);
}
//template base_ita.tmp
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//template base_ita_registrato
function impostaSelect(cosa, valore)
{
  //dato un campo select, lo imposta a valore
  var i;

  for(i = 0; i < cosa.length; i++)
    if(cosa.options[i].text == valore)
    {
      cosa.selectedIndex = i;
      break;
    }
}
function eliminatore(cosa)
{
  document.riepilogo.codlib.value=cosa;
  document.riepilogo.elimina.value='si';
  document.riepilogo.submit();
}
  //controlla se il tipo di spedizione e' impostato
  function controllaTipoSpedizione(miaForm)
  {
    if(! miaForm.paese_sped.selectedIndex > 0)
    {
      alert("Inserire il Paese di Destinazione");
      return(false);
    }
    else
      return(true);
  }
  //controlla form laterali ricerca
  function controllacus()
  {
    if(document.cus.autore.value.length < 2 && document.cus.titolo.value.length < 2)
    {
      alert("Inserire almeno 2 caratteri di titolo o di autore");
      return(false);
    }
    else
      return(true);
  }
  //form laterale login
  function controlla()
  {
    if(document.f.utente.value.length == 0 || document.f.password.value.length == 0)
    {
      alert("Inserire Login e Password");
      return(false);
    }
    else
      return(true);
  }
//lista registrati
function DISPLAYSTATUSMSG(msgStr) { //v1.2
  status=msgStr;
  document.returnValue = true;
}
 // function controllaricerca()
  //{
 //   ok = 0;

 //   if(document.ricerca.generale[0].checked)
   //   ok = 1;
    //if(document.ricerca.generale[1].checked)
//      ok = 1;
//    if(document.ricerca.sezioni[0].checked)
//      ok = 1;
//    if(document.ricerca.sezioni[1].checked)
//      ok = 1;
//    if(document.ricerca.sezioni[2].checked)
//      ok = 1;
//     if(document.ricerca.sezioni[3].checked)
 //      ok = 1;
//     if(document.ricerca.autore.value.length > 1)
 //      ok = 1;
 //    if(document.ricerca.titolo.value.length > 1)
 //      ok = 1;
 //    if(document.ricerca.collana.value.length > 1)
 //      ok = 1;
 //    if(document.ricerca.periodo.selectedIndex > 0)
 //      ok = 1;
 //    if(document.ricerca.luogo.selectedIndex > 0)
 //      ok = 1;
  //   if(document.ricerca.sottosoggetto.selectedIndex > 0)
  //     ok = 1;
 //    if(document.ricerca.extra.selectedIndex > 0)
 //      ok = 1;
 //    if(document.ricerca.lingua_libro.selectedIndex > 0)
  //     ok = 1;
  //   if(!ok)
  //   {
  //     alert("Inserire qualche criterio di scelta");
  //     return(false);
  //   }
 //    else
  //     return(true);
 //  }
  function ritorno(finestra){
 var newwindow=window.open(finestra,"","width=350,height=300")
newwindow.creator=self
}
function loadurl(url)
{
window.creator.location=url
window.close()
}


function catalogo(finestra){
 var newwindow=window.open(finestra,"","width=400,height=500")
newwindow.creator=self
}
function loadurl(url)
{
window.creator.location=url
window.close()
}

function controllari()
  {
    ok = 0;

    if(document.ricerca.sezioni[0].checked)
      ok = 1;
    if(document.ricerca.sezioni[1].checked)
      ok = 1;
    if(document.ricerca.sezioni[2].checked)
      ok = 1;
    if(document.ricerca.sezioni[3].checked)
      ok = 1;
    if(document.ricerca.autore.value.length > 3)
      ok = 1;
    if(document.ricerca.titolo.value.length > 3)
      ok = 1;
    if(document.ricerca.collana.value.length > 3)
      ok = 1;
    if(document.ricerca.editore.value.length > 3)
      ok = 1;
    if(document.ricerca.periodo.selectedIndex > 0)
      ok = 1;
    if(document.ricerca.luogo.selectedIndex > 0)
      ok = 1;
    if(document.ricerca.sottosoggetto.selectedIndex > 0)
      ok = 1;
    if(document.ricerca.extra.selectedIndex > 0)
      ok = 1;
    if(document.ricerca.lingua_libro.selectedIndex > 0)
      ok = 1;
    if(!ok)
    {
alert("Inserire qualche criterio di scelta");
      return(false);
    }
    else
      return(true);
  }
function apriDescrizione(argomento)
{
window.open("/cgi-bin/argomenti.cgi?argomento=" + argomento ,"apriDescrizione","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=455,height=350")
}
function aprihelp()
{
window.open("","apriDescrizione","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=yes,width=455,height=350")
}

function impostaHidden()
{
  var origine = document.ricerca.riepilogoTerne;
  var destinazione = document.ricerca.tutti;

  destinazione.value = "Luogo-|-sottosoggetto-|-Periodo\n";
  for(i=0;i<origine.length;i++)
    destinazione.value = destinazione.value + origine.options[i].text + "\n";
}

function primaRiga(tipoRiepilogo)
{
  if(tipoRiepilogo.length == 1)
  {
    if(tipoRiepilogo.options[0].text.substring(0, 3) == "---")
      return 1;
    else
      return 0;
  }
  else
    return 0;
}


function aggiungiTrio()
{
  var destinazione = document.ricerca.riepilogoTerne;
  var selezionato = destinazione.selectedIndex;
  var luogo = document.ricerca.luogo;
  var sottosoggetto = document.ricerca.sottosoggetto;
  var periodo = document.ricerca.periodo;

  if(luogo.selectedIndex<1 &&
     sottosoggetto.selectedIndex<1 &&
     periodo.selectedIndex<1)
  {
    alert("Scegliere almeno un elemento");
    return
  }
  if(primaRiga(destinazione))
    destinazione.options[0]=null;
  nuova_option = new Option(luogo.options[luogo.selectedIndex].text + "-|-" 
                           +sottosoggetto.options[sottosoggetto.selectedIndex].text+ "-|-"
                           +periodo.options[periodo.selectedIndex].text );
  destinazione.options[destinazione.length] = nuova_option;
}

function rimuoviTrio()
{
  var origine = document.ricerca.riepilogoTerne;
  var scelta;
  var selezionato = origine.selectedIndex;

  if(selezionato != -1)
  {
    scelta = origine.options[selezionato].text;
    if(scelta != "")
    {
      if(!primaRiga(origine))
        origine.options[selezionato]=null;
      else
        alert("Non ci sono elementi da rimuovere");
    }
    else
      alert("Selezionare un elemento da rimuovere");
  }
  else
    alert("Selezionare un elemento da rimuovere");
}

function aggiungiExtra()
{
  var destinazione = document.ricerca.riepilogoExtra;
  var selezionato = destinazione.selectedIndex;
  var extra = document.ricerca.extra;

  if(extra.selectedIndex<1)
  {
    alert("Scegliere un extra");
    return
  }
  if(primaRiga(destinazione))
    destinazione.options[0]=null;
  nuova_option = new Option(extra.options[extra.selectedIndex].text);
  destinazione.options[destinazione.length] = nuova_option;
}

function rimuoviExtra()
{
  var origine = document.ricerca.riepilogoExtra;
  var scelta;
  var selezionato = origine.selectedIndex;

  if(selezionato != -1)
  {
    scelta = origine.options[selezionato].text;
    if(scelta != "")
    {
      if(!primaRiga(origine))
        origine.options[selezionato]=null;
      else
        alert("Non ci sono elementi da rimuovere");
    }
    else
      alert("Selezionare un elemento da rimuovere");
  }
  else
    alert("Selezionare un elemento da rimuovere");
}
function aggiungiLingua()
{
  var destinazione = document.ricerca.riepilogoLingue;
  var selezionato = destinazione.selectedIndex;
  var lingua = document.ricerca.lingua;

  if(lingua.selectedIndex<1)
  {
    alert("Scegliere una lingua");
    return
  }
  if(primaRiga(destinazione))
    destinazione.options[0]=null;
  nuova_option = new Option(lingua.options[lingua.selectedIndex].text);
  destinazione.options[destinazione.length] = nuova_option;
}

function rimuoviLingua()
{
  var origine = document.ricerca.riepilogoLingue;
  var scelta;
  var selezionato = origine.selectedIndex;

  if(selezionato != -1)
  {
    scelta = origine.options[selezionato].text;
    if(scelta != "")
    {
      if(!primaRiga(origine))
        origine.options[selezionato]=null;
      else
        alert("Non ci sono elementi da rimuovere");
    }
    else
      alert("Selezionare un elemento da rimuovere");
  }
  else
    alert("Selezionare un elemento da rimuovere");
}

function controllaMailingList(form)
{
  var origine = form.riepilogoTerne;

  if(origine.length<=1)
  if(origine.length == 0 ||
     (origine.length == 1 && origine.options[0].value.charAt(0) == '-'))
  {
    alert("Selezionare almeno una terna");
    return(false);
  }
  if(!form.novita_arte.checked &&
     !form.novita_architettura.checked &&
     !form.fuori_commercio.checked &&
     !form.libri_50.checked &&
     !form.libri_banca.checked)
  {
    alert("Selezionare almeno un tipo (Novità arte, novità architettura, ...)");
    return(false);
  }
  
  for(i=0;i<origine.length;i++)
    origine.options[i].selected = true;
  origine = form.riepilogoExtra;
  for(i=0;i<origine.length;i++)
    origine.options[i].selected = true;
  origine = form.riepilogoLingue;
  for(i=0;i<origine.length;i++)
    origine.options[i].selected = true;
  return(true);
}

function controllaIscrizione(form)
{
  if(form.email.value.length < 8)
  {
    alert("email mancante o troppo corta");
    form.email.focus();
    return(false);
  }
  //if(form.password.value.length < 6)
  //{
  //  alert("password mancante o troppo corta (almeno 6)");
  //  form.password.focus();
  //  return(false);
  //}
  //if(form.password2.value != form.password.value)
  //{
  //  alert("Password diverse");
  //  form.password.focus();
  //  return(false);
  //}
  if(form.nome.value.length < 6)
  {
    alert("nome mancante o nome troppo corto");
    form.nome.focus();
    return(false);
  }
  if (form.data_nascita.value.substring(2,3) != "/" ||
    form.data_nascita.value.substring(5,6) != "/" ||
    isNaN(form.data_nascita.value.substring(0,2)) ||
    isNaN(form.data_nascita.value.substring(3,5)) ||
    isNaN(form.data_nascita.value.substring(6,10))) {
      alert("Inserire nascita in formato gg/mm/aaaa");
      form.data_nascita.focus();
      return false;
  }
  else if (form.data_nascita.value.substring(0,2) > 31) {
     alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
     form.data_nascita.focus();
     return false;
  }
  else if (form.data_nascita.value.substring(3,5) > 12) {
     alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
     form.data_nascita.focus();
     return false;
  }
  else if (form.data_nascita.value.substring(6,10) < 1900) {
     alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
     form.data_nascita.focus();
     return false;
  }
  oggi = new Date()
  if(oggi.getFullYear() - parseInt(form.data_nascita.value.substring(6,10)) > 18)
  {
    //nulla
  }
  else
    if(oggi.getFullYear() - parseInt(form.data_nascita.value.substring(6,10)) == 18 &&
       oggi.getMonth() +1 > parseInt(form.data_nascita.value.substring(3,5)))
    {
      //nulla
    }
    else
      if(oggi.getFullYear() - parseInt(form.data_nascita.value.substring(6,10)) == 18 &&
         oggi.getMonth() +1 == parseInt(form.data_nascita.value.substring(3,5)) &&
         oggi.getDate() >= parseInt(form.data_nascita.value.substring(0,2)))
      {
        //nulla
      }
      else
      {
        alert("Non sei maggiorenne");
        return false;
      }
  if(form.indirizzo.value.length < 6)
  {
    alert("indirizzo mancante o troppo corto");
    form.indirizzo.focus();
    return(false);
  }
  if(form.cap.value.length < 4)
  {
    alert("cap mancante o troppo corto");
    form.cap.focus();
    return(false);
  }
  if(form.citta.value.length < 4)
  {
    alert("citta mancante o troppo corta");
    form.citta.focus();
    return(false);
  }
  return(true);
}

function apriApprofondimento(cosa)
{
  if(cosa != 'Tutti' &&
     cosa != 'All')
  {
    a = window.open("aaa","approf","width=40,height=50");
    a.close();
    comando = "window.open(\"/cgi-bin/argomenti.cgi?argomento="+cosa+"#"+cosa+"\", \"approf\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=418,height=500\")"
    setTimeout(comando,100);
  }
}
function apriApprofondimentoex(cosa)
{
  if(cosa != 'Tutti' &&
     cosa != 'All')
  {
    a = window.open("aaa","approf","width=40,height=50");
    a.close();
    comando = "window.open(\"/cgi-bin/argomenti_extra.cgi?argomento="+cosa+"#"+cosa+"\", \"approf\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=418,height=500\")"
    setTimeout(comando,100);
  }
}


function setCookie (name, value) 
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

