  var MyMap = null;
  var tileSourceSpec = null;
  var tileSourceSpecFIRE = null;
  var selectedParcel = null;
  var findCommand = false;
  var pushpin = null;
  var switchtiles = true;
  var styles = '&STYLES=style1';
  var SleepVal = 1;
  
  var ParcelDemonstration = "<h1>PARCELS DEMONSTRATION</h1>";
  var DiscoverPower = "<h2>Discover the POWER of Parcel data</h2>";
  var ParcelDataAllows = "<h5>Parcel data allows property characteristics to be mapped and analyzed across an entire area of interest.  Using a database identifier that links to the parcel polygon, a limitless amount of information can be associated with properties including valuations, service areas, environmental factors, demographics and more.<h5>";
  var ParcelDataAlso = "<h5>Parcel data also enables sophisticated spatial analysis such as proximity, overlay and buffer zone operations.  Numerous industries use parcel data in their daily operations, and many are realizing new ways to enhance their capabilities, provide additional services and reduce operating costs.<h5>";
  var HorizontalRule = "<hr style=\"width:95%; color:Gray; text-align:center\" />";
  var ParcelInformation = "<h3>PARCEL INFORMATION</h3>";
  var ShiftClick = "<h4>To obtain Parcel information, please shift click on any parcel displayed.</h4>";
  var BoldTest = "<b>Bold</b> Test";

  window.onresize = OnMapResize;

  function LoadMap ( )
  {
    if(MyMap != null)
    {
      MyMap.Dispose();
    }
    try
    {
      MyMap = new VEMap('MyMapDIV');
      
      if ( document.FormMap.hidZoomLevel.value == "0" )
      {
        MyMap.LoadMap ( new VELatLong(39,-109) );
      }
      else
      {
        var latLon = new VELatLong ( document.FormMap.hidCenterLatitude.value, document.FormMap.hidCenterLongitude.value );
        MyMap.LoadMap ( latLon, document.FormMap.hidZoomLevel.value );
      } 
      
      MyMap.AttachEvent ( "onchangeview", OnMapViewChange );
      MyMap.AttachEvent ( "onclick", OnMapClick );
      MyMap.AttachEvent ( "onchangemapstyle", OnMapStyleChange );
      SwitchTileLayers ( );
     }       
     catch ( VEException )            
     {
  //               document.getElementById('lblError').innerText =
       alert ( VEException.message );// VEException.name  VEException.source;
     }
  }     

  function GetMapLocation ( )
  {
    try
    {
      var center = MyMap.GetCenter ( );  
      document.FormMap.hidCenterLongitude.value = center.Longitude;
      document.FormMap.hidCenterLatitude.value = center.Latitude;

      var y = MyMap.GetTop ( );
      var x = MyMap.GetLeft ( );
      var pixel = new VEPixel ( x, y );

      var upperleftcorner = MyMap.PixelToLatLong ( pixel );

      document.FormMap.hidLeftLongitude.value = upperleftcorner.Longitude;
      document.FormMap.hidTopLatitude.value = upperleftcorner.Latitude;
      
      if ( findCommand )
      {
        findCommand = false;
        if ( parseInt ( document.FormMap.hidZoomLevel.value ) > MyMap.GetZoomLevel ( ) )
        {
          MyMap.SetZoomLevel ( parseInt ( document.FormMap.hidZoomLevel.value ) );
        }
      }
      else
      {
        document.FormMap.hidZoomLevel.value = MyMap.GetZoomLevel();
      }
      
      
      document.FormMap.hidMapWidth.value = document.getElementById ( 'MyMapDIV' ).style.pixelWidth;
      document.FormMap.hidMapHeight.value = document.getElementById ( 'MyMapDIV' ).style.pixelHeight;
    }
    catch ( VEException )            
    {
      alert ( VEException.message );// VEException.name  VEException.source;
    }
  }
  
  function SwitchTileLayers ( )
  {

    if ( switchtiles )
    {
      try
      {
        if ( tileSourceSpec != null )
        {
          MyMap.DeleteTileLayer ( "G1Map" );
          tileSourceSpec = null;
        }
      }
      catch(e)
      {
      }
      
      try
      {        
        switch ( document.FormMap.hidNewTile.value )
        {
          case '0':
            tileSourceSpec = null;
            break;
          case '1':
            tileSourceSpec = new VETileSourceSpecification ( "G1Map", 
                                                              document.FormMap.hidWMSURL1.value + styles,
                                                              1,      // number of hosting servers
                                                              null,
                                                              15,      // min zoom
                                                              19 );     // max zoom
          
            MyMap.AddTileLayer ( tileSourceSpec, true );
            MyMap.ShowTileLayer ( "G1Map" );
            //alert("document.FormMap.hidWMSURL3.value + styles: "+document.FormMap.hidWMSURL1.value + styles);
            //AddFireWMS();
            break;
            
            
          case '2':
            tileSourceSpec = new VETileSourceSpecification ( "G1Map", 
                                                              document.FormMap.hidWMSURL2.value + styles,
                                                              1,      // number of hosting servers
                                                              null,
                                                              15,      // min zoom
                                                              19 );     // max zoom
            MyMap.AddTileLayer ( tileSourceSpec, true );
            MyMap.ShowTileLayer ( "G1Map" );
            //alert("document.FormMap.hidWMSURL3.value + styles: "+document.FormMap.hidWMSURL2.value + styles);
            //AddFireWMS();

            break;
          case '3':
            tileSourceSpec = new VETileSourceSpecification ( "G1Map", 
                                                              document.FormMap.hidWMSURL3.value + styles,
                                                              1,      // number of hosting servers
                                                              null,
                                                              15,      // min zoom
                                                              19 );     // max zoom
            
            //alert("document.FormMap.hidWMSURL3.value + styles: "+document.FormMap.hidWMSURL3.value + styles);
            
            MyMap.AddTileLayer ( tileSourceSpec, true );
            MyMap.ShowTileLayer ( "G1Map" );
            
            
            break;
            
        }
      }
      catch(e)
      {
      }        
    }      
    
    switchtiles = false;
    document.FormMap.hidCurrentTile.value = document.FormMap.hidNewTile.value;
  }
  

  function AddFireWMS()
  {
     // attempt to add the fire WMS
     var fireurl = "http://www.cadastra.com/wms/centrus.asp?";
     var firerequeststring = "REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=TRUE&BGCOLOR=0x";
     var testfirerequeststring =
         "http://www.cadastra.com/wms/centrus_getmap.asp?service=wms&version=1.1.1&request=getmap&layers=fire&srs=epsg:4326&BBOX=%16,%17,%18,%19&WIDTH=256&HEIGHT=256&TRANSPARENT=TRUE&FORMAT=image/png";
         //"http://www.cadastra.com/wms/centrus_getmap.asp?service=wms&version=1.1.1&request=getmap&layers=fire&format=image/png&srs=epsg:4326&width=1040&height=698&styles=default&BBOX=%16,%17,%18,%19&BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE";
         
         //"http://www.cadastra.com/wms/centrus.asp?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=fire&STYLES=&FORMAT=image/png&BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE&SRS=EPSG:4326&WIDTH=256&HEIGHT=256"
            
     //alert("testfirerequeststring: "+testfirerequeststring);
     
     // Only works in 3D for now...
     
     var bounds = [new VELatLongRectangle(new VELatLong(34,-117), new VELatLong(30,-115))];
     tileSourceSpecFIRE = new VETileSourceSpecification ( "FireRiskLayer", 
                                                          testfirerequeststring,
                                                          1,      // number of hosting servers
                                                          bounds,
                                                          1,      // min zoom
                                                          19 );     // max zoom
            
	 tileSourceSpec.Opacity = 0.5;
	 tileSourceSpec.MaxZoom = 19;
	 tileSourceSpec.MinZoom = 1;
	 tileSourceSpec.zIndex = 100;
	 tileSourceSpec.NumServers = 1;				
     MyMap.AddTileLayer ( tileSourceSpecFIRE, true );
     MyMap.ShowTileLayer ( "FireRiskDemo" );
  }

  
  function RemovePushpins ( )
  {
    if ( pushpin != null )
    {
      try
      {
        MyMap.DeleteShape ( pushpin );
      }
      catch ( VEException )
      {
      }
      pushpin = null;
            

    }
    
    return;
  }

  
  function RemoveInterpolatedPushpins ( )
  {
    if ( Ipushpin != null )
    {
      try
      {
        MyMap.DeleteShape ( Ipushpin );
      }
      catch ( VEException )
      {
      }
      Ipushpin = null;
    }
    
    if ( Gpushpin != null )
    {
      try
      {
        MyMap.DeleteShape ( Gpushpin );
      }
      catch ( VEException )
      {
      }
      Gpushpin = null;
    }

    return;
  }

  function DispatchInfo ( x, y )
  {
    GetInformation ( x, y );
    return;
  }
   
  function ProcessCommand ( )
  {
    
    /*
    timedMsg();
    
    if (MyMap != null || document.FormMap.hidCommand.value  != '1')
    {
        //var newmap = "Why is map null?";
        //alert ("Synchronizing map display.  Please cick the ok button.");
        //alert("redo of map control...");
        //MyMap.Dispose();
        //MyMap = new VEMap('MyMapDIV');
        LoadMap();
    }
    */
    
    //alert("In ProcessCommand...");
    //document.getElementById("MyMapDIV").style["visibility"] = "hidden";
        
    if (MyMap == null)
    {
        window.status = "Map Control is null!";
        //LoadMap();
    }
    else
    {
    try
    {
      //alert("document.FormMap.hidCommand.value: "+document.FormMap.hidCommand.value);
      switch ( document.FormMap.hidCommand.value )
      {
        case '1':
          ShowTextPanel();
          MyMap.SetMapStyle(VEMapStyle.Hybrid);
          RemovePushpins ( );
          var latLong = new VELatLong(document.FormMap.hidCommandString1.value, document.FormMap.hidCommandString2.value);
          if ( MyMap.GetZoomLevel ( ) < 17 )
          {
            MyMap.SetZoomLevel ( 17 );
          }
          MyMap.PanToLatLong(latLong);
          pushpin = new VEShape(VEShapeType.Pushpin, latLong);
          MyMap.AddShape(pushpin);
          pushpin.SetTitle("Found Location");
          pushpin.SetDescription(document.FormMap.hidCommandString1.value + ', ' + document.FormMap.hidCommandString2.value);
          
          break;
        case '2':
          ShowTextPanel();
          if ( MyMap.GetZoomLevel ( ) < 17 )
          {
            MyMap.SetZoomLevel ( 17 );
          }
          MyMap.SetMapStyle(VEMapStyle.Hybrid);
          RemovePushpins ( );
          findCommand = true;
          MyMap.Find ( document.FormMap.hidCommandString1.value,
                     document.FormMap.hidCommandString2.value,
                     null,
                     null,
                     0,
                     1,
                     true,
                     true,
                     true,
                     true,
                     FindResults );
          //window.status = "Executed MyMap.Find...";
          break;
        case '3':
          ShowTextPanel();
          MyMap.SetMapStyle(VEMapStyle.Hybrid);
          RemovePushpins ( );
          var latLong = new VELatLong(document.FormMap.hidCommandString3.value, document.FormMap.hidCommandString4.value) ;
         
          if ( MyMap.GetZoomLevel ( ) < 17 )
          {
            MyMap.SetZoomLevel ( 17 );
          }
          SetPushpin();
          //MyMap.PanToLatLong(latLong);
          MyMap.SetCenterAndZoom(latLong, MyMap.GetZoomLevel());
          //window.status = "Executed MyMap.SetCenterAndZoom...";
                    
          break;

      }
      
      
    }
    catch ( VEException )            
    {
      alert ("Process Records Exception: "+ VEException.message );// VEException.name  VEException.source;
    }
    } // else on if map control is null
    
    document.FormMap.hidCommand.value = 0;
    
// force refresh    
    
    document.FormMap.hidNewTile.value = document.FormMap.hidCurrentTile.value;
    document.FormMap.hidCurrentTile.value = 0;
    
    //document.getElementById("MyMapDIV").style["visibility"] = "visible";
    SwitchTileLayers ( );
    
    window.status = "Done processing...";
    
  }  

  function FindResults ( layer, results, places ) //, hasMore, VEError )
  {
  
    if ( document.FormMap.hidCommandString1.value != '' )
    {
      try
      {
        pushpin = layer.GetShapeByIndex ( 0 );
      }
      catch ( VEException )
      {
//        alert ( VEException.message );
      }
      
      return;
    }
    
    if ( MyMap.GetZoomLevel ( ) < 15 )
    {
        MyMap.SetZoomLevel ( 15 );
    }
    //ShowTextPanel();

    document.FormMap.hidCommandString1.value = '';
    document.FormMap.hidCommandString2.value = '';
    document.FormMap.hidCommandString3.value = '';
    document.FormMap.hidCommandString4.value = '';
    
    try
    {
      latlong = places [ 0 ].LatLong;
      
      pushpin = new VEShape(VEShapeType.Pushpin, latlong);
 
      MyMap.AddShape(pushpin);
      pushpin.SetTitle("Found Location");
      pushpin.SetDescription(places[0].Name);
    }
    catch ( VEException )
    {
      alert ( VEException.message );
    }
  }

  function GetTilePath ( e )
  {   // UNUSED: override to supply tile path
    alert ( "XPOS: " + e.XPos );
    alert ( "YPOS: " + e.YPos );
    alert ( "ZOOM: " + e.ZoomLevel );
  }

  function GetInformation ( x, y )
  {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) 
     {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      try 
      {
        xmlhttp = new XMLHttpRequest();
      } catch (e) {
        xmlhttp=false;
      }
    }
    
    if (!xmlhttp && window.createRequest) {
      try {
        xmlhttp = window.createRequest();
      } catch (e) {
        xmlhttp=false;
      }
    }
  
    var url = document.FormMap.hidGFIURL.value + "&X=" + x + "&Y=" + y;
    
    try
    {  
      try {netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');} catch(e) {}  
      xmlhttp.open("GET", url,true);
      xmlhttp.onreadystatechange=function() 
      {
        if (xmlhttp.readyState==4) 
        {
//          alert ( xmlhttp.responseText );
          RenderSelectedParcel ( xmlhttp.responseText );
        }
       }          
     }
     catch(e)
     {
      alert ( e );
     }        
     xmlhttp.send(null)
  }  
  
  function RenderSelectedParcel ( aInfo )
  {
  //alert ( aInfo );
  
    try
    {
      if ( aInfo.indexOf ( '~' ) > -1 )
      {
    
        //document.getElementById("tbInfo").value = aInfo.substring ( 0, aInfo.indexOf ( '~' ) );
        var llstr = aInfo.substr ( aInfo.indexOf ( '~' ) + 1 );
        
        var ptarray = new Array ( );
        
        while ( llstr.length > 0 )
        {
          var lng = llstr.substring ( 0, llstr.indexOf ( ',' ) );
          llstr = llstr.substr ( llstr.indexOf ( ',' ) + 1 );
          var lat = llstr.substring ( 0, llstr.indexOf ( ',' ) );
          
          if ( lat.length == 0 )
          {
            lat = llstr;
          }
          
//alert ( lng );
//alert ( parseFloat ( lng ) );
//alert ( lat );
//alert ( parseFloat ( lat ) );
          
          ptarray.push ( new VELatLong ( parseFloat ( lat ), parseFloat ( lng ) ) );
          
          if ( llstr.indexOf ( ',' ) == -1 )
          {
            break;
          }            
          
          llstr = llstr.substr ( llstr.indexOf ( ',' ) + 1 );
        }
        
        if ( selectedParcel != null )
        {
          MyMap.DeleteShape ( selectedParcel );
        }
        
        selectedParcel = new VEShape ( VEShapeType.Polygon, ptarray );
        selectedParcel.SetLineWidth ( 1 );
        selectedParcel.SetLineColor ( new VEColor ( 255, 0, 0, 0.25 ) );
        selectedParcel.SetFillColor ( new VEColor ( 255, 0, 0, 0.25 ) );
        selectedParcel.HideIcon ( );
        
        MyMap.AddShape ( selectedParcel );
//        alert ( llstr );
      
      }
      else
      {
        //document.getElementById("tbInfo").value = aInfo;
        //alert(aInfo);
        var sIndex, eIndex;
        var sSRCDT = "&nbsp;&nbsp;<b>SRC DATE:</b>&nbsp;";
        sIndex = aInfo.indexOf(" ");
        eIndex = aInfo.indexOf("RELDT");
        sSRCDT = sSRCDT+aInfo.substring(sIndex+1,eIndex-1);
        
        var sRELDT = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RELEASE DATE:</b> &nbsp;";
        sIndex = aInfo.indexOf("RELDT: ");
        eIndex = aInfo.indexOf("ADDRESS");
        sRELDT = sRELDT+aInfo.substring(sIndex+7,eIndex-1);

        var sADDRESS = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADDRESS:</b> &nbsp;";
        sIndex = aInfo.indexOf("ADDRESS: ");
        eIndex = aInfo.indexOf("UNIT_NUM");
        sADDRESS = sADDRESS+" "+aInfo.substring(sIndex+9,eIndex-1);

        var sUNIT_NUM = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UNIT NUM:</b> &nbsp;";
        sIndex = aInfo.indexOf("UNIT_NUM: ");
        eIndex = aInfo.indexOf("PROP_CITY");
        sUNIT_NUM = sUNIT_NUM+" "+aInfo.substring(sIndex+10,eIndex-1);

        var sPROP_CITY = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROP CITY:</b> &nbsp;";
        sIndex = aInfo.indexOf("PROP_CITY: ");
        eIndex = aInfo.indexOf("PROP_ST");
        sPROP_CITY = sPROP_CITY+" "+aInfo.substring(sIndex+11,eIndex-1);

        var sPROP_ST = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROP STATE:</b> &nbsp;";
        sIndex = aInfo.indexOf("PROP_ST: ");
        eIndex = aInfo.indexOf("PROP_ZIP");
        sPROP_ST = sPROP_ST+" "+aInfo.substring(sIndex+9,eIndex-1);

        var sPROP_ZIP = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROP ZIP:</b> &nbsp;";
        sIndex = aInfo.indexOf("PROP_ZIP: ");
        eIndex = aInfo.indexOf("LANDUSE");
        sPROP_ZIP = sPROP_ZIP+" "+aInfo.substring(sIndex+10,eIndex-1);

        //for $x in doc("books.xml")/bookstore/book
        //where $x/price>30
        //var LUCData = $x/
        //var LUCData = doc(Land use codes.xml)/Worksheet/Row/Cell/Code Description[Code Value=117];
        
        var sLANDUSE = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LAND USE:</b> &nbsp;";
        sIndex = aInfo.indexOf("LANDUSE: ");
        eIndex = aInfo.indexOf("APN");
        sLANDUSE = sLANDUSE+" "+aInfo.substring(sIndex+9,eIndex-1);

        var sAPN = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ASSESSORS PARCEL NUMBER:</b> &nbsp;";
        sIndex = aInfo.indexOf("APN: ");
        eIndex = aInfo.indexOf("FIPS");
        sAPN = sAPN+" "+aInfo.substring(sIndex+5,eIndex-1);

        var sFIPS = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FIPS:</b> &nbsp;";
        sIndex = aInfo.indexOf("FIPS: ");
        eIndex = aInfo.indexOf("ELEVATION");
        sFIPS = sFIPS+" "+aInfo.substring(sIndex+6,eIndex-1);

        var sELEVATION = "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELEVATION:</b> &nbsp;";
        sIndex = aInfo.indexOf("ELEVATION: ");
        eIndex = aInfo.length-1;
        sELEVATION = sELEVATION+" "+aInfo.substring(sIndex+11,eIndex-1)+" ft.";

        document.getElementById("PanelCell").innerHTML = ParcelDemonstration+DiscoverPower+
                                                              ParcelDataAllows+ParcelDataAlso+
                                                              HorizontalRule+ParcelInformation+
                                                              sSRCDT+sRELDT+sADDRESS+sUNIT_NUM+
                                                              sPROP_CITY+sPROP_ST+sPROP_ZIP+
                                                              sLANDUSE+sAPN+sFIPS+sELEVATION;      
        
        //document.getElementById("tblBottomTable").style["top"] = "95%";
        document.getElementById("MyMapDIV").style["height"] = "73%";
       
      }        
      
    }
    catch ( ex )
    {
      alert ( ex.message );
    }      
  }
  
