/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

 function showInnerHTML() {
     htmlText = document.getElementById("searchResultsList").innerHTML;
     new Ajax.Updater("htmlInfo","debugSearchProject.do",{asynchronous:true, parameters: {searchValue: htmlText}, evalScripts: true});
 }

    function searchUpdater(id,url,key) {
     width = this.wsnav.config.mapWidth;
     height = this.wsnav.config.mapHeight;
     searchText = $(id).innerHTML;
     $(id).innerHTML = "";
     $("searchResultsList").style.display = "none";
     $("searchResultsProcessing").style.display = "block";
     searchProjectValue = document.getElementById("searchProjectValue").value;
     new Ajax.Updater(id,url,
        {
            asynchronous:true,
            parameters: {searchValue: searchProjectValue, workspaceKey: key, mapWidth: ""+width, mapHeight: ""+height},
            evalScripts: true,
            onSuccess: function(transport) {
                $(id).style.display = 'block';
            },
            onComplete: function(transport) {
                initTabSizes();
                document.getElementById("searchResultsProcessing").style.display = "none";
            }
        });
    }

    function showMore(isMore) {
        $("lessResultsLayer").style.display = !isMore?"block":"none";
        $("moreResultsLayer").style.display = isMore?"block":"none";
        $("showMoreDiv").style.display = !isMore?"block":"none";
        $("showLessDiv").style.display = isMore?"block":"none";
        if(isMore){
            if ( (typeof wsnav != 'undefined') && (wsnav != null)) {
                if (wsnav.config.embed) {
                    $("searchProjectBoxOverflow").style.height = "";
                }else{
                    $("searchProjectBoxOverflow").style.height = ($('wsnav').getHeight()-$('searchProjectBoxHeader').getHeight())+"px";
                }
            }
        }else{
            $("searchProjectBoxOverflow").style.height = "";
        }
        initTabSizes();
    }

    var currentFieldPrefix;
    var currentLayer;
    var selectedFieldPrefix=null;
    var selectedLayer;

    function setColor(targetElement, color) {
        if (targetElement != null)
            targetElement.style.backgroundColor = color;
    }

    function onMouseOverResult(section, count, resultDivPrefix) {
        try {
            resultDivWrapperLayer = section+"resultsDivWrapper_"+count;
            resultDivLayer = section+"resultsDiv_"+count;
            layerDivLayer = section+"LayerPre_"+count;
            omniShowMoreLayer = section+"omniShowMore_"+count;
            omniShowLessLayer = section+"omniShowLess_"+count;
            searchResultDiv = section+"searchResult_"+count;
            //$(resultDivWrapperLayer).style.backgroundColor = "#CCCCCC";
            setColor($(resultDivLayer), "#CCCCCC");
            setColor($(layerDivLayer), "#CCCCCC");
            setColor($(omniShowMoreLayer), "#CCCCCC");
            setColor($(omniShowLessLayer), "#CCCCCC");
            setColor($(searchResultDiv), "#CCCCCC");
            try {
                for (i = 0; ; i++) {
                    document.getElementById(resultDivPrefix+i).style.backgroundColor = "#CCCCCC";
                }
            } catch(resultsDivException) {
                resultsDivException = resultsDivException;
            }
        } catch(exception) {
            exception = exception;
        }
    }

    function onMouseOutResult(section, count, resultDivPrefix) {
        try {
            if (resultDivPrefix!=selectedFieldPrefix) {
                //resultDivWrapperLayer = section+"resultsDivWrapper_"+count;
                resultDivLayer = section+"resultsDiv_"+count;
                layerDivLayer = section+"LayerPre_"+count;
                omniShowMoreLayer = section+"omniShowMore_"+count;
                omniShowLessLayer = section+"omniShowLess_"+count;
                searchResultDiv = section+"searchResult_"+count;
                //$(resultDivWrapperLayer).style.backgroundColor = "#F4F3F2";
                setColor($(resultDivLayer), "#F4F3F2");
                setColor($(layerDivLayer), "#F4F3F2");
                setColor($(omniShowMoreLayer), "#F4F3F2");
                setColor($(omniShowLessLayer), "#F4F3F2");
                setColor($(searchResultDiv), "#F4F3F2");
                try {
                    for (i = 0; ; i++) {
                        $(resultDivPrefix+i).style.backgroundColor = "#F4F3F2";
                    }
                } catch(resultsDivException) {
                    resultsDivException = resultsDivException;
                }
            }
        } catch(exception) {
            exception = exception;
        }
    }

    function getResultElements(parent) {
        kids = Array.concat(parent.getElementsByTagName("pre")
                            ,parent.getElementsByTagName("span")
                            ,parent.getElementsByTagName("div"));
        return kids;
    }

    function clearFields() {
       tempFieldPrefix = selectedFieldPrefix;
       tempLayer = selectedLayer;
       selectedFieldPrefix = currentFieldPrefix;
       selectedLayer = currentLayer;
       onMouseOutResult(tempLayer, tempFieldPrefix);
    }

    function setPoint(geom, workspaceKey, result) {
       clearFields();
       geomCenter = geom.split(",");
       showToolTipAfterMapLoaded(result.getAttributes());
       var center = {"x" : parseFloat(geomCenter[0]), "y" : parseFloat(geomCenter[1])};
       this.wsnav.setLoadingState(true);
       this.wsnav.previewCenter(this.wsnav.bounds, center, true);
       this.wsnav.setCenter(center);
       // alert("[geometry.x: "+geomCenter[0]+"] [geometry.y: "+geomCenter[1]+"] [workspaceKey: "+workspaceKey+"]");
    }

    function setBounds(geom, workspaceKey, result) {
        clearFields();
        geomRect = geom.split(",");
        var bounds = {"xmin": parseFloat(geomRect[1]), "ymin": parseFloat(geomRect[3]), "xmax": parseFloat(geomRect[0]), "ymax": parseFloat(geomRect[2])};
        
        if(googleLayer!=null){
            bounds = getClosestBounds(this.wsnav.config.mapWidth, this.wsnav.config.mapHeight, bounds, true);
        }

        showToolTipAfterMapLoaded(result.getAttributes());
        this.wsnav.setLoadingState(true);
        this.wsnav.previewBounds(this.wsnav.bounds, bounds, true);
        this.wsnav.setBounds(bounds, false);
        // alert("[geometry.xmax: "+geomRect[0]+"] [geometry.xmin: "+geomRect[1]+"] [geometry.ymax "+geomRect[2]+"] [geometry.ymin: "+geomRect[3]+"] [workspaceKey: "+workspaceKey+"]");
    }

    function closeResults() {
        $("searchResultsList").style.display = "none";
        $("searchResultsList").innerHTML = "";
        //document.getElementById("projectInfoContent").style.top = document.getElementById("searchResultsList").getBoundingClientRect().top+36+"px";
        //document.getElementById("searchResultsList").innerHTML = "";
    }

    function getPosition(obj){
        var topValue= 0,leftValue= 0;
        while(obj){
            leftValue+= obj.offsetLeft;
            topValue+= obj.offsetTop;
            obj= obj.offsetParent;
        }
        finalvalue = leftValue + "," + topValue;
        return topValue;
    }

