function PrintReferto(sTipo,IDReferto) {
 	
 	OpenPopupWindow('/admin/referti/stampareferto.asp?tipo='+sTipo + '&id='+IDReferto,'StampaRefertoWnd','menubar=no,toolbar=no,resizable=no,status=no, scrollbars=yes, modal', 800, 600 );	
}

function CheckFormSearchRiscossioni(theForm) {	
	ris= CutSpace(theForm.Inizio.value);
  	if (!IsDate(ris)) {
  		alert("Data Inizio non valida");			
  		theForm.Inizio.focus();
  		return false;
  	}  	
	
	// check sulla data
	ris= CutSpace(theForm.Fine.value);
  	if (!IsDate(ris)) {
  		alert("Data Fine non valida");			
  		theForm.Fine.focus();
  		return false;
  	}  	

	return true;
}

function RiscossioniCommand(theForm, sAction) {	
 	
 	switch(sAction) { 	 		
 	case "MODIFY": 	
		theForm.ACT.value = 'MODIFY'; 
		theForm.submit();
 		break; 		

 	case "DELETE":
	 	if(confirm("Sei sicuro di voler cancellare i records selezionati ?")) {
			if(confirm("Te lo chiedo ancora una volta: \nSei sicuro di voler cancellare i records selezionati ?")) {		
				theForm.ACT.value = 'DELETE_SINGLE'; 
				theForm.submit();
			    return true;
			}
			return false;
		}
		else {
			return false;
		} 	
		break;
		
	default: 
		theForm.ACT.value = ''; 
		theForm.submit();	
	} 	
			
	return true;
}

function CheckFormRiscossioni(theForm) {
	var ris;
	
    ris= CutSpace(theForm.IDRiscossione.value);       	
	if (ris.value== "") {
    	alert("IDRiscossione non valido o nullo");
    	theForm.IDMedico.focus();
		return false;	    
	}
	
    ris= CutSpace(theForm.IDMedico.value);       	
	if (ris.length== 0) {
    	alert("Inserire il medico");
    	theForm.IDMedico.focus();
		return false;	     
	}	

	ris= CutSpace(theForm.DataFattura.value) ;       
	if (!IsDate(ris)) {
		alert("Data Fattura non valida!");
		theForm.DataFattura.focus();
		return false;
	}

	ris= CutSpace(theForm.NumeroFattura.value)        
	if (ris.length== 0) {		
	    alert("Inserire il Numero Fattura");
	    theForm.NumeroFattura.focus();
	    return false;	    
	}
	
	ris= CutSpace(theForm.DataPagamento.value) ;       
	if (!IsDate(ris)) {
		alert("Data Pagamento non valida!");
		theForm.DataPagamento.focus();
		return false;
	}

	ris= CutSpace(theForm.ImportoRiscosso.value)        
	if (ris.length== 0) {		
	    alert("Inserire l'Importo Riscosso");
	    theForm.ImportoRiscosso.focus();
	    return false;	    
	}	
	
	ris= CutSpace(theForm.ModalitaPagamento.value)
	if (ris=='A') {
		ris= CutSpace(theForm.NumeroAssegno.value)        
		if (ris.length== 0) {		
		    alert("Inserire il Numero Assegno");
		    theForm.NumeroAssegno.focus();
		    return false;	    
		}	
	}
			
	return true;
}

function CheckEliminaAppuntamenti(theForm) {
	if(confirm("Sei sicuro di voler cancellare i records selezionati ?")) {
		if(confirm("Te lo chiedo ancora una volta: \nSei sicuro di voler cancellare i records selezionati ?")) {		
			theForm.submit();
			return true;
		}
		return false;
	}
	else {
		return false;
	} 
	return true;	
}

