
// start functii pentru verificarea corectitudinii datelor introduse in formular
var mail = /^[a-zA-Z0-9]+[-_.\a-zA-Z0-9\.-_]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
//var mail = /^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,4}$/i;
function verifyEmail(champs) 
{
     reponse = mail.test(champs.value)
//	 alert(reponse);
     if (reponse) 
	 {
         return true;
     }
     else 
	 {         
         return false;
     }
}
function changeCase()
{
	//	alert("da");
	this.document.formular_oferta_pf.email.value = this.document.formular_oferta_pf.email.value.toLowerCase();
}
function check_fields()
{
   var ok				= true; // confirmare introducere corecta a datelor
   var err_nume			= 0; // eroare introducere numele
   var err_prenume		= 0; // eroare introducere prenumele
   var err_cnp			= 0; // eroare introducere CNP
   var err_tel			= 0; // eroare introducere telefon
   var err_fax			= 0; // eroare introducere fax    
   var err_email		= 0; // eroare introducere email

   	     
   var 	mesaj =   "_______________________________________     \n\n";
	mesaj += "Va rugam sa corectati erorile din lista de mai jos!  \n";
	mesaj += "_______________________________________     \n\n";

	if (this.document.formular_oferta_pf.numele.value.length == 0 )
	{
		mesaj += " -   Introduceti numele.\n";
		err_nume = 1;
		ok = false;
	}
	if (this.document.formular_oferta_pf.prenumele.value == "" )
	{
		mesaj += " -   Introduceti prenumele.\n";
		err_prenume = 1;
		ok = false;
	}
	
	if (this.document.formular_oferta_pf.cnp.value != "" )
	{
		if (isNaN(this.document.formular_oferta_pf.cnp.value))
		{
			mesaj += " -   Introduceti doar cifre pentru CNP.\n";
			err_cnp = 1;
			ok = false;
		}
		if (this.document.formular_oferta_pf.cnp.value.length != 13 & err_cnp != 1)
		{
			mesaj += " -   Introduceti 13 cifre pentru CNP.\n";
			err_cnp = 1;
			ok = false;
		}
		if(this.document.formular_oferta_pf.cnp.value.substring(0, 1) != 1 & this.document.formular_oferta_pf.cnp.value.substring(0, 1) != 2)
		{
			mesaj += " -   Prima cifra pentru CNP trebuie sa fie 1 sau 2.\n";
			err_cnp = 1;
			ok = false;		
		}
		if(this.document.formular_oferta_pf.cnp.value.substring(1, 3) > 90 )
		{
			mesaj += " -   CNP incorect (anul).\n";
			err_cnp = 1;
			ok = false;		
		}
		if(this.document.formular_oferta_pf.cnp.value.substring(3, 5) <= 0 || this.document.formular_oferta_pf.cnp.value.substring(3, 5) > 12 )
		{
			mesaj += " -   CNP incorect (luna).\n";
			err_cnp = 1;
			ok = false;		
		}
		if(this.document.formular_oferta_pf.cnp.value.substring(5, 7) <= 0 || this.document.formular_oferta_pf.cnp.value.substring(5, 7) > 31 )
		{
			mesaj += " -   CNP incorect (ziua).\n";
			err_cnp = 1;
			ok = false;		
		}		
		
	}

	if (this.document.formular_oferta_pf.telefon.value != "" )
	{
		if (isNaN(this.document.formular_oferta_pf.telefon.value) )
		{
			mesaj += " -   Numarul de telefon este incorect.\n";
			err_tel = 1;
			ok = false;
		}
		
	}
	
	if (this.document.formular_oferta_pf.fax.value != "" )
	{
		if (isNaN(this.document.formular_oferta_pf.fax.value))
		{
			mesaj += " -   Numarul de fax este incorect.\n";
			err_fax = 1;
			ok = false;
		}
		
	}		
	
	if (!verifyEmail(this.document.formular_oferta_pf.email) )
	{
		mesaj += " -   Introduceti o adresa de email valida!\n";
		err_email = 1;
		ok = false;
	}
	
/*
alert('anul: '+this.document.formular_oferta_pf.cnp.value.substring(1, 3));
alert('luna: '+this.document.formular_oferta_pf.cnp.value.substring(3, 5));
alert('ziua: '+this.document.formular_oferta_pf.cnp.value.substring(5, 7));
*/
			
   if(ok)
   {
	 return true;
   }
   else
   {
   	 alert(mesaj);

		if(err_nume == 1)
		{
			this.document.formular_oferta_pf.numele.select();
			return false;
		}

		if(err_prenume == 1)
		{
			this.document.formular_oferta_pf.prenumele.select();
			return false;
		}

		if(err_cnp == 1)
		{
			document.formular_oferta_pf.cnp.select();
			return false;
		}
		
		if(err_tel == 1)
		{
			document.formular_oferta_pf.telefon.select();
			return false;
		}

		if(err_fax == 1)
		{
			document.formular_oferta_pf.fax.select();
			return false;
		}
										
		if(err_email == 1)
		{
			document.formular_oferta_pf.email.select();		
			return false;
		}			

	
		 return false;
	}

}
// end