// layer events

  function OnParcelsClick( ctl )
  {  // swap wms url
    switchtiles = true;

    if ( document.getElementById('hidWMSURL').value == '0' )
    {
      document.getElementById('hidWMSURL').value = '1';
      document.getElementById("imgParcelsSelected").style["visibility"] = "visible"; 
    }
    else if ( document.getElementById('hidWMSURL').value == '1' )
    {
      document.getElementById('hidWMSURL').value = '0';
      document.getElementById("imgParcelsSelected").style["visibility"] = "hidden"; 
    }
    else if ( document.getElementById('hidWMSURL').value == '2' )
    {
      document.getElementById('hidWMSURL').value = '3';
      document.getElementById("imgParcelsSelected").style["visibility"] = "visible"; 
    }
    else if ( document.getElementById('hidWMSURL').value == '3' )
    {
      document.getElementById('hidWMSURL').value = '2';
      document.getElementById("imgParcelsSelected").style["visibility"] = "hidden"; 
    }
    
    document.getElementById('hidNewTile').value=document.getElementById('hidWMSURL').value;
    
    OnMapStyleChange ( );

    

  }
  
  function OnLabelsClick( ctl )
  {  // swap wms url
    switchtiles = true;
    
    if ( document.getElementById('hidWMSURL').value == '0' )
    {
      document.getElementById('hidWMSURL').value = '2';
      document.getElementById('imgLabelsSelected').style['visibility'] = 'visible';
    }
    else if ( document.getElementById('hidWMSURL').value == '1' )
    {
      document.getElementById('hidWMSURL').value = '3';
      document.getElementById('imgLabelsSelected').style['visibility'] = 'visible';
    }
    else if ( document.getElementById('hidWMSURL').value == '2' )
    {
      document.getElementById('hidWMSURL').value = '0';
      document.getElementById('imgLabelsSelected').style['visibility'] = 'hidden';
    }
    else if ( document.getElementById('hidWMSURL').value == '3' )
    {
      document.getElementById('hidWMSURL').value = '1';
      document.getElementById('imgLabelsSelected').style['visibility'] = 'hidden';
    }
  
    document.getElementById('hidNewTile').value=document.getElementById('hidWMSURL').value;
    
    OnMapStyleChange ( );
  }
  
  function OnPointsClick (ctl )
  {
    // not yet implemented
    
  }
  
  function OnPushpinsClick ( ctl )
  {
    if (pushpin == null)
    {
        SetPushpin();
        document.getElementById("imgPushpinsSelected").style["visibility"] = "visible"; 
    }
    else
    {
        RemovePushpins ( );
        document.getElementById("imgPushpinsSelected").style["visibility"] = "hidden"; 
    }
  }

  function OnShowInterpolatedClick ( ctl )
  {
    if (document.getElementById("imgShowInterpolatedLocationSelected").style["visibility"] == "hidden")
    {
        document.getElementById("imgShowInterpolatedLocationSelected").style["visibility"] = "visible";
        document.getElementById("imgGeocodingLabels").style["visibility"] = "visible";
        AddIntepolatedLatLon();
    }
    else
    {
        document.getElementById("imgShowInterpolatedLocationSelected").style["visibility"] = "hidden";
        document.getElementById("imgGeocodingLabels").style["visibility"] = "hidden";
        RemoveInterpolatedPushpins();
    }
  }

