﻿function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.truncate = (tr != null && tr); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{	
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); 
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');	
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}


    function GZoomControl() {}
    GZoomControl.prototype = new GControl();
    GZoomControl.isClickZoom = true;
    GZoomControl.oButton = null;
    GZoomControl.mc = null;
    GZoomControl.posx = 0;
    GZoomControl.posy = 0;
    GZoomControl.drawSatus = false;
    GZoomControl.map = null;
    GZoomControl.rect = null;

    GZoomControl.prototype.getIsClickZoom = function(){
        return GZoomControl.isClickZoom;
    }

    GZoomControl.prototype.initialize = function(oMap) {
        GZoomControl.map = oMap;
	    var oMC=oMap.getContainer();
	    var oButton = document.createElement('div');
	    oButton.innerHTML="<img src='images/gmaps/hand.gif' />";
	    oButton.style.cursor = 'pointer';
	    oButton.style.zIndex = 200;
	    oMC.appendChild(oButton);
        GZoomControl.oButton = oButton;

	    var o = document.createElement("div");
        o.style.width='100%';
        o.style.height='100%';
        o.style.position='absolute';
        o.style.display='block';
        o.style.overflow='hidden';
        o.style.cursor='crosshair';
        o.style.zIndex = 8;
        o.style.filter='alpha(opacity=0)';
        o.style.opacity='0.0';
        o.style.background='#000';
 
       var divs = document.getElementsByTagName("div");
        
        GZoomControl.rect = document.createElement("div");
        GZoomControl.rect.setAttribute("id","rectangle");
        
        oMC.appendChild(GZoomControl.rect);
	    oMC.appendChild(o);
	    GEvent.addDomListener(oButton, 'click', GZoomControl.prototype.buttonClick_);
	    GEvent.addDomListener(o, 'mousedown', GZoomControl.prototype.coverMousedown_);
	    GEvent.addDomListener(o, 'mousemove', GZoomControl.prototype.drag_);
	    GEvent.addDomListener(o, 'mouseup', GZoomControl.prototype.mouseup_);
	    GEvent.addDomListener(GZoomControl.rect, 'mousemove', GZoomControl.prototype.drag_);
	    GEvent.addDomListener(GZoomControl.rect, 'mouseup', GZoomControl.prototype.mouseup_);
	    GZoomControl.mc=o;

      return oButton;
    };

    GZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(24, 290));
    };

    GZoomControl.prototype.coverMousedown_ = function(e){
    if (GZoomControl.isClickZoom==true){
        GZoomControl.drawSatus = true;
        // --- tilføjet af Jonas ---
        var positions = findPos(document.getElementById('map'));
        var diffX = positions[0];
        var diffY = positions[1];
	    GZoomControl.posx = GZoomControl.prototype.mouseX_(e) - diffX;
	    GZoomControl.posy = GZoomControl.prototype.mouseY_(e) - diffY;
	    // -------------------------
	    //GZoomControl.posx = GZoomControl.prototype.mouseX_(e);
	    //GZoomControl.posy = GZoomControl.prototype.mouseY_(e);
	    GZoomControl.rect.style.visibility="visible";
	    }
        return false;
    };

    function findPos(obj) {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
		    curleft = obj.offsetLeft
		    curtop = obj.offsetTop
		    while (obj = obj.offsetParent) {
			    curleft += obj.offsetLeft
			    curtop += obj.offsetTop
		    }
	    }
	    return [curleft,curtop];
    }

    GZoomControl.prototype.drag_=function(e){
        if(GZoomControl.drawSatus == true){
            if (GZoomControl.isClickZoom==true){
                var pointX = GZoomControl.prototype.mouseX_(e);
                var pointY = GZoomControl.prototype.mouseY_(e);
                // --- tilføjet af Jonas ---
                var positions = findPos(document.getElementById('map'));
                var diffX = positions[0];
                var diffY = positions[1];
                var lenX = (pointX-GZoomControl.posx) - diffX;
                var lenY = (pointY-GZoomControl.posy) - diffY;
                // -------------------------
                //var lenX = (pointX-GZoomControl.posx);
                //var lenY = (pointY-GZoomControl.posy);
                if (lenY >=0) {
                    GZoomControl.rect.style.top = GZoomControl.posy+"px"; 
                    GZoomControl.rect.style.height = lenY+"px";
                }else{
                    GZoomControl.rect.style.top = (GZoomControl.posy+lenY)+"px"; 
                    GZoomControl.rect.style.height = (lenY*-1)+"px";
                }
                if (lenX >=0) {
                    GZoomControl.rect.style.left = GZoomControl.posx+"px";
                    GZoomControl.rect.style.width = lenX+"px";
                } else {
                    GZoomControl.rect.style.left = (GZoomControl.posx+lenX)+"px";
                    GZoomControl.rect.style.width = (lenX*-1)+"px"; 
                }
            }
        }
    };

    GZoomControl.prototype.mouseup_=function(e){
    if (GZoomControl.isClickZoom==true){
        GZoomControl.drawSatus = false;
        GZoomControl.rect.style.visibility="hidden";
        if (GZoomControl.isClickZoom) {
            var pointX = GZoomControl.prototype.mouseX_(e);
            var pointY = GZoomControl.prototype.mouseY_(e);
            // --- tilføjet af Jonas ---
            var positions = findPos(document.getElementById('map'));
            var diffX = positions[0];
            var diffY = positions[1];
            var lenX = (pointX-GZoomControl.posx) - diffX;
            var lenY = (pointY-GZoomControl.posy) - diffY;
            if(lenX != 0 && lenY != 0)
            {       
            // -------------------------
            //var lenX = (pointX-GZoomControl.posx);
            //var lenY = (pointY-GZoomControl.posy);
                var t=0;
                var h=0;
                var l=0;
                var w=0;
                if (lenY >=0) {
                    t = GZoomControl.posy; 
                    h = lenY;
                }else{
                    t = (GZoomControl.posy+lenY); 
                    h = (lenY*-1);
                }
                if (lenX >=0) {
                    l = GZoomControl.posx;
                    w = lenX;
                }else{
                    l = (GZoomControl.posx+lenX);
                    w = (lenX*-1);
                }    
               
                var mapType = GZoomControl.map.getCurrentMapType();
                var proj = mapType.getProjection();
                var zoom = GZoomControl.map.getZoom();
                
                var BoundsSW = GZoomControl.map.getBounds().getSouthWest();
                var BoundsNE = GZoomControl.map.getBounds().getNorthEast();
                var px=proj.fromLatLngToPixel(BoundsSW, GZoomControl.map.getZoom()); 
                var px1=proj.fromLatLngToPixel(BoundsNE, GZoomControl.map.getZoom());
                px.y = px1.y + t;
                px.x = px.x + l;
                
                px1.y = px.y + h;
                px1.x = px.x + w;

                var geoSW = proj.fromPixelToLatLng(px,  zoom,  true);
                var geoNE = proj.fromPixelToLatLng(px1,  zoom,  true);
                 
                
                var geoRectBounds = new GLatLngBounds(geoSW,geoNE);
               
                var newCenter = new GLatLng(((geoRectBounds.getSouthWest()).lat()+(geoRectBounds.getNorthEast()).lat())/2,
                ((geoRectBounds.getSouthWest()).lng()+(geoRectBounds.getNorthEast()).lng())/2 ,false );
               
                var newZoom = GZoomControl.map.getBoundsZoomLevel(geoRectBounds);
                GZoomControl.rect.style.height = "0px";    
                GZoomControl.rect.style.width ="0px"
                if ((newZoom - zoom)>=3){
                    GZoomControl.map.setCenter(newCenter,zoom+3);
                } else {
                    GZoomControl.map.setCenter(newCenter,newZoom);
                }
            }
        }
        }return false;
    };

    GZoomControl.prototype.buttonClick_=function(){
        if (GZoomControl.isClickZoom) {
            map.enableDragging();
            GZoomControl.isClickZoom = false;
     	    GZoomControl.oButton.innerHTML="<img src='images/gmaps/zoom-button.gif' />";
     	    GZoomControl.mc.style.height='0px';
     	    GZoomControl.mc.style.width='0px';
     	    GZoomControl.mc.style.display='none';
     	    GZoomControl.mc.style.background='transparent';
	    } else {
	        map.disableDragging();
            GZoomControl.mc.style.height='100%';
     	    GZoomControl.mc.style.width='100%';
     	    GZoomControl.mc.style.display='block';
     	    GZoomControl.mc.style.background='#000';
	        GZoomControl.isClickZoom = true;
            GZoomControl.oButton.innerHTML="<img src='images/gmaps/hand.gif' />";
        }
    };

    GZoomControl.prototype.mouseX_=function(evt){
                if (evt.pageX) return evt.pageX;
                else if (evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
                else return null;
            };
          
    GZoomControl.prototype.mouseY_=function(evt){
                if (evt.pageY) return evt.pageY;
                else if (evt.clientY) return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
                else return null;
            };
            
// customwindow.js
      function EStyle(stemImage, stemSize, boxClass, boxOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
        //this.border = border;
        
        // Known fudge factors are:
        // Firefox (1.0.6 and 1.5)    0, -1
        // IE 6.0                     0, -1
        // Opera 8.54                 3, -1
        // Opera 9 prev               4, -1
        // Netscape (7.2, 8.0)        5, -1
        // Safari                     5, -1        
        
        var agent = navigator.userAgent.toLowerCase();
        
        var fudge = 0;  // assume Netscape if no match found
       
        if (agent.indexOf("opera") > -1) {
          fudge = 3;
        }   
        if (agent.indexOf("firefox") > -1) {
          fudge = 0;
        }   
        if (agent.indexOf("safari") > -1) {
          fudge = 5;
        }   
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
          fudge = 0;
        }
        this.fudge = fudge;
      }
      
