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 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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function SottoCategorie(name,lista)
{
  //array lista_id = new Array(j)
  lista_id = lista.split(',');

  for (var i=0; i < lista_id.length; i++) {
		MM_findObj('SottoCategoria'+lista_id[i]).style.position	= 'absolute';
		MM_findObj('SottoCategoria'+lista_id[i]).style.visibility	= 'hidden';
		MM_findObj('SottoCategoria'+lista_id[i]).name	= 'a'
	}

	MM_findObj(name).style.visibility	= 'visible';
	MM_findObj(name).style.position	= 'relative';
	MM_findObj(name).name	= 'Sottocategoria';
	return i;
}


function Validate_Contattaci(theForm){

if (theForm.Messaggio.value == "") {
			alert("Scrivi un messaggio.");
			theForm.Messaggio.focus();
			return(false)
	}


if (theForm.Email_utente.value == "") {
			alert("Inserisci il tuo indirizzo email per la risposta.");
			theForm.Email_utente.focus();
			return(false)
	}

  var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
  var checkStr = theForm.Email_utente.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 (checkStr.indexOf('@') == -1)
	  allValid = false;

	if (checkStr.indexOf('.') == -1)
	  allValid = false;

	if (!allValid)
	{
	alert("Inserisci un indirizzo email valido");
	theForm.Email_utente.focus();
	return (false);
	}
  }

  var checkOK = "0123456789/";
  var checkStr = theForm.Cellulare.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 un numero di Cellulare valido, solo cifre, senza spazi vuoti.");
    theForm.Cellulare.focus();
    return (false);
  }

  return (true);
}

function Validate_Newsletter_Home(theForm){

  // Controlla se l'email e' vuoto
  if (theForm.Email.value == "") {
	alert("Inserire l\'indirizzo Email.");
	theForm.Email.focus();
	return(false)
  }

  // Controlla se l'email e' valida: caratteri consentiti
  var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
  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;
	}

  }

  // Controlla se l'email e' valida: presenza della @
  if (checkStr.indexOf('@') == -1)
    allValid = false;

  // Controlla se l'email e' valida: presenza di 1 punto
  if (checkStr.indexOf('.') == -1)
    allValid = false;

  if (!allValid)
	{
	alert("Inserire un indirizzo email valido");
	theForm.Email.focus();
	return (false);
	}

  // Controlla se il nome e' vuoto
  /*
  if (theForm.Nome.value == "") {
  			alert("Inserire il Nome.");
  			theForm.Nome.focus();
  			return(false)
  	}

  // Controlla se il cognome e' vuoto

  if (theForm.Cognome.value == "") {
			alert("Inserire il Cognome.");
			theForm.Cognome.focus();
			return(false)
	}
  */

  // Controlla se il telefonino e' in cifre
  /*
  var checkOK = "0123456789/ .";
  var checkStr = theForm.Telefonino.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 un numero di Cellulare valido, solo cifre.");
    theForm.Telefonino.focus();
    return (false);
  }
  */

  if (theForm.Privacy.checked == false )
  {
	alert('Per l\'iscrizione alla newsletter e\' necessario autorizzare l\'uso dei dati personali.');
	theForm.Privacy.focus();
	return (false);
  }

  return (true);
}

var max_char=1000;
function count(sender)
{
	if (sender.value.length > max_char)
		sender.value = sender.value.substr(0, max_char);
	MM_findObj('textfield2').value = sender.value.length;
}