//    function repositionProjectInfoDiv() {
//        layerLess = document.getElementById("lessResultsLayer");
//        document.getElementById("projectInfoContent").style.top = (layerLess.getBoundingClientRect().bottom+18)+"px";
//    }

    var tooltipEventBindedToWsNav = false;
    var tooltipValue = "";
    function showToolTipAfterMapLoaded(value){
        try{
            if(wsnav.config.embed){
                llc.scrollUp();
            }
        }catch(err){

        }
        tooltip.forcehide();
        if(!tooltipEventBindedToWsNav){
            this.wsnav.eventDispatcher.register("map_loaded", null, "showToolTipValue");
            tooltipEventBindedToWsNav = true;
        }
        tooltipValue = value;
    }
    function showToolTipValue(){
        tooltip.forcehide();
        if(tooltipValue!=""){
            tooltip.show("", tooltipValue, {x: Math.round(this.wsnav.config.mapWidth/2), y: Math.round(this.wsnav.config.mapHeight/2)}, true, this.wsnav.config.skin);
            tooltipValue = "";
        }
    }

    function searchResult(resultLayerName, resultAttributes) {
        this.resultAttributes = resultAttributes;
        this.attributes = resultAttributes.split("}{");
        this.attributes[0] = this.attributes[0].substring(1);
        this.attributes[this.attributes.length-1] =
            this.attributes[this.attributes.length-1]
                .substring(0, this.attributes[this.attributes.length-1].length-1);

        this.getAttribute = function(index) {
            return this.attributes[index];
        }

        this.getAttributes = function() {
            attribs = resultLayerName;
            for (count = 0; count < this.attributes.length; count++) {
                attribs += "\n";
                attribs += this.attributes[count];
            }
            return attribs;
        }
    }

    function showAllFields(section, divId) {
        resultDiv = document.getElementById(section+'resultsDiv_'+divId);
        resultDiv.style.display = "block";
        showMoreDivId = section+'omniShowMore_'+divId;
        showDiv = document.getElementById(showMoreDivId);
        showDiv.style.display = "none";
        fieldPreWrapperId = section+"fieldPreWrapper_"+divId+"_0";
        $(fieldPreWrapperId).className = "fieldPreOverflowShown";
        initTabSizes();
        return false;
    }

    function closeSomeFields(section, divId) {
        resultDiv = document.getElementById(section+'resultsDiv_'+divId);
        showDivString = section+'omniShowMore_'+divId;
        showDiv = document.getElementById(section+'omniShowMore_'+divId);
        showDiv.style.display = "block";
        resultDiv.style.display = "none";
        fieldPreWrapperId = section+"fieldPreWrapper_"+divId+"_0";
        $(fieldPreWrapperId).className = "fieldPreOverflowHidden";
        initTabSizes();
        return false;
    }


function handleSearchEnterKey(event)
{
        var key;

        if (window.event) {
           key = window.event.keyCode;
           srcTarget = event.srcElement;
        } else if (event) {
           key = event.which;
           srcTarget = event.currentTarget;
        } else {
           return true;
        }
        if (key != 13)
            return true;

        button = document.getElementById("searchProjectButton");
        if (button != null)
            button.onclick();
        event.returnValue = false;
        return false;
        }

function returnFalse() {
    return false;
}
function MWWaterMark(imagePath, position){
    this.imagePath = imagePath;
    this.position = position;
}

MWWaterMark.prototype.init=function(wsnav){
    this.wsnav = wsnav;
    this.controlDiv = document.createElement("div");
    this.controlDiv.style.position = "absolute";
    this.controlDiv.style.visibility = "hidden";
    this.wsnav.mapDiv.appendChild(this.controlDiv);
    this.img = document.createElement("img");
    if(dojo.isIE==6)
        this.img.className = "imgAlphaIE6";
    var temp = this;
    dojo.connect(this.img, 
            "onload", 
            function(evt){
                if(temp.position=="bottomRight"){
                    temp.controlDiv.style.left = (temp.wsnav.config.navWidth-temp.img.width)+"px";
                    temp.controlDiv.style.top = (temp.wsnav.config.navHeight-temp.img.height-2)+"px";
                }else if(temp.position=="bottomRightGoogle"){
                    temp.controlDiv.style.left = (temp.wsnav.config.navWidth-temp.img.width)+"px";
                    temp.controlDiv.style.top = (temp.wsnav.config.navHeight-temp.img.height-17)+"px";
                }
                if(dojo.isIE==6)
                    temp.controlDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+temp.img.src+"')";
                temp.controlDiv.style.visibility = "visible";
            }
        );
    this.controlDiv.appendChild(this.img);
    dojo.connect(this.img, "onmousedown", function(evt){evt.preventDefault();});
    this.wsnav.eventDispatcher.register("overview_loaded", this, "mapZoomListener");
}