//      var E_STYLE_1 = new EStyle("images/gmaps/icons/stem1.png", new GSize(81,87),  "estyle1", new GPoint(-30,87-3));
//      var E_STYLE_2 = new EStyle("images/gmaps/icons/stem2.png", new GSize(81,87),  "estyle2", new GPoint(-30,87-1));
//      var E_STYLE_3 = new EStyle("images/gmaps/icons/stem3.png", new GSize(81,87),  "estyle3", new GPoint(-30,87-10));
//      var E_STYLE_4 = new EStyle("images/gmaps/icons/stem3.png", new GSize(81,87),  "estyle4", new GPoint(-30,87-10));
//      var E_STYLE_5 = new EStyle("images/gmaps/icons/stem1.png", new GSize(81,87),  "estyle5", new GPoint(-30,87-3));
//      var E_STYLE_6 = new EStyle("images/gmaps/icons/stem6.png", new GSize(100,50), "estyle6", new GPoint(100-2,20));
      var E_STYLE = new EStyle("images/gmaps/icons/stem7.png", new GSize(24,24),  "ewstyle", new GPoint(-10,23));
      var E_STYLE_FRAME = new EStyle("images/gmaps/icons/stem_frame3.png", new GSize(24,17),  "ewstyle_frame", new GPoint(-10,16));

      function EWindow(map,estyle) {
        // parameters
        this.map=map;
        this.estyle=estyle;
        // internal variables
        this.visible = false;
        // browser - specific variables
        this.ie = false;
        var agent = navigator.userAgent.toLowerCase();
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
      } 
      
      EWindow.prototype = new GOverlay();

      EWindow.prototype.initialize = function(map) {
        var div1 = document.createElement("div");
        div1.style.position = "absolute";
        //div1.style.width = "100%";
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
        var div2 = document.createElement("div");
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        //div2.style.width = "100%";
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
        this.div1 = div1;
        this.div2 = div2;
      }

      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '"><nobr>' + html + '</nobr></div>';
        if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
          this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
        } else {
          this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
        }
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z;
        this.div2.style.zIndex = z+1;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
        this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
      }
      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        var p = this.map.fromLatLngToDivPixel(this.point);
        this.div2.style.left   = (p.x + this.offset.x) + "px";
        this.div2.style.bottom = (-p.y + this.offset.y - this.estyle.fudge) + "px";
        this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
        this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
      }

      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        this.div2.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.div2.style.display="none";
        this.visible = false;
      }
      
      
      
