﻿var loadmap = true;
var map;
function loadMyMapBig(point,zoom) {    
    if (GBrowserIsCompatible()) {
       
        map = new GMap2(document.getElementById('map'));
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(point,zoom);
        map.clearOverlays();
                    
     }
     else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
     }
}

function loadMyMap(addlistener,point,zoom) {    
    if (GBrowserIsCompatible()) {
       
        map = new GMap2(document.getElementById('map'));
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(new GLatLng(49.145784,12.826538),zoom);
        map.clearOverlays();
       
        if (addlistener)
        {
            GEvent.addListener(map, "click", function(overlay, point) {
                if (!overlay) {
                
                map.clearOverlays();
                map.addOverlay(new GMarker(point));
                BindLatAndLng(point);}
           
         });
         }
//         else {LoadOverlayMarkers(map);}
         
         if (point != null){  
            map.addOverlay(new GMarker(point)); 
            map.setCenter(point,zoom);
            }
          map.setMapType(G_HYBRID_MAP);
     }
     else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
     }
}

     // of the "marker" and "html" variables which will be needed later when the event triggers.    
      function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
      
    function ShowOrHideMap(point,zoom)
    {
        if ($get('mapcontainer').style.display == "none") 
        {$get('mapcontainer').style.display = "block"; if(loadmap){loadMyMap(true,point,zoom);loadmap=false;}}
        else {$get('mapcontainer').style.display = "none";}
    }
    
    function centerInfoWindow(map,point,html)
    {
        map.setCenter(point,13);
        map.openInfoWindow(map.getCenter(), html);
    }

function ec20loadMyMap2(point,controlid) {    
    if (GBrowserIsCompatible()) {
       
        var repeatscontrol = $get('ec20resultRepeatEvents_'+controlid)
        var mapcontrol = $get('ec20map_'+controlid)
        var repeatslink = $get('ec20linkRepeatEvents_'+controlid)
        var maplink = $get('ec20linkMap_'+controlid)
        
        if (mapcontrol.style.display == "block") {
            mapcontrol.style.display = "none";
            maplink.innerHTML = "Karte anzeigen";
            return;
        }
        
        
        maplink.innerHTML = "Karte ausblenden";
        mapcontrol.style.display = "block";
        repeatscontrol.style.display = "none";
        if (repeatslink!=null)repeatslink.innerHTML = "Termine anzeigen";
         
        var map = new GMap2(mapcontrol);
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(point,14);
        
        map.addOverlay(new GMarker(point));
        map.setMapType(G_SATELLITE_MAP);
     }
     else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
     }
}

function loadMyMap3(mapcontrol,point) {    
    if (GBrowserIsCompatible()) {
       
        var map = new GMap2($get(mapcontrol));
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(point,14);
        
        map.addOverlay(new GMarker(point));
        map.setMapType(G_SATELLITE_MAP);
     }
     else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
     }
}

