﻿ 
        function pageLoad(sender, args){
             //   
              if(!args.get_isPartialLoad())
              {

                LoadPage1 ();
                map.AttachEvent("onclick", onVEclick);

                if  (typeof (ShapeHandler) !== 'undefined')
                {
                    map.AttachEvent("onmouseover", ShapeHandler);
                    map.AttachEvent("onmouseout", ShapeHandler);
                }
              
               }  
              }
            //
        function GetSize()
        {
                var myWidth = 0, myHeight = 0;

                if( typeof( window.innerWidth ) == 'number' ) {
                    //Non-IE
                    myWidth = window.innerWidth;
                    myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                    //IE 6+ in 'standards compliant mode'
                    myWidth = document.documentElement.clientWidth;
                    myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                    //IE 4 compatible
                    myWidth = document.body.clientWidth;
                    myHeight = document.body.clientHeight;
                }

                if (myWidth > 0)
                {
                        var result = new Array();
                        result[0] = myWidth;
                        result[1] = myHeight;
                        return result;
                }
                else
                {
                        return null;
                }
        }

            //
         function onVEclick(e)
         {
         if (e.elementID != null)
           {
         
            var shape = map.GetShapeByID(e.elementID)
         
            map.SetMapView (shape.GetPoints());
            map.SetZoomLevel(15);
            //  get the value from the title
            
            myPostPack (shape.GetTitle ());
            
            // $get('<%= me.hdnKircheIDzurueck.ClientID %>').value = shape.GetTitle ();
            //__doPostBack('<%= me.btnUpdatePinSelected.ClientID %>', ''); 
              // get the id of the element
              // force the update panel to update
            }
          }        
        
  function PinsShowAll()
         {     
             var oLayerColl = null;
             var i_ende = 0;
             //
             oLayerColl = map.GetShapeLayerByIndex (1);
              if (oLayerColl != null) 
              { 
                i_ende = oLayerColl.GetShapeCount () - 1;
                //
                for (var i = 0; i <= i_ende; i++)
                {
                      var oPin = oLayerColl.GetShapeByIndex (i);
                     oPin.Show ();
                 }           
               }        
           }
        
          function menuShow(seacharg)
         {     
          //  ToggleLayer('NewLayer', false);
             //
             var oLayerColl = null;
             var i_ende = 0;
             //
             oLayerColl = map.GetShapeLayerByIndex (1);
              if (oLayerColl != null) 
              { 
                i_ende = oLayerColl.GetShapeCount () - 1;
                for (var i = 0; i <= i_ende; i++)
                {
                
                 var oPin = oLayerColl.GetShapeByIndex (i);
                    if (oPin.Title == seacharg)
                    {
                       var LA =  oPin.GetPoints ();
                       
                       map.SetMapStyle(VEMapStyle.Hybrid);
                       map.SetMapView (LA);
                       
                       var zoomLevel =15;
                 
                       if (typeof(m_ZoomLevelClick) == "number")
                         {zoomLevel =  m_ZoomLevelClick;}
                         
                        map.SetZoomLevel(zoomLevel);
                       //
                     oPin.Show ();
                    }
                    else 
                    {
                    oPin.Hide ();
                    }
                 } 
                 
                  myPostPack (seacharg);
               
               }           
                         
            //
               
          //   alert(bild);
          }
          
         function LoadPage1()
        {
                SetMapSize();
                window.onresize = SetMapSize;
                
                 var zoomLevel = 10;
                 
                if (typeof(m_ZoomLevel) == "boolean")
                  {zoomLevel =  m_ZoomLevel;}

 
                map = new VEMap('Map');
                map.LoadMap(LA_First, zoomLevel, VEMapStyle.Road);
                map.AttachEvent("oninitmode", MapModeChanged);
                map.SetMapStyle(VEMapStyle.Road);
                map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);

                if (isCrunchedLayer == true)
				{
		    		crunchedLayerManager = new VE.MapCruncher.CrunchedLayerManager(map);
		    		crunchedLayerManager.ImportLayersFromAnchorHRef("CrunchedLayers");
           
                     var permalinkProvided = crunchedLayerManager.ApplyPermalink(document.layerCheckboxForm);

                     if (!permalinkProvided) {
                       var layer = crunchedLayerManager.layerList.find('NewLayer');
                       layer.Activate(map);
                       layer.SetDefaultView(map);
                      }
                             
                       ToggleLayer ('NewLayer');
                               
                    document.getElementById('VE_MapCruncher_legend_box').style.display = "none";
                 }
             
               
                  AddMyLayer();   
                
          }
          
            function AddMyLayer()
         {
             
            if (cCollectionID != null)
             {
                    var Lay = new VEShapeLayer();
                    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.VECollection, cCollectionID, Lay);
                    map.ImportShapeLayerData(veLayerSpec, onFeedLoad);
             }
         }
         
         function onFeedLoad(feed)
         {
              document.getElementById('divMenue').style.display = ""
               document.getElementById('divLoadVE').style.display = "none";
          }
          
             function SetMapSize()
        {
                var browserSize = GetSize();

                var div = document.getElementById("Map");
            
                div.style.overflow = "hidden";
                div.style.position = "relative";

				if (crunchedLayerManager!=null)
				{
					crunchedLayerManager.controlManager.UpdateControlLayout();
				}
        }

     function clickButton (e)
        {
        
         var targ;
        try 
        {
            if (e == null)
                {
                var e=window.event;
                }
            if (e.target != null)
                {
                targ = e.target;
                }
            if (e.srcElement != null)
                {
                targ = e.srcElement;
                }
             if (targ.nodeType != null)
             {
                  if (targ.nodeType == 3)    // defeat Safari bug
                {
                    targ = targ.parentNode;
                } 
              }  
             }
             catch (ex)
             {  targ = "" }
            //
             var searchname = ""
             if (targ.value != null)
                {
                searchname = targ.value;
                }
             
        //    alert(searchname);
             menuShow (searchname)
           }
   
        
           function MapModeChanged(e)
        {
            /*    if (map.GetMapMode() == Msn.VE.MapActionMode.Mode3D &&
                    window.location.protocol == "file:")
                {
                        alert("MapCruncher tiles will only display in 3D mode " +
                        "if your map is hosted on a web server (using http://).\n" +
                        "Currently, your tiles are coming from a local machine (file://) " +
                        "so only 2D mode is available.");
                }   */
        }
     
      
     
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