function GetIcon(housetype, change)
{
    switch(housetype)
    {
        case 1:
            if (change == 0)
                return icon1;
            else if (change > 0)
                return icon1_up;
            else
                return icon1_down;
            break;
        case 2:
            if (change == 0)
                return icon2;
            else if (change > 0)
                return icon2_up;
            else
                return icon2_down;
            break;
        case 3:
            if (change == 0)
                return icon3;
            else if (change > 0)
                return icon3_up;
            else
                return icon3_down;
            break;
        case 4:
            if (change == 0)
                return icon4;
            else if (change > 0)
                return icon4_up;
            else
                return icon4_down;
            break;
        case 5:
            if (change == 0)
                return icon5;
            else if (change > 0)
                return icon5_up;
            else
                return icon5_down;
            break;
        case 6:
            if (change == 0)
                return icon6;
            else if (change > 0)
                return icon6_up;
            else
                return icon6_down;
            break;
        case 7:
            if (change == 0)
                return icon7;
            else if (change > 0)
                return icon7_up;
            else
                return icon7_down;
            break;
        case 8:
            if (change == 0)
                return icon8;
            else if (change > 0)
                return icon8_up;
            else
                return icon8_down;
            break;
        case 9:
            if (change == 0)
                return icon7;
            else if (change > 0)
                return icon7_up;
            else
                return icon7_down;
            break;
        default:
            if (change == 0)
                return icon1;
            else if (change > 0)
                return icon1_up;
            else
                return icon1_down;
            break;
    }
}

