// JavaScript Document
<!--
function DisplaySerialError() {
      alert('Attenzione: il codice seriale inserito non è valido!\n\nAssicurarsi che non ci siano spazi alla fine o all\'inizio\ne che gli zeri non vengano confusi con "o" maiuscole'); 
	  document.SRequest.serial.value = '';	  
	  document.SRequest.serial.focus();	  
}

function CharCheck(str, pos) {
   var myChar;
   
   myChar = str.charAt(pos);
   
   switch (pos) {

      case 0: return myChar == 'F';
	  
	  case 1: return myChar == 'T'  || myChar == 'C' || myChar == 'U';
	  
	  case 2: return (!isNaN(myChar)) || myChar == 'C'  || myChar == 'D'  || myChar == 'L' || myChar == 'S' || myChar == 'X' || myChar =='G' || myChar =='O';
       
      case 3: return (!isNaN(myChar)) || myChar == 'W' || myChar == 'X' || myChar == 'S' || myChar =='A' || myChar == 'C' || myChar == 'N';
   
      case 4: return myChar == '-'; 

      default: return false;
   }  
		    
}

function SerialCheck() {
   var i, t, t1, s, s1='';

   // Evita di mostrare allerta su campi vuoti
   if (!document.SRequest.serial.value) return true;
   
   s  = document.SRequest.serial.value;
   s1 = s.toLowerCase();
   
   // Controllo sulla lunghezza del numero seriale
   // Nota: introdotto controllo per seriali Comex il 03/01/2008 (un carattere in meno)
   t = s.length;
   if (t < 13) { DisplaySerialError(); return; }
   

   // Controllo sui primi 5 caratteri del codice
   for (i = 0; i < 5; i++) {
       t = CharCheck(s, i);
       if (!t) { DisplaySerialError(); return; }
   }	   
   
   // Controllo sul codice restante
   t = (s.substr(5) == s1.substr(5));
   if (!t) { DisplaySerialError(); }     
}

function EmailCheck(emailfield1, emailfield2)
{
   var mytest, res='', emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
   
   if (emailfield2)
   {
		if (document.forms[0].elements[emailfield1].value == document.forms[0].elements[emailfield2].value) return true;        
		
		alert('Attenzione: gli indirizzi e-mail inseriti non sono uguali!');
      	document.forms[0].elements[emailfield1].value = "";        
		document.forms[0].elements[emailfield2].value = "";        
		document.forms[0].elements[emailfield2].focus();        
        return false;
   }

   // Evita di mostrare allerta su campi vuoti
   if (!document.forms[0].elements[emailfield1].value) return true;
/*   
   if (window.RegExp)
   {
		res  = new RegExp(emailAddress);
     	mytest = res.test(document.forms[0].elements[emailfield1].value);
   }	
   else
   {
		mytest = document.forms[0].elements[emailfield1].value.indexOf('@');
   }
*/   
   mytest = document.forms[0].elements[emailfield1].value.indexOf('@');
   
   if (!mytest)		
   {
		alert('Attenzione: l\'indirizzo e-mail non è valido!');
		document.forms[0].elements[emailfield1].value = "";        
		document.forms[0].elements[emailfield1].focus();        
        return false;
    } 
	
}
//-->