MWWaterMark.prototype.mapZoomListener = function(evt) {
    this.img.src = this.imagePath + "?cartoSession=" + this.wsnav.masterLayer.state.cartoSession + "&refresh=" + Math.random();
}
//////////////////////////////////////////////////////////////////
// ContextMenuControl
//////////////////////////////////////////////////////////////////
function ContextMenuControl(config){
        if (config)
        this.config = config;
}
ContextMenuControl.prototype = new AbstractControl;

ContextMenuControl.prototype.init=function(wsnav){
    this.wsnav = wsnav;
    this.locale = this.wsnav.config.locale;
    this.render(this.wsnav.mapDiv);
    this.wsnav.eventDispatcher.register('mapMouseRightUp', this, 'onMouseClick');
    this.wsnav.eventDispatcher.register('before_map_loaded', this, 'onMapLoaded');
    this.wsnav.eventDispatcher.register('mapWindowShow', this, 'onMapWindowShow');
}
ContextMenuControl.prototype.onMapWindowShow = function(evt) {
    if (evt.target != this) {
        this.menuDiv.style.visibility = 'hidden';
    }
}
ContextMenuControl.prototype.onMapLoaded = function(evt) {
    this.menuDiv.style.visibility = 'hidden';
}
ContextMenuControl.prototype.onMouseClick = function(evt) {
    var e = evt.evt;
    /*
    alert('client: ' + e.clientX + ', ' + e.clientY + '; layer: ' + e.layerX + ', ' + e.layerY
        + '; offset: ' + e.offsetX + ', ' + e.offsetY
        + '; page: ' + e.pageX + ', ' + e.pageY
        + '; screen: ' + e.screenX + ', ' + e.screenY
        + '; x,y: ' + e.x + ', ' + e.y
    );
    */
    //var xPos = typeof(e.pageX) != 'undefined'? e.pageX: e.clientX;
    //var yPos = typeof(e.pageY) != 'undefined'? e.pageY: e.clientY;
    var mapCoords = dojo.coords(this.wsnav.mapDiv);
    this.mapX = e.clientX - mapCoords.x;
    this.mapY = e.clientY - mapCoords.y;
    this.menuDiv.style.top = Math.min(this.mapY, mapCoords.h - 80) + 'px';
    this.menuDiv.style.left = Math.min(this.mapX, mapCoords.w - 120) + 'px';
    this.menuDiv.style.visibility = 'visible';
    this.wsnav.eventDispatcher.dispatch('mapWindowShow', {"target": this});
}
ContextMenuControl.prototype.render = function(container) {
    /* Menu Layout:
   <div class="menu" >
        <div class="topLeft"></div>
        <div class="top"></div>
        <div class="topRight"></div>
        <div class="left"></div>
        <div class="leftBottom"></div>
        <div class="bottom"></div>
        <div class="rightBottom"></div>
        <div class="right"></div>
        <div class="contents">Send to...</div>
    </div>
    */
    this.menuDiv = document.createElement('div');
    this.menuDiv.id = 'contextMenuControl';
    this.menuDiv.className = "contextMenu";
    var IE6 = dojo.isIE == 6? '_IE6': dojo.isIE > 6? '_IE7': '';
//    IE6 = '_IE6';
    this.addMenuBorderDiv(this.menuDiv, 'rightMenutopLeft' + IE6, 'TopLeft', 'image');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenutop' + IE6, 'Top', 'scale');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenutopRight' + IE6, 'TopRight', 'image');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenuleft' + IE6, 'Left', 'scale');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenuleftBottom' + IE6, 'BottomLeft', 'image');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenubottom' + IE6, 'Bottom', 'scale');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenurightBottom' + IE6, 'BottomRight', 'image');
    this.addMenuBorderDiv(this.menuDiv, 'rightMenuright' + IE6, 'Right', 'scale');
    this.contextDiv = this.addMenuBorderDiv(this.menuDiv, 'rightMenucontents' + IE6, 'Center', 'scale');

    dojo.connect(this.menuDiv, 'onmousedown', this, function(evt){dojo.stopEvent(evt);});
    dojo.connect(this.menuDiv, 'ondblclick', this, function(evt){dojo.stopEvent(evt);});
    dojo.connect(this.menuDiv, 'onmouseup', this, function(evt){dojo.stopEvent(evt);});

    var header = this.addMenuItem(this.contextDiv, this.config.strings.sendTo, 'onHeader');
    header.className = 'rightMenuHeader';

    this.addMenuItem(this.contextDiv, this.config.strings.googleMaps, 'onGoogleMapsClick');
    this.addMenuItem(this.contextDiv, this.config.strings.googleEarth, 'onGoogleEarthClick');

    container.appendChild(this.menuDiv);
}
ContextMenuControl.prototype.addMenuBorderDiv = function(menuDiv, divClass, imageName, method) {
    var div = document.createElement('div');
    div.className = divClass;
    menuDiv.appendChild(div);
    div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+baseHREF+"images/contextMenu/" + imageName + ".png', sizingMethod='" + method + "')";
    return div;
}
ContextMenuControl.prototype.closeMenu = function(evt) {
    this.menuDiv.style.visibility = 'hidden';

}
ContextMenuControl.prototype.addMenuItem = function(container, menuTitle, callbackName) {
    var menuItem = document.createElement('div');
    menuItem.innerHTML = menuTitle;
    menuItem.className = 'rightMenuItem';

    menuItem.dojoConnection = dojo.connect(menuItem, "onclick", this, callbackName);
    container.appendChild(menuItem);
    return menuItem;
}
ContextMenuControl.prototype.onHeader = function(evt) {
    return false;
}
ContextMenuControl.prototype.onGoogleEarthClick = function(evt) {
    var width = Number(this.wsnav.wsnavDiv.getAttribute("width"))
    var point = wsnav.screenToNumeric({'x': this.mapX, 'y': this.mapY});
    this.menuDiv.style.visibility = 'hidden';
    window.location = 'GotoGoogleEarth.do?workspaceKey=' + this.wsnav.masterLayer.state.mapKey + '&width=' + width + '&zoom=' + wsnav.zoom + '&coordx=' + point.x + '&coordy=' + point.y;
}
ContextMenuControl.prototype.onGoogleMapsClick = function(evt) {
    var width = Number(this.wsnav.wsnavDiv.getAttribute("width"))
    var point = this.wsnav.screenToNumeric({'x': this.mapX, 'y': this.mapY});
    this.menuDiv.style.visibility = 'hidden';
    var mapType = 'm';
    if (this.config.googleLayer) {
        mapType = this.config.googleLayer.getGoogleTypeCode().xV;
    }
    var newWindow = window.open('GotoGoogleMaps.do?workspaceKey=' + this.wsnav.masterLayer.state.mapKey + '&width=' + width + '&zoom=' + wsnav.zoom + '&coordx=' + point.x + '&coordy=' + point.y + '&mapType=' + mapType,'MapWorkspace','width=1024,height=768');
    newWindow.focus();
}