function ValidateNewsletter(theForm){

  // Controlla se l'email e' vuoto
  if (theForm.Email.value == "") {
	alert("Inserire l\'indirizzo Email.");
	theForm.Email.focus();
	return(false)
  }

  // Controlla se l'email e' valida: caratteri consentiti
  var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
  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;
	}

  }

  // Controlla se l'email e' valida: presenza della @
  if (checkStr.indexOf('@') == -1)
    allValid = false;

  // Controlla se l'email e' valida: presenza di 1 punto
  if (checkStr.indexOf('.') == -1)
    allValid = false;

  if (!allValid)
	{
	alert("Inserire un indirizzo email valido");
	theForm.Email.focus();
	return (false);
	}

  // Controlla se il nome e' vuoto
  /*
  if (theForm.Nome.value == "") {
  			alert("Inserire il Nome.");
  			theForm.Nome.focus();
  			return(false)
  	}

  // Controlla se il cognome e' vuoto

  if (theForm.Cognome.value == "") {
			alert("Inserire il Cognome.");
			theForm.Cognome.focus();
			return(false)
	}
  */

  // Controlla se il telefonino e' in cifre
  var checkOK = "0123456789/ ";
  var checkStr = theForm.Telefonino.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 un numero di Cellulare valido, solo cifre.");
    theForm.Telefonino.focus();
    return (false);
  }

  if (theForm.Privacy.checked == false )
  {
	alert('Per l\'iscrizione alla newsletter e\' necessario autorizzare l\'uso dei dati personali.');
	theForm.Privacy.focus();
	return (false);
  }

  return (true);
}

function detail(name)
{
	var detail, show;
	detail = MM_findObj(name + 'Detail');
	show = detail.style.visibility == 'visible';
	if (show){
		image_SWP = 'immagini/detail_show.gif';
		detail.style.position		= 'absolute';
		detail.style.visibility	= 'hidden';
	}
	else{
		image_SWP = 'immagini/detail_hide.gif';
		detail.style.position		= 'relative';
		detail.style.visibility	= 'visible';
	}
	MM_swapImage(name + '_detail_IMG', '' , image_SWP, 1);
}

function ApriMenu(name)
{
	var detail, show;
	detail = MM_findObj(name + 'Content');
	voice = MM_findObj(name + 'Voice');
	show = detail.style.visibility == 'visible';
	if (show){
		image_SWP = 'immagini/menu_apri.gif';
		detail.style.position		= 'absolute';
		detail.style.visibility	= 'hidden';
	}
	else{
		image_SWP = 'immagini/menu_chiudi.gif';
		detail.style.position		= 'relative';
		detail.style.visibility	= 'visible';
		voice.href= '#';
	}
	MM_swapImage(name + 'Image', '' , image_SWP, 1);
}


// presente per compatibilita' retro
// da eliminare
function Validate_Newsletter(theForm){

  // Controlla se l'email e' vuoto
  if (theForm.Email.value == "") {
	alert("Inserire l\'indirizzo Email.");
	theForm.Email.focus();
	return(false)
  }

  // Controlla se l'email e' valida: caratteri consentiti
  var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
  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;
	}

  }

  // Controlla se l'email e' valida: presenza della @
  if (checkStr.indexOf('@') == -1)
    allValid = false;

  // Controlla se l'email e' valida: presenza di 1 punto
  if (checkStr.indexOf('.') == -1)
    allValid = false;

  if (!allValid)
	{
	alert("Inserire un indirizzo email valido");
	theForm.Email.focus();
	return (false);
	}

  // Controlla se il nome e' vuoto
  /*
  if (theForm.Nome.value == "") {
  			alert("Inserire il Nome.");
  			theForm.Nome.focus();
  			return(false)
  	}

  // Controlla se il cognome e' vuoto

  if (theForm.Cognome.value == "") {
			alert("Inserire il Cognome.");
			theForm.Cognome.focus();
			return(false)
	}
  */

  // Controlla se il telefonino e' in cifre
  /*
  var checkOK = "0123456789/ .";
  var checkStr = theForm.Telefonino.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 un numero di Cellulare valido, solo cifre.");
    theForm.Telefonino.focus();
    return (false);
  }
  */

  if (theForm.Privacy.checked == false )
  {
	alert('Per l\'iscrizione alla newsletter e\' necessario autorizzare l\'uso dei dati personali.');
	theForm.Privacy.focus();
	return (false);
  }

  return (true);
}