// MyMap events

  function OnMapResize ( )
  {  // resize MyMap div, recenter MyMap
    if ( document.FormMap.hidCommand.value != '0' )
    {
      return;
    }
            
    try
    {
      OldMapCenter = MyMap.GetCenter();

      var myWidth = 0, myHeight = 0;

      
      if( typeof( window.innerWidth ) == 'number' )
      {
        // Non-IE
        //myWidth = window.innerWidth;
        //myHeight = window.innerHeight;
        //myWidth = document.getElementById("MapCell").width;
        //myHeight = document.getElementById("MapCell").getAttribute("height");
      } 
      else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
      {
        // IE 6
        //myWidth = document.documentElement.clientWidth;
        //myHeight = document.documentElement.clientHeight;
        //myWidth = document.getElementById("MapCell").width;
        //myHeight = document.getElementById("MapCell").getAttribute("height");
      }
      else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
      {
        // IE 7
        //myWidth = document.body.clientWidth;
        //myHeight = document.body.clientHeight;
        //myWidth = document.getElementById("MapCell").width;
        //myHeight = document.getElementById("MapCell").getAttribute("height");
      }
      
      /*
      var mapStyle = document.getElementById("MyMapDIV").getAttribute("style");
      myWidth = mapStyle.width;
      myHeight = mapStyle.height;
      */
      
      //alert("Height,Width: "+myHeight+","+myWidth);
      //MyMap.Resize(myWidth, myHeight );
      //MyMap.PanToLatLong(OldMapCenter);
      
    }
    catch ( VEException )
    {
        //alert("Exception: "+VEException);
    }
  }
  
  function OnMapViewChange ( )
  {
    GetMapLocation ( );
    
    if ( document.FormMap.hidNewMap.value == '0' )  // not cooperating on new MyMap
    {
      SwitchTileLayers ( );  
    }      
    
    document.FormMap.hidNewMap.value = '0';
  }
  
  function OnMapClick ( mapEvent )
  {
    if ( mapEvent.shiftKey )  // ctrl doesn't work in Firefox
    {
//      var y = MyMap.GetTop ( );
//      var x = MyMap.GetLeft ( );

      var pixel = new VEPixel ( mapEvent.mapX, mapEvent.mapY );

      var pt = MyMap.PixelToLatLong ( pixel );

      DispatchInfo ( pt.Longitude, pt.Latitude );
    }
  }

  function OnMapStyleChange ( )
  {
    switchtiles = true;
    
    var mapstyle = MyMap.GetMapStyle();
    if ( MyMap.GetMapStyle() == VEMapStyle.Road )
    {
      if ( document.getElementById('hidWMSURL').value == '1' || document.getElementById('hidWMSURL').value == '2' )
      {
        styles = '&STYLES=style1';
      }
      else
      {
        styles = '&STYLES=style1,style1';
      }        
    }
    else
    {
      if ( document.getElementById('hidWMSURL').value == '1' || document.getElementById('hidWMSURL').value == '2' )
      {
        styles = '&STYLES=style2';
      }
      else
      {
        styles = '&STYLES=style2,style2';
      }        
    }
    
    SwitchTileLayers ( );  // not cooperating on new map
  }
 
  function AddMyLayer(type)
  {
      var l = new VEShapeLayer();
      var veLayerSpec = new VEShapeSourceSpecification(type, document.getElementById("txbMyLayerData").value, l);
      MyMap.ImportShapeLayerData(veLayerSpec, onFeedLoad);
  }

  function LoadLayerData(type)
  {
      var l = new VEShapeLayer();
      var veLayerSpec = new VEShapeSourceSpecification(type, document.getElementById("txbAddLayerFile").value, l);
      MyMap.ImportShapeLayerData(veLayerSpec, onFeedLoad);
    
  }
  
  function onFeedLoad(feed)
  {
    alert('Collection loaded. There are ' +feed.GetShapeCount() + ' items in this list.');
  }
  
  function LocationsClick()
  {
    var LocationButtonStyle = document.getElementById("btnLocations").getAttribute("style");
    
    if (LocationButtonStyle.color == "green")
    {
        document.getElementById("btnLocations").getAttribute("style").setAttribute("color","silver");
        document.getElementById("btnLocations").getAttribute("style").setAttribute("fontWeight","normal");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("color","green");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("fontWeight","bold");
        var IHTML = document.getElementById("txbAddressLatLonInput").getAttribute("value");
        var newIHTML = IHTML.replace(/Address, City, State ZIP/,"Latitude, Longitude");
        document.getElementById("txbAddressLatLonInput").setAttribute("value", newIHTML);
        document.FormMap.hidCommand.value = "1";
    }
    else
    {
        document.getElementById("btnLocations").getAttribute("style").setAttribute("color","green");
        document.getElementById("btnLocations").getAttribute("style").setAttribute("fontWeight","bold");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("color","silver");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("fontWeight","normal");
        var IHTML = document.getElementById("txbAddressLatLonInput").getAttribute("value");
        var newIHTML = IHTML.replace(/Latitude, Longitude/, "Address, City, State ZIP");
        document.getElementById("txbAddressLatLonInput").setAttribute("value", newIHTML);
        document.FormMap.hidCommand.value = "3";
    }
  }
  
  function LatLonClick()
  {
    var LatLonButtonStyle = document.getElementById("btnLatLon").getAttribute("style");
    
    if (LatLonButtonStyle.color == "silver")
    {
        document.getElementById("btnLocations").getAttribute("style").setAttribute("color","silver");
        document.getElementById("btnLocations").getAttribute("style").setAttribute("fontWeight","normal");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("color","green");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("fontWeight","bold");
        var IHTML = document.getElementById("txbAddressLatLonInput").getAttribute("value");
        var newIHTML = IHTML.replace(/Address, City, State ZIP/,"Latitude, Longitude");
        document.getElementById("txbAddressLatLonInput").setAttribute("value", newIHTML);
        document.FormMap.hidCommand.value = "1";
    }
    else
    {
        document.getElementById("btnLocations").getAttribute("style").setAttribute("color","green");
        document.getElementById("btnLocations").getAttribute("style").setAttribute("fontWeight","bold");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("color","silver");
        document.getElementById("btnLatLon").getAttribute("style").setAttribute("fontWeight","normal");
        var IHTML = document.getElementById("txbAddressLatLonInput").getAttribute("value");
        var newIHTML = IHTML.replace(/Latitude, Longitude/, "Address, City, State ZIP");
        document.getElementById("txbAddressLatLonInput").setAttribute("value", newIHTML);
        document.FormMap.hidCommand.value = "3";
    }
}
  
