var srcFrame;
var trovato = false;
function ValidateContatti(theForm)
{

// Controlla che il num serie non sia vuoto
if (theForm.NumSerie.value == "") {
			alert("You must Insert the Number of Series of the acquired product.");
			theForm.NumSerie.focus();
			return(false)
	}
// Controlla che il num serie sia corretto	
	loadOuter('../temi/milkline/h_c.txt');
	
	if(trovato == false)
	{
		return(false);
	}


// Controlla che la data di acquisto non sia vuota
if (theForm.DataAcquistoGG.value == "") {
			alert("You must Insert the day of the purchase.");
			theForm.DataAcquistoGG.focus();
			return(false)
	}
if (theForm.DataAcquistoMM.value == "") {
			alert("You must Insert the month of the purchase.");
			theForm.DataAcquistoMM.focus();
			return(false)
	}
if (theForm.DataAcquistoAA.value == "") {
			alert("You must Insert the year of the purchase.");
			theForm.DataAcquistoAA.focus();
			return(false)
	}
	

// Controlla che il num dei Box non sia vuoto
if (theForm.Box_N.value == "") {
			alert("You must insert the Box number.");
			theForm.Box_N.focus();
			return(false)
	}
// Controlla che il num Tag non sia vuoto
if (theForm.Tag_N.value == "") {
			alert("You must insert  the Tag number.");
			theForm.Tag_N.focus();
			return(false)
	}
// Controlla che Posizionamento non sia vuoto

  if (theForm.Posizionamento.checked == false )
  {
	alert('You must insert the Positioning.');
	theForm.Posizionamento.focus();
	return (false)
	}

// Controlla che Azienda non sia vuoto
if (theForm.RagSoc.value == "") {
			alert("You must insert  the Company name.");
			theForm.RagSoc.focus();
			return(false)
	}
// Controlla che il nome non sia vuoto
 if (theForm.Nome.value == "") {
 			alert("You must insert  the name.");
 			theForm.Nome.focus();
 			return(false)
  	}
// Controlla che il cognome non sia vuoto
 if (theForm.Cognome.value == "") {
		alert("You must insert  the Last Name.");
		theForm.Cognome.focus();
		return(false)
	}
// Controlla che l'indirizzo non sia vuoto
 if (theForm.Indirizzo.value == "") {
		alert("You must insert  the Address.");
		theForm.Indirizzo.focus();
		return(false)
	}
// Controlla che la Località non sia vuoto
 if (theForm.Citta.value == "") {
		alert("You must insert  the Locality.");
		theForm.Citta.focus();
		return(false)
	}
// Controlla che il CAP non sia vuoto
 if (theForm.Cap.value == "") {
		alert("You must insert  the Zip Code");
		theForm.Cap.focus();
		return(false)
	}
// Controlla che la Provincia non sia vuoto
// if (theForm.Provincia.value == "") {
//		alert("You must insert  the  Province.");
//		theForm.Provincia.focus();
//		return(false)
//	}

  // Controlla che il telefono non sia vuoto

  if (theForm.Telefono.value == "") {
			alert("You must insert  the Telephone.");
			theForm.Telefono.focus();
			return(false)
	}
	
  // Controlla che il telefono sia in cifre
  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("You must insert a number of Telephone valid, only figures.");
    theForm.Telefono.focus();
    return (false);
  }

	
// Controlla se email non sia vuota
 if (theForm.EMail.value == "") {
	alert("You must insert the E-mail.");
	theForm.EMail.focus();
	return(false)
  }

// Controlla che email sia 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 che email sia valida: presenza della @
  if (checkStr.indexOf('@') == -1)
    allValid = false;

// Controlla che email sia valida: presenza di 1 punto
  if (checkStr.indexOf('.') == -1)
    allValid = false;

 if (!allValid)
	{
	alert("You must insert a valid E-mail address. ");
	theForm.EMail.focus();
	return (false);
	}

  if (theForm.Privacy.checked == false )
  {
	alert('In order to send a message it is necessary to authorize the use of the Personal Data.');
	theForm.Privacy.focus();
	return (false);
  }

  return (true);
}


//External content into a layer
function loadOuter(doc) {
 srcFrame = document.getElementById("hiddenContent");
 srcFrame.src = doc;
 // workaround for missing onLoad event in IFRAME for NN6
 if (!srcFrame.onload) {
  setTimeout("transferHTML()", 1000)
 }
}

function transferHTML(){
 srcContent='';
 var NumSerie=document.getElementById("NumSerie");
 if (srcFrame.contentDocument){
  srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
 }
 else if (srcFrame.contentWindow){
  srcContent=srcFrame.contentWindow.document.body.innerHTML;
 }
 document.getElementById("outerDisplay").innerHTML = srcContent
 if(srcContent.indexOf('$' + NumSerie.value + '$') == -1){
	alert("The serial numer is incorrect! Try again.");
	theForm.NumSerie.focus();
	trovato = false;
	}
	else
	{
	trovato = true;
  }

}
