function regSave()
	{var tuttoOK = true
		if ((ControllaMail(document.reg_save.job_email.value) == 'KO') && (tuttoOK == true))
			{
				window.alert('L\'indirizzo di posta elettronica inserito\nnon sembra essere valido.\nVi preghiamo di controllarlo. Grazie');
				tuttoOK = false
			}
			
		if ((document.reg_save.ctrCtrl.value == '') && (tuttoOK == true))
			{
				window.alert('Codice di controllo non inserito');
				tuttoOK = false
			}
			
		if (tuttoOK == true)
			{document.reg_save.submit();
			}
	}

function casSave()
	{var tuttoOK = true
		if ((ControllaMail(document.cas_save.jca_email.value) == 'KO') && (tuttoOK == true))
			{
				window.alert('L\'indirizzo di posta elettronica inserito\nnon sembra essere valido.\nVi preghiamo di controllarlo. Grazie');
				tuttoOK = false
			}
			
		if ((document.cas_save.jca_testo.value == '') && (tuttoOK == true))
			{
				window.alert('Inserite un breve messaggio del vostro caso');
				tuttoOK = false
			}
			
		if ((document.cas_save.ctrCtrl.value == '') && (tuttoOK == true))
			{
				window.alert('Codice di controllo non inserito');
				tuttoOK = false
			}
			
		if (tuttoOK == true)
			{document.cas_save.submit();
			}
	}
	
function regDelSave()
	{var tuttoOK = true
		if ((ControllaMail(document.reg_save.job_email.value) == 'KO') && (tuttoOK == true))
			{
				window.alert('L\'indirizzo di posta elettronica inserito\nnon sembra essere valido.\nVi preghiamo di controllarlo. Grazie');
				tuttoOK = false
			}
			
		if (tuttoOK == true)
			{document.reg_save.submit();
			}
	}

function aziSave()
	{	var stringa_piva = document.azi_save.jaz_piva.value;
		var stringa_cf = document.azi_save.jaz_cf.value;
		var tuttoOK = true
			
		if ((document.azi_save.jaz_rag_soc.value == '') && (tuttoOK == true))
			{
				window.alert('Ragione sociale mancante');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_settore.value == '') && (tuttoOK == true))
			{
				window.alert('Indicare il settore');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_indirizzo.value == '') && (tuttoOK == true))
			{
				window.alert('Indirizzo mancante');
				tuttoOK = false
			}
			
		if ((document.azi_save.jaz_cap.value == '') && (tuttoOK == true))
			{
				window.alert('CAP mancante');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_citta.value == '') && (tuttoOK == true))
			{
				window.alert('Città mancante');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_provincia.value == '') && (tuttoOK == true))
			{
				window.alert('Provincia mancante');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_nazione.value == '') && (tuttoOK == true))
			{
				window.alert('Nazione mancante');
				tuttoOK = false
			}
		
		
		if ((controllaPIVA(document.azi_save.jaz_piva.value) == 'KO')  && (tuttoOK == true))
			{
				window.alert('La partita IVA non è corretta');
				tuttoOK = false
			}
			
			
		if ((document.azi_save.jaz_cf.value != '') && (tuttoOK == true))
			{
				if (stringa_cf.length < 16) 
					{
						if (stringa_cf.length == 11) 
							{
								if (controllaPIVA(stringa_cf) == 'KO')
									{
										window.alert('Il Codice Fiscale inserito non è corretto');
										tuttoOK = false
									}
							}
						else
							{
								window.alert('Il Codice Fiscale non rispetta i parametri di lunghezza richiesti');
								tuttoOK = false
							}
					}
				else
					{
						if (controllaCF(stringa_cf) == 'KO')
							{
								window.alert('Il Codice Fiscale inserito non è corretto)');
								tuttoOK = false
							}
					}
			
			}
		
		
		if ((ControllaMail(document.azi_save.jaz_email.value) == 'KO') && (tuttoOK == true))
			{
				window.alert('L\'indirizzo di posta elettronica inserito\nnon sembra essere valido.\nVi preghiamo di controllarlo. Grazie');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_url.value == '') && (tuttoOK == true))
			{
				window.alert('Inserire l\'indirizzo del sito web aziendale ');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_password.value == '') && (tuttoOK == true))
			{
				window.alert('Password mancante');
				tuttoOK = false
			}
		
		if ((document.azi_save.jaz_password.value != document.azi_save.jaz_password2.value) && (tuttoOK == true))
			{
				window.alert('La password e la conferma non coincidono');
				tuttoOK = false
			}
		
		if (tuttoOK == true)
			{document.azi_save.submit();
			}
	}


