
function addToFavorites(title) { 
	if (window.external) { 
		window.external.AddFavorite(location.href, title);
	} else { 
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function scaleImgs(whichId, maxW, maxH) {
	if (document.getElementById(whichId) != null) {
		var pix = document.getElementById(whichId).getElementsByTagName('img');
		for (i=0; i<pix.length; i++) {
			scale(pix[i], maxW, maxH);
		}
	}
}

function scale(foto, maxW, maxH) {
	w=foto.width;
	h=foto.height;
	if (w > maxW) {
		f=1-((w - maxW) / w);
		foto.width=w * f;
		foto.height=h * f;
		if (foto.height > maxH) {
			f=1-((h - maxH) / h);
			foto.width=w * f;
			foto.height=h * f;
		}
	} else if (h > maxH) {
		f = 1-((h - maxH) / h);
		foto.width=w * f;
		foto.height=h * f;
		if (foto.width > maxW) {
			f=1-((w - maxW) / w);
			foto.width=w * f;
			foto.height=h * f;
		}
	}
}

 /**
  * ACTION
  */
function doInfoAction(form,forward) {
	form.elements["forward"].value=forward;
	form.submit();
}
/** Filtra per agenzia */ 
function filterAgenzia(form, idAgenzia) {
	form.elements["idAgenzia"].value  = idAgenzia;
	form.submit();
}
/** richiama la home page */
function doHomeAction(form,operazione) {
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue la ricerca dettalio
function doImmobileDetail (idImmobile, operazione, form) {
	form.elements['idImmobile'].value=idImmobile;
	form.elements['operazione'].value=operazione;
	form.submit();
}

function switchBackground(divID, stato) {
	if (stato == 'on') {
		document.getElementById(divID).style.background = 'transparent url(/common/images/servizi/btn_orange_over.gif) center center no-repeat';
	} else {
		document.getElementById(divID).style.background = 'transparent url(/common/images/servizi/btn_orange.gif) center center no-repeat';
	}
}
function switchBackground2(divID, stato) {
	if (stato == 'on') {
		document.getElementById(divID).style.background = 'transparent url(/common/images/servizi/btn_orange_over2.gif) center center no-repeat';
	} else {
		document.getElementById(divID).style.background = 'transparent url(/common/images/servizi/btn_orange2.gif) center center no-repeat';
	}
}


function showText(idOn, count) {
	for (var i=0; i<=count; i++) {
		document.getElementById("testo" + i).style.display = (i == idOn) ? "block" : "none";
	}
}

function doNewsLetter(form,operazione) {
	if (form.consenso.checked) {
		form.elements['operazione'].value=operazione;
		form.submit();
	} else {
		alert("Per iscriverti alla newsletter devi acconsentire alle condizioni della privacy.");
	}
}

//esegue la ricerca dettalio agenzia
function doAgenziaDetail (idAgenzia, operazione, form) {
	form.elements['idAgenzia'].value = idAgenzia;
	form.elements['operazione'].value = operazione;
	form.submit();
}
//esegue la action immobili
function doImmobileAction(form, operazione) {
	form.elements["operazione"].value = operazione;
	form.submit();
}
//esegue pagina successiva
function doNextPage(form, operazione) {
	form.elements["numeroPag"].value = (eval(form.elements["numeroPag"].value) + 1);
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue pagina precedente
function doPreviousPage(form, operazione) {
	form.elements["numeroPag"].value = (eval(form.elements["numeroPag"].value) -1);
	form.elements["operazione"].value=operazione;
	form.submit();
}
//va alla pagina indicata
function doGotoPage(form, operazione) {
	var totalpage = (eval(document.getElementById("totalpage").value));
	var gotopage = (eval(document.getElementById("gotopage").value));

	if (gotopage > totalpage) {
		alert("La pagina che si vuole raggiungere non esiste");
		return;
	}
	form.elements["numeroPag"].value = eval(gotopage - 1);
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue la action immobili con paginazione
function doImmobileAction(form, operazione, numeroPag) {
	form.elements["operazione"].value = operazione;
	form.elements["numeroPag"].value = numeroPag;
	form.submit();
}
//esegue il controllo sui parametri di ricerca dell'immobile
function doFilterImmobileAction(form, operazione, numeroPag) {

	doImmobileAction(form, operazione, numeroPag);

}
//esegue la action agenzie
function doAgenziaAction(form, operazione, numeroPag) {
	form.elements["operazione"].value=operazione;
	form.elements["numeroPag"].value = numeroPag;
	form.submit();
}
//esegue il controllo sui parametri di ricerca dell'immobile
function doFilterAgenziaAction(form, operazione, numeroPag) {
	try {
		if (form.elements["idProvincia"].value == '') {
			alert('E\' obbligatorio specificare almeno una provincia!');
		} else {
			doAgenziaAction(form, operazione, numeroPag);
		}
	} catch(e) {
			alert('E\' obbligatorio specificare almeno una provincia!');
	}
}
/**esegue la action agenzie */
function doAgenziaActionOrdered(form, operazione, orderby, ordertype) {
	form.elements["orderType"].value=ordertype;
	form.elements["orderBy"].value=orderby;
	form.elements["operazione"].value=operazione;

	form.submit();

}
/**esegue la action agenzie */
function doImmobiliActionOrdered(form, operazione, orderby, ordertype) {
	form.elements["orderType"].value=ordertype;
	form.elements["orderBy"].value=orderby;
	form.elements["operazione"].value=operazione;

	form.submit();

}
//esegue la action login
function doLoginAction(form,operazione) {
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue la action login
function doServiziAction(form,operazione) {
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue la action login
function doMailAction(form,operazione) {
	form.elements["operazione"].value=operazione;
	form.submit();
}
//esegue il filtro sul form della mail
function doFilterMailAction(form, operazione) {
	var errcount = 0;
	if (form.elements["fromName"].value == '') {
		errcount++;
	}
	if (form.elements["fromCognome"].value == '') {
		errcount++;
	}
	if (form.elements["telefono"].value == '') {
		errcount++;
	}
	if (form.elements["from"].value == '') {
		errcount++;
	}
	if (form.elements["note"].value == '') {
		errcount++;
	}
	if (errcount > 0) {
		alert("Riempire tutti i campi!");
	} else {
		if (form.privacy[0].checked) {
			doMailAction(form,operazione);
		} else {
			alert("Per effettuare la richiesta deve dare il consenso per la privacy!");
		}
	}
}
// esegue il submit di PageAction
function doPageAction(form, page, section, tab) {
	form.elements["page"].value = page;
	form.elements["section"].value = section;
	form.elements["tab"].value = tab;
	form.submit();
}



/**
 * doArticleAction(document.pageFooter, 'azienda.chi.siamo.stampa', 'home', 'classic')
 */
function doArticleAction(form, num) {
	form.elements["page"].value = 'azienda.chi.siamo.stampa';
	form.elements["section"].value = 'home';
	form.elements["tab"].value = 'classic';
	form.elements["article"].value = num;
	form.submit();
}

// esegue il submit di HeaderAction
function doHeaderAction(page) {
	if (page == 'fast') {
		location.href = '/fast.do?func=ricerca&tab=fast';
	} else if (page == 'classic') {
		location.href = '/ricerca.do?ricerca=immobili&tab=classic';
	} else if (page == 'tv') {
		location.href = 'http://tv.realesse.com';
	} else if (page == 'tg') {
		location.href = 'http://tg.realesse.com';
	} else if (page == 'myrealesse') {
		location.href = '/page.do?tab=myrealesse&section=download&page=sw.download';
	}
}

//** **/

var ALLOWED_CHARS       = "(0-9),(a-z),(A-Z),( ()*+|!.,_-/:;)";
var GIORNI_SETTIMANA    = new Array("Lunedi'","Martedi'","Mercoledi'","Giovedi'","Venerdi'","Sabato","Domenica");
var contrattoCheckbox   = new Array();
var tipoCheckbox        = new Array();

/** restituisce un oggetto tramite id **/
function getOggetto(idOggetto){
	return document.getElementById(idOggetto);
}
/** apre finestra **/
function openWindow(address, width, height) {
    window.open(address,
                "window",
                "toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no",
                + ", width="+width
                + ", height="+height
                + ", screenX=20"
                + ", left=20"
                + ", screenY=50"
                + ", top=50")
}
/** valida checkbox */
function validateCheckbox(form) {
    var count = 0;
    for (var i=0; i<form.elements.length; i++) {
        var e = form.elements[i];
        if (e.name == 'sections' && !e.checked) {
            count++;
        }
    }
    if (count == 5) {
        for (var i=0; i<form.elements.length; i++) {
            var e = form.elements[i];
            if (e.name == 'sections' && !e.checked) {
                e.checked = !e.checked;
            }
        }
    }
    if (form.keywords.value == '') {
        if(confirm("Non hai digitato nessuna chiave di ricerca: in questo modo effettuerai una ricerca per tutti i valori possibili.\nSei sicuro di voler continuare?")) {
            form.submit();
        }
    } else {
       form.submit();
    }
}
/** visualizza div */
function dynListSwapper(id, fieldToClear, divToHide, divToShow) {
    if (id == -2) {
        fieldToClear.value='';
        hideDiv(divToHide);
        showDiv(divToShow);
    }
}
/** clean div */
function cleanup(newField, selectField, oldValue, listDiv, newDiv) {
    clear(newField);
    selectField.value = oldValue;
    showhide(listDiv, newDiv);
}
/** reindirizza a action */
function goTo(loc) {
  var hrf = "/";
  if (loc == 'home') {
    location.href = "/index.jsp";
  }
  else if (loc == 'notizie') {
    location.href = "/notizie/index.jsp";
  }
  else if (loc == 'immobili') {
    location.href = "/immobili.do";
  }
  else if (loc == 'secure') {
    location.href = "/secure/index.jsp";
  }
  else if (loc == 'statistiche') {
    location.href = "/statistiche.do";
  }
  else if (loc == 'utente') {
    location.href = "/utenti.do";
  }
}

/** setta un utente sul form e submit */
function setUser(form, newID, user_type) {
    form.agendaUserID.value = newID;
    form.user_type.value = user_type;
    form.submit();
}

/** elimina il valore in un campo */
function clear(field) {
  field.value = "";
}

/** mostra filtri */
function filterview(BlockName) {
    if (document.getElementById(BlockName).style.display == "block") {
        document.getElementById(BlockName).style.display = "none";
        document.getElementById('filtertitle').innerHTML='Mostra Filtri';
    } else {
        document.getElementById(BlockName).style.display = "block";
        document.getElementById('filtertitle').innerHTML='Nasconda Filtri';
    }
}
/** visualizzazione div */
function showhide(toShow, toHide) {
    showHide(toShow);
    showHide(toHide);
}
function showHide(aDiv) {
    document.getElementById(aDiv).style.display = (document.getElementById(aDiv).style.display == "block" ? "none" : "block");
}
function showHideDiv(aDiv) {
	showHide(aDiv)
}
function showHideNoBlock(aDiv) {
    var elementsList = document.getElementsByName(aDiv);
    for (var i=0; i<elementsList.length; i++){
        var element = elementsList[i];
        element.style.display = (element.style.display == 'none' ? 'block' : 'none');
    }
}
function showDiv(aDiv) {
    document.getElementById(aDiv).style.display = 'block';
}

function secureShowDiv(aDiv) {
	if (document.getElementById(aDiv) != null) {
		document.getElementById(aDiv).style.display = 'block';
	}
}

function hideDiv(aDiv) {
    document.getElementById(aDiv).style.display = 'none';
}
function hide(aDiv) {
    document.getElementById(aDiv).style.display = 'none';
}
/** ricerca caratteri speciali */
function doSpecialCharCheck(field) {
    if (hasStrangeChars(field) > 0) {
        alert("ATTENZIONE!\n\nIl campo contiene caratteri vietati\n\nSono consentiti:\n"+ALLOWED_CHARS+"\ne i caratteri accentati.");
    }
}
/** schede immobili */
function apreScheda(rif) {
    location.href = "/immobili.do?db_action=carica&rif="+rif;
}
function apreSchedaImmobileNewWindow(rif) {
    winopen("/immobili.do?db_action=carica&rif="+rif,550,400,"yes","yes");
}
function apreRichiesta(id) {
    location.href = "/richieste.do?db_action=carica&id="+id;
}
function apreSchedaRichiestaNewWindow(id) {
    winopen("/richieste.do?db_action=carica&id="+id,550,400,"yes","yes");
}
function mostraScheda(form, rif) {
    form.rif.value = rif;
    form.submit();
}
function showScheda(form, rif) {
    form.db_action.value = "carica";
    form.rif.value = rif;
    form.submit();
}

/** controllo valori  */
function isBlank(val){
    if(val==null) {
        return true;
    }
    for(var i=0;i<val.length;i++) {
        if ((val.charAt(i)!=' ')  && (val.charAt(i)!="\t") &&
            (val.charAt(i)!="\n") && (val.charAt(i)!="\r")) {
                return false;
            }
        }
    return true;
}

function allowOnlyNumbers(obj) {
    obj.value = numericOnly(obj.value);
}

function isAnyBlank(form, obj) { 
    for (var i=0; i<form.elements.length; i++) { 
        var e = form.elements[i];
        if ((e.name == obj.name) && (e.type=='text')) { 
            if (isBlank(e.value)) {
                return true;
            }
        } 
    }
    return false;
} 


function doFullSearch(form) {
    form.db_action.value='full_search';
}


/********************************************************** DATE CHECKER **/
function isDateOk(dateField, dateValue) {
    var isOk = false;

    if ((dateValue).length != 0) { 
        if (dateValue.indexOf('-') != -1) {
            dateField.value = dateValue.replace(/-/gi, '/');
        }
        isOk = CheckBothFormat(dateField, dateField.value);
        isOk = CheckDayFormat(dateField, dateField.value);
        isOk = CheckMonthFormat(dateField, dateField.value);
        isOk = CheckFormat(dateField, dateField.value);
    }
    return isOk;
}

function CheckBothFormat (dateField, dateValue) {
    if (dateValue.charAt(1)=="/" || dateValue.charAt(1)=="-") {
        dateField.value = "0" + dateValue.substring(0,1) + "/0" + dateValue.substring(2,9);
    }
    return true;
}

function CheckDayFormat(dateField, dateValue) {
    if (dateValue.charAt(1)=="/" || dateValue.charAt(1)=="-") {
        dateField.value = "0" + dateValue;
    }
    return true;
}

function CheckMonthFormat(dateField, dateValue) {
    if (dateValue.charAt(4)=="/" || dateValue.charAt(4)=="-") {
        dateField.value = dateValue.substring(0,2) + "/0" + dateValue.substring(3,9);
    }
    return true;
}

function CheckFormat(dateField, dateValue) {
    var bError = false;
    var aChar = null;
    var holder = null;  
    var Short =0;
    var FebCheck = null;
    var NovCheck = 0;
    var MonthCheck = null;
    var Reference = dateField.value;

        for (i = 0; i < 10; i++)
        {
            aChar = dateValue.charAt(i)
            if (i == 3 && aChar > 1) bError = true;
            if (i == 3 && aChar < "0") bError = true;
            if (i == 3 && aChar == 1) MonthCheck =1;
            if (i == 3 && aChar ==1) NovCheck=1;
            if (i == 4 && aChar < "0" || aChar > "9") bError = true;
            if (i == 4 && aChar == 2) FebCheck=1;
            if (i == 4 && MonthCheck == 1 && aChar > 2) bError = true;
            if (i == 4 && aChar == 4 || aChar ==6 || aChar ==9) Short=1;
            if (i == 4 && NovCheck == 1 && aChar == 1) Short=1;
            if (i == 2 && aChar != '-' && aChar != '/')  bError = true;
            if (FebCheck == 1 && NovCheck != 1) {
                if (i==3 && aChar > 2) bError = true;
            } 
            if (i == 0 && aChar > 3) bError = true;        
            if (i == 0 && aChar ==3) holder=1;
            if (i == 1 && aChar >0 && Short==1 && holder==1) bError = true;
            if (i == 1 && aChar >1 && holder==1) bError = true;         
            if (i == 1 && aChar < "0" || aChar > "9") bError = true;        
            if (i == 5 && aChar != '-' && aChar != '/')  bError = true;
            if (i == 8 && aChar < "0" || aChar > "9") bError = true;
            if (i == 9 && aChar < "0" || aChar > "9") bError = true;            
        }
        
    if ((Reference.substring(0,5) =="29/02" || Reference.substring(0,5) =="29-02") && Reference.substring(6,10) %4 !=0) {
        return false;
    }
    
    if (bError) {
        return false;
    }

    return true;
}
/** controllo caratteri e valori */
function hasStrangeChars(field) {
    var string = " ()*+|!.,_-/:;1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ??????";
    
    var counter = 0;
    for (var i=0; i<field.value.length; i++) {
        if(string.indexOf(field.value.charAt(i))==-1) counter++;
    }
    if (counter > 0) {
        return 1;
    }
    else return 0;
}
function isNotValidNumeric(divID, field) {
    // Allow empty, there's the possibility in the call to exclude this later
    if (field.value == null || field.value == '') return 0;
    if (!isValidNumericValue(field.value)) {
        return 1;
    }
    return 0;
}
function isNotValidDate(divID, field) {
    // Allow empty, there's the possibility in the call to exclude this later
    if (field.value == null || field.value == '') return 0;
    if (!isDateOk(field, field.value)) {
        return 1;
    }
    return 0;
}
function isNotValidEmail(divID, field) {
    // Allow empty, there's the possibility in the call to exclude this later
    if (field.value == null || field.value == '') return 0;
    if (!isValidEmail(field)) {
        return 1;
    }
    return 0;
}

function doHighlighting(divID, val) {
    switch (val) {
        case 0: unHighlightField(divID); break;
        case 1: highlightField(divID); break;
        default: unHighlightField(divID);
    }
}
function highlightField(divID) {
    document.getElementById(divID).style.color = "#FF0000";
}
function unHighlightField(divID) {
    document.getElementById(divID).style.color = "#000000";
}



/** seleziona affitto */
function affittoSelector(inFieldVal, expVal, affectedField, formType) {
    if (inFieldVal == expVal) {
        showDiv('id_'+formType+'_'+affectedField.name);
    }
    else {
        affectedField.options[0].selected=true;
        hideDiv('id_'+formType+'_'+affectedField.name);
    }
}


/** visualizza immobile */
function mostraImmobile(riferimento) {
    if (riferimento != null) {
        location.href = "/immobili.do?db_action=carica&rif="+riferimento;
    }
    else {
        alert("Attenzione: Scheda non trovata.");
    }
}

/** conta caratteri di una text area */
function textareaCounter(messageId, counterId, maxChars) {
    var myTextArea=document.getElementById(messageId);
    var myCounter=document.getElementById(counterId);
    if (myTextArea.value.length > maxChars) myTextArea.value = myTextArea.value.substring(0, maxChars);
    else myCounter.value = maxChars - myTextArea.value.length;
}
function updateTotal(totalDiv,checkbox) {
//	alert("checkbox.name="+checkbox.name+"\ncheckbox.type="+checkbox.type);
    if (totalDiv!=null && checkbox.checked) {
        totalDiv.innerHTML = eval(totalDiv.innerHTML) + 1;
    }
    else {
        totalDiv.innerHTML = eval(totalDiv.innerHTML) - 1;
    }
}
/*################
### UTENTI ####
################*/
function submitUtenti(form,operazione,idSelezionato){
    form.operazione.value = operazione;
    if (idSelezionato != null) 
        form.idSelezionato.value = idSelezionato;
    form.submit(); 
}
function controllaCancellaUtente(form,operazione,idSelezionato) {
    var answer = confirm("ATTENZIONE!\n\Vuoi cancellare permanentamente l\'Utente dal sistema?");
    if (answer) {
        submitUtenti(form,operazione,idSelezionato);
    }
}
function aggiungiPermessoAltri(form,operazione,idComponente){
    form.idComponenteSelezionato.value = idComponente;
    submitUtenti(form,operazione);
}
function cancellaPermessoAltri(form,operazione,idComponente,idPermesso){
    form.idComponenteSelezionato.value = idComponente;
    form.idPermessoSelezionato.value = idPermesso;
    submitUtenti(form,operazione);
}
// Somma le differenze fine-inizio per mattina e pomeriggio 
// di tutti i giorni della settimana
// e restituisce il totale formattato in: HH:mm
// nel layer passato.
function calcolaTotaleTempo(form,layer) {
    var totaleMilliSecondi = 0;
    for (i=0; i<=6; i++){
        var iniMattina = getData(form.elements["iniMattina["+i+"]"].value);
        var finMattina = getData(form.elements["finMattina["+i+"]"].value);
        totaleMilliSecondi += finMattina-iniMattina;
        var iniPomeriggio = getData(form.elements["iniPomeriggio["+i+"]"].value);
        var finPomeriggio = getData(form.elements["finPomeriggio["+i+"]"].value);
        totaleMilliSecondi += finPomeriggio-iniPomeriggio;
    }
    layer.innerHTML = getTempo(totaleMilliSecondi);
}
// Accetta una stringa nel formato HH:mm
// e restituisce un oggetto Date corrispondente alla data odierna
// ma con le ore e i minuti estratti dalla stringa.
// I secondi sono impostati a 0.
function getData (tempo) {
    if (tempo.length == 0 || tempo.length > 5 || tempo.indexOf(':') != 2)
        return null;
    var ore = parseInt(tempo.substring(0,2),10);
    var min = parseInt(tempo.substring(3,5),10);
    if (isNaN(ore) || isNaN(min))
        return null;
    var data = new Date();
    data.setHours(ore);
    data.setMinutes(min);
    data.setSeconds(0);
    return data;
}
// Calcola le ore e i minuti corrispondenti ai millisecondi passati
// e restituisce una stringa nel formato HH:mm.
function getTempo (milliSecondi) {
    var negativo = false;
    if (milliSecondi < 0){
        negativo = true;
        milliSecondi = Math.abs(milliSecondi);
    }
    var secondi = Math.floor(milliSecondi / 1000);
    var ore     = Math.floor(secondi/3600);
    var minuti  = Math.floor((secondi-(ore*3600)) / 60);
    return (negativo?"-":"")+(ore<10?"0"+ore:ore)+":"+(minuti<10?"0"+minuti:minuti);
}

/*################
### Bug ####
################*/
function submitBug(form,operazione,id){
    if (operazione != null && operazione != '') {
        form.elements["operazione"].value = operazione;
    } 
    if (id != null) 
        form.id.value = id;
    form.submit(); 
}
function controllaCancellaBug(form,operazione,id) {
    if (id != null && id != '') {
        var answer = confirm("Attenzione: Vuoi cancellare permanentamente il bug?");
        if (answer) {
            submitBug(form,operazione,id);
        }
    }
}

/*################
###  INTERNET  #####
################*/
function submitInternet(form,operazione,nomeSezione){
    form.operazione.value = operazione;
    if (nomeSezione != null) 
        form.focus.value = nomeSezione;
    form.action             = '/internet.do';
    form.submit(); 
    form.target = '';
}

//******* Fuzione per aprire una finestra con le statistiche sui numeri *******

function mostraStatistichePortafoglio(form,operazione,tipocontratto,tipologiaimm,numeroVani){

	if ((tipocontratto != null)&& (tipocontratto != ''))
		form.tipocontratto.value=tipocontratto;
	else
		form.tipocontratto.value='';
	if ((tipologiaimm != null)&&(tipologiaimm != ''))
		form.tipologiaimm.value=tipologiaimm;
	else
		form.tipologiaimm.value='';
	if ((numeroVani != null)&& (numeroVani != ''))
		form.numerovani.value=numeroVani;
	else
		form.numerovani.value='';

	openThisWindow("finestraStatistiche", "", 550, 550, "yes", "yes");
	form.target = 'finestraStatistiche';
    submitPortafoglio(form,operazione);
    form.target='';
}
//**************************************************************************************
function mostraRichiesteStatistichePortafoglio(form,operazione,tipocontratto,tipologiaimm,numeroVani){

	if ((tipocontratto != null)&& (tipocontratto != ''))
		form.tipocontratto.value=tipocontratto;
	else
		form.tipocontratto.value='';
	if ((tipologiaimm != null)&&(tipologiaimm != ''))
		form.tipologiaimm.value=tipologiaimm;
	else
		form.tipologiaimm.value='';
	if ((numeroVani != null)&& (numeroVani != ''))
		form.numerovani.value=numeroVani;
	else
		form.numerovani.value='';

	openThisWindow("finestraRichieste", "", 710, 550, "yes", "yes");
	form.target = 'finestraRichieste';
    submitPortafoglio(form,operazione);
    form.target='';
}
function mostraDistribuzione(form) {
    if (form.page.value != '') {
        NewWindow(form.page.value, form.title.value, 400, 400, 'auto');
    }
    else {
        alert("Pagina non trovata.\n\nContattare \"aiuto.tecnico@cortimmobiliare.com\"");
    }
}
var win = null;
function NewWindow(mypage,myname,w,h,scroll) {
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
    win = window.open(mypage,myname,settings);
}

var the_count = 0;
var the_timeout;
function doTimedUpdate(newDate, spanID) {
    alert(newDate.value);
    document.getElementById(spanID).innerHTML = newDate.value;
    the_count += 2;
    the_timeout = setTimeout("doTimedUpdate("+newDate+", '"+spanID+"');", 2000);
}

function toggleCheckbox(cb) {
    cb.checked = !cb.checked;
    if (cb.value == 'cantieri') {
        showFotoCheck('cantieri');
    } else if (cb.value == 'immobili') {
        showFotoCheck('immobili');
    }
}

/**
 * Nome della sottoversione
 */
function subversion(c) {
	//(dott. M. F&#245;ttemberg)
	if (c == "1") {
		document.getElementById("subversion").innerHTML = "<p style='text-align: center; color: #CCCCCC'><small>REALESSE PORTALE V. 1.0.02 b  - 11/08/2006</small></p>";
	} else {
		document.getElementById("subversion").innerHTML = "";
	}
}

function showFotoCheck(cb) {
    if (cb == 'immobili' && document.ricerca_generica_form.cantieri.checked == false) {
        document.getElementById("foto").style.display = document.getElementById("foto").style.display == "block" ? "none" : "block";
    } else if (cb == 'cantieri' && document.ricerca_generica_form.immobili.checked == false) {
        document.getElementById("foto").style.display = document.getElementById("foto").style.display == "block" ? "none" : "block";
    }
}

/** apre un pop up per l'help*/
function openPopHelp() {
    var dir= "/ricerca/help.html";
    var popUpWin = window.open(dir,"popup","scrollbars=no, menubar=no,width=400, height=250, top=300, right=50, left=350");
}

noweokno=null;

/** apre un pop up */
function winopen(url, w, h, scroll, resize) {
    if(window.screen) {
      aw=screen.availwidth;
      ah=screen.availheight;
    }else{
      aw=640;
      ah=450;
    }if(noweokno==null || noweokno.closed){
     ustawienia=
     "left="+(aw-w)/2+","
     +"top="+(ah-h)/2+","
     +"screenX="+(aw-w)/2+","
     +"screenY="+(ah-h)/2+","
     +"width="+w+","
     +"height="+h+","
     +"toolbar=no,"
     +"location=no,"
     +"directories=no,"
     +"status=np,"
     +"menubar=no,"
     +"scrollbars="+scroll+","
     +"resizable="+resize
     noweokno=window.open(url,'nowe',ustawienia);
     noweokno.focus();
    }else{
     noweokno.close();
      ustawienia=
     "left="+(aw-w)/2+","
     +"top="+(ah-h)/2+","
     +"screenX="+(aw-w)/2+","
     +"screenY="+(ah-h)/2+","
     +"width="+w+","
     +"height="+h+","
     +"toolbar=no,"
     +"location=no,"
     +"directories=no,"
     +"status=np,"
     +"menubar=no,"
     +"scrollbars="+scroll+","
     +"resizable="+resize
     noweokno=window.open(url,'nowe',ustawienia);
     noweokno.focus();
    }
}
/** apre la finestra in un pop up */
function openThisWindow(nomeFinestra, url, w, h, scroll, resize) {
    if(window.screen) {
      aw=screen.availwidth;
      ah=screen.availheight;
    }
    else{
      aw=640;
      ah=450;
    }
    ustawienia =
     "left="+(aw-w)/2+","
     +"top="+(ah-h)/2+","
     +"screenX="+(aw-w)/2+","
     +"screenY="+(ah-h)/2+","
     +"width="+w+","
     +"height="+h+","
     +"toolbar=no,"
     +"location=no,"
     +"directories=no,"
     +"status=np,"
     +"menubar=no,"
     +"scrollbars="+scroll+","
     +"resizable="+resize
    finestra = window.open(url,nomeFinestra,ustawienia);
    finestra.focus();
    
    return finestra;
}


/** ricarica un frame */
function refreshFrame(frameId,url){
    window.frames[frameId].location = url;
}
function loadFrame(frameId, url) {
  if (window.frames[frameId]) {
    window.frames[frameId].location = url;
    return false;
  }
  return true; // other browsers follow link
}


/**aggiungi ai preferiti*/
  function Preferiti(descrizione) {
     window.external.AddFavorite(location.href, descrizione);
  }
  
/** titolo pcreport **/
function changeImgSrc(idImg) {
	img = document.getElementById(idImg);
	img.src = img.src.substr(0, img.src.indexOf("_")) + "_" + (img.src.indexOf("up") != -1 ? "dw" : "up") + ".gif";
//	img.src = "/common/images/buttons/freccia_" + (img.src.indexOf("up") != -1 ? "dw" : "up") + ".gif";
}


function loadImage(fileName)
{

  var img = new Image(); /* NEW IMAGE OBJECT */

  img.src = fileName;
  document.preview.src = img.src; /* SETS THE THUMBNAIL */

}

