//inizializza immagini
/*
P_mn_home_up = new Image();	P_mn_home_up.src = "imago/P_mn_home_up.gif";
P_mn_home_dn = new Image();	P_mn_home_dn.src = "imago/P_mn_home_dn.gif";
P_mn_info_up = new Image();	P_mn_info_up.src = "imago/P_mn_info_up.gif";
P_mn_info_dn = new Image();	P_mn_info_dn.src = "imago/P_mn_info_dn.gif";
P_mn_stat_up = new Image();	P_mn_stat_up.src = "imago/P_mn_stat_up.gif";
P_mn_stat_dn = new Image();	P_mn_stat_dn.src = "imago/P_mn_stat_dn.gif";
P_mn_soci_up = new Image();	P_mn_soci_up.src = "imago/P_mn_soci_up.gif";
P_mn_soci_dn = new Image();	P_mn_soci_dn.src = "imago/P_mn_soci_dn.gif";
P_mn_cong_up = new Image();	P_mn_cong_up.src = "imago/P_mn_cong_up.gif";
P_mn_cong_dn = new Image();	P_mn_cong_dn.src = "imago/P_mn_cong_dn.gif";
P_mn_grup_up = new Image();	P_mn_grup_up.src = "imago/P_mn_grup_up.gif";
P_mn_grup_dn = new Image();	P_mn_grup_dn.src = "imago/P_mn_grup_dn.gif";
P_mn_prem_up = new Image();	P_mn_prem_up.src = "imago/P_mn_prem_up.gif";
P_mn_prem_dn = new Image();	P_mn_prem_dn.src = "imago/P_mn_prem_dn.gif";
P_mn_ital_up = new Image();	P_mn_ital_up.src = "imago/P_mn_ital_up.gif";
P_mn_ital_dn = new Image();	P_mn_ital_dn.src = "imago/P_mn_ital_dn.gif";
*/

P_mn_home_up = new Image();	P_mn_home_up.src = "imago/P_mn_home_up.gif";
P_mn_home_dn = new Image();	P_mn_home_dn.src = "imago/P_mn_home_dn.gif";

P_mn_info_up = new Image();	P_mn_info_up.src = "imago/P_mn_info_up.png";
P_mn_info_dn = new Image();	P_mn_info_dn.src = "imago/P_mn_info_dn.png";

P_mn_cong_up = new Image();	P_mn_cong_up.src = "imago/P_mn_cong_up.gif";
P_mn_cong_dn = new Image();	P_mn_cong_dn.src = "imago/P_mn_cong_dn.gif";

P_mn_grup_up = new Image();	P_mn_grup_up.src = "imago/P_mn_grup_up.gif";
P_mn_grup_dn = new Image();	P_mn_grup_dn.src = "imago/P_mn_grup_dn.gif";

P_mn_news_up = new Image();	P_mn_news_up.src = "imago/P_mn_news_up.gif";
P_mn_news_dn = new Image();	P_mn_news_dn.src = "imago/P_mn_news_dn.gif";

P_mn_link_up = new Image();	P_mn_link_up.src = "imago/P_mn_link_up.gif";
P_mn_link_dn = new Image();	P_mn_link_dn.src = "imago/P_mn_link_dn.gif";

P_mn_special_up = new Image();	P_mn_special_up.src = "imago/P_mn_special_up.png";
P_mn_special_dn = new Image();	P_mn_special_dn.src = "imago/P_mn_special_dn.png";

P_mn_forum_up = new Image();	P_mn_forum_up.src = "imago/P_mn_forum_up.png";
P_mn_forum_dn = new Image();	P_mn_forum_dn.src = "imago/P_mn_forum_dn.png";

//metti il nome del file nella variabile: sNomeFile
	var sNomeFile
	//becca percorso
		sPercorso = sNomeFile = location.href;
		//estrai nome file
		re = /\//;
		do {
			xyz=sNomeFile.search(re)
			sNomeFile=sNomeFile.slice(xyz+1)
		} while (xyz>-1);
		
		

		
 