function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}


function initEmailMap() {
    var formInputs = $$(".blueText")
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
                
        if (theInput.type == 'text' || theInput.type=='textarea' ) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
                     
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {      
        target.removeClassName('blueText');
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
        target.addClassName('blueText');
    }
}

function replaceAllDefaultText() {
    var formInputs = $$(".blueText")
     for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        theInput.addClassName('blueText');
        theInput.value = theInput.defaultText;
        
     }
}


function clearAllDefaultText() {
    var formInputs = $$(".blueText")
     for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        theInput.value ='';
     }
}

function sendEmailMap(key) {
    
   /* var f=$$('.overviewControlContainer');
    var overviewDivContent=''
    if (f[0]){
      if(f[0].style.display!='none')
         overviewDivContent=f[0].innerHTML;
      
        
    }*/

  clearAllDefaultText();
  if(checkEmailMapForm()){

        if(removeSpaces($("nameEmailMap").value)==''){
            $("nameEmailMap").value='';       
        }
        if(removeSpaces($("senderEmailMap").value)==''){
            $("senderEmailMap").value='';       
        }
        if(removeNL(removeSpaces($("messageEmailMap").value))==''){
            $("messageEmailMap").value='';       
        }
        var params = $('emailMapForm').serialize(true);
        $('emailMapLoading').style.display="block";
        $('emailMapError').style.visibility="hidden";
        $('emailMapContent').style.display="none";
        //$('emailMapSend').style.display="none";
        //$('emailMaPErrorMessage').style.display="none";
        $("emailMaPConfirmMessage").style.display = "none";
        $("emailMap").className="emailMapBoxClear";

        if(googleLayer!=null){
            params["googleType"] = googleLayer.googleType;
            params["showLabels"] = googleLayer.showLabels;
        }
        var serverLayer = wsnav.masterLayer;
        if (serverLayer != null) {
            params["forceAlpha"] = serverLayer.state.forceAlpha;
            params["transparency"] = serverLayer.state.transparency;
        }

        new Ajax.Request(baseHREF+"sendEmailMap.do?cartoSession="+wsnav.masterLayer.state.cartoSession+"&refresh="
            +new Date().getTime(), {
          method: 'get',
          parameters: params,
          onSuccess: function(transport) {
                 
            $('emailMapLoading').style.display="none";
            $('emailMapError').style.visibility="hidden";
            $('emailMapContent').style.display="none";
            //$('emailMapSend').style.display="none";
            //$('emailMaPErrorMessage').style.display="none";
            $("emailMapLoading").style.display = "none";
            $("emailMaPConfirmMessage").style.display = "block";
            $("emailMap").className="emailMapBoxClear";
            replaceAllDefaultText();
            setTimeout("closeEmailMap()",3000);

            
          },
          onFailure: function(transport) {
              
            $("emailMaPConfirmMessage").style.display = "none";
            $('emailMapLoading').style.display="none";
            $('emailMapError').style.visibility="hidden";
            $('emailMapContent').style.display="block";
            //$('emailMapSend').style.display="block";
            //$('emailMaPErrorMessage').style.display="block";
            replaceAllDefaultText();
            $("emailMap").className="emailMapBox";
            
              
          }
        });
      
  }

}





function EmailMap(){

    this.name = "emailMapTool";
    this.toggle = false;
    var isIE6 = dojo.isIE && dojo.isIE<7;
    if(!isIE6)
      this.imageBase = baseHREF+"images/emailMapTool.png";
    else
      this.imageBase = baseHREF+"images/emailMapTool.gif";  
    
   wsnav.eventDispatcher.register('mapWindowShow', this, 'onMapWindowShow');
}

EmailMap.prototype = new AbstractTool;

EmailMap.prototype.toolClicked=function(event){
    
    wsnav.eventDispatcher.dispatch('mapWindowShow', {"target": this});
     /*var isIE6 = dojo.isIE && dojo.isIE<7;
      if(!isIE6)
        this.image.src = baseHREF+"images/emailMapToolActive.png";
      else
        this.image.src = baseHREF+"images/emailMapToolActive.gif";  */

    if($("infoWindow")){
        $("infoWindow").style.zIndex = 0;
    }
     $("emailMap").style.zIndex = 1;
     $("emailMap").style.visibility = "visible";
     $("emailMap").style.left = $("wsnav").cumulativeOffset()[0]+((mapWidth-$("emailMap").getWidth())/2)+"px";
     $("emailMap").style.top = $("wsnav").cumulativeOffset()[1]+((mapHeight-$("emailMap").getHeight())/2)+"px";
     initEmailMap();
     
     var formInputs = $$(".clearInput")
     for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        if(theInput.defaultText && !theInput.hasClassName('blueText'))
            theInput.addClassName('blueText');
     }
     if(!$('messageEmailMap').hasClassName('blueText'))
         $('messageEmailMap').addClassName('blueText');
}