function CheckSpostaAppuntamento(theForm) {
   	var ris;
	var AppOra_h;
	var AppOra_m;
	   	
   	ris= CutSpace(theForm.IDAgenda.value);       	
	if (ris.value== "") {
    	alert("IDAgenda non valido o nullo");
    	theForm.AppOra_h.focus();
		return false;	    
	}
	
   	ris= CutSpace(theForm.IDAppuntamento.value);       	
	if (ris.value== "") {
    	alert("IDAppuntamento non valido o nullo");
    	theForm.AppOra_h.focus();
		return false;	    
	}	

	AppOra_h= Strip(theForm.AppOra_h.value)
    AppOra_m= Strip(theForm.AppOra_m.value)	
	if (check_ora(AppOra_h) || check_minuti(AppOra_m)) {
		alert("Orario dell'appuntamento non valido!")
	  	theForm.AppOra_h.focus();
	  	return false;
	}

	if(confirm("Confermi lo spostamento dell'appuntamento selezionato?")) {		
		return true;
	}
	
	return false;
}

function AgendaCommand(theForm, sAction) {	
 	
 	switch(sAction) {
 	case "PREV":
		theForm.ACT.value = 'PREV'; 
		theForm.submit();
		break;
		
 	case "NEXT": 	
		theForm.ACT.value = 'NEXT'; 
		theForm.submit();
 		break;
 		
 	case "MODIFY": 	
		theForm.ACT.value = 'MODIFY'; 
		theForm.submit();
 		break; 		
 	
 	case "COMPLETO":
 		theForm.ACT.value = 'COMPLETO'; 
		theForm.submit();
 		break; 			
 		
 	case "DELETE":
	 	if(confirm("Sei sicuro di voler cancellare i records selezionati ?")) {
			if(confirm("Te lo chiedo ancora una volta: \nSei sicuro di voler cancellare i records selezionati ?")) {		
				theForm.ACT.value = 'DELETE_SINGLE'; 
				theForm.submit();
			    return true;
			}
			return false;
		}
		else {
			return false;
		} 	
		break;
		
	default: 
		theForm.ACT.value = ''; 
		theForm.submit();	
	} 	
			
	return true;
}

function AppuntamentoCommand(theForm, sAction) {	
 	
 	switch(sAction) {
 	case "PREV":
		theForm.ACT.value = 'PREV'; 
		theForm.submit();
		break;

 	case "M_APP": 	
		theForm.ACT.value = 'M_APP'; 
		theForm.submit();
 		break; 		
 				
 	case "NEXT": 	
		theForm.ACT.value = 'NEXT'; 
		theForm.submit();
 		break;
 		
 	case "D_APP_SINGLE":
	 	if(confirm("Sei sicuro di voler cancellare il record selezionato ?")) {
			if(confirm("Te lo chiedo ancora una volta: \nSei sicuro di voler cancellare il record selezionato ?")) {		
				theForm.ACT.value = 'D_APP_SINGLE'; 
				theForm.submit();
			    return true;
			}
			return false;
		}
		else {
			return false;
		} 	
		break;
		
	default: 
		theForm.ACT.value = 'VIEW'; 
		theForm.submit();	
	} 	
			
	return true;
}

function CheckFormSearchAgenda(theForm) {
	var ris;		
	ris= CutSpace(theForm.Inizio.value);
  	if (!IsDate(ris)) {
  		alert("Data Inizio non valida");			
  		theForm.Inizio.focus();
  		return false;
  	}  	
	
	// check sulla data
	ris= CutSpace(theForm.Fine.value);
  	if (!IsDate(ris)) {
  		alert("Data Fine non valida");			
  		theForm.Fine.focus();
  		return false;
  	}  			
			
	return true;
}

