var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
var homeTabSelected = 1;
var blurImageIndex = 0;
var blurImageOpacity = 0;
var calendar = new Calendar();
var schedaHotelId = 0;
var schedaHotelNum = 0;
var layerMappaDefaultParams = "";
var blinkrsx = 0;
var clickPlanner = 0;
function addOpenSearchPlugin() {
    try {
        window.external.AddSearchProvider(urlAppBase + "xml/opensearch");
    } catch (e) {
        alert( "Cannot install search plugin. Your client might not be compatible." );
    }
}
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;
}
String.prototype.trim = function() {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
Date.prototype.ohformat = function(f) {
    var c = {
        "%d": (this.getDate() < 10 ? "0" : "") + this.getDate(),
        "%m": (this.getMonth() < 9 ? "0" : "") + (this.getMonth() + 1),
        "%n": monthNames[this.getMonth()],
        "%Y": this.getFullYear(),
        "%y": this.getFullYear() - 2000
    }
    for (var h in c) f = f.replace(h, c[h]);
    return f;
}
Date.prototype.daydiff = function(b) {
    return Math.round((this.getTime()-b.getTime())/86400000);
}
Date.ohparse = function(v) {
    var d = v.match(/([0-9]{4}).([0-9]{2}).([0-9]{2})/);    
    return d ? new Date(d[1], d[2] - 1, d[3]) : new Date();
}
Date.today = function() {
    var d = new Date();
    d.setHours(0, 0, 0, 0);
    return d;
}
$.fn.extend({
    ohdpupdate: function(v) {
        if (v) {
            this.each(function() {
                if (this.nodeName == 'SPAN')
                    this.innerHTML = v.ohformat("%d - %n - %Y");
                else
                    this.value = v.ohformat("%d - %n - %Y");
                $("input[name$='" + this.id + "']").val(v.ohformat("%Y-%m-%d"))
            });
        }
    },
    ohdpvalue: function() {
        return this.length > 0 ? Date.ohparse($("input[name$='" + this[0].id + "']").val()) : new Date();
    },
    ohdpclick: function() {
        this.each(function() {
            var dp = this;
            var dpq = $(this);
            var d = dpq.ohdpvalue();
            var pt = dpq.offset();
            pt.left += dpq.innerWidth() + 4;
            calendar.clickDayCustom = function(d) {
                dpq.ohdpupdate(d);
                if (dp.dpclickCustom) dp.dpclickCustom();
            };
            calendar.selectedDate = d;
            calendar.display(d.getFullYear(), d.getMonth() + 1, pt);
        });
    },
    ohdatepicker : function(f) {
        this.each(function() {            
            this.dpclickCustom = f;
            var dpq = $(this);
            dpq.bind('focus', function() {
                $(this).ohdpclick()
                this.select();
            });
            dpq.bind('blur', function() {
                if (!calendar.isMouseOver) calendar.hide()
            });
            dpq.bind('change', function() {
                var q = $(this);                
                var t = this.value.replace(/[ /\-.]+/g, ' ').trim();
                for (var i = 0; i < 12; i++) {
                    var r = new RegExp(monthNames[i], 'i');
                    t = t.replace(r, i + 1);
                }
                t = t.match(/^([0-9]{1,2}) ([0-9]{1,2}) ([0-9]{1,4})$/);
                var d = t ? new Date(t[3] < 2000 ? parseInt(t[3]) + 2000 : t[3], t[2] - 1, t[1]) : null;
                q.ohdpupdate(d = d ? d : q.ohdpvalue());
                if (this.dpclickCustom) this.dpclickCustom();
                calendar.hide();
            });
        });
    }
});
function Calendar() {
    this.selectedDate = new Date();    
    this.highlightStart = null;
    this.highlightEnd = null;
    this.isMouseOver = false;
    this.clickDayCustom = null;
    this.display = function(y, m, pt) {
        var div = $('#calendar');
        if (div.length == 0) {
            var cal = document.createElement("div");
            cal.id = "calendar";
            cal.onmouseover = function() {
                calendar.isMouseOver = true
            }
            cal.onmouseout = function() {
                calendar.isMouseOver = false
            }
            document.body.appendChild(cal);
            div = $('#calendar');
        } else {
            $('#calendar table').remove();
        }
        var mindate = Date.today();
        var firstDay = new Date(y, m - 1, 1);
        y = firstDay.getFullYear();
        m = firstDay.getMonth();
        var lastDay = new Date(y, m + 1, 0);
        var table = document.createElement("table");
        table.cellPadding = "0";
        table.cellSpacing = "1px";
        var tbody = document.createElement("tbody");
        table.appendChild(tbody);
        var tr = document.createElement("tr");
        tr.className = "title";
        tbody.appendChild(tr);
        var td = document.createElement("td");
        tr.appendChild(td);
        td.className = "a";
        td.onclick = function() {
            calendar.display(y, m)
        }
        td = document.createElement("td");
        tr.appendChild(td);
        td.colSpan = 4;
        td.innerHTML = monthNames[m] + " " + y;
        td = document.createElement("td");
        tr.appendChild(td);
        td.className = "b";
        td.onclick = function() {
            calendar.display(y, m + 2);
        }
        td = document.createElement("td");
        tr.appendChild(td);
        td.className = "c";
        td.onclick = function() {
            calendar.hide();
        }
        tr = document.createElement("tr");
        tbody.appendChild(tr);
        for (i=0; i<7; i++) {
            var th = document.createElement("th");
            th.innerHTML = dayNames[i];
            tr.appendChild(th);
        }
        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);
        if (this.highlightStart) this.highlightStart.setHours(0, 0, 0, 0);
        if (this.highlightEnd) this.highlightEnd.setHours(0, 0, 0, 0);
        while (firstDay <= lastDay) {
            w = firstDay.getDay();
            if (w % 7 == 1) {
                tr = document.createElement("tr");
                tbody.appendChild(tr);
            }
            var tdcss = '';
            var t = firstDay.getTime();
            if (t < mindate) tdcss = 'off';
            else if (this.highlightStart && this.highlightEnd && t >= this.highlightStart && t < this.highlightEnd) tdcss = 'sel';
            else if (this.highlightEnd && t == this.highlightEnd.getTime()) tdcss = 'hgl';
            else if (firstDay.getMonth() != m) tdcss = 'other';
            else if (t == this.selectedDate) tdcss = 'over';
            td = document.createElement("td");
            tr.appendChild(td);
            td.value = t;
            td.className = tdcss;
            if (tdcss != 'off') {
                td.onclick = function() {
                    calendar.clickDay(this.value);
                }
                td.onmouseover = function() {
                    $(this).addClass("over");
                }
                td.onmouseout = function() {
                    $(this).removeClass("over");
                }
            }
            td.innerHTML = firstDay.getDate();
            firstDay.setDate(firstDay.getDate() + 1);
        }        
        div.append(table);
        if (pt) div.css({
            left: pt.left + 'px',
            top: pt.top + 'px'
        });
        div.fadeIn('medium');
    }
    this.hide = function() {
        $('#calendar').hide();
    }
    this.clickDay = function(d) {
        this.hide();
        this.selectedDate = new Date(d);        
        if (this.clickDayCustom) this.clickDayCustom(this.selectedDate);
    };    
}
function controllaCampoVuoto(c, a) {
    if (c == null || c.value == "") {
        alert(langErrCampoVuoto.replace("$1", a));
        c.focus();
        return false;
    }
    return true;
}
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');
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(e.value)) {
        $.get(urlAjaxNewsletter + "/m=" + e.value, function(h) {
            alert(h)
        });
    } else {
        alert("Devi inserire un indirizzo email valido per iscriverti alla newsletter!");
        e.focus();
    }
}
function onMouseOverRegione(r) {
    var i = document.getElementById("imgItalia");
    if (i) i.src = "/resx/images/italia/" + r + ".gif";
}
function creaMarkerHotel(point, html, img) {
    var icon = new GIcon();
    icon.image = "/resx/images/mappe/" + img;
    icon.shadow = "/resx/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);
    });    
    return marker;
}
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 = "/index.php?action=hotel.info&idh=" + id;
}
function onChangeTipoGruppo() {
    var f = document.forms[0];
    var t = f["richiesta_temp_tipo_gruppo"];
    if (t.value == '4') {
        f["richiesta_tipo_gruppo"].type = "text";
    } else {
        f["richiesta_tipo_gruppo"].type = "hidden";
        f["richiesta_tipo_gruppo"].value = t.options[t.value].text;
    }
}
function showLayerMappaHotel(p) {
    var url = layerMappaDefaultParams;
    if (p) url += "&" + p;
    showLayerContent(url, 170);
}
function showLayerRisultatiMappa(i, h) {
    var u = layerMappaDefaultParams;
    if (i) u += "&id=" + i;
    showLayerContent(u, h ? $('#' + h).offset().top + 25 : 170);
}
function showSchedaHotel(h, n) {
    if (n == 4) {
        // mappa
        showLayerRisultatiMappa(h, 'hotel_' + h);
    }
    else {
        // richiedi html
        schedaHotelId = h;
        schedaHotelNum = n;
        var url = '/index.php?action=ajax.tabhotel&id=' + h + '&tab=' + n;
        $('#tdSchedaHotel' + schedaHotelId).load(url, function() {
            for (i = 1; i < 4; i++) {
                var btn = 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) {
    $("#divFotoPanoramio").load('/index.php?action=ajax.fotoarea&idh=' + id);
}
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) {
    var img = new Image();
    img.src = 'http://www.offerhotel.com/foto_alberghi/' + n;
    var i = setInterval(function() {
        if (img.complete) {
            clearInterval(i);
            var div = document.getElementById('layerFotoHotel');
            var imgct = document.getElementById('layerImgFotoHotel');
            if (!div) {
                div = document.createElement("div");
                div.id = "layerFotoHotel";
                div.className = "layer";
                div.onclick = closeLayerFoto;
                imgct = document.createElement("img");
                imgct.id = "layerImgFotoHotel";
                imgct.title = ohlang.chiudi;
                diva = document.createElement("div");
                divb = document.createElement("div");
                divc = document.createElement("div");
                divd = document.createElement("div");
                dive = document.createElement("div");
                divf = document.createElement("div");
                divg = document.createElement("div");
                divh = document.createElement("div");
                divi = document.createElement("div");
                divcl = document.createElement("div");
                diva.className = "a";
                divb.className = "b";
                divc.className = "c";
                divd.className = "d";
                dive.className = "e";
                divf.className = "f";
                divg.className = "g";
                divh.className = "h";
                divi.className = "i";
                divi.style.paddingBottom = "5px";
                divi.style.textAlign = "center";
                divcl.className = "close";
                diva.appendChild(divb);
                divb.appendChild(divc);
                divd.appendChild(dive);
                dive.appendChild(divf);
                divg.appendChild(divh);
                divh.appendChild(divi);
                divi.appendChild(divcl);
                divi.appendChild(imgct);
                div.appendChild(diva);
                div.appendChild(divg);
                div.appendChild(divd);
                spancl = document.createElement("span");
                spancl.onclick = closeLayerFoto;
                spancl.innerHTML = ohlang.chiudi;
                divcl.appendChild(spancl);
                document.body.appendChild(div);
            }
            imgct.src = img.src;
            var pt = $(d).offset();
            var $div = $(div);
            if (isIE6) $div.addClass("layer6");
            $div.css({
                top: (pt.top + 25 - $div.height() / 2) + 'px',
                left: (pt.left + 25 - (img.width + 30) / 2) + 'px',
                width: (img.width + 30) + 'px'
            });
            $div.show();
        }
    }, 100);
}
function closeLayerFoto() {
    $('#layerFotoHotel').hide();
}
function showLayerContent(u, y) {
    var div = document.getElementById('ohLayerDiv');
    if (!div) {
        div = document.createElement("div");
        div.id = "ohLayerDiv";
        div.className = "layer";
        divct = document.createElement("div");
        divct.id = "ohLayerCenter";
        diva = document.createElement("div");
        divb = document.createElement("div");
        divc = document.createElement("div");
        divd = document.createElement("div");
        dive = document.createElement("div");
        divf = document.createElement("div");
        divg = document.createElement("div");
        divh = document.createElement("div");
        divi = document.createElement("div");
        divcl = document.createElement("div");        
        diva.className = "a";
        divb.className = "b";
        divc.className = "c";
        divd.className = "d";
        dive.className = "e";
        divf.className = "f";
        divg.className = "g";
        divh.className = "h";
        divi.className = "i";
        divcl.className = "close";
        diva.appendChild(divb);
        divb.appendChild(divc);
        divd.appendChild(dive);
        dive.appendChild(divf);
        divg.appendChild(divh);
        divh.appendChild(divi);
        divi.appendChild(divcl);
        divi.appendChild(divct);
        div.appendChild(diva);
        div.appendChild(divg);
        div.appendChild(divd);
        spancl = document.createElement("span");
        spancl.onclick = closeLayer;
        spancl.innerHTML = ohlang.chiudi;
        divcl.appendChild(spancl);
        document.body.appendChild(div);
    }
    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 {
        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';
    if (isIE6) $(div).addClass("layer6");
    // 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() {
    $('#ohLayerDiv').css({
        visibility:'hidden',
        left:'-1000px',
        top:'-1000px'
    });
}
function displayErrForm(n, msg) {
    var errform = document.forms[0][n];
    if (errform) {        
        var d = document.createElement("div");
        d.className = "errform";
        d.innerHTML = "<table cellspacing='0' cellpadding='0'><tr><td>" + msg + "</td></tr></table>";
        $(d).insertAfter(errform);
        errform.onchange = function() {
            d.style.display = "none";
            closeTooltip();
        }
        errform.focus();
    }
}
function showTooltip(obj, txt, w, open, side) {
    if (!side) side = 'l';
    var pt = $(obj).offset();
    var div = document.getElementById('tooltip');
    var divC = document.getElementById('tooltipContent');
    if (!div) {
        div = document.createElement('div');
        div.id = 'tooltip';
        div.className = 'l';
        divC = document.createElement('div');
        divC.id = "tooltipContent";
        var tt1 = document.createElement('div');
        var tt2 = document.createElement('div');
        var tt3 = document.createElement('div');
        var tt4 = document.createElement('div');
        var tt5 = document.createElement('div');
        var tt6 = document.createElement('div');        
        tt1.className = 'tt1';
        tt2.className = 'tt2';
        tt3.className = 'tt3';
        tt4.className = 'tt4';
        tt5.className = 'tt5';
        tt6.className = 'tt6';
        tt2.appendChild(tt3);
        tt1.appendChild(tt2);
        tt5.appendChild(tt6);
        tt4.appendChild(tt5);
        div.appendChild(tt1);
        div.appendChild(divC);
        div.appendChild(tt4);
        var body = document.getElementsByTagName('body');
        body[0].appendChild(div);
    }
    divC.innerHTML = txt;
    div.style.display = 'block';
    div.className = side;
    div.style.width = w > 0 ? w + 'px' : '300px';
    div.style.left = (side == 'r' ? pt.left + obj.offsetWidth - 5 : pt.left - div.offsetWidth + 5) + 'px';
    div.style.top = (pt.top + obj.offsetHeight - 2) + 'px';
    if (!open) obj.onmouseout = closeTooltip;
}
function showTooltipDisponibili(s, d) {
    showTooltip(s, ohlang.disponibili.replace('$1', d), 360, false, 'r')
}
function showFrame(url, w, h, y) {
    var f = $('#ohmodalframe');
    if (f.length == 0) {
        f = document.createElement("iframe");
        f.id = "ohmodalframe";
        f.setAttribute('frameborder', '0');
        f = $(f);
    }
    f.attr('src', url);
    if (w > 0) f.css({
        width: w + 'px'
    });
    if (h > 0) f.css({
        height: h + 'px'
    });
    f.modal();
}
function showSsl() {
    var u = 'https://sealinfo.thawte.com/thawtesplash?form_file=fdf/thawtesplash.fdf&dn=WWW.OFFERHOTEL.COM';
    var w = 516;
    var h = Math.min(650, Math.max(300, $(document.body).outerHeight() - 110));
    showFrame(u, w, h);
    $('#simplemodal-container').css({
        top: '100px'
    });
}
function closeTooltip() {
    $('#tooltip').css({
        display:'none',
        left:'-1000px',
        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.setAttribute('size', 6);
            cs.style.width = tx.offsetWidth + 'px';            
            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;
            }            
            dv = document.createElement("div");
            dv.setAttribute('id', 'citiesSuggestDiv');
            dv.style.position = 'absolute';
            dv.style.display = 'none';
            dv.style.zIndex = '1000';
            dv.appendChild(cs);
            document.body.appendChild(dv);
            window.onresize = function() {
                if (dv) {
                    dv.style.display = 'none';
                }
            }
        }
        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") submitrs();
                    else dv.style.display = 'none';
                    return false;
                case 27:
                    dv.style.display = 'none';
                    return false;
                default:
                    lv = tx.value.replace(/ +$/, '');
                    if (lv.length <= 2) {
                        lo = "";
                        dv.style.display = 'none';
                    } else {
                        setTimeout(function() {
                            var tv = tx.value.replace(/ +$/, '');
                            if (tv != "" && tv == lv && tv != lo && dn) {
                                lv = '';
                                dn = false;
                                $.getJSON(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));
                                    calendar.hide();
                                    var pt = $(tx).offset();
                                    dv.style.display = righe.length > 0 ? 'block' : 'none';
                                    dv.style.left = pt.left + 'px';
                                    dv.style.top = (pt.top + tx.offsetHeight + 1) + 'px';
                                    dn = true;
                                });
                            }
                        }, 250);
                    }
                    return true;
            }
        };
    // tx.focus();
    }
}
function calcoloTotalePrenotazione() {
    var frm = document.forms[0];
    var tot = 0;
    var hNotti = frm['notti'];
    var notti = (hNotti != null) ? parseInt(hNotti.value) : 0;
    if (notti == 0) {
        var dpa = $('#prenotazione_data_arrivo');
        var dpp = $('#prenotazione_data_partenza');
        notti = Math.abs(dpp.ohdpvalue().daydiff(dpa.ohdpvalue()));
    }
    else {
        notti = 1;
    }
    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);
    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);
    }
    var divTP = document.getElementById('divTotalePrenotazione');
    divTP.innerHTML = tot.toFixed(2);
}
function onClickDettagliCancellazione() {
    var $d = $("#divDettagliCancellazione");    
    $("#aDettagliCancellazione").html($d.is(':visible') ? langvisualizza : ohlang.chiudidettagli);
    $d.slideToggle('medium');
}
function onMouseoverPagamento(s) {
    if (s.className == 'modpagoff') s.className = 'modpagover';
    s.onmouseout = onMouseoutPagamento;
}
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) {
    closeTooltip();
    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() {
    $('#privacyDettagli').toggle();
}
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(function() {
            var b = document.getElementById("btnrs");
            if (b) {
                if (b.className == "btnsmallI") b.className = "btnsmallP";
                else if (b.className == "btnsmallP") b.className = "btnsmallI";
                else if (b.className == "btnbigv") b.className = "btnbigr";
                else if (b.className == "btnbigr") b.className = "btnbigv";
                else if (b.className == "btnrson") b.className = "btnrsoff";
                else if (b.className == "btnrsoff") b.className = "btnrson";
            }
        }, 500);
    }
}
function onChangeCamereRS(frmn, roomtypes) {
    if (!frmn) frmn = "frmrsh";
    var frm = document.getElementById(frmn);
    var $frm = $(frm);
    var fds = $frm.children('.f2');
    var r = parseInt(frm["ricerca_camere"].value);
    for (i = r; i < fds.length; i++) frm.removeChild(fds[i]);
    for (i = 1; i <= r; i++) {
        if (i > fds.length) {
            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");
            if (!roomtypes) roomtypes = ["S", "D", "M", "T", "Q", "A", "6", "7", "8", "9", "X"];
            var roomnames = {
                "S":langrscts,
                "D":langrsctd,
                "M":langrsctm,
                "T":langrsctt,
                "Q":langrsctq,
                "A":langrscta,
                "6":langrsct6,
                "7":langrsct7,
                "8":langrsct8,
                "9":langrsct9,
                "X":langrsctx
            };
            for (var rti in roomtypes) sel.options[sel.options.length] = new Option(roomnames[roomtypes[rti]], roomtypes[rti]);
            sel.style.width = "142px";
            sel.onchange = blinkrs;
            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 = function() {
                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();
            };
            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();
}
function onsubmitrs() {
    var f = document.forms.ricerca;
    if (!f) f = document.forms.frmrsh;
    return controllaCampoVuoto(f['ricerca_citta'], ohlang.citta);
}
function submitrs() {
    if (onsubmitrs()) {
        var f = document.forms.ricerca;
        if (!f) f = document.forms.frmrsh;
        f.submit();
    }
}
function onRicercaAvanzata() {
    document.forms.ricerca.submit();
}
function onAumentaDistanza(d) {
    var f = document.forms.ricerca;
    f['ricerca_distanza'].value = d;
    submitrs();
}
function onloadrs(h) {
    if (!h && ohRicercaK) h = ohRicercaK;
    if (h) {
        var r = h.split('+');
        if (r && r.length > 5) {
            blinkrsx = 1;
            var frm = document.getElementById("formRicercaSoggiorno");
            if (!frm) frm = document.getElementById("frmrsh");
            if (frm["ricerca_luogo"]) frm["ricerca_luogo"].value = r[0];
            if (frm["ricerca_distanza"]) frm["ricerca_distanza"].value = r[1];
            frm["ricerca_hotel"].value = r[2];
            $('#ricerca_arrivo').ohdpupdate(Date.ohparse(r[4]));
            $('#ricerca_partenza').ohdpupdate(Date.ohparse(r[5]));
            frm["ricerca_persone"].value = r[6];
            frm["ricerca_camere"].value = r[6];            
            frm["ricerca_camere"].onchange = function() {
                frm["ricerca_persone"].value = Math.max(parseInt(this.value), parseInt(frm["ricerca_persone"].value));
            }
            onChangeRicercaArrivo();
            blinkrsx = 0;
        }
    }
}
function onloadrsh(h) {
    if (!h && ohRicercaK) h = ohRicercaK;
    if (h) {
        var r = h.split('+');
        if (r && r.length > 5) {
            blinkrsx = 1;            
            $('#ricerca_arrivo').ohdpupdate(Date.ohparse(r[4]));
            $('#ricerca_partenza').ohdpupdate(Date.ohparse(r[5]));
            onChangeRicercaArrivo();
            var frm = document.getElementById("frmrsh");
            frm["ricerca_camere"].value = r[6];
            if (frm["ricerca_camere"].onchange != null) {
                frm["ricerca_camere"].onchange();
                var i, j, p = 6, b;
                for (i=1; i<= r[6]; 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 onClickPlanner(d, be) {
    if (be) {
        window.location = be;
    } else {
        $('#ricerca_' + (++clickPlanner % 2 == 0 ? 'partenza' : 'arrivo')).ohdpupdate(new Date(d));
        onChangeRicercaArrivo();
    }
}
function onChangeRicercaArrivo() {
    onChangeRicerca('a');
}
function onChangeRicercaPartenza() {
    onChangeRicerca('p');
}
function onChangeRicerca(t) {
    var dpa = $('#ricerca_arrivo');
    var a = dpa.ohdpvalue();
    if (a) {        
        var b = new Date();
        if (a < b) {
            a = b;
            dpa.ohdpupdate(a);
        }
        var dpp = new $('#ricerca_partenza');
        var p = dpp.ohdpvalue();
        if (a >= p) {
            if (t == 'p') while (a >= p) p.setMonth(p.getMonth() + 1)
            else if (t == 'a') {
                p.setTime(a.getTime());
                p.setDate(p.getDate() + 1);
            }
            dpp.ohdpupdate(p);
        }
        if (calendar) {
            calendar.highlightStart = a;
            calendar.highlightEnd = p;
        }
    }
    blinkrs();
}
function onFiltroVicino(v) {
    document.forms.ricerca.ricerca_filtroVicino.value = v;
    submitrs();
}
function onFiltroOrdinamento(v) {
    document.forms.ricerca.ricerca_ordinamento.value = v;
    submitrs();
}
function onFiltroPrenotazione(v) {
    document.forms.ricerca.ricerca_filtroPrenotazione.value = v;
    submitrs();
}
function onFiltroStruttura(v) {
    document.forms.ricerca.ricerca_filtroStruttura.value = v;
    submitrs();
}
function onMouseOverFiltroStrutturaStelle(n) {
    var d = document.getElementById('filtroStrutturaStelle');
    d.style.background = 'url(/resx/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;
    submitrs();
}
function onChangeDateShort(name, func) {
    var frm = window.document.forms[0];
    var y = frm['dateShort_y_' + name].value;
    var m = frm['dateShort_m_' + name].value;
    var d = frm['dateShort_d_' + name].value;
    var h = frm[name];
    h.value = '';
    if (y > 0 && m > 0 && d > 0) {
        m = parseInt((m.substring(0, 1) == "0") ? m.substring(1) : m);
        d = parseInt((d.substring(0, 1) == "0") ? d.substring(1) : d);
        var t = new Date(y, parseInt(m) - 1, parseInt(d));
        h.value = t.ohformat('%Y-%m-%d');
    }
    if (func && self[func] != null) eval(func + '()');
}
function onChangeOra(n) {
    var a = document.getElementById(n);
    a.value = document.getElementById(n + "_ora").value + ":" + document.getElementById(n + "_min").value;
}
function onChangeHomeTab(i) {
    if (i != homeTabSelected) {
        var d = document.getElementById("homeTab" + homeTabSelected);
        d.className = "";
        d = document.getElementById("homeTab" + i);
        d.className = "sel";
        d = document.getElementById("homeTabContent" + homeTabSelected);
        d.style.display = "none";
        d = document.getElementById("homeTabContent" + i);
        d.style.display = "block";
        homeTabSelected = i;    
    }
    return false;
}
function onclickpoi(h, p) {
    window.location = "/index.php?action=hotel.mappa&idh=" + h + "&poi=" + p;
}
function onkeygiudizio(s) {
    if (s.value.length>130)s.value=s.value.substr(0,130);
    document.getElementById('numchars').innerHTML = 130-s.value.length;
    return true;
}
function initRisultatiRicerca() {
    $(document).ready(function() {
        $('.tipsoluz').each(function() {
            var ts = $(this).hide();
            var ta = ts.prev('table');
            var imgsrc = $('.left img:first', ts).attr('src');
            var div = document.createElement("div");
            div.style.position = 'relative';
            div.style.textAlign = 'center';
            var imgma = document.createElement("img");
            if (imgsrc != null) {
                imgma.src = imgsrc;
                imgma.className = "rsmall";
                var info = document.createElement("img");
                info.src = "/resx/info.png";
                info.style.width = '16px';
                info.style.height = '16px';
                info.style.cursor = 'pointer'
                info.style.position = 'absolute';
                info.style.top = '-8px';
                info.style.right ='0px';
                div.appendChild(info);
            } else {
                imgma.src = "/resx/info.png";
            }
            div.appendChild(imgma);
            $('td:first', ta).addClass('ma').empty().append(div).click(function(){ts.toggle("slow");});
            $('td:eq(1)', ta).addClass('link').click(function(){ts.toggle("slow");});
            $('img.small', ts).click(function(){$('img:last', this.parentNode).attr('src', this.src);});
            $('.tipclose img', ts).click(function(){ts.hide('slow')});
        });
        $('.btnsmallP').mouseover(function(){
            showTooltip(this, "<p><b>" + ohlang.avvisoRichiesta + "</b></p>", 300)
        });
    });
}
