$(document).ready(function() {
    $(".map_form").hide();
    $(".nav li").each(function(index) {
        $(this).click(function() {
            $(".nav li").removeClass("tab_active");
            $(this).addClass("tab_active");
            $(".main").children().hide();
            $(".main").children().eq(index).show()
        });
    });

    $("#tabMap").click(function() {
        if (map == null) {
            mapsLoaded();
        }
    });

    $("#queryBtn").click(function() {
        searchHotel();
    });
    $(".query_search .list_form h5").click(function() {
        $(".query_search .other").toggle();
    })
});

function hotelJoin() {
    $.post(_contextpath + "/hotel/hotelJoin.action?time=" + new Date().getTime(), function(data) {
        $.facebox(data);
    });
}


function mapsLoaded() {

    /*自定义类*/
    function KMarker(latlng, tip, markerContent, clickParamer)
    {
        this._latlng = latlng;
        this._tip = tip;
        this._markerContent = markerContent;
        this._clickParamer = clickParamer;
    }
    KMarker.prototype = new GOverlay();
    KMarker.prototype.initialize = function(map) {
        var markerHtml = document.createElement('div');
        markerHtml.innerHTML = this._markerContent;
        markerHtml.style.position = "absolute";
        markerHtml.title = this._tip;
        map.getPane(G_MAP_MARKER_PANE).appendChild(markerHtml);
        var _this = this;
        markerHtml.onclick = function() {
            GetCity(_this);
        }
        this._markerHtml = markerHtml;
        this._map = map;
    };
    KMarker.prototype.remove = function() {
        this._markerHtml.parentNode.removeChild(this._markerHtml);
    };
    KMarker.prototype.copy = function() {
        return new (this._latlng,this._tip,this._markerContent,this._clickParamer);
    };
    KMarker.prototype.redraw = function(force) {
        if (force)
        {
            var p = this._map.fromLatLngToDivPixel(this._latlng);
            this._markerHtml.style.left = (p.x) + "px";
            this._markerHtml.style.top = (p.y) - 25 + "px";
        }
    };
    function GetCity(marker)
    {
        getCityName(marker._clickParamer[0], marker._clickParamer[1], marker._clickParamer[2]);
    }
    map = new google.maps.Map2(document.getElementById("map_search"));

    map.setCenter(new GLatLng(32.22395859822874, 111.47857666015625), 4);
    var temp = $("#markerTemp").html();
    var myMarker = new Array();
    myMarker[0] = new KMarker(new GLatLng(31.222, 121.420), "点击进入上海", temp.replace("_CITYNAME_", "上海"), ["上海", "Shanghai", "CNT3N60"]);
    myMarker[1] = new KMarker(new GLatLng(30.56226, 114.389), "点击进入武汉", temp.replace("_CITYNAME_", "武汉"), ["武汉","Wuhan", "CNSHN20"]);
    myMarker[2] = new KMarker(new GLatLng(29.535, 106.5454), "点击进入重庆", temp.replace("_CITYNAME_", "重庆"), ["重庆","Chongqing", "CNRVMW0"]);
    map.addOverlay(myMarker[0]);
    map.addOverlay(myMarker[1]);
    map.addOverlay(myMarker[2]);
}

function queryHotelInfo(hotelPassport, hotelCategoryName, hotelInfoTab) {
    var cityName = $('#cityName').val();
    var cityEnuName = $('#cityEnuName').val();
    var countryCode = $('#countryCode').val();
    var cityCode = $('#cityCode').val();


    $('#checkinDate').val($('#checkinDateSubmited').val());
    $('#checkoutDate').val($('#checkoutDateSubmited').val());
    $('#roomQuantity').val($('#roomQuantitySubmited').val());
    $('#adultCount').val($('#adultCountSubmited').val());
    $('#childrenCount').val($('#childrenCountSubmited').val());
    $('#hotelPassport').val(hotelPassport);
    $('#hotelCategoryName').val(hotelCategoryName);
    $('#hotelInfoTab').val(hotelInfoTab || "");
    if ($('#hotelPassport').length > 0) {
        $('#cf').attr("action", _contextpath + "/hotel/queryRoomRate.action");
    } else {
        $('#cf').attr("action", _contextpath + "/hotel/queryRoomRate.action?hotelPassport=" + hotelPassport);
    }

    $('#cf').attr('target', '_blank');

    $('#cityName').val("");
    $('#cityEnuName').val("");
    $('#countryCode').val("");

    $('#cf').submit();

    $('#cityName').val(cityName);
    $('#cityEnuName').val(cityEnuName);
    $('#countryCode').val(countryCode);
    $('#cityCode').val(cityCode);
}