EmailMap.prototype.onMapWindowShow=function(evt){
    if (evt.target != this) {
        closeEmailMap();
    }
}

function closeEmailMap(){
    var isIE6 = dojo.isIE && dojo.isIE<7;
      if(!isIE6)
        emailMapTool.image.src = baseHREF+"images/emailMapTool.png";
      else
        emailMapTool.image.src = baseHREF+"images/emailMapTool.gif";  
    replaceAllDefaultText();
    $('emailMap').style.visibility="hidden";
    $("emailMapError").innerHTML='';
    $("emailMapForm").reset();
    $('emailMapLoading').style.display="none";
    $('emailMapError').style.visibility="hidden";
    $('emailMapContent').style.display="block";
    //$('emailMapSend').style.display="block";
    //$('emailMaPErrorMessage').style.display="none";
    $("emailMapLoading").style.display = "none";
    $("emailMaPConfirmMessage").style.display = "none";
    $("emailMap").className="emailMapBox";
}
        


function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 1;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);
  dragObj.width=dragObj.elNode.offsetWidth;
  dragObj.height=dragObj.elNode.offsetHeight;

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {

    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
     
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.
dragLeftPos=(dragObj.elStartLeft + x - dragObj.cursorStartX)
dragTopPos=(dragObj.elStartTop  + y - dragObj.cursorStartY)


if(dragOut ||  ((dragLeftPos+dragObj.width)<document.body.offsetWidth && dragLeftPos>0 &&  dragTopPos>0 && (dragTopPos+dragObj.height)<document.body.offsetHeight) ){
  dragObj.elNode.style.left = dragLeftPos + "px";
  dragObj.elNode.style.top  = dragTopPos + "px";
  //console.debug(document.body.offsetWidth+" "+document.body.offsetHeight+" "+(dragLeftPos+dragObj.width)+" "+dragTopPos);
  }


  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}


function checkEmail(email) {

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) 
 return false;
else
 return true;

}

function checkEmailMapForm(){
    if(removeSpaces($("senderEmailMap").value)!='' ){
       if(!checkEmail($("senderEmailMap"))){
           $('emailMapError').style.visibility = "visible";
           $("emailMapError").innerHTML=errorEmailMapSender;
           replaceAllDefaultText();
           return false;

       }
   }
  
   if(!checkEmail($("receiverEmailMap"))) {
       $('emailMapError').style.visibility = "visible";
       $("emailMapError").innerHTML=errorEmailMapReceiver;
       replaceAllDefaultText();
       return false;
   }
        
   return true; 
}

function removeSpaces(string) {
  return string.split(' ').join('');
}

function removeNL(s) {
  /*
  ** Remove NewLine, CarriageReturn and Tab characters from a String
  **   s  string to be processed
  ** returns new string
  */
  r = "";
  for (i=0; i < s.length; i++) {
    if (s.charAt(i) != '\n' &&
        s.charAt(i) != '\r' &&
        s.charAt(i) != '\t') {
      r += s.charAt(i);
      }
    }
  return r;
  }




function textCounter(maxlimit) {
  if ($("messageEmailMap").value.length > maxlimit) // if too long...trim it!
    $("messageEmailMap").value = $("messageEmailMap").value.substring(0, maxlimit);


}


/**
 * NOTE IMPORTANTE:
 * POUR QUE LE CONTROLE FONCTIONNE CORRECTEMENT, IL EST IMPORTANT DE METTRE LA PROPRIETE [sessionful: true] 
 * DANS LA DECLARATION DU WSNAV. IL SERA A VALIDER SI ON PEUT FORCER CE STATUT LORS DE L'INITIALISATION DU CONTROLE
 */

/*Modified by slahrech on 2008-09-27 */
/**
 * Create a new LayerControl instance.
 * @class Control used to get information of the map.
 * @constructor
 */
function MwLayerControl(config) {
    this.id = MwLayerControl.idCounter++;
    this.name = "MwLayerControl_" + this.id;
    this.isCallingServer=false;
    this.config = config;    // if config.layers == null map default use
    
    if (this.config.labelControl == undefined)  // by default it's on
        this.config.labelControl = true;
    
    this.displayDiv; 
    this.layers = [];
    this.connectHandle= [];
    this.divVisible=true;
    
    this.layersVisibilityInProcess = [];
    this.changeLayersVisibilityTimeoutId;
    this.labelLayersVisibilityInProcess = [];
    this.changeLabelLayersVisibilityTimeoutId;
    
    MwLayerControl.list[this.id] = this;
}
MwLayerControl.prototype = new AbstractControl;

MwLayerControl.multiClickTimeout = 1000;
MwLayerControl.idCounter = 0;
// afin de permettre d'avoir plus d'un layer control
MwLayerControl.list = [];

/*
 *
 */
MwLayerControl.prototype.init = function(wsnav) {
   
    this.wsnav = wsnav;
    this.icon = {
        none: baseHREF + 'images/checkboxNone.gif',
        lcOn: baseHREF + 'images/checkboxBlueEnabled.gif',
        lcOnPink: baseHREF + 'images/checkboxPinkEnabled.gif',
        lcOff: baseHREF + 'images/checkboxClearEnabled.gif',

        lcOnDis: baseHREF + 'images/checkboxBlueDisabled.gif',
        lcOnPinkDis: baseHREF + 'images/checkboxPinkDisabled.gif',
        lcOffDis: baseHREF + 'images/checkboxClearDisabled.gif'
    };
    
    /* listener to change display status on map zoom change*/
    this.displayDiv=document.getElementById(this.config.displayDivId);
    this.wsnav.eventDispatcher.register("before_map_loaded", this, "setDisabled");
    this.wsnav.eventDispatcher.register("map_loaded", this, "mapZoomListener");
    
    // init layers information
    if (this.config.layers) {
        var layers = this.config.layers;
        for (var i=0; i<layers.length; i++) {
            var layer = layers[i];
            this.layers[this.layers.length] = {
                configId: i,
                name: layer.name,
                alias: layer.alias,
                layers: layer.layers
            }
                
        }
    } else {
        var layers = this.wsnav.layers;
        for (var i=0; i<layers.length; i++) {
            var layer = layers[i];
            this.layers[this.layers.length] = {
                name: layer.state.name,
                layers: []
            }
        }
    }

}

