// JavaScript Document

/* **************************Inizio regExpression***************************** */

function checkMail( strValue ) 
{
	var objRegExp = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	return objRegExp.test(strValue);
	
	
}

function checktesto( strValue ) 
{
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(mail)) 
		{
			alert('Inserisi un indirizzo Mail Valido');
			mail.focus
			return false;
		}else
		{ return true; }
}

function checkNumero( strValue ) 
{

	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

 	//check for numeric characters
  	return objRegExp.test(strValue);
}


function CheckEmpty( strValue ) 
{

   var strTemp = strValue;
   if(strTemp.length > 0)
   		return true;
			else
				return false;
}

function CheckCheckBox( checkbox )
 { 
	return checkbox.checked;	
}
/***************************Fine regExpression******************************/


function check_recupero_dati()
{
	
	var mail = document.getElementById('mail').value;
	if (checkMail(mail))
		{
			document.form_lost_data.action = 'recupera_dati.php';
			document.form_lost_data.submit();
		}
			else
				alert(main_non_valida);
}

function check_login_download()
{
	
	var user = document.getElementById('username').value;
	var pwd = document.getElementById('password').value;
	if ((CheckEmpty(user))&&(CheckEmpty(pwd)))
		{
			document.login.action = 'controlla_login_user.php';
			document.login.submit();
		}
			else
				alert(campi_vuoti);
}

function check_registration()
{
	var error = 0;
	var nome = document.getElementById('nome').value;
	var user = document.getElementById('username').value;
	var pwd = document.getElementById('password').value;
	var mail = document.getElementById('mail').value;
	var checkbox = document.getElementById('accettazione_contratto');

	if ( ( !CheckEmpty(nome) ) || ( !CheckEmpty(user) ) || ( !CheckEmpty(pwd) ) || ( !CheckEmpty(mail) ) )
		{ alert(campi_vuoti);
		  error = 1;
		  return;
		}
	
	( !CheckEmpty(user) )
	
	if (!checkMail(mail))
		{
		  alert(main_non_valida);
		  error = 1;
		  return;
		}
	
	if (!CheckCheckBox(checkbox))
		{ alert(accetta_contratto);
		  error = 1;
		  return;
		}
	
	//document.login.action = 'controlla_login_user.php';
	//document.login.submit();
	if (error == 0)
		{
			document.form_registrazione.action = 'registra_user.php';
			//document.form_registrazione.submit();
		}
}