function createSimpleMarker(point,housetype,id,totalchange,lat,lng,newCoord) 
{
    
    var change = parseInt(totalchange);
    var icon = GetIcon(housetype, change);
    var marker1 = new GMarker(point, icon);
    
    if(lat != null && lng != null)
    {
        GEvent.addListener(marker1, "click", function() {
            ToggleLoading(true);          
            var types = getValues("types");
            var prices = getValues("prices");
            var rooms = getValues("rooms");
            var size = getValues("size");
            var garden = getValues("garden");
            var time = getValues("time");
            var year = "";
            var query = getValues("query");
            var street = getValues("street");
            var zips = "";
            var area = "";
            var sqmPrice = getValues("sqmPrice");
            
            mapCallServer("GetHousesOnThisCoord", "07:" + lat + "|" + lng + "|" + types + "|" + prices + "|" + rooms + "|" + size + "|" + garden + "|" + time + "|" + year + "|" + query + "|" + sqmPrice);
        });
    }
    else
    {
        GEvent.addListener(marker1, "click", function() {
            ToggleLoading(true);
            map.closeInfoWindow();
            mapCallServer("GetHouse", "01:" + id); 
        });
    }
    return marker1;
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
	    curleft = obj.offsetLeft
	    curtop = obj.offsetTop
	    while (obj = obj.offsetParent) {
		    curleft += obj.offsetLeft
		    curtop += obj.offsetTop
	    }
    }
    return [curleft,curtop];
}

function parseQuerystring()
{
    var housetype = getQueryVariable('type');
    //var byggetMin = getQueryVariable('byggetMin');
    //var byggetMax = getQueryVariable('byggetMax');
    var q = getQueryVariable('q');
    var minPrice = getQueryVariable('minPrice');
    var maxPrice = getQueryVariable('maxPrice');
    var minNetPrice = getQueryVariable('minNetPrice');
    var maxNetPrice = getQueryVariable('maxNetPrice');
    var minSqmPrice = getQueryVariable('minSqmPrice');
    var maxSqmPrice = getQueryVariable('maxSqmPrice');
    var minPeriod = getQueryVariable('minPeriod');
    var maxPeriod = getQueryVariable('maxPeriod');
    var region1 = getQueryVariable('region1');
    var region2 = getQueryVariable('region2');
    var street = getQueryVariable('street');
    var minRooms = getQueryVariable('minRooms');
    var maxRooms = getQueryVariable('maxRooms');
    var minBedRooms = getQueryVariable('minBedRooms');
    var maxBedRooms = getQueryVariable('maxBedRooms');
    var minSize = getQueryVariable('minSize');
    var maxSize = getQueryVariable('maxSize');
    var minGardenSize = getQueryVariable('minGardenSize');
    var maxGardenSize = getQueryVariable('maxGardenSize');
    var localarea = getQueryVariable('localarea');

    if (localarea != null && localarea != "")
        document.getElementById('localarea').value = localarea;
        
    if(street != null && street != "")
        document.getElementById('street').value = street;
    
    if(region1 != null && region1 != "")
        for(i=0;i<document.getElementById('region1chooser').options.length;i++)
            if(document.getElementById('region1chooser').options[i].value == region1.replace('+',' '))
                  document.getElementById('region1chooser').selectedIndex = i;
    
    if(region2 != null && region2 != "")
        for(i=0;i<document.getElementById('region2chooser').options.length;i++)
            if(document.getElementById('region2chooser').options[i].value == region2.replace('+',' '))
                  document.getElementById('region2chooser').options[i].selected = true;

    if(minNetPrice != null && minNetPrice != "")
        document.getElementById('minNetPrice').value = minNetPrice;
    if(maxNetPrice != null && maxNetPrice != "")
        document.getElementById('maxNetPrice').value = maxNetPrice;           
    if(minSqmPrice != null && minSqmPrice != "")
        document.getElementById('minSqmPrice').value = minSqmPrice;
    if(maxSqmPrice != null && maxSqmPrice != "")
        document.getElementById('maxSqmPrice').value = maxSqmPrice;
    
    // form fields
    if(maxGardenSize != null && maxGardenSize != "")
        document.getElementById('maxGardenSize').value = maxGardenSize;
    if(minGardenSize != null && minGardenSize != "")
        document.getElementById('minGardenSize').value = minGardenSize;
    if(maxSize != null && maxSize != "")
        document.getElementById('maxSize').value = maxSize;
    if(minSize != null && minSize != "")
        document.getElementById('minSize').value = minSize;
    if(maxRooms != null && maxRooms != "")
        document.getElementById('maxRooms').value = maxRooms;
    if(minRooms != null && minRooms != "")
        document.getElementById('minRooms').value = minRooms;
    if(maxBedRooms != null && maxBedRooms != "")
        document.getElementById('maxRooms').value = maxBedRooms;
    if(minBedRooms != null && minBedRooms != "")
        document.getElementById('minRooms').value = minBedRooms;
    if(maxPeriod != null && maxPeriod != "")
        document.getElementById('maxPeriod').value = maxPeriod;
    if(minPeriod != null && minPeriod != "")
        document.getElementById('minPeriod').value = minPeriod;
    if(maxPrice != null && maxPrice != "")
        document.getElementById('maxPrice').value = formatNumber(maxPrice);
    if(minPrice != null && minPrice != "")
        document.getElementById('minPrice').value = formatNumber(minPrice);
    if(q != null && q != "")
        document.getElementById('freetext').value = q;
    //if(byggetMax != null && byggetMax != "")
    //    document.getElementById('byggetMax').value = byggetMax;
    //if(byggetMin != null && byggetMin != "")    
    //    document.getElementById('byggetMin').value = byggetMin;
    if(housetype != null && housetype != "")
    {
        document.getElementById('type1').checked = false;
        if(housetype.indexOf("1") > -1)
            document.getElementById('type1').checked = true;
        if(housetype.indexOf("2") > -1)
            document.getElementById('type2').checked = true;
        if(housetype.indexOf("3") > -1)
            document.getElementById('type3').checked = true;
        if(housetype.indexOf("4") > -1)
            document.getElementById('type4').checked = true;
        if(housetype.indexOf("5") > -1)
            document.getElementById('type5').checked = true;
        if(housetype.indexOf("6") > -1)
            document.getElementById('type6').checked = true;
        if(housetype.indexOf("7") > -1)
            document.getElementById('type7').checked = true;
        if(housetype.indexOf("8") > -1)
            document.getElementById('type8').checked = true;
        if(housetype.indexOf("9") > -1)
            document.getElementById('type9').checked = true;
        if(housetype.indexOf("10") > -1)
            document.getElementById('type10').checked = true;
    }
    else
        document.getElementById('type1').checked = true;
}