/*
 *
 */
MwLayerControl.prototype.mapZoomListener = function(evt) {
    if(this.divVisible)
        this.refreshLayersStatus();

}

/*
 *
 */
MwLayerControl.prototype.bindLayersToPrototype = function(parentLayerName, layers) {
    for (var i=0; i<layers.length; i++) {
        var layer = layers[i];
        //layer.parentLayerName
        layer.init = LayerStatus.prototype.init;
        layer.init(this);
    }
}
 
/*
 *
 */
MwLayerControl.prototype.refreshLayersStatus = function() {
    this.recievedReponses = [];
    for (var i=0; i<this.layers.length; i++) {
        var layer = this.layers[i];
        var mapLayer = this.wsnav.getLayerByName(layer.name);
        
        var layerConfig;
        if (typeof(layer.configId) != "undefined"){
            layerConfig = this.config.layers[layer.configId];
        }
        

        if (mapLayer.type == SERVER_LAYER) {
            this.requestServerLayersStatus(mapLayer, layerConfig);
        } else if (mapLayer.type == OVERLAY_LAYER) {
            this.requestOverlayLayersStatus(mapLayer, layerConfig);
        }
    }
}

/*
 *
 */
MwLayerControl.prototype.requestServerLayersStatus = function(mapLayer, layerConfig) {
     
    var requestParams = {};
    requestParams.operation = "getLayersStatus";
    requestParams.layerControlId = this.id;
    requestParams.layerName = mapLayer.state.name;

    if (layerConfig)
        requestParams.requestedLayers = layerConfig.layers;
    callServer2(mapLayer.state.serverURL+"MainServlet",
        {
            config: dojo.toJson(this.wsnav.config),
            state: dojo.toJson(mapLayer.state),
            requestParams: dojo.toJson(requestParams)
        },
        function (response, ioArgs){
            if (response.responseParams.ERROR) {
               
                console.info("error"+response.responseParams.ERROR);
               
            } else {                 
                var lc = MwLayerControl.list[response.responseParams.layerControlId];
                lc.processRefreshStatus(response.responseParams.layerName, response.responseParams.layersStatus);
            }
           
        }
        );
}

/*
 *
 */
MwLayerControl.prototype.requestOverlayLayersStatus = function(mapLayer, layerConfig) {
    this.recievedReponses[mapLayer.state.name] = true;
// to be done!!!
}

MwLayerControl.prototype.processRefreshStatus = function(layerName, layersStatus) {
    
    
    this.recievedReponses[layerName] = true;
    for (var i=0; i<this.layers.length; i++) {
        if (this.layers[i].name == layerName){
            this.layers[i].layers = layersStatus;
            for(var j=0;j<this.layers[i].layers.length;j++){
                if(this.layers[i].layers[j].id == -1){
                    this.layers[i].layers[j].visible = googleLayer.state.visible;
                }
            }
        }
    }

    this.bindLayersToPrototype(layerName, layersStatus);
    
    if (this.receivedAllResponse()) {
        this.draw();
    }
}

MwLayerControl.prototype.receivedAllResponse = function() {
    var layers;
    if (this.config.layers) {
        layers = this.config.layers;
        for (var i=0; i<this.layers.length; i++) {
            if (!this.recievedReponses[layers[i].name])
                return false;
        }
    } else {
        layers = this.wsnav.layers;
        for (var i=0; i<layers.length; i++) {
            if (!this.recievedReponses[layers[i].state.name])
                return false;
        }
    }
    return true;
}

/*
 *
 */
