/*	File: script.js
	Author: Marco Adami - marco.adami@ieee.org
	
	Description:
	
	- adjust
		Sistema gli stili CSS per essere visualizzati correttamente da IE.

	- function VerificaModulo(f) 
		Controlla il modulo d'iscrizione prima di inviare i dati.
		
	- function VerificaLogin(f) 
		Controlla i dati per effettuare il login nelle pagine di amministrazione.
		
	- function VerificaNuovaPassword(f) 
		Controlla i dati prima di cambiare la password dell'utente.
		
	- function VerificaModuloPartecipazione(f) 
		Controlla i dati immessi nel modulo di partecipazione.
		
*/


/******  M O D I F I C A    S T I L I  ******/

ok = (document.styleSheets) ? 1 : 0;
IE = ((ind1 = navigator.appVersion.indexOf("MSIE")) > -1) ? 1 : 0;
IE4 = (IE && document.all) ? 1:0;

if(ok) 
	if(IE4) stile = document.styleSheets[0].rules

function adjust() 
{
	if(ok) 
	{
		stile[4].style.left = 1 + 'px';	
		stile[5].style.left = 1 + 'px';	
		stile[6].style.left = 1 + 'px';	
		stile[9].style.left = 451 + 'px';	
		stile[10].style.left = 8 + 'px';	
	}
	else
  		alert("l'oggetto styleSheets\nNON\nč supportato")
}


/******  C O N T R O L L O   D E L   M O D U L O   I S C R I Z I O N E  *****/

var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/
	
function Maiuscola(s) 
{
    s.value = s.value.charAt(0).toUpperCase() + s.value.substr(1, s.value.length)
}
	
function VerificaModulo(f) 
{
	if (f.nome.value == "") 
	{
		alert("Attenzione: il campo Nome e' obbligatorio.")
	    f.nome.focus()
	    return false
	}
    if (f.cognome.value == "") 
    {
        alert("Attenzione: il campo Cognome e' obbligatorio.")
        f.cognome.focus()
        return false
    }
    if (f.email.value == "") 
    {
        alert("Attenzione: il campo Email e' obbligatorio.")
        f.email.focus()
        return false
    }
    else if (!email_reg_exp.test(f.email.value))
    {
        alert("Attenzione: l'indirizzo Email non e' corretto.")
        f.email.select()
        return false 
    }
    if (f.provincia.value == "") 
    {
        alert("Attenzione: il campo Provincia e' obbligatorio.")
        f.provincia.focus()
        return false
    }
    return true
}


/******  C O N T R O L L O   D E L   L O G I N  *****/

function VerificaLogin(f) 
{
	if (f.login.value == "") 
	{
		alert("Attenzione: e' necesario inserire una login.")
	    f.login.focus()
	    return false
	}
    if (f.pass.value == "") 
    {
        alert("Attenzione: e' necesario inserire una password.")
        f.pass.focus()
        return false
    }
    return true
}


/******  C O N T R O L L O   D E L L A   N U O V A   P A S S W O R D  *****/

function VerificaNuovaPassword(f) 
{
	if (f.oldPassword.value == "") 
	{
		alert("Attenzione: e' necesario inserire la vecchia password.")
	    f.oldPassword.focus()
	    return false
	}
    if (f.newPassword.value == "") 
    {
        alert("Attenzione: La nuova password deve contenere almeno un carattere alfanumerico.")
        f.newPassword.focus()
        return false
    }
    if (f.checkPassword.value == "") 
    {
        alert("Attenzione: Nel campo Verifica e' necessario introdurre nuovamente la nuova password.")
        f.checkPassword.focus()
        return false
    }
    if (f.checkPassword.value != f.newPassword.value) 
    {
        alert("Attenzione: La nuova password e la verifica non coincidono.")
        f.checkPassword.focus()
        return false
    }
    return true
}


/******  C O N T R O L L O   D E L   M O D U L O   P A R T E C I P A Z I O N E  *****/

function VerificaModuloPartecipazione(f) 
{
	if (f.nome.value == "") 
	{
		alert("Attenzione: il campo Nome e' obbligatorio.")
	    f.nome.focus()
	    return false
	}
    if (f.cognome.value == "") 
    {
        alert("Attenzione: il campo Cognome e' obbligatorio.")
        f.cognome.focus()
        return false
    }
    if (f.email.value == "") 
    {
        alert("Attenzione: il campo Email e' obbligatorio.")
        f.email.focus()
        return false
    }
    else if (!email_reg_exp.test(f.email.value))
    {
        alert("Attenzione: l'indirizzo Email non e' corretto.")
        f.email.select()
        return false 
    }
    return true
}