function CheckFormAgendaAppuntamenti(theForm) {	
	var ris;
	var Inizio_h;
	var Inizio_m;	
	var Fine_h;
	var Fine_m;	

  	var sInizio;
  	var sFine;

    ris= CutSpace(theForm.IDAgenda.value);       	
	if (ris.value== "") {
    	alert("IDAgenda non valido o nullo");
    	theForm.IDMedico.focus();
		return false;	    
	}
	
    ris= CutSpace(theForm.IDMedico.value);       	
	if (ris.length== 0) {
    	alert("Inserire il medico");
    	theForm.IDMedico.focus();
		return false;	     
	}	

    ris= CutSpace(theForm.Studio.value);       	
	if (ris.length== 0) {
    	alert("Inserire lo Studio");
    	theForm.Studio.focus();
		return false;	   
	}	
			 
	// check sulla data
	ris= CutSpace(theForm.data_app.value);
  	if (!IsDate(ris)) {
  		alert("Data non valida");			
  		theForm.data_app.focus();
  		return false;
  	}  			
		
	Inizio_h= Strip(theForm.Inizio_h.value)
    Inizio_m= Strip(theForm.Inizio_m.value)	
	if (check_ora(Inizio_h) || check_minuti(Inizio_m)) {
		alert("Ora di inizio appuntamenti non valida!")
	  	theForm.Inizio_h.focus();
	  	return false;
	}

	Fine_h= Strip(theForm.Fine_h.value)
    Fine_m= Strip(theForm.Fine_m.value)	
	if (check_ora(Fine_h) || check_minuti(Fine_m)) {
		alert("Ora di fine appuntamenti non valida!")
	  	theForm.Fine_h.focus();
	  	return false;
	}	   

  	sInizio=Inizio_h +':'+ Inizio_m + ':00';
  	sFine=Fine_h +':'+ Fine_m +':00';
	
	if (bVerificaInizioFine(sInizio, sFine)==false) {
		alert("Ora di Inizio e Fine visite coincidenti o non valide!");
		theForm.Inizio_h.focus();
		return false;
	} 

    ris= CutSpace(theForm.Durata.value);       	
	if (ris.length== 0) {
    	alert("Inserire la durata tipica degli appuntamenti");
    	theForm.Durata.focus();
		return false;	   
	}  		 
	return true;
}

function bVerificaInizioFine(sInizio, sFine)
{	
	var dInizio= new Date('01/01/2000 ' + sInizio);	
	var dFine= new Date('01/01/2000 ' + sFine);
	
	if (dFine<= dInizio) 
		return false;
	else
		return true;			
}

function CheckFormAppuntamento(theForm) {

	var AppOra_h;
	var AppOra_m;	

    ris= CutSpace(theForm.IDAgenda.value);       	
	if (ris.value== "") {
    	alert("IDAgenda non valido o nullo");
    	theForm.AppCognome.focus();
		return false;	    
	}
	
	ris= CutSpace(theForm.AppCognome.value)        
	if (ris.length== 0) {
    	alert("Inserire il Cognome");
    	theForm.AppCognome.focus();
		return false;	        
	}	
				 
	ris= CutSpace(theForm.AppNome.value)        
	if (ris.length== 0) {		
	    alert("Inserire il nome");
	    theForm.AppNome.focus();
	    return false;	    
	}	

	ris= CutSpace(theForm.AppDataNascita.value) ;       
	if (!IsDate(ris)) {
		alert("Data di nascita non valida!");
		theForm.AppDataNascita.focus();
		return false;
	}

	AppOra_h= Strip(theForm.AppOra_h.value)
    AppOra_m= Strip(theForm.AppOra_m.value)	
	if (check_ora(AppOra_h) || check_minuti(AppOra_m)) {
		alert("L'orario dell'appuntamento non è valido!")
	  	theForm.AppOra_h.focus();
	  	return false;
	}

	return true;
}

