/// <reference path="Live.js" />
var locationResults = new Array();
var shapesLayer = null;
var collectionsLayer = null;
var searchLocationOnlyTerm = "";
var qParameterTerm = "";
var detailLayerFocus = false;
/**/
var speedCamerasLayer = null;
var gasStationLayer = null;

var axPage = new Object();
/* modalpopup */
var modalPopupopened = false;
var lastZoomLevel = null;
var businessID = "";

axPage.SetStartParameters = function(url) {
    /// <summary>Set URL parameters </summary>
    if (url.length == 0 || url.indexOf("?") == -1) {
        axMap.LoadDefaultMap();
    }
    else {
        var decodedUrl = url;
        try {
            decodedUrl = unescape(decodeURIComponent(url));
        }
        catch (e) {
            decodedUrl = unescape(url);
        }
        var q = axPage.GetParameter("q", decodedUrl);
        if (q == "") {
            q = axPage.GetParameter("Q", decodedUrl);
            if (q == "") {
                axPage.ParseParameters(decodedUrl);
            }
            else {
                axMap.LoadDefaultMap();
                axPage.SetQParameter(q);
            }
        }
        else {
            axMap.LoadDefaultMap();
            axPage.SetQParameter(q);
        }
    }
}
axPage.SetQParameter = function(q) {
    /// <summary>Sets q-parameter (business or location search must be performed) </summary>
    var containsQ = false;
    var index = q.indexOf("+");
    containsQ = index > 0;
    qParameterTerm = q;
    while (q.indexOf("+") > -1) {
        q = q.replace("+", " ");
    }
    searchLocationOnlyTerm = q;
    axSearch.ShowTaskProgress();
    if (containsQ) {
        $get("header_taskBar_what").value = qParameterTerm.substring(0, index);
        $get("header_taskBar_where").value = qParameterTerm.substring(index + 1, searchLocationOnlyTerm.length);
        $get("header_taskBar_what").className = "";
        CallPageMethod("SearchLocation", { "locationWhere": q }, axSearch.OnQParameterSearch, axSearch.OnQParameterSearchError);
    }
    else
        CallPageMethod("SearchLocation", { "locationWhere": q }, axSearch.OnSearchLocationOnly);
}
axPage.ParseParameters = function(decodedUrl) {
    /// <summary>Parses URL parameters </summary>
    var a = axPage.GetParameter("cp", decodedUrl);
    var d = axPage.GetParameter("rtp", decodedUrl);
    var s = axPage.GetParameter("rtop", decodedUrl);
    var dir = axPage.GetParameter("dir", decodedUrl);
    var tilt = axPage.GetParameter("tilt", decodedUrl);
    var alt = axPage.GetParameter("alt", decodedUrl);

    // Check if map is in 3D mode
    var ThreeDMode = false;
    if (dir != "" && tilt != "" && alt != "") {
        if (dir != 0 || tilt != -90 || alt != -1000) {
            ThreeDMode = true;
        }
    }
    if (a != "") {
        a = a.replace(/,/g, ".");

        var _d;
        if (a.indexOf("~") > -1) {
            _d = a.split("~");
        }
        else {
            _d = a.split("|");
        }

        var e = new VELatLong(_d[0], _d[1]);
        if (e == "" || e == null || e == 'undefined') {
            // Set 3D mode if parameters dir, tilt or alt is set
            if (ThreeDMode == true) {
                // Do not set zoom(lvl)
                map.LoadMap(new VELatLong(50.6, 10), null, VEMapStyle.Shaded, false);
                map.SetMapMode(VEMapMode.Mode3D);
                map.SetAltitude(alt);
                map.SetPitch(tilt);
                map.SetHeading(dir);
            }
            else {
                axMap.LoadDefaultMap();
            }
        }
        else {
            var b = axPage.GetParameter("style", decodedUrl);
            var c = axPage.GetParameter("lvl", decodedUrl);
            var l = axPage.GetParameter("scene", decodedUrl);

            // Set 3D mode if parameters dir, tilt or alt is set
            if (ThreeDMode == true) {
                // Do not set zoom(lvl)
                map.LoadMap(e, null, b, null, VEMapMode.Mode3D, null, null);
                map.SetAltitude(alt);
                map.SetHeading(dir);
                map.SetPitch(tilt);

            }
            else {

                // TODO: Temporary solution! for back parameter, change back when NL business service is fixed
                //                map.LoadMap(e, c, b, null, VEMapMode.Mode2D, null, null);

                var where = axPage.GetParameter("where", decodedUrl)
                if (where == "" || where == null || where == 'undefined') {
                    map.LoadMap(e, c, b, null, VEMapMode.Mode2D, null, null);
                    var shape = new VEShape(VEShapeType.Pushpin, e);
                    shape.SetCustomIcon(imagesPath + "poi_precise_location.gif");
                    map.AddShape(shape);


                }
                else {

                    var what = axPage.GetParameter("ss", decodedUrl);

                    searchIsOver = false;
                    axSearch.ShowSearchProgress();
                    axPage.ChangeTaskBarByName("Biz");
                    axMap.LoadDefaultMap();
                    $get("search_latLongField").value = e.Latitude + ";" + e.Longitude;
                    $get("search__searchWhere").value = where;
                    $get("search__searchWhat").value = what;
                    $get("search_btnHidden").click();
                    searchBusinesses = true;
                    searchBusinessesBestMapView = true;
                }
            }

            if (l != "" && (b == "o" || b == "b")) {
                map.SetBirdseyeScene(l);
            }

            var f = axPage.GetParameter("ss", decodedUrl);
            if (f != null && f != "") {
                searchIsOver = false;
                axSearch.ShowSearchProgress();
                $get("search_latLongField").value = e.Latitude + ";" + e.Longitude;
                $get("search__searchWhat").value = f;
                $get("search_btnHidden").click();
                searchBusinesses = true;
                searchBusinessesBestMapView = true;
            }
        }
    }
    else {
        map = new VEMap('msve_mapContainer');
        axMap.LoadDefaultMap();
    }
    if (d != null && d != "") {
        var r = d.split("~");
        var doSearch = false;
        if (r[0] != 0) {
            r[0] = r[0].replace(/\+/g, " ");
            var i = r[0].indexOf(".");
            var i2 = unescape(r[0].substring(i + 1, r[0].length));
            var _i = i2.split("_");

            if (_i.length == 5) {
                $get("TaskHost_Directions_StartLatLong").value = _i[0] + "~" + _i[1];
                $get("TaskHost_Directions_StartAddress").value = _i[2];
                $get("direction_TaskHost_Directions_from").value = _i[2];
                $get("direction_TaskHost_Directions_from").className = "";
                doSearch = true;
            }
            else {
                $get("direction_TaskHost_Directions_from").value = r[0];
                $get("direction_TaskHost_Directions_from").className = "";
                doSearch = true;
            }
        }

        if (r[1] != 0) {
            r[1] = r[1].replace(/\+/g, " ");
            var j = r[1].indexOf(".");
            var j2 = unescape(r[1].substring(j + 1, r[1].length));
            var _j = j2.split("_");

            if (_j.length == 5) {
                $get("TaskHost_Directions_EndLatLong").value = _j[0] + "~" + _j[1];
                $get("TaskHost_Directions_EndAddress").value = _j[2];
                $get("direction_TaskHost_Directions_to").value = _j[2];
                $get("direction_TaskHost_Directions_to").className = "";
                doSearch = true;
            }
            else {
                $get("direction_TaskHost_Directions_to").value = r[0];
                $get("direction_TaskHost_Directions_to").className = "";
                doSearch = true;
            }
        }
        if (s != null && s != "") {
            if (s.indexOf("1") > -1) {
                //$get("TaskHost_Directions_Shortest").checked = true;
                $get("direction_routeOptions_1").checked = true;
            }
            else if (s.indexOf("2") > -1) {
                //$get("TaskHost_Directions_Walking").checked = true;
                $get("direction_routeOptions_2").checked = true;
            }
        }

        axRoute.ShowDirectionsPanel();
        if (doSearch = true) {
            axRoute.GetRoute();
        }
    }
    else {
        var cid = axPage.GetParameter("cid", decodedUrl);
        var mapurl = axPage.GetParameter("mapurl", decodedUrl);
        var explore = axPage.GetParameter("explore", decodedUrl);
        if (cid != "") {
            axCollection.DisplayCollections(cid, VEDataType.VECollection);
        }
        if (mapurl != "") {
            axCollection.DisplayCollections(mapurl, VEDataType.ImportXML);
        }
        if (explore != "") {
            if (b == "o" || b == "b") {
                exploreColParameterSet = true;
            }

            ExploreCollections('relevance', this);
        }

        var b_id = axPage.GetParameter("bsid", decodedUrl);
        if (b_id != "") {
            businessID = b_id; // parameter for print page
            searchIsOver = false;
            axSearch.ShowSearchProgress();
            $get("search_business_searchid").value = b_id;
            $get("search_btnHidden").click();
        }
    }
}
axPage.GetParameter = function(name, url) {
    /// <summary> Parses given parameters from the igven URL </summary>
    /// <returns> Specified parameter value </returns>
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var _15 = "[\\?&]" + name + "=([^&#]*)";
    var _16 = new RegExp(_15);
    var _17 = _16.exec(url);
    if (_17 == null) {
        return "";
    }
    else { return _17[1]; }
}
axPage.CloseTaskArea = function() {
    axRoute.RemoveDirections();
    var t = document.getElementById("msve_taskArea");
    var m = document.getElementById("msve_mapArea");
    var r = document.getElementById("msve_mapResizer");
    t.style.display = "none";
    r.style.display = "none";
    m.style.marginLeft = "0pt";
    axSearch.ShowMessage("");
    if (isCustomResize) {
        ResizeMap();
    }
    else {
        axPage.ResizeMap();
    }
    searchBusinesses = false;
    exlopereCollections = false;
    searchBusinessesBestMapView = true;
    if (collectionsLayer != null) {
        collectionsLayer.DeleteAllShapes();
    }
    var ss = $get("search__searchWhat");
    if (ss != null) {
        ss.value = "";
    }
    $get("collections_body").innerHTML = "";
}
axPage.ShowWelcomePane = function() {
    axSearch.ShowTaskArea();

    axSearch.ShowTaskHostLayer("welcome");
    exlopereCollections = false;
    searchBusinesses = false; 
    searchBusinessesBestMapView = true;

    axSearch.ShowMessage(L_WELCOME_TEXT);
    if (isCustomResize) {
        ResizeMap();
    }
    else {
        axPage.ResizeMap();
    }
    axRoute.RemoveDirections();
}
axPage.GetElementTopPositionByID = function(a) {
    return axPage.GetElementTopPosition($ID(a))
}

