function changefoto(elem,foto) {
	elem.style.backgroundColor = "#FAFDFE";
//	elem.children.tags('A')[0].style.color = "#FF0000";
	elem.style.cursor = 'hand'
	
	MM_swapImage('ImageHome','',foto,1)
}



function over2(elem,foto) {
//	elem.style.backgroundColor = "#FAFDFE";
//	elem.children.tags('A')[0].style.color = "#FF0000";
	elem.style.cursor = 'hand'
	
//	MM_swapImage('ImageHome','',foto,1)
}

function up2(elem,foto) {
//	elem.style.backgroundColor = "#FAFDFE";
//	elem.children.tags('A')[0].style.color = "#FF0000";
	elem.style.cursor = 'hand'	
	MM_swapImage('ImageHome','',foto,1)
}

function out2(elem,foto) {
	elem.style.backgroundColor = "";
//	elem.children.tags('A')[0].style.color = "#FFFFC0";
	MM_swapImage('ImageHome','',foto,1)
}


function over(elem) {
	elem.style.backgroundColor = "#FAFDFE";
//	elem.children.tags('A')[0].style.color = "#FF0000";
	elem.style.cursor = 'hand'
}

function out(elem) {
	elem.style.backgroundColor = "";
//	elem.children.tags('A')[0].style.color = "#FFFFC0";
}

function go(path) {
	top.self.location.href = path;
}

function go2(path) {
	blank.self.location.href = path;
}



var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.focus();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