function aziRecPass()
	{	var stringa_piva = document.azi_login.jaz_piva.value;
		var tuttoOK = true
						
		if ((controllaPIVA(document.azi_login.jaz_piva.value) == 'KO')  && (tuttoOK == true))
			{
				window.alert('La partita IVA non è corretta');
				tuttoOK = false
			}

		if (tuttoOK == true)
			{window.open('azi_recpass.asp?jaz_piva=' + stringa_piva,'_self')
			}
	}

function offSave()
	{	var tuttoOK = true
		document.off_save.action = 'off_save.asp'
		document.off_save.target = '_self'
		if ((document.off_save.jof_titolo.value == '') && (tuttoOK == true))
			{
				window.alert('Titolo obbligatorio');
				tuttoOK = false
			}
		
		if ((document.off_save.jof_sede.value == '') && (tuttoOK == true))
			{
				window.alert('La sede è obbligatoria');
				tuttoOK = false
			}
		
		if ((document.off_save.jof_settore.value == '') && (tuttoOK == true))
			{
				window.alert('Indicare il settore dell\'offerta');
				tuttoOK = false
			}
		
		if ((document.off_save.jof_descrizione.value == '') && (tuttoOK == true))
			{
				window.alert('Non si può omettere la descrizione');
				tuttoOK = false
			}
				
		if (tuttoOK == true)
			{document.off_save.submit();
			}
	}

function offPreview() {
	document.off_save.action = 'off_preview.asp'
	document.off_save.target = 'preOff'
	document.off_save.submit();
	document.getElementById('preview').style.display = 'block'
	document.getElementById('preShadow').style.display = 'block'
}

function offDelete(jof_id){
	if (confirm('Eliminare l\'offerta dall\'archivio?')){
		window.open('off_save.asp?op=delete&jof_id=' + jof_id,'_self')
	}
}

function offRenewal(jof_id){
	if (confirm('Rinnovare l\'offerta?')){
		window.open('off_save.asp?op=renewal&jof_id=' + jof_id,'_self')
	}
}

function delUser(job_id){
	if (confirm('Eliminare Utente?')){
		window.open('job_save.asp?op=delete&job_id=' + job_id,'_self')
	}
}

function preClose() {
	document.getElementById('preview').style.display = 'none'
	document.getElementById('preShadow').style.display = 'none'
}


function ControllaLogo()
{var tuttoOK = true
	if ((document.logoUpdate.attach.value == '') && (tuttoOK == true))
		{
			window.alert('Inserire un nome di file valido')
			tuttoOK = false
		}
	if (tuttoOK == true)
		{document.logoUpdate.submit();}
}

function ControllaMail(EmailAddr)
   {
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return 'OK';
   else
      {
      return 'KO';
      }
   }


function controllaCF(codice) {
	var cfctot
	var ndigit
	var ckd
	cfctot = 0
	ndigit = 0
   //Estrazione dei caratteri di posizione pari
	for(var i=1;i<14;i=i+2)
		{
			cfctot = cfctot + NumeriPari(codice.charAt(i))
   		}
   
   //Estrazione dei caratteri di posizione dispari
   for(var i=0;i<15;i=i+2)
		{
			cfctot = cfctot + NumeriDispari(codice.charAt(i))
   		}
  
   // Calcolo del check-digit di controllo
   ndigit = (cfctot / 26) - Math.floor(cfctot / 26)
   ndigit = Math.round(ndigit * 26)
   // check digit ricavato
   ckd = String.fromCharCode(65 + ndigit)
   if (ckd == codice.charAt(15))
   		{
			return 'OK'
		}
   else	
   		{
			return 'KO'
		}
}

