function dataValida(giorno,mese,anno) {
           var messaggio,sbagliato;
                    
           if ((mese==4) && (giorno>30)) {
              return false;
           }
           if ((mese==6) && (giorno>30)) {
              return false;
           }
           if ((mese==9) && (giorno>30)) {
               return false;
           }
           if ((mese==11) && (giorno>30)) {
               return false;
           }
           if (((anno % 100) == 0) && ((anno % 400) != 0) && (mese==2) && (giorno>28)) {
                 
                 return false;
           }
           if (((anno % 4) == 0) && (mese==2) && (giorno>29)) {
                  return false;
           }
           if (((anno % 4) != 0) && (mese==2) && (giorno>28)) {
                return false;
           }
                

		return true;
        }
/************************************
/* function ws_IsUsernameValid		*
/* descritpion : check username		*
/* comment : TODO if needed			*
*************************************/
function ws_IsUsernameValid(checkThisUsername)
{return true;}

/************************************
/* function ws_IsPasswordValid		*
/* descritpion : check password		*
/* comment : TODO if needed			*
*************************************/
function ws_IsPasswordValid(checkThisPassword)
{return true;}

/************************************
/* function ws_IsPICFValid			*
/* descritpion : check PI/CF		*
/* comment : TODO if needed			*
*************************************/
function ws_IsPICFValid(checkThisPICF)
{return true;}

/*************************************
/* function ws_IsEmailValid			 *
/* descritpion : check email address *
*************************************/
function ws_IsEmailValid(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


return myEMailIsValid
}



/************************
/* function setContent	*
/* descritpion :		*
************************/
function setContent(id)
{
	document.navigation1.id_content.value=id;
}



/****************************
/* function submitCarrello	*
/* descritpion :			*
*****************************/
function submitCarrello(form,lang)
{
	msg_ita="inserire una quantita positiva";
	msg_eng="insert positive quantity";
	msg_deu="inseriren quantitien positiven";

	if(lang=="ita") msg=msg_ita;
	else if (lang=="eng") msg=msg_eng;
	else if (lang=="deu") msg=msg_deu;

	cmd = 'if (document.' + form + '.quantita.value==null) local_quantita=0; else local_quantita=document.' + form + '.quantita.value;';
	eval(cmd);

	if (local_quantita > 0)
	{
		cmd='document.' + form + '.action = "trolley_add.php";';
		eval(cmd);
		cmd='document.' + form + '.submit();';
		eval(cmd);
	}
	else alert(msg);
	
}

//N.B.i parametri param, idProduct, idArea non sono utilizzati dalla funzione...
function submitPreferiti(form, param, idProduct, idArea)
{
	cmd='document.' + form + '.action = "favorite_add.php";';
	eval(cmd);
	cmd='document.' + form + '.submit();';
	eval(cmd);
}


/****************************
/* function ws_SubmitForm	*
/* descritpion :			*
*****************************/
function ws_SubmitForm(form)
{
	cmd='document.' + form + '.submit();';
	eval(cmd);
}


/************************************
/* function ws_SubmitFormWithAction	*
/* descritpion :					*
*************************************/
function ws_SubmitFormWithAction(form, action)
{
	cmd='document.' + form + '.action = "' + action + '";';
	eval(cmd);
	cmd='document.' + form + '.submit();';
	eval(cmd);
}


/************************************************
/* function ws_SubmitFormWithActionWithCheck	*
/* descritpion :								*
*************************************************/
function ws_SubmitFormWithActionWithCheck(form, lang, action, checkFunction)
{
	cmd="isFormChecked=" + checkFunction + "('" + form + "','" + lang + "');";
	eval(cmd);

	if (isFormChecked==true)
	{
		cmd='document.' + form + '.action = "' + action + '";';
		eval(cmd);
		cmd='document.' + form + '.submit();';
		eval(cmd);
	}
	
}


