//  ###############################
//	==>>  DIV NASCOSTI
//  ###############################
function MostraLayer(nomelayer)
{
	document.getElementById(nomelayer).style.visibility = 'visible';
	document.getElementById(nomelayer).style.display = 'block';
}

function NascondiLayer(nomelayer)
{
	document.getElementById(nomelayer).style.visibility = 'hidden';
	document.getElementById(nomelayer).style.display = 'none';
}
function MostraRiga(nomeriga)
{
	document.getElementById(nomeriga).style.visibility = 'visible';
	document.getElementById(nomeriga).style.display = 'block';
}

function NascondiRiga(nomeriga)
{
	document.getElementById(nomeriga).style.visibility = 'hidden';
	document.getElementById(nomeriga).style.display = 'none';
}
function OpenPopupBO(id)
{
	var h = 220;
	var w = 450;
	var pw = Math.floor((screen.width-w)/2);
	var ph = Math.floor((screen.height-h)/2);
	window.open("bo_utility.asp?id=" + id, "popup", "width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
}

function Controlla(valore, obbligatorio)
{
	if (obbligatorio)
	{
		if ( (valore == "") || (valore.replace(/\s*/gi,'') == '') || (valore.replace(/\x13\x10*/gi,'') == '') )
			return false;
		else
			return true;
	}
	else
	{
		if ( (valore != "") && ( (valore.replace(/\s*/gi,'') == '') || (valore.replace(/\x13\x10*/gi,'') == '') ) )
			return false;
		else
			return true;
	}
}

function VerificaData(strData)
{
	var regex = new RegExp("[/-]");
	var data = strData.split(regex);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var result = true;
	
	if (data['1'] == "" || data['2'] == "" || data['3'] == "")
		result = false;
	
	if ( data['2']%4 == 0 && data['2']%100 > 0 || data['2']%400 == 0 )
		nbJours['2'] = 29;
	
	if( isNaN(data['2']) )
		result=false;
	
	if ( isNaN(data['1']) || data['1'] > 12 || data['1'] < 1 )
		result=false;
	
	if ( isNaN(data['0']) || data['0'] > nbJours[Math.round(data['1'])] || data['0'] < 1 )
		result=false;
	
	return result;
}

function ValidaAccesso(valore)
{
	if (!valore.match(/^[a-zA-Z0-9]{4,12}$/))
		return false;
	else
		return true;
}

function ValidaEmail(indirizzo)
{
   if (indirizzo.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
   else
		return false;
}

function CountDown(elemento, dimensione, id_elemento)
{
	var n = dimensione;
	var lunghezza = elemento.value.length;
	var myspan = document.getElementById(id_elemento);
	if (n-lunghezza < 0)
	{
		alert("Hai superato il limite di 250 caratteri");
		elemento.value = elemento.value.substr(0,n);
		return;
	}
	else myspan.innerHTML = n-lunghezza;
}

function ContaCaratteri(elemento, id_elemento)
{
	var lunghezza = elemento.value.length;
	var myspan = document.getElementById(id_elemento);
	myspan.innerHTML = lunghezza;
}

function ControllaFormContatti(f, lingua)

{
	var controlla;
	var msgErrore = '';

	switch (lingua)
	{
		case 'eng':
			var tit_msg_errore = "Errors found:\n\n";
			var msg_errore1 = ": is required and can\'t be empty.\n";
			var msg_errore2 = ": insert a valid e-mail address.\n";
			break;
		default:
			var tit_msg_errore = "Si sono verificati i seguenti errori:\n\n";
			var msg_errore1 = ": è obbligatorio e non può essere vuoto.\n";
			var msg_errore2 = ": inserire un indirizzo e-mail valido.\n";
	}

	for(var i=0 ; i < f.elements.length ; i++)
	{
		controlla = f.elements[i].name.substring(f.elements[i].name.indexOf("|")+1,f.elements[i].name.indexOf("|")+2);
		if (controlla != '0')
		{
			switch (controlla)
			{
				case '1':
					if (!Controlla(f.elements[i].value, true))
						msgErrore += "- " + FormattaAlert(f.elements[i].name.substring(0,f.elements[i].name.indexOf("|"))) + msg_errore1;
					break;
				case '2':
					if (!ValidaEmail(f.elements[i].value))
						msgErrore += "- " + FormattaAlert(f.elements[i].name.substring(0,f.elements[i].name.indexOf("|"))) + msg_errore2;
					break;
			}
		}
	}

	if (msgErrore != '')
	{
		alert(tit_msg_errore + msgErrore);
		return false;
	}
	else
	{
		return true;
	}
}

function FormattaAlert(nome)
{
	var testo = nome;
	testo = testo.replace("§"," ");
	testo = testo.replace("[a]","à");
	testo = testo.replace("[e]","è");
	testo = testo.replace("[i]","ì");
	testo = testo.replace("[o]","ò");
	testo = testo.replace("[u]","ù");
	testo = testo.replace("{a}","á")
	testo = testo.replace("{e}","é")
	testo = testo.replace("{i}","í")
	testo = testo.replace("{o}","ó")
	testo = testo.replace("{u}","ú")
	return testo;
}

function FiltroAnnunci(f)
{
	var errMsg = '';
	var parolachiave = f.filtro_parolachiave.value;
	var tipoimmobile = f.filtro_idtipoimmobile;
	var tipocontratto = f.filtro_idtipocontratto;
	var tipoannuncio = f.filtro_idtipoannuncio;
	
	titolo_errore = "Si sono verificati i seguenti errori:\n\n";
	errore1 = "- Inserire un quartiere/località/zona, o scegliere un tipo di\nimmobile, contratto o annuncio.\n";
	errore2 = "- Inserire un quartiere/località/zona di almeno 3 caratteri.\n";

	if (!Controlla(parolachiave, true))
	{
		if (tipoimmobile.options[tipoimmobile.selectedIndex].value == "" && tipocontratto.options[tipocontratto.selectedIndex].value == "" && tipoannuncio.options[tipoannuncio.selectedIndex].value == "")
			errMsg += errore1;
	}
	else
	{
		if (Controlla(parolachiave, true))
		{
			if (!parolachiave.match(/^.{3,}$/))
				errMsg += errore2;
		}
	}

	if (errMsg != '')
	{
		alert(titolo_errore+errMsg);
		return false;
	}
	else
		return true;
}