var ctlCities = null;
var ctlCounties = null;
function GetCitiesByCountyName(countyName, portalId, ctlCitiesId, ctlCountiesId)
{   
    ctlCities = $get(ctlCitiesId);
    ctlCounties = $get(ctlCountiesId);
    ctlCities.disabled = "disabled";
    ctlCounties.disabled = "disabled";
    ctlCities.options[0].innerHTML = "Wird geladen...";
   
    AjaxEventCoreService.GetCitiesByCountyName(countyName, portalId, OnGetOrteSucceeded);   
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function OnGetOrteSucceeded(result)
{
    ctlCities.disabled = false;
    ctlCounties.disabled = false;
    
    var list = ctlCities;
    list.options[0].innerHTML = "- Alle Orte -";
   
    // *** Clear the list first
    for (x=list.options.length-1; x > -1; x--) 
    {
        list.remove(1);
    }

    for (i=0;i<result.length;i++)
    {
        var option = document.createElement("option");
        option.text = result[i];
        option.value = result[i];
            
        if ( window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
            list.add(option);  
        else
            list.add(option, null); 
       
    }    
    
}

function ActivateUmkreis(list, control)
{
    var drop = $get(control);

    if (list == '-1' || list == '') drop.disabled = 'disabled'
    else drop.disabled = '' 
}


//function showCurrentLineTab(tabindex, controlid)
//{
//    $get('resultDisplay_'+controlid).style.display = "none"; 
//    $get('map_'+controlid).style.display = "none";
//    //$get('description_'+controlid).style.display = "none";
//    
//    //if (tabindex == 0) $get('description_'+controlid).style.display = "block";
//    if (tabindex == 1) $get('resultDisplay_'+controlid).style.display = "block";   
//    if (tabindex == 2) $get('map_'+controlid).style.display = "block";           
//}


function ec20getRepeatEvents(id,controlid)
{   
    var repeatscontrol = $get('ec20resultRepeatEvents_'+controlid)
    var mapcontrol = $get('ec20map_'+controlid)
    var repeatslink = $get('ec20linkRepeatEvents_'+controlid)
    var maplink = $get('ec20linkMap_'+controlid)
    
    if (repeatscontrol.style.display == "block") {
            repeatscontrol.style.display = "none";
            repeatslink.innerHTML = "Termine anzeigen"; 
            return;
        }
    if (maplink!=null) maplink.innerHTML = "Karte anzeigen";
    repeatslink.innerHTML = "Termine ausblenden";
    repeatscontrol.style.display = "block";
    mapcontrol.style.display = "none";
    AjaxEventCoreService.GetRepeatEvents(id, OnGetRepeatEventsSucceeded,FailedCallback,controlid);   
}

function OnGetRepeatEventsSucceeded(result,controlid)
{
    $get('ec20resultRepeatEvents_'+controlid).innerHTML = result;   
}



function ec20getGeoEvents(portalId, startDate, endDate, highlights,
    isTourism, categoryId, cityName, countyName, searchTerm)
{   
    AjaxEventCoreService.GetGeoEvents(portalId, startDate, endDate, highlights, isTourism, categoryId, cityName, countyName, searchTerm, OnGetGeoEventsSucceeded,FailedCallback);   
}

function OnGetGeoEventsSucceeded(result)
{
    for (i=0;i<result.length;i++) {
        var item = result[i];
        ec20_LoadOverlay(item[0], item[1], item[2]);
    }
    $get('mapresultcount').innerHTML = "<strong>" + result.length + " Veranstaltung/en geographisch erfasst.</strong>";
}



function FailedCallback(error)
{
    
}

function ec20_LoadOverlay(lat, lng, id) {   
    var point = new GLatLng(lat,lng);
    map.addOverlay(ec20_createMarker(point, id));
}

function ec20_createMarker(point,id) {
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    var marker = new GMarker(point, icon);    
    GEvent.addListener(marker, "click", function() { ec20_OpenInfo(marker, id);});
                        
    return marker;
}

function ec20_OpenInfo(marker, id)
{
    AjaxEventCoreService.GetInfoWindows(id, OnOpenInfoSucceeded, FailedCallback, marker);
}

function OnOpenInfoSucceeded(result,marker)
{
//    var point = marker.getPoint();
//    // The info window version with the "to here" form open
//    to_htmls = result + 'Route berechnen: <b>Hierher</b> - <a href="javascript:fromhere(' + i + ')">Von hier</a>' +
//       '<br>Startadresse:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
//       '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
//       '<INPUT value="Route berechnen" TYPE="SUBMIT">' +
//       '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
//              // "(" + name + ")" + 
//       '"/>';
//    // The info window version with the "to here" form open
//    from_htmls = result + 'Route berechnen: <a href="javascript:tohere(' + i + ')">Hierher</a> - <b>Von hier</b>' +
//       '<br>Zieladresse:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
//       '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
//       '<INPUT value="Route berechnen" TYPE="SUBMIT">' +
//       '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
//              // "(" + name + ")" + 
//       '"/>';
//    // The inactive version of the direction info
//    result = result + '<b>Route berechnen: </b><a href="javascript:tohere()">Hierher</a> - <a href="javascript:fromhere()">Von hier</a>'; 
    
    marker.openInfoWindowHtml(result);
      
}
// functions that open the directions forms
function tohere() {
    markerclicked.openInfoWindowHtml(to_htmls);
}
function fromhere() {
    markerclicked.openInfoWindowHtml(from_htmls);
}