function InserisciMenu()
{
	//recupera il valore di lingua dalla querystring
	var lingua;	
	lingua = "ita";
	
	//home page
	document.write ("<a href=\"index.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_home','P_mn_home_dn')\" onmouseout=\"ScambiaImago('P_mn_home','P_mn_home_up');\">");
	document.write ("<img src=\"imago/P_mn_home_up.gif\" border=\"0\" name=\"P_mn_home\"></a><br />");

	//info
	if (sNomeFile == "info.php")
	{
		document.write ("<img src=\"imago/P_mn_info_dn.gif\" border=\"0\" name='P_mn_info'><br />");
	}
	else
	{
		document.write ("<a href=\"info.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_info','P_mn_info_dn')\" onmouseout=\"ScambiaImago('P_mn_info','P_mn_info_up');\">");
		document.write ("<img src=\"imago/P_mn_info_up.gif\" border=\"0\" name='P_mn_info' alt='Contatti, statuto, elenco probiviri, elenco delle Neurochirurgie Italiane...'></a><br />");
	}

	//eventi
	if (sNomeFile == "eventi.php")
	{
		document.write ("<img src=\"imago/P_mn_cong_dn.gif\" border=\"0\" name='P_mn_cong'><br />");
	}
	else
	{
		document.write ("<a href=\"eventi.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_cong','P_mn_cong_dn')\" onmouseout=\"ScambiaImago('P_mn_cong','P_mn_cong_up');\">");
		document.write ("<img src=\"imago/P_mn_cong_up.gif\" border=\"0\" name='P_mn_cong' alt='Congressi e Corsi organizzati e/o patrocinati dalla SINch'></a><br />");
	}

	//gruppi
	if (sNomeFile == "gruppi.php")
	{
		document.write ("<img src=\"imago/P_mn_grup_dn.gif\" border=\"0\" name='P_mn_grup'><br />");
	}
	else
	{
		document.write ("<a href=\"gruppi.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_grup','P_mn_grup_dn')\" onmouseout=\"ScambiaImago('P_mn_grup','P_mn_grup_up');\">");
		document.write ("<img src=\"imago/P_mn_grup_up.gif\" border=\"0\" name='P_mn_grup' alt='Gruppi di Studio' /></a><br />");
	}

	//news
	if (sNomeFile == "news.php")
	{
		document.write ("<img src=\"imago/P_mn_news_dn.gif\" border=\"0\" name=\"P_mn_news\"><br />");
	}
	else
	{
		document.write ("<a href=\"news.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_news','P_mn_news_dn')\" onmouseout=\"ScambiaImago('P_mn_news','P_mn_news_up');\">");
		document.write ("<img src=\"imago/P_mn_news_up.gif\" border=\"0\" name='P_mn_news' alt='Avvisi, comunicazioni urgenti e novitą' /></a><br />");
	}

	//link
	if (sNomeFile == "link.php")
	{
		document.write ("<img src=\"imago/P_mn_link_dn.gif\" border=\"0\" name='P_mn_link'><br />");
	}
	else
	{
		document.write ("<a href=\"link.php?l=" + lingua  +  "\" onmouseover=\"ScambiaImago('P_mn_link','P_mn_link_dn')\" onmouseout=\"ScambiaImago('P_mn_link','P_mn_link_up');\">");
		document.write ("<img src=\"imago/P_mn_link_up.gif\" border=\"0\" name='P_mn_link' alt='Link di interesse medico e non'></a><br />");		
	}

}


function ScambiaImago(imgName,imgVar)
{
	ijk = eval(imgVar + ".src");
	document [imgName].src = ijk;
}

function apriFinestra(nomefile) {
window.open(nomefile,"pop","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=630,height=500");
}

function apriFinestraPiccola(nomefile) {
window.open(nomefile,"pop","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=400,height=200");
}