function getValues(fieldName)
{
    var result = "";
    var minResult = "", maxResult = "";
    switch(fieldName)
    {
        case "types":
            if(document.getElementById('type1') != null && document.getElementById('type1').checked == true)
                result += "1,"; 
            if(document.getElementById('type2') != null && document.getElementById('type2').checked == true)
                result += "2,"; 
            if(document.getElementById('type3') != null && document.getElementById('type3').checked == true)
                result += "3,"; 
            if(document.getElementById('type4') != null && document.getElementById('type4').checked == true)
                result += "4,"; 
            if(document.getElementById('type5') != null && document.getElementById('type5').checked == true)
                result += "5,"; 
            if(document.getElementById('type6') != null && document.getElementById('type6').checked == true)
                result += "6,"; 
            if(document.getElementById('type7') != null && document.getElementById('type7').checked == true)
                result += "7,"; 
            if(document.getElementById('type8') != null && document.getElementById('type8').checked == true)
                result += "8,";
            if(document.getElementById('type9') != null && document.getElementById('type9').checked == true)
                result += "9,";
            if(document.getElementById('type10') != null && document.getElementById('type10').checked == true)
                result += "10,";
            break;
        case "prices":
            var min = "0", max = "10000000";
            var minValue = document.getElementById('minPrice').value.trim().replace('.','').replace('.','');
            var maxValue = document.getElementById('maxPrice').value.trim().replace('.','').replace('.','');
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "netPrice":
            var min = "0", max = "10000000";
            var minValue = document.getElementById('minNetPrice').value.trim().replace('.', '').replace('.', '');
            var maxValue = document.getElementById('maxNetPrice').value.trim().replace('.', '').replace('.', '');
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "rooms":
            var min = "0", max = "100";
            var minValue = document.getElementById('minRooms').value.trim();
            var maxValue = document.getElementById('maxRooms').value.trim();
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "size":
            var min = "0", max = "5000";
            var minValue = document.getElementById('minSize').value.trim().replace('.','').replace('.','');
            var maxValue = document.getElementById('maxSize').value.trim().replace('.','').replace('.','');
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "garden":
            var min = "0", max = "50000";
            var minValue = document.getElementById('minGardenSize').value.trim().replace('.','').replace('.','');
            var maxValue = document.getElementById('maxGardenSize').value.trim().replace('.','').replace('.','');
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "year":
//            var min = "0", max = "2010";
//            if(document.getElementById('minYears').value.trim() != "")
//                min = document.getElementById('minYears').value.trim(); 
//            if(document.getElementById('maxYears').value.trim() != "")
//                max = document.getElementById('maxYears').value.trim(); 
//            result = min + "," + max;
//            break;
        case "time":
            var min = "0", max = "1000";
            var minValue = document.getElementById('minPeriod').value.trim();
            var maxValue = document.getElementById('maxPeriod').value.trim();
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "query":
            if(document.getElementById('freetext').value.trim() != "")
                result = document.getElementById('freetext').value.trim(); 
            break;
        case "street":
            if(document.getElementById('street').value.trim() != "")
                result = document.getElementById('street').value.trim(); 
            break;
        case "region1":
            var region1elem = document.getElementById('region1chooser');
            if(region1elem.options[region1elem.selectedIndex].value != "")
                result = result + region1elem.options[region1elem.selectedIndex].value + ","; 
            break;
        case "region2":
            var region2elem = document.getElementById('region2chooser');
            for(var i=0;i<region2elem.options.length;i++)
                if(region2elem.options[i].selected == true)
                    result = result + region2elem.options[i].value + ",";
            break;
        case "sqmPrice":
            var min = "0", max = "100000";
            var minValue = document.getElementById('minSqmPrice').value.trim().replace('.','').replace('.','');
            var maxValue = document.getElementById('maxSqmPrice').value.trim().replace('.','').replace('.','');
            result = ParseResult(min, max, minValue, maxValue);
            break;
        case "localarea":
            if (document.getElementById('localarea').value.trim() != "")
                result = document.getElementById('localarea').value.trim(); 
            break;
    }
    return result;
}

