﻿// Funzioni

function contaCaratteri(parOggetto, parSpanContantore, parMax){
	var intCaratteriRimanenti = parMax
	intCaratteriRimanenti -= parOggetto.value.length
	document.getElementById(parSpanContantore).innerHTML = intCaratteriRimanenti.toString();
	if(intCaratteriRimanenti < 0){
		alert("Attenzione!\rHai superato il limite massimo di caratteri disponibile.\rDevi cancellare almeno " + Math.abs(intCaratteriRimanenti) + " caratteri.")
	}
	if(parOggetto.value.length > 0){
		parOggetto.form._Invio.disabled = ""
	}
	else{
		parOggetto.form._Invio.disabled = "disabled"
	}
}

function chkFormUtente(theForm){
	if(! Trim(theForm.pqtNome.value)){
		alert("Attenzione! E' necessario inserire il Nome!!");
		theForm.pqtNome.value = "";
		theForm.pqtNome.focus(); return false;
	}
	if(! Trim(theForm.pqtCognome.value)){
		alert("Attenzione! E' necessario inserire il Cognome!!");
		theForm.pqtCognome.value = "";
		theForm.pqtCognome.focus(); return false;
	}
	if(! Trim(theForm.pqtIndirizzo.value)){
		alert("Attenzione! E' necessario inserire l'Indirizzo!!");
		theForm.pqtIndirizzo.value = "";
		theForm.pqtIndirizzo.focus(); return false;
	}
	if(! Trim(theForm.pqtNCivico.value)){
		alert("Attenzione! E' necessario inserire il Numero Civico!!");
		theForm.pqtNCivico.value = "";
		theForm.pqtNCivico.focus(); return false;
	}
	if(! Trim(theForm.pqtLocalita.value)){
		alert("Attenzione! E' necessario indicare la localita'!!");
		theForm.pqtLocalita.value = "";
		theForm.pqtLocalita.focus(); return false;
	}
	if(! Trim(theForm.pqtCap.value)){
		alert("Attenzione! E' necessario indicare il Cap!!");
		theForm.pqtCap.value = "";
		theForm.pqtCap.focus(); return false;
	}
	if(! Trim(theForm.pqtProv.value)){
		alert("Attenzione! E' necessario indicare la provincia!!");
		theForm.pqtProv.value = "";
		theForm.pqtProv.focus(); return false;
	}
	if(!Trim(theForm.pqdDtNascitaG.value) || !Trim(theForm.pqdDtNascitaM.value) || !Trim(theForm.pqdDtNascitaA.value)){
		alert("Attenzione! E' necessario indicare la data di nascita!!");
		theForm.pqdDtNascitaG.focus(); return false;
	}
	
	
	if(!theForm.pqiTiSpecm[0].checked && !theForm.pqiTiSpecm[1].checked && !theForm.pqiTiSpecm[2].checked && !theForm.pqiTiSpecm[3].checked && !theForm.pqiTiSpecm[4].checked && !theForm.pqiTiSpecm[5].checked || (theForm.pqiTiSpecm[5].checked && !Trim(theForm.pqtSpecializzazione.value))){
		if(!theForm.pqiTiNonmed[0].checked && !theForm.pqiTiNonmed[1].checked && !theForm.pqiTiNonmed[2].checked && !theForm.pqiTiNonmed[3].checked && !theForm.pqiTiNonmed[4].checked && !theForm.pqiTiNonmed[5].checked && !theForm.pqiTiNonmed[6].checked || (theForm.pqiTiSpecm[5].checked && !Trim(theForm.pqtSpecializzazione.value))){
			alert("Attenzione! E' necessario indicare la Specializzazione!!");
			return false;
		}
	}
	
	if(theForm.pqiTiNonmed[6].checked && !Trim(theForm.pqtProfessione.value)){
		alert("Attenzione! E' necessario indicare la Professione!!");
		return false;
	}
	
	if(! Trim(theForm.pqtIndirizzo2.value)){
		alert("Attenzione! E' necessario inserire l'Indirizzo del luogo di lavoro!!");
		theForm.pqtIndirizzo2.value = "";
		theForm.pqtIndirizzo2.focus(); return false;
	}
	if(! Trim(theForm.pqtNCivico2.value)){
		alert("Attenzione! E' necessario inserire il Numero Civico del luogo di lavoro!!");
		theForm.pqtNCivico2.value = "";
		theForm.pqtNCivico2.focus(); return false;
	}
	if(! Trim(theForm.pqtLocalita2.value)){
		alert("Attenzione! E' necessario indicare la localita' del luogo di lavoro!!");
		theForm.pqtLocalita2.value = "";
		theForm.pqtLocalita2.focus(); return false;
	}
	if(! Trim(theForm.pqtCap2.value)){
		alert("Attenzione! E' necessario indicare il Cap del luogo di lavoro!!");
		theForm.pqtCap2.value = "";
		theForm.pqtCap2.focus(); return false;
	}
	if(! Trim(theForm.pqtProv2.value)){
		alert("Attenzione! E' necessario indicare la provincia del luogo di lavoro!!");
		theForm.pqtProv2.value = "";
		theForm.pqtProv2.focus(); return false;
	}
	
	if(! Trim(theForm.pqtEMail.value)){
		alert("Attenzione! E' necessario inserire un indirizzo EMail!!");
		theForm.pqtEMail.value = "";
		theForm.pqtEMail.focus(); return false;
	}
	if(! Trim(theForm.pqtNomeUtente.value)){
		alert("Attenzione! E' necessario inserire un Nome Utente!!");
		theForm.pqtNomeUtente.value = "";
		theForm.pqtNomeUtente.focus(); return false;
	}

	if(! Trim(theForm.pqtPwd.value)){
		alert("Attenzione! E' necessario inserire la Password!!");
		theForm.pqtPwd.value = "";
		theForm.pqtPwd.focus(); return false;
	}
	if(theForm.pqtPwd.value != theForm._PwdConf.value){
		alert("Attenzione! La Password inserita non corrisponde a quella di verifica!!");
		theForm._PwdConf.value = "";
		theForm._PwdConf.focus(); return false;
	}
	
	bAtOk=false
	bMailOk=false
	for(i=0;i<=theForm.pqtEMail.value.length;i++){
		if(theForm.pqtEMail.value.substring(i,i+1) == "@"){
			bAtOk=true;
		}
		if(bAtOk==true && theForm.pqtEMail.value.substring(i,i+1) == "."){
			bMailOk=true;
			break;
		}
	}
	if(bMailOk==false){
		alert("Attenzione! L'indirizzo mail non e' corretto!");
		theForm.pqtEMail.focus();
		return false;
	}
	if(!theForm.pqbConf675.checked){
		alert("Attenzione! E' necessario dare il consenso al trattamento dei dati!!");
		theForm.pqbConf675.focus(); return false;
	}

}

