function MM_swapImgRestore(){ 
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage(){ 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d){ 
  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); return x;
}

function IsNumeric(sText){
	return numberControl(sText,"0123456789.");
}

function IsInteger(sText){
	return numberControl(sText,"0123456789");
}

function numberControl(sText,ValidChars){
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function checkmail(mailValue){
	var strMail = new String(mailValue.toLowerCase());
	var len = strMail.length;
   	var aa;
   	var bb;
   	var stato;
    if (strMail.length < 4 ){
	    stato = false;
    }
    if ((aa=strMail.indexOf("@")) < 3){
	    stato = false;
    }
    var strbb = new String(strMail.substring(aa,len) );
    if ((bb=strbb.indexOf(".")) < 3){
	    stato = false;
    }
    if(stato == false){
		alert("ATTENZIONE! Il campo email inserito non è valido!");
		return false;   
    }
    else{
	 	return true;   
    }
}

function controllaCampoNumerico(sText){
	sText.value = sText.value.replace(/[\,]/g,".");
	if(!IsNumeric(sText.value)){
		alert('ATTENZIONE!Il campo inserito non è un numero!');
		sText.value = "";
		sText.focus();
		return false;
	}
}

function controllaCampoIntero(sText){
	if(!IsInteger(sText.value)){
		alert('ATTENZIONE!Il campo inserito non è un intero!');	
		sText.value = "";
		sText.focus();
		return false;
	}
}

function controllaTariffa(sText){
	sText.value = sText.value.replace(/[\,]/g,".");
	if(sText.value != ''){
		if(!IsNumeric(sText.value)){
			alert('ATTENZIONE!Il campo inserito non è un numero!');
			sText.value = "";
			sText.focus();
			return false;
		}
	}
	else{
		alert('ATTENZIONE!Il campo non è stato valorizzato!');
		sText.value = "";
		sText.focus();
		return false;
	}
}

function controllaCampoInteroData(sText){
	if(!IsInteger(sText)){
		return false;
	} else return true;
}

function IsImage(sText){
	return imageControl(sText,"0123456789._-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

function imageControl(sText,ValidChars){
   var IsImage=true;
   var Char;

 
   for (i = 0; i < sText.length && IsImage == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsImage = false;
         }
      }
   return IsImage;
}


function IsImage(sText){
	return imageControl(sText,"0123456789._-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
}


function controllaImmagine(string,ogg){
	if(!IsImage(string)){
		alert('ATTENZIONE!Il campo inserito non è valido!');	
		ogg.focus();
	}	
}

function FindMonthNum(mese){
	mese = String(mese);
	var strmese;
	
	switch (mese){ 
		case "Gennaio":
		strmese = "1";
		break;
    
		case "Febbraio":
		strmese = "2";
		break;
    
		case "Marzo":
		strmese = "3";
		break;
    
		case "Aprile":
		strmese = "4";
		break;
    
		case "Maggio":
		strmese = "5";
		break;
    
		case "Giugno":
		strmese = "6";
		break;
    
		case "Luglio":
		strmese = "7";
		break;
    
		case "Agosto":
		strmese = "8";
		break;														
    
		case "Settembre":
		strmese = "9";
		break;														
    
		case "Ottobre":
		strmese = "10";
		break;														
    
		case "Novembre":
		strmese = "11";
		break;														
    
		case "Dicembre":
		strmese = "12";
		break;																						
	}	
	return strmese;
}

function confermaInserimento(cod_appuntamento,giorni_settimana,numero_settimane){
	if (window.confirm("ATTENZIONE: alcuni appuntamenti coincidono con appuntamenti già presenti! Continuare l'inserimento?")){
		alert('Gli appuntamenti che coincidono con quelli già presenti non verranno inseriti automaticamente!');
	}
	else{
		document.location = "body.php?SUBFUNCTIO=inserisci_appuntamento_multiplo.php&cod_appuntamento=" + cod_appuntamento + "&giorni_settimana=" + giorni_settimana + "&numero_settimane=" + numero_settimane;
	}
}


function cancellaTrainer(cod_trainer,filtro_lettera){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare il trainer?")){
		alert('Tutti i dati associati al trainer verranno eliminati!')
		document.location = 'body.php?SUBFUNCTION=ricerca_trainer.php&cod_trainer=' + cod_trainer +'&filtro_lettera=' + filtro_lettera + '&go_delete=1';
	}
}

function cancellaCliente(cod_cliente,filtro_lettera){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare il cliente?")){
		alert('Tutti i dati associati al cliente verranno eliminati!')
		document.location = 'body.php?SUBFUNCTION=ricerca_clienti.php&cod_cliente=' + cod_cliente +'&filtro_lettera=' + filtro_lettera + '&go_delete=1&go_ricerca=1';
	}
}

function cancellaAdmin(cod_amministratore, filtro_lettera){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare l'amministratore?")){
		alert("Tutti i dati associati all'ammninistratore verranno eliminati!");
		document.location = 'body.php?SUBFUNCTION=ricerca_amministrazione.php&cod_amministratore=' + cod_amministratore +'&filtro_lettera=' + filtro_lettera + '&go_delete=1&go_ricerca=1';
	}
}

function popNew(url,pop_name,y,w) {
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;

	//alert(1);
	
	searchWin = window.open(url , pop_name, 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + w + ',height=' + y + ',left='+ l +',top='+ t +'');
	searchWin.focus();
}

function popNewScroll(url,pop_name,y,w) {
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;

	searchWin = window.open(url , pop_name, 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=' + w + ',height=' + y + ',left='+ l +',top='+ t +'');
	searchWin.focus();
}

function popNewExcel(url,pop_name,y,w) {
	document.location = url;
}

function cancellaCv(cod_trainer,rm_file_cv){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare il file?")){
		document.location = 'body.php?SUBFUNCTION=anagrafica_trainer.php&cod_trainer=' + cod_trainer + '&rm_file_cv=' + rm_file_cv;
	}
}

function cancellaImmagine(cod_trainer,rm_immagine){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare l'immagine?")){
		document.location = 'body.php?SUBFUNCTION=anagrafica_trainer.php&cod_trainer=' + cod_trainer + '&rm_immagine=' + rm_immagine;
	}
}

function cancellaCitta(cod_trainer,rm_citta){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare l'associazione?")){
		document.location = 'body.php?SUBFUNCTION=associa_citta.php&cod_trainer=' + cod_trainer + '&rm_citta=' + rm_citta;
	}
}

function menuTrainer(subf) {
	var oElementMenu = parent.document.getElementById("menu_sx");
	oElementMenu.src = "menu_backend.php?submenu_agenda=1&submenu_link=" + subf;
	var oElementBody = parent.document.getElementById("frame_body");
	oElementBody.src = "body.php?SUBFUNCTION=" + subf;
}

function menuCliente(subf) {
	var oElementMenu = parent.document.getElementById("menu_sx");
	oElementMenu.src = "menu_backend.php?submenu_link=" + subf;
	var oElementBody = parent.document.getElementById("frame_body");
	oElementBody.src = "body.php?SUBFUNCTION=" + subf;
}

function menuTecno(subf) {
	var oElementMenu = parent.document.getElementById("menu_sx");
	oElementMenu.src = "menu_backend.php?submenu_link=" + subf;
	var oElementBody = parent.document.getElementById("frame_body");
	oElementBody.src = "body.php?SUBFUNCTION=" + subf;
}