axPage.GetElementTopPosition = function(d, c) {
    var a = d, b = 0;
    while (a && a != c) {
        b += a.offsetTop;
        a = a.offsetParent
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.topMargin != "undefined")
        b += document.body.topMargin;
    return b;
}
axPage.GetElementLeftPositionByID = function(a) {
    return axPage.GetElementLeftPosition($ID(a))
}
axPage.GetElementLeftPosition = function(d, c) {
    var a = d, b = 0;
    while (a && a != c) {
        b += a.offsetLeft;
        a = a.offsetParent
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
        b += document.body.leftMargin;
    return b;
}
axPage.ShowSendToDropDown = function(b, id) {
    var sendtodropdown = document.getElementById(id);
    if (b == true)
        sendtodropdown.style.display = "block";
    else
        sendtodropdown.style.display = "none";
}
axPage.OpenPrintWindow = function() {
    var parameters = "";
    var s = new String(map.GetCenter());
    parameters += "?b=" + map.GetMapStyle();
    parameters += "&z=" + map.GetZoomLevel(); // zoom
    parameters += "&cp=" + s.replace(", ", ","); // latlong

    // Check if route is present: pf - checkRoute(), pb - ShowNormalMap()
    var r = $get("TaskHost_Directions_RouteGenerated").value;
    if (r == "false") {

        parameters += "&pt=pb&bsid=" + businessID;
    }
    else {
        parameters += "&pt=pf";
        //var taskDirStart = encodeURIComponent($get("TaskHost_Directions_StartAddress").value);
        //var taskDirEnd = encodeURIComponent($get("TaskHost_Directions_EndAddress").value);
        var taskDirStart = decodeURIComponent($get("TaskHost_Directions_StartAddress").value);
        var taskDirEnd = decodeURIComponent($get("TaskHost_Directions_EndAddress").value);
            
        // TODO: Take parameters from hidden fields instead!
        // If can not get parameters from taskpanael take from header
        if (taskDirStart != "" && taskDirEnd != "" && taskDirStart != FROM_STRING && taskDirEnd != TO_STRING) {
            parameters += "&start=" + taskDirStart;
            parameters += "&end=" + taskDirEnd;
        }
        else {
            var headDirStart = encodeURIComponent($get("header_directions_from").value);
            var headDirEnd = encodeURIComponent($get("header_directions_to").value);
            parameters += "&start=" + headDirStart;
            parameters += "&end=" + headDirEnd;
        }
        var a = $get("direction_routeOptions_1");
        var b = $get("direction_routeOptions_0");
        var c = $get("direction_routeOptions_2");
        // qs - quickest; st - shortest; wd - walking
        var rs = "qs";
        if (a.checked) {
            rs = "st";
        }
        if (b.checked) {
            rs = "qs";
        }
        if (c.checked) {
            rs = "wd";
        }
        parameters += "&rs=" + rs;
        parameters += "&endll=" + $get("TaskHost_Directions_EndLatLong").value;
        parameters += "&startll=" + $get("TaskHost_Directions_StartLatLong").value;
    }
    if (!IsNullOrEmpty(precicePOIID)) {
        var shape = map.GetShapeByID(precicePOIID);
        if (!IsNullOrEmpty(shape)) {
            //parameters += "&where1=" + shape.GetDescription();
            parameters += "&where1=" + $get("header_taskBar_placessearch").value;
        }
    }
    
    var s_what = $get("search__searchWhat");
    if (s_what != null) {
        if (s_what.value != "") {

            // Do not add searchWhat parameter in collection search, it will trigger a conflict in drawing map in AxMap.js
            if (!exlopereCollections)
                parameters += "&searchWhat=" + s_what.value;
            
            parameters += "&llf=" + $get("search_latLongField").value;
            parameters += "&itemIndex=" + $get("search__itemIndex").value;
            parameters += "&searchWhere=" + $get("search__searchWhere").value;
        }
    }
    if (exploreSpeedCameras) {
        parameters += "&explSC=true";
        var view = map.GetMapView();
        var topleft;
        var bottomright;
        var m = map.GetBirdseyeScene();
        if (m != null) {
            var dc = new _xy1;
            topleft = dc.Decode(view.TopLeftLatLong);
            bottomright = dc.Decode(view.BottomRightLatLong);
        }
        else {
            topleft = view.TopLeftLatLong;
            bottomright = view.BottomRightLatLong;
        }
        parameters += "&topLat=" + topleft.Latitude;
        parameters += "&topLon=" + topleft.Longitude;
        parameters += "&btmLat=" + bottomright.Latitude;
        parameters += "&btmLon=" + bottomright.Longitude;
    }

    if (exlopereCollections) {
        var colParams = $get("search__searchCollections").value;
        if (colParams != null && colParams != "") {
            parameters += "&colSearch=" + colParams;
        }
    }

    // Detect Language
    var lang = "";
    if ($get("lang") != null)
        lang = $get("lang").value;
    parameters += "&lang=" + lang;

    var url = "";
    // Speedcameras page has different print page - MSNAutoPrint
    if (pageName == "auto/default.aspx") {
        url = pageURL + 'MSNAutoPrint.aspx' + parameters + "&brd=" + brd;
    }
    else {
        url = pageURL + '/Print.aspx' + parameters + "&brd=" + brd;
    }

    window.open(url, "");
}
axPage.CloseModalPopUp = function() {
    var modalpopup = $get("modalpopup");
    modalpopup.style.display = "none";
    $get("modalpopupIframe").style.display = "none";
    var modalpopupB = $get("modalpopupBackground");
    modalpopupB.style.display = "none";
    modalPopupopened = false;
}
axPage.EmailCollection = function(link) {
    window.open("mailto:?subject=" + L_PERMALINK_EMAIL_SUBJ + "&body=" + escape(link));
}
var printDisabled = false;
axPage.SetPrintMenu = function() {
    var style = map.GetMapStyle();
    if (style == 'b' || style == 'o') {
        var a = $get("menuContrl_taskBar_printBtn");
        a.title = L_PRINT_DIS_MES;
        a.style.cursor = "default";
        a.detachEvent("onclick", axPage.OpenPrintWindow);
        var b = $get("menuContrl_taskBar_printBtn_a");
        b.className = "printDisabled"
        printDisabled = true;
    }
    else {
        if (printDisabled) {
            var a = $get("menuContrl_taskBar_printBtn");
            a.title = "Drucken";
            a.style.cursor = "pointer";
            a.attachEvent("onclick", axPage.OpenPrintWindow);
            var b = $get("menuContrl_taskBar_printBtn_a");
            b.className = "printEnabled"
            printDisabled = false;
        }
    }
}
axPage.AttachPageEvents = function() {
    var a = $get("menuContrl_taskBar_printBtn");
    if (map.GetMapStyle() != 'o') {
        a.attachEvent("onclick", axPage.OpenPrintWindow);
    }
    else {
        var b = $get("menuContrl_taskBar_printBtn_a");
        b.className = "printDisabled"
        a.title = L_PRINT_DIS_MES;
        printDisabled = true;
    }
    var b = $get("header_taskBar_Biz_link");
    b.attachEvent("onclick", axPage.ChangeTaskBar);
    var c = $get("header_taskBar_Places_link");
    c.attachEvent("onclick", axPage.ChangeTaskBar);
    var d = $get("header_taskBar_Routenplaner_link");
    if (d != null) {
        d.attachEvent("onclick", axPage.ChangeTaskBar);
    }
    var col = $get("header_taskBar_col_link");
    if (col != null) {
        col.attachEvent("onclick", axPage.ChangeTaskBar);
    }
}
axPage.OpenSuchagent = function(city)
{
    var url = "http://suchagent.msn.de/Travel.Suchagent?ss=" + city;
    window.open(url, "_blank");
}
axPage.ChangeSearchBoxes = function(_b) {
    if (_b.value == WHAT_STRING || _b.value == WHERE_STRING || _b.value == COL_STRING || _b.value == FROM_STRING || _b.value == TO_STRING) {
        _b.value = "";
        _b.className = "";
    }
}
axPage.ChangeBack = function(_e) {
    if (_e.value == "") {
        if (_e.id == "header_taskBar_what") {
            _e.value = WHAT_STRING;
            _e.className = "Watermark";
        }
        if (_e.id == "header_taskBar_where") {
            _e.value = WHERE_STRING;
            _e.className = "Watermark";
        }
        if (_e.id == "header_taskBar_placessearch") {
            _e.value = WHERE_STRING;
            _e.className = "Watermark";
        }
        if (_e.id == "header_taskBar_collsearch") {
            _e.value = COL_STRING;
            _e.className = "Watermark";
        }
        if (_e.id == "header_directions_from") {
            _e.value = FROM_STRING;
            _e.className = "Watermark";
        }
        if (_e.id == "header_directions_to") {
            _e.value = TO_STRING;
            _e.className = "Watermark";
        }
    }
}
axPage.CopyToClipBoard = function() {
    var permalink = axPage.GetPermalink();
    window.clipboardData.setData('Text', permalink);
}
axPage.BlogPermalink = function() {
    var title = "Title=" + L_PERMALINK_EMAIL_SUBJ;
    var description = "description=" + encodeURIComponent("<a href=" + axPage.GetPermalink() + ">" + L_PERMALINK_EMAIL_SUBJ + "</a>");
    window.open(BLOG_IT_LINK + "&" + title + "&" + description);
}
axPage.EmailPermalink = function(parameters) {
    if (parameters == null || parameters == "")
        parameters = "";
    window.open("mailto:?subject=" + L_PERMALINK_EMAIL_SUBJ + "&body=" + escape(axPage.GetPermalink()) + escape(encodeURIComponent(parameters)));
}
axPage.ShowModalPopUp = function(e) {
    var permalink = axPage.GetPermalink();
    var pl = $get("pl_input");
    if (pl != null)
        pl.value = permalink;
        
    $get("p_linkContent").innerHTML = "<a href='" + permalink + "'>" + permalink + "</a>";
    if (navigator.appName == "MSIE" || navigator.appName == "IE" || navigator.appName == "Microsoft Internet Explorer") {
        $get("layers_pl_copy").style.display = "block";
    }
    var w = document.body.clientWidth;
    var h = document.body.clientHeight;
    var modalpopup = $get("modalpopup");
    modalpopup.style.left = (w / 2 - 245) + "px";
    modalpopup.style.display = "block";
    if (map.GetMapMode() == VEMapMode.Mode3D) {
        $get("modalpopupIframe").style.left = modalpopup.style.left;
        $get("modalpopupIframe").style.display = "block";
    }
    var modalpopupB = $get("modalpopupBackground");
    modalpopupB.style.display = "block";
    modalpopupB.style.width = w + "px";
    modalpopupB.style.height = h + "px";
    modalPopupopened = true;
}
axPage.OpenBusinessPermalink = function(id, name, address) {
/// <summary> Opens e-mail client with permalink to the business </summary>
    var params = "?bsid=" + escape(id) + "";
    var link = pageURL + pageName + params;
    name = unescape(name);
    address = unescape(address);

    window.open("mailto:?subject=" + escape(name) + L_PERMALINK_EMAIL_BUSN + "&body=" + escape(name) + "%0A" + escape(address) + "%0A" + escape(link) + "%0A" + L_PRINT_VER + ": " + escape(axPage.GetPrintWindowUrl() + params));
}

axPage.GetPrintWindowUrl = function() {
    var url = pageURL + '/Print.aspx';
    return url;
}
axPage.Resize = function() {
    /// <summary> Resizes content area (left content area + map ) </summary>
    var m = document.getElementById("msve_main");
    var f = document.getElementById("msve_footer");
    m.style.height = f.offsetTop - m.offsetTop + "px";
    axPage.ResizeMap();
    axPage.ResizeModalPopup();
}
axPage.ResizeMap = function() {
    /// <summary> Resizes map </summary>
    if (map != null) {
        map.Resize();
    }
}
axPage.SearchWeb = function(t)
{
    var u = LiveSearchURL + "&q=";
    if(t.id.indexOf("Places") > -1)
    {
        var a = $get("header_taskBar_placessearch");
        if(a.value != "" && a.value != WHERE_STRING)
        {
            window.open(u+encodeURIComponent(a.value),"_blank");
            return;
        }
    }
    else
    {
        var p = "";
        var a = $get("header_taskBar_what");
        if(a.value != "" && a.value != WHAT_STRING)
        {
            p += a.value + " ";
        }
        var b = $get("header_taskBar_where");
        if(b.value != "" && b.value != WHERE_STRING)
        {
            p += b.value;
        }
        if(p != "")
        {
            window.open(u+encodeURIComponent(p),"_blank");
            return;
        }
    }
    window.open(LiveSearchURL, "_blank");  
}
axPage.ChangeTaskBarByName = function(name) {
    var a = $get("taskBar_inputs_cs");
    var b = $get("header_taskBar_Biz_link");
    var c = $get("header_taskBar_Places_link");
    var d = $get("taskBar_Places");
    var e = $get("taskBar_Biz");
    var f = $get("header_taskBar_Routenplaner_link");
    var cl = $get("header_taskBar_col_link");
    var tc = $get("taskbar_collections");
    var tr = $get("taskbar_routenplaner");

    if (name == "Places") {
        b.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        f.className = "SubScopeSwitch";
        c.className = "SubScopeSwitch scopeTabsSelected";
        a.value = "Places";
        d.style.display = "block";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "none";
    }
    if (name == "Biz") {
//        b.className = "SubScopeSwitch scopeTabsSelected";
        c.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        a.value = "Business";
        d.style.display = "none";
        e.style.display = "block";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "none";
    }
    if (name == "col") {
//        b.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch scopeTabsSelected";
        }
        c.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch";
        a.value = "Collection";
        d.style.display = "none";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "block";
        }
        tr.style.display = "none";
    }
    if (name == "Routenplaner") {
//        b.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch scopeTabsSelected";
        c.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        f.value = "Routenplaner";
        d.style.display = "none";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "block";
    }
}
axPage.ChangeTaskBar = function() {
    var a = $get("taskBar_inputs_cs");
    var b = $get("header_taskBar_Biz_link");
    var c = $get("header_taskBar_Places_link");
    var d = $get("taskBar_Places");
    var e = $get("taskBar_Biz");
    var f = $get("header_taskBar_Routenplaner_link");
    var cl = $get("header_taskBar_col_link");
    var tc = $get("taskbar_collections");
    var tr = $get("taskbar_routenplaner");


    var evt = (event) ? event : ((window.event) ? window.event : "");
    var t = evt.target ? evt.target : evt.srcElement;
    if (t.id.indexOf("Places") != -1) {
        b.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        f.className = "SubScopeSwitch";
        c.className = "SubScopeSwitch scopeTabsSelected";
        a.value = "Places";
        d.style.display = "block";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "none";
    }
    if (t.id.indexOf("Biz") != -1) {
        b.className = "SubScopeSwitch scopeTabsSelected";
        c.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        a.value = "Business";
        d.style.display = "none";
        e.style.display = "block";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "none";
    }
    if (t.id.indexOf("col") != -1) {
//        b.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch scopeTabsSelected";
        }
        c.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch";
        a.value = "Collection";
        d.style.display = "none";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "block";
        }
        tr.style.display = "none";
    }
    if (t.id.indexOf("Routenplaner") != -1) {
//        b.className = "SubScopeSwitch";
        f.className = "SubScopeSwitch scopeTabsSelected";
        c.className = "SubScopeSwitch";
        if (cl != null) {
            cl.className = "SubScopeSwitch";
        }
        f.value = "Routenplaner";
        d.style.display = "none";
        e.style.display = "none";
        if (tc != null) {
            tc.style.display = "none";
        }
        tr.style.display = "block";
    }
}
axPage.GetPermalink = function() {
    if (map == null) {
        return "";
    }
    var _40 = pageURL + pageName + "?";
    var s = new String(map.GetCenter());
    if (map.IsBirdseyeAvailable()) {
        var m = map.GetBirdseyeScene();
        if (m != null) {
            var dc = new _xy1;
            s = new String(dc.Decode(map.GetCenter()));
            _40 += "cp=" + s.replace(", ", "~");
            _40 += "&scene=" + m.GetID();
        }
    }
    else {
        _40 += "cp=" + s.replace(", ", "~");
    }
    var t = $get("search__searchWhat");
    if (t != null) {
        if (t.value != "") {
            if (t.value != WHAT_STRING && $get("TaskHost_Search").style.display != "none") {
                _40 += "&ss=" + t.value;
            }
        }
    }

    // TODO: Until NL business search is fixed add parameter where
    // NL where fix ------------------------------------------------
    var e = $get("taskBar_Biz").style.display;
    if (e != "none") {
        var w = $get("search__searchWhere");
        if (w != null) {
            if (w.value != "") {
                if (w.value != WHERE_STRING && $get("TaskHost_Search").style.display != "none") {
                    _40 += "&where=" + escape(w.value);
                }
            }
        }
    }
    // NL where fix ------------------------------------------------



    _40 += "&style=" + map.GetMapStyle();
    _40 += "&lvl=" + map.GetZoomLevel();
    _40 += "&dir=" + map.GetHeading();
    _40 += "&tilt=" + map.GetPitch();
    _40 += "&alt=" + map.GetAltitude();

    var r = $get("TaskHost_Directions_RouteGenerated").value;
    if (r == "true") {
        //rtp=pos.56.6803740283681_26.2792970730855_Origin__~pos.55.4040700760001_23.4667968223139_Destination__&rtop=0~0~0
        //&rtp=pos.58.36667798129861_26.704832382311167_tartu__~pos.58.57261501861814_26.280242258271954_puurmani__&rtop=1~0~0
        var a = $get("TaskHost_Directions_StartLatLong").value;
        var b = $get("TaskHost_Directions_EndLatLong").value;
        _40 += "&rtp=pos." + a.replace("~", "_") + "_" + escape($get("TaskHost_Directions_StartAddress").value) + "__";
        _40 += "~pos." + b.replace("~", "_") + "_" + escape($get("TaskHost_Directions_EndAddress").value) + "__";
        var c = $get("direction_routeOptions_1");
        var q = $get("direction_routeOptions_0");
        var w = $get("direction_routeOptions_2");
        if (c.checked) {
            _40 += "&rtop=1~0~0";
        }
        else if (q.checked) {
            _40 += "&rtop=0~0~0";
        }
        else if (w.checked) {
            _40 += "&rtop=2~0~0";
        }
    }
    if ($get("TaskHost_CollectionsViewer").style.display == "block") {
        _40 += "&explore=sst.0";
    }

    return _40;
}
axPage.ResizeModalPopup = function() {
    /// <summary> Resizes modalpopup </summary>
    if (modalPopupopened) {
        var w = document.body.clientWidth;
        var h = document.body.clientHeight;
        var modalpopupB = $get("modalpopupBackground");
        modalpopupB.style.width = w + "px";
        modalpopupB.style.height = h + "px";
    }
}

