﻿
function QueryManager() {
    this.a = new Object();

    this.GetQueryString = function () {
        var s = '';
        for (var i in this.a) {
            if (s.length > 0)
                s += "&";
            if (typeof (i) != "null" && this.a[i])
                s += i + "=" + this.a[i];
        }
        return s;
    }
    this.AdrRouteMode = function (startAddress, stopAddress, pickStartAddress, pickStopAddress, id, csys, fromXpos, fromYpos, toXpos, toYpos) {
        this.SetMode("adrroute");
        this.a["startAddress"] = startAddress;
        this.a["stopAddress"] = stopAddress;
        this.a["pickStartAddress"] = pickStartAddress;
        this.a["pickStopAddress"] = pickStopAddress;
        this.a["id"] = id;
        this.a["csys"] = csys;
        this.a["fromXpos"] = fromXpos;
        this.a["fromYpos"] = fromYpos;
        this.a["toXpos"] = toXpos;
        this.a["toYpos"] = toYpos;
    }
    this.AdrBingRouteMode = function (startAddress, stopAddress) {
        this.SetMode("BingAddressRoute");
        this.a["startAddress"] = startAddress;
        this.a["stopAddress"] = stopAddress;

    }
    this.AddressMode = function (xpos, ypos, adrinfo) {
        this.SetMode("adr");
        this.a["xpos"] = xpos;
        this.a["ypos"] = ypos;
        this.a["adrinfo"] = adrinfo;
    }
    this.CustAdrMode = function (id) {
        this.SetMode("custadr");
        this.SetID(id);
    }
    this.HotelAddressMode = function (id) {
        this.SetMode("hoteladr");
        this.SetID(id);
    }
    this.SetMode = function (mode) {
        this.a["mode"] = mode;
    }
    this.SetID = function (pkey) {
        this.a["id"] = pkey;
    }
    this.GetKeyCount = function () {
        var c = 0;
        for (var i in this.a) {
            if (i && this.a[i])
                c++;
        }
        return c;
    }
}

