﻿/*var Data = null;
$(document).ready(function() {
    $.getJSON('BoligEkstra/KTPAutoComplete.aspx.aspx', function(data) {
        alert(data);
        Data = data.Afdelinger;

        $("#SearchTxt").focus().autocomplete(Data, {
            selectFirst: true,
            autoFill: true,
            formatItem: function(item) {
                alert(item);
                return item;
            }
        });
    });
});
*/
                         


jQuery.fn.toggleText = function(a, b) {
    return this.each(function() {
        jQuery(this).text(jQuery(this).text() == a ? b : a);
    });
};
function GetAfdelingsText() {

    $("#AfdelingTab").addClass("selected");
    $("#VarmeMesterTab").removeClass("selected");
    $("#BestyrelsesTab").removeClass("selected");
    $("#FilarkivTab").removeClass("selected");
    $("#Afdelings_Varmemestre").css({ "display": "none" });
    $("#Afdelings_Bestyrelse").css({ "display": "none" });
    $("#Afdelings_Beskrivelse").css({ "display": "block" });
    $("#Afdelings_Filarkiv").css({ "display": "none" });
}
function GetAfdelingsVarmeMestre() {

    $("#AfdelingTab").removeClass("selected");
    $("#VarmeMesterTab").addClass("selected");
    $("#BestyrelsesTab").removeClass("selected");
    $("#FilarkivTab").removeClass("selected");
    $("#Afdelings_Beskrivelse").css({ "display": "none" });
    $("#Afdelings_Bestyrelse").css({ "display": "none" });
    $("#Afdelings_Varmemestre").css({ "display": "block" });
    $("#Afdelings_Filarkiv").css({ "display": "none" });
}
function GetAfdelingsBestyrelse() {

    $("#AfdelingTab").removeClass("selected");
    $("#VarmeMesterTab").removeClass("selected");
    $("#BestyrelsesTab").addClass("selected");
    $("#FilarkivTab").removeClass("selected");
    $("#Afdelings_Varmemestre").css({ "display": "none" });
    $("#Afdelings_Beskrivelse").css({ "display": "none" });
    $("#Afdelings_Bestyrelse").css({ "display": "block" });
    $("#Afdelings_Filarkiv").css({ "display": "none" });
}
function GetAfdelingsFilarkiv() {

    $("#AfdelingTab").removeClass("selected");
    $("#VarmeMesterTab").removeClass("selected");
    $("#BestyrelsesTab").removeClass("selected");
    $("#FilarkivTab").addClass("selected");
    $("#Afdelings_Varmemestre").css({ "display": "none" });
    $("#Afdelings_Beskrivelse").css({ "display": "none" });
    $("#Afdelings_Bestyrelse").css({ "display": "none" });
    $("#Afdelings_Filarkiv").css({ "display": "block" });
}
function OpenPano(link) {

    var winWidth = parent.document.documentElement.clientWidth;
    var winHeight = parent.document.documentElement.clientHeight;
    window.open('http://www.boligsilkeborg.dk/' + link, '_blank', 'status=yes,resizable=yes,top=0,left=0,width=' + winWidth + ',height=' + winHeight + '');
    /*window.open('../' + link, '_blank', 'status=yes,resizable=yes,top=0,left=0,width=' + winWidth + ',height=' + winHeight + '');*/
}
function CreateTheme(id, src, title, address, zip, city, xPos, yPos, theme) {
    var poiDom = document.createElement('img');
    poiDom.id = id;
    poiDom.src = src;
    poiDom.desc = createCallOutContentTheme(title, address, zip, city);
    poiDom.popupWidth = 250;
    poiDom.popupHeight = 100;

    poiDom.onclick = poiThemeClick;
    poiDom.style.cursor = 'hand';

    // Add point to map using the API
    var x = Number(xPos.replace(',', '.'));
    var y = Number(yPos.replace(',', '.'));
    var coord = new KrakMap.Coordinate(x, y);
    var poi = new KrakMap.Poi(poiDom, coord, theme, 20, 20); // size of gif is 20 pixels square
    tc.addPoi(poi);
}
function createCallOutContentTheme(title, address, zip, city) {

    var html = '<table class="PopUpHeader" width="250" border="0" cellspacing="0" cellpadding="0">';
    html += '<tr>';
    html += '<td width="10" height="30">&nbsp;</td>'
    html += '<td width="204" height="30" class="PopUpHeader">' + title + '</td>';
    html += '<td width="17" height="30"><a class="PopUpClose" onclick="removePopup()">Luk</a></td>';
    html += '<td width="10" height="30">&nbsp;</td>'
    html += '</tr>';
    html += '<tr>';
    html += '<td height="8"></td>';
    html += '<td height="8" colspan="2" valign="top"></td>';
    html += '<td height="8"></td>';
    html += '</tr>';
    html += '<tr>';
    html += '<td width="10" height="160">&nbsp;</td>';
    html += '<td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="10">';
    html += '<tr>';
    html += '<td width="51%" valign="top"><span class="PopUpTxt"><strong>Adresse</strong><br />';
    html += address + '<br />';
    html += zip + ' ' + city + '</td>';
    html += '</tr>';
    html += '</table></td>';
    html += '<td width="10">&nbsp;</td>';
    html += '</tr>';
    html += '</table>';

    return (html);
}
function poiThemeClick(evt) {
    // Handle the non-standard IE event model ...
    var target = (evt && evt.target) ? evt.target : window.event.srcElement;

    // Only show one popup at a time
    removePopup();

    // Width and height must be > 0
    var popupWidth = Math.max(0, this.popupWidth);
    var popupHeight = Math.max(0, this.popupHeight);

    var left = Number(target.style.left.replace('px', '')) + 26;
    var top = Number(target.style.top.replace('px', ''));
    // These are needed because the POI layer doesn't have the
    // same origin as the map layer.
    var deltaX = Number(tc.getMousePosition().x - left);
    var deltaY = Number(tc.getMousePosition().y - top);

    // Create the popup div tag
    var popdiv = document.createElement('div');
    popdiv.id = 'pUp';

    // Auto-resize if height is zero
    if (popupHeight > 0) {
        popdiv.style.height = popupHeight + 'px';
        popdiv.style.width = popupWidth + 'px';
    }
    else {
        popdiv.style.width = popupWidth + 'px';
    }

    popdiv.style.left = (window.event.clientX + document.documentElement.scrollLeft) + 'px';
    popdiv.style.top = (window.event.clientY + document.documentElement.scrollTop) + 'px';

    //popdiv.innerHTML += '<p>' + this.desc + '</p>';
    popdiv.innerHTML += this.desc;
    // Launch the popup, close it by clicking on the close image
    document.body.appendChild(popdiv);
    popdiv.focus();
}
function removePopup() {
    $('#pUp').remove();
    $('#pUpRids').remove();
}

$(document).ready(function() {
    $("#SearchTop").focus(function() {
        $(this).filter(function() {
        return $(this).val() == "" || $(this).val() == "Skriv en adresse"
        }).removeClass("watermarkOn").val("");
    });

    $("#SearchTop").blur(function() {
        $(this).filter(function() {
            return $(this).val() == ""
        }).addClass("watermarkOn").val("Skriv en adresse");
    });

    $("#SearchTxt").focus(function() {
        $(this).filter(function() {
            return $(this).val() == "" || $(this).val() == "Skriv en adresse"
        }).removeClass("watermarkOn").val("");
    });

    $("#SearchTxt").blur(function() {
        $(this).filter(function() {
            return $(this).val() == ""
        }).addClass("watermarkOn").val("Skriv en adresse");
    });
});