/**/
function EnterPressed(e) {
    var _1b;
    if (window.event) {
        _1b = e.keyCode;
    }
    else {
        if (e.which) {
            _1b = e.which;
        }
    }
    if (_1b == 13) {
        e.returnValue = false;
        e.cancel = true;
        axSearch.SearchLocation();
        return false;
    }
    else { return true; }
}
function Enter2(e, c) {
    var _1b;
    if (window.event) {
        _1b = e.keyCode;
    }
    else {
        if (e.which) {
            _1b = e.which;
        }
    }
    if (_1b == 13) {
        e.returnValue = false;
        e.cancel = true;
        if (c == "col") {
            //SearchCollections(0, CollectionSearchType.Tag, 'relevance', true);
            axSearch.VESearchCollections(0, 'relevance');
        }
        else {
            axSearch.SearchLocationOnly();
        }
        return false;
    }
    else { return true; }
}

/**/
var searchBusinesses = false;
var searchBusinessesBestMapView = true;
var axSearch = new Object();

axSearch.PerformSearch = function() {
    searchIsOver = false;
    axSearch.ShowSearchProgress();
    var ll = map.GetCenter();
    $get("search_latLongField").value = ll.Latitude + ";" + ll.Longitude;
    $get("search_btnHidden").click();
}
axSearch.ShowMessage = function(a) {
    var r = $get("menuContrl_TaskHost_WelcomeTask_pc");
    r.innerHTML = a;
}
axSearch.ShowSearchProgress = function() {
    searchIsOver = false;
    axSearch.ShowTaskProgress();
    axSearch.ShowTaskHostLayer("search");
    exlopereCollections = false;
}
axSearch.ShowLocationResult = function(locationResult) {
    axSearch.ShowTaskHostLayer("search");

    var displayName = locationResult.DisplayName;
    if (locationResult.Address.City != null && locationResult.Address.City != "") {
        displayName = locationResult.Address.City;
    }

    var content = "<div class='callToAction'>";
    content += "<img align='middle' style='border-width: 0px;' alt='' src='" + imagesPath + "poi_precise_location.gif' class='locationPin'/>";
    content += "<span style='color:#444444;font-weight:bold;'>" + locationResult.DisplayName + "</span>";
    content += "<div class='actionwrapper'>";
    content += "<ul class='taskStrip'><li><a href='javascript:SetDrvDirAdress(1,\"start\"," + "\"" + locationResult.DisplayName + "\"" + ");' style='padding-right: 2px;'>" + L_Directions_Text + "</a></li>";
    content += "<li class='nonFirst' onmouseout='axPage.ShowSendToDropDown(false, \"sendtodropdown_1\")' onmousedown='axPage.ShowSendToDropDown(true, \"sendtodropdown_1\")'><a href='#' style='margin-left:4px;padding-left:4px;'>" + L_SEND_TO + "</a>";
    content += "<div onmouseover='axPage.ShowSendToDropDown(true, \"sendtodropdown_1\")' id='sendtodropdown_1' style='position: absolute;left:77px; top: 13px; display: none; border: solid 1px #CCCCCC; background-color: #FFFFFF; text-align: center; padding: 3px 5px 3px 5px !important;'>";
    content += "<button type='button' onclick='axPage.EmailPermalink(\"" + "&where1=" + locationResult.DisplayName + "\")' class='taskItem' title='" + L_SEND_PER_EMAIL + "' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)'>";
    content += "<div>";
    content += "<span style='padding: 0px 5px 0px 5px !important;'>" + L_EMAIL_RECEIVER + "</span>";
    content += "</div>";
    content += "</button><br/>";
    if (showSuchagentPromotion) {
        content += "<button type='button' style='' class='taskItem' onclick='axPage.OpenSuchagent(\"" + displayName + "\")' title='" + L_SEND_TO_SUCHAGENT + "' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)'>";
        content += "<div>";
        content += "<span style='padding: 0px 5px 0px 5px !important;'>MSN Suchagent</span>";
        content += "</div>";
        content += "</button>";
    }
    content += "</div>";
    content += "</li></ul>";
    content += "";
    content += "";
    content += "</div>";
    content += "</div>";

    // Explore collections link
    var collLink = "<div><a id=\"taskBar_collectionsAnchor\" type=\"button\" onclick=\"javascript:ExploreCollections('relevance',this);\"  class=\"exploreCollections\" title=\"" + L_EXPLORE_COLLECTIONS + "\">" + L_EXPLORE_COLLECTIONS + "</a></div>";

    $get("TaskHost_businessSearchPanel_searchResultsBody").innerHTML = content + collLink + "<div id='generic_ads'></div>";
    if (showSuchagentPromotion) {
        $get("TaskHost_businessSearchPanel_searchResultsBody").innerHTML += "<div style='border-top:1px solid #CCCCCC;margin-top:15px;padding-top:15px;'><a href='http://suchagent.msn.de/Travel.Suchagent?ss=" + displayName + "' target='_blank' style='float:left;margin:5px;'><img class='MSNpic' src='http://suchagent.msn.de/templates/images/startpage/welcomebox.jpg'> Der MSN Suchagent zeigt Ihnen mehr Infos \xfcber <span style='color:Red'>" + displayName + "</span>" + "</div>";
    }
    if (showAdsDE) {
        CallPageMethod("GetAds", { "where": displayName }, OnGetAds);
    }
    if (showAdsNL) {
        CallPageMethod("GetAds", { "whatWhere": displayName }, OnGetAdsNL); // in NL.js
    }
    searchBusinesses = false;
    exlopereCollections = false;

    searchBusinessesBestMapView = true;
    axSearch.HideTaskProgress();
    $get("search__searchContainer").style.display = "block";

}

