// JavaScript Document

var AlrTxt = "";

/* CONTROLLO EMAIL */
function FrmEml(id, txt, css)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(document.getElementById(id).value == ""){ AlrTxt = AlrTxt + txt + ': campo obbligatorio.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else if(reg.test(document.getElementById(id).value) == false) { AlrTxt = AlrTxt + txt + ': sembra non essere valido.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else{ document.getElementById(id).className = css + ' FrmOk'; }
}

/* CONTROLLO NUMERO */
function FrmNum(id, txt, css)
{
	var strValidChars = "0123456789,.-"; var strChar; var blnResult = true;
	for (i = 0; i < document.getElementById(id).value.length && blnResult == true; i++){ strChar = document.getElementById(id).value.charAt(i);if (strValidChars.indexOf(strChar) == -1){ blnResult = false;} }
	if (document.getElementById(id).value.length == 0){ AlrTxt = AlrTxt + txt + ': campo obbligatorio.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else if(blnResult == false){ AlrTxt = AlrTxt + txt + ': sembra non essere valido.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else{ document.getElementById(id).className = css + ' FrmOk'; }
}

/* CONTROLLO TESTO */
function FrmTxt(id, txt, css)
{
	if(document.getElementById(id).value == ""){ AlrTxt = AlrTxt + txt + ': campo obbligatorio.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else{ document.getElementById(id).className = css + ' FrmOk'; }
}

/* CONTROLLO SELECT */
function FrmSel(id, txt, css)
{
	if(document.getElementById(id)[document.getElementById(id).selectedIndex].value == ""){ AlrTxt = AlrTxt + txt + ': campo obbligatorio.\n'; document.getElementById(id).className = css + ' FrmKo'; return; }
	else{ document.getElementById(id).className = css + ' FrmOk'; }
}

/* CONTROLLO RADIO BUTTON */
function FrmRadBtn(name, txt)
{
	var blnResult = false;
	for(counter=0; counter<document.getElementsByName(name).length; counter++){ if (document.getElementsByName(name)[counter].checked){ blnResult = true; } }
	if(blnResult == false){ AlrTxt = AlrTxt + txt + ': selezionare un valore.\n'; return; }
}





/* CONTROLLO FORM REGISTRAZIONE */
function Chk_Registrati(action)
{
	FrmEml('eml','Email', 'FrmInp FrmSiz05');
	FrmTxt('nom','Nome', 'FrmInp FrmSiz05');
	FrmTxt('cog','Cognome', 'FrmInp FrmSiz05');
	
	/* Newsletter */
	FrmRadBtn('nsl', 'Newsletter');

	/* Privacy */
	FrmRadBtn('pry', 'Condizioni Generali e Privacy');
	if(document.getElementsByName('pry')[1].checked == true){ AlrTxt = AlrTxt + 'Condizioni Generali e Privacy: per effettuare la registrazione è necessario dare il proprio consenso.\n'; }
	
	if(AlrTxt != ""){ alert(AlrTxt); AlrTxt = ""; }
	else{ document.general.action = action; document.general.submit(); }
}

/* CONTROLLO FORM RECUPERO PASSWORD */
function Chk_Password(action)
{
	FrmEml('eml','Email', 'FrmInp FrmSiz05');
		
	if(AlrTxt != ""){ alert(AlrTxt); AlrTxt = ""; }
	else{ document.general.action = action; document.general.submit(); }
}

/* CONTROLLO FORM MODIFICA ACCOUNT */
function Chk_Modifica_Account(action)
{
	/* Dati Utente */
	if(document.getElementById('edtusr').value == "Y")
	{
		FrmTxt('nom','Nome', 'FrmInp FrmSiz05');
		FrmTxt('cog','Cognome', 'FrmInp FrmSiz05');
	}
	
	/* Dati Personali */
	if(document.getElementById('edtres').value == "Y")
	{
		FrmSel('id_naz','Nazione', 'FrmInp FrmSiz05');
		FrmSel('id_prv','Provincia', 'FrmInp FrmSiz05');
		FrmSel('id_com','Comune', 'FrmInp FrmSiz05');
		FrmTxt('codfis','Codice Fiscale', 'FrmInp FrmSiz05');
		FrmTxt('ind','Indirizzo', 'FrmInp FrmSiz05');
		FrmTxt('cap','CAP', 'FrmInp FrmSiz05');
		FrmTxt('tel','Telefono', 'FrmInp FrmSiz05');
	}
	
	/* Dati Aziendali */ 
	if(document.getElementById('edtazi').value == "Y")
	{
		FrmSel('azi_id_naz','Nazione', 'FrmInp FrmSiz05');
		FrmSel('azi_id_prv','Provincia', 'FrmInp FrmSiz05');
		FrmSel('azi_id_com','Comune', 'FrmInp FrmSiz05');
		FrmTxt('azi_ragsoc','Ragione Sociale', 'FrmInp FrmSiz05');
		FrmTxt('azi_pariva','Partita IVA', 'FrmInp FrmSiz05');
		FrmTxt('azi_codfis','Codice Fiscale', 'FrmInp FrmSiz05');
		FrmTxt('azi_ind','Indirizzo', 'FrmInp FrmSiz05');
		FrmTxt('azi_cap','CAP', 'FrmInp FrmSiz05');
		FrmTxt('azi_tel','Telefono', 'FrmInp FrmSiz05');
	}
	
	/*Password e Conferma Password */ 
	if(document.getElementById('edtpwd').value == "Y")
	{
		FrmTxt('regpwd','Password', 'FrmInp FrmSiz05');
		FrmTxt('cnfpwd','Conferma Password', 'FrmInp FrmSiz05');
		if(document.getElementById('regpwd').value != document.getElementById('cnfpwd').value){ AlrTxt = AlrTxt + 'Password e Conferma Password: i valori risultano diversi.\n'; document.getElementById('regpwd').className = 'FrmInp FrmSiz05 FrmKo'; document.getElementById('cnfpwd').className = 'FrmInp FrmSiz05 FrmKo'; }
		else{ document.getElementById('regpwd').className = 'FrmInp FrmSiz05 FrmOk'; document.getElementById('cnfpwd').className = 'FrmInp FrmSiz05 FrmOk'; }
	}
	
	if(AlrTxt != ""){ alert(AlrTxt); AlrTxt = ""; }
	else{ document.general.action = action; document.general.submit(); }
}
