//input ins imm
function set_rif_imm() 
{ 
	document.getElementById('rif').select();	
}

//abilita link
function disabilita_link(param) 
{ 
	if(param == 0)	//conv
	{
		document.getElementById('link_lc').disabled = true;
		document.getElementById('link_lc').style.backgroundColor = '#cccccc';
	}
	else	//link
	{
		document.getElementById('link_lc').disabled = false;
		document.getElementById('link_lc').style.backgroundColor = '#ffffff';
	}
}

function controlla_input_file() 
{ 
	invio = true; 	
	var num_foto = document.getElementById('attuali').value;
	if(num_foto == 0)
	{alert('Attenzione!! Inserite un numero diverso di zero !!'); invio = false;document.getElementById('attuali').select();}
	if(num_foto > 10)
	{alert('Attenzione!! Avete inserito un numero maggiore di 10 foto !!'); invio = false;document.getElementById('attuali').select();}
	//
	return invio;
}
function controlla_input_file_agg() 
{ 
	invio = true; 	
	var num_Foto = document.getElementById('aggiungi').value;
	if(parseInt(num_Foto) > 10)
	{alert('Attenzione!! Avete un numero di foto maggiore di 10 !!'); invio = false;document.getElementById('aggiungi').select();}
	//
	return invio;
}

//abilita campi file
function abilita_file(id) 
{ 
	if(id==2){document.getElementById('foto2').disabled = false;}	
	if(id==3){document.getElementById('foto3').disabled = false;}
	if(id==4){document.getElementById('foto4').disabled = false;}
	if(id==5){document.getElementById('foto5').disabled = false;}
	if(id==6){document.getElementById('foto6').disabled = false;}
}