function setStyle(objId, style, value)
{
   document.getElementById(objId).style[style]= value;
}
 
function ChangeCursor()
{
   this.style.cursor = 'hand';
}

function ClickVerticalSamples()
{
    if (document.getElementById("imgInsurance").style["visibility"] == "hidden")
    {
       document.getElementById("imgInsurance").style["visibility"] = "visible"; 
       //document.getElementById("imgCommunications").style["visibility"] = "visible"; 
       //document.getElementById("imgFinancialServices").style["visibility"] = "visible"; 
       //document.getElementById("imgEnterpriseTax").style["visibility"] = "visible"; 
    }
    else
    {
       document.getElementById("imgInsurance").style["visibility"] = "hidden"; 
       //document.getElementById("imgCommunications").style["visibility"] = "hidden"; 
       //document.getElementById("imgFinancialServices").style["visibility"] = "hidden"; 
       //document.getElementById("imgEnterpriseTax").style["visibility"] = "hidden"; 
    }
}

function ShowTextPanel()
{
          if (document.FormMap.hidTextPanel.value == "Show")
          {
                    
            document.getElementById("MapControlTextBoxTable").style["top"] = "128px";
            document.getElementById("MyMapDIV").style["top"] = "130px";
            //document.getElementById("tblBottomTable").style["top"] = "91%";
            document.getElementById("MyMapDIV").style["width"] = "69%";
            document.getElementById("MyMapDIV").style["height"] = "69%";
            document.getElementById("PanelCell").style["width"] = "30%";
            document.getElementById("PanelCell").style["visibility"] = "visible";
            document.getElementById("PanelCell").style["height"] = "69%";
            document.getElementById("tblMapInfo").style["visibility"] = "visible";
            document.getElementById("tblMapInfo").style["height"] = "20px";
            document.getElementById("ibtnParcelsClick").style["visibility"] = "visible"; 
            document.getElementById("imgParcelsDivider").style["visibility"] = "visible";
            document.getElementById("imgParcelsSelected").style["visibility"] = "visible";       
            document.getElementById("ibtnLabelsClick").style["visibility"] = "visible"; 
            document.getElementById("imgLabelsDivider").style["visibility"] = "visible";
            document.getElementById("ibtnPushpinsClick").style["visibility"] = "visible"; 
            //document.getElementById("imgPushpinsDivider").style["visibility"] = "visible"; 
            document.getElementById("imgPushpinsSelected").style["visibility"] = "visible"; 
            
            /*
            if (document.FormMap.hidShowInterpolated.value == "true")
            {
                document.getElementById("ibtnShowInterpolatedLocation").style["visibility"] = "visible"; 
                document.getElementById("imgShowInterpolatedLocationSelected").style["visibility"] = "hidden"; 
            }
            else
            {
                document.getElementById("ibtnShowInterpolatedLocation").style["visibility"] = "hidden"; 
                document.getElementById("imgShowInterpolatedLocationSelected").style["visibility"] = "hidden"; 
            }
            */
            
            document.getElementById("PanelCell").innerHTML = ParcelDemonstration+DiscoverPower+
                                                              ParcelDataAllows+ParcelDataAlso+
                                                              HorizontalRule+ParcelInformation+
                                                              ShiftClick;      
           
          }
}