function formAziende_submit(theForm) {
	// Disallow submit until the form fields have been validated
	var ris;
	
    ris= CutSpace(theForm.Denominazione.value);    
	if (ris.length==0) {
    	alert("Inserire la Denominazione");
    	theForm.Denominazione.focus();
		return false;	    
	}	
			 
    ris= CutSpace(theForm.Indirizzo.value);    
	if (ris.length==0) {
	    alert("Inserire l'indirizzo");
	    theForm.Indirizzo.focus();
	    return false;	    
	}
			
    ris= CutSpace(theForm.Citta.value);    
	if (ris.length==0) {
	    alert("Inserire la Citta");
	    theForm.Citta.focus();
	    return false;	    
	}

    ris= CutSpace(theForm.CAP.value);    
	if (ris.length==0) {
	    alert("Inserire il CAP");
	    theForm.CAP.focus();
	    return false;	    
	}
	
    ris= CutSpace(theForm.Provincia.value);    
	if (ris.length==0) {
	    alert("Inserire la Provincia");
	    theForm.Provincia.focus();
	    return false;	    
	}

    ris= CutSpace(theForm.Paese.value);    
	if (ris.length==0) {
	    alert("Inserire il Paese");
	    theForm.Paese.focus();
	    return false;	    
	}	

    ris= CutSpace(theForm.Path_Esami_Holter_Ecg.value);    
	if (ris.length==0) {
	    alert("Inserire il Path_Esami_Holter_Ecg");
	    theForm.Path_Esami_Holter_Ecg.focus();
	    return false;	    
	}	

    ris= CutSpace(theForm.Path_Programma_Holter_Ecg.value);    
	if (ris.length==0) {
	    alert("Inserire il Path_Programma_Holter_Ecg");
	    theForm.Path_Esami_Holter_Ecg.focus();
	    return false;	    
	}	
		    
	return true;
}

function AskStampaRiscossioni(theForm) {
	var ris;
	var IDMedico;
	var sUrl;
	var sModalita;	

	sUrl = '/admin/appuntamenti/stampariscossioni.asp?ACT=REPORT';	

	// check sulla data
	ris= CutSpace(theForm.Inizio.value);
  	if (!IsDate(ris)) {
  		alert("Data Inizio non valida");			
  		theForm.Inizio.focus();
  		return false;
  	}  	
  	else {		
		sUrl = sUrl + '&Inizio=' + ris;				
	}
	
	// check sulla data
	ris= CutSpace(theForm.Fine.value);
  	if (!IsDate(ris)) {
  		alert("Data Fine non valida");			
  		theForm.Fine.focus();
  		return false;
  	}
	else {					
		sUrl = sUrl + '&Fine='+ ris;		
	}
	
	IDMedico= CutSpace(theForm.IDMedico.value);	
	if (IDMedico.length>0) {
		sUrl = sUrl + '&IDMedico='+ IDMedico;
	} 
	else {
		alert("E' possibile stampare il report solo per un singolo medico");
		return false;
	}
		
	window.open(sUrl, 'StampaReport','');
	
	return true;
}	

function AskExcelRiscossioni(theForm) {	
	var ris;
	var IDMedico;
	var sUrl;
	var sModalita;	

	sUrl = '/admin/appuntamenti/ElenchiExcel.asp?VIEW=RISCOSSIONI';

	// check sulla data
	ris= CutSpace(theForm.Inizio.value);
  	if (!IsDate(ris)) {
  		alert("Data Inizio non valida");			
  		theForm.Inizio.focus();
  		return false;
  	}  	
  	else {		
		sUrl = sUrl + '&Inizio=' + ris;				
	}
	
	// check sulla data
	ris= CutSpace(theForm.Fine.value);
  	if (!IsDate(ris)) {
  		alert("Data Fine non valida");			
  		theForm.Fine.focus();
  		return false;
  	}
	else {					
		sUrl = sUrl + '&Fine='+ ris;		
	}

	IDMedico= CutSpace(theForm.IDMedico.value);		
	if (IDMedico.length>0) {
		sUrl = sUrl + '&IDMedico='+ IDMedico;
	}

	sModalita= CutSpace(theForm.Modalita.value);	
	if (sModalita.length>0) {
		sUrl = sUrl + '&Modalita='+ sModalita;
	}
	
	window.open(sUrl, 'ElencoExcel','');
			
	return true;
}