//
function controlla_modulo_utente(ilmodulo) 
{
	msg="\nIl campo obbligatorio non compilato.\n\n" + "Per favore, inserisci il " + ilmodulo.nome.name + "."
	
	
	//campi obbligatori
	if (ilmodulo.nome.value == ""){
	   alert("\nIl campo obbligatorio non compilato.\n\n" + "Per favore, inserisci il nome.")
	   ilmodulo.nome.focus();
	   return false;
	}
	if (ilmodulo.cognome.value == ""){
	   alert("\nIl campo obbligatorio non compilato.\n\n" + "Per favore, inserisci il cognome.")
	   ilmodulo.cognome.focus();
	   return false;
	}   

	if (ilmodulo.user_email.value == ""){
	   alert("\nIl campo obbligatorio non compilato.\n\n" + "Per favore, inserisci un indirizzo e-mail.")
	   ilmodulo.email.focus();
	   return false;
	}
	if (ilmodulo.username.value == ""){
	   alert("\nIl campo obbligatorio non compilato.\n\n" + "Per favore, inserisci un Nome Utente.")
	   ilmodulo.username.focus();
	   return false;
	} 
	/*		
	//controllo email
//	if (ilmodulo.user_email.value.indexOf ('@',0)  == -1 || ilmodulo.user_email.value.indexOf ('.',0)  == -1){
//		alert("\nErrore nella compilazione del campo e-mail.")
//		ilmodulo.user_email.focus();
//		return false;
//	}

	*/

	
	//se tutte le condizioni sono OK parte il form
    return true;
}

//
//o'reilly
// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}