MwLayerControl.prototype.draw = function() {
    this.displayDiv.innerHTML = '';
    
    
    for (var j=0; j<this.layers.length; j++) {
        var mapLayer = this.layers[j];

        var mainDiv=document.createElement('div');

        var titleDiv = document.createElement('div');
        titleDiv.className = "layersCTitle clearfix"
        
        var titleDivLayer = document.createElement('div');
        titleDivLayer.className ="layersCTitle contentText";
        titleDivLayer.innerHTML=(layerCLayerTitle);
        
        var titleDivVisibility =document.createElement('div');
        titleDivVisibility.className ="layersCTitle contentInput";
        var titleVisibilityImg=document.createElement('img');
        titleVisibilityImg.src=baseHREF+layerCVisibilityImageName;
        titleVisibilityImg.alt=layerCVisibilityAlt;
        titleVisibilityImg.title=layerCVisibilityAlt;
        titleDivVisibility.appendChild(titleVisibilityImg);
        
        
        
        
        var titleDivInfo = document.createElement('div');
        titleDivInfo.className="layersCTitle contentInputright";
        var titleInfoImg=document.createElement('img');
        titleInfoImg.src=baseHREF+layerCInfoImageName;
        titleInfoImg.alt=layerCInfoAlt;
        titleInfoImg.title=layerCInfoAlt;
        titleDivInfo.appendChild(titleInfoImg);
        
        var titleDivSpacing = document.createElement('div');
        titleDivSpacing.className="layersCTitleSpacing ";
        
        
        titleDiv.appendChild(titleDivLayer); 
        titleDiv.appendChild(titleDivVisibility);
        titleDiv.appendChild(titleDivInfo);
       

        for (var i=0; i<mapLayer.layers.length; i++) {
             
            var layer = mapLayer.layers[i];
            
            
            var rowDiv=document.createElement('div');
            var rowNameDiv=document.createElement('div');
            var rowVisibilityDiv=document.createElement('div');
            var rowInfoDiv=document.createElement('div');
            
            
            rowNameDiv.appendChild(document.createTextNode(layer.alias ? (layer.alias).replace("&#92;&#39;", "\'") : (layer.name).replace("&#92;&#39;", "\'")));
            
            layer.cbV = document.createElement('img');
            layer.setVisibilityCBIcon();
            layer.cbV.style.cursor = 'pointer';
            rowVisibilityDiv.appendChild(layer.cbV);
            
            layer.cbL = document.createElement('img');
            layer.setLabelVisibilityCBIcon();
            if (this.config.labelControl && !this.theme && layer.id>=0)//agilbert
                layer.cbL.style.cursor = 'pointer';
            rowInfoDiv.appendChild(layer.cbL);
            
            
            var spacingDiv= document.createElement('div');
            
            if (layer.theme) {          
           
                rowDiv.className="themesLCRows clearfix"
                rowNameDiv.className="themesLCRows contentName maximumSizeRule";
                rowVisibilityDiv.className="themesLCRows contentInputV";
                rowInfoDiv.className="themesLCRows contentInputI";
                spacingDiv.className="themesLCRowSpacing";
                
                
            }else{
               

                
                
                rowDiv.className="layersLCRows clearfix"
                rowNameDiv.className="layersLCRows contentName maximumSizeRule";
                rowVisibilityDiv.className="layersLCRows contentInputV";
                rowInfoDiv.className="layersLCRows contentInputI";  
                spacingDiv.className="layersLCRowSpacing";
            } 
                           
            rowDiv.appendChild(rowNameDiv);
            rowDiv.appendChild(rowVisibilityDiv);
            rowDiv.appendChild(rowInfoDiv);

        
            
            mainDiv.appendChild(rowDiv);
            mainDiv.appendChild(spacingDiv);
            this.connectHandle.push(dojo.connect(layer.cbV, "onclick", layer, "changeVisibility"));
            if (this.config.labelControl && !this.theme && layer.id>=0)//agilbert
                this.connectHandle.push(dojo.connect(layer.cbL, "onclick", layer, "changeLabelVisibility"));
        }

        this.displayDiv.appendChild(titleDiv);
        this.displayDiv.appendChild(titleDivSpacing);
        
        this.displayDiv.appendChild(mainDiv);
        
      
    }
    initTabSizes();

}

LayerStatus.changeLayersVisibilityCallServer = function(lcId) {
  
    var MwlayerControl = MwLayerControl.list[lcId];
    MwlayerControl.setDisabled();
    var requestParams = {
        operation: "setLayersVisibility"
    };
    requestParams.layersVisibility = MwlayerControl.layersVisibilityInProcess;
    requestParams.layerControlId = MwlayerControl.id;
    
     
    
    
    for(var i=0;i<MwlayerControl.config.layers.length;i++){
        var mapLayer = MwlayerControl.wsnav.getLayerByName(MwlayerControl.config.layers[i].name);
     
        // Setup client state
        for(var j=0;j<MwlayerControl.layersVisibilityInProcess.length;j++){
            if(mapLayer.state.layersStatus!= undefined){
                for (var k=0;k<mapLayer.state.layersStatus.length;k++){
                    if ( mapLayer.state.layersStatus[k].id==MwlayerControl.layersVisibilityInProcess[j].id){
                        mapLayer.state.layersStatus[k].visible=MwlayerControl.layersVisibilityInProcess[j].visibility
                        if(MwlayerControl.labelLayersVisibilityInProcess[j])
                            mapLayer.state.layersStatus[k].labelVisible=MwlayerControl.labelLayersVisibilityInProcess[j].labelVisibility;
                    }
                }
            }
        }
        if(!MwlayerControl.isCallingServer){
            MwlayerControl.isCallingServer=true;
            callServer2(mapLayer.state.serverURL+"MainServlet",
                {
                    config: dojo.toJson(MwlayerControl.wsnav.config),
                    state: dojo.toJson(mapLayer.state),
                    requestParams: dojo.toJson(requestParams)
                },
                function (response, ioArgs){
                    MwlayerControl.isCallingServer=false;
              
                    if(response.responseParams.ERROR) {
                        console.warn(response.responseParams.ERROR);
                  
                    } else {
                        MwLayerControl.list[response.responseParams.layerControlId].wsnav.refreshMap();
                  
                    }
                }
                );
        }
        MwlayerControl.changeLayersVisibilityTimeoutId = null;
        MwlayerControl.layersVisibilityInProcess = [];
             
      
    }

}

/*
 *
 */
LayerStatus.changeLabelLayersVisibilityCallServer = function(lcId) {
    var MwlayerControl = MwLayerControl.list[lcId];
    MwlayerControl.setDisabled();
    var requestParams = {
        operation: "setLabelLayersVisibility"
    };
    requestParams.labelLayersVisibility = MwlayerControl.labelLayersVisibilityInProcess;
    requestParams.layerControlId = MwlayerControl.id;
    for(var i=0;i<MwlayerControl.config.layers.length;i++){

        var mapLayer = MwlayerControl.wsnav.getLayerByName(MwlayerControl.config.layers[i].name);
    
    
        // Setup client state
        for(var j=0;j<MwlayerControl.labelLayersVisibilityInProcess.length;j++){
            if(mapLayer.state.layersStatus!= undefined){
                for (var k=0;k<mapLayer.state.layersStatus.length;k++){
                    if ( mapLayer.state.layersStatus[k].id==MwlayerControl.labelLayersVisibilityInProcess[j].id){
                        mapLayer.state.layersStatus[k].labelVisible=MwlayerControl.labelLayersVisibilityInProcess[j].labelVisibility;
                        if(MwlayerControl.layersVisibilityInProcess[j])
                            mapLayer.state.layersStatus[k].visible=MwlayerControl.layersVisibilityInProcess[j].visibility;
                    }
                }
            }
        }


        if(!MwlayerControl.isCallingServer){
            MwlayerControl.isCallingServer=true;
            callServer2(mapLayer.state.serverURL+"MainServlet",
                {
                    config: dojo.toJson(MwlayerControl.wsnav.config),
                    state: dojo.toJson(mapLayer.state),
                    requestParams: dojo.toJson(requestParams)
                },
                function (response, ioArgs){
                    MwlayerControl.isCallingServer=false;
                    if(response.responseParams.ERROR) {
                        console.warn(response.responseParams.ERROR);
                    } else {
                        MwLayerControl.list[response.responseParams.layerControlId].wsnav.refreshMap();
                    }
                }
                );
        }
        MwlayerControl.changeLabelLayersVisibilityTimeoutId = null;
        MwlayerControl.labelLayersVisibilityInProcess = [];
    }


}