function OnGetAds(r) {
    if (r == null) return;
    if (r.length == 0) return;
    var d = $get("generic_ads");
    if (d == null) return;
    var content = "<div style='border-top:1px solid #CCCCCC;margin-top:15px;padding-top:5px;'><span style='color:#999999;font-size:0.8em;font-weight:bold;'>" + L_SPONSORED_LINKS + "</span><br/><br/>";
    for (var i = 0; i < r.length; i++) {
        content += "<a class='adTitle' style='color:black' target='_blank' href='" + r[i].Address.Url + "'>" + r[i].Address.CompanyName + "</a>" + "<br/><span style='font-size:11px;'>" + r[i].Description + "</span><br/>" + "<a target='_blank' href='" + r[i].Address.Url + "'>" + r[i].Address.PostalCode + "</a><br/>";
    }
    d.innerHTML += content + "</div>";
}
axSearch.ShowTaskProgress = function() {
    /// <summary> Shows progress indicator when some search process has started </summary>
    $get("TaskProgress").style.display = "inline";
    $get("TaskHost").style.display = "none";
}
axSearch.HideTaskProgress = function() {
    /// <summary> Shows progress indicator when some search process has started </summary>
    $get("TaskProgress").style.display = "none";
    $get("TaskHost").style.display = "block";
}
axSearch.ShowTaskArea = function() {
    var a = $get("msve_taskArea");
    if (a.style.display == "none" || a.style.width == "0px") {
        a.style.display = "block";
        a.style.width = "32em";
        var m = $get("msve_mapArea");
        var r = $get("msve_mapResizer");
        r.style.display = "block";
        m.style.marginLeft = "32em";

        if (isCustomResize) {
            ResizeMap();
        }
        else {
            axPage.ResizeMap();
        }
    }
    if (collectionsLayer != null) {
        collectionsLayer.DeleteAllShapes();
    }
}
axSearch.ShowTaskHostLayer = function(name) {
    /// <summary>Shows TashHost layer - possible value are: "welcome", "search", "driving", "collection" </summary>
    var welcomName = "WelcomeTask_TaskHost_WelcomeTask";
    var searchName = "TaskHost_Search";
    var drivingName = "TaskHost_Driving";
    var collectionName = "TaskHost_CollectionsViewer";
    if (name == "welcome") {
        $get(welcomName).style.display = "block";
        $get(searchName).style.display = "none";
        $get(drivingName).style.display = "none";
        $get(collectionName).style.display = "none";
    }
    if (name == "search") {
        $get("TaskHost_disambgid_disambgContainer").style.display = "none";
        $get("search__disambgContainer").style.display = "none";
        $get(welcomName).style.display = "none";
        $get(searchName).style.display = "block";
        $get(drivingName).style.display = "none";
        $get(collectionName).style.display = "none";
    }
    if (name == "driving") {
        $get(welcomName).style.display = "none";
        $get(searchName).style.display = "none";
        $get(drivingName).style.display = "block";
        $get(collectionName).style.display = "none";
    }
    if (name == "collection") {
        $get(welcomName).style.display = "none";
        $get(searchName).style.display = "none";
        $get(drivingName).style.display = "none";
        $get(collectionName).style.display = "block";
    }
}
axSearch.OnBusinessSearchSuccess = function(_4) {
    results = _4;
    if (results == null) {
        return;
    }
    latLongList.length = 0;
    pushPins.length = 0;
    if (results.length > 0) {
        if (results.length == 1 && results[0].SearchResultType == 2) {
            axMap.ShowPlace();
        }
        else {
            axMap.ShowPins();
            $get("TaskHost_disambgid_disambgContainer").style.display = "none";
            $get("search__disambgContainer").style.display = "none";
        }
    }
}
axSearch.UpdateAmbiguousList = function(location_results, taskr) {
    ///<summary>Show Multiple Addresses List</summary>
    if (!location_results || location_results.constructor != Array) {
        return;
    }
    if (taskr == "biz") {
        if (location_results.length == 1) {
            var _wht = $get("header_taskBar_what"); 
            if (_wht.value == WHAT_STRING || _wht.value == "") {
                axMap.ShowLocation(location_results[0]);
                return;
            }
            // If What field correct, perform search and save params in hidden fields
            $get("header_latLongField").value = location_results[0].Latitude + ";" + location_results[0].Longitude;
            $get("search_latLongField").value = location_results[0].Latitude + ";" + location_results[0].Longitude;

            //            $get("search__searchWhere").value = location_results[0].DisplayName;
            //            $get("header_taskBar_where").value = location_results[0].DisplayName;
            $get("search__searchWhere").value = $get("header_taskBar_where").value;

            $get("header_taskBar_where").className = "";
            $get("search__searchWhat").value = _wht.value;
            $get("search_btnHidden").click();
            searchBusinesses = true; searchBusinessesBestMapView = true;
            axSearch.ShowSearchProgress();
            $get("TaskHost_disambgid_disambgContainer").style.display = "none";
            return;
        }
        else {
            var content = "<ol>";
            for (var d = 0; d < location_results.length; d++) {
                content += "<li><a href='#' onclick='axSearch.SetLocation(" + d + ", \"biz\")'>" + location_results[d].DisplayName + "</a></li>";
            }
            $get("disambiglist").innerHTML = content + "</ol>";
            axSearch.ShowTaskHostLayer("search");
            axSearch.ShowSearchDisambWarning();
            axSearch.HideTaskProgress();
        }
    }
    if (taskr == "loc") {
        if (location_results.length == 1) {
            axMap.ShowLocation(location_results[0]);
            return;
        }
        else {
            var content = "<ol>";
            for (var d = 0; d < location_results.length; d++) {
                content += "<li><a href='#' onclick='axSearch.SetLocation(" + d + ", \"loc\")'>" + location_results[d].DisplayName + "</a></li>";
            }
            $get("disambiglist").innerHTML = content + "</ol>";
            axSearch.ShowTaskHostLayer("search");
            axSearch.ShowSearchDisambWarning();
        }
    }
}
axSearch.SetLocation = function(index, type) {
    if (type == 'biz') {
        var _wht = $get("header_taskBar_what");
        if (_wht.value == WHAT_STRING || _wht.value == "") {
            axMap.ShowLocation(locationResults[index]);
            return;
        }
        $get("header_latLongField").value = locationResults[index].Latitude + ";" + locationResults[index].Longitude;
        $get("search_latLongField").value = locationResults[index].Latitude + ";" + locationResults[index].Longitude;
        $get("search__searchWhere").value = locationResults[index].DisplayName;
        $get("search__searchWhat").value = $get("header_taskBar_what").value;
        $get("search_btnHidden").click();
        searchBusinesses = true; searchBusinessesBestMapView = true;
        axSearch.ShowSearchProgress();
    }
    else {
        axMap.ShowLocation(locationResults[index]);
    }
}
axSearch.OnParameterSearch = function(_e) {
    var _f = $get("header_taskBar_where");
    var _10 = $get("header_taskBar_what");
    if (!_e || _e.length == 0) {
        if (whatwhereValue != null && whatwhereValue != "") {
            //_10.value = whatwhereValue;
            _10.className = "";

            // _f.value = _e[0].DisplayName;
            _f.className = "";
        }
        return;
    }
    locationResults.length = 0;

    for (var i = 0; i < _e.length; i++) {
        locationResults.push(_e[i]);
    }
    axSearch.UpdateAmbiguousList(locationResults, "loc");
}
axSearch.OnParameterExtraSearch = function(_e) {
    var _f = $get("header_taskBar_where");
    var _10 = $get("header_taskBar_what");
    if (_e == "") {
        axSearch.SearchLocation();
        return;
    }
    if (_e != null) {
        //_f.value = _e[0].DisplayName;
        _f.className = "";

        //_10.value = _e[0].Description;
        _10.className = "";
        axSearch.SearchLocation();
        return;
    }
}
axSearch.SearchLocation = function() {
    ///<summary>Search business location</summary>
    searchIsOver = false;

    $get("search__searchWhat").value = "";

    var a = $get("header_taskBar_where");
    if (a.value == WHERE_STRING || a.value == "") {
        axSearch.ShowSearchDisambContainer();
        return;
    }
    axSearch.ShowTaskArea();
    axSearch.ShowTaskProgress();
    
    CallPageMethod("SearchLocation", { "locationWhere": a.value }, axSearch.OnSearchLocation);
    Log();
    axRoute.RemoveDirections();
    $get("TaskHost_disambgid_disambgContainer").style.display = "none";
}
axSearch.OnSearchLocation = function(_17) {
if (!_17 || _17.length == 0) {
        axSearch.HideTaskProgress()
        axSearch.ShowSearchDisambContainer();
        return;
    }
    locationResults.length = 0; 
    for (var i = 0; i < _17.length; i++) {
        locationResults.push(_17[i]);
    }
    axSearch.UpdateAmbiguousList(locationResults, "biz");
}
axSearch.SearchLocationOnly = function() {
    searchIsOver = false;

    $get("search__searchWhat").value = "";
    var a = $get("header_taskBar_placessearch"); 
    if (a.value == WHERE_STRING || a.value == "") {
        return;
    }
    axSearch.ShowTaskArea();
    axSearch.ShowTaskProgress();
    
    searchLocationOnlyTerm = a.value;
    CallPageMethod("SearchLocation", { "locationWhere": a.value }, axSearch.OnSearchLocationOnly);
    Log();
    axRoute.RemoveDirections();
}
axSearch.DisplayInfo = function(event, id) {
    var c = id % 10;
    if (c == 0) {
        c = 10;
    }
    var p = pushPins[c - 1];
    axSearch.ConstructInfoDetailLayer(p, c);

    var layer = $get("infoDetailLayer");
    var e = (event) ? event : ((window.event) ? window.event : "");
    layer.style.top = e.clientY - 50 + "px";
    layer.style.left = axPage.GetElementLeftPositionByID("search__searchContainer") + 25 + "px";
    layer.style.display = "block";
}
axSearch.OnQParameterSearch = function(a) {
    axSearch.HideTaskProgress();
    if (!a || a.length == 0) {
        var t = $get("search_disambgParse_scope");
        t.selectedIndex = 1;
        $get("search_disambgParse_whatBox").style.display = "none";
        $get("search_disambgParse_whatText").style.display = "none";
        $get("search_disambgParse_whereBox").value = searchLocationOnlyTerm;
        axSearch.ShowSearchDisambContainer();
        return;
    }
    locationResults.length = 0;
    for (var i = 0; i < a.length; i++) {
        locationResults.push(a[i]);
    }
    axSearch.UpdateAmbiguousList(locationResults, "biz");
}
axSearch.OnQParameterSearchError = function(a) {
    // TODO
}
axSearch.OnSearchLocationOnly = function(a) {
    axSearch.HideTaskProgress();
    if (!a || a.length == 0) {
        var t = $get("search_disambgParse_scope");
        t.selectedIndex = 1;
        $get("search_disambgParse_whatBox").style.display = "none";
        $get("search_disambgParse_whatText").style.display = "none";
        $get("search_disambgParse_whereBox").value = searchLocationOnlyTerm;
        axSearch.ShowSearchDisambContainer();
        return;
    }
    locationResults.length = 0;
    for (var i = 0; i < a.length; i++) {
        locationResults.push(a[i]);
    }
    axSearch.UpdateAmbiguousList(locationResults, "loc");
}
axSearch.ShowSearchDisambContainer = function() {
    axSearch.ShowMessage(L_NO_SEARCHRESULTS);
    axSearch.ShowTaskHostLayer("search");
    $get("search__searchContainer").style.display = "none";
    $get("TaskHost_disambgid_disambgContainer").style.display = "none";
    $get("search__disambgContainer").style.display = "block";
    exlopereCollections = false;
}
axSearch.ShowSearchDisambWarning = function() {
    axSearch.ShowTaskHostLayer("search");
    $get("search__searchContainer").style.display = "none";
    $get("TaskHost_disambgid_disambgContainer").style.display = "block";
    $get("search__disambgContainer").style.display = "none";
    exlopereCollections = false;
}
axSearch.DisambgParseChanged = function() {
    var t = $get("search_disambgParse_scope");
    // 0 = business, 1 = location, 2 = collection
    if (t.selectedIndex == 0) {
        $get("search_disambgParse_whatBox").style.display = "block";
        $get("search_disambgParse_whatText").style.display = "block";
    }
    else {
        $get("search_disambgParse_whatBox").style.display = "none";
        $get("search_disambgParse_whatText").style.display = "none";
    }
}
axSearch.DisambgBtnPanelSearch = function() {
    var t = $get("search_disambgParse_scope");
    // 0 = business, 1 = location, 2 = collection
    if (t.selectedIndex == 0) {
        $get("header_taskBar_what").value = $get("search_disambgParse_whatBox").value;
        $get("header_taskBar_where").value = $get("search_disambgParse_whereBox").value;
        axSearch.SearchLocation();
    }
    else if (t.selectedIndex == 1) {
        $get("header_taskBar_placessearch").value = $get("search_disambgParse_whereBox").value;
        axSearch.SearchLocationOnly();
    }
    else {
        $get("header_taskBar_collsearch").value = $get("search_disambgParse_whereBox").value;
        axSearch.VESearchCollections(0, 'relevance');
    }
}
axSearch.OnInfoDetailLayerEnter = function() {
    detailLayerFocus = true;
}