function chkPwd(theForm){
		if(! Trim(theForm.pqtPwd.value)){
			alert("Attenzione! E' necessario inserire la Password!!");
			theForm.pqtPwd.value = "";
			theForm.pqtPwd.focus(); return false;
		}
		if(theForm.pqtPwd.value != theForm._PwdConf.value){
			alert("Attenzione! La Password inserita non corrisponde a quella di verifica!!");
			theForm._PwdConf.value = "";
			theForm._PwdConf.focus(); return false;
		}
}

function Trim(argvalue) {
	argvalue = argvalue.toString();
	if (argvalue.length == 0)
		return false;
	ct=0;
	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) == " ")
			ct ++;
		if (ct == argvalue.length)
			return false;
	return true;
}

function showBigPicture(pictureToShow, width, height){
	if(width == null){
		width = 800;
	}
	if(height == null){
		height = 500;
	}
	window.open(pictureToShow,'BigPicture','scrollbars=auto,resizable=yes,width=' + width + ',height=' + height + ',status=no,location=no,toolbar=no');
}

function slideShow(slideShowId){
	if(slideShowId != null){
		window.open("ss.aspx?pfiCnt=" + slideShowId + "&pflPag=1",'SlideShow','scrollbars=auto,resizable=yes,width=900,height=645,status=no,location=no,toolbar=no');
	}
}

function newWin(parStrIndirizzo, parIntLarg, parIntAlt){
	window.open(parStrIndirizzo, '', 'toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=' + parIntLarg + ',height=' + parIntAlt);
}

