//funzione GV_checkform v 1.00 : controlla se i campi sono vuoti e la sintassi del campo EMAIL

/* ISTRUZIONI:
Associare la chiamata al metodo "GV_checkform()" all'evento onclick del "button" che invia i dati al server.
Non utilizzare submit.
I parametri che prende in input sono: il primo è l'id della form, il resto dei parametri sono gli id dei campi obbligatori.
Inserire su ogni TAG <STRONG> l'id "labelID_CAMPO". ESEMPIO: se il campo ha id=NOME allora il tag STRONG avrà id=labelNOME
Per qualsiasi problema contattare l'autore dello script vincent2784@virgilio.it
*/


function GV_checkform() {
  var a=GV_checkform.arguments;
  var check=true; 
  for (i=1; i<a.length; i++)
  {
	  var temp = document.getElementById(a[i]).value;
		//alert (document.getElementById(a[i]).className)

    	if ((temp == "")||(temp == "null")) {
			document.getElementById(a[i]).className='campoFormError';
     	 	check=false;
   		}
    	else if (a[i] == 'Mail') {
			var pattern=/^[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$/;
        	if (temp.search(pattern) == -1) {
				document.getElementById(a[i]).className="campoFormError";
          		check=false;
        	} else document.getElementById(a[i]).className="campoForm";
    	}
		else if (a[i] == 'Telefono1') {
   	  		var pattern2=/[0-9]$/;
			if (temp.search(pattern2) == -1) {
				document.getElementById(a[i]).className="campoFormError";
				check=false;
			} else document.getElementById(a[i]).className="campoForm";
		}
		else {
			document.getElementById(a[i]).className="campoForm";
    	}
	
  }
  
  
  
  if (check) /*alert ("faccio submit")*/ document.getElementById(a[0]).submit();
  else 
  	if (document.getElementById('ALERT') != null )
		document.getElementById('ALERT').innerHTML="Controlla i campi in ROSSO"
}
