// stringhe localizzate per la lingua corrente
var langErrCampoVuoto = "Вы должны заполнить поле $1";
var langRicercaCitta = "Город";
var langrseb = "Возраст ребенка";
var langrsb = "Дети";
var langrsc = "Комната";
var langrsct = "Тип номера";
var langprivacy = "Вы должны принять условия обработки конфиденциальных персональных данных."
var langrscts = "Одноместный (1чел.)";
var langrsctd = "Двухместный (2чел.)";
var langrsctm = "Супружеский (2 чел.)";
var langrsctt = "Трёхместный (3 чел.)";
var langrsctq = "Четырёхместный (4чел.)";
var langrscta = "Апартамент (5+)"
var labelEmailNewsletter = "Email";
var langvisualizza = "&#1055;&#1086;&#1089;&#1084;&#1086;&#1090;&#1088;&#1080; &#1076;&#1077;&#1090;&#1072;&#1083;&#1080;";
var langchiudi = "&#1047;&#1072;&#1082;&#1088;&#1099;&#1074;&#1072;&#1081; &#1076;&#1077;&#1090;&#1072;&#1083;&#1080;";
var urlAjaxNewsletter = "http://www.offerhotel.com/lastminute/ru/newsletter/iscrivi";
var urlAppAjax = "/ru/app/ajax";
var constPagamentoCarta = "C";
var constPagamentoAcconto = "B";
var monthNames = new Array(    
"Январь",
"Февраль",
"Март",
"Апрель",
"Май",
"Июнь",
"Июль",
"Август",
"Сентябрь",
"Октябрь",
"Ноябрь",
"Декабрь");
var dayNames = new Array(
"пн",
"вт",
"ср",
"чт",
"пт",
"сб",
"вс");
// carica css
if (isIE6) loadFile("/lastminute/resources/ie6.css", "css");
else loadFile("/lastminute/resources/firefox.css", "css");
// funzioni globali
function addOpenSearchPlugin() {
    try { window.external.AddSearchProvider('http://www.offerhotel.com/ru/app/xml/opensearch'); }
    catch (e) { alert( "Cannot install search plugin. Your client might not be compatible." ); }
}
function requestHtml(u, f) {
    var r;
    if (window.XMLHttpRequest) {
        r = new XMLHttpRequest();
        if (r.overrideMimeType) r.overrideMimeType('text/xml');
    } else if (window.ActiveXObject) {
        try {
            r = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                r = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!r) return false;
    else {
        r.onreadystatechange = function() { if ((r.readyState == 4) && (r.status == 200)) f(r.responseText); };
        r.open('GET', u, true);
        r.send(null);
    }
}
function jsonRequest(u, f) { requestHtml(u, function(h) { var t = /^<result>(.*)<\/result>$/.exec(h); if (t) f(eval(t[1])); }); }
function createNamedElement(t, n) {
    var m = null;
    try { m = document.createElement('<'+t+' name="'+n+'">'); } catch (e) { }
    if (!m || m.nodeName != t.toUpperCase()) { m = document.createElement(t); m.name = n; }
    return m;
}
function submitAction(a) {
    document.forms[0]["action"].value = a;
    document.forms[0].submit();
}var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
var homeTabSelected = 1;
var blurImageIndex = 0;
var blurImageOpacity = 0;
var lastImg;
var lastZoom;
var lastSource;
var dateShortName = '';
var dateShortFunc = '';
var calendar = new Calendar();
var schedaHotelId = 0;
var schedaHotelNum = 0;
var layerMappaDefaultParams = "";
var blinkrsx = 0;
function onChangeHomeTab(i) {
    if (i != homeTabSelected) {
        var d = document.getElementById("homeTab" + homeTabSelected);
        d.className = "hti";
        d = document.getElementById("homeTab" + i);
        d.className = "hts";
        d = document.getElementById("homeTabContent" + homeTabSelected);
        d.style.display = "none";
        d = document.getElementById("homeTabContent" + i);
        d.style.display = "block";
        homeTabSelected = i;
    }
}
function dateDiff(dataa, datab) {
    return Math.round((dataa.getTime()-datab.getTime())/86400000);
}
function monthDiff(a, b) {
    return ((a.getFullYear() - b.getFullYear()) * 12 + a.getMonth()) - b.getMonth();
}
function getToday() {
    var d = new Date(); d.setHours(0); d.setMinutes(0); d.setSeconds(0); d.setMilliseconds(0); return d;
}
function getDateShortValue(name, frm) {
    if (!frm) frm = document.forms[0];
    var sm = frm['dateShort_m_' + name].value;
    var sd = frm['dateShort_d_' + name].value;
    if (sm != '' && sd != '') {
        var adesso = getToday();
        adesso.setDate(1);
        adesso.setMonth(adesso.getMonth() + parseInt(sm));
        adesso.setDate(parseInt(sd));
        return adesso;
    } else return null;
}
function setDateShortValue(n) {
    updateDateShortValue(n, getDateShortValue(n));
}
function clearDateShortValue(n) {
    var f = document.forms[0];
    f[n].value = '0000-00-00';
    f['dateShort_m_' + n].value = "";
    f['dateShort_d_' + n].value = "";
}
function updateDateShortValue(n, v, f) {
    if (!f) f = document.forms[0];
    var h = f[n];
    if (v) {
        var yd = v.getFullYear();
        var md = v.getMonth() + 1;
        var gd = v.getDate();
        var adesso = getToday();
        f['dateShort_m_' + n].value = monthDiff(v, adesso);
        f['dateShort_d_' + n].value = gd;
        if (md < 10) md = "0" + md;
        if (gd < 10) gd = "0" + gd;
        h.value = yd + '-' +  md + '-' + gd;
    }
    else h.value = "";
}
function onChangeDateShort(name, func) {
    setDateShortValue(name); if (arguments.length > 1) if (self[func] != null) eval(func + '()');
}
function fillDateShort(name, frm) {
    if (!frm) frm = document.forms[0];
    for (i = 1; i <= 31; i++) frm['dateShort_d_' + name].options[i] = new Option(i, i);
    var oggi = new Date();
    oggi.setDate(1);
    for (i = 0; i < 12; i++) {
        frm['dateShort_m_' + name].options[i + 1] = new Option(monthNames[oggi.getMonth()] + " " + oggi.getFullYear(), i);
        oggi.setMonth(oggi.getMonth() + 1);
    }
}
function toDateYmd(n) {
    var h = document.forms[0][n].value; return h.substr(0, 4) + h.substr(5, 2) + h.substr(8, 2);
}
function fromDateToYmd(v) {
    if (v) {
        var yd = v.getFullYear();
        var md = v.getMonth() + 1;
        if (md < 10) md = "0" + md;
        var gd = v.getDate();
        if (gd < 10) gd = "0" + gd;
        return yd + "" + md + "" + gd;
    } else return "";
}
function onChangeOra(n) {
    var a = document.getElementById(n); a.value = document.getElementById(n + "_ora").value + ":" + document.getElementById(n + "_min").value;
}
function Calendar() {
    this.selectedDate = new Date();
    this.minDate = getToday();
    this.highlightStart = null;
    this.highlightEnd = null;
    this.display = calendarDisplay;
    this.getHtmlElement = function() {
        return document.getElementById('calendar');
    }
    this.hide = function() {
        this.getHtmlElement().style.visibility = 'hidden';
    }
    this.isVisible = function() {
        return this.getHtmlElement().style.visibility == 'visible';
    };
    this.clickDay = calendarClickDay;
    this.clickDayCustom = null;
}
function calendarDisplay(y, m, pt) {
    var div = this.getHtmlElement();
    if (div) {
        var firstDay = new Date(y, m - 1, 1);
        var currMonth = firstDay.getMonth();
        var lastDay = new Date(firstDay.getFullYear(), firstDay.getMonth() + 1, 0);
        var html = "<div class='calendarTable'>";
        var jscalendar = ''; // parent.';
        html += "<div class='calendarRow'>";
        html += "<div class='calendarMonthPrev'><a class='azzurro12' href='javascript:" + jscalendar + "calendar.display(" + firstDay.getFullYear() + "," + firstDay.getMonth() + ");'><img src='/lastminute/images/calendar_prev.gif' /></a></div>";
        html += "<div class='azzurro10 calendarMonthName'>";
        html += monthNames[firstDay.getMonth()] + " " + firstDay.getFullYear();
        html += "</div>";
        html += "<div class='calendatMonthNext'><a class='azzurro12' href='javascript:" + jscalendar + "calendar.display(" + firstDay.getFullYear() + "," + (firstDay.getMonth() + 2) + ");'><img src='/lastminute/images/calendar_next.gif' /></a></div>";
        html += "<div class='calendarClose'><a href='javascript:" + jscalendar + "calendar.hide();'><img src='/lastminute/images/close.gif' /></a></div>";
        html += "</div>";
        html += "<div class='calendarRow'>";
        for (i=0; i<7; i++) html += "<div class='calendarWeekDayName'>" + dayNames[i] + "</div>";
        var w = firstDay.getDay();
        if (w != 1) firstDay.setDate(firstDay.getDate() - (w > 0 ? w - 1 : 6));
        w = lastDay.getDay();
        if (w != 0) lastDay.setDate(lastDay.getDate() + 7 - w);
        while (firstDay.getTime() <= lastDay.getTime()) {
            w = firstDay.getDay();
            if (w % 7 == 1) html += "</div><div class='calendarRow'>";
            var tdcss = '';
            var t = firstDay.getTime();
            if (this.minDate && (t < this.minDate.getTime())) tdcss = 'calendarDayOff';
            else if (this.highlightStart && this.highlightEnd && t >= this.highlightStart.getTime() && t < this.highlightEnd.getTime()) tdcss = 'calendarDaySelected';
            else if (this.highlightEnd && t == this.highlightEnd.getTime()) tdcss = 'calendarDayHighlight';
            else if (firstDay.getMonth() != currMonth) tdcss = 'calendarDayOther';
            else if (t == this.selectedDate.getTime()) tdcss = 'calendarDayOver';
            else tdcss = 'calendarDay';
            html += "<div class='" + tdcss +"'";
            if (tdcss != 'calendarDayOff') html += " onclick='" + jscalendar + "calendar.clickDay(" + firstDay.getFullYear() + "," + (firstDay.getMonth() + 1) + "," + firstDay.getDate() + ");' onmouseover='this.className=\"calendarDayOver\";' onmouseout='this.className=\"" + tdcss + "\";'";
            html += ">" + firstDay.getDate() + "</div>";
            firstDay.setDate(firstDay.getDate() + 1);
        }
        html += "</div>";
        div.innerHTML = html;
        if (pt) {
            div.style.left = pt.x + 'px';
            div.style.top = pt.y + 'px';
        }
        div.style.visibility = 'visible';
    }
}
function calendarClickDay(y, m, d) {
    this.hide();
    this.selectedDate = new Date(y, m - 1, d);
    if (this.clickDayCustom) this.clickDayCustom();
}
function clickDateShortCalendar(b, n, f) {
    if (dateShortName != n || !calendar.isVisible()) {
        var d = new Date();
        if (f) dateShortFunc = f;
        if (n) {
            dateShortName = n;
            var dsv = getDateShortValue(n);
            if (dsv && dsv.getFullYear() > 2000) d = dsv;
        }
        var pt = getAbsolutePosition(b);
        pt.y += b.offsetHeight + 2;
        calendar.clickDayCustom = onClickDayDateShort;
        calendar.selectedDate = d;
        calendar.display(d.getFullYear(), d.getMonth() + 1, pt);
    }
    else calendar.hide();
}
function onClickDayDateShort() {
    if (dateShortName != '') updateDateShortValue(dateShortName, calendar.selectedDate);
    if (dateShortFunc != '') eval(dateShortFunc + '()');
}
function isCampoVuoto(c) {
    return (c == null) || (c.value == "");
}
function isCampoNumero(c) {
    return !isCampoVuoto(c) && !isNaN(c.value);
}
function strFormat(s, p) {
    return s.replace("$1", p);
}
function controllaCampoVuoto(c, a) {
    if (isCampoVuoto(c)) {
        alert(strFormat(langErrCampoVuoto, a)); c.focus(); return false;
    } return true;
}
function controllaCampoNumero(c, a, o) {
    if (!o && isCampoVuoto(c)) return true; else {
        if (controllaCampoVuoto(c, a)) {
            if (!isNaN(c.value)) return true; else {
                alert("Il campo " + a + " contiene un numero non valido"); c.focus();
            }
        }
    } return false;
}
function controllaCampoEmail(c, a, o) {
    if (!o && isCampoVuoto(c)) return true;
    else {
        if (controllaCampoVuoto(c, a)) {
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(c.value)) return true;
            else {
                alert("Il campo " + a + " contiene un indirizzo email non valido"); c.focus();
            }
        }
    }
    return false;
}