/********************************
/* function ws_checkUserReg1	*
/* descritpion :				*
*********************************/
function ws_CheckUserReg1(form, lang)
{
	//init var
	msg_error_bad_pi_cf_ita="partita iva/codice fiscale non valido";
	msg_error_bad_pi_cf_eng="partita iva/codice fiscale non valido";
	msg_error_bad_pi_cf_deu="partita iva/codice fiscale non valido";
	msg_error_bad_email_ita="indirizzo email non valido";
	msg_error_bad_email_eng="email addresses not valid";
	msg_error_bad_email_deu="email addresses not valid";
	msg_error_email_notequal_ita="gli indirizzi email non coincidono";
	msg_error_email_notequal_eng="email addresses does not ";
	msg_error_email_notequal_deu="type email addresses again";
	msg_error_privacy_ita="per continuare occorre aderire alla legge sulla privacy";
	msg_error_privacy_eng="to continue accept the User Agreement and Privacy Policy above";
	msg_error_privacy_deu="to continue accept the User Agreement and Privacy Policy above";
	

	msg_error_bad_birthdate_ita="data di nascita non valida";
	msg_error_bad_birthdate_eng="data di nascita non valida";
	msg_error_bad_birthdate_deu="data di nascita non valida";


	msg_error_bad_pi_cf="";
	msg_error_bad_email="";
	msg_error_email_notequal="";
	msg_error_privacy="";
	msg_erro_birthdate="";


	local_pi_cf="";
	local_email="";
	local_ridigita_email="";
	local_privacy="";
	
	//init error messages with correct language
	if (lang=="eng") 
	{
		msg_error_bad_pi_cf=msg_error_bad_pi_cf_eng;
		msg_error_bad_email=msg_error_bad_email_eng;
		msg_error_email_notequal=msg_error_email_notequal_eng;
		msg_error_privacy=msg_error_privacy_eng;
		msg_erro_birthdate=msg_error_bad_birthdate_eng;
	}
	else if (lang=="deu")
	{
		msg_error_bad_pi_cf=msg_error_bad_pi_cf_deu;
		msg_error_bad_email=msg_error_bad_email_deu;
		msg_error_email_notequal=msg_error_email_notequal_deu;
		msg_error_privacy=msg_error_privacy_deu;
		msg_erro_birthdate=msg_error_bad_birthdate_deu;
	}
	else(lang=="ita") 
	{
		msg_error_bad_pi_cf=msg_error_bad_pi_cf_ita;
		msg_error_bad_email=msg_error_bad_email_ita;
		msg_error_email_notequal=msg_error_email_notequal_ita;
		msg_error_privacy=msg_error_privacy_ita;
		msg_erro_birthdate=msg_error_bad_birthdate_ita;
	}

	//PARTITA IVA CODICE FISCALE
	//init partita iva/codice fiscale value
	cmd='local_pi_cf=document.' + form + '.piva_cf.value;';
	eval(cmd);
	
	//check if partita iva/codice fiscale are null
	/*
	if (local_pi_cf=="")
	{
		alert(msg_error_bad_pi_cf); 
		return false;
	}
	*/
	//check if partita iva/codice fiscale are correct
	if ( !(ws_IsPICFValid(local_pi_cf)) )
	{
		alert(msg_error_bad_pi_cf); 
		return false;
	}

	//EMAIL
	//init email value
	cmd='local_email=document.' + form + '.email.value;';
	eval(cmd);
	cmd='local_ridigita_email=document.' + form + '.ridigita_email.value;';
	eval(cmd);

	//check if email addresses are null
	if ( (local_email=="") || (local_ridigita_email=="") )
	{
		alert(msg_error_bad_email); 
		return false;
	}

	//check if email addresses are correct
	if ( !(ws_IsEmailValid(local_email)) || !(ws_IsEmailValid(local_ridigita_email)) )
	{
		alert(msg_error_bad_email); 
		return false;
	}
	
	//check if email addresse are equal
	if (local_email!=local_ridigita_email) 
	{
		alert(msg_error_email_notequal); 
		//error=1;
		return false;
	}

	//PRIVACY
	//check if privacy is null
	if (!(document.NewRecord1.privacy[0].checked))
	{
		alert(msg_error_privacy); 
		return false;
	}


	if (!(dataValida(document.NewRecord1.data_di_nascita_day.value,document.NewRecord1.data_di_nascita_month.value,document.NewRecord1.data_di_nascita_year.value))){
		alert ("Attenzione! La data del documento non è valida!");
		return false;
	}


	return true;
}


/********************************
/* function ws_checkUserReg2	*
/* descritpion :				*
*********************************/
function ws_CheckUserReg2(form, lang)
{
	//init var
	msg_error_bad_username_ita="username non valido";
	msg_error_bad_username_eng="username is not valid";
	msg_error_bad_username_deu="username is not valid";
	
	msg_error_bad_password_ita="password non valida";
	msg_error_bad_password_eng="password is not valid";
	msg_error_bad_password_deu="password is not valid";
	
	msg_error_password_notequal_ita="le password non coincidono";
	msg_error_password_notequal_eng="passwords does not match";
	msg_error_password_notequal_deu="passwords does not match";
	
	msg_error_bad_username="";
	msg_error_bad_password="";
	msg_error_password_notequal="";
	
	local_username="";
	local_password="";
	local_ridigita_password="";
	
	
	//init error messages with correct language
	if (lang=="eng") 
	{
		msg_error_bad_username=msg_error_bad_username_eng;
		msg_error_bad_password=msg_error_bad_password_eng;
		msg_error_password_notequal=msg_error_password_notequal_eng;
	}
	else if (lang=="deu")
	{
		msg_error_bad_username=msg_error_bad_username_deu;
		msg_error_bad_password=msg_error_bad_password_deu;
		msg_error_password_notequal=msg_error_password_notequal_deu;
	}
	else(lang=="ita") 
	{
		msg_error_bad_username=msg_error_bad_username_ita;
		msg_error_bad_password=msg_error_bad_password_ita;
		msg_error_password_notequal=msg_error_password_notequal_ita;
	}

	//init var
	cmd='local_username=document.' + form + '.username.value;';
	eval(cmd);
	cmd='local_password=document.' + form + '.password.value;';
	eval(cmd);
	cmd='local_ridigita_password=document.' + form + '.ridigita_password.value;';
	eval(cmd);

	//check if username is null
	if (local_username=="")
	{
		alert(msg_error_bad_username); 
		return false;
	}

	//check if username is correct
	if ( !(ws_IsUsernameValid(local_username)) )
	{
		alert(msg_error_bad_username); 
		return false;
	}

	//check if passwords are null
	if ( (local_password=="") || (local_ridigita_password=="") )
	{
		alert(msg_error_bad_password); 
		return false;
	}

	//check if passwords are correct
	if ( !(ws_IsPasswordValid(local_password)) || !(ws_IsPasswordValid(local_ridigita_password)) )
	{
		alert(msg_error_bad_password); 
		return false;
	}
	
	//check if passwords are equal
	if (local_password!=local_ridigita_password) 
	{
		alert(msg_error_password_notequal); 
		//error=1;
		return false;
	}
	
	return true;
}



