﻿var hotelinfo;
var map = null;
var nearbyhotels = null;
var iframeloaded = false;

function HideTabs()
{
    $("tcPicture").style.display = "none";
    $("tcMap").style.display = "none";
    $("tcWeather").style.display = "none";
    $("tcGallery").style.display = "none";
}

function AddToWatchlistHotelDetails(link) {
    WatchlistAddItem(link);
    DisplayWatchlistLinkHotelDetails();
}

function RemoveFromWatchlistHotelDetails(link) {
    WatchlistRemoveItem(link);
    DisplayWatchlistLinkHotelDetails();
}

function DisplayWatchlistLinkHotelDetails() {
    var link = "Add to watchlist";
    var linkremove = "Remove from watchlist";
    if (clang == "de") {
        link = "Hotel merken";
        linkremove = "Hotel aus Merkliste entfernen";
    }

    if (WatchlistContainsItem(hotelinfo["link"])) {
        $("HotelDetails_WatchlistActions").innerHTML = "<a onclick=\"RemoveFromWatchlistHotelDetails('" + hotelinfo["link"] + "')\">" + linkremove + "</a>";
    } else {
        $("HotelDetails_WatchlistActions").innerHTML = "<a onclick=\"AddToWatchlistHotelDetails('" + hotelinfo["link"] + "')\">" + link + "</a>";
    }
}

function DisplayPicture()
{
    HideTabs();
    $("tcPicture").style.display = "block";
    
}

function DisplayMap()
{
    HideTabs();
    $("tcMap").style.display = "block";
    if(map == null) {

        $("tcMap").style.width = "100%";
        map = new VEMap("tcMap");
        map.LoadMap();
        var latlon = new VELatLong(hotelinfo["latitude"], hotelinfo["longitude"]); 
        map.LoadMap(latlon, 15, "r", 0, VEMapMode.Mode2D, 1);

        for (var x = 0; x < nearbyhotels.size(); x++) {
            if (nearbyhotels[x]["rowid"] == hotelinfo["rowid"] || nearbyhotels[x]["hotelname"] == hotelinfo["hotelname"])
                continue;
                
            latlon = new VELatLong(nearbyhotels[x]["latitude"], nearbyhotels[x]["longitude"]);

            var shape = new VEShape(VEShapeType.Pushpin, latlon);
            shape.SetCustomIcon("<img width=\"20\" height=\"20\" src='/imgs/mapstar.png'></img>");
            shape.SetTitle("<a href=\"" + nearbyhotels[x]["hotelurl"] + "\">" + nearbyhotels[x]["hotelname"] + "</a>");

            var thumbnail = "";
            if (nearbyhotels[x]["thumbnail"]) {
                thumbnail = "<img src=\"" + nearbyhotels[x]["thumbnail"] + "\"></img><br />"; 
            }
            
            shape.SetDescription(thumbnail + "<div>" + nearbyhotels[x]["address"] + "<br /><img style=\"margin-top: 10px;\" src=\"" + nearbyhotels[x]["partnerlogourl"] + "\"></img></div>");
            map.AddShape(shape);
        }

        var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
        shape.SetCustomIcon("<img src='/imgs/mapstar.png'></img>");
        shape.SetTitle(hotelinfo["hotelname"]);
        shape.SetDescription("<img src=\"" + hotelinfo["imageurl"] + "\" ></img><br />" + hotelinfo["address"] + "<br /><img style=\"margin-top: 10px;\" src=\"" + hotelinfo["partnerlogourl"] + "\"></img>");
        map.AddShape(shape);
    }
}

function DisplayGallery()
{
    HideTabs();
    $("tcGallery").style.display = "block";        
}

function DisplayWeather()
{
    HideTabs();
    $("tcWeather").style.display = "block";
    if(!iframeloaded)
    {
        iframeloaded = true;
        $("tcWeatherIFrame").src = "http://www.wetterclub.com/WeatherDetailShower.aspx?width=750&height=290&lat=" + hotelinfo["latitude"] + "&lon=" + hotelinfo["longitude"] + "&zoom=10&title=" + escape(hotelinfo["hotelname"]) + "&description=" + escape(hotelinfo["address"]);
    }
}

function DisplayBookingconditions()
{

}

function ShowImage(url)
{
    window.open(url);

}

function HideWatchlist() 
{
    watchlist.style.display = 'none';
}