﻿//the map object
var map = null;

//load map    
function GetMap() {
    
    var _aid = "1";
    
    var mapArgs = null;
    
    var selStyle = VEMapStyle.Road;

    var selMode = VEMapMode.Mode2D;

    if(map != null)
    {
        map.Dispose();
    }
    
//    if ($get('PanelShowVMap'))
//    {
    
        if ($get('ctl00_MiddleContentHolder_activity_id'))               
          _aid = $get('ctl00_MiddleContentHolder_activity_id').value;
          
        if (_aid=="1")
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(-27.5, 137), 1, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else if (_aid=="7") // Golf courses
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(-4.0, -50.0), 2, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else if (_aid=="10") // Football
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(-27.5, 137), 1, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else if (_aid=="9") // Snow sports
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(-27.5, 137), 1, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else if (_aid=="8") // Coastal Courses
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(48.2, 16.4), 3, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else if (_aid=="11") // Walking/Climbing
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(54.5, -3), 5, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        else
            mapArgs = new Weather2.MapSearch.MapArgs("myMap", new VELatLong(-27.5, 137), 1, selStyle, false, selMode, VEDistanceUnit.Kilometers);
        
        
        map = new Weather2.MapSearch.Map(SoulSolutions.ClusterArticle.MapService, mapArgs);
     //}
     //else
       // map = null;
        
}  

//Clean up all objects
function ClearMap() {
    if (map!=null) {
        map.Dispose();
        map = null;
    }
}

function hideQuickSearchTownBox(e)
{

    var targ;
    
    if (!e)
    {
        e = window.event;
    }
    if (e.target)
      {
      targ = e.target;
      }
    else if (e.srcElement)
      {
      targ = e.srcElement;
      }
    if (targ.nodeType == 3) // defeat Safari bug
      {
      targ = targ.parentNode;
      }
      
    var tname;
    
    tname=targ.tagName;
    
    if (tname != 'TD')            
    {
        var id=document.getElementById('weatheractivity2_PanelQSTown');
    
        if (id!=null)
            id.style.display='none';
     }
}

//set page event handlers
if (window.attachEvent) {
	window.attachEvent("onload", GetMap);
	window.attachEvent("onunload", ClearMap);	
	document.attachEvent("onmouseup", hideQuickSearchTownBox); 
} else {
	window.addEventListener("DOMContentLoaded", GetMap, false);
	window.addEventListener("unload", ClearMap, false);
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


    var styleToSelect;
    
    function onOk() {
        $get('Paragraph1').className = styleToSelect;
    }
    
    function handleBroswerBackButton()
    {
        var str = window.location;
    }
    
    // Add click handlers for buttons to show and hide modal popup on pageLoad
    function pageLoad() {
                
        
        if ($get("butNo"))
            $addHandler($get("butNo"), 'click', hideModalRemoveForecastConfirmPopupViaClient);
            
        if ($get("lnkLogin"))
            $addHandler($get("lnkLogin"), 'click', showModalLoginPopupViaClient);
        
        if ($get("lnkSignUp"))                                            
            $addHandler($get("lnkSignUp"), 'click', showModalSignupPopupViaClient);
                
        if ($get("lnkEditDetails"))
            $addHandler($get("lnkEditDetails"), 'click', hideModalPaypalConfirmPopupViaClient); 
        
        if ($get("CancelButtonPaypalConfirm"))
            $addHandler($get("CancelButtonPaypalConfirm"), 'click', hideModalPaypalConfirmPopupViaClient);
    
        if ($find("cpeVirtualEarthMap"))    
            $find("cpeVirtualEarthMap").add_expandComplete( expandHandler );            
            
        //GetMap();
        
   }

    function expandHandler(sender, args)
    {
        var cpe = document.getElementById("LoadMapCounter");
        
        if (cpe!=null)
        {
            if (cpe.value == "0")
            {
                cpe.value = "1";
                
                //GetMap();                                
            }
        }
    }

function collapseHandler(sender, args)
{
    document.getElementById("tdMenu").style.width = "20px";
}

    
    function hideModalRemoveForecastConfirmPopupViaClient(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('programmaticModalRemoveForecastPopupBehavior');
        modalPopupBehavior.hide();
    }     
    
    
    function hideModalPaypalConfirmPopupViaClient(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('programmaticModalPaypalConfirmPopupBehavior');
        modalPopupBehavior.hide();
    }  
                
                
     function showModalVMapPopupViaClient(ev) {
        ev.preventDefault();        
                                   
        var modalPopupBehavior = $find('programmaticModalVMapBehavior');
        modalPopupBehavior.show();
        
        GetMap();                    
    }
                                
    function showModalLoginPopupViaClient(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('programmaticModalLoginPopupBehavior');
        modalPopupBehavior.show();
    }
    
    function hideModalLoginPopupViaClient(ev) {
        ev.preventDefault();        
        var modalPopupBehavior = $find('programmaticModalLoginPopupBehavior');
        modalPopupBehavior.hide();
    }
    
     function showModalSignupPopupViaClient(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('programmaticModalSignupPopupBehavior');
        modalPopupBehavior.show();
    }
    
    function hideModalSignupPopupViaClient(ev) {
        ev.preventDefault();        
        var modalPopupBehavior = $find('programmaticModalSignupPopupBehavior');
        modalPopupBehavior.hide();
    }

    


    function toggleMapDisplay(v)
    {
        var obj = document.getElementById(v);
         
        if (obj.style.display == 'none' || obj.style.display =='' )
            obj.style.display = 'block';
        else
           obj.style.display = 'none';
           
    }
   