function AtlasMan() {
    this.minSearchLength = 3;
    this.weatherEnabled = null;
    var gpsManager;
    var tiManager;
    var weatherManager;
    this.querymanager = null;
    var ImgExt = ".png";
    var originalMap = 'nk';
    var biFlag = false;
    var birdseye = null;
    var beRotateRight = null;
    var beRotateLeft = null;
    var vektor = null;
    var fromBirdsEye = false;
    var gpsButtonImageActive = new Image();
    gpsButtonImageActive.src = 'images/mnu/sm_gpsA' + ImgExt;
    var flyButtonImageActive = new Image();
    flyButtonImageActive.src = 'images/mnu/sm_photoA' + ImgExt;
    var vektorButtonImageActive = new Image();
    vektorButtonImageActive.src = 'images/mnu/sm_mapA' + ImgExt;
    var hybridButtonImageActive = new Image();
    hybridButtonImageActive.src = 'images/mnu/sm_hybridA' + ImgExt;
    var weatherButtonImageActive = new Image();
    weatherButtonImageActive = 'images/mnu/sm_weatherA' + ImgExt;

    tiManager = new AtlasTrafikkInfo();

    this.SetOrginalMap = function (om) {
        originalMap = om;
        var verden = document.getElementById("setVerdenskartButton");
        var norge = document.getElementById("setNorgeskartButton");
        if (originalMap == 've') {
            if (norge) {
                norge.src = 'images/mnu/sm_Norgeskart' + ImgExt;
            }
            if (verden) {
                verden.src = 'images/mnu/sm_VerdenskartA' + ImgExt;
            }
        }
        else {
            if (norge) {
                norge.src = 'images/mnu/sm_NorgeskartA' + ImgExt;
            }
            if (verden) {
                verden.src = 'images/mnu/sm_Verdenskart' + ImgExt;
            }
        }
    }
    this.SetPngIncapable = function () {
        ImgExt = ".gif";
    }
    this.DeterminePngCapable = function (pngincapable) {
        if (pngincapable)
            this.SetPngIncapable();
    }

    this.zoomedOut = function () {
        if (bVEMap == false) {

            zl = map.getZoomLevel();
            if (zl > 12) {
                weatherManager.disableWeather();
            }
        }
        else {
            vezl = vemap.GetZoomLevel();
            if (vezl < 8) {
                weatherManager.disableWeather();
            }
        }
        return false;
    }
    this.SetAllMapStyleButtonInActive = function () {
        var norge = document.getElementById("setNorgeskartButton");
        var verden = document.getElementById("setVerdenskartButton");
        var hybrid = document.getElementById("setMapStyleHybridButton");
        vektor = document.getElementById("setMapStyleVektorButton");
        var fly = document.getElementById("setMapStyleFlyButton");
        birdseye = document.getElementById("setBirdsEyeButton");
        if (originalMap == 've') {
            if (norge) {
                norge.src = 'images/mnu/sm_Norgeskart' + ImgExt;
            }
        }
        else {
            if (verden) {
                verden.src = 'images/mnu/sm_Verdenskart' + ImgExt;
            }
        }
        hybrid.src = 'images/mnu/sm_hybrid' + ImgExt;
        vektor.src = 'images/mnu/sm_map' + ImgExt;
        fly.src = 'images/mnu/sm_photo' + ImgExt;
        if (birdseye) birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
    }
    this.SetMapStyleButtonActive = function (img, imgsrc) {
        this.SetAllMapStyleButtonInActive();
        if (img != null) {
            if (imgsrc != '') {
                img.src = imgsrc;
                img.style.cursor = 'pointer';
            }
            img.disabled = false;
        }
    }
    this.DisableMapStyleButton = function (img, imgsrc) {
        if (img != null) {
            if (imgsrc != '') {
                img.src = imgsrc;
                img.style.cursor = 'default';
            }
            img.disabled = true;
        }
    }
    this.MapStyleChanged = function (e) {
        return true;
    }

    this.ChangeToVE = function (img) {
        this.DisableMapStyleButton($('mainctrl1_compSearchPanel'), '');
        this.DisableMapStyleButton($('mainctrl1_companySearchTxt'), '');
        this.DisableMapStyleButton($('mainctrl1_searchCompanyButton'), 'images/sokbuttonD.gif');
        this.SetMapStyleButtonActive($('adrroute'), 'images/mnu/sm_route' + ImgExt);
        this.DisableMapStyleButton($('toggleTrafikkInfoButton'), 'images/mnu/sm_trafikkinfoD' + ImgExt);
        this.DisableGPSAndWeather();
        fromBirdsEye = false; 
        vemap.DeleteAllShapes();
        originalMap = 've';
        bVEMap = true;
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_VerdenskartA' + ImgExt);
        this.SetMapStyleButtonActive(vektor, 'images/mnu/sm_mapA' + ImgExt);
        vemap.SetMapStyle(VEMapStyle.Shaded);
        if (null != veCenter) {
            vemap.SetCenter(veCenter);
        }
        if (null != veZoom) {
            vemap.SetZoomLevel(veZoom);
        }
        veMiniMapExtender.Hide();
        if (null != birdseye) {
            if (vemap.IsBirdseyeAvailable()) {
                birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
            }
            else {
                birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
            }
        }
        this.SetMapVisible('ve');
    }
    this.ChangeToNK = function (img) {
        this.SetMapStyleButtonActive($('mainctrl1_compSearchPanel'), '');
        this.SetMapStyleButtonActive($('mainctrl1_companySearchTxt'), '');
        this.SetMapStyleButtonActive($('mainctrl1_searchCompanyButton'), 'images/sokbutton.gif');
        this.SetMapStyleButtonActive($('adrroute'), 'images/mnu/sm_route' + ImgExt);
        this.SetMapStyleButtonActive($('toggleTrafikkInfoButton'), 'images/mnu/sm_trafikkinfo' + ImgExt);
        this.DisableGPSAndWeather();
        fromBirdsEye = false;
        originalMap = 'nk';
        bVEMap = false;
        vemap.SetMapStyle(VEMapStyle.Shaded);
        this.GetVEZoomAndCenter();
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_NorgeskartA' + ImgExt);
        this.setMapStyleVektor(vektor);
        this.isBirdsEyeAvail();//jeh
        if (vemap.IsBirdseyeAvailable()) {
            birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
        }
        else {
            birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
        }
    }
    this.setMapStyleFly = function (img) {
        this.SetMapStyleButtonActive($('enableGpsButton'), 'images/mnu/sm_gps' + ImgExt);
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_photoA' + ImgExt);
        if (originalMap == 've') {
            bVEMap = true;
            fromBirdsEye = false;
            veMiniMapExtender.Hide();
            vemap.SetMapStyle(VEMapStyle.Aerial);
            this.SetMapVisible('ve');
        }
        else {
            if (fromBirdsEye) {
                fromBirdsEye = false;
                this.SetNKMapCenterAndZoom(2);
            }
            bVEMap = false;
            map.setMapStyle(1);
            this.SetMapVisible('nk');
        }
        if (vemap.IsBirdseyeAvailable()) {
            birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
        }
        else {
            birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
        }
    }
    this.setMapStyleVektor = function (img) {
        this.SetMapStyleButtonActive($('enableGpsButton'), 'images/mnu/sm_gps' + ImgExt);
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_mapA' + ImgExt);
        if (bVEMap) {
            veMiniMapExtender.Hide();
        }
        if (originalMap == 've') {
            bVEMap = true;
            fromBirdsEye = false;
            vemap.SetMapStyle(VEMapStyle.Shaded);
            this.SetMapVisible('ve');
        }
        else {
            if (fromBirdsEye) {
                fromBirdsEye = false;
                this.SetNKMapCenterAndZoom(2);
            }
            bVEMap = false;
            map.setMapStyle(0);
            this.SetMapVisible('nk');
        }
        if (vemap.IsBirdseyeAvailable()) {
            birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
        }
        else {
            birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
        }
    }
    this.setMapStyleHybrid = function (img) {
        this.SetMapStyleButtonActive($('enableGpsButton'), 'images/mnu/sm_gps' + ImgExt);
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_hybridA' + ImgExt);
        if (bVEMap) {
            veMiniMapExtender.Hide();
        }
        if (originalMap == 've') {
            bVEMap = true;
            fromBirdsEye = false;
            vemap.SetMapStyle(VEMapStyle.Hybrid);
            this.SetMapVisible('ve');
        }
        else {
            if (fromBirdsEye) {
                fromBirdsEye = false;
                this.SetNKMapCenterAndZoom(2);
            }
            bVEMap = false;
            map.setMapStyle(2);
            this.SetMapVisible('nk');
        }
        if (vemap.IsBirdseyeAvailable()) {
            birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
        }
        else {
            birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
        }
    }
    this.BirdsEyeOn = function (img) {
        if (biFlag == false) {
            return;
        }
        this.DisableGPSAndWeather();
        this.DisableMapStyleButton($('enableGpsButton'), 'images/mnu/sm_gpsD' + ImgExt);
        this.SetMapStyleButtonActive(img, 'images/mnu/sm_SkraafotoA' + ImgExt);
        var latlonSenter = vemap.GetCenter();
        vemap.SetBirdseyeOrientation(VEOrientation.North);
        this.SetBirdsEyeBtn(1, img);
        ChangedToRoad = false;
        vemap.SetFailedShapeRequest(VEFailedShapeRequest.QueueRequest);
        //vemap.SetShapesAccuracyRequestLimit(51);
        vemap.SetShapesAccuracy(VEShapeAccuracy.All)
       

        veMiniMapExtender.Show();
        vemap.SetMapStyle(VEMapStyle.Birdseye);
        vemap.SetCenter(latlonSenter);

        if (originalMap == 'nk') {
             var nkMidt = map.getCenterCoordinate();
            var nkMidtLatLong = map.UTMToLatLon(nkMidt);
            var veMidtLong = new VELatLong(nkMidtLatLong.y, nkMidtLatLong.x);
            vemap.SetCenter(veMidtLong);
            fromBirdsEye = true;
            vemap.DeleteAllShapes();
            var o = map.getAnnotations();
            var nOfAnn = 0;
            for (i = 0; i < o.length; i++) {
                var d = o[i];
                var nkCoordAn = d.coordinate;
                bbr = map.getBoundingBox();
                if (nkCoordAn.x < bbr.left || nkCoordAn.x > bbr.right) continue;
                if (nkCoordAn.y > bbr.top || nkCoordAn.y < bbr.bottom) continue;
                ++nOfAnn;
                var nkLatLongAn = map.UTMToLatLon(nkCoordAn);
                var veLatLongAn = new VELatLong(nkLatLongAn.y, nkLatLongAn.x);
                c1Shape = new VEShape(VEShapeType.Pushpin, veLatLongAn);
                iconfile = d.iconURL;

                var idof = -1;
                if (iconfile != null) idof = iconfile.indexOf("flag_blue");

                var pin = new VEShape(VEShapeType.Pushpin, veLatLongAn);
                if (idof != -1) {
                    pin.SetTitle('');
                    var icon1 = '<div id=\"bingaddressinfodiv\"  style=\"background-image: url(./images/addressdialog.png); position:relative;top:-121px;left:-67px;  background-repeat: no-repeat; font-size: x-small; font-weight: bold; height: 121px; width:138px; border: none; z-index: 99999\"><table width=\"138px\"><tr><td style=\"height: 11px; width: 124px;\">&nbsp;</td><td style=\"width: 14px;\"><img src=\"images/dialog_close.gif\" style=\"cursor:pointer\" onclick=\"closeBingAddressDialog()\" /></td></tr><tr><td colspan=\"2\"><div class=\"addressdialogbody\">';
                    var icon2 = '</div></td></tr></table></div>';
                    var icon = icon1 + d.element.innerText + icon2;
                    pin.SetCustomIcon(icon);
                    vemap.AddShape(pin);
                }
                else {
                    var icon1 = "<div style='position:relative;top:" + d.yOffset + "px;left:" + d.xOffset + "px;'><img src=";
                    var icon2 = "></div>";
                    pin.SetTitle(d.title == 'test' ? '' : d.title);
                    pin.SetDescription(d.description == 'test' ? '' : d.description);
                    pin.SetCustomIcon(icon1 + iconfile + icon2);
                    vemap.AddShape(pin);
                }
            }
            bVEMap = true;
        }
        this.SetMapVisible('ve');
    }
    this.SetBITrue = function () {
        if (null == birdseye) {
            birdseye = document.getElementById('setBirdsEyeButton');
        }
        if (null != birdseye) {
            birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
            birdseye.style.cursor = 'pointer';
        }
        if (null == beRotateRight) {
            beRotateRight = document.getElementById('beRotateRightButton');
        }
        if (beRotateRight != null) {
            beRotateRight.src = 'images/mnu/sm_rotateRight.gif';
            beRotateRight.disabled = false;
        }
        if (null == beRotateLeft) {
            beRotateLeft = document.getElementById('beRotateLeftButton');
        }
        if (beRotateLeft != null) {
            beRotateLeft.src = 'images/mnu/sm_rotateLeft.gif';
            beRotateLeft.disabled = false;
        }
        biFlag = true;
        return true;
    }

    this.SetBIFalse = function () {
        if (null == birdseye) {
            birdseye = document.getElementById('setBirdsEyeButton');
        }
        if (null != birdseye) {
            birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
            birdseye.style.cursor = 'default';
        }
        if (null == beRotateRight) {
            beRotateRight = document.getElementById('beRotateRightButton');
        }
        if (beRotateRight != null) {
            beRotateRight.src = 'images/mnu/sm_rotateRightDisabled.gif';
            beRotateRight.disabled = true;
        }
        if (null == beRotateLeft) {
            beRotateLeft = document.getElementById('beRotateLeftButton');
        }
        if (beRotateLeft != null) {
            beRotateLeft.src = 'images/mnu/sm_rotateLeftDisabled.gif';
            beRotateLeft.disabled = true;
        }
        biFlag = false;
        veMiniMapExtender.Hide();
        if (originalMap == 'nk' && fromBirdsEye == true) {
            var zl = vemap.GetZoomLevel();
            var veLatlong = vemap.GetCenter();
            var nkLatlong = new Coordinate(veLatlong.Longitude, veLatlong.Latitude);
            var nkCenter = map.decimalDegreesToUTM(nkLatlong);
            map.centerAndZoom(nkCenter, 2);
            this.SetMapVisible('nk');
        }
        return true;
    }
    this.isBirdsEyeAvail = function () {
        if (originalMap == 've') {
            return;
        }
        if (null == birdseye) {
            birdseye = document.getElementById('setBirdsEyeButton');
        }
        mapCenter = map.getCenterCoordinate();
        nkLatLongCenter = map.UTMToLatLon(mapCenter);
        veLatLongCenter = new VELatLong(nkLatLongCenter.y, nkLatLongCenter.x);
        nkZoomLevel = map.getZoomLevel();
        // vezoomlevel = 18 - nkZoomLevel;
        vezoomlevel = nkZoomLevel; // MH 12.05.2010
        vemap.SetCenterAndZoom(veLatLongCenter, vezoomlevel);
        if (null != birdseye) {
            if (vemap.IsBirdseyeAvailable()) {
                birdseye.src = 'images/mnu/sm_Skraafoto' + ImgExt;
                birdseye.style.cursor = 'pointer';

                if (null == beRotateLeft) {
                    beRotateLeft = document.getElementById('beRotateLeftButton');
                }
                if (beRotateLeft != null) {
                    beRotateLeft.src = 'images/mnu/sm_rotateLeft.gif';
                    beRotateLeft.disabled = false;
                }
                if (null == beRotateRight) {
                    beRotateRight = document.getElementById('beRotateRightButton');
                }
                if (beRotateRight != null) {
                    beRotateRight.src = 'images/mnu/sm_rotateRight.gif';
                    beRotateRight.disabled = false;
                }
            }
            else {
                birdseye.src = 'images/mnu/sm_SkraafotoD' + ImgExt;
                birdseye.style.cursor = 'default';
            }
        }
    }
    this.recalculateShapePosition = function (bm) {
        var zl = bm.zoomLevel
        var wb = document.getElementById('toggleWeatherButton');
        if (zl < 8) {
            wb.src = 'images/mnu/sm_weatherD' + ImgExt;
            wb.style.cursor = 'default';
            wb.disabled = true;
            if (weatherManager) {
                if (weatherManager.WeatherIsEnabled())
                    weatherManager.disableWeather();
            }
        }
        else {
            wb.src = 'images/mnu/sm_weather' + ImgExt;
            wb.style.cursor = 'pointer';
            wb.disabled = false;
        }
    }
    this.BeRotateLeftBtnDown = function (btn) {
        if (biFlag) {
            btn.src = 'images/mnu/sm_rotateLeftD.gif';
            btn.disabled = false;
        }
    }
    this.BeRotateLeftBtnUp = function (btn) {
        if (biFlag) {
            btn.src = 'images/mnu/sm_rotateLeft.gif';
            btn.disabled = false;
        }
    }
    this.BeRotateRightBtnDown = function (btn) {
        if (biFlag) {
            btn.src = 'images/mnu/sm_rotateRightD.gif';
            btn.disabled = false;
        }
    }
    this.BeRotateRightBtnUp = function (btn) {
        if (biFlag) {
            btn.src = 'images/mnu/sm_rotateRight.gif';
            btn.disabled = false;
        }
    }
    this.RotateLeft = function () {
        if (vemap.IsBirdseyeAvailable()) {
            var be = vemap.GetBirdseyeScene();
            var orientation = be.GetOrientation();
            switch (orientation) {
                case 'North': vemap.SetBirdseyeOrientation(VEOrientation.East);
                    break;
                case 'South': vemap.SetBirdseyeOrientation(VEOrientation.West);
                    break;
                case 'East': vemap.SetBirdseyeOrientation(VEOrientation.South);
                    break;
                default: vemap.SetBirdseyeOrientation(VEOrientation.North);
                    break;
            }
            this.recalculateShapePosition(vemap);
        }
    }
    this.RotateRight = function () {
        if (vemap.IsBirdseyeAvailable()) {
            var be = vemap.GetBirdseyeScene();
            var orientation = be.GetOrientation();
            switch (orientation) {
                case 'North': vemap.SetBirdseyeOrientation(VEOrientation.West);
                    break;
                case 'South': vemap.SetBirdseyeOrientation(VEOrientation.East);
                    break;
                case 'East': vemap.SetBirdseyeOrientation(VEOrientation.North);
                    break;
                default: vemap.SetBirdseyeOrientation(VEOrientation.South);
                    break;
            }
            this.recalculateShapePosition(vemap);
        }
    }
    this.ZoomIn = function () {
        if (bVEMap) {
            vemap.ZoomIn();
        }
        else {
            map.zoomIn();
        }
    }
    this.ZoomOut = function () {
        if (bVEMap) {
            vemap.ZoomOut();
        }
        else {
            map.zoomOut();
        }
    }
    this.WeatherDisabled = function () {
        var wb = document.getElementById("toggleWeatherButton");
        wb.src = 'images/mnu/sm_weatherD' + ImgExt;
    }
    this.WeatherEnabled = function () {
        var wb = document.getElementById("toggleWeatherButton");
        wb.src = 'images/mnu/sm_weatherA' + ImgExt;
    }
    this.OnWeatherClick = function (img) {
        if (weatherManager) {
            this.disableGps();
            weatherManager.ToggleWeather();
        }
    }
    this.SetTIManager = function (obj) {
        tiManager = obj;
    }
    this.onTIDisabled = function () {
        var e = document.getElementById('toggleTrafikkInfoButton');
        e.src = 'images/mnu/sm_Trafikkinfo' + ImgExt;
    }
    this.disableTI = function () {
        if (tiManager) {
            if (tiManager.tiIsEnabled())
                tiManager.disableTI();
        }
    }
    this.ToggleTrafikkInfo = function (img, map) {
        if (tiManager) {
            if (!tiManager.tiIsEnabled()) {
                img.src = 'images/mnu/sm_TrafikkInfoA' + ImgExt;
                tiManager.enableTI(this.onTIDisabled);
                tiManager.showTI(map);
            }
            else
                tiManager.disableTI();
        }
    }
    this.onGpsDisabled = function () {
        var e = document.getElementById('enableGpsButton');
        e.src = 'images/mnu/sm_gps' + ImgExt;
    }
    this.disableGps = function () {
        if (gpsManager) {
            if (gpsManager.gpsIsEnabled())
                gpsManager.disableGps();
        }
    }
    this.disableWeather = function () {
        if (weatherManager) {
            if (weatherManager.WeatherIsEnabled())
                weatherManager.disableWeather();
        }
    }
    this.ToggleGps = function (img) {
        if (gpsManager) {
            if (!gpsManager.gpsIsEnabled()) {
                img.src = 'images/mnu/sm_gpsA' + ImgExt;
                gpsManager.enableGps(this.onGpsDisabled);
                this.disableWeather();
            }
            else
                gpsManager.disableGps();
        }
    }
    this.onRouteClick = function () {
        if (bVEMap && originalMap!='nk') {
            window.location = 'Default.aspx?mode=BingAddressRoute'; //jeh 2009.12.18
        }
        else {
            window.location = 'Default.aspx?mode=adrroute';
        }
    }
    this.SetGpsManager = function (obj) {
        gpsManager = obj;
    }
    this.SetWeatherManager = function (obj) {
        weatherManager = obj;
    }
    this.searchAddress = function (eid) {
        var adrInput = $(eid);
        if (adrInput.value.length < this.minSearchLength) {
            alert("Søkestrengen er for kort, vennligst prøv igjen.");
            return false;
        }
        else
            return true;
    }
    this.searchCompany = function (eid) {
        var compInput = $(eid);
        if (compInput.value.length < this.minSearchLength) {
            alert("Søkestrengen er for kort, vennligst prøv igjen.");
            return false;
        }
        else
            return true;
    }
    this.onPrintMapClick = function (img) {
        this.printMap(img);
    }
    this.printMap = function (img) {
        if (bVEMap) {
            var zl = vemap.GetZoomLevel();
            var latlong = vemap.GetCenter();
            var mapstyle = vemap.GetMapStyle();

            if (mapstyle == 'b' || mapstyle == 'o') {
                vemap.SetMapStyle('r');
                latlong = vemap.GetCenter();
                vemap.SetMapStyle(mapstyle);
            }
            var bingextra = '';
            if (!Object.isUndefined(this.querymanager) && this.querymanager != null) {
                bingextra = this.querymanager.GetQueryString();
            }
            var s1 = 'printbingmap.aspx?x=' + latlong.Longitude + "&y=" + latlong.Latitude + "&zl=" + zl + "&ms=" + mapstyle + "&" + bingextra + ",";
            window.open(s1, '_blank', 'width=700, height=600, resizable=yes, scrollbars=yes');
        }
        else {
            var c = map.getCenterCoordinate();
            var zoomLevel = map.getZoomLevel();
            var ms = map.getMapStyle();
            var extra = '';
            if (!Object.isUndefined(this.querymanager) && this.querymanager != null) {
                extra = this.querymanager.GetQueryString();
            }
            window.open('printmap.aspx?x=' + c.x + "&y=" + c.y + "&zl=" + zoomLevel + "&ms=" + ms + "&" + extra, '_blank', 'width=700, height=600, resizable=yes, scrollbars=yes');
        }

    }
    this.onPrintBingMapClick = function (img) {
        this.printBingMap(img);
    }
    this.printBingMap = function (img) {
        var zl = vemap.GetZoomLevel();
        var latlong = vemap.GetCenter();
        var mapstyle = vemap.GetMapStyle();

        if (mapstyle == 'b' || mapstyle == 'o') {
            vemap.SetMapStyle('r');
            latlong = vemap.GetCenter();
            vemap.SetMapStyle(mapstyle);
        }
        var bingextra = '';
        if (!Object.isUndefined(this.querymanager) && this.querymanager != null) {
            bingextra = this.querymanager.GetQueryString();
        }
        var s1 = 'printbingmap.aspx?x=' + latlong.Longitude + "&y=" + latlong.Latitude + "&zl=" + zl + "&ms=" + mapstyle + "&" + bingextra + ",";
        window.open(s1, '_blank', 'width=700, height=600, resizable=yes, scrollbars=yes');
    }
    this.onEmailMapClick = function (img) {
        var c = map.getCenterCoordinate();
        var zoomLevel = map.getZoomLevel();
        var ms = map.getMapStyle();
        var extra = '';
        if (!Object.isUndefined(this.querymanager) && this.querymanager != null) {
            extra = this.querymanager.GetQueryString();
        }
        if (!Object.isUndefined(gpsManager)) {
            if (gpsManager != null) {
                if (gpsManager.gpsIsEnabled()) {
                    var gpsPos = gpsManager.getPosition();
                    if (extra.len > 0)
                        extra += "&";
                    extra += 'gpsx=' + gpsPos.x + '&gpsy=' + gpsPos.y;
                }
            }
        }
        window.open('emailmap.aspx?x=' + c.x + "&y=" + c.y + "&zl=" + zoomLevel + "&ms=" + ms + "&" + extra, '_blank', 'width=290, height=300, resizable=no');
    }
    this.onEmailBingMapClick = function (img) {
        var latLonCenter = vemap.GetCenter();
        var zoomLevel = vemap.GetZoomLevel();
        var veMapStyle = vemap.GetMapStyle();
        var extra = '';
        if (!Object.isUndefined(this.querymanager) && this.querymanager != null) {
            extra = this.querymanager.GetQueryString();
        }
        if (!Object.isUndefined(gpsManager)) {
            if (gpsManager != null) {
                if (gpsManager.gpsIsEnabled()) {
                    var gpsPos = gpsManager.getPosition();
                    if (extra.len > 0)
                        extra += "&";
                    extra += 'gpsx=' + gpsPos.x + '&gpsy=' + gpsPos.y;
                }
            }
        }
        window.open('emailmap.aspx?x=' + latLonCenter.Latitude + "&y=" + latLonCenter.Longitude + "&zl=" + zoomLevel + "&ms=" + veMapStyle + "&" + extra, '_blank', 'width=290, height=300, resizable=no');
    }
    this.moveUp = function () {
        if (bVEMap) {
            var pixel = vemap.LatLongToPixel(vemap.GetCenter(), vemap.GetZoomLevel());
            pixel.y = pixel.y - 500;
            vemap.SetCenter(vemap.PixelToLatLong(pixel));
        }
        else {
            map.move({ 'x': 0, 'y': 500 });
        }
    }
    this.moveLeft = function () {
        if (bVEMap) {
            var pixel = vemap.LatLongToPixel(vemap.GetCenter(), vemap.GetZoomLevel());
            pixel.x = pixel.x + 500;
            vemap.SetCenter(vemap.PixelToLatLong(pixel));
        }
        else {
            map.move({ 'x': 500, 'y': 0 });
        }
    }
    this.moveRight = function () {
        if (bVEMap) {
            var pixel = vemap.LatLongToPixel(vemap.GetCenter(), vemap.GetZoomLevel());
            pixel.x = pixel.x - 500;
            vemap.SetCenter(vemap.PixelToLatLong(pixel));
        }
        else {
            map.move({ 'x': -500, 'y': 0 });
        }
    }
    this.moveDown = function () {
        if (bVEMap) {
            var pixel = vemap.LatLongToPixel(vemap.GetCenter(), vemap.GetZoomLevel());
            pixel.y = pixel.y + 500;
            vemap.SetCenter(vemap.PixelToLatLong(pixel));
        }
        else {
            map.move({ 'x': 0, 'y': -500 });
        }
    }
    this.onNavUpMouseDown = function () {
        var navtd = document.getElementById('navtd');
        navtd.className = 'navUp';
    }
    this.onNavDownMouseDown = function () {
        var navtd = document.getElementById('navtd');
        navtd.className = 'navDown';
    }
    this.onNavRightMouseDown = function () {
        var navtd = document.getElementById('navtd');
        navtd.className = 'navRight';
    }
    this.onNavLeftMouseDown = function () {
        var navtd = document.getElementById('navtd');
        navtd.className = 'navLeft';
    }
    this.onNavMouseUp = function () {
        var navtd = document.getElementById('navtd');
        navtd.className = 'navNormal';
    }
    this.SetBirdsEyeBtn = function (status, btn) {
        if (status == 1) {
            if (null != btn) {
                if (vemap.IsBirdseyeAvailable()) {
                    btn.src = 'images/mnu/sm_SkraafotoA' + ImgExt; // PerK 22062009 - byttet bilde
                }
                else {
                    btn.src = 'images/mnu/sm_SkraafotoD' + ImgExt; // PerK 22062009 - byttet bilde
                }
            }
        }
        else {
            if (null != btn) {
                if (vemap.IsBirdseyeAvailable()) {
                    btn.src = 'images/mnu/sm_Skraafoto' + ImgExt; // PerK 22062009 - byttet bilde
                }
                else {
                    btn.src = 'images/mnu/sm_SkraafotoD' + ImgExt; // PerK 22062009 - byttet bilde
                }
            }
        }
    }
    this.GetVEZoomAndCenter = function () {
        veCenter = vemap.GetCenter();
        veZoom = vemap.GetZoomLevel();
    }
    this.DisableGPSAndWeather = function () {
        if (gpsManager) {
            gpsManager.disableGps();
        }
        this.disableWeather();
    }
    this.veAtStartupInit = function () {
        this.DisableMapStyleButton($('mainctrl1_compSearchPanel'), '');
        this.DisableMapStyleButton($('mainctrl1_companySearchTxt'), '');
        this.DisableMapStyleButton($('mainctrl1_searchCompanyButton'), 'images/sokbuttonD.gif');
        this.SetMapStyleButtonActive($('adrroute'), 'images/mnu/sm_route' + ImgExt);
        this.DisableMapStyleButton($('toggleTrafikkInfoButton'), 'images/mnu/sm_trafikkinfoD' + ImgExt);
    }
    this.SetNKMapCenterAndZoom = function (z2) {
        vemap.SetMapStyle(VEMapStyle.Shaded);
        var zl = vemap.GetZoomLevel();
        var veLatlong = vemap.GetCenter();
        var nkLatlong = new Coordinate(veLatlong.Longitude, veLatlong.Latitude);
        if (null != nkLatlong) {
            var nkCenter = map.decimalDegreesToUTM(nkLatlong);
            if (null != nkCenter) {
                if (nkCenter.x != NaN && nkCenter.y != NaN) {
                    map.centerAndZoom(nkCenter, z2);
                }
            }
        }
    }
    this.SetMapVisible = function (map) {
        am = $('tbActiveMap');
        if (map == 'nk') {
            am.value = 'nk';
            bVEMap = false;
            if (veDiv) {
                veDiv.style.visibility = 'hidden';
                veDiv.visible = false;
            }
            if (nkDiv) {
                nkDiv.style.visibility = 'visible';
                nkDiv.visible = true;
            }
        }
        else {
            if (fromBirdsEye != true) {
                am.value = 've';
            }
            bVEMap = true;
            if (veDiv) {
                veDiv.style.visibility = 'visible';
                veDiv.visible = true;
            }
            if (nkDiv) {
                nkDiv.style.visibility = 'hidden';
                nkDiv.visible = false;
            }
        }
    }
    this.DisposeMap = function () {
        if (vemap != null) {
            vemap.Dispose();
        }
    }
}
