function showPic (whichpic) 
{ 
   if (document.getElementById) 
   { 
      document.getElementById('placeholder').src = whichpic.href; 
      if (whichpic.title) 
      { 
        document.getElementById('desc').childNodes[0].nodeValue = whichpic.title; 
      } 
      else 
      { 
        document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; 
      } 
      return false; 
   } 
   else 
   { 
      return true; 
   } 
}


// -------------------------------------------------------
// ricerca libera
// -------------------------------------------------------
function ExecFreeSearch()
{
  var inputText = document.getElementById('full_text_field');
  document.formFreeSearch.full_text.value = inputText.value;
  document.formFreeSearch.submit();
}

// -------------------------------------------------------
// validazione io sono, io cerco
// -------------------------------------------------------
function ExecIoSonoCerco()
{
  var sono  = document.form_sono_cerco.io_sono.value;
  var cerco = document.form_sono_cerco.io_cerco.value;
  
  if ( 
        ( (sono == '') && (cerco == '') )
        ||
        ( (sono == 'ALL') && (cerco == 'ALL') )
        ||
        ( (sono == '') && (cerco == 'ALL') )
        ||
        ( (sono == 'ALL') && (cerco == '') )
     )   
  {
  	 alert('specificare un valore per "io sono" e "io cerco"');
  	 return;
  }
  document.form_sono_cerco.submit()
}



// -------------------------------------------------------
// validazione io cerco
// -------------------------------------------------------
function ExecIoCerco(cerco)
{
  var theForm = document.getElementById("form_sono_cerco");
  //theForm.io_cerco.value = cerco;
  
  if (cerco == '') 
  {
  	 alert('specificare il parametro di ricerca');
  	 return;
  }
  theForm.submit();
}



// -------------------------------------------------------
// validazione io cerco
// -------------------------------------------------------
function ExecIoCerco2(cerco)
{
  var theForm = document.getElementById("form_sono_cerco_2");
  theForm.io_cerco.value = cerco;
  
  if (cerco == '') 
  {
  	 alert('specificare il parametro di ricerca');
  	 return;
  }
  theForm.submit();
}

function showPic (whichpic) 
{ 
   if (document.getElementById) 
   { 
      document.getElementById('placeholder').src = whichpic.href; 
      if (whichpic.title) 
      { 
        document.getElementById('desc').childNodes[0].nodeValue = whichpic.title; 
      } 
      else 
      { 
        document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; 
      } 
      return false; 
   } 
   else 
   { 
      return true; 
   } 
}



// -------------------------------------------------------
// validazione newsletter
// -------------------------------------------------------
function validateNewsletter()
{
  var nome = document.newsletterForm.newsletter_nome.value;
  var cogn = document.newsletterForm.newsletter_cognome.value;
  var mail = document.newsletterForm.newsletter_mail.value;
  
  if (nome && mail && cogn)
  {
    if (mail.indexOf('@',0) != -1 && mail.indexOf('.',0) != -1)
       return true;
    else
    {
       alert('inserire un indirizzo di mail corretto.');
       return false;
    }
  }
  else
  {
     alert('compilare tutti i campi obbligatori.');
     return false;
  }
}


// -------------------------------------------------------
// validazione contatti
// -------------------------------------------------------
function validateContatti()
{
  var nome    = document.contactForm.nome.value;
  var cognome = document.contactForm.cognome.value;
  var mail    = document.contactForm.email.value;
  var oggetto = document.contactForm.oggetto.value;
  var testo   = document.contactForm.testo.value;
  
  if (nome && cognome && mail && oggetto && testo)
  {
    if (mail.indexOf('@',0) != -1 && mail.indexOf('.',0) != -1)
       return true;
    else
    {
       alert('inserire un indirizzo di mail corretto.');
       return false;
    }
  }
  else
  {
     alert('compilare tutti i campi.');
     return false;  }
}


// -------------------------------------------------------
// galleria generale: selezione di una categoria di immagini
// -------------------------------------------------------
function SelectCategory()
{
  
  if (document.selectCategory.selected_step != null)
    document.selectCategory.selected_step.value = 0;
  
  document.selectCategory.submit();
}

// -------------------------------------------------------
// galleria generale: selezione di una categoria di immagini
// -------------------------------------------------------
function SelectImageGroup()
{
  document.selectCategory.submit();
}



// -------------------------------------------------------
// apertura pagina di edit delle schede
// -------------------------------------------------------
function EditSk(page)
{
  var wnd = window.opener;
  
  if ( (wnd != null) && (!wnd.closed) )
  {
    wnd.focus();
    wnd.location.href = page;
  }  
  else
    OpenWindow(page, 'EditSk', 700, 500);
}


// -------------------------------------------------------
// messaggio di conferma
// -------------------------------------------------------
function ConfirmDelete(msg)
{
  return confirm(msg);
}

// -------------------------------------------------------
// permette di digitare solo numeri
// -------------------------------------------------------
function numbersonly(myfield, e, dec)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
     return true;
  
  // decimal point jump
  else if (dec && (keychar == "."))
     {
     myfield.form.elements[dec].focus();
     return false;
     }
  else
     return false;
}

// -------------------------------------------------------
// permette di digitare solo numeri e lettere
// -------------------------------------------------------
function letternumber(e)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // alphas and numbers
  else if (((" '.-abcdefghijklmnopqrstuvwxyz0123456789àèìòù?_,éç&âäèêëöüçß&()@").indexOf(keychar) > -1))
     return true;
  else
     return false;
}

// -------------------------------------------------------
// classica openWindow
// -------------------------------------------------------
function OpenWindow(url, windowName, w, h)
{
   var wf = "";
   wf = wf + "width=" + w;
   wf = wf + ",height=" + h;
   wf = wf + ",resizable=yes";
   wf = wf + ",scrollbars=yes";
   wf = wf + ",menubar=no";
   wf = wf + ",toolbar=no";
   wf = wf + ",directories=no";
   wf = wf + ",location=no";
   wf = wf + ",status=yes";
   var wnd = window.open(url,windowName,wf);
   wnd.focus();
}


// -------------------------------------------------------
// si muove tra le pagine del navigatore
// -------------------------------------------------------
function ChangeOffset(NewOffset) {
  document.getElementById("mainForm").last_record.value = NewOffset;
  document.getElementById("mainForm").submit();
}
