var win_wf = null;
function OpenWebFiction(url)
{
	var width = window.screen.width
  var height = window.screen.height  

	if (win_wf != null && !win_wf.closed) { win_wf.close(); }
	win_wf = window.open(url,"popup_webfiction","top=0,left=0,status=yes,location=no,titlebar=yes,toolbar=no,menubar=no,width=" + (width-10) + ",height=" + (height-75));
  return;
}
//-- gestione visualizzazione approfondisci in homepage-------------------------------------------------------------
function ShowApprofondisci(){
	if (GetProp("tabApprofondisci",true,"display") == "none") {
		SetProp("tabApprofondisci",true,"display","");
		SetProp("app_button",false,"src","../../../../images/html/ok_button.jpg");
	} else {
		SetProp("tabApprofondisci",true,"display","none");
		SetProp("app_button",false,"src","../../../../images/html/cont_button.jpg");
	}
}
//-- gestione visualizzazione aree catalogo-------------------------------------------------------------
function ShowAree(pkt){
	// in attesa che decidano se i corsi verranno pubblicati anche all'interno delle tipologie (primo livello del catalogo)
	// e non solo nelle aree di contenuto, gestisco l'apertura della sezione scelta chiudendo le altre
	// in caso decidessero di attivare anche le tipologie decommentare il codice sottostante
	document.forms[0].elements["tipo"].value = "1";
	document.forms[0].elements["pkt"].value = pkt;
	document.forms[0].elements["pka"].value = "";
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
	return;
}
function isTabVis(pkt) {
	// verifico se il tab indicato è visibile o meno
	return (GetProp("tabAree"+pkt,true,"display") != "none");
}
function setClassName(pkt,sel,out){
	if (out && isTabVis(pkt)) return;
	SetProp("tdAreeCn"+pkt,false,"className","sezioniaree"+sel);
}
function lanciaListaCorsi(pkt,pka) {
	document.forms[0].elements["tipo"].value = "4"; //1
	document.forms[0].elements["pkt"].value = pkt;
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function apriDettaglioNotizia(area,desc_area) {
	document.forms[0].elements["tipo"].value = "9";
	document.forms[0].elements["area"].value = area;
	document.forms[0].elements["desc_area"].value = desc_area;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
//-- gestione calendario -----------------------------------------
var linkGiorno = new Array();
var linkGiornoOK = false;
var et = null;
var win_cal = null;

function showDayLinkNew(serverName,data,obj) {
	//per motivi di spazio visualizzo la lista dei corsi in un popup
	if (win_cal != null && !win_cal.closed) { win_cal.close(); }
	win_cal = window.open("popup_calendar.asp?serverName="+serverName+"&data="+data,"popup_calendar","statusbar,menubar=no,height=300,width=300,top="+(screen.height/2));
}
function showDayLink(index,top,left) {
  //procedo solo se il caricamento dei link nell'apposito array è stata completata
  if (linkGiornoOK) {
  	//inserisco la lista di link del div di popup corsi e lo visualizzo
  	document.getElementById("oLink").innerHTML = linkGiorno[index];
  	document.getElementById("oLink").style.display = "";
  //alert(document.getElementById("oLink").offsetLeft+"-"+left+"-"+document.getElementById("oLink").clientWidth);
    var extra_left = ((document.getElementById("oLink").clientWidth>200)?(parseInt(document.getElementById("oLink").offsetLeft/10)):30);
  	document.getElementById("oLink").style.top = (top+15).toString()+"px";
  	document.getElementById("oLink").style.left = (left-extra_left).toString()+"px"; // ((document.getElementById("oLink").clientWidth>0)?document.getElementById("oLink").clientWidth/2+extra_left:extra_left)
  }
}
function stopHideDayLink() {
	window.clearTimeout(et);
}
function hideDayLink() {
	et = window.setTimeout(hideDayLink2, 1000);
}
function hideDayLink2() {
	document.getElementById("oLink").style.display = "none";
}
function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
function setParentParam(anno,mese) {
	document.forms[0].elements["anno"].value = anno;
	document.forms[0].elements["mese"].value = mese;
	document.forms[0].submit();
}
function setCalClassName(pk,up){
	var objName = "td"+pk;
	SetProp(objName,false,"className","giorno"+up);
}
//-- gestione scheda corso -----------------------------------------
var sk = null;
var win_popup = null;

function RefreshSchedaCorso() {
	sk = window.setTimeout(RefreshSchedaCorso2, 300000);
}
function RefreshSchedaCorso2() {
	document.forms[0].submit(); // aggiorno la scheda ogni 5 minuti
}
function backSchedaCorso(tipo,menu_back) {
	document.forms[0].elements["tipo"].value = tipo;
	document.forms[0].action = "/"+((menu_back=="")?"Home/tabid/36/Default.aspx":menu_back);
	document.forms[0].submit();
}
function lanciaSchedaCorso(crs,ed,pka) {
	document.forms[0].elements["tipo"].value = "2";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = "0"; // rimuovo l'edizione perché per enapra l'iscrizione è solo un invio di una mail a formazione
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaInfoCorso(crs,ed,pka) {
	document.forms[0].elements["tipo"].value = "10";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = "0"; // rimuovo l'edizione perché per enapra l'iscrizione è solo un invio di una mail a formazione
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaCalCorso(crs,ed,pka) {
	document.forms[0].elements["tipo"].value = "11";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = "0"; // rimuovo l'edizione perché per enapra l'iscrizione è solo un invio di una mail a formazione
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaAdesioneCorso(crs,ed,pka) {
	document.forms[0].elements["tipo"].value = "12";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = "0"; // rimuovo l'edizione perché per enapra l'iscrizione è solo un invio di una mail a formazione
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaIscrizioneCorso(crs,ed,pka) {
	document.forms[0].elements["tipo"].value = "13";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = "0"; // rimuovo l'edizione perché per enapra l'iscrizione è solo un invio di una mail a formazione
	document.forms[0].elements["pka"].value = pka;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaVediNewsletter(pk_newsletter) {
    document.forms[0].elements["pk_newsletter"].value = pk_newsletter;
    document.forms[0].action = "/newsletter_show/tabid/106/Default.aspx";
    document.forms[0].submit();
}
function lanciaCompilaCV(pk_utente) {
    document.location.href = "/compilaCv/tabid/108/Default.aspx?pk_utente=" + pk_utente + "&search_area=" + document.forms[0].elements["search_area"].value + "&search_luogo=" + document.forms[0].elements["search_luogo"].value;
}
function lanciaVisualizzaCv(pk_utente) {
    document.forms[0].elements["pk_utente"].value = pk_utente;
    document.forms[0].action = "/visualizzaCv/tabid/112/Default.aspx";
    document.forms[0].submit();
}
function lanciaContattaDocente(pk_utente) {
    document.forms[0].elements["pk_utente"].value = pk_utente;
    document.forms[0].action = "/contattaCv/tabid/111/Default.aspx";
    document.forms[0].submit();
}
function lanciaRicercaCV(pk_area,pk_luogo) {
    document.forms[0].elements["search_area"].value = pk_area;
    document.forms[0].elements["search_luogo"].value = pk_luogo;
	document.forms[0].elements["tipo"].value = "14";
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaSegnalazione(crs) {
	document.forms[0].elements["tipo"].value = "5";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaContattaResp(crs) {
	document.forms[0].elements["tipo"].value = "6";
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaIscriviti(pku,crs,ed) {
	// per enapra l'iscrizione da portale consiste solo nell'invio di una mail
  // a formazione x evidenziare l'interesse dell'utente al corso 
  // poi provvederà formazione via back-office ad iscriverlo ad una delle edizioni del corso
  document.forms[0].elements["tipo"].value = "7";
	document.forms[0].elements["pku"].value = pku;
	document.forms[0].elements["crs"].value = crs;
	document.forms[0].elements["ed"].value = ed;
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaIscrizione() {
	// verifico che sia stato fornito l'indirizzo e-mail del responsabile
	if (document.forms[0].elements["email_resp"].value == "")	{
		alert("Indicare l'indirizzo e-mail del proprio responsabile.");
		document.forms[0].elements["email_resp"].focus();
		return false;
	}
	// verifico che l'indirizzo e-mail del responsabile sia corretto
	if (!checkMailAddress(document.forms[0].elements["email_resp"].value)){
		alert("Indicare un indirizzo e-mail valido.");
		document.forms[0].elements["email_resp"].focus();
		return false;
	}
	// verifico che l'indirizzo e-mail fornito termini con @enapra.it (uniche due estensioni al momento consentite)
	/*var email = document.forms[0].elements["email_resp"].value.trim().toLowerCase();
	if (email.indexOf("@enapra.it") == -1 && email.indexOf("@labelformazione.it") == -1) {
		alert("Estensione dell'indirizzo e-mail non valida.\n\nSono ammessi solo indirizzi di @enapra.it.");
		document.forms[0].elements["email_resp"].focus();
		return false;
  }*/
	document.forms[0].elements["tipo"].value = "7";
	document.forms[0].action = "/Default.aspx";
	document.forms[0].submit();
}
function lanciaListaPartecipanti(pke) {
	//visualizza la lista dei partecipanti all'edizione in un popup
	if (win_popup != null && !win_popup.closed) { win_popup.close(); }
	win_popup = window.open("ListaPartecipanti.aspx?pk_edizione="+pke,"popup_scheda","statusbar,menubar=no,height=600,width=500,top=0");
}
function lanciaPrerequisiti(pkc) {
	//visualizza i requisiti per partecipare al corso in un popup
	if (win_popup != null && !win_popup.closed) { win_popup.close(); }
	win_popup = window.open("Prerequisiti.aspx?pk_corso="+pkc,"popup_scheda","statusbar,menubar=no,height=300,width=500,top=0");
}
function lanciaStampaScheda(pkc) {
	//visualizza la scheda corso in un popup per la stampa
	if (win_popup != null && !win_popup.closed) { win_popup.close(); }
	win_popup = window.open("StampaScheda.aspx?sk_print=1&crs="+pkc+"&ed=0","popup_scheda","statusbar,menubar=no,height=800,width=650,top=0,resizable=yes,scrollbars=yes");
}
function checkContattaResp(argID,testoID){

    var selArgomento = document.getElementById(argID);
    var testo = document.getElementById(testoID);
    
    if(selArgomento.value == 0)
    {
        alert("Selezionare l'argomento.");
        selArgomento.focus();
        return false;
    }
    
    if(testo.value.replace(/\s/g, '') == '')
    {
        alert("Indicare i termini della richiesta.");
        testo.focus();
        return false;
    }

}
function showNoEdizioni(top,left) {
	document.getElementById("oMsgEdizioni").style.display = "";
	document.getElementById("oMsgEdizioni").style.top = (top-35).toString()+"px";
	document.getElementById("oMsgEdizioni").style.left = (left-138).toString()+"px";
}
function hideNoEdizioni() {
  document.getElementById("oMsgEdizioni").style.display = "none";
}

function checkRegistrati(cognomeID,nomeID,telID,cfID,emailID,assSID,assNID,upID,urID,rgID,prID,check_mail){

    var cognome = document.getElementById(cognomeID);
    var nome = document.getElementById(nomeID);
    var tel = document.getElementById(telID);
    var cf = document.getElementById(cfID);
    var email = document.getElementById(emailID);
    var associatoS = document.getElementById(assSID);
    var associatoN = document.getElementById(assNID);
    var listaUP = document.getElementById(upID);
    var listaUR = document.getElementById(urID);
    var listaRG = document.getElementById(rgID);
    var listaPR = document.getElementById(prID);
    
    if(cognome.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il cognome.");
        cognome.focus();
        return false;
    }
    if(nome.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il nome.");
        nome.focus();
        return false;
    }
    if(tel.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il telefono.");
        tel.focus();
        return false;
    }
    if(cf.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il codice fiscale.");
        cf.focus();
        return false;
    }
    if(!checkCodiceFiscale(cf.value))
    {
        alert("Indicare un codice fiscale valido.");
        cf.focus();
        return false;
    }
	if (!checkMailAddress(email.value) && check_mail){
		alert("Indicare un indirizzo e-mail valido.");
		email.focus();
		return false;
	}
	//verifico se si tratta di un associato o meno
	if (!associatoS.checked && !associatoN.checked)
	{
        alert("Indicare se associati o meno a Confagricoltura.");
        listaUR.focus();
        return false;
	
	}
	if (associatoS.checked)
	{
	     //la scelta della UR di riferimento è obbligatoria solo se è stata seleziona l'UP
        if(listaUP.value != 0 && listaUR.value == 0)
        {
            alert("Selezionare l'UP di riferimento.");
            listaUR.focus();
            return false;
        }
    }
    else
    {
        //la scelta della regione e della provincia di riferimento sono abbligatori
        if(listaRG.value == 0)
        {
            alert("Selezionare la regione di riferimento.");
            listaRG.focus();
            return false;
        }
        if(listaPR.value == 0)
        {
            alert("Selezionare la provincia di riferimento.");
            listaPR.focus();
            return false;
        }
    }
    //controllo modulo privacy
    for(j=0;j<document.forms[0].elements.length;j++)
    {
	    // se c'è un campo obbligatorio controllo che sia OK
	    if ( document.forms[0].elements[j].name.indexOf("obb_") > -1 )
	    {
		    if (document.forms[0].elements[j].value!="OK")
		    {		
			    alert(" Attenzione !! devi acconsentire all'informativa");
			    return false;
		    }
	    }
    }
    
    //chiedo conferma all'invio dei dati indicati per la registrazione
    if (!confirm("Confermi la registrazione dei tuoi dati al portale EnapraLearning?")) {
      return false;
    }
}
function checkPrivacy(a,b)
{ 
	// a nome del tag
	// b obbligatorio
	if (a.substr(0,6).toLowerCase()=="confsi")
	{	
	    comodo=eval("document.forms[0].confno"+a.substr(6,a.length-6));
	    comodo.checked="";

	    como=eval("document.forms[0].confsi"+a.substr(6,a.length-6));
		if (b==1)
		{
		    comodo=eval("document.forms[0].obb_"+a.substr(7,a.length-6));
		    if (como.checked )
		    {					
				    comodo.value="OK";
		    }
		    else
		    {
				    comodo.value="";
		    }
		}
	}
	if (a.substr(0,6).toLowerCase()=="confno")
	{
	    comodo=eval("document.forms[0].confsi"+a.substr(6,a.length-6));
	    comodo.checked="";
	    como=eval("document.forms[0].confsi"+a.substr(6,a.length-6));
		if (b==1)
		{
		    comodo=eval("document.forms[0].obb_"+a.substr(7,a.length-6));
			if (como.checked )
			{					
					comodo.value="OK";
			}
			else
			{
					comodo.value="";
			}
		}
	}

}
function checkCompilaCV(emailID,cittadinanzaID,dataNascitaID,codFiscID,pivaID,ibanID,viaID,nrID,capID,cittaID,prID,telID,cellID,nomeFile,allCVID,areeID,sediID,check_mail){

    var email = document.getElementById(emailID);
    var citt = document.getElementById(cittadinanzaID);
    var dataNascita = document.getElementById(dataNascitaID);
    var codFisc = document.getElementById(codFiscID);
    var piva = document.getElementById(pivaID);
    var iban = document.getElementById(ibanID);
    var via = document.getElementById(viaID);
    var nr = document.getElementById(nrID);
    var cap = document.getElementById(capID);
    var citta = document.getElementById(cittaID);
    var pr = document.getElementById(prID);
    var tel = document.getElementById(telID);
    var cell = document.getElementById(cellID);
    var allText = document.getElementById(allCVID);	
    var listaAREE = document.getElementById(areeID);
    var listaSedi = document.getElementById(sediID);		
		
		if (!checkMailAddress(email.value) && check_mail){
		  alert("Indicare un indirizzo e-mail valido.");
		  email.focus();
		  return false;
	  }
	  
		if(citt.value.replace(/\s/g, '') == '')
    {
        alert("Indicare la cittadinanza.");
        citt.focus();
        return false;
    }
           
		if (!checkDataCalendar(dataNascita))
		{
			alert("Inserire una data valida nel formato: gg/mm/aaaa");
			dataNascita.value = "";
			dataNascita.focus();
			return false;
		}   
        
    if (codFisc.value.replace(/\s/g, '') == '' && piva.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il codice fiscale oppure il numero di partita IVA.");
        codFisc.focus();
        return false;
    }
    
    if(!checkCodiceFiscale(codFisc.value) && piva.value.replace(/\s/g, '') == '')
    {
        alert("Indicare un codice fiscale valido.");
        codFisc.focus();
        return false;
    }
    
    if (!checkPIVA(piva) && codFisc.value.replace(/\s/g, '') == '')
    {
        alert("Indicare un numero di partita IVA valido.");
        piva.focus();
        return false;
    }
    
    if (iban.value.replace(/\s/g, '') != '' && (!checkIBAN(iban)))
    {
        alert("Indicare un numero IBAN valido.");
        iban.focus();
        return false;
    }
    
    if(via.value.replace(/\s/g, '') == '')
    {
        alert("Indicare la via.");
        via.focus();
        return false;
    }
    
    if(nr.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il numero civico.");
        nr.focus();
        return false;
    }
    
    if(cap.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il CAP.");
        cap.focus();
        return false;
    }
    
    if(citta.value.replace(/\s/g, '') == '')
    {
        alert("Indicare la citta'.");
        citta.focus();
        return false;
    }
    
    if(pr.value.replace(/\s/g, '') == '')
    {
        alert("Indicare la provincia.");
        pr.focus();
        return false;
    }
    
    if(tel.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il numero di telefono.");
        tel.focus();
        return false;
    }
    
    if(cell.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il numero di cellulare.");
        cell.focus();
        return false;
    }     
    
    // controllo che sia stato allegato il file del CV
    if (nomeFile.replace(/\s/g, '') == '')
    {
        alert("Allegare il file del CV.");
        allText.focus();
        return false;
    }     
    
	  //la scelta dell'area tematica è obbligatoria
	  if(listaAREE.length == 0)
    {
        alert("Selezionare l'area tematica di competenza.");
        listaAREE.focus();
        return false;
    }
    
    //la scelta della regione e della provincia di riferimento è obbligatoria
    if(listaSedi.length == 0)
    {
        alert("Selezionare la regione e la provincia di riferimento.");
        listaRG.focus();
        return false;
    }
	
    //chiedo conferma all'invio dei dati indicati per la registrazione
    if (!confirm("Confermi la registrazione dei tuoi dati al portale EnapraLearning?")) {
      return false;
    }
}
function checkNoModifyDataCalendar(e)
{
	// annullo l'evento, qualsiasi cosa abbia premuto
		window.event ? window.event.keyCode = 0 : e.keyCode = 0;
}
function checkDataCalendar(dataCalendar){
	var val = dataCalendar.value;
	var ris = true;   
  var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;    

	if (val == ""){
    ris = true;
  }
  else
  {
		if (!espressione.test(val))
		{
			ris = false;
		}
		else
		{
			anno = parseInt(val.substr(6),10);
			mese = parseInt(val.substr(3, 2),10);
			giorno = parseInt(val.substr(0, 2),10);
			var data=new Date(anno, mese-1, giorno);
			if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno)
			{
				ris = true;
			}
			else
			{
				ris = false;
			}
		}
  }
	return ris;
}
function checkAutocandidatura(cognomeID,nomeID,telID,emailID,areeID,check_mail)
{
    var cognome = document.getElementById(cognomeID);
    var nome = document.getElementById(nomeID);
    var tel = document.getElementById(telID);
    var email = document.getElementById(emailID);
    var listaAREE = document.getElementById(areeID);
    
    if(cognome.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il cognome.");
        cognome.focus();
        return false;
    }
    if(nome.value.replace(/\s/g, '') == '')
    {
        alert("Indicare il nome.");
        nome.focus();
        return false;
    }
    if(email.value.replace(/\s/g, '') == '')
    {
        alert("Indicare l'indirizzo e-mail.");
        email.focus();
        return false;
    }
	if (!checkMailAddress(email.value) && check_mail){
		alert("Indicare un indirizzo e-mail valido.");
		email.focus();
		return false;
	}
	
    //chiedo conferma all'invio dei dati indicati per la registrazione
    if (!confirm("Confermi la tua candidatura come decente sul portale EnapraLearning?")) {
      return false;
    }

}

function checkRicercaCV(areeID,rgID,prID)
{
    var listaAREE = document.getElementById(areeID);
    var listaRG = document.getElementById(rgID);
    var listaPR = document.getElementById(prID);

    //la scelta dell'area tematica è obbligatoria
    if(listaAREE.value == "")
    {
        alert("Selezionare l'area tematica.");
        listaAREE.focus();
        return false;
    }
    //la scelta della regione o della provincia di riferimento sono abbligatori
    if(listaRG.value == 0 && listaPR.value == 0)
    {
        alert("Selezionare il luogo di riferimento.");
        listaRG.focus();
        return false;
    }
    lanciaRicercaCV(listaAREE.value,((listaPR.value != 0) ? listaPR.value : listaRG.value));
}

function DeselAssociato(associato)
{
    document.getElementById(associato).checked = false;
}

function checkCodiceFiscale(cfins)
{
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
}

function checkPassword(emailID,usernameID){

    var email = document.getElementById(emailID);
    var username = document.getElementById(usernameID);
    
    if(email.value.replace(/\s/g, '') == '' && username.value.replace(/\s/g, '') == '')
    {
        alert("Indicare uno dei campi identificativi per il recupero della password.");
        email.focus();
        return false;
    }
  	if (!checkMailAddress(email.value) && username.value.replace(/\s/g, '') == ''){
  		alert("Indicare un indirizzo e-mail valido.");
  		email.focus();
  		return false;
  	}
    //chiedo conferma all'invio dei dati indicati per il recupero password
    if (!confirm("Confermi l'invio della richiesta per il recupero delle credenziali di accesso?")) {
      return false;
    }
}

function checkPIVA(piva)
{
  //controllo del campo partita iva
	var expPiva = /^[0-9]{11}$/;
	if (expPiva.test(piva))	
	{
      return false;
  }
  return true;
}

function checkIBAN(iban)
{
  var expReg = /IT\d{2}[ ][a-zA-Z]\d{3}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{3}|IT\d{2}[a-zA-Z]\d{22}/;
  if (!expReg.test(iban))
      return false;
  return true;
}

//-- funzioni globali ---------------------------------------------
function GetProp(objName,IsStyle,theProp) {
	var x = MM_findObj(objName);
	var s = "x."+(IsStyle?"style.":"")+theProp;
	return eval(s);
}
function SetProp(objName,IsStyle,theProp,theValue) {
	var x = MM_findObj(objName);
	var s = "if(x) { x."+(IsStyle?"style.":"")+theProp+"='"+theValue+"'; }";
	eval(s);
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function dummy() {
  return;
}
/******************************************************************************
* Functions To Check an EMail Address syntax validity
******************************************************************************/

function checkMailAddress(emailStr)
{
	emailStr = emailStr.trim();
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray=emailStr.match(emailPat);
    if (matchArray==null)
    {
        //alert("L'indirizzo email non sembra corretto. Controlla.")
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    
    if (user.match(userPat)==null)
    {
        //alert("Il nome utente non sembra corretto.")
        return false;
    }
    
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null)
    {
        for (var i=1;i<=4;i++)
        {
            if (IPArray[i]>255)
            {
                //alert("L'IP di destinazione non è corretto.")
                return false;
            }
        }
        return true;
    }
    
    var domainArray=domain.match(domainPat);
    if (domainArray==null)
    {
        //alert("Il nome del dominio non sembra valido.")
        return false;
    }
    
    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
    {
        /*alert("L'indirizzo email deve terminare con un 
        dominio di tre lettere (.com, .net, etc...) o con due lettere 
        per i domini nazionali (.it, .fr, etc..).")*/
        return false;
    }
    
    if (len<2)
    {
        //var errStr="Questo indirizzo non presenta il nome dell'host!"
        //alert(errStr)
        return false;
    }

	var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	return Filtro.test(emailStr);

}

// dovrebbe controllare solo che ci siano il carattere @ e . e poi che nel caso l'estensione del dominio sia di 3 char questa sia esattamente tra quelle ammesse altrimenti se è di 2 tutto va bene...
function checkMailAddress2(mail) 
{
  return mail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
}

String.prototype.trim = function() {
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function LeggiTutto(flg_apri) {

  for (var key in document.body.getElementsByTagName("DIV"))
  {
      if (key.substring(0,8) == 'risposta') {
        document.getElementById(key).style.display = ((flg_apri) ? '' : 'none');
      }
  }
  document.getElementById("btnOpenAll1").value = ((flg_apri) ? 'Solo domande' : 'Leggi tutto');
  document.getElementById("btnOpenAll1").onclick = function() { 
    if (flg_apri) { 
      LeggiTutto(false); 
    } else {
      LeggiTutto(true);
    }
  }
  document.getElementById("btnOpenAll2").value = ((flg_apri) ? 'Solo domande' : 'Leggi tutto');
  document.getElementById("btnOpenAll2").onclick = function() { 
    if (flg_apri) { 
      LeggiTutto(false); 
    } else {
      LeggiTutto(true);
    }
  }
}

function Leggi(item, flg_apri) {

  var key = 'risposta' + item;
  document.getElementById(key).style.display = ((flg_apri) ? '' : 'none');

}