/************************************
/* function ws_CheckUserDataAccess	*
/* descritpion :					*
*************************************/
function ws_CheckUserDataAccess(form, lang)
{
	//init var
	msg_error_bad_password_ita="password non valida";
	msg_error_bad_password_eng="password is not valid";
	msg_error_bad_password_deu="password is not valid";
	
	msg_error_password_notequal_ita="le password non coincidono";
	msg_error_password_notequal_eng="passwords does not match";
	msg_error_password_notequal_deu="passwords does not match";
	
	msg_error_bad_password="";
	msg_error_password_notequal="";
	
	local_password="";
	local_ridigita_password="";
	
	
	//init error messages with correct language
	if (lang=="eng") 
	{
		msg_error_bad_password=msg_error_bad_password_eng;
		msg_error_password_notequal=msg_error_password_notequal_eng;
	}
	else if (lang=="deu")
	{
		msg_error_bad_password=msg_error_bad_password_deu;
		msg_error_password_notequal=msg_error_password_notequal_deu;
	}
	else(lang=="ita") 
	{
		msg_error_bad_password=msg_error_bad_password_ita;
		msg_error_password_notequal=msg_error_password_notequal_ita;
	}

	//init var
	cmd='local_password=document.' + form + '.password.value;';
	eval(cmd);
	cmd='local_ridigita_password=document.' + form + '.ripeti_password.value;';
	eval(cmd);

	//check if passwords are null
	if ( (local_password=="") || (local_ridigita_password=="") )
	{
		alert(msg_error_bad_password); 
		return false;
	}

	//check if passwords are correct
	if ( !(ws_IsPasswordValid(local_password)) || !(ws_IsPasswordValid(local_ridigita_password)) )
	{
		alert(msg_error_bad_password); 
		return false;
	}
	
	//check if passwords are equal
	if (local_password!=local_ridigita_password) 
	{
		alert(msg_error_password_notequal); 
		//error=1;
		return false;
	}
	
	return true;
}



/************************************
/* function ws_checkActivityDetail	*
/* descritpion :					*
*************************************/
function ws_checkActivityDetail(form, lang)
{
	//init var
	msg_error_bad_quantita_ita="inserire una quantita positiva";
	msg_error_bad_quantita_eng="insert a positive quantity";
	msg_error_bad_quantita_deu="insert a positive quantity";
	msg_error_bad_quantita="";
	local_quantita="";
	
	//init error messages with correct language
	if (lang=="eng") 
	{
		msg_error_bad_quantita=msg_error_bad_quantita_eng;
	}
	else if (lang=="deu")
	{
		msg_error_bad_quantita=msg_error_bad_quantita_deu;
	}
	else(lang=="ita") 
	{
		msg_error_bad_quantita=msg_error_bad_quantita_ita;
	}

	//init email value
	cmd='local_quantita=document.' + form + '.quantita.value;';
	eval(cmd);
	
	//check if email addresses are null
	if ( (local_quantita=="") || (isNaN(local_quantita)) || (local_quantita<0) )
	{
		alert(msg_error_bad_quantita); 
		return false;
	}

	return true;
}


/********************************
/* function ws_CheckLoginRequestPWD	*
/* descritpion :				*
*********************************/
function ws_CheckLoginRequestPWD(form, lang)
{
	//init var
	msg_error_bad_email_ita="indirizzo email non valido";
	msg_error_bad_email_eng="email addresses not valid";
	msg_error_bad_email_deu="email addresses not valid";
	
	msg_error_bad_email="";
	
	local_email="";
	
	//init error messages with correct language
	if (lang=="eng") 
	{
		msg_error_bad_email=msg_error_bad_email_eng;
	}
	else if (lang=="deu")
	{
		msg_error_bad_email=msg_error_bad_email_deu;
	}
	else(lang=="ita") 
	{
		msg_error_bad_email=msg_error_bad_email_ita;
	}


	//EMAIL
	//init email value
	cmd='local_email=document.' + form + '.email.value;';
	eval(cmd);
	
	//check if email addresses are null
	if (local_email=="")
	{
		alert(msg_error_bad_email); 
		return false;
	}

	//check if email addresses are correct
	if ( !(ws_IsEmailValid(local_email)) )
	{
		alert(msg_error_bad_email); 
		return false;
	}
	

	return true;
}
