﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="jquery-vsdoc.js" />

var addthis_pub = "deltaq";

$().ready(function () {
    if (self.location.href.indexOf("cmspagemode=edit") > -1 || self.location.href.indexOf("cmspagemode=preview") > -1) {
        return;
    }

    searchBoxInitialize();
});

function doSearch() {
    var jSearchQueryTextBox = $("#" + $searchBoxSearchQueryTextBoxClientID);
    var searchQuery = jSearchQueryTextBox.val();
    var watermarkText = jSearchQueryTextBox.attr("WatermarkText");

    if (searchQuery.length == 0 || searchQuery == watermarkText) {
        //alert("Søgeforespørgslen skal have en længde på mindst 2 tegn.");

        blink(jSearchQueryTextBox, true);

        return false;
    }

    top.location.href = $searchResultsPageUrl + "?SearchQuery=" + encodeURI(searchQuery);
}

function searchBoxInitialize() {
    var jSearchQueryTextBox = $("#" + $searchBoxSearchQueryTextBoxClientID);

    // Attach onKeyDown event to search textBox
    jSearchQueryTextBox.keydown(function (event) {
        if (event.keyCode == 13) {
            doSearch();
            return false;
        }
    });

    var searchQuery = jSearchQueryTextBox.val();

    if (searchQuery == "") {
        var watermarkText = jSearchQueryTextBox.attr("WatermarkText");
        jSearchQueryTextBox.val(watermarkText);
    }

    jSearchQueryTextBox.focus(function () {
        var jtb = $(this);
        if (jtb.val() == jtb.attr("WatermarkText")) {
            jtb.val("");
        }
    });

    jSearchQueryTextBox.blur(function () {
        var jtb = $(this);
        if (jtb.val() == "") {
            jtb.val(jtb.attr("WatermarkText"));
        }
    });
}

function blink(control, doFocus) {
    control.fadeOut(75, function () {
        control.fadeIn(75, function () {
            control.fadeOut(75, function () {
                control.fadeIn(75, function () {
                    if (doFocus) {
                        control.focus();
                    }
                });
            });
        });
    });
}

function eml(u, d) {
    top.location.href = "mailto:" + u + "@" + d;
}


function popup(url, name, width, height, resize) {
    width = width > 0 ? width : 400;
    height = height > 0 ? height : 500;

    var t = (screen.height - height) / 2;
    var l = (screen.width - width) / 2;

    window.open(url, name, "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=" + resize + ",width=" + width + ",height=" + height + ",screenX=0,screenY=0,top=" + t + ",left=" + l);
    return false;
}

var map;

function mapIt(hlId, name, lat, lng) {
    if (GBrowserIsCompatible()) {

        lat = lat.replace(",", ".");
        lng = lng.replace(",", ".");

        var point = new GLatLng(parseFloat(lat), parseFloat(lng));

        if (map == null) {
            map = new GMap2(document.getElementById("gmap"), { size: new GSize(370 , 335) });
            map.setCenter(point, 13);

            var mapTypeControl = new GMapTypeControl();
            var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10));
            var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10));
            map.addControl(mapTypeControl, topRight);
            map.addControl(new GLargeMapControl3D());
        }


        map.addOverlay(new GMarker(point));
        //        map.openInfoWindow(map.getCenter(),
        //                   document.createTextNode(name));

        map.panTo(point);
    }
}