function GetNumericValue(name, defaultValue) {
    var element = document.getElementById(name);
    var value = element.value;
    if (!element || !value) return defaultValue;
    return value.trim().replace('.', '').replace('.', '');
}

function GetString(name) {
    return document.getElementById(name).value.trim();
}

function ParseResult(min, max, minValue, maxValue)
{
    var result = "";
    var minResult = "", maxResult = "";
    
    if(minValue == "undefined") minValue = "";
    if(maxValue == "undefined") maxValue = "";
    if(minValue != "" && minValue != min) minResult = minValue;
    if(maxValue != "" && maxValue != max) maxResult = maxValue;
    
    if(minResult != "" && maxResult != "")
        result = minResult + "," + maxResult;
    else if(minResult != "")
        result = minResult + "," + max;
    else if(maxResult != "")
        result = min + "," + maxResult;
    
    return result;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}


function ToggleLoading(show)
{
    if(show)
        loader.style.display = 'block';
    else
        loader.style.display = 'none';
}

function addValue(name, value, isPrice) 
{
    var newValue;
    if(isPrice)
    {
        newValue = parseInt(document.getElementById(name).value.replace('.','').replace('.','')) + value;
        if(newValue >= 0)
            newValue = formatNumber(newValue);
        else
            newValue = 0;
    }
    else
    {
        newValue = parseInt(document.getElementById(name).value) + value;
        if(newValue < 0)
            newValue = 0;
    }
    document.getElementById(name).value = newValue;
}

function formatNumber(myValue)
{
    var num = new NumberFormat();
    num.setInputDecimal('.');
    num.setNumber(myValue);
    num.setPlaces('0', false);
    num.setCurrencyValue('');
    num.setCurrency(true);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(false);
    num.setSeparators(true, '.', ',');
    return num.toFormatted();
}

function hideHouse(id)
{
    ToggleLoading(true);
    mapCallServer("HideHouse", "06:" + id); 
}

// querystring.js
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  var result = "";
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      result = result + "," + pair[1];
    }
  }
  if(result != "")
    return result.substring(1);
}
            
        //]]> 
        
        
        
        
        //
// Various functions for creating a pedometer using Google Maps.
//
// You use this software at your own risk. It shouldn't be used to run
// nuclear power stations or fly aeroplanes.
//
// Written by Simon Buckle (simon@simonbuckle.com) 
//
// Copyright 2005
//