/**
 * LayerStatus
 */
function LayerStatus() { }

LayerStatus.prototype.init = function(MwlayerControl) {
    this.MwlayerControl = MwlayerControl;
    for (var property in LayerStatus.prototype)
        this[property] = LayerStatus.prototype[property];
}

/*
 *
 */
LayerStatus.prototype.changeVisibility = function(evt) {
    if(this.id==-1){
        googleLayer.setVisible(!this.visible);
    }else{
        this.MwlayerControl.layersVisibilityInProcess[this.MwlayerControl.layersVisibilityInProcess.length] =
        {
            'id': this.id,
            'name': this.name,
            'visibility': !this.visible
            };

        MwLayerControl.list[this.MwlayerControl.id] = this.MwlayerControl;
        if (this.MwlayerControl.changeLayersVisibilityTimeoutId)
            window.clearTimeout(this.MwlayerControl.changeLayersVisibilityTimeoutId);
        this.MwlayerControl.changeLayersVisibilityTimeoutId = window.setTimeout('LayerStatus.changeLayersVisibilityCallServer('+this.MwlayerControl.id+')', MwLayerControl.multiClickTimeout);
    }

    this.visible = !this.visible;
    this.setVisibilityCBIcon();

    


}

/*
 *
 */
LayerStatus.prototype.changeLabelVisibility = function(evt) {


    this.MwlayerControl.labelLayersVisibilityInProcess[this.MwlayerControl.labelLayersVisibilityInProcess.length] =
    {
        'id': this.id,
        'name': this.name,
        'labelVisibility': !this.labelVisible
        };
    if (this.MwlayerControl.changeLabelLayersVisibilityTimeoutId)
        window.clearTimeout(this.MwlayerControl.changeLabelLayersVisibilityTimeoutId);
    this.MwlayerControl.changeLabelLayersVisibilityTimeoutId = window.setTimeout('LayerStatus.changeLabelLayersVisibilityCallServer('+this.MwlayerControl.id+')', MwLayerControl.multiClickTimeout);
    
    this.labelVisible = !this.labelVisible;
    this.setLabelVisibilityCBIcon();

}

/*
 *
 */
LayerStatus.isInZoom = function(zoomRange, mapZoom) {
    if (zoomRange.minZoom < mapZoom && mapZoom < zoomRange.maxZoom)
        return true;
    return false;
}

/*
 *
 */
LayerStatus.prototype.setVisibilityCBIcon = function() {
    if (!this.visible)
        this.cbV.src = this.MwlayerControl.icon.lcOff;
    else if (this.zoomRange.active && !LayerStatus.isInZoom(this.zoomRange, this.mapZoom))
        this.cbV.src = this.MwlayerControl.icon.lcOnPink;
    else
        this.cbV.src = this.MwlayerControl.icon.lcOn;
}

/*
 *
 */
LayerStatus.prototype.setLabelVisibilityCBIcon = function() {
    if (this.theme||this.id<0)
        this.cbL.src = this.MwlayerControl.icon.none;
    else if (!this.labelVisible)
        this.cbL.src = this.MwlayerControl.icon.lcOff;
    else if (this.labelZoomRange.active && !LayerStatus.isInZoom(this.labelZoomRange, this.mapZoom))
        this.cbL.src = this.MwlayerControl.icon.lcOnPink;
    else
        this.cbL.src = this.MwlayerControl.icon.lcOn;
}


MwLayerControl.prototype.setVisibility = function(visibility)
{
    this.divVisible=visibility;
}
    

MwLayerControl.prototype.setDisabled = function()
{

        
    if ( !document.getElementById
        || !document.getElementsByTagName) 
        
        return;

    var nodesToDisable = {
        img :''
    };

    var node, nodes;
    var div = this.displayDiv;
    if (!div)
            
        return;

    nodes = div.getElementsByTagName('*');
    if (!nodes)
        return;

    var i = nodes.length;
    for (var k=0; k<this.connectHandle.length; k++) {
        dojo.disconnect(this.connectHandle[k]);
    }
    while (i--){
        node = nodes[i];
        if ( node.nodeName
            && node.nodeName.toLowerCase() in nodesToDisable ){
                
            var imgOn = new Image();
            imgOn.src = this.icon.lcOn;
                
            var imgPink = new Image();
            imgPink.src = this.icon.lcOnPink;
                
            var imgOff = new Image();
            imgOff.src = this.icon.lcOff;
    
            if (node.src==imgOn.src){
                node.src=this.icon.lcOnDis;
                node.onclick=null ;
            }
            if (node.src==imgPink.src){
                node.src=this.icon.lcOnPinkDis;
                node.onclick=null;
            }
            if (node.src==imgOff.src){
                node.src=this.icon.lcOffDis;
                node.onclick=null;
                    
            }
        //console.debug(node.src+"  |  "+imgPink.src);
         
       
        }
    }

}