

    /* interface */
    function hideGmapPopup() {
        $hide("gmap_help_popup");
        Cookies.set("gmap_help", "hidden");
    }
    
        function searchRoomQonclick(){
            if($("search_room_q").value =='Search here ...'){
                $("search_room_q").value = '';
                $("search_room_q").className = 'q';
            }
        }
        function onSearchStringLoad(){
            if($("search_room_q").value =='Search here ...' || isEmpty($("search_room_q").value)){
                $("search_room_q").className = 'qs';
                $("search_room_q").value ='Search here ...';
            }
        }
        
        function hideSearch(){
            if(isEmpty($("search_room_q").value)){
                $("search_room_q").value = 'Search here ...';
                    $("search_room_q").className = 'qs';
            }
        }
        
    /* Cookies */

    Cookies = {
        get: function(name) {
            var cookie = "" + document.cookie;
            var search = "" + name + "=";
            var setStr = null;
            var offset = 0;
            var end = 0;
            if (cookie.length > 0) {
                offset = cookie.indexOf(search);
                if (offset != -1) {
                    offset += search.length;
                    end = cookie.indexOf(";", offset);
                    if (end == -1) {
                        end = cookie.length;
                    }
                    setStr = unescape(cookie.substring(offset, end));
                }
            }
            return(setStr);
        },

        set: function(name, value, sessionOnly) {
            if(sessionOnly) {
                var expstr = "";                
            } else {
                var expdate = new Date();
                expdate.setTime(expdate.getTime() + 31536000000); // 1 year
                var expstr = "; expires=" + expdate.toGMTString();
            }
            var cookieValue = name + "=" + escape(value) + expstr;
            document.cookie = cookieValue;
        },


        del: function(name) {
            document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT;";
        }
    }

      


    // Home page info

    HomeData = {
         
            
    
        clearCart: function(){
            var r = {
                action: 'clear_sc',
                dialog: 'booking'
            }
            this.req_obj = new AJAX_Request({url: "/", params: r, callback: this.onClearCartResponce});
        },

        onClearCartResponce: function() {
            if(window.is_shopping_cart_page) {
                location.href = location.href;
            } else {
                HomeData.updateCartCountShow();
            }
        },
            
        updateCartCountShow: function(){
            var r = {
                action: 'get_cart_count',
                dialog: 'booking'
            }
            this.req_obj = new AJAX_Request({url: "/", params: r, callback: this.onUpdateCartCountShow});
        },
        
        onUpdateCartCountShow: function(res){
            if(res && res.length){
                $("scart_total").innerHTML = res.length;

                var totalSC = 0;
                for(var i=0; i<res.length;i++){
                    totalSC += res[i].amount;
                }
                $("scart_amount_checkout").innerHTML = totalSC;
                $("scart_total_checkout").innerHTML = res.length+' Item'+(res.length>1 ? 's' : '');
                if(!window.is_shopping_cart_page) {
                    $("checkout_box").style.display = "";
                }
            }else{
                $("scart_total").innerHTML = 0;
                $("checkout_box").style.display = "none";
            }
        },

        data: {},

        setValue: function(key, value) {
            if(this.data[key] == value) return;
            this.data[key] = value;
        },

        getValue: function(key) {
            return this.data[key] || "";
        },

        delValue: function(key) {
            this.data[key] = undefined;
        },

        load: function() {
            this.updateCartCountShow();
            var hd = Cookies.get("_hd");
            if(hd) {
                hd = hd.split("-");
                this.data.hd_year = hd[0];
                this.data.hd_month = hd[1];
            }

            var loc = Cookies.get("_loc");
            if(loc) {
                loc = loc.split("-");
                this.data.country = loc[0];
                this.data.state = loc[1];
                this.data.city = loc[2];
            }

            this.data.find_target = Cookies.get("_ft");

            this.data.find_motel = Cookies.get("_fm");
            this.data.find_location = Cookies.get("_fl");

            this.data.trip_start = Cookies.get("_ts");
            this.data.trip_end = Cookies.get("_te");

            this.data.tab = Cookies.get("_tab");

            this.data.map_target = Cookies.get("_mt");
            var mc = Cookies.get("_mc");
            if(mc) {
                mc = mc.split(",");
                this.data.map_lat = mc[0];
                this.data.map_lng = mc[1];
                this.data.map_zoom = mc[2];
            }

        },

        save: function() {
            if(this.data["hd_year"] || this.data["hd_month"]) {
                Cookies.set("_hd", this.getValue("hd_year") + "-" + this.getValue("hd_month"), true);
            } else {
                Cookies.del("_hd");
            }

            Cookies.set("_tab", this.getValue("tab"), true);

            Cookies.set("_ft", this.getValue("find_target"), true);
            Cookies.set("_fm", this.getValue("find_motel"), true);
            Cookies.set("_fl", this.getValue("find_location"), true);

            Cookies.set("_ts", this.getValue("trip_start"), true);
            Cookies.set("_te", this.getValue("trip_end"), true);
            Cookies.set("_loc", this.getValue("country") + "-" + this.getValue("state") + "-" + this.getValue("city"), true);

            var mt = this.getValue("map_target");
            if(mt) {
                Cookies.set("_mt", this.getValue("map_target"), true);
                var mc = 
                    this.getValue("map_lat") + "," +
                    this.getValue("map_lng") + "," +
                    this.getValue("map_zoom");
                Cookies.set("_mc", mc, true);
//                alert(mc);
            }

        }
    }
    HomeData.load();




    /* Top Menu */


    TopMenuHandler = {
        activeSubmenu: null,
        hideSubmenuTimer: null,
        fxSubmenuTimer: null,
        submenuFxPos: 0,


        onTabMouseOver: function(tabIdx) {
            clearTimeout(TopMenuHandler.hideSubmenuTimer);
            if(TopMenuHandler.activeSubmenu != tabIdx) {
                TopMenuHandler.hideSubmenu();
                TopMenuHandler.showSubmenu(tabIdx);
            }
            return true;
        },


        onTabMouseOut: function(e, el) {
            e = e || window.event;
            if(!e) return;
            var target = e.relatedTarget || e.toElement || e.fromElement;
            if(isChildElement(target, el)) return true;
            TopMenuHandler.hideSubmenuTimer = setTimeout(TopMenuHandler.hideSubmenu, 50);
        },


        onSubmenuMouseOver: function() {
            clearTimeout(TopMenuHandler.hideSubmenuTimer);
            return true;
        },

        onSubmenuMouseOut: function() {
            TopMenuHandler.hideSubmenuTimer = setTimeout(TopMenuHandler.hideSubmenu, 500);
        },



        processSubmenuFx: function() {
            var el = $("top_menu_popup_"+TopMenuHandler.activeSubmenu);
            if(!el) return;
            if(TopMenuHandler.submenuFxPos < 5) {
                TopMenuHandler.submenuFxPos ++;
                var es = el.style;
                es.opacity = TopMenuHandler.submenuFxPos / 5;
                es.filter = 'alpha(opacity=' + TopMenuHandler.submenuFxPos * 20 + ')';
                TopMenuHandler.fxSubmenuTimer = setTimeout(TopMenuHandler.processSubmenuFx, 45);
            }
        },


        showSubmenu: function(n) {
            var el = $("top_menu_popup_"+n);
            if(!el) return;
            var pos = getElPos($("top_menu_tab_"+n));
            with(el.style) {
                left = pos.left - 3 + "px";
                top = pos.top + $("top_menu_tab_"+n).offsetHeight - 1 + "px";
                zIndex = 10000;
            }
            el.style.display = "block";
            TopMenuHandler.activeSubmenu = n;

            TopMenuHandler.submenuFxPos = 0;
            TopMenuHandler.processSubmenuFx();
        },


        hideSubmenu: function() {
            if(TopMenuHandler.activeSubmenu == null) return;
            $("top_menu_popup_"+TopMenuHandler.activeSubmenu).style.display = "none";   
            TopMenuHandler.activeSubmenu = null;
            clearTimeout(TopMenuHandler.fxSubmenuTimer);
        }
    }