function AddIntepolatedLatLon()
{
    
    var latLon = new VELatLong(document.FormMap.hidCommandString3.value, document.FormMap.hidCommandString4.value);
    //alert("latLon.Longitude: "+latLon.Longitude);
    var dLon, dLat;
    dLon = Number(latLon.Longitude);
    dLat = Number(latLon.Latitude)
    dLon = dLon + 0.00020;
    dLat = dLat - 0.00012;
    //alert ("dLon: "+dLon);
    latLon.Longitude = dLon;
    latLon.Latitude = dLat;
    //alert("latLon.Longitude: "+latLon.Longitude);
    Gpushpin = new VEShape(VEShapeType.Pushpin, latLon);

    var custIcon = new VECustomIconSpecification();
    custIcon.Image = "BoxBlueLeft.png";
    custImageOffset = new VEPixel(45,-10);
    //custImageOffset.x = 50;
    //custImageOffset.y = 50;
    //alert("custImageOffset.x, custImageOffset.y: "+ custImageOffset.x +", "+ custImageOffset.y);
    custIcon.ImageOffset = custImageOffset;
    //var backgroundColor = new VEColor(255, 255, 255, 0);
    //custIcon.BackColor = backgroundColor;
    
    if (document.FormMap.hidLocationQuality.value == "Point")
    {
        Gpushpin.SetTitle("Point Location");
        custIcon.Image = "BoxGreenLeft.png";
        
        // add the interpolated pushpin
        latLon = new VELatLong(document.FormMap.hidInterpolatedLat.value, document.FormMap.hidInterpolatedLon.value);
        // move it down and to the right so that it points at the correct location
        dLon = Number(latLon.Longitude);
        dLat = Number(latLon.Latitude)
        dLon = dLon + 0.00020;
        dLat = dLat - 0.00012;
        latLon.Longitude = dLon;
        latLon.Latitude = dLat;
        Ipushpin = new VEShape(VEShapeType.Pushpin, latLon);
        Ipushpin.SetTitle("Interpolated Location");
        var IcustIcon = new VECustomIconSpecification();
        IcustIcon.Image = "BoxBlueLeft.png";
        Ipushpin.SetCustomIcon(IcustIcon);
        Ipushpin.SetDescription('<div style="width: 200px; background-color: white; color: DarkBlue font-size: 75% font-weight: bold">' + document.FormMap.hidCommandString1.value + ', ' + document.FormMap.hidCommandString2.value + '</div>');
        MyMap.AddShape(Ipushpin);
    }
    else if (document.FormMap.hidLocationQuality.value == "Address")
    {
        Gpushpin.SetTitle("Interpolated Address Location");
        custIcon.Image = "BoxBlueLeft.png";
    }
    else if (document.FormMap.hidLocationQuality.value == "Street")
    {
        Gpushpin.SetTitle("Street Cetroid Location");
        custIcon.Image = "BoxOrangeLeft.png";
    }
    else
    {
        Gpushpin.SetTitle("ZIP Centroid Location");
        custIcon.Image = "BoxYellowleft.png";
    }
    

    /*  tried to add text to the icon...
    var forgroundColor = new VEColor(0,50,240,1);
    Ipushpin.ForColor = forgroundColor;
    Ipushpin.TextBold = true;
    Ipushpin.TextSize = 12;
    Ipushpin.TextFont = "Arial"
    Ipushpin.TextContent = "Interpolated";
    */
    
    Gpushpin.SetCustomIcon(custIcon);
    Gpushpin.SetDescription('<div style="width: 200px; background-color: white; color: DarkBlue font-size: 75% font-weight: bold">' + document.FormMap.hidCommandString1.value + ', ' + document.FormMap.hidCommandString2.value + '</div>');
    MyMap.AddShape(Gpushpin);
}

