﻿function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function controllo_form(theForm)
{
  if (theForm.realname.value== "")
  {
    alert("Inserire il Vs. Nome!!");
    theForm.realname.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
  var checkStr = theForm.realname.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettere nel campo \"Nome\".");
    theForm.realname.select();
    return (false);
  }
  if (theForm.cognome.value== "")
  {
    alert("Inserire il Vs. cognome!!");
    theForm.cognome.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.cognome.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettere nel campo \"Cognome\".");
    theForm.cognome.focus();
    return (false);
  }
  if (theForm.giorno_arrivo.selectedIndex == 0)
  {
    alert("Selezionare un giorno di arrivo!!");
    theForm.giorno_arrivo.focus();
    return (false);
  }
  if (theForm.mese_arrivo.selectedIndex == 0)
  {
    alert("Selezionare il mese di arrivo!!");
    theForm.mese_arrivo.focus();
    return (false);
  }
  if (theForm.giorno_partenza.selectedIndex == 0)
  {
    alert("Selezionare un giorno di partenza!!");
    theForm.giorno_partenza.focus();
    return (false);
  }
  if (theForm.mese_partenza.selectedIndex == 0)
  {
    alert("Selezionare il mese di partenza!!");
    theForm.mese_partenza.focus();
    return (false);
  }
  if (theForm.N_persone.value== "")
  {
    alert("Inserire il numero delle persone!!");
    theForm.N_persone.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.N_persone.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo cifre nel campo \"N° persone\".");
    theForm.N_persone.focus();
    return (false);
  }
  if (theForm.N_persone.value.length > 2)
  {
    alert("Inserire un numero più basso nel campo \"N° persone\"!");
    theForm.N_persone.select();
    return (false);
  }
  if (theForm.email.value== "")
  {
    alert("Inserire la Vs. E-mail!!");
    theForm.email.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789@.- \t\r\n\f";
  var checkStr = theForm.email.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettere, cifre nel campo \"E-mail:\".");
    theForm.email.focus();
    return (false);
  }
  if (theForm.telefono.value== "")
  {
    alert("Inserire il Vs. N° di telefono!!");
    theForm.telefono.focus();
    return (false);
  }
  var checkOK = "0123456789./";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }  
	}
  if (!allValid)
  {
    alert("Inserire solo cifre nel campo \"telefono:\".");
    theForm.telefono.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.citta.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettere nel campo \"CittÃ :\".");
    theForm.citta.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.cap.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo cifre nel campo \"CAP:\".");
    theForm.cap.focus();
    return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.provincia.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettere nel campo \"Provincia:\".");
    theForm.provincia.focus();
    return (false);
  }
    if (theForm.provincia.value.length == 1)
  {
    alert("Inserire 2 caratteri nel campo \"provincia\".");
    theForm.provincia.focus();
    return (false);
  }
  var checkOK = "0123456789./";
  var checkStr = theForm.fax.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }  
	}
  if (!allValid)
  {
    alert("Inserire solo cifre nel campo \"Fax:\".");
    theForm.fax.focus();
    return (false);
  }
  var checkOK = "0123456789./";
  var checkStr = theForm.cell.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }  
	}
  if (!allValid)
  {
    alert("Inserire solo cifre nel campo \"Cellulare:\".");
    theForm.cell.focus();
    return (false);
  }

  var allValid = true;
	if(getCheckedValue(theForm.privacy) != 'Acconsento'){
		allValid = false;
	}
  if (!allValid)
  {
    alert("Per inviare il modulo è necessario accettare l'informativa sulla privacy");
    return (false);
  }
}
function privacy(str,winName,larg,alt){
	finestra=window.open(str,winName,"width=" + larg + ", height="+alt+", left=" + ((screen.width-larg)/2) + ",top="+((screen.height-alt)/2)+", scrollbars, resizable" );
	finestra.focus();
}