var Codec = {

	// The algorithm for route encoding can be found here:
	// http://www.thrall.net/~mking/maps/points.py
	// I translated it into Javascript.

	encodePoints : function (locations) {
		var points = [];
		var x0 = 0;
		var y0 = 0;

		locations = this.map(function (x) { return Math.round(x / 1.0E-5); }, locations);

		for (var i = 0; i < locations.length / 2; i++) {
			var y = locations[i << 1];
			var dy = y - y0;
			y0 = y;
			var f = (Math.abs(dy) << 1) - (dy < 0);
			while (1) {
				var e = f & 31;
				f >>= 5;
				if (f) 
					e |= 32;
				points.push(String.fromCharCode(e + 63));
				if (f == 0)
					break;
			}
			var x = locations[(i << 1) + 1]
			var dx = x - x0;
			x0 = x;
			f = (Math.abs(dx) << 1) - (dx < 0);
			while (1) {
				var e = f & 31;
				f >>= 5;
				if (f) 
					e |= 32;
				points.push(String.fromCharCode(e + 63));
				if (f == 0)
					break;
			}
		}
		return points.join("");
	},

	decodePoints : function (points) {
		if (!points) 
			return [];
	
		var locations = [];
    	var pb = 0;
		var Ka = 0;
		var Pa = 0;

		while (pb < points.length) {
			var oc = 0;
			var Fa = 0;
			while (1) {
				var ub = points.charCodeAt(pb) - 63;
				pb += 1;
				Fa |= (ub & 31) << oc;
				oc += 5;
				if (ub < 32) 
					break;
			}
			var i;
			if (Fa & 1) 
				i = ~(Fa >> 1);
			else
				i = Fa >> 1;
			Ka += i;
			locations.push(Ka * 1.0E-5);

			oc = 0;
			Fa = 0;
			while (1) {
				var ub = points.charCodeAt(pb) - 63;
				pb += 1;
				Fa |= (ub & 31) << oc;
				oc += 5;
				if (ub < 32) 
					break;
			}
			if (Fa & 1) 
				i = ~(Fa >> 1);
			else
				i = Fa >> 1;
			Pa += i;
			locations.push(Pa * 1.0E-5); 
		}
		return locations;
	},

	map : function (f, a) {
		var results = [];
		for(var i = 0; i < a.length; i++) {
			results[i] = f(a[i]);
		}
		return results;
	}
}

var routePoints = new Array(0);
var routeLines = new Array(0);
var routeMarkers = new Array(0);
var total_distance = 0;

var MILES = {
	label : "miles",
	f : function (distance) {
			return distance / 1609.344;
	}
}

var KMS = {
	label: "km",
	f : function (distance) {
			return distance / 1000;
	}
}

var MS = {
	label: "m",
	f : function (distance) {
			return distance;
	}
}

var unit_handler = KMS;
var calculatorIsOn = false;

// Takes an array of points and works out the total distance
function calculateDistance (points) {
	if (points.length < 2)	
		return 0;

	var dist = 0.0;

	for (var i = 0; i < points.length - 1; i++) {
		dist += distance_between_points(points[i], points[i + 1]);		
	}

	return dist;
}

function updateDisplay () {
	var dist = unit_handler.f(total_distance);
	if(unit_handler == KMS)
	    document.getElementById("distance").innerHTML = dist.toFixed(1) + " km";
	else
	    document.getElementById("distance").innerHTML = dist.toFixed(0) + " m";
} 

function toggleUnits (arg) {
	if (arg == "MILES") 
		unit_handler = MILES;
	else if (arg == "KMS")
		unit_handler = KMS;
    else if (arg == "MS")
		unit_handler = MS;
	else
		// Revert to the default
		unit_handler = KMS;
	// Refresh
	updateDisplay();
}


// Utility function for converting degrees to radians
Math.deg2rad = function ( x ) {
        return x * (Math.PI / 180.0); 
}

// Distance in metres
var EARTH_RADIUS = 6367000;

// Calculates the distance (in metres) between 2 points. 
function distance_between_points ( p1, p2 ) {
    var a = Math.deg2rad( 90 - p1.y);
    var b = Math.deg2rad( 90 - p2.y);
    var theta = Math.deg2rad( p2.x - p1.x);
    var c = Math.acos( Math.cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math.cos(theta));
    return c * EARTH_RADIUS; 
}

// Clear the last leg
function clearLastLeg ( ) {
	if (routePoints.length < 2)
		return;
	for(var x = 0;x<routePoints.length;x++)
	    map.removeOverlay(routePoints[x]);
    for(var y = 0;y<routeLines.length;y++)
        map.removeOverlay(routeLines[y]);
    for(var z = 0;z<routeMarkers.length;z++)
        map.removeOverlay(routeMarkers[z]);
    routeLines = [];
    routeMarkers = [];
	routePoints.pop();
	//map.clearOverlays();

	// Re-draw
	var newLine = new GPolyline(routePoints);
	routeLines.push(newLine);
	map.addOverlay(newLine);

	// Add the start/end markers
	var newMarkerStart = new GMarker(routePoints[0]);
	routeMarkers.push(newMarkerStart);
	var newMarkerEnd = new GMarker(routePoints[routePoints.length - 1]);
	routeMarkers.push(newMarkerEnd);
	map.addOverlay(newMarkerStart);
	map.addOverlay(newMarkerEnd);	
	
	// Re-calculate the total distance
	total_distance = calculateDistance(routePoints);
	updateDisplay();
}