var popUpWin2=0;
function popUpWindow2(URLStr, left, top, width, height)
{
  if(popUpWin2)
  {
    if(!popUpWin2.closed) popUpWin2.focus();
  }
  popUpWin2 = open(URLStr, 'popUpWin2', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function check_form() {

  var error = 0;
  var error_message = "ATTENZIONE! ";
  var mnome = document.account_edit2.mnome.value;
  var memail = document.account_edit2.memail.value;
  var mtel = document.account_edit2.mtel.value;

  if (mnome == "") {

    error_message = error_message + " Inserire il tuo nome.  ";

    error = 1;

  }

  if (memail == "") {

    error_message = error_message + " Inserire il tuo e-mail.  ";

    error = 1;

  }

if (mtel == "") {
    error_message = error_message + " Inserire il tuo n di telefono.  ";

    error = 1;

  }


  if (error == 1) {

    alert(error_message);

    return false;

  } else {

    return true;

  }

}



// #################################################################################################
// ########################################### CONTROLLI FORM ######################################
// #################################################################################################

// VERIFICA EMAIL
function isEmail(what)
{
   var i=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
   if(!i.test(what.value)) { alert("Il campo EMAIL non č valido."); what.focus(); return false}   
   return true;
}


//FORM DI LOGIN
function controllaformLogin(theForm)
{
if (theForm.UserID.value == "")
	{
		alert("Inserire un valore per il campo \"username\".");
		theForm.UserID.focus();
		return (false);
	}
if (theForm.Password.value == "")
	{
		alert("Inserire un valore per il campo \"password\".");
		theForm.Password.focus();
		return (false);
	}

	return (true);
}

//RICERCA PER CODICE
function controllaformTC(theForm)
{
if (theForm.id_immobile.value == "")
	{
		alert("Inserire il codice dell'annuncio da cercare!");
		theForm.id_immobile.focus();
		return (false);
	}
	return (true);
}


function controllaFormRichiestaInfo(theForm)
{
if (theForm.nominativo.value == "")
	{
		alert("Inserire un valore per il campo \"NOME\".");
		theForm.nominativo.focus();
		return (false);
	}
if (theForm.mail.value == "")
	{
		alert("Inserire un valore per il campo \"INDIRIZZO E-MAIL\".");
		theForm.mail.focus();
		return (false);
	}
	
if(!isEmail(theForm.mail)) return false;
	
	
if (theForm.richiesta.value == "")
	{
		alert("Inserire un valore per il campo \"RICHIESTA\".");
		theForm.richiesta.focus();
		return (false);
	}	

	return (true);
}




//FORM REGISTRAZIONE
function controllaformRegistrazione(theForm)
{
if (theForm.mail.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.mail.focus();
		return (false);
	}	
if (theForm.telefono.value == "")
	{
		alert("Inserire un valore per il campo \"Nr. di Telefono\".");
		theForm.telefono.focus();
		return (false);
	}	
	
/*if (theForm.password.value == "")
	{
		alert("Inserire un valore per il campo \"Password\".");
		theForm.password.focus();
		return (false);
	}
*/	
	return (true);
}
//########################################################################################

//FORM REGISTRAZIONE
function controllaFormPromo(theForm)
{
if (theForm.nome.value == "")
	{
		alert("Inserire un valore per il campo \"Nome Agenzia\".");
		theForm.nome.focus();
		return (false);
	}
if (theForm.ragione.value == "")
	{
		alert("Inserire un valore per il campo \"Ragione Sociale\".");
		theForm.ragione.focus();
		return (false);
	}		
if (theForm.piva.value == "")
	{
		alert("Inserire un valore per il campo \"Partita IVA\".");
		theForm.piva.focus();
		return (false);
	}
if (theForm.titolare.value == "")
	{
		alert("Inserire un valore per il campo \"Titolare/referente\".");
		theForm.titolare.focus();
		return (false);
	}
if (theForm.indirizzo.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo\".");
		theForm.indirizzo.focus();
		return (false);
	}		
if (theForm.cap.value == "")
	{
		alert("Inserire un valore per il campo \"CAP\".");
		theForm.cap.focus();
		return (false);
	}
if (theForm.comune.value == "")
	{
		alert("Inserire un valore per il campo \"Comune\".");
		theForm.comune.focus();
		return (false);
	}			
if (theForm.provincia.value == "")
	{
		alert("Inserire un valore per il campo \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}	
if (theForm.regione.value == "")
	{
		alert("Inserire un valore per il campo \"Regione\".");
		theForm.regione.focus();
		return (false);
	}	
if (theForm.mail.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.mail.focus();
		return (false);
	}	
if(!isEmail(theForm.mail)) return false;	
if (theForm.tel.value == "")
	{
		alert("Inserire un valore per il campo \"Nr. di Telefono\".");
		theForm.tel.focus();
		return (false);
	}	
	
	return (true);
}
//########################################################################################


//FORM IMMOBILE //########################################################################################
function controllaformImmobili(theForm)
{
if (theForm.id_agenzia.value == "")
	{
		alert("Inserire un valore per il campo \"Nome Agenzia\".");
		theForm.id_agenzia.focus();
		return (false);
	}
if (theForm.nazione.value == "IT"){
		if (theForm.provincia.value == ""){
				alert("Inserire un valore per il campo \"Provincia\".");
				theForm.provincia.focus();
				return (false);
			}	
		}else{
		theForm.provincia.value = ""
}		
if (theForm.comune.value == "" || theForm.comune.value == "undefined")
	{
		alert("Inserire un valore per il campo \"Comune\".");
		theForm.comune.focus();
		return (false);
	}	
if (theForm.descrizione.value == "")
	{
		alert("Inserire un valore per il campo \"Descrizione\".");
		theForm.descrizione.focus();
		return (false);
	}
	return (true);
}
//########################################################################################


//FORM REGISTRAZIONE UTENTE ########################################################################################
function controllaformRegistrazioneUtente(theForm)
{
if (theForm.nome.value == "")
	{
		alert("Inserire un valore per il campo \"Nome\".");
		theForm.nome.focus();
		return (false);
	}
if (theForm.cognome.value == "")
	{
		alert("Inserire un valore per il campo \"Cognome\".");
		theForm.cognome.focus();
		return (false);
	}
if (theForm.citta.value == "")
	{
		alert("Inserire un valore per il campo \"Cittā\".");
		theForm.citta.focus();
		return (false);
	}	
if (theForm.cap.value == "")
	{
		alert("Inserire un valore per il campo \"CAP\".");
		theForm.cap.focus();
		return (false);
	}	
if (theForm.provincia.value == "")
	{
		alert("Inserire un valore per il campo \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}	
if (theForm.email.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.email.focus();
		return (false);
	}	
if (theForm.conferma_mail.value == "")
	{
		alert("Inserire un valore per il campo \"Conferma indirizzo e-mail\".");
		theForm.conferma_mail.focus();
		return (false);
	}	
if (eval(theForm.h_id_motivazione.value) == 0)
	{ 
		alert("Selezionare almeno una preferenza per \"Tipo Contratto\".");
		theForm.id_motivazione[0].focus();		
		return (false);
	}		
if (eval(theForm.h_id_tipologia.value) == 0)
	{
		alert("Inserire almeno una preferenza per \"Tipologia Immobile\".");
		theForm.id_tipologia[0].focus();				
		return (false);
	}		
if (eval(theForm.h_id_provincia.value) == 0)
	{
		alert("Inserire almeno una preferenza per \"Provincia Immobile\".");
		theForm.id_provincia[0].focus();				
		return (false);
	}		
if (eval(theForm.h_prezzo.value) == 0)
	{
		alert("Inserire almeno una preferenza per \"Fascia di prezzo\".");
		theForm.prezzo[0].focus();				
		return (false);
	}		
	return (true);
}
//########################################################################################

//Eliminazioe Immobile
function confermaEliminazioneImmobile(theForm)
{
	return confirm("Confermi l'eliminazione dell'immobile?");
	return (true);
}

//Eliminazioe Immagine
function confermaEliminazioneImmagine(theForm)
{
	return confirm("Confermi l'eliminazione dell'immagine?");
	return (true);
}

// #################################################################################################
// #################################################################################################


function check_green(controllo, hide, maxopt) {
	if (controllo.checked) {
	if ( eval(hide.value) >= maxopt ){alert("E' possibile selezionare un massimo di "+maxopt+" opzioni!"); return false;}	if ( eval(hide.value) >= maxopt ){alert("E' possibile selezionare un massimo di "+maxopt+" opzioni!"); return false;}
		hide.value = eval(hide.value) + 1;
		return controllo.className = 'Green';
	}	else {
			hide.value = eval(hide.value) - 1;
			return controllo.className = '';		
		}
	}

/*function getXMLHttp() {
var xmlhttp = null;
if (window.ActiveXObject) {
  if (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) {
  	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
  }
}
if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined') {
  xmlhttp = new XMLHttpRequest()
}
return xmlhttp
}
*/

function green(controllo, hide) {
	if (controllo.checked) {
		hide.value = eval(hide.value) + 1;
		return controllo.className = 'Green';
	}	else {
		hide.value = eval(hide.value) - 1;
		return controllo.className = '';		
	}
}

function getXMLHttp()
{
  var xmlhttp=false;
  // Utilizziamo la compilazione condizionale di JScript
  // per far fronte alle vecchie versioni di
  // Internet Explorer che non supportano i blocchi try/catch.
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // Prova la creazione dell'oggetto ActiveX XMLHTTP
  try
  {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
  }
  catch (e)
  {
    try
    {
      xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (E)
    {
      xmlhttp = false;
    }
  }
  @end @*/
  // Se il browser non č Internet Explorer viene creato
  // l'oggetto XMLHttpRequest (Netscape, Mozilla)
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}



//FORM CERCO IMMOBILE ########################################################################################
function controllaformCercoImmobile(theForm)
{

if (theForm.id_tipologia.value == "")
	{
		alert("Selezionare la tipologia dell'immobile cercato.");
		theForm.id_tipologia.focus();				
		return (false);
	}		

if (theForm.provincia.value == "")
	{
		alert("Selezionare una Provincia.");
		theForm.provincia.focus();
		return (false);
	}

if (! document.all.id_localita)
	{ 
		display(theForm.provincia.value);
		alert("Selezionare il Comune dell'immobile.");
		theForm.id_localita.focus();		
		return (false);
	}		


if (theForm.id_localita.value == "")
	{ 
		alert("Selezionare il Comune dell'immobile cercato.");
		theForm.id_localita.focus();
		return (false);
	}		
	

if (theForm.descrizione.value == "")
	{
		alert("Inserire il testo dell'annuncio.");
		theForm.descrizione.focus();				
		return (false);
	}		

if (theForm.prezzo.value == "")
	{
		alert("Inserire il prezzo massimo dell'immobile.");
		theForm.prezzo.focus();				
		return (false);
	}		

if (theForm.nome.value == "")
	{
		alert("Inserire un valore per il campo \"Nome\".");
		theForm.nome.focus();
		return (false);
	}

if (theForm.telefono.value == "")
	{
		alert("Inserire un valore per il campo \"Telefono\".");
		theForm.telefono.focus();
		return (false);
	}
if (theForm.email.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.email.focus();
		return (false);
	}	

if(!isEmail(theForm.email)) return false;
	
	return confirm("Confermi l'invio della richiesta?");	
	return (true);
}
//########################################################################################


//FORM OFFRO IMMOBILE ########################################################################################
function controllaformOffroImmobile(theForm)
{

if (theForm.id_tipologia.value == "")
	{
		alert("Selezionare la tipologia dell'immobile.");
		theForm.id_tipologia.focus();				
		return (false);
	}
	
if (theForm.regione.value == "")
	{ 
		alert("Selezionare la Regione dell'immobile.");
		theForm.regione.focus();
		return (false);
	}
	

if (theForm.provincia.value == "")
	{
		alert("Selezionare una Provincia.");
		theForm.provincia.focus();
		return (false);
	}


		


if (theForm.descrizione.value == "")
	{
		alert("Inserire il testo dell'annuncio.");
		theForm.descrizione.focus();				
		return (false);
	}		

if (theForm.prezzo.value == "")
	{
		alert("Inserire il prezzo dell'immobile.");
		theForm.prezzo.focus();				
		return (false);
	}		


if (theForm.nome.value == "")
	{
		alert("Inserire un valore per il campo \"Nome\".");
		theForm.nome.focus();
		return (false);
	}
if (theForm.telefono.value == "")
	{
		alert("Inserire un valore per il campo \"Telefono\".");
		theForm.telefono.focus();
		return (false);
	}
if (theForm.email.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.email.focus();
		return (false);
	}	
	
if(!isEmail(theForm.email)) return false;

	return confirm("Confermi l'invio della richiesta?");	
	return (true);
}


//FORM REGISTRAZIONE Portali Immobiliarei (pag registrazione_agenzie_PI.asp)
function controllaFormRicercaImm(theForm)
{
if (theForm.regione.value == "Italia")
	{
		alert("Seleziona \"Regione\".");
		theForm.regione.focus();
		return (false);
	}
if (theForm.provincia.value == "*")
	{
		alert("Seleziona \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}				
	
	//return confirm("Confermi l'invio dei dati?");
	return (true);
}

//FORM CERCO IMMOBILE ########################################################################################
function controllaformSchedaImmobile(theForm)
{
if (theForm.riferimento.value == "")
	{
		alert("Inserisci il riferimento.");
		theForm.riferimento.focus();
		return (false);
	}

if (theForm.regione.value == "")
	{
		alert("Selezionare una Regione.");
		theForm.regione.focus();
		return (false);
	}
	
if (theForm.provincia.value == "")
	{
		alert("Selezionare una Provincia.");
		theForm.provincia.focus();
		return (false);
	}	

if (theForm.comune.value == "")
	{
		alert("Selezionare un comune.");
		theForm.comune.focus();
		return (false);
	}	

if (theForm.id_categoria.value == "")
	{
		alert("Seleziona una \"Categoria Immobile\".");
		theForm.id_categoria.focus();
		return (false);
	}		

if (theForm.id_tipologia.value == "")
	{
		alert("Inserire almeno una preferenza per \"Tipologia Immobile\".");
		theForm.id_tipologia.focus();
		return (false);
	}

}
//########################################################################################



//########################################################################################

//FORM REGISTRAZIONE Portali Immobiliarei (pag registrazione_agenzia.php)
function controllaFormRegistrazioneAgenzia(theForm)
{
if (theForm.agency_firstname.value == "")
	{
		alert("Inserire un valore per il campo \"Nome Agenzia\".");
		theForm.agency_firstname.focus();
		return (false);
	}
if (theForm.agency_ragsoc.value == "")
	{
		alert("Inserire un valore per il campo \"Ragione Sociale\".");
		theForm.agency_ragsoc.focus();
		return (false);
	}		
if (theForm.agency_iva.value == "")
	{
		alert("Inserire un valore per il campo \"Partita IVA\".");
		theForm.agency_iva.focus();
		return (false);
	}
if (theForm.agency_reference.value == "")
	{
		alert("Inserire un valore per il campo \"Titolare/referente\".");
		theForm.agency_reference.focus();
		return (false);
	}
if (theForm.agency_street_address.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo\".");
		theForm.agency_street_address.focus();
		return (false);
	}		
if (theForm.agency_postcode.value == "")
	{
		alert("Inserire un valore per il campo \"CAP\".");
		theForm.agency_postcode.focus();
		return (false);
	}
			

if (theForm.regione.value == "")
	{
		alert("Inserire un valore per il campo \"Regione\".");
		theForm.regione.focus();
		return (false);
	}
	
if (theForm.provincia.value == "")
	{
		alert("Inserire un valore per il campo \"Provincia\".");
		theForm.provincia.focus();
		return (false);
	}
	
if (theForm.comune.value == "")
	{
		alert("Inserire un valore per il campo \"Comune\".");
		theForm.comune.focus();
		return (false);
	}	
	
if (theForm.agency_telephone.value == "")
	{
		alert("Inserire un valore per il campo \"Nr. di Telefono\".");
		theForm.agency_telephone.focus();
		return (false);
	}	

if (theForm.agency_email_address.value == "")
	{
		alert("Inserire un valore per il campo \"Indirizzo e-mail\".");
		theForm.agency_email_address.focus();
		return (false);
	}	
if(!isEmail(theForm.agency_email_address)) return false;
	

if (theForm.agency_password.value == "")
	{
		alert("Inserire un valore per il campo \"Password\".");
		theForm.agency_password.focus();
		return (false);
	}		
	
	return confirm("Confermi l'invio dei dati?");
	return (true);
}
//########################################################################################