function createPdf(mese, anno, cod_user, numero, data, tipo_fattura, tipo_pagamento, tipo_azione, id, rimborso_spese) {
	w = 800;
	y = 600;
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;
	var url = 'test_pdf.php?mese_fatturazione=' + mese + '&anno_fatturazione=' + anno + '&cod_user=' + cod_user + '&numero_fattura=' + numero + '&data_fattura=' + data + '&tipo_fattura=' + tipo_fattura + '&tipo_pagamento=' + tipo_pagamento + '&tipo_azione=' + tipo_azione + '&cod_fattura_trainer=' + id + '&rimborso_spese=' + rimborso_spese;
	pdfWin = window.open(url, 'pdf_trainer', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + w + ',height=' + y + ',left='+ l +',top='+ t +'');
	pdfWin.focus();
}

function cancellaAppuntamento(url){
	if (window.confirm("ATTENZIONE: vuoi davvero eliminare l'appuntamento?")){
		alert('Tutti i dati associati all\'appuntamento verranno eliminati!')
		document.location = url;
	}
}

function popImages(cod_trainer) {
	w = 300;
	y = 300;
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;

	searchWin = window.open("visualizza_immagini.php?cod_trainer=" + cod_trainer, "lista_immagini", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=" + w + ",height=" + y + ",left="+ l +",top="+ t);
	searchWin.focus();
}

function popCitta(cod_trainer) {
	w = 500;
	y = 600;
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;

	searchWin = window.open("associa_citta.php?cod_trainer=" + cod_trainer, "associa_citta", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=" + w + ",height=" + y + ",left="+ l +",top="+ t);
	searchWin.focus();
}

function visualizzaAgendaSett(cod_trainer,data_inizio_settimana) {
	w = 650;
	y = 650;
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2; 

	searchWin = window.open("visualizza_agenda_trainer_sett.php?cod_trainer=" + cod_trainer + "&data_inizio_settimana=" + data_inizio_settimana, "visualizza_agenda", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=" + w + ",height=" + y + ",left="+ l +",top="+ t);
	searchWin.focus();
}

function visualizzaAgendaGiorno(cod_trainer,data_agenda) {
	w = 650;
	y = 650;
	t = (screen.height - y) / 2; 
	l = (screen.width - w) / 2;

	searchWin = window.open("visualizza_agenda_trainer_giorno.php?cod_trainer=" + cod_trainer + "&data_agenda=" + data_agenda, "visualizza_agenda", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=" + w + ",height=" + y + ",left="+ l +",top="+ t);
	searchWin.focus();
}
/*
function menuLocationAgenda(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=0";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=nuovo_appuntamento.php";
}

function menuLocationClienti(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=1&submenu_link=ana_clienti";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_clienti.php";
}

function menuLocationTrainer(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=1&submenu_link=ana_trainer";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_trainer.php";
}

function menuLocationAppuntamenti(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=3";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_appuntamenti.php";
}

function menuLocationReport(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=2&submenu_link=report";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_report.php";
}

function menuLocationPagamenti(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=2&submenu_link=pagamenti";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_pagamenti.php";
}

function menuLocationTariffe(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=2&submenu_link=tariffe";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_tariffe.php";
}

function menuLocationAccount(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=2&submenu_link=account";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_account_gestore.php";
}

function submenuLocationNuovoApp(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=0&submenu_link=nuovo_app";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=nuovo_appuntamento.php";
}

function submenuLocationRicercaApp(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=0&submenu_link=ricerca_app";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_appuntamento_gestore.php";
}
*/
//fatta da roberto
function menuLocation(submenu_agenda, submenu_link){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	if(submenu_link != "")
		oElementMenu.src = "menu_backend.php?submenu_agenda="+submenu_agenda+"&submenu_link="+submenu_link;
	else
		oElementMenu.src = "menu_backend.php?submenu_agenda="+submenu_agenda;
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION="+submenu_link;
}

//fine

/*
function menuLocationNuovoContratto(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=3&submenu_link=nuovo_contratto";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=nuovo_contratto.php";
}

function menuLocationRicercaContratto(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=3&submenu_link=ricerca_contratto";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_contratto_gestore.php";
}

function menuLocationFattureGestore(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=6&submenu_link=nuova_fattura";
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_fatture_gestore.php";
}

function submenuLocationNuovaFatt(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=6&submenu_link=nuova_fattura";
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=gestione_fatture_gestore.php";
}

function submenuLocationCaricoLav(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=0&submenu_link=carico_lav";	
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=carico_lavorativo_sett.php";
}

function submenuLocationRicercaFatt(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=6&submenu_link=ricerca_fatt";
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_fatture_gestore.php";
}

function submenuLocationStatoApp(){
	var oElementMenu = parent.document.getElementById("menu_sx");	
	oElementMenu.src = "menu_backend.php?submenu_agenda=0&submenu_link=cambia_stato_app";
	var oElementBody = parent.document.getElementById("frame_body");	
	oElementBody.src = "body.php?SUBFUNCTION=ricerca_stato_app.php";
}
*/
function findBrowser(){
	if (document.all){ // Explorer
		return 0;	
	}
	else if (document.getElementById){ //Netscape 6.x
		return 1;
	}	
}

function controllaFatturaTrainer(){
	var numero_fattura = document.genera_fattura.numero_fattura.value;
	if(numero_fattura == ""){
		alert('ATTENZIONE! Numero di fattura nn valido!');
		return false;	
	}
	else{
		document.genera_fattura.submit();
	}
}

function anno_bisestile(anno){
	var ritorno = false;
	if(anno % 100 == 0){
		if(anno % 400 == 0){
			ritorno = true;
		}
	}
	else{
		if (anno % 4 == 0){
			ritorno = true;
		}
	} 
	return ritorno;
}	

function verifica_data(giorno, mese, anno) {
	if(!controllaCampoInteroData(giorno) || !controllaCampoInteroData(mese) || !controllaCampoInteroData(anno)) {
		alert("Inserisci un campo numerico!");
		return false;
	}
	if(giorno > 31 || mese > 12 || anno.length > 5 || anno.length < 4) {
		alert("Inserisci un campo valido!");
	}
	if(giorno != "" && mese != "" && anno != ""){ 
		var stato;
		data_immessa = new Date(anno,mese,giorno);
		mese_ita = data_immessa.getMonth();
		mese_ita = mese_ita - 1;
		data_immessa = new Date(anno,mese_ita,giorno);
		
		if((giorno > 30 ) && (mese == 11 || mese == 4 || mese == 6 || mese == 9) ){
			alert("Impossibile utilizzare un valore corrispondente al giorno superiore a 30 per il mese indicato!");
			return false;
		}
		
		else if(anno_bisestile(anno) == false && giorno > 28 && mese == 2){
			alert("Impossibile utilizzare un valore corrispondente al giorno superiore a 28 per il mese indicato!");
			return false;
		}
			
		else if(anno_bisestile(anno) == true && giorno > 29 && mese==2){
		   	alert("Impossibile utilizzare un valore corrispondente al giorno superiore a 29 per il mese indicato!");
		   	return false;
		}
		else{
			return true;	
		}
	}
	else if(giorno == "" || mese == "" || anno == ""){ 
		alert("Campo data inserito non valido");
		return false;
	}
}

function validaEmail(form_email){
	var email = form_email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")){
		alert("ATTENZIONE!Inserire un indirizzo email corretto!");
		form_email.value = "";
		form_email.focus(); 
		return false;
	}
	else{
		return true;
	}
}

function controllaDataRicerca(data){
	var campo = data.value;
	if(campo != ""){
		var gg = campo.substring(0,2);
		var mm = campo.substring(3,5);
		var aa = campo.substring(6,10);
		var data_corrente = new Date();
		var data_immessa = new Date(aa,mm,gg);
		var mm_ita = data_immessa.getMonth();
		mm_ita = mm_ita - 1;
		data_immessa = new Date(aa,mm_ita,gg);
		
		if(campo.substring(2,3) != "/" ||
		   campo.substring(5,6) != "/" ||
		   isNaN(campo.substring(0,2)) ||
		   isNaN(campo.substring(3,5)) ||
		   isNaN(campo.substring(6,10))) {
		      alert("Inserire la data nel formato gg/mm/aaaa!");
		      data.value = "";
		      data.focus();
		      return false;
		}
		
		else if(mm < 1 || gg < 1 ) {
		   	alert("Data non valida!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
		
		else if(mm > 12 ) {
		   	alert("Impossibile utilizzare un valore superiore a 12 per i mesi!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
			
		else if(aa < 1900) {
		   	alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
			
		else if( (gg > 30 ) && (mm==11 || mm==4 || mm==6 || mm==9) ) {
		   	alert("Impossibile utilizzare un valore corrispondente al giorno superiore a 30 per il mese indicato!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
		
		else if (anno_bisestile(aa) == false &&  gg > 28 && (mm==2) ) {
		   	alert ("Impossibile utilizzare un valore corrispondente al giorno superiore a 28 per il mese indicato!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
		
		else if (anno_bisestile(aa) == true &&  gg > 29 && (mm==2) ) {
		   	alert ("Impossibile utilizzare un valore corrispondente al giorno superiore a 29 per il mese indicato!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
			
		else if (gg > 31) {
		   	alert("Impossibile utilizzare un valore superiore a 31 per i giorni!");
		   	data.value="";
		   	data.focus();
		   	return false;
		}
		else{
			return true;	
		}
	}
}

function confrontaData(data1,data2){
	if(data1 != "" && data2 != ""){
		data1_gg = data1.substring(0,2);
		data1_mm = data1.substring(3,5);
		data1_aa = data1.substring(6,10);
		data1_value = new Date(data1_aa,data1_mm,data1_gg);
		
		data2_gg = data2.substring(0,2);
		data2_mm = data2.substring(3,5);
		data2_aa = data2.substring(6,10);
		data2_value = new Date(data2_aa,data2_mm,data2_gg);
		
		if(data1_value > data2_value){
			alert("Il campo 'data dal' è maggiore del campo 'data al'!");
			return false;
		}
		else{
			return true;
		}
	}
	else if(data1 == "" && data2 != ""){
		alert("Con il campo 'data al' valorizzato è necessario inserire un valore per il campo 'data dal'!");
		return false;
	}
	else if(data1 == "" && data2 == ""){
		alert("Inserire il periodo di tempo!");
		return false;
	}
	else{
		return true;
	}
}

function verificaRegistrazione(){
	var nome = document.nuovo_cliente.nome.value;
	var cognome = document.nuovo_cliente.cognome.value;
	var email = document.nuovo_cliente.email.value;
	var telefono_casa = document.nuovo_cliente.telefono_casa.value;
	var telefono_ufficio = document.nuovo_cliente.telefono_ufficio.value;
	var cellulare_1 = document.nuovo_cliente.cellulare_1.value;
	var cellulare_2 = document.nuovo_cliente.cellulare_2.value;
	var indirizzo = document.nuovo_cliente.indirizzo.value;
	var citta_residenza = document.nuovo_cliente.citta_residenza.value;
	var provincia_residenza = document.nuovo_cliente.provincia_residenza.value;
	var cap = document.nuovo_cliente.cap.value;
	var codice_fiscale = document.nuovo_cliente.codice_fiscale.value;
	
	if(nome == ""){
		alert('ATTENZIONE! Il campo nome è obbligatorio!');
		document.nuovo_cliente.nome.focus();
		return false;		
	}
	
	if(cognome == ""){
		alert('ATTENZIONE! Il campo cognome è obbligatorio!');
		document.nuovo_cliente.cognome.focus();		
		return false;
	}
	
	if(telefono_casa == "" && telefono_ufficio == "" && cellulare_1 == "" && cellulare_2 == ""){
		alert('ATTENZIONE! Almeno un numero di telefono deve essere inserito!');
		return false;	
	}
	
	if(indirizzo == ""){
		alert("ATTENZIONE! Il campo indirizzo è obbligatorio!");
		document.nuovo_cliente.indirizzo.focus();		
		return false;
	}
	
	if(citta_residenza == ""){
		alert('ATTENZIONE! Il campo città residenza è obbligatorio!');
		document.nuovo_cliente.citta_residenza.focus();		
		return false;
	}
	
	if(provincia_residenza == ""){
		alert('ATTENZIONE! Il campo provincia residenza è obbligatorio!');
		document.nuovo_cliente.provincia_residenza.focus();		
		return false;
	}
	
	if(cap == ""){
		alert('ATTENZIONE! Il campo CAP è obbligatorio!');
		document.nuovo_cliente.cap.focus();		
		return false;
	}
	
	if(codice_fiscale != ""){
		if(codice_fiscale.length < 16){
			alert('ATTENZIONE! Il campo codice fiscale deve contenere 16 caratteri!');
			document.nuovo_cliente.codice_fiscale.focus();		
			return false;
		}
	}
	
	document.nuovo_cliente.submit();
	return true;
}

function formattaCampoData(campo){
	campo = String(campo);
	var campo_mod;
	
	switch (campo){ 
		case "0":
		campo_mod = "00";
		break;
    
		case "1":
		campo_mod = "01";
		break;
		
		case "2":
		campo_mod = "02";
		break;
		
		case "3":
		campo_mod = "03";
		break;
		
		case "4":
		campo_mod = "04";
		break;
		
		case "5":
		campo_mod = "05";
		break;
		
		case "6":
		campo_mod = "06";
		break;
		
		case "7":
		campo_mod = "07";
		break;
		
		case "8":
		campo_mod = "08";
		break;
		
		case "9":
		campo_mod = "09";
		break;																			
	}	
	return campo_mod;
}

function CheckKey(id){
	if (window.event.keyCode == 13){
		var oElement = document.getElementById(id);
		oElement.click();
	}
}

function calcolaImporto(totale,quantita,unitario){
	var quantita_abbonamento = quantita.value;
	var prezzo_unitario = unitario.value;
	var prezzo_totale;
	
	if(quantita_abbonamento != ""){
		prezzo_totale = quantita_abbonamento * prezzo_unitario;	
		totale.value = prezzo_totale;
	}
	else{
		return false;	
	}
}

//--prenota_appuntamento_cliente.php--//
function verificaOra(input_ora){
	var ora = input_ora.value;
	
	if(ora.substring(0,1) == 0){
		var ore = parseInt(ora.substring(1,2));	
	}
	else{
		var ore = parseInt(ora.substring(0,2));
	}
	
	if(ora.substring(3,4) == 0){
		var minuti = parseInt(ora.substring(4,5));
	}
	else{
		var minuti = parseInt(ora.substring(3,5));	
	}
	
	if(ora != ""){
		if(ora.substring(2,3) != ":" || isNaN(ora.substring(0,2)) || isNaN(ora.substring(3,5))){
			alert("ATTENZIONE! Inserire l'ora nel formato hh:mm !");
			input_ora.value = "";
			input_ora.focus();
			return false;	
		}
		else if((ore < 7 || ore > 22) || (minuti < 0 || minuti > 59)){
			alert("ATTENZIONE! L'orario utile per lo svolgimento dell'appuntamento va dalle 07:00 alle 22:00 !");
			input_ora.value = "";
			input_ora.focus();
			return false;	
		}
	}
}

function confrontaOra(input_start, input_end){
	var ora_start = input_start.value;
	var ora_end = input_end.value;
	
	var array_campi_start = ora_start.split(":");
	var ore_start = array_campi_start[0];
	var minuti_start = array_campi_start[1];
				
	var array_campi_end = ora_end.split(":");
	var ore_end = array_campi_end[0];
	var minuti_end = array_campi_end[1];
					
	ora_start = new Date(2000,01,01,ore_start,minuti_start);
	ora_end = new Date(2000,01,01,ore_end,minuti_end);
	
	if(ora_end <= ora_start){
		alert('ATTENZIONE! L\'ora di fine appuntamento inserita è minore di quella di inizio!');
		input_start.value = "";
		input_end.value = "";
		input_start.focus();
		return false;	
	}	
	else{
		return true;	
	}
}

function inviaPrenotazione(){
	if(document.prenota_appuntamento.data_appuntamento.value == ""){
		alert("ATTENZIONE! Data appuntamento non valorizzata!");
		document.prenota_appuntamento.data_appuntamento.value = "";
		document.prenota_appuntamento.data_appuntamento.focus();
		return false;	
	}
		
	if(document.prenota_appuntamento.ora_inizio_appuntamento.value == ""){
		alert("ATTENZIONE! Ora inizio appuntamento non valorizzata!");
		document.prenota_appuntamento.ora_inizio_appuntamento.value = "";
		document.prenota_appuntamento.ora_inizio_appuntamento.focus();
		return false;	
	}
		
	if(document.prenota_appuntamento.ora_fine_appuntamento.value == ""){
		alert("ATTENZIONE! Ora fine appuntamento non valorizzata!");
		document.prenota_appuntamento.ora_fine_appuntamento.value = "";
		document.prenota_appuntamento.ora_fine_appuntamento.focus();
		return false;	
	}
		
	if(confrontaOra(document.prenota_appuntamento.ora_inizio_appuntamento,document.prenota_appuntamento.ora_fine_appuntamento) != false){
		document.prenota_appuntamento.submit();	
	}
}
//--end prenota_appuntamento_cliente.php--//


//--funzioni specifiche per la pagina body.php--//
function checkInsAppMultiplo(){
	var data_appuntamento = document.ins_app_multiplo.data_end_inserimento.value;
	if(data_appuntamento != ""){
		if (window.confirm("ATTENZIONE: inserisco gli appuntamenti fino alla data " + data_appuntamento + "?")){
			document.ins_app_multiplo.submit();			
		}
		else{
			return false;	
		}
	}
	else{
		document.ins_app_multiplo.submit();	
	}
}

function CheckArray(obj){
	var lenLevel = obj.length;
	bArray = typeof(lenLevel)!="undefined"
	return bArray;
}

function selectAll(){
	var obj = document.cambia_stato_app.elements['cod_appuntamento_change[]'];
	if(CheckArray(obj)){
		var dim = document.cambia_stato_app.elements['cod_appuntamento_change[]'].length;
		for(x=0; x<dim; x++){
			obj[x].checked = 'true';
		}
	}
	else{
		obj.checked = 'true';	
	}					
}

function deselectAll(){
	var obj = document.cambia_stato_app.elements['cod_appuntamento_change[]'];
	if(CheckArray(obj)){
		var dim = document.cambia_stato_app.elements['cod_appuntamento_change[]'].length;
		for(x=0; x<dim; x++){
			obj[x].checked = '';
		}
	}
	else{
		obj.checked = '';	
	}		
}

function cambiaAllCheck(){
	var obj = document.cambia_stato_app.select_all;
	if(obj.checked == false){
		deselectAll();	
	}
	else if(obj.checked == true){
		selectAll();	
	}
}

function selectAllRate(){
	var obj = document.form_numero_rate.elements['seleziona_rata[]'];
	if(CheckArray(obj)){
		var dim = document.form_numero_rate.elements['seleziona_rata[]'].length;
		for(x=0; x<dim; x++){
			obj[x].checked = 'true';
		}
	}
	else{
		obj.checked = 'true';	
	}					
}

function deselectAllRate(){
	var obj = document.form_numero_rate.elements['seleziona_rata[]'];
	if(CheckArray(obj)){
		var dim = document.form_numero_rate.elements['seleziona_rata[]'].length;
		for(x=0; x<dim; x++){
			obj[x].checked = '';
		}
	}
	else{
		obj.checked = '';	
	}		
}

function cambiaAllCheckRate(){
	var obj = document.form_numero_rate.select_all;
	if(obj.checked == false){
		deselectAllRate();	
	}
	else if(obj.checked == true){
		selectAllRate();	
	}
}

function checkSubmitRate(){
	var obj = document.form_numero_rate.elements['seleziona_rata[]'];
	var numero_rate_fattura = 0;
	if(CheckArray(obj)){
		var numero_rate = document.form_numero_rate.elements['seleziona_rata[]'].length;
		for(x=0; x<numero_rate; x++){
			if(obj[x].checked == true){
				numero_rate_fattura = parseInt(numero_rate_fattura) + 1;
			}
		}
		if(numero_rate_fattura == 0){
			alert('ATTENZIONE! Nessuna rata selezionata!');
			return false;	
		}
		else{
			document.form_numero_rate.numero_rate_fattura.value = numero_rate_fattura;
			document.form_numero_rate.submit();
		}
	}
}

function controllaAccount()
{
	//alert("3");
	
	var password = document.account_gestore.password.value;
	var check_password = document.account_gestore.check_password.value;
	var username = document.account_gestore.username.value;
	var email = document.account_gestore.email.value;
	
	if(email == "")
	{
		alert('ATTENZIONE! il campo email è obbligatorio!');
		document.account_gestore.email.value = "";
		document.account_gestore.email.focus();
		return false;
	}
	else
	{
		var err = verifica_email(email);
		
		if (err > "")
		{
			alert(err);
			
			document.account_gestore.email.focus();
			
			return false;
		}
	}
	
	if(username == "")
	{
		alert('ATTENZIONE! il campo username è obbligatorio!');
		document.account_gestore.username.value = "";
		document.account_gestore.username.focus();
		return false;
	}
	
	if(password == "")
	{
		alert('ATTENZIONE! il campo password è obbligatorio!');
		document.account_gestore.password.value = "";
		document.account_gestore.password.focus();
		return false;
	}
	
	if(password != check_password)
	{
		alert("ATTENZIONE! La password di conferma non è uguale alla precedente!");
		document.account_gestore.check_password.value = "";
		document.account_gestore.check_password.focus();	
		return false;
	}
	document.account_gestore.submit();	
}

function verifica_email(email) 
{
	var str=email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str)) return("Email non valida");
	
}

/*funzione da completare non cancellare*/
function controllaSelezioneAbb(){
	document.seleziona_contratti.submit();
}
/**************************************/

function testAccount(){
	var username = document.gestione_account.username.value;
	var password = document.gestione_account.password.value;
	var conferma_password = document.gestione_account.conferma_password.value;
	if(username == "" || password == "" || conferma_password == "") {
		alert("Non hai inserito tutti i dati!");
		return false;
	}
	else if(password != conferma_password) {
		alert("Non hai inserito la stessa password!");	
		return false;
	} else {
		document.gestione_account.submit();
		return true;
	}
}

function inviaRicercaTrainer(suffisso_page){
	var tipo_browser = findBrowser();
	var data_appuntamento = document.cerca_trainer.data_appuntamento.value;
	var ora_inizio_appuntamento = document.cerca_trainer.ora_inizio_appuntamento.value;
	var ora_fine_appuntamento = document.cerca_trainer.ora_fine_appuntamento.value;
	var cod_cliente = document.cerca_trainer.cod_cliente.value;
	var stato;
	if(data_appuntamento == ""){
		alert('Data appuntamento non valorizzata!');
		return false;
	}
		
	if(ora_inizio_appuntamento == ""){
		alert('Ora inizio appuntamento non valorizzata!');
		return false;
	}
	
	if(ora_fine_appuntamento == ""){
		alert('Ora fine appuntamento non valorizzata!');
		return false;
	}
	
	var page = "elenco_trainer_appuntamento" + suffisso_page + ".php";
	
	document.cerca_trainer.ricerca_eseguita.value = 1;
	
	if(tipo_browser == 0){ 
		//explorer
		var obj = top.framebody.elenco_trainer;
		var data_inizio_settimana = obj.form_data_inizio.data_inizio_settimana.value;
		var shift = obj.form_data_inizio.shift.value;
		obj.location = page + '?data_appuntamento='+data_appuntamento+'&ora_inizio_appuntamento='+ora_inizio_appuntamento+'&ora_fine_appuntamento='+ora_fine_appuntamento+'&cod_cliente='+cod_cliente+'&tipo_ricerca=no_option&data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift;
	}
	else if(tipo_browser == 1){ 
		//netscape
		var obj = document.getElementById('elenco_trainer');
		var data_inizio_settimana = obj.contentDocument.form_data_inizio.data_inizio_settimana.value;
		var shift = obj.contentDocument.form_data_inizio.shift.value;
		obj.location = page + '?data_appuntamento='+data_appuntamento+'&ora_inizio_appuntamento='+ora_inizio_appuntamento+'&ora_fine_appuntamento='+ora_fine_appuntamento+'&cod_cliente='+cod_cliente+'&tipo_ricerca=no_option&data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift;
	}	
}

function dettaglioAppuntamentoCliente(cod_appuntamento){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj = top.framebody.frame_dettaglio;
	}
	else if(tipo_browser == 1){
		var obj = document.getElementById('frame_dettaglio');
	}
	
	var frame_location = 'dettaglio_agenda_cliente.php?cod_appuntamento=' + cod_appuntamento;
	
	//alert(frame_location);
	
	obj.location = frame_location;
}
	
function aggiornaClienteIndirizzo(cod_cliente_indirizzo){
	var tipo_browser = findBrowser();
	try{
		var obj = document.getElementById('elenco_trainer');
		obj.contentDocument.form_data_inizio.cod_cliente_indirizzo.value = cod_cliente_indirizzo;
	}
	catch(err){
	    var stinga='aggiornaClienteIndirizzo('+cod_cliente_indirizzo+');';
		setTimeout(stinga,3000);
	}
}
	
function changeFrameElenco(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj_frame = top.framebody.elenco_trainer;
		var frame_location = obj_frame.location.pathname;
		if(frame_location != '/backend/frame_ricerca_trainer.php'){
			var data_inizio_settimana = obj_frame.form_data_inizio.data_inizio_settimana.value;
			var shift = obj_frame.form_data_inizio.shift.value;
			var cod_cliente = obj_frame.form_data_inizio.cod_cliente.value;
			var source_frame = 'frame_ricerca_trainer.php?data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift + '&cod_cliente=' + cod_cliente;  
			obj_frame.location = source_frame;
		}
		else{
			return false;
		}
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var frame_location = obj_frame.src;
		var array_location = frame_location.split('/');
		var array_page = array_location[4].split('?');
		var page_src = array_page[0];
		if(page_src != 'frame_ricerca_trainer.php'){
			var data_inizio_settimana = obj_frame.contentDocument.form_data_inizio.data_inizio_settimana.value;
			var shift = obj_frame.contentDocument.form_data_inizio.shift.value;
			var cod_cliente = obj_frame.contentDocument.form_data_inizio.cod_cliente.value;
			var source_frame = 'frame_ricerca_trainer.php?data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift + '&cod_cliente=' + cod_cliente;  
			obj_frame.src = source_frame;
		}
		else{
			return false;	
		}
	}	
}

function changeFrameElencoOperatore(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj_frame = top.framebody.elenco_trainer;
		var frame_location = obj_frame.location.pathname;
		if(frame_location != '/backend/frame_ricerca_trainer_operatore.php'){
			var data_inizio_settimana = obj_frame.form_data_inizio.data_inizio_settimana.value;
			var shift = obj_frame.form_data_inizio.shift.value;
			var cod_cliente = obj_frame.form_data_inizio.cod_cliente.value;
			var source_frame = 'frame_ricerca_trainer_operatore.php?data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift + '&cod_cliente=' + cod_cliente;  
			obj_frame.location = source_frame;
		}
		else{
			return false;
		}
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var frame_location = obj_frame.src;
		var array_location = frame_location.split('/');
		var array_page = array_location[4].split('?');
		var page_src = array_page[0];
		if(page_src != 'frame_ricerca_trainer_operatore.php'){
			var data_inizio_settimana = obj_frame.contentDocument.form_data_inizio.data_inizio_settimana.value;
			var shift = obj_frame.contentDocument.form_data_inizio.shift.value;
			var cod_cliente = obj_frame.contentDocument.form_data_inizio.cod_cliente.value;
			var source_frame = 'frame_ricerca_trainer_operatore.php?data_inizio_settimana=' + data_inizio_settimana + '&shift=' + shift + '&cod_cliente=' + cod_cliente;  
			obj_frame.src = source_frame;
		}
		else{
			return false;	
		}
	}	
}

function changeRicerca(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj_frame = top.framebody.elenco_trainer;
		var cod_cliente = obj_frame.form_data_inizio.cod_cliente.value;
		var source_frame = 'elenco_trainer_appuntamento.php?tipo_ricerca=default&cod_cliente=' + cod_cliente;  
		obj_frame.location = source_frame;
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var cod_cliente = obj_frame.contentDocument.form_data_inizio.cod_cliente.value;
		var source_frame = 'elenco_trainer_appuntamento.php?tipo_ricerca=default';  
		obj_frame.src = source_frame;
	}	
}

function changeRicercaOperatore(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj_frame = top.framebody.elenco_trainer;
		var cod_cliente = obj_frame.form_data_inizio.cod_cliente.value;
		var source_frame = 'elenco_trainer_appuntamento_operatore.php?tipo_ricerca=default&cod_cliente=' + cod_cliente;  
		obj_frame.location = source_frame;
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var cod_cliente = obj_frame.contentDocument.form_data_inizio.cod_cliente.value;
		var source_frame = 'elenco_trainer_appuntamento_operatore.php?tipo_ricerca=default';  
		obj_frame.src = source_frame;
	}	
}

function changeRicercaCliente(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj_frame = top.framebody.elenco_trainer;
		var source_frame = 'elenco_trainer_appuntamento_cliente.php?tipo_ricerca=default'; 
		obj_frame.location = source_frame;
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var source_frame = 'elenco_trainer_appuntamento_cliente.php?tipo_ricerca=default';  
		obj_frame.src = source_frame;
	}	
}
	
function visualizzaBottoneRiepilogo(cod_trainer,cod_cliente,data_appuntamento,ora_inizio_appuntamento,ora_fine_appuntamento){
	var tipo_browser = findBrowser();
	var ricerca_effettuata = document.cerca_trainer.ricerca_eseguita.value;
		
	if(tipo_browser == 0){ //exploder
		var button_anteprima = top.framebody.elenco_trainer.bottone_ant;
	}
	else if(tipo_browser == 1){
		var obj_frame = document.getElementById('elenco_trainer');
		var button_anteprima = obj_frame.contentDocument.getElementById('button_anteprima');
	}
	
	if(cod_trainer != "" && cod_cliente != "" && data_appuntamento != "" && ora_inizio_appuntamento != "" && ora_fine_appuntamento != "" && ricerca_effettuata == 1){
		button_anteprima.style.visibility = 'visible';
	}
	else{
		document.cerca_trainer.ricerca_eseguita.value = 0;
		button_anteprima.style.visibility = 'hidden';
	}
}
	
function annullaSelezione(){
	document.ricerca_app_gestore.tipo_ricerca_tempo[0].checked=false; 
	document.ricerca_app_gestore.tipo_ricerca_tempo[1].checked=false;
	document.ricerca_app_gestore.data_start.readOnly = 'readonly'; 
	document.ricerca_app_gestore.data_end.readOnly = 'readonly'; 
	document.ricerca_app_gestore.data_ricerca.readOnly = 'readonly';
	document.ricerca_app_gestore.data_start.value = ''; 
	document.ricerca_app_gestore.data_end.value = ''; 
	document.ricerca_app_gestore.data_ricerca.value = '';
}

function inviaRicercaAppGestore(){
	var ricerca_periodo = document.ricerca_app_gestore.tipo_ricerca_tempo[0].checked;
	var ricerca_data = document.ricerca_app_gestore.tipo_ricerca_tempo[1].checked;
	if(ricerca_periodo == true && ricerca_data == false){
		var confronto_date = confrontaData(document.ricerca_app_gestore.data_start.value, document.ricerca_app_gestore.data_end.value);
		if(confronto_date == true){
			document.ricerca_app_gestore.submit();	
		}
		else{
			return false;	
		}	
	}
	else{
		document.ricerca_app_gestore.submit();	
	}
}

function insertAbbonamentoCorp(){
	var data_inizio = document.insert_contratto_corp.data_inizio.value;
	var data_fine =  document.insert_contratto_corp.data_fine.value;
	var costo_abbonamento =  document.insert_contratto_corp.costo_abbonamento.value;
	var numero_rate =  document.insert_contratto_corp.numero_rate.value;
	var confronto_date = confrontaData(data_inizio,data_fine);

	if(confronto_date == true){
		if(data_fine == ""){
			alert('ATTENZIONE! Campo data fine non valorizzato!');
			return false;		
		}
		
		if(costo_abbonamento == ""){
			alert('ATTENZIONE! Campo importo non valorizzato!');
			return false;	
		}
	
		if(numero_rate == ""){
			alert('ATTENZIONE! Campo numero rate non valorizzato!');
			return false;	
		}
	}
	else{
		return false;	
	}
	
	document.insert_contratto_corp.submit();
}

function inviaRicercaContratto(){
	var data_da = document.ricerca_contratto.data_start.value;
	var data_a =  document.ricerca_contratto.data_end.value;
	if(data_da != ""){
		var confronto_date = confrontaData(data_da,data_a);
		if(confronto_date == true){
			document.ricerca_contratto.submit();	
		}
		else{
			return false;	
		}
	}	
	else{
		document.ricerca_contratto.submit();
	}
}


function visualizzaAnteprima(cod_appuntamento,update){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj = top.framebody.elenco_trainer;
		var cod_trainer = obj.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.form_data_inizio.cod_cliente.value;
		var frame_cliente = top.framebody.frame_dati_cliente;
		var cod_cliente_indirizzo = frame_cliente.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	else if(tipo_browser == 1){
		var obj = document.getElementById('elenco_trainer');	
		var cod_trainer = obj.contentDocument.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.contentDocument.form_data_inizio.cod_cliente.value;
		var frame_cliente = document.getElementById('frame_dati_cliente');	
		var cod_cliente_indirizzo = frame_cliente.contentDocument.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	var data_appuntamento = document.cerca_trainer.data_appuntamento.value;
	var ora_inizio_appuntamento = document.cerca_trainer.ora_inizio_appuntamento.value;	
	var ora_fine_appuntamento = document.cerca_trainer.ora_fine_appuntamento.value;
	var distanza_km = document.cerca_trainer.distanza_km.value;
	
	if(cod_trainer == ""){
		alert("Selezionare un trainer!");
		return false;
	}
	if(cod_cliente == ""){
		alert("Selezionare un cliente!");	
		return false;
	}
	if(data_appuntamento == ""){
		alert("Data appuntamento non valorizzata!");
		return false;	
	}
	if(ora_inizio_appuntamento == "" || ora_fine_appuntamento == ""){
		alert("Orario appuntamento non valorizzato!");
		return false;		
	}
	
	
	
	
	document.location = 'body.php?SUBFUNCTION=nuovo_appuntamento.php&cod_trainer=' + cod_trainer + '&cod_cliente=' + cod_cliente + '&data_appuntamento=' + data_appuntamento + '&ora_inizio_appuntamento=' + ora_inizio_appuntamento + '&ora_fine_appuntamento=' + ora_fine_appuntamento + '&distanza_km=' + distanza_km + "&cod_cliente_indirizzo=" + cod_cliente_indirizzo + "&cod_appuntamento=" + cod_appuntamento + "&update=" + update; 
}

function visualizzaAnteprimaOperatore(cod_appuntamento,update){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj = top.framebody.elenco_trainer;
		var cod_trainer = obj.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.form_data_inizio.cod_cliente.value;
		var frame_cliente = top.framebody.frame_dati_cliente;
		var cod_cliente_indirizzo = frame_cliente.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	else if(tipo_browser == 1){
		var obj = document.getElementById('elenco_trainer');	
		var cod_trainer = obj.contentDocument.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.contentDocument.form_data_inizio.cod_cliente.value;
		var frame_cliente = document.getElementById('frame_dati_cliente');	
		var cod_cliente_indirizzo = frame_cliente.contentDocument.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	var data_appuntamento = document.cerca_trainer.data_appuntamento.value;
	var ora_inizio_appuntamento = document.cerca_trainer.ora_inizio_appuntamento.value;	
	var ora_fine_appuntamento = document.cerca_trainer.ora_fine_appuntamento.value;
	var distanza_km = document.cerca_trainer.distanza_km.value;
	
	if(cod_trainer == ""){
		alert("Selezionare un trainer!");
		return false;
	}
	if(cod_cliente == ""){
		alert("Selezionare un cliente!");	
		return false;
	}
	if(data_appuntamento == ""){
		alert("Data appuntamento non valorizzata!");
		return false;	
	}
	if(ora_inizio_appuntamento == "" || ora_fine_appuntamento == ""){
		alert("Orario appuntamento non valorizzato!");
		return false;		
	}
	document.location = 'body.php?SUBFUNCTION=nuovo_appuntamento_operatore.php&cod_trainer=' + cod_trainer + '&cod_cliente=' + cod_cliente + '&data_appuntamento=' + data_appuntamento + '&ora_inizio_appuntamento=' + ora_inizio_appuntamento + '&ora_fine_appuntamento=' + ora_fine_appuntamento + '&distanza_km=' + distanza_km + "&cod_cliente_indirizzo=" + cod_cliente_indirizzo + "&cod_appuntamento=" + cod_appuntamento + "&update=" + update; 
}

function visualizzaAnteprimaCliente(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var obj = top.framebody.elenco_trainer;
		var cod_trainer = obj.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.form_data_inizio.cod_cliente.value;
		var frame_cliente = top.framebody.frame_dati_cliente;
		var cod_cliente_indirizzo = frame_cliente.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	else if(tipo_browser == 1){
		var obj = document.getElementById('elenco_trainer');	
		var cod_trainer = obj.contentDocument.form_data_inizio.cod_trainer.value;
		var cod_cliente = obj.contentDocument.form_data_inizio.cod_cliente.value;
		var frame_cliente = document.getElementById('frame_dati_cliente');	
		var cod_cliente_indirizzo = frame_cliente.contentDocument.form_carica_indirizzo.cod_cliente_indirizzo.value;
	}
	var data_appuntamento = document.cerca_trainer.data_appuntamento.value;
	var ora_inizio_appuntamento = document.cerca_trainer.ora_inizio_appuntamento.value;	
	var ora_fine_appuntamento = document.cerca_trainer.ora_fine_appuntamento.value;
	
	if(cod_trainer == ""){
		alert("Selezionare un trainer!");
		return false;
	}
	if(cod_cliente == ""){
		alert("Selezionare un cliente!");	
		return false;
	}
	if(data_appuntamento == ""){
		alert("Data appuntamento non valorizzata!");
		return false;	
	}
	if(ora_inizio_appuntamento == "" || ora_fine_appuntamento == ""){
		alert("Orario appuntamento non valorizzato!");
		return false;		
	}
	popNew('riepilogo_appuntamento_cliente.php?cod_trainer=' + cod_trainer + '&cod_cliente=' + cod_cliente + '&data_appuntamento=' + data_appuntamento + '&ora_inizio_appuntamento=' + ora_inizio_appuntamento + '&ora_fine_appuntamento=' + ora_fine_appuntamento + '&cod_cliente_indirizzo=' + cod_cliente_indirizzo,'pop_anteprima_cliente',330,600); 
}

function inviaRicercaCognome(){
	var string_cognome = document.form_cognome.filtro_cognome.value.replace(/(^ +| +$)/, "");
	if(string_cognome == ""){
		alert("Campo non valorizzato!");
		return false;
	}
	else{
		document.form_cognome.submit();
	}
}

function checkDatiFattura(){
	var numero_fattura = document.dati_fattura.numero_fattura_cliente.value;
	var data_fattura = document.dati_fattura.data_fattura.value;
	
	if(numero_fattura == ""){
		alert('ATTENZIONE!Numero fattura non valorizzato!');
		document.dati_fattura.numero_fattura_cliente.focus();
		return false;
	}
	
	if(data_fattura == ""){
		alert('ATTENZIONE!Data fattura non valorizzata!');
		document.dati_fattura.data_fattura.focus();
		return false;
	}
	
	document.dati_fattura.submit();
	return true;	
}

function verificaAbbonamentiCliente()
{
	var costo_tot = document.insert_contratto.totale_complessivo.value;	
	
	if(costo_tot == "" || costo_tot == 0)
	{
		alert('ATTENZIONE!Nessun contratto è stato selezionato!');
	}
	else{
		document.insert_contratto.submit();	
	}
}

function changeFrameBestOf(cod_regione){
	var frame_best_of = document.getElementById('frame_best_of');
	frame_best_of.src = 'best_of_regione.php?cod_regione=' + cod_regione;	
}

function changeFrameStaff(cod_regione){
	var frame_staff = document.getElementById('frame_staff');
	frame_staff.src = 'staff_regione.php?cod_regione=' + cod_regione;	
}
//--end funzioni specifiche per la pagina body.php--//

//--frame_dati_cliente.php--//
function agendaCliente(cod_cliente){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){ //exploder
		var frame_agenda = top.framebody.frame_agenda;
		var data_inizio_settimana = frame_elenco.form_data_inizio.data_inizio_settimana.value;
		var shift = frame_elenco.form_data_inizio.shift.value;
		
		frame_agenda.location = "visualizza_agenda_appuntamento.php?cod_trainer=&cod_cliente=" + cod_cliente + "&data_inizio_settimana=" + data_inizio_settimana + "&shift=" + shift;
	}
	else if(tipo_browser == 1){
		var frame_agenda = parent.document.getElementById("frame_agenda");
		var frame_elenco = parent.document.getElementById("elenco_trainer");
		var data_inizio_settimana = frame_elenco.contentDocument.form_data_inizio.data_inizio_settimana.value;
		var shift = frame_elenco.contentDocument.form_data_inizio.shift.value;
		frame_agenda.src = "visualizza_agenda_appuntamento.php?cod_trainer=&cod_cliente=" + cod_cliente + "&data_inizio_settimana=" + data_inizio_settimana + "&shift=" + shift;
	}
}

function reloadElencoTrainer(){
	var tipo_browser = findBrowser();
	if(tipo_browser == 0){
		var frame_elenco = top.framebody.elenco_trainer;
		var data_inizio_settimana = frame_elenco.form_data_inizio.data_inizio_settimana.value;
		var shift = frame_elenco.form_data_inizio.shift.value;
		var cod_trainer = frame_elenco.form_data_inizio.cod_trainer.value;
		var cod_cliente = frame_elenco.form_data_inizio.cod_cliente.value;
		var check_bold = frame_elenco.form_data_inizio.check_bold.value;
		var tipo_ricerca = frame_elenco.form_data_inizio.tipo_ricerca.value;
		var cod_livello = frame_elenco.form_data_inizio.cod_livello.value;
		var cod_provincia = frame_elenco.form_data_inizio.cod_provincia.value;
		var find_cognome = frame_elenco.form_data_inizio.find_cognome.value;
		var ora_inizio_appuntamento = frame_elenco.form_data_inizio.ora_inizio_appuntamento.value;
		var ora_fine_appuntamento = frame_elenco.form_data_inizio.ora_fine_appuntamento.value;
		var data_appuntamento = frame_elenco.form_data_inizio.data_appuntamento.value;
		
		frame_elenco.location = 'elenco_trainer_appuntamento.php?data_inizio_settimana='+data_inizio_settimana+'&shift='+shift+'&cod_cliente='+cod_cliente+'&cod_trainer='+cod_trainer+'&check_bold='+check_bold+'&tipo_ricerca='+tipo_ricerca+'&cod_livello='+cod_livello+'&cod_provincia='+cod_provincia+'&find_cognome='+find_cognome+'&ora_inizio_appuntamento='+ora_inizio_appuntamento+'&ora_fine_appuntamento='+ora_fine_appuntamento+'&data_appuntamento='+data_appuntamento;
		
	}
	else if(tipo_browser == 1)
	{
		var frame_elenco = parent.document.getElementById("elenco_trainer");
		var data_inizio_settimana = frame_elenco.contentDocument.form_data_inizio.data_inizio_settimana.value;
		var shift = frame_elenco.contentDocument.form_data_inizio.shift.value;
		var cod_trainer = frame_elenco.contentDocument.form_data_inizio.cod_trainer.value;
		var cod_cliente = frame_elenco.contentDocument.form_data_inizio.cod_cliente.value;
		var check_bold = frame_elenco.contentDocument.form_data_inizio.check_bold.value;
		var tipo_ricerca = frame_elenco.contentDocument.form_data_inizio.tipo_ricerca.value;
		var cod_livello = frame_elenco.contentDocument.form_data_inizio.cod_livello.value;
		var cod_provincia = frame_elenco.contentDocument.form_data_inizio.cod_provincia.value;
		var find_cognome = frame_elenco.contentDocument.form_data_inizio.find_cognome.value;
		var ora_inizio_appuntamento = frame_elenco.contentDocument.form_data_inizio.ora_inizio_appuntamento.value;
		var ora_fine_appuntamento = frame_elenco.contentDocument.form_data_inizio.ora_fine_appuntamento.value;
		var data_appuntamento = frame_elenco.contentDocument.form_data_inizio.data_appuntamento.value;
		
		frame_elenco.src = 'elenco_trainer_appuntamento.php?data_inizio_settimana='+data_inizio_settimana+'&shift='+shift+'&cod_cliente='+cod_cliente+'&cod_trainer='+cod_trainer+'&check_bold='+check_bold+'&tipo_ricerca='+tipo_ricerca+'&cod_livello='+cod_livello+'&cod_provincia='+cod_provincia+'&find_cognome='+find_cognome+'&ora_inizio_appuntamento='+ora_inizio_appuntamento+'&ora_fine_appuntamento='+ora_fine_appuntamento+'&data_appuntamento='+data_appuntamento;
	}
}	

function CheckValueInsertContratto(ilen)
{
	var bchoose = 0;
	
	for (i=0; i<ilen; i++) 
	{
		var strid = "acquista_abbonamento_" + i;
		
		var obj_check = document.getElementById(strid);
		
		if (obj_check.checked)
		{
			var ival = obj_check.value;
			
			var strid = "quantita_abbonamento_" + ival;
			
			var obj_input = document.getElementById(strid);
			
			if (obj_input.value.length == 0)
			{	
				alert("Inserire una quantità per il contratto scelto");
				obj_input.focus();
				return false;
			}
			
			bchoose = 1;
		}
	}
	
	if (bchoose == 0)
	{
		alert("Scegliere un tipo di contratto");
		return false;
	}
	
	return true;
}

function CheckValueModificaContratto(ilen)
{
	var bchoose = 0;
	
	for (i=0; i<ilen; i++) 
	{
		var strid = "modifica_abbonamento_" + i;
		
		var obj_check = document.getElementById(strid);
		
		if (obj_check.checked)
		{
			var ival = obj_check.value;
			
			var strid = "quantita_abbonamento_" + ival;
			
			var obj_input = document.getElementById(strid);
			
			if (obj_input.value.length == 0)
			{	
				alert("Inserire una quantità per il contratto scelto");
				obj_input.focus();
				return false;
			}
			
			bchoose = 1;
		}
	}
	
	if (bchoose == 0)
	{
		alert("Scegliere un tipo di contratto");
		return false;
	}
}


function checkQuantita(obj, val)
{
	if (obj.value == 0)
	{
		alert("Il numero di contratti acquistati deve essere maggiore di zero");
		obj.value = val;
		obj.focus();
		return false;		
	}
}










function CheckValueAcquistaAbbonamenti(ilen)
{
	//alert("in");
	
	var bchoose = 0;
	
	//alert(ilen);
	
	for (i=0; i<ilen; i++) 
	{
		var strid = "acquista_abbonamento_" + i;
		
		var obj_check = document.getElementById(strid);
		
		//alert(obj_check);
		
		if (obj_check.checked)
		{
			//var ival = obj_check.value;
			
			//var strid = "quantita_abbonamento_" + ival;
			var strid = "quantita_abbonamento_" + i;
			
			var obj_input = document.getElementById(strid);
			
			//alert(strid);
			
			if (obj_input.value.length == 0)
			{	
				alert("Inserire una quantità per il contratto scelto");
				obj_input.focus();
				return false;
			}
			
			bchoose = 1;
		}
	}
	
	if (bchoose == 0)
	{
		alert("Scegliere un tipo di contratto");
		return false;
	}
	
	document.insert_contratto.submit();	        
}

function ControllaDatiTrainer()
{
	nome		= document.info_trainer.nome.value;
	cognome		= document.info_trainer.cognome.value;
	email		= document.info_trainer.email.value;
	username	= document.info_trainer.username.value;
	password	= document.info_trainer.password.value;
	
	if (nome.length == 0)	
	{
		alert("Il nome è un campo obbligatorio");
		document.info_trainer.nome.focus();
		return false;
	}
	
	if (cognome.length == 0)	
	{	
		alert("Il cognome è un campo obbligatorio");
		document.info_trainer.cognome.focus();
		return false;
	}
	
	/*if (email.length == 0)	
	{
		alert("L\'indirizzo email è un campo obbligatorio");
		document.info_trainer.email.focus();
		return false;
	}*/
	if (email.length != 0)	
	{
		var err = verifica_email(email);
		
		if (err > "")
		{
			alert(err);
			
			document.info_trainer.email.focus();
			
			return false;
		}		
	}
	
	if (username.length == 0)	
	{
		alert("L\'username è un campo obbligatorio");
		document.info_trainer.username.focus();
		return false;
	}
	
	if (password.length == 0)	
	{
		alert("La password è un campo obbligatorio");
		document.info_trainer.password.focus();
		return false;
	}	
	
	document.info_trainer.submit();
}

function CheckModificaCliente()
{
	var nome       		= document.info_cliente.nome.value;    
	var cognome    		= document.info_cliente.cognome.value; 
	var email      		= document.info_cliente.email.value;   
	var username   		= document.info_cliente.username.value;
	var password   		= document.info_cliente.password.value;
	var ragione_sociale = document.info_cliente.password.value;

	if(ragione_sociale == ""){
		if (nome.length == 0)	
		{
			alert("Il nome è un campo obbligatorio");
			document.info_cliente.nome.focus();
			return false;
		}
	
		if (cognome.length == 0)	
		{
			alert("Il cognome è un campo obbligatorio");
			document.info_cliente.cognome.focus();
			return false;
		}	
	}
/*
	if (email.length == 0)	
	{
		alert("L\'indirizzo email è un campo obbligatorio");
		document.info_cliente.email.focus();
		return false;
	}*/
	if (email.length != 0)
	{
		var err = verifica_email(email);
		
		if (err > "")
		{
			alert(err);
			
			document.info_cliente.email.focus();
			return false;
		}		
	}
	
	if (username.length == 0)	
	{
		alert("L\'username è un campo obbligatorio");
		document.info_cliente.username.focus();
		return false;
	}

	if (password.length == 0)	
	{
		alert("La password è un campo obbligatorio");
		document.info_cliente.password.focus();
		return false;
	}		
	
	document.info_cliente.submit();
}