function verifica(il_modulo) {
	//Verifica che i campi obbligatori	siano compilati
	// This is the function that performs form verification. It is invoked
	// from the onsubmit event handler. The handler should return whatever
	// value this function returns.
    var msg;
    var empty_fields = "";
    var errors = "";
    
    //
    var questo_campo = "";
    //Costruzione di un array per associare i nomi interni degli elementi di un form a nomi comprensibili all'utente
    //Questo array dovra' contenere tutti i nomi dei campi valutati in tutti i form  del sito
    //modulo_utente
    var nome = new Array ( 'nome' ,' Nome');
    var cognome = new Array ( 'cognome' , 'Cognome');
    var user_email = new Array ( 'user_email' , 'Indirizzo e-mail');
    var username = new Array ( 'username' , 'Nome Utente');
    var new_password = new Array ( 'new_password' , 'Password');
	var password_confirm = new Array ( 'password_confirm' , 'Conferma Password');
	var socio_presentatore_1 = new Array ( 'socio_presentatore_1' , 'Socio presentatore 1');
	var socio_presentatore_2 = new Array ( 'socio_presentatore_2' , 'Socio presentatore 2');
	var ente_nome = new Array ('ente_nome' , 'Ente di appartenenza');
	var ente_via = new Array ('ente_via' , 'Indirizzo Ente');
	var ente_cap = new Array ('ente_cap' , 'Indirizzo Ente, CAP');
	var ente_citta = new Array ('ente_citta' , 'Indirizzo Ente, Cittą');
	var ente_tel = new Array ('ente_tel' , 'Telefono Ente');
	var indirizzo = new Array ('indirizzo' , 'Indirizzo privato');
	var cap = new Array ('cap' , 'Indirizzo privato, CAP');
	var citta = new Array ('citta' , 'Indirizzo privato, citta');
	var tel = new Array ('tel' , 'Telefono privato');
	//modulo_cognome_partecipanti.php
	var cognome_partecipante = new Array ( 'cognome_partecipante' , 'Cognome del nuovo partecipante'); 
	//modulo_cognome_coor
	var cognome_coor = new Array ( 'cognome_coor' , 'Cognome del coordinatore');
	//modulo_login
	var uname = new Array ( 'uname' , 'Nome Utente');
	var passw = new Array ( 'passw' , 'Password');
	
	    
    //array di array con i nomi dei campi 
    //l'ordine e' lo stesso delle variabili definite qui sopra
    var nomi_campi = new Array (
    					nome , cognome, user_email, username
    					,new_password , password_confirm
    					,cognome_partecipante , cognome_coor
    					,uname , passw
    					,socio_presentatore_1 , socio_presentatore_2
    					,ente_nome , ente_via , ente_cap , ente_citta , ente_tel
    					,indirizzo, cap, citta, tel
    				);
    //usato da modulo_utente.php

    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // verify that they are numbers and in the right range.
    // If the element has a "numeric" property defined, verify that
    // it is a number, but don't check its range.
    // Put together error messages for fields that are wrong.
    
    //Ciclo attraverso gli elemento del form alla ricerca degli elemento text e textarea
    //che hanno la proprieta' "obbligatorio" definita.
    //Poi controlla tra questi i campi vuoti e fa una lista.
    //
    for(var i = 0; i < il_modulo.length; i++) {
        var e = il_modulo.elements[i];
        
        //controllo campi testo
        if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && e.obbligatorio) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
	            //empty_fields += "\n          " + e.name;
	            for(var j = 0; j < nomi_campi.length; j++) {
		            if (e.name ==  nomi_campi[j][0]){
			            questo_campo = nomi_campi[j][1];
			        }
				}
		         empty_fields += "\n          " + questo_campo;            
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) { 
                var v = parseFloat(e.value);
                if (isNaN(v) || 
                    ((e.min != null) && (v < e.min)) || 
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null) 
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null) 
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
		}
		
		//Controlli password 
		if (e.type == "password")  {
			
				if ( ((e.cambiapassi) || (e.confermapassi) ) && (e.value != "")  ) {
					//se e' stata digitata una nuova pw controlla se e' stata digitata anche la vecchia password		
					if ((il_modulo.cur_password.value == null) || (il_modulo.cur_password.value == "") || isblank(il_modulo.cur_password.value)) {
						errors += "E' necessario digitare la vecchia password per impostarne una nuova.\n";
					}	
					
					//controlla se la nuova password non e' vuota o nulla
					 if (   (il_modulo.new_password.value == null) || (il_modulo.new_password.value == "") || isblank(il_modulo.new_password.value)   ) {
							errors += "Non e' stata impostata la nuova password.\n";
					}
					
					//controlla se la conferma della password  non e' vuota o nulla
					 if (   (il_modulo.password_confirm.value == null) || (il_modulo.password_confirm.value == "") || isblank(il_modulo.password_confirm.value)   ) {
							errors += "La nuova password non e' stata confermata.\n";
					}
															
					//controlla se le due nuove password sono uguali	
					if (  (il_modulo.password_confirm.value != il_modulo.password_confirm.value)  ) {
							errors += "Le due nuove password digitate sono diverse.\n";
					}							
				}		
							
					
			//controlla se le due nuove password sono uguali	
				if ( (e.checkpassi) && (e.value != il_modulo.password_confirm.value) ) {
						errors += "Le due nuove password digitate sono diverse";
				}						
		}
		

    }

    //Se ci sono errori  restituisce FALSE e mostra i messaggi di errore.
    //Altrimenti restituisce TRUE
    if (!empty_fields && !errors) return true;

		msg  = "______________________________________________________\n\n"
		//msg += "The form was not submitted because of the following error(s).\n";
		//msg += "Please correct these error(s) and re-submit.\n";
		msg += "Il modulo non e' stato spedito a causa di errori di compilazione.\n";
		msg += "Per favore correggere gli errori e ri-sottomettere il modulo.\n";
		msg += "______________________________________________________\n\n"


    if (empty_fields) {
        msg += "- I campi obbligatori seguenti sono vuoti:"
        //msg += "- The following required field(s) are empty:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}
//fine o'reilly
