﻿/// <reference path="intellisense/jquery-1.3.2-vsdoc2.js" />

var latitude;
var longitude;
var info;

function loadmaps(lat_value, long_value, infotext)
{
    latitude = lat_value;
    longitude = long_value;
    info = infotext
    google.load("maps", "2",{"other_params":"sensor=false"});
    google.setOnLoadCallback(initialize);
}

function initialize() {
    var map = new google.maps.Map2(document.getElementById("map_canvas"));
    var point = new GLatLng(latitude, longitude);
    map.setCenter(point, 14);
    map.setUIToDefault();
    map.setMapType(G_NORMAL_MAP);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(info + "<p>From<input type='text' id='txtfrom' class='from'/><button type='button' class='ui-state-default ui-corner-all' onclick='getdir()'>Get Directions</button></p>")
        });
    $('#map_directions').hide();
   
}

function getdir()
{
    var from = $('#txtfrom').val();
    if (from != "")
    {
        var map = new google.maps.Map2(document.getElementById("map_canvas"));
        var directionsPanel = document.getElementById("map_directions");
        var directions = new GDirections(map, directionsPanel);
        directions.load("from: " + from + " to: " + latitude + "," + longitude,{locale:"en_UK"}); 
        //var code = route.getStatus();
        //if(code == G_GEO_SUCCESS)
        //{
          
            $('#map_directions').show();
        //}
        //else alert ('Address not found.');
    }
    else{
        alert("Please enter the place you're travelling from");
    }
}