function SetPushpin()
{
    var latLon = new VELatLong(document.FormMap.hidCommandString3.value, document.FormMap.hidCommandString4.value) ;
    pushpin = new VEShape(VEShapeType.Pushpin, latLon);

    var custIcon = new VECustomIconSpecification();
    pushpin.SetTitle("Geocoded Location");
    custIcon.Image = "RedPushpin.png";
    var backgroundColor = new VEColor(255, 255, 255, 0);
    custIcon.BackColor = backgroundColor;
    pushpin.SetCustomIcon(custIcon);
    pushpin.SetDescription('<div style="width: 200px; background-color: white; color: DarkBlue font-size: 75% font-weight: bold">' 
                           + document.FormMap.hidCommandString1.value + ', ' + document.FormMap.hidCommandString2.value + '</div>');
    MyMap.AddShape(pushpin);
}

function MySleep(u)
{
    var x = 0;
    var i = 0;
    for (i=0;i<=u;i++)
    {
        x = x+1;
    }
}

function AddFireData()
{
    /*var shapeLayer = new VEShapeLayer();
    var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,
                    "http://geotax.centrus.com/CA_BK57_BrushFire_region.kml", shapeLayer);
     shapeLayer.Show();
     MyMap.ImportShapeLayerData(shapeSpec, onFeedLoad,1);*/
     //,'_blank','resizable=yes, copyhistory=yes, width=820, height=620'
     window.open("WildfireImage.aspx","_blank", "resizable=yes, copyhistory=yes, width=875, height=600", false);
    
}
function AddParkData()
{
    var shapeLayer = new VEShapeLayer();
    var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,
                    "http://geotax.centrus.com/nationalparks.kml", shapeLayer);
    /*
    shapeLayer.Show();
     MyMap.ImportShapeLayerData(shapeSpec, onFeedLoad,1);
    */
}
function AddLimeData()
{
    var shapeLayer = new VEShapeLayer();
    var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,
               "http://geotax.centrus.com/Lme.kml", shapeLayer);
     /*
     shapeLayer.Show();
     MyMap.ImportShapeLayerData(shapeSpec, onFeedLoad,1);
    */
}
function AddTestData()
{
    var shapeLayer = new VEShapeLayer();
    var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,
               "http://geotax.centrus.com/park.kml", shapeLayer);
    /*
    shapeLayer.Show();
    MyMap.ImportShapeLayerData(shapeSpec, onFeedLoad,1);
    */
}
function onFeedLoad(feed)
{
    alert('Collection loaded. There are ' +feed.GetShapeCount() + ' items in this list.');
}

function OnEnterTrigger()
{
if (window.event && window.event.keyCode == 13)
{
    //alert("Enter Key is Pressed");
    //document.getElementById("SearchMagnifyingLogo").click();
    //alert("Enter Key is Pressed");
 }
}

function timedMsg()
{
    var msg = "window.status = 'Synchronizing for 3 seconds...';"
    var t=setTimeout("window.status = "+msg,3000);
    window.status = "Done Synchronizing.";
}

function SelectAll(element)
{
    element.focus();
    element.select();
}