//stampa foto immobili originali
function apri_img_originale(idriga, param, b, h) 
{ 
	winName = window.open('stampa_foto_th.php?param='+param+'&id='+idriga+'', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
}
function apri_img_originale_conv(idriga, param, b, h) 
{ 
	winName = window.open('stampa_foto_th_conv.php?param='+param+'&id='+idriga+'', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
}
function apri_img_originale_evento(idriga, param, b, h) 
{ 
	winName = window.open('stampa_foto_th_eventi.php?param='+param+'&id='+idriga+'', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
}
function apri_img_originale_velivolo(idriga, param, b, h) 
{ 
	winName = window.open('stampa_foto_th_velivoli.php?param='+param+'&id='+idriga+'', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
}
function apri_img_originale_gall(idriga, param, b, h) 
{ 
	winName = window.open('stampa_foto_th_gallerie.php?param='+param+'&id='+idriga+'', '', 'scrollbars=0,status=0,width='+b+',height='+h+',left=0,top=0,resizable=0');
}
//finestra link
function apri_link(href, wName, dimWin) 
{ 
	winName = window.open(href, wName, dimWin);
}

//form email
function form_email(id_immobile) 
{ 
	winName = window.open('invio_info_immobile.php?idImm=' + id_immobile + '', "", "scrollbars=0,status=0,width=260,height=385,left=300,top=230,resizable=0");
}
function input_login() 
{ 
	document.getElementById('utente').focus();
}
//stampa scheda imm
function stampa_scheda(id_immobile) 
{ 
	winName = window.open('stampa_scheda.php?idImm=' + id_immobile + '', "", "scrollbars=0,status=0,width=850,height=610,left=0,top=0,resizable=0");
}

//colora pulsanti login
function colora_pulsante(param, pulsante) 
{ 
	if(pulsante == 0)
	{
		if(param == 0)
		{
			document.getElementById('reset').style.backgroundColor = '#ffffff';
		}
		else
		{
			document.getElementById('reset').style.backgroundColor = '#eaeaea';
		}
	}
	else
	{
		if(param == 0)
		{
			document.getElementById('submit').style.backgroundColor = '#ffffff';
		}
		else
		{
			document.getElementById('submit').style.backgroundColor = '#eaeaea';
		}
	}
}

//convalida campi frm 
function convalidaInput(convalida) 
{
	invio = true; 	
	//
	switch(convalida)
	{	
		//login
		case 0:	
			NU = document.getElementById('utente').value;
			PW = document.getElementById('pw').value;
			//
			if(NU == null || NU == '')
			{
				alert('Nome utente mancante!! Prego reinserirlo');
				invio = false; 
				document.getElementById('utente').select();
			}
			else if(PW == null || PW == '')
			{
				alert('Password mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('pw').select();
			}
		break;
		
		//link/conv
		case 1:	
			textarea_lc = trim(document.getElementById('textarea-lc').value);
			link_lc = trim(document.getElementById('link_lc').value);
			//
			if(textarea_lc == null || textarea_lc == '')
			{
				alert('Attenzione!! State inserendo un testo vuoto.');
				invio = false; 
				document.getElementById('textarea-lc').focus();
			}
			else if(link_lc == null || link_lc == '')
			{
				alert('Attenzione!! State inserendo un link vuoto.');
				invio = false; 
				document.getElementById('link_lc').focus();
			}
		break;
		
		//news
		case 2:	
			titolo = trim(document.getElementById('titolo').value);
			testo = trim(document.getElementById('textarea-n').value);
			//
			if(titolo == null || titolo == '')
			{
				alert('Attenzione!! State inserendo un titolo vuoto.');
				invio = false; 
				document.getElementById('titolo').focus();
			}
			else if(testo == null || testo == '')
			{
				alert('Attenzione!! State inserendo un testo vuoto.');
				invio = false; 
				document.getElementById('textarea-n').focus();
			}
		break;
		
		//ins galleria
		case 3:	
			titolo_gall = trim(document.getElementById('titolo_gall').value);
			foto_indice = trim(document.getElementById('foto_indice').value);
			//
			if(titolo_gall == null || titolo_gall == '')
			{
				alert('Titolo galleria mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('titolo_gall').focus();
			}
			else if(foto_indice == null || foto_indice == '')
			{
				alert('Foto indice galleria mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('foto_indice').focus();
			}
		break;
		
		//agg galleria
		case 4:	
			titolo_gall = trim(document.getElementById('titolo_gall').value);
			//
			if(titolo_gall == null || titolo_gall == '')
			{
				alert('Titolo galleria mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('titolo_gall').focus();
			}
		break;
		
		case 5:	
			titolo = trim(document.getElementById('titolo-v').value);
			foto = trim(document.getElementById('foto_news').value);
			//
			if(titolo == null || titolo == '')
			{
				alert('Testo velivolo mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('titolo-v').focus();
			}
			else if(foto == null || foto == '')
			{
				alert('Foto velivolo mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('foto_news').focus();
			}
		break;
		case 6:	
			titolo = trim(document.getElementById('titolo-v').value);
			//
			if(titolo == null || titolo == '')
			{
				alert('Testo velivolo mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('titolo-v').focus();
			}
		break;
		case 7:	
			testo = trim(document.getElementById('textarea-conv').value);
			foto = trim(document.getElementById('foto_conv').value);
			//
			if(testo == null || testo == '')
			{
				alert('Testo convenzione mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('textarea-conv').focus();
			}
			else if(foto == null || foto == '')
			{
				alert('Foto convenzione mancante!!Prego reinserirla');
				invio = false; 
				document.getElementById('foto_conv').focus();
			}
		break;
		case 8:	
			testo = trim(document.getElementById('textarea-conv').value);
			//
			if(testo == null || testo == '')
			{
				alert('Testo convenzione mancante!! Prego inserirlo');
				invio = false; 
				document.getElementById('textarea-conv').focus();
			}
		break;
	}
	return invio;
}
	
//trim per le stringhe
function trim(input)
{
	var valore = input.split(' ');
	var msg = ''; 
	for (i=0; i<valore.length; i++)
	{
		msg += valore[i]; 
	} 
	return msg;	
}

//verifica se un numero è decimale o no
function isInt(myNum) 
{ 
	var myMod = myNum % 1;
 	if(myMod == 0){return true;}else{return false;}
}

//estrae la parte intera
function estrae_intero(myNum) 
{ 
	var parte_dec = myNum % 1;          
	var parte_int = myNum - parte_dec;
	return parte_int + "";
}