function NumeriDispari(cifra) {
	var i
	var TD = new Array();
	TD[0] = new Array('B',"1");
	TD[1] = new Array('A','0');
	TD[2] = new Array('K','');
	TD[3] = new Array('P','');	
	TD[4] = new Array('L','');
	TD[5] = new Array('C','2');
	TD[6] = new Array('Q','');
	TD[7] = new Array('D','3');
	TD[8] = new Array('R','');
	TD[9] = new Array('E','4');
	TD[10] = new Array('V','');
	TD[11] = new Array('O','');
	TD[12] = new Array('S','');
	TD[13] = new Array('F','5');
	TD[14] = new Array('T','');
	TD[15] = new Array('G','6');
	TD[16] = new Array('U','');
	TD[17] = new Array('H','7');
	TD[18] = new Array('M','');
	TD[19] = new Array('I','8');
	TD[20] = new Array('N','');
	TD[21] = new Array('J','9');
	TD[22] = new Array('W','');
	TD[23] = new Array('Z','');
	TD[24] = new Array('Y','');
	TD[25] = new Array('X','');
	
	for(i=0;i<26;i++)
		{
			if ((TD[i][0] == cifra) || (TD[i][1] == cifra))
				{
					return i;
					//window.alert(i)
				}
		}
}

function NumeriPari(cifra) {
	var i
	var TP = new Array();
	TP[0] = new Array('A',"0");
	TP[1] = new Array('B','1');
	TP[2] = new Array('C','2');
	TP[3] = new Array('D','3');	
	TP[4] = new Array('E','4');
	TP[5] = new Array('F','5');
	TP[6] = new Array('G','6');
	TP[7] = new Array('H','7');
	TP[8] = new Array('I','8');
	TP[9] = new Array('J','9');
	TP[10] = new Array('K','');
	TP[11] = new Array('L','');
	TP[12] = new Array('M','');
	TP[13] = new Array('N','');
	TP[14] = new Array('O','');
	TP[15] = new Array('P','');
	TP[16] = new Array('Q','');
	TP[17] = new Array('R','');
	TP[18] = new Array('S','');
	TP[19] = new Array('T','');
	TP[20] = new Array('U','');
	TP[21] = new Array('V','');
	TP[22] = new Array('W','');
	TP[23] = new Array('X','');
	TP[24] = new Array('Y','');
	TP[25] = new Array('Z','');
	
	for(i=0;i<26;i++)
		{
			if ((TP[i][0] == cifra) || (TP[i][1] == cifra))
				{
					return i;
					//window.alert(i)
				}
		}
}


function controllaPIVA(piva) {
	var cifre = new Array;
	var i
	var calcolo = 0
	var totPari = 0
	var totDispari = 0
	var tot = 0
	var complemento
	var check = piva.charAt(10);
	
	//operazioni di verifica
	for(i=0;i<10;i++) 
		{
			cifre[i] = piva.charAt(i)
		}
		
	for(i=0;i<10;i++) 
		{
			if ((i==1) || (i==3) || (i==5) || (i==7) || (i==9)) 
				{
					calcolo = parseInt(cifre[i],10) * 2;
					if (calcolo > 9) 
						{
							totPari = totPari + Math.floor(calcolo/10);
							totPari = totPari + (calcolo - (Math.floor(calcolo/10))*10);
						}
					else
						{
							totPari = totPari + calcolo;
						}
				}
			else
				{
					totDispari = totDispari + parseInt(cifre[i],10);
				}
		}
	
	tot = totPari + totDispari;
	var totaleStringa = String(tot);
	
	if (totaleStringa.charAt(1) == '0')
		{
			if (check == totaleStringa.charAt(1))
				{
					return('OK')
				}
			else
				{
					return('KO')
				}
		}
	else
		{
			complemento = 10 - parseInt(totaleStringa.charAt(1),10);
			if (check == String(complemento))
				{
					return('OK')
				}
			else
				{
					return('KO')
				}
		}
}