axSearch.OnInfoDetailLayerLeave = function() {
    detailLayerFocus = false;
    setTimeout("axSearch.DetailLayerLeave()", 2000);
}

axSearch.DetailLayerLeave = function() {
    if (!detailLayerFocus) {
        axSearch.HideInfoDetailLayer();
    }
}
axSearch.HideInfoDetailLayer = function() {
    var layer = $get("infoDetailLayer");
    layer.style.display = "none";
}
axSearch.ConstructInfoDetailLayer = function(p, index) {
    var i = $get("infoDetailLayerBody");
    var url = "";
    if (p.Address.Url != null) {
        url = "<a href='" + p.DetailsUrl + "' target='_blank' style='#0066A7;text-decoration:none;'>" + p.DetailsUrl + "</a><br/>";
    }
    var addressLine = "";
    if (p.Address.AddressLine != null) {
        addressLine = p.Address.AddressLine;
    }
    var city = "";
    if (p.Address.City != null) {
        city = p.Address.City;
    }
    var zipcode = "";
    if (p.Address.PostalCode != null) {
        zipcode = p.Address.PostalCode;
    }
    var phone = "";
    if (p.Address.Phone != null) {
        phone = p.Address.Phone;
    }
    var companyName = "";
    if (p.Address.CompanyName != null) {
        companyName = p.Address.CompanyName;
    }
    var _url = "";
    if (p.Address.Url != null) {
        _url = p.Address.Url;
    }
    var address = addressLine + ", " + zipcode + " " + city;
    var vCardLink = companyName + "_" + _url + "_" + address + "_" + phone + "_" + p.LatLong.Latitude + "&" + p.LatLong.Longitude;
    var vCardPrefix = "vCard.aspx?";
    var content = "<p/>";
    content += "<div class='VE_Pushpin_Popup_Title' style='height:200px;'>";
    content += "<div style='margin: 0pt 0pt 8px; color: rgb(68, 68, 68); font-size: 1.1em; font-weight: bold;'>";
    // Show logo on popup
    if (BusinessSearchLogo == true) {
        content += "<div class='partnerLogo'></div>"
        //        content += "<div style='margin: 0px 0px 10px 0px'><img  src='images/BusinessSearchLogo.gif'></img></div>";
    }
    content += "<a target='_blank' href='" + p.DetailsUrl + "'>" + p.Address.CompanyName + "</a>";
    content += "<div style='color: rgb(103, 103, 103); font-size: 0.9em; font-weight: normal; height: 60px;'>";
    content += addressLine + "<br/>";
    content += zipcode + " " + city + "<br/>";
    content += phone;
    content += "</div>";
    content += "<br/>";
    content += "<div style='width: 100%; text-align: right;font-weight:normal;'>";
    content += "<a id=\"vCardLink\" href=" + vCardPrefix + encodeURIComponent(vCardLink) + ">" + L_OUTLOOK_VCARD + "</a>";
    content += "</div>";
    content += "</div>";
    content += "<div class='VE_Pushpin_Popup_Body'>";
    content += "<div style='padding: 4px 8px 15px; position: absolute; bottom: 3px; background-color: rgb(228, 237, 243); left: 2px; right: 2px; height: 45px; text-align: left;'>";
    
    //Send To DropDown
    if (p.BusinessID != null && p.BusinessID != "") {
        content += "<div style='cursor: pointer; ' onmouseout='axPage.ShowSendToDropDown(false, \"sendtodropdown_" + index + "\")' onmousedown='axPage.ShowSendToDropDown(true, \"sendtodropdown_" + index + "\")'><a class='VE_Panel_sublink'>" + L_SEND_TO + "</a>";
        content += "<div onmouseover='axPage.ShowSendToDropDown(true, \"sendtodropdown_" + index + "\")' id='sendtodropdown_" + index + "' style='position: absolute; left: 7px; top: 18px; display: none; border: solid 1px #CCCCCC; background-color: #FFFFFF; text-align: center; padding: 3px 5px 3px 5px !important;'>";
        content += "<button type='button' style='' class='taskItem' title='" + L_SEND_PER_EMAIL + "' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)' onclick=\"axPage.OpenBusinessPermalink('" + p.BusinessID + "','" + escape(p.Address.CompanyName) + "','" + escape(addressLine) + ", " + zipcode + " " + city + "')\">";
        content += "<div>";
        content += "<span style='padding: 0px 5px 0px 5px !important;'>" + L_EMAIL_RECEIVER + "</span>";
        content += "</div>";
        content += "</button>";
        content += "</div>";
        content += "</div>";
    }
    content += "<div>";
    content += "<a class='VE_Panel_sublink' href='javascript:SetDrvDirAdress1(" + index + ",\"start\"," + "\"" + address + "\"" + ");axSearch.HideInfoDetailLayer();'>";
    content += L_ContextMenu_DriveFrom + "</a> " + L_OR + " ";
    content += "<a class='VE_Panel_sublink' href='javascript:SetDrvDirAdress(" + index + ",\"end\"," + "\"" + address + "\"" + ");axSearch.HideInfoDetailLayer();'>";
    content += L_ContextMenu_DriveTo;
    content += "</a><br/>" + L_ZOOMLEVEL_TYPE + ": ";
    content += "<a class='VE_Panel_sublink' href='javascript:axMap.SetZoom(" + index + ",16);axSearch.HideInfoDetailLayer();'>";
    content += L_STREET + "</a> | ";
    content += "<a class='VE_Panel_sublink' href='javascript:axMap.SetZoom(" + index + ",11);axSearch.HideInfoDetailLayer();'>";
    content += L_CITY + "</a> | ";
    content += "<a class='VE_Panel_sublink' href='javascript:axMap.SetZoom(" + index + ",6);axSearch.HideInfoDetailLayer();'>";
    content += L_REGION + "</a></div></div></div></div>";
    i.innerHTML = content;
}
/***/
/* AXMAP */
var map = null;

var precicePOIID;
var tempDragLl;