// Clears the existing route
function clearRoute ( ) {
	for(var x = 0;x<routePoints.length;x++)
	    map.removeOverlay(routePoints[x]);
    for(var y = 0;y<routeLines.length;y++)
        map.removeOverlay(routeLines[y]);
    for(var z = 0;z<routeMarkers.length;z++)
        map.removeOverlay(routeMarkers[z]);
    routeLines = [];
    routeMarkers = [];
	routePoints = [];
	//map.clearOverlays();
	total_distance = 0.00;
	// Refresh the distance field
	updateDisplay();
}

function DistanceCalculatorControl() {
}

DistanceCalculatorControl.prototype = new GControl();

DistanceCalculatorControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.style.backgroundColor = "white";
  container.style.border = "1px solid black";
  
  var clearDiv = document.createElement("div");
  var undoDiv = document.createElement("div");
  var meassureDiv = document.createElement("div");
  var distanceDiv = document.createElement("div");
  var modeDiv = document.createElement("div");
  
  this.setDivStyle_(meassureDiv);
  
  container.appendChild(meassureDiv);
  meassureDiv.innerHTML = "<img src=\"images/icons/ruler_w.gif\" title=\"Mål afstand\" />";
  GEvent.addDomListener(meassureDiv, "click", function() {
    calculatorIsOn = !calculatorIsOn;
    var status = "none";
    var statusDistance = "none";
    if(calculatorIsOn) {
        meassureDiv.innerHTML = "Stop måling";
        container.style.height = "60px";
        meassureDiv.style.width = "80px";
        status = "inline";
        statusDistance = "block";
    } else {
        meassureDiv.innerHTML = "<img src=\"images/icons/ruler_w.gif\" title=\"Mål afstand\" />";
        meassureDiv.style.width = "39px";
        container.style.height = "";
        clearRoute();
    }
    clearDiv.style.display = status;
    undoDiv.style.display = status;
    distanceDiv.style.display = statusDistance;
    modeDiv.style.display = status;
  });
  
  distanceDiv.innerHTML = "0 km";
  distanceDiv.id = "distance";
  distanceDiv.style.display = "none";
  distanceDiv.style.font = "12px Verdana";
  distanceDiv.style.fontWeight = "bold";
  distanceDiv.style.paddingLeft = "3px";
  container.appendChild(distanceDiv);

  this.setButtonStyle_(clearDiv);
  container.appendChild(clearDiv);
  clearDiv.innerHTML = "<img src=\"images/icons/bin_w.gif\" title=\"Nulstil måling\" />";
  GEvent.addDomListener(clearDiv, "click", function() {
    clearRoute();
  });
  
  this.setButtonStyle_(undoDiv);
  container.appendChild(undoDiv);
  undoDiv.innerHTML = "<img src=\"images/icons/arrow_undo_w.gif\" title=\"Fotryd sidste punkt\" />";
  GEvent.addDomListener(undoDiv, "click", function() {
    clearLastLeg();
  });
  
  this.setButtonStyle_(modeDiv);
  container.appendChild(modeDiv);
  modeDiv.innerHTML = "<input id=\"KMS\" type=\"radio\" name=\"mode\" checked=\"checked\">km</input><input id=\"MS\" type=\"radio\" name=\"mode\">m</input>";
  GEvent.addDomListener(modeDiv, "click", function() {
    if(document.getElementById("KMS").checked)
        toggleUnits("KMS");
    else
        toggleUnits("MS");
  });
  
  map.getContainer().appendChild(container);
  return container;
}

DistanceCalculatorControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(24, 320));
}

DistanceCalculatorControl.prototype.setDivStyle_ = function(button) {
  button.style.textDecoration = "underline";
  button.style.color = "#6699CC";
  button.style.font = "11px Verdana";
  button.style.fontWeight = "bold";
  button.style.padding = "2px";
  //button.style.marginBottom = "3px";
  //button.style.textAlign = "center";
  button.style.width = "39px";
  button.style.cursor = "pointer";
}

DistanceCalculatorControl.prototype.setButtonStyle_ = function(button) {
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.cursor = "pointer";
  button.style.display = "none";
  button.style.styleFloat = "left";
}
        