function controllaCampoRadio(c, a) {
    for (i=0; i<c.length; i++) if (c[i].checked) return true;
    alert("Devi selezionare almeno un'opzione per il campo " + a);
    c[0].focus();
    return false;
}
function addbookmark() {
    if (window.sidebar) window.sidebar.addPanel(document.title, window.location, ""); else if(window.external) window.external.AddFavorite(window.location, document.title);
}
function blink(n) {
    var d = document.getElementById(n);
    if (d.style.visibility == "visible") {
        d.style.visibility = 'hidden';
        setTimeout("blink('" + n + "')", 200);
    }
    else {
        d.style.visibility = 'visible';
        setTimeout("blink('" + n + "')", 800);
    }
}
function iscriviNewsletter() {
    var e = document.getElementById('email_newsletter'); if (controllaCampoEmail(e, labelEmailNewsletter, true)) requestHtml(urlAjaxNewsletter + "/m=" + e.value, function(m) {
        alert(m);
    });
}
function onMouseOverRegione(r) {
    var i = document.getElementById("imgItalia"); if (i) i.src = "/lastminute/images/italia/" + r + ".gif";
}
function Point(x, y) {
    this.x = x; this.y = y;
}
function getAbsolutePosition(o) {
    var objParent = o;
    var x = 0;
    var y = 0;
    while (objParent){
        y += objParent.offsetTop;
        x += objParent.offsetLeft;
        objParent = objParent.offsetParent;
    }
    return new Point(x, y);
}
function loadFile(filename, filetype){
    if (filetype == "js"){
        // if filename is a external JavaScript file
        var fileref = document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", filename);
    }
    else if (filetype == "css"){
        //if filename is an external CSS file
        var fileref = document.createElement("link");
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", filename);
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref);
}
// crea il marker per gli hotel sulla mappe di google
function creaMarkerHotel(point, html, img) {
    var icon = new GIcon();
    icon.image = "/lastminute/images/mappe/" + img;
    icon.shadow = "/lastminute/images/mappe/pointer_ombra.gif";
    icon.iconSize = new GSize(17, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(8, 20);
    icon.infoWindowAnchor = new GPoint(8, 10);
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });
    mapRisultati.addOverlay(marker);
    return marker;
}
// visualizza l'indirizzo sulla mappa
function onKeyPressIndirizzo(s, e) {
    var keycode = null;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if (keycode == 13) onClickTrovaIndirizzo();
    return true;
}
function vaiSchedaHotel(id) {
    parent.location = "/lastminute/offerhotel.php?action=hotel.info&idh=" + id;
}
// evento generato al cambio del tipo di gruppo
function onChangeTipoGruppo() {
    var f = document.forms[0];
    var t = f["richiesta:temp_tipo_gruppo"];
    if (t.value == '4') {
        // altro
        f["richiesta:tipo_gruppo"].type = "text";
    // form["richiesta:tipo_gruppo"].value = "";
    } else {
        // predefinito
        f["richiesta:tipo_gruppo"].type = "hidden";
        f["richiesta:tipo_gruppo"].value = t.options[t.value].text;
    }
}
function showLayerMappaHotel(p, s) {
    var url = layerMappaDefaultParams;
    if (p) url += "&" + p;
    var y = s ? (getAbsolutePosition(s)).y : 170;
    showLayerContent(url, y);
}
function showLayerRisultatiMappa(i, h) {
    var u = layerMappaDefaultParams;
    if (i) u += "&id=" + i;
    var y = h ? (getAbsolutePosition(document.getElementById(h))).y + 25 : 170;
    showLayerContent(u, y);
}
// visualizza la mini scheda hotel
function showSchedaHotel(h, n) {
    if (n == 4) {
        // mappa
        showLayerRisultatiMappa(h, 'hotel_' + h);
    } else {
        // richiedi html
        schedaHotelId = h;
        schedaHotelNum = n;
        var url = '/lastminute/offerhotel.php?action=ajax.tabhotel&id=' + h + '&tab=' + n;
        requestHtml(url, function(httpResponse) {
            // visualizza le info hotel
            var divC = window.document.getElementById('tdSchedaHotel' + schedaHotelId);
            divC.innerHTML = httpResponse;
            for (i = 1; i < 4; i++) {
                var btn = window.document.getElementById("btnSchedaHotel_" + i + "_" + schedaHotelId);
                btn.className = (i == schedaHotelNum ? "infohoteltabsel" : "infohoteltab") + " col" + (i + 1);
            }
        });
    }
}
function showFotoSchedaHotel(n) {
    var f = document.getElementById('infoHotelFoto'); f.src = 'http://www.offerhotel.com/foto_alberghi/' + n;
}
function showFotoArea(n, t, u, d) {
    var divFotoAreaGrande = document.getElementById("divFotoAreaGrande");
    divFotoAreaGrande.style.visibility = "visible";
    var f = document.getElementById('imgFotoArea');
    f.src = n;
    var a = document.getElementById('hrefFotoAutore');
    a.href = u;
    a.innerHTML = t;
    var htmld = document.getElementById('spanDistanza');
    htmld.innerHTML = d < 1 ? (d * 1000) + 'm' : d + ' Km';
}
function loadFotoPanoramio(id) {
    requestHtml('/lastminute/offerhotel.php?action=ajax.fotoarea&idh=' + id, function(html) {
        if (html) (document.getElementById("divFotoPanoramio")).innerHTML = html;
    });
}
function blurHotelImage() {
    var d = document.getElementById("hfb");
    var g = document.getElementById("fbg");
    if (d && g) {
        blurImageOpacity -= 5
        if (blurImageOpacity <= 0) {
            blurImageOpacity = 300;
            blurImageIndex = (blurImageIndex + 1) % foto.length;
            d.style.backgroundImage = g.style.backgroundImage;
            g.style.backgroundImage = "url(http://www.offerhotel.com/foto_alberghi/" + foto[blurImageIndex] + ")"
        }
        d.style.opacity = blurImageOpacity / 100;
        d.style.filter = "alpha(opacity=" + blurImageOpacity + ")";
    }
}
function scrollFoto(pv, h) {
    var f = document.getElementById('scrollFoto' + h);
    var f2 = document.getElementById('scrollFotoContainer' + h);
    if (f && f2) {
        var w = parseInt(f.style.width);
        var l = parseInt(f.style.left);
        var w2 = parseInt(f2.offsetWidth);
        l = Math.min(Math.max(l + pv * 70, w2 - w), 0);
        f.style.left = l + "px";
        var sx = document.getElementById('scrollFotoSx' + h);
        var dx = document.getElementById('scrollFotoDx' + h);
        // abilita scroll sinistra
        sx.className = 'scrollFotoSx' + (l == 0 ? 'Off' : '');
        dx.className = 'scrollFotoDx' + (w <= w2 || l == w2 - w ? 'Off' : '');
    }
}
function showFotoHotel(n, d) {
    lastImg = new Image();
    lastImg.src = 'http://www.offerhotel.com/foto_alberghi/' + n;
    lastSource = d;
    waitImageLoad();
}
// attende che l'immagine sia caricata
function waitImageLoad() {
    if (!lastImg.complete) setTimeout("waitImageLoad()", 50);
    else {
        // imposta layer
        var div = document.getElementById('layerFotoHotel');
        var pt = getAbsolutePosition(lastSource);
        // imposta img
        var img = document.getElementById('layerImgFotoHotel');
        img.src = lastImg.src;
        if (isIE6) {
            // nessun effetto con ie6
            img.style.width = lastImg.width;
            img.style.height = lastImg.height;
            div.style.display = 'block';
            div.style.top = (pt.y - lastImg.height / 2) + 'px';
            div.style.left = (pt.x - lastImg.width / 2) + 'px';
            div.style.width = (lastImg.width + 30) + 'px';
        } else {
            // esegue effetto zoom
            lastZoom = 50;
            div.style.display = 'none';
            div.style.top = (pt.y - 20) + 'px';
            div.style.left = (pt.x - 20) + 'px';
            img.style.width = lastZoom + 'px';
            img.style.height = lastZoom + 'px';
            zoomLayerFoto();
        }
    }
}
// ingrandisce il layer delle foto
function zoomLayerFoto() {
    var ok = lastImg.height && lastImg.width;
    if (ok) {
        // ingrandisci
        var div = document.getElementById('layerFotoHotel');
        var img = document.getElementById('layerImgFotoHotel');
        div.style.display = 'block';
        if (lastZoom <= lastImg.height) {
            var h = Math.min(lastZoom + 50, lastImg.height);
            div.style.top = (parseInt(div.style.top) - (h - lastZoom) / 2) + 'px';
            img.style.height = h + 'px';
        }
        if (lastZoom <= lastImg.width) {
            var w = Math.min(lastZoom + 50, lastImg.width);
            div.style.left = Math.max(0, (parseInt(div.style.left) - (w - lastZoom) / 2)) + 'px';
            img.style.width = w + 'px';
        }
        lastZoom += 50;
    }
    if (!(ok && (lastZoom > lastImg.height) && (lastZoom > lastImg.width))) {
        // esegui ancora
        setTimeout('zoomLayerFoto(' + lastZoom + ')', 10);
    }
}
function closeLayerFoto() {
    (document.getElementById('layerFotoHotel')).style.display = 'none';
}
function showLayerContent(u, y) {
    // posizione layer
    var div = document.getElementById('ohLayerDiv');
    var top = 0;
    if (document.documentElement.scrollTop) top = document.documentElement.scrollTop;
    else if (document.layers) top = window.pageYOffset;
    else if (document.all) top = document.body.scrollTop;
    else if (document.getElementById) top = window.pageYOffset;
    if (y <= 0) y = (top + 100);
    else {
        // dimensione pagina
        var wh = 0;
        if (document.documentElement.clientHeight) wh = document.documentElement.clientHeight;
        else if (window.innerHeight) wh = window.innerHeight;
        else if (document.body.clientHeight) wh = document.body.clientHeight;
        var bh = document.body.scrollHeight ? document.body.scrollHeight : document.body.offsetHeight;
        y = Math.min(y, bh - div.offsetHeight);
        if (y < top) window.scroll(0, y - 10);
        else if (y + div.offsetHeight > top + wh) window.scroll(0, y + div.offsetHeight - wh + 10);
    }
    div.style.top = y + 'px';
    div.style.left = ((document.body.clientWidth / 2) - (div.offsetWidth / 2)) + 'px';
    div.style.visibility = 'visible';
    // imposta il contenuto del frame
    var div2 = document.getElementById('ohLayerCenter');
    var frame = document.getElementById('ohLayerFrame');
    if (!frame) {
        // crea oggetto frame
        frame = document.createElement('iframe');
        frame.setAttribute("id", "ohLayerFrame");
        frame.setAttribute("frameBorder", "0");
        frame.setAttribute("scrolling", "no");
        div2.appendChild(frame);
    }
    if (u && u != "") frame.src = u;
}
function closeLayer() {
    var div = document.getElementById('ohLayerDiv');
    if (div) {
        div.style.visibility = 'hidden';
        div.style.left = '-1000px';
        div.style.top = '-1000px';
    }
}
function displayErrForm(n) {
    var errform = document.forms[0][n];
    if (errform) {
        var pt = getAbsolutePosition(errform);
        var d = document.getElementById("errform");
        d.onclick = hideErrForm;
        d.style.display = "block";
        d.style.top = (pt.y - d.offsetHeight + 4) + "px";
        d.style.left = (pt.x + 5) + "px";
        errformTimer = setInterval("blinkErrForm()", 1000);
        errform.onchange = hideErrForm;
        errform.focus();
    }
}
var errformTimer = null;
function blinkErrForm() {
    var d = document.getElementById("errform");
    d.className = (d.className == "on") ? "off" : "on";
}
var errmsgTimer = null;
function blinkErr(id) {
    if (errmsgTimer == null) errmsgTimer = setInterval("blinkErr('" + id + "')", 1000);
    else {
        var d = document.getElementById(id);
        d.className = (d.className == "errmsgon") ? "errmsgoff" : "errmsgon";
    }
}
function hideErrForm() {
    var d = document.getElementById("errform");
    d.style.display = "none";
    if (errformTimer) clearTimeout(errformTimer);
}
function showTooltip(obj, txt, w) {
    var pt = getAbsolutePosition(obj);
    // imposta il contenuto
    var divC = document.getElementById('tooltipContent');
    divC.innerHTML = txt;
    // posiziona
    var div = document.getElementById('tooltip');
    div.style.display = 'block';
    if (w > 0) div.style.width = w + 'px';
    div.style.left = (pt.x - div.offsetWidth + 5) + 'px';
    div.style.top = (pt.y + obj.offsetHeight - 2) + 'px';
}
function closeTooltip() {
    var div = document.getElementById('tooltip');
    if (div) {
        div.style.display = 'none';
        div.style.left = '-1000px';
        div.style.top = '-1000px';
    }
}
function getKeyCode(e) {
    if (!e) e = window.event; return e.keyCode ? e.keyCode : (e.which ? e.which : 0);
}
function CitiesSuggest(id) {
    var tx = document.getElementById(id);
    if (tx) {
        var lo = tx.value;
        var lv = "";
        var mo = false;
        var dn = true;
        var dv = null;
        var cs = document.getElementById("citiesSuggest");
        if (!cs) {
            cs = document.createElement("select");
            cs.setAttribute('id', 'citiesSuggest');
            cs.style.width = tx.parentNode.offsetWidth + 'px';
            cs.size = 6;
            cs.onclick = function() {
                tx.value = cs.options[cs.selectedIndex].text;
                dv.style.display = 'none';
                return true;
            }
            cs.onkeyup = function(e) {
                if (getKeyCode(e) == 27) {
                    dv.style.display = 'none'; tx.focus();
                }
                return true;
            }
            cs.onmouseover = function() {
                mo = true;
            }
            cs.onmouseout = function() {
                mo = false;
            }
            var pt = getAbsolutePosition(tx.parentNode);
            dv = document.createElement("div");
            dv.setAttribute('id', 'citiesSuggestDiv');
            dv.style.position = 'absolute';
            dv.style.display = 'none';
            dv.style.zIndex = '1000';
            dv.style.left = pt.x + 'px';
            dv.style.top = (pt.y + tx.parentNode.offsetHeight) + 'px';
            dv.appendChild(cs);
            document.body.appendChild(dv);
            window.onresize = function() {
                if (dv) {
                    dv.style.display = 'none';
                    var pt = getAbsolutePosition(tx.parentNode);
                    dv.style.left = pt.x + 'px';
                    dv.style.top = (pt.y + tx.parentNode.offsetHeight) + 'px';
                }
            }
        }
        tx.setAttribute('autocomplete', 'off');
        tx.onkeypress = function(e) {
            return getKeyCode(e) != 13;
        }
        tx.onblur = function() {
            if (!mo) dv.style.display = 'none';
        }
        tx.onkeyup = function(e) {
            var keycode = getKeyCode(e);
            switch (keycode) {
                case 38: cs.selectedIndex = Math.max(0, cs.selectedIndex - 1); return false;
                case 40: cs.selectedIndex = Math.min(cs.options.length - 1, cs.selectedIndex + 1); return false;
                case 13:
                    if (cs.selectedIndex > -1) tx.value = cs.options[cs.selectedIndex].text;
                    if (dv.style.display == "none") onSubmitRicerca();
                    else dv.style.display = 'none';
                    return false;
                case 27: dv.style.display = 'none'; return false;
                default:
                    lv = tx.value.replace(/ +$/, '');
                    if (lv.length <= 2) dv.style.display = 'none';
                    else {
                        setTimeout(function() {
                            var tv = tx.value.replace(/ +$/, '');
                            if (tv != "" && tv == lv && tv != lo && dn) {
                                lv = '';
                                dn = false;
                                jsonRequest(urlAppAjax + '/helpluogo/q=' + tv, function(righe) {
                                    lo = tv;
                                    var sel = cs.selectedIndex;
                                    for (i=0; i<righe.length; i++) cs.options[i] = new Option(righe[i].nome, righe[i].id);
                                    for (i=cs.options.length; i>=righe.length; i--) cs.options[i] = null;
                                    if (sel < righe.length) cs.selectedIndex = sel;
                                    cs.size = Math.min(6, Math.max(2, righe.length));
                                    dv.style.display = righe.length > 0 ? 'block' : 'none';
                                    dn = true;
                                });
                            }
                        }, 250);
                    }
                    return true;
            }
        };
        tx.focus();
    }
}
function onChangeDataPartenza() {
    calcoloTotalePrenotazione();
}
function calcoloTotalePrenotazione() {
    var frm = document.forms[0];
    var tot = 0;
    // numero di notti
    var hNotti = frm['notti'];
    var notti = (hNotti != null) ? parseInt(hNotti.value) : 0;
    if (notti == 0) {
        // differenza giorni
        var partenza = getDateShortValue('prenotazione:data_partenza');
        var arrivo = getDateShortValue('prenotazione:data_arrivo');
        notti = dateDiff(partenza, arrivo);
    }
    else {
        notti = 1;
    }
    // quote doppia
    var divQD = document.getElementById('divQuoteDoppia');
    var selQD = frm['prenotazione:quote_doppia'];
    var unitPriceD = frm['prezzoDoppia'].value;
    var costoD = parseInt(selQD.value) * unitPriceD * notti;
    tot += costoD;
    divQD.innerHTML = costoD.toFixed(2);
    // quote singola
    var divQS = document.getElementById('divQuoteSingola');
    if (divQS != null) {
        var selQS = frm['prenotazione:quote_singola'];
        var unitPriceS = frm['prezzoSingola'].value;
        var costoS = parseInt(selQS.value) * unitPriceS * notti;
        tot += costoS;
        divQS.innerHTML = costoS.toFixed(2);
    }
    // totale quote
    // var divTQ = document.getElementById('divTotaleQuote');
    // divTQ.innerHTML = tot.toFixed(2);
    // totale prenotazione
    var divTP = document.getElementById('divTotalePrenotazione');
    divTP.innerHTML = tot.toFixed(2);
}
function onClickDettagliCancellazione() {
    var d = window.document.getElementById("divDettagliCancellazione");
    var a = window.document.getElementById("aDettagliCancellazione");
    if (d.style.display == "block") {
        d.style.display = "none";
        a.innerHTML = langvisualizza;
    } else {
        d.style.display = "block";
        a.innerHTML = langchiudi;
    }
}
function onMouseoverPagamento(s) {
    if(s.className=='modpagoff')s.className='modpagover';
}
function onMouseoutPagamento() {
    var h = document.forms[0]["prenotazione:modalita_pagamento"].value;
    var c = document.getElementById("divPagamentoCarta");
    var b = document.getElementById("divPagamentoAnticipato");
    if (c) c.className = h==constPagamentoCarta ? "modpagon" : "modpagoff";
    if (b) b.className = h==constPagamentoAcconto ? "modpagon" : "modpagoff";
}
function onClickPagamento(s) {
    var h = document.forms[0]["prenotazione:modalita_pagamento"];
    h.value = s;
    var c = document.getElementById("divCarta");
    var b = document.getElementById("divInfoBonifico");    
    switch (s) {
        case constPagamentoCarta: if (c) c.style.display = "block"; if (b) b.style.display = "none"; break;
        case constPagamentoAcconto: if (b) b.style.display = "block"; if (c) c.style.display = "none"; break;
    }
    onMouseoutPagamento();
}
function onChangeCountryPrefisso(n) {
    var f = document.forms[0]; f[n + '_prefisso_1'].value = f['country_' + n + '_prefisso_1'].value;
}
function onChangePrefisso1(n) {
    var f = document.forms[0];
    f['country_' + n + '_prefisso_1'].value = '';
    f['country_' + n + '_prefisso_1'].value = f[n + '_prefisso_1'].value;
}
function checkPrivacy(form) {
    var p1 = document.getElementById('privacy1');
    if (p1.checked) form.submit();
    else alert(langprivacy);
}
function onClickDettagliPrivacy() {
    var d = document.getElementById('privacyDettagli');
    d.style.display = d.style.display == "block" ? "none" : "block";
}
function onKeyupCliente() {
    var n = document.getElementById("cliente_nome");
    var c = document.getElementById("cliente_cognome");
    var i = document.getElementById("cartagaranzia_intestato");
    if (i && n && c) i.value = n.value + " " + c.value;
}
function blinkrs() {
    if (blinkrsx == 0) {
        blinkrsx=1; setInterval(blinkrstime, 500);
    }
}
function blinkrstime() {
    var b = document.getElementById("btnrs"); if (b) b.className = b.className == "btnrsa" ? "btnrsv" : "btnrsa";
}
function onChangeCamereRS(frmn, roomtypes) {
    if (!frmn) frmn = "frmrsh";
    var frm = document.getElementById(frmn);
    var r = parseInt(frm["ricerca:camere"].value);
    while (frm.childNodes.length > 1 + r) frm.removeChild(frm.lastChild);
    for (i = frm.childNodes.length; i <= r; i++) {
        var fs = document.createElement("fieldset");
        fs.className = "f2";
        var leg = document.createElement("legend");
        leg.innerHTML = langrsc + " " + i;
        var lab = document.createElement("label");
        lab.innerHTML = langrsct;
        var sel = createNamedElement("select", "ricerca:camera" + i + "tipo");
        sel.onchange = blinkrs;
        sel.className = "tc";
        if (!roomtypes) roomtypes = ["S", "D", "M", "T", "Q", "A"];
        var roomnames = {"S":langrscts, "D":langrsctd, "M":langrsctm, "T":langrsctt, "Q":langrsctq, "A":langrscta};       
        for (var rti in roomtypes) sel.options[sel.options.length] = new Option(roomnames[roomtypes[rti]], roomtypes[rti]);
        /*
        sel.options[0] = new Option(langrscts, "S");
        sel.options[1] = new Option(langrsctd, "D");
        sel.options[2] = new Option(langrsctm, "M");
        sel.options[3] = new Option(langrsctt, "T");
        sel.options[4] = new Option(langrsctq, "Q");
        sel.options[5] = new Option(langrscta, "A");
        */
        var labb = document.createElement("label");
        labb.className = "f2";
        labb.innerHTML = langrsb;
        var selb = createNamedElement("select", "ricerca:camera" + i + "bambini");
        selb.style.width = "40px";
        selb.onchange = onChangeBambini;
        for (j=0; j<=4; j++) selb.options[j] = new Option(j, j);
        fs.appendChild(leg);
        fs.appendChild(lab);
        fs.appendChild(sel);
        fs.appendChild(document.createElement("br"));
        fs.appendChild(labb);
        fs.appendChild(selb);
        fs.appendChild(document.createElement("br"));
        frm.appendChild(fs);
    }
    blinkrs();
}
// controlla i criteri di ricerca
function onSubmitRicerca() {
    var f = document.forms.ricerca; if (controllaCampoVuoto(f['ricerca:citta'], langRicercaCitta)) f.submit();
}
function onRicercaAvanzata() {
    document.forms.ricerca.submit();
}
function onAumentaDistanza(d) {
    var f = document.forms.ricerca; f['ricerca:distanza'].value = d; onSubmitRicerca();
}
function onLoadRicercaSoggiorno(h) {
    if (h) {
        var r = h.split('+');
        if (r && r.length > 5) {
            var frm = document.getElementById("formRicercaSoggiorno");
            frm["ricerca:luogo"].value = r[0];
            frm["ricerca:distanza"].value = r[1];
            frm["ricerca:hotel"].value = r[2];
            var dataArrivo = new Date(r[3].substr(0, 4), r[3].substr(5, 2) - 1, r[3].substr(8, 2));
            var dataPartenza = new Date(r[4].substr(0, 4), r[4].substr(5, 2) - 1, r[4].substr(8, 2));
            updateDateShortValue("ricerca:arrivo", dataArrivo, frm);
            updateDateShortValue("ricerca:partenza", dataPartenza, frm);
            frm["ricerca:camere"].value = r[5];
            onChangeRicercaArrivo();
        }
    }
}
function onloadrsh(h) {
    if (h) {
        var r = h.split('+');
        if (r && r.length > 5) {
            blinkrsx = 1;
            var frm = document.getElementById("frmrsh");
            var dataArrivo = new Date(r[3].substr(0, 4), r[3].substr(5, 2) - 1, r[3].substr(8, 2));
            var dataPartenza = new Date(r[4].substr(0, 4), r[4].substr(5, 2) - 1, r[4].substr(8, 2));
            updateDateShortValue("ricerca:arrivo", dataArrivo, frm);
            updateDateShortValue("ricerca:partenza", dataPartenza, frm);
            onChangeRicercaArrivo();
            frm["ricerca:camere"].value = r[5];
            frm["ricerca:camere"].onchange();
            var i, j, p = 5, b;
            for (i=1; i<= r[5]; i++) {
                frm["ricerca:camera" + i + "tipo"].value = r[++p];
                b = r[++p];
                frm["ricerca:camera" + i + "bambini"].value = b;
                frm["ricerca:camera" + i + "bambini"].onchange();
                for (j = 1; j <= b; j++) frm["ricerca:camera" + i + "etaBambino" + j].value = r[++p];
            }
            blinkrsx = 0;
        }
    }
}
function onChangeRicercaArrivo() {
    onChangeRicerca('a');
}
function onChangeRicercaPartenza() {
    onChangeRicerca('p');
}
function onChangeRicerca(t) {
    var frm = document.forms.ricerca;
    var arrivo = getDateShortValue("ricerca:arrivo", frm);
    if (arrivo != null) {
        var adesso = new Date();
        var arrivoYmd = fromDateToYmd(arrivo);
        var adessoYmd = fromDateToYmd(adesso);
        if (arrivoYmd < adessoYmd) {
            do {
                arrivo.setMonth(arrivo.getMonth() + 1);
                arrivoYmd = fromDateToYmd(arrivo);
            }
            while (arrivoYmd < adessoYmd);
            updateDateShortValue("ricerca:arrivo", arrivo, frm);
        }
        var partenza = getDateShortValue("ricerca:partenza", frm);
        if (partenza != null) {
            if (arrivo.getTime() >= partenza.getTime()) {
                if (t == 'a') {
                    partenza.setTime(arrivo.getTime());
                    partenza.setDate(arrivo.getDate() + 1);
                } else if (t == 'p') {
                    while (arrivo.getTime() >= partenza.getTime()) {
                        partenza.setMonth(partenza.getMonth() + 1);
                    }
                }
                updateDateShortValue("ricerca:partenza", partenza, frm);
            }
            if (calendar) {
                calendar.highlightStart = getDateShortValue("ricerca:arrivo", frm);
                calendar.highlightEnd = getDateShortValue("ricerca:partenza", frm);
            }
        }
    }
    blinkrs();
}
function onChangeBambini() {
    var fs = this.parentNode;
    var name = this.name.replace("bambini", "etaBambino");
    while (fs.childNodes.length > 7 + this.value * 3) fs.removeChild(fs.lastChild);
    for (i = (fs.childNodes.length - 7) / 3 + 1; i <= this.value; i++) {
        var lab = document.createElement("label");
        lab.className = "f2";
        lab.innerHTML = langrseb + " " + i;
        var sel = createNamedElement("select", name + i);
        sel.onchange = blinkrs;
        sel.style.width = "40px";
        for (j=0; j<=17; j++) sel.options[j] = new Option(j, j);
        fs.appendChild(lab);
        fs.appendChild(sel);
        fs.appendChild(document.createElement("br"));
    }
    blinkrs();
}
function onChangeCamere() {
    var form = document.forms['ricerca'];
    var camere = parseInt(form['ricerca:camere'].value);
    for (i=1; i<=form['ricerca:camere'].options.length; i++) {
        var tr = document.getElementById('trRicercaCamera' + i);
        if (i <= camere) tr.style.display = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" : "table-row";
        else {
            form['ricerca:camera' + i + 'tipo'].value = "M";
            form['ricerca:camera' + i + 'bambini'].value = "0";
            tr.style.display = 'none';
        }
        var bambini = parseInt(form['ricerca:camera' + i + 'bambini'].value);
        for (j=1; j<=4; j++) {
            var trb = document.getElementById('trRicercaCameraBambini' + i + '_' + j);
            if ((i <= camere) && (j <= bambini)) {
                trb.style.display = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" : "table-row";
            }
            else {
                form['ricerca:camera' + i + 'etaBambino' + j].value = "0";
                trb.style.display = 'none';
            }
        }
    }
}
function onFiltroVicino(v) {
    var f = document.forms.ricerca; f['ricerca:filtroVicino'].value = v; f.submit();
}
function onFiltroOrdinamento(v) {
    var f = document.forms.ricerca; f['ricerca:ordinamento'].value = v; f.submit();
}
function onFiltroPrenotazione(v) {
    var f = document.forms.ricerca; f['ricerca:filtroPrenotazione'].value = v; f.submit();
}
function onFiltroStruttura(v) {
    var f = document.forms.ricerca; f['ricerca:filtroStruttura'].value = v; f.submit();
}
function onMouseOverFiltroStrutturaStelle(n) {
    var d = document.getElementById('filtroStrutturaStelle'); d.style.background = 'url(/lastminute/images/stelle/mini' + n + '.gif) no-repeat left 4px';
}
function onChangeFiltroServizi(s, c) {
    var form = document.forms['ricerca'];
    var i = parseInt(form["ricerca:filtroServizi"].value);
    if (!c) i = i | s; else if (i & s) i -= s;
    form["ricerca:filtroServizi"].value = i;
    onSubmitRicerca();
}