AxMap = function() {
    this.LoadDefaultMap = function() {
        map.LoadMap(defaultLatLong, defaultZoomLevel, VEMapStyle.Shaded, false);
        map.SetMapStyle(VEMapStyle.Shaded);
    }
    this.DisplayMiniMap = function() {
        map.ShowMiniMap(0);
        var minimap = $get("MSVE_minimap");
        minimap.className = "MSVE_smallMinimap MSVE_Minimap_V6 collapsed";
        minimap.style.clip = "rect(auto, auto, 15px, 135px)";
        var el = document.createElement("span");
        el.id = "MSVE_minimap_glyph";
        el.title = L_INCREASE_MINIMAP;
        el.attachEvent("onclick", axMap.ShowMiniMap);
        minimap.appendChild(el);
    }
    this.ShowMiniMap = function() {
        var minimap = $get("MSVE_minimap");
        if (minimap.className == "MSVE_smallMinimap MSVE_Minimap_V6 collapsed") {
            minimap.className = "MSVE_smallMinimap MSVE_Minimap_V6 expanded";
            minimap.style.clip = "rect(auto, auto, auto, auto)";
            $get("MSVE_minimap_resize").style.display = "none";
            $get("MSVE_minimap_glyph").title = L_DECREASE_MINIMAP;
        }
        else {
            minimap.className = "MSVE_smallMinimap MSVE_Minimap_V6 collapsed";
            minimap.style.clip = "rect(auto, auto, 15px, 135px)";
            $get("MSVE_minimap_glyph").title = L_INCREASE_MINIMAP;
        }
    }
    this.AttachMapEvents = function() {
        map.AttachEvent("onendzoom", axMap.OnEndZoom);
        map.AttachEvent("onchangemapstyle", axMap.OnMapStyleChange);
        map.AttachEvent("onmouseup", CheckResizer);
        //map.AttachEvent("onchangeview" , EventViewChanged);
        // map.AttachEvent("onendpan" , axMap.OnPanEnded);
        //map.AttachEvent("onstartpan" , axMap.OnPanStarted);
        map.AttachEvent("onmousedown", axMap.OnMouseDown);
        map.AttachEvent("onmouseup", axMap.OnMouseUp);
        map.AttachEvent("onmousewheel", axMap.OnMouseWheel);
        map.AttachEvent("ondoubleclick", axMap.OnDoubleClick);

        var zoomOutBtn = $get("MSVE_navAction_tinyZoomBar_minus");
        zoomOutBtn.attachEvent("onclick", axMap.ToggleBirdsEyeOnZoom);

        var zoomInBtn = $get("MSVE_navAction_tinyZoomBar_plus");
        zoomInBtn.attachEvent("onclick", axMap.ToggleBirdsEyeOnZoom);
    }
    this.OnMouseDown = function() {
        if (searchBusinesses || exlopereCollections || exploreSpeedCameras) {
            tempDragLl = map.GetCenter();
        }
    }

    this.OnMouseUp = function() {
        if (searchBusinesses) {
            var center = map.GetCenter();
            if (tempDragLl.Latitude != center.Latitude && tempDragLl.Longitude != center.Longitude)
                axSearch.PerformSearch();
        }
        if (exlopereCollections) {
            var center = map.GetCenter();
            if (tempDragLl.Latitude != center.Latitude && tempDragLl.Longitude != center.Longitude) {
                // Don´t search after drag when CommunitySearch is active
                if ($get("VEsorting_panel").style.display == "none")
                    SearchCollections(0, tempCollectionSearchType, temporderby, false);
            }
        }
        if (exploreSpeedCameras) {
            var center = map.GetCenter();
            if (tempDragLl.Latitude != center.Latitude && tempDragLl.Longitude != center.Longitude)
                axMap.ShowSpeedCameras();
        }

    }
    this.OnContextMenu = function(e) {
        if (e.rightMouseButton) {
            axMap.OpenContextMenu(e);
        }
        else {
            axMap.HideContextMenu();
        }
    }
    this.OpenContextMenu = function(e) {
        var mode = map.GetMapMode();
        if (mode == VEMapMode.Mode2D) {
            var x = e.clientX;
            var y = e.clientY;
            var l = map.GetLeft();
            var t = map.GetTop();
            var pixel = new VEPixel(x - l, y - t);
            temporaryLatLong = map.PixelToLatLong(pixel);
            var m = map.GetBirdseyeScene();
            if (m != null) {
                var dc = new _xy1;
                temporaryLatLong = dc.Decode(temporaryLatLong);
            }
            var menu = document.getElementById('contextMenu');
            menu.style.display = 'block';
            menu.style.left = x + "px";
            menu.style.top = y + "px";
            contextMenuManager = new ContextMenuManager();
        }
        else {
            temporaryLatLong = e.latLong;
            var pixel = map.LatLongToPixel(e.latLong);
            var x = pixel.x + map.GetLeft();
            var y = pixel.y + map.GetTop();
            var menu = document.getElementById('contextMenu');
            var menuiframe = document.getElementById('contextMenuIframe');
            menu.style.display = 'block';
            menu.style.left = x + "px";
            menu.style.top = y + "px";
            menuiframe.style.display = 'block';
            menuiframe.style.left = x + "px";
            menuiframe.style.top = y + "px";
            contextMenuManager = new ContextMenuManager();
        }
    }
    this.HideContextMenu = function() {
        $get('contextMenu').style.display = 'none';
        $get('contextMenuIframe').style.display = 'none';
    }
    this.OnPanStarted = function(mapevent) { }
    this.OnPanEnded = function(mapevent) { }
    this.OnMapStyleChange = function() {
        var style = map.GetMapStyle();
        if (style == 'r') {
            map.SetMapStyle(VEMapStyle.Shaded);
        }
        axMap.OnEndZoom();
        axPage.SetPrintMenu();
    }
    this.SetCustomIcon = function(customHTML, poiNr, imageURL) {
        /// <summary>Set icon properties through VECustomIconSpecification</summary>
        // http://msdn.microsoft.com/en-us/library/bb412556.aspx  -  VECustomIconSpecification Class 
        var custSpec = new VECustomIconSpecification();

        var color = new VEColor(255, 255, 255, 1);

        if (imageURL == 1) {
            imageURL = imagesPath + "poi_search.gif";
        }
        else if (imageURL == 2) {
            imageURL = imagesPath + "poi_precise_location.gif";
        }
        else if (imageURL == 3) {
            imageURL = imagesPath + "poi_viewer.gif";
        }
        else if (imageURL == 4) {
            imageURL = imagesPath + "SpeedCameras/ges.gif";
            color = new VEColor(0, 0, 0, 1);
        }
        else if (imageURL == 5) {
            imageURL = imagesPath + "SpeedCameras/ampel.gif";
        }

        custSpec.Image = imageURL;
        // More than one digit numbers have less offset
        if (imageURL == imagesPath + "SpeedCameras/ges.gif") {
            if (poiNr > 99) {
                custSpec.TextOffset = new VEPixel(2, 6);
            }
            else {
                custSpec.TextOffset = new VEPixel(5, 6);
            }
        }
        else {
            if (poiNr > 9) {
                custSpec.TextOffset = new VEPixel(4, 5);
            }
            else if (poiNr > 99) {
                custSpec.TextOffset = new VEPixel(2, 5);
            }
            else {
                custSpec.TextOffset = new VEPixel(7, 5);
            }
        }

        custSpec.ForeColor = color;
        custSpec.TextSize = 7.5;
        custSpec.TextFont = "verdana,arial,sans-serif";

        // Custom HTML representing the pin's appearance. When specified, this HTML represents the pin's icon for 2D views only
        custSpec.CustomHTML = customHTML;
        custSpec.TextContent = poiNr.toString();

        return custSpec;
    }
    this.OnEndZoom = function() {
        if (map.GetZoomLevel() < 9) {
            if (exploreSpeedCameras) { speedCamerasLayer.DeleteAllShapes(); }
            if (exploreGasStations) { gasStationLayer.DeleteAllShapes(); }
        }
        else {
            if (exploreSpeedCameras) { axMap.ShowSpeedCameras(); }
            if (exploreGasStations) { axMap.ShowGasStations(); }
        }
    }
    this.ChangeZoomBtnEnabled = function() {
        if (map.GetZoomLevel() > 18) {
            var zoomInBtn = $get("MSVE_navAction_tinyZoomBar_plus");
            zoomInBtn.className = "MSVE_ZoomBar_plus";
        }
        if ((map.GetMapStyle() == 'b' || map.GetMapStyle() == 'o') && map.GetZoomLevel() < 2) {
            var zoomOutBtn = $get("MSVE_navAction_tinyZoomBar_minus");
            zoomOutBtn.className = "MSVE_ZoomBar_minus";
        }

    }
    this.OnDoubleClick = function() {
        axMap.ToggleBirdsEyeOnZoom();
    }
    this.OnMouseWheel = function() {
        axMap.ToggleBirdsEyeOnZoom();
    }
    this.SetZoom = function(a, b) {
        try {
            var s = map.GetMapStyle();
            if (s == "o") {
                map.SetMapStyle("r");
            }
            //var c = a % 10;
            //if (c == 0) {
            //    c = 10;
            //}
            var c;
            if (resultsOnPage != null) {
                c = a % resultsOnPage;
                if (c == 0) {
                    c = resultsOnPage;
                }
            }
            else {
                c = a % 10;
                if (c == 0) {
                    c = 10;
                }
            }
            map.SetCenterAndZoom(latLongList[c - 1], b)
        }
        catch (e) { }
    }
    this.ToggleBirdsEyeOnZoom = function() {
        ///<summary>If user is in „Luftbild“ view and in the highest zoom level and wants to zoom further, automatich switch to „Bird’s eye“ view will be made if available</summary>
        var zoom = map.GetZoomLevel();
        if ((map.GetMapStyle() == 'h' || map.GetMapStyle() == 'a') && map.IsBirdseyeAvailable() && zoom > 18) {
            map.SetBirdseyeScene(map.GetCenter());
        }

        if ((map.GetMapStyle() == 'b' || map.GetMapStyle() == 'o') && zoom == 1 && lastZoomLevel == zoom) {
            map.SetMapStyle(VEMapStyle.Aerial);

        }
        lastZoomLevel = zoom;
    }
    this.ShowLocation = function ShowLocation(locationResult) {
        axSearch.ShowMessage(L_Search_Result_for + " <b>" + locationResult.DisplayName + "</b>");

        shapesLayer.DeleteAllShapes();

        var latlong = new VELatLong(locationResult.Latitude, locationResult.Longitude);
        latLongList.length = 0;
        latLongList.push(latlong);
        var shape = new VEShape(VEShapeType.Pushpin, latlong);
        shape.SetCustomIcon(imagesPath + "poi_precise_location.gif");
        var content = "<div style='cursor: pointer; ' onmouseout='axPage.ShowSendToDropDown(false, \"sendtodropdown_0\")' onmousedown='axPage.ShowSendToDropDown(true, \"sendtodropdown_0\")'><a class='VE_Panel_sublink'>" + L_SEND_TO + "</a>";
        content += "<div onmouseover='axPage.ShowSendToDropDown(true, \"sendtodropdown_" + index + "\")' id='sendtodropdown_" + index + "' style='position: absolute; left: 7px; top: 18px; display: none; border: solid 1px #CCCCCC; background-color: #FFFFFF; text-align: center; padding: 3px 5px 3px 5px !important;'>";
        content += "<button onclick='axPage.EmailPermalink(\"" + "&where1=" + locationResult.DisplayName + "\")' type='button' style='' class='taskItem' title='" + L_SEND_PER_EMAIL + "' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)'>";
        content += "<div>";
        content += "<span style='padding: 0px 5px 0px 5px !important;'>E-Mail-Empf&auml;nger</span>";
        content += "</div>";
        content += "</button><br/>";
        if (showSuchagentPromotion) {
            content += "<button onclick='axPage.OpenSuchagent(\"" + locationResult.DisplayName + "\")' type='button' style='' class='taskItem' title='Zu Suchagent senden' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)'>";
            content += "<div>";
            content += "<span style='padding: 0px 5px 0px 5px !important;'>MSN Suchagent</span>";
            content += "</div>";
            content += "</button>";
        }
        content += "</div>";
        content += "</div>";

        var driving_directions = "<a href='javascript:SetDrvDirAdress(1,\"start\"," + "\"" + locationResult.DisplayName + "\"" + ");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveFrom + "</a> " + L_OR + " <a href='javascript:SetDrvDirAdress(1,\"end\"," + "\"" + locationResult.DisplayName + "\"" + ");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveTo + "</a>";

        var desc = "<div style='text-align:left;position:absolute;bottom:3px;background-color:#E4EDF3;left:2px;right:2px;height:65px;padding:4px 8px 15px;'>" + content + driving_directions + "<br/>" + L_ZOOMLEVEL_TYPE + ": <a href='javascript:axMap.SetZoom(1,16);' class='VE_Panel_sublink'>" + L_STREET + "</a> | <a href='javascript:axMap.SetZoom(1,11);''>" + L_CITY + "</a> | <a href='javascript:axMap.SetZoom(1,6);'' class='VE_Panel_sublink'>" + L_REGION + "</a></div>";
        shape.SetDescription(desc);
        shape.SetTitle("<div style='color:#444444;font-size:1.1em;margin-bottom:8px;height:80px;font-weight:normal;'>" + locationResult.DisplayName + "</div>");
        shapesLayer.AddShape(shape);
        precicePOIID = shape.GetID();

        var zoomlevel = 15;
        // EntityType - "Sovereign"(coutnry), "PopulatedPlace" (city), "Address" etc - http://msdn.microsoft.com/en-us/library/cc981001.aspx

        if (locationResult.EntityType == "Sovereign" || locationResult.EntityType == "Island") {
            zoomlevel = 7;
        }
        map.SetCenterAndZoom(latlong, zoomlevel);

        axSearch.ShowLocationResult(locationResult);
    }
    this.ShowPlace = function() {
        shapesLayer.DeleteAllShapes();

        var latlong = new VELatLong(results[0].LatLong.Latitude, results[0].LatLong.Longitude);
        var shape = new VEShape(VEShapeType.Pushpin, latlong);
        shape.SetCustomIcon(imagesPath + "poi_precise_location.gif");
        shape.SetDescription(results[0].Description);
        shapesLayer.AddShape(shape);
        map.SetCenterAndZoom(latlong, '16');
    }


    this.ShowPins = function() {
        var index = 0;
        shapesLayer.DeleteAllShapes();
        for (var i = 0; i < results.length; ++i) {
            if (results[i].LatLong != null) {
                var latlong = new VELatLong(results[i].LatLong.Latitude, results[i].LatLong.Longitude);
                if (results[i].No != null) {
                    index = results[i].No;
                }
                else {
                    index = i + 1;
                }
                var shape = new VEShape(VEShapeType.Pushpin, latlong);
                var icon = "<span id='resultPinMap_" + index + "' class='bullet_' onmouseover='changePin(this)' onmouseout='changePinBack(this)'>" + index + "</span>";

                // Create icon
                var custSpec = axMap.SetCustomIcon(icon, index, 1);
                shape.SetCustomIcon(custSpec);
                var totaladress = results[i].Address.AddressLine + ", " + results[i].Address.PostalCode + " " + results[i].Address.City;

                var driving_directions = "<a href='javascript:SetDrvDirAdress(" + index + ",\"start\"," + "\"" + totaladress + "\"" + ");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveFrom + "</a> " + L_OR + " <a href='javascript:SetDrvDirAdress(" + index + ",\"end\"," + "\"" + totaladress + "\"" + ");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveTo + "</a>";

                //Send To DropDown
                var content = "<div style='cursor: pointer; ' onmouseout='axPage.ShowSendToDropDown(false, \"sendtodropdown_" + index + "\")' onmousedown='axPage.ShowSendToDropDown(true, \"sendtodropdown_" + index + "\")'><a class='VE_Panel_sublink'>" + L_SEND_TO + "</a>";
                content += "<div onmouseover='axPage.ShowSendToDropDown(true, \"sendtodropdown_" + index + "\")' id='sendtodropdown_" + index + "' style='position: absolute; left: 7px; top: 18px; display: none; border: solid 1px #CCCCCC; background-color: #FFFFFF; text-align: center; padding: 3px 5px 3px 5px !important;'>";
                content += "<button type='button' style='' class='taskItem' title='" + L_SEND_PER_EMAIL + "' onmouseover='ChangeTaskBarButton(this)' onmouseout='ChangeTaskBarButtonBack(this)' onclick=\"axPage.OpenBusinessPermalink('" + results[i].BusinessID + "','" + escape(results[i].Address.CompanyName) + "','" + escape(totaladress) + "')\">";
                content += "<div>";
                content += "<span style='padding: 0px 5px 0px 5px !important;'>" + L_EMAIL_RECEIVER + "</span>";
                content += "</div>";
                content += "</button>";
                content += "</div>";
                content += "</div>";

                if (results[i].BusinessID == null || results[i].BusinessID == "") {
                    content = ""; ;
                }

                var desc = "<div style='text-align:left;position:absolute;bottom:3px;background-color:#E4EDF3;left:2px;right:2px;height:45px;width:300px;padding:4px 8px 15px;'>";
                desc += content + driving_directions + "<br/>" + L_ZOOMLEVEL_TYPE + ": <a href='javascript:axMap.SetZoom(" + index + ",16);' class='VE_Panel_sublink'>" + L_STREET + "</a> | <a href='javascript:axMap.SetZoom(" + index + ",11);''>" + L_CITY + "</a> | <a href='javascript:axMap.SetZoom(" + index + ",6);'' class='VE_Panel_sublink'>" + L_REGION + "</a></div>";

                var url = "";
                if (results[i].Address.Url != null) {
                    url = "<a href='" + results[i].Address.Url + "' target='_blank' style='#0066A7;text-decoration:none;'>" + results[i].Address.Url + "</a><br/>";
                }

                var companyName = "";
                if (results[i].Address.CompanyName != null) {
                    companyName = results[i].Address.CompanyName;
                }

                var _url = "";
                if (results[i].Address.Url != null) {
                    _url = results[i].Address.Url;
                }

                var address = "";
                if (results[i].Address.AddressLine != null) {
                    address = results[i].Address.AddressLine;
                }

                var city = "";
                if (results[i].Address.City != null) {
                    city = results[i].Address.City;
                }

                var zipcode = "";
                if (results[i].Address.PostalCode != null) {
                    zipcode = results[i].Address.PostalCode;
                }

                var phone = "";
                if (results[i].Address.Phone != null) {
                    phone = results[i].Address.Phone;
                }

                var _address = address + ", " + zipcode + " " + city;

                var vCardLink = encodeURIComponent(companyName + "_" + _url + "_" + _address + "_" + phone + "_" + results[i].LatLong.Latitude + "&" + results[i].LatLong.Longitude);
                var vCardPrefix = "vCard.aspx?";

                // Show logo on popup
                var SearchLogo = "";
                if (BusinessSearchLogo == true) {
                    SearchLogo = "<div class ='partnerLogo'></div>";
                }

                shape.SetTitle("<div style='text-align:left;color:#444444;font-size:1.1em;font-weight:bold;margin:0pt 0pt 8px;'>" + SearchLogo + "<a target='_blank' href='" + encodeURIComponent(results[i].DetailsUrl) + "'>" + results[i].Address.CompanyName + "</a></div><div style='text-align:left;color:#676767;font-size:0.9em;font-weight:normal;height:125px;'>" + address + "<br/>" + zipcode + " " + city + "<br/>" + phone + "<br/><div style='width: 100%; text-align: right;'><a id=\"vCardLink\" href=" + vCardPrefix + encodeURIComponent(vCardLink) + ">Outlook vCard</a><div></div>");
                shape.SetDescription(desc);
                shapesLayer.AddShape(shape);

                latLongList.push(latlong);
                pushPins.push(results[i]);
            }
        }

        // TODO:CircleClusteredShapes(shapesLayer, map.GetZoomLevel());

        if (latLongList.length > 0 && searchBusinessesBestMapView) {
            map.SetMapView(latLongList);
        }
        searchBusinessesBestMapView = false;
        axPage.ChangeTaskBarByName("Biz");
    }
    this.SetCenterAndZoom = function(lat, lon, zoom) {
        var latlong = new VELatLong(lat, lon);
        map.SetCenterAndZoom(latlong, zoom);
    }
    this.ShowGasStations = function() {
        var view = map.GetMapView();
        var topleft;
        var bottomright;
        var m = map.GetBirdseyeScene();
        if (m != null) {
            var dc = new _xy1;
            topleft = dc.Decode(view.TopLeftLatLong);
            bottomright = dc.Decode(view.BottomRightLatLong);
        }
        else {
            topleft = view.TopLeftLatLong;
            bottomright = view.BottomRightLatLong;
        }
        var style = map.GetMapStyle();
        $get("sorting_panel").style.visibilty = "hidden";
        if (map.GetZoomLevel() < 9 && style != VEMapStyle.Birdseye && style != VEMapStyle.BirdseyeHybrid) {
                    axSearch.ShowTaskHostLayer("collection");
                    $get("collections_body").innerHTML = "<a onclick='map.SetZoomLevel(9);' style='cursor:pointer;'>Bitte vergr\xf6\xdfern Sie den aktuellen Kartenausschnitt um Tankstellen anzeigen zu lassen.</a>";
                    return;
                }
        try {
            CallPageMethod("GetGasStations", { "topLeft": topleft, "bottomRight": bottomright, "top": 50 }, axMap.OnGetGasStationsSuccess, axMap.OnGetGasStationsError);
        }
        catch (e) { }
        searchBusinesses = false;
    }
    this.OnGetGasStationsSuccess = function(result, userContext, methodName) {
        axMap.DisplayGasStations(result);
    }
    this.OnGetGasStationsError = function(error) { }
    this.DisplayGasStations = function(result) {
        if (gasStationLayer == null) {
            gasStationLayer = new VEShapeLayer();
            map.AddShapeLayer(gasStationLayer);
        }

        gasStationLayer.DeleteAllShapes();

        var veClusteringOptions = new VEClusteringOptions();
        gasStationLayer.SetClusteringConfiguration(VEClusteringType.None, veClusteringOptions);
        
        for (var i = 0; i < result.length; i++) {
            var r = result[i];
            var latlong = new VELatLong(r.Latitude, r.Longitude);
            var shape = new VEShape(VEShapeType.Pushpin, latlong);
            var icon = "<img src='" + imagesPath + "gas_stations.png' style='height:30px;width:30px;'></img>";

            if (r.Description != null && r.Description != "") {
                _description += r.Description;
            }

            var title = "<div>";
            title += "<div style='text-align: left;'>";
            title += "<div>" + r.Name + "</div>";
            title += "</div>";
            title += "</div>";

            var desc = "<div style='text-align: left; height: 230px;'>";
            desc += "<b>Adresse</b>: " + r.Address + "<div class='clear'></div>";
            desc += "<b>Telefon</b>: " + r.Phone + "<div class='clear'></div>";
            desc += "<b>\xf6ffnungszeiten</b>:<div class='clear'></div>"
            desc += r.Opening + "<div class='clear'></div></br>";
            desc += "<b>Bezahlung</b>:" + r.Payment;
            desc += "</div>";

            var controlsLayer = "<div style='text-align:left; position:absolute; bottom:3px; background-color:#E4EDF3; left:2px; right:2px; height:40px; padding:10px 10px 10px 10px;'>";
            controlsLayer += "<div><a href='javascript:void(0);' onclick='_SetDrvDir(" + latlong.Latitude + "," + latlong.Longitude + ",\"start\");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveFrom + "</a> " + L_OR + " <a href='javascript:void(0);' onclick='_SetDrvDir(" + latlong.Latitude + "," + latlong.Longitude + ",\"end\");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveTo + "</a></div>";
            controlsLayer += "<div style='padding-top: 5px;'>" + L_ZOOMLEVEL_TYPE + ": <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",16)' class='VE_Panel_sublink'>" + L_STREET + "</a> | <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",11)'>" + L_CITY + "</a> | <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",6)' class='VE_Panel_sublink'>" + L_REGION + "</a></div>";
            controlsLayer += "</div>";

            shape.SetDescription(desc + controlsLayer);
            shape.SetCustomIcon(icon);
            shape.SetTitle(title);
            gasStationLayer.AddShape(shape);
        }
        var veCustomIconSpecification = new VECustomIconSpecification();
        veCustomIconSpecification.Image = imagesPath + "gas-station.gif";

        var veClusteringOptions = new VEClusteringOptions();
        veClusteringOptions.Icon = veCustomIconSpecification;

        L_ClusterDefaultTitle_Text = "%1 Tankstellen in diesem Bereich";
        L_ClusterDefaultDescription_Text = "Vergr\xf6\xdfern Sie den Kartenausschnitt f\xfcr weitere Details."

        gasStationLayer.SetClusteringConfiguration(VEClusteringType.Grid, veClusteringOptions);
    }
    this.ShowSpeedCameras = function() {
        var view = map.GetMapView();
        var topleft;
        var bottomright;
        var m = map.GetBirdseyeScene();
        if (m != null) {
            var dc = new _xy1;
            topleft = dc.Decode(view.TopLeftLatLong);
            bottomright = dc.Decode(view.BottomRightLatLong);
        }
        else {
            topleft = view.TopLeftLatLong;
            bottomright = view.BottomRightLatLong;
        }
        var style = map.GetMapStyle();
        $get("sorting_panel").style.visibilty = "hidden";
        if (map.GetZoomLevel() < 9 && style != VEMapStyle.Birdseye && style != VEMapStyle.BirdseyeHybrid) {
            axSearch.ShowTaskHostLayer("collection");
            $get("collections_body").innerHTML = "<a onclick='map.SetZoomLevel(9);' style='cursor:pointer;'>Bitte vergr\xf6\xdfern Sie den aktuellen Kartenausschnitt um Radarfallen anzeigen zu lassen.</a>";
            return;
        }
        try {
            CallPageMethod("GetSpeedCameras", { "topLeft": topleft, "bottomRight": bottomright, "top": 50 }, axMap.OnSpeedCamerasSuccess, axMap.OnSpeedCamerasError);
        }
        catch (e) { }
        searchBusinesses = false;
    }
    this.OnSpeedCamerasSuccess = function(result, userContext, methodName) {
        axMap.DisplaySpeedCameras(result);
    }
    this.OnSpeedCamerasError = function(error) { }

    this.DisplaySpeedCameras = function(result) {
        if (speedCamerasLayer == null) {
            speedCamerasLayer = new VEShapeLayer();
            map.AddShapeLayer(speedCamerasLayer);
        }

        speedCamerasLayer.DeleteAllShapes();

        var veClusteringOptions = new VEClusteringOptions();
        speedCamerasLayer.SetClusteringConfiguration(VEClusteringType.None, veClusteringOptions);

        for (var i = 0; i < result.length; i++) {
            var r = result[i];
            var latlong = new VELatLong(r.Latitude, r.Longitude);
            var shape = new VEShape(VEShapeType.Pushpin, latlong);
            var icon = "";
            var ampel = false;
            var vmax = r.Vmax;
            if (vmax == '' || vmax == "/" || vmax == null) {
                icon = "<img src='" + imagesPath + "SpeedCameras/ampel.gif' style='height:25px'></img>";
                ampel = true;
            }
            else if (vmax == '?') {
                icon = "<span class='speedCameraGes'>V</span>";
            }
            else {
                icon = "<span class='speedCameraGes'>" + vmax + "</span>";
            }


            var _street = ""; var _zip = ""; var _district = ""; var _location = ""; var _county = "";
            var _province = ""; var _country = ""; var _speedCameraType = ""; var _vmax = ""; var _status = "";
            var _direction = ""; var _description = ""; var _editDate = "";

            if (r.Country != null && r.Country != "")
                _country += "Land: " + r.Country;
            if (r.Province != null && r.Province != "")
                _province += "Bundesland: " + r.Province;
            if (r.County != null && r.County != "")
                _county += "Landkreis: " + r.County;
            if (r.Location != null && r.Location != "")
                _location += "Ort: " + r.Location;
            if (r.District != null && r.District != "")
                _district += "Ortsteil: " + r.District;

            if (r.StreetAddress != null && r.StreetAddress != "")
                _street += "Strasse: " + r.StreetAddress;
            if (r.Zip != null && r.Zip != "")
                _zip += "PLZ: " + r.Zip;

            if (r.SpeedCameraType != null && r.SpeedCameraType != "") {
                _speedCameraType += "Kamera typ: ";
                if (r.SpeedCameraType == "AK")
                    _speedCameraType += "Abstandskontrolle";
                if (r.SpeedCameraType == "AT")
                    _speedCameraType += "Attrappe";
                if (r.SpeedCameraType == "AFK")
                    _speedCameraType += "Auffahrtskontrolle";
                if (r.SpeedCameraType == "BK")
                    _speedCameraType += "Busspurkontrolle";
                if (r.SpeedCameraType == "EK")
                    _speedCameraType += "Einfahrtskontrolle";
                if (r.SpeedCameraType == "FGW")
                    _speedCameraType += "Fußgängerüberweg";
                if (r.SpeedCameraType == "G")
                    _speedCameraType += "Geschwindigkeit";
                if (r.SpeedCameraType == "GK")
                    _speedCameraType += "Gewichtskontrolle";
                if (r.SpeedCameraType == "HK")
                    _speedCameraType += "Höhenkontrolle";
                if (r.SpeedCameraType == "GA")
                    _speedCameraType += "Kombiniert, Rotlicht und Geschwindigkeit";
                if (r.SpeedCameraType == "A")
                    _speedCameraType += "Rotlicht";
                if (r.SpeedCameraType == "SC")
                    _speedCameraType += "Section Control";
                if (r.SpeedCameraType == "SCE")
                    _speedCameraType += "Section Control Ende";
                if (r.SpeedCameraType == "UHV")
                    _speedCameraType += "Überholverbot";
            }

            if (r.Vmax != null && r.Vmax != "") {
                _vmax = "Maximale Geschwindigkeit: ";
                if (r.Vmax == "/") {
                    _vmax += "nicht bekannt";
                }
                else if (r.Vmax == "?") {
                    _vmax += "variabel";
                }
                else {
                    if (r.Country == "GBR" || r.Country == "GB") {
                        _vmax += r.Vmax + "mp/h";
                    }
                    else {
                        _vmax += r.Vmax + "km/h";
                    }
                }
            }

            if (r.Status != null && r.Status != "") {
                _status += "Status: ";
                if (r.Status == "A")
                    _status += "Aktiv";
                if (r.Status == "L")
                    _status += "Lange nicht benutzt";
                if (r.Status == "Z")
                    _status += "Zerstört/Abgebaut";
            }

            if (r.Description != null && r.Description != "") {
                _description += r.Description;
            }

            var title = "<div style='height: 100px;'>";
            title += "<div style='text-align: left;'>";
            title += "<div>" + _country + "</div>";
            title += "<div>" + _province + "</div>";
            title += "<div>" + _county + "</div>";
            title += "<div>" + _location + "</div>";
            title += "<div>" + _district + "</div>";
            title += "<br/>";
            title += "<div>" + _street + "</div>";
            title += "<div>" + _zip + "</div>";
            title += "</div>";
            title += "</div>";

            var desc = "<div style='text-align: left; height: 145px;'>";
            desc += "<br/>";
            desc += "<div>" + _speedCameraType + "</div>";
            desc += "<div>" + _vmax + "</div>";
            desc += "<div>" + _status + "</div>";
            desc += "<div>" + _direction + "</div>";
            desc += "<br/>";
            desc += "<div>" + _description + "</div>";
            desc += "<div>";

            var controlsLayer = "<div style='text-align:left; position:absolute; bottom:3px; background-color:#E4EDF3; left:2px; right:2px; height:40px; padding:10px 10px 10px 10px;'>";
            controlsLayer += "<div><a href='javascript:void(0);' onclick='_SetDrvDir(" + latlong.Latitude + "," + latlong.Longitude + ",\"start\");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveFrom + "</a> " + L_OR + " <a href='javascript:void(0);' onclick='_SetDrvDir(" + latlong.Latitude + "," + latlong.Longitude + ",\"end\");' class='VE_Panel_sublink'>" + L_ContextMenu_DriveTo + "</a></div>";
            controlsLayer += "<div style='padding-top: 5px;'>" + L_ZOOMLEVEL_TYPE + ": <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",16)' class='VE_Panel_sublink'>" + L_STREET + "</a> | <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",11)'>" + L_CITY + "</a> | <a href='javascript:void(0);' onclick='axMap.SetCenterAndZoom(" + latlong.Latitude + "," + latlong.Longitude + ",6)' class='VE_Panel_sublink'>" + L_REGION + "</a></div>";
            controlsLayer += "</div>";

            var custSpec = null;
            if (ampel == true) {
                custSpec = axMap.SetCustomIcon(icon, vmax, 5);
            }
            else {
                custSpec = axMap.SetCustomIcon(icon, vmax, 4);
            }
            shape.SetCustomIcon(custSpec);

            shape.SetDescription(desc + controlsLayer);
            shape.SetTitle(title);
            speedCamerasLayer.AddShape(shape);
        }
        var veCustomIconSpecification = new VECustomIconSpecification();
        veCustomIconSpecification.Image = imagesPath + "SpeedCameras/ges-multi.gif";

        var veClusteringOptions = new VEClusteringOptions();
        veClusteringOptions.Icon = veCustomIconSpecification;

        L_ClusterDefaultTitle_Text = "%1 Radarfallen in diesem Bereich";
        L_ClusterDefaultDescription_Text = "Vergr\xf6\xdfern Sie den Kartenausschnitt f\xfcr weitere Details."

        speedCamerasLayer.SetClusteringConfiguration(VEClusteringType.Grid, veClusteringOptions);
    }
}

function format(str) {
  /// <summary> String.Format clone, turns arguments bold </summary>

  for(i = 1; i < arguments.length; i++) {
    str = str.replace('{' + (i - 1) + '}', "<strong>"+arguments[i]+"</strong>");
  }
  return str;
}

function formatLink(str) {
    /// <summary> String.Format clone </summary>

    for (i = 1; i < arguments.length; i++) {
        str = str.replace('{' + (i - 1) + '}', arguments[i]);
    }
    return str;
}

function removeHTMLTags(htmlString) {
    /// <summary> Removes HTML tags </summary>
    if (htmlString) {
        var mydiv = document.createElement("div");
        mydiv.innerHTML = htmlString;

        if (document.all) // IE Stuff
        {
            return mydiv.innerText;

        }
        else // Mozilla does not work with innerText
        {
            return mydiv.textContent;
        }
    }
}