function ReportAppuntamenti(theForm, sAction) {	
	var IDMedico;
	var sCognome;
	var sNome;
	var nStudio;	
	var sUrl;	
	
	sUrl ="";
	
	IDMedico= CutSpace(theForm.IDMedico.value);	
	nStudio= CutSpace(theForm.Studio.value);	
	sCognome= CutSpace(theForm.Cognome.value);	
	sNome= CutSpace(theForm.Nome.value);	
  	  	
	// check sulla data
	ris= CutSpace(theForm.Inizio.value);
  	if (!IsDate(ris)) {
  		alert("Data Inizio non valida");			
  		theForm.Inizio.focus();
  		return false;
  	}  	
  	else {		
		sUrl = sUrl + '&Inizio=' + ris;				
	}
	
	// check sulla data
	ris= CutSpace(theForm.Fine.value);
  	if (!IsDate(ris)) {
  		alert("Data Fine non valida");			
  		theForm.Fine.focus();
  		return false;
  	}
	else {					
		sUrl = sUrl + '&Fine='+ ris;		
	}
	if (IDMedico.length>0) {
		sUrl = sUrl + '&IDMedico='+ IDMedico;
	}

	if (sCognome.length>0) {
		sUrl = sUrl + '&Cognome='+ sCognome;
	}

	if (sNome.length>0) {
		sUrl = sUrl + '&Nome='+ sNome;
	}

	if (nStudio.length>0) {
		sUrl = sUrl + '&Studio='+ nStudio;
	}

	switch (sAction) {
		case "EXCEL":
			sUrl = '/admin/appuntamenti/ElenchiExcel.asp?VIEW=APPUNTAMENTI' + sUrl;
			window.open(sUrl, 'ElencoExcel','');					
			break;

		case "APP_NON_RISCOSSI":
			sUrl = '/admin/appuntamenti/ElenchiExcel.asp?VIEW=APP_NON_RISCOSSI' + sUrl;
			window.open(sUrl, 'ElencoExcel','');					
			break;
			
		case "PRINT": {
			sUrl = '/admin/appuntamenti/StampaAppuntamenti.asp?ACT=APP' + sUrl;
			window.open(sUrl, 'StampaAppuntamenti','');				
			break;
			
		}
	}
	
	return true;
}

function formSupporto_submit(theForm) {
	// Disallow submit until the form fields have been validated
	var bReturn = false;		
		 
	if (theForm.Nome.value== "") {
	    alert("Inserire il nome");
	    theForm.Nome.focus();
	    return bReturn;	    
	}
	
	if (theForm.Cognome.value== "") {
    	alert("Inserire il Cognome");
    	theForm.Cognome.focus();
		return bReturn;	    
	}	
	
	if (isEmail(theForm.EMail.value) == false) {			
		alert("L'indirizzo Email inserito non è valido");
		theForm.EMail.focus();
		return bReturn;	 
	}	

	if (theForm.subject.value== "") {
    	alert("Inserire l'oggetto della mail");
    	theForm.subject.focus();
		return bReturn;	    
	}
	
	if (theForm.Messaggio.value== "") {
    	alert("Inserire il messaggio");
    	theForm.Messaggio.focus();
		return bReturn;	    
	}

	return true;
}

function ContactUs_onsubmit(theForm) {
	// Disallow submit until the form fields have been validated
	var bReturn = false;		
		 
	if (theForm.Nome.value== "") {
	    alert("Inserire il nome");
	    theForm.Nome.focus();
	    return bReturn;	    
	}
	
	if (theForm.Cognome.value== "") {
    	alert("Inserire il Cognome");
    	theForm.Cognome.focus();
		return bReturn;	    
	}	
	
	if (isEmail(theForm.EMail.value) == false) {			
		alert("L'indirizzo Email inserito non è valido");
		theForm.EMail.focus();
		return bReturn;	 
	}	

	if (theForm.subject.value== "") {
    	alert("Inserire l'oggetto della mail");
    	theForm.subject.focus();
		return bReturn;	    
	}
	
	if (theForm.Messaggio.value== "") {
    	alert("Inserire il messaggio");
    	theForm.Messaggio.focus();
		return bReturn;	    
	}

	return true;
}

