﻿// JScript File
    var htmls = [];          
    var to_htmls=[];
    var from_htmls=[];
    var prevDir;
     
     
var XmlHttpGoogleMap;    
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateGoogleMapXmlHttp()
{
    //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    //Creating object of XMLHTTP in IE
    try
    {
        XmlHttpGoogleMap = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            XmlHttpGoogleMap = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch(oc)
        {
            XmlHttpGoogleMap = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if(!XmlHttpGoogleMap && typeof XMLHttpRequest != "undefined") 
    {
        XmlHttpGoogleMap = new XMLHttpRequest();
    }
}
 
//declare variable to hold the global reference to the dropdown object 
//from where SHOW MAP link is clicked
//Assign it in OpenGoogleMap method


var _ddlReferenceObject = null;
var _globalpickdropFlag;

function OpenGoogleMap(_obj,fromDate,toDate,_pickdropFlag)
{ 
    _globalpickdropFlag=_pickdropFlag;

    //Assign dropdown Object
    _ddlReferenceObject = _obj;    
    
    var requestUrl = "";
    var _DdlObjectValue = "";    
    
    var _txtFromObjectValue = "";
    var _txtToObjectValue = "";
    
    //Get the dropdown value selected
    _DdlObjectValue = getObj(_obj).options[getObj(_obj).selectedIndex].text;
    
    _txtFromObjectValue = getObj('ctl00_cphContent_' + fromDate).value;
    _txtToObjectValue = getObj('ctl00_cphContent_' + toDate).value;        
     
     //Create URL to be requested with Querystring     
     //GoogleMap: it will identify on Ajax page that Query is for Google Map
     //Location: it is the location which will be shown by default highlighted     
     requestUrl = RelativePathGMP() + "Ajax.aspx?GoogleMap=1&Location=" + encodeURIComponent(_DdlObjectValue) + "&FromDate=" + encodeURIComponent(_txtFromObjectValue) + "&ToDate=" + encodeURIComponent(_txtToObjectValue) + "&PickDropFlag= " + encodeURIComponent(_pickdropFlag) + "&" + Math.random();
     //Create XMLHttp Object
     CreateGoogleMapXmlHttp();
  
     // If browser supports XMLHTTPRequest object
    if(XmlHttpGoogleMap)
    {   
        XmlHttpGoogleMap.onreadystatechange = HandleResponseGoogleMap;
        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttpGoogleMap.open("GET", requestUrl,  true);

        //Sends the request to server
        XmlHttpGoogleMap.send(null);
    }       
}

//When User clicks "Select This Hotel" in google map info popup
//Following function assigns that value in the respective dropdown
function setSelectThisHotel(_value,_pickdropFlagValue)
{ 
    //Get the global reference of dropdown
    
    var _ddl = getObj(_ddlReferenceObject);
    var _ddlPickLocation = getObj('ddlPickLocation');
    var _ddlDropOffLocation = getObj('ddlDropOffLocation');
    var _ddlReturnPickLocation = getObj('dlReturnPickLocation');
    var _ddlReturnDropOffLocation = getObj('ddlReturnDropOffLocation');
    
    //Search for the value in the pickup/dropoff dropdown  
//    for(var i=0; i<_ddl.length;i++)
//    { 
//        //If it matches
//       if(_value == _ddl.options[i].value)
//       { 
//            //Assign it
//            _ddl.options[i].selected = true;
//            break;
//       } 
//    }    
if (_pickdropFlagValue==1 || _pickdropFlagValue==3)
   {
        if(_ddlPickLocation!=null)
        { 
            for(var i=0; i<_ddlPickLocation.length;i++)
            { 
                //If it matches
               if(_value == _ddlPickLocation.options[i].value)
               { 
                    //Assign it
                    _ddlPickLocation.options[i].selected = true;
                    break;
               } 
            } 
        }
    }
    
    
    if (_pickdropFlagValue==2 || _pickdropFlagValue==4)
    {
    
            if(_ddlDropOffLocation!=null)
            { 
                 for(var i=0; i<_ddlDropOffLocation.length;i++)
                { 
                    //If it matches
                   if(_value == _ddlDropOffLocation.options[i].value)
                   { 
                        //Assign it
                        _ddlDropOffLocation.options[i].selected = true;
                        break;
                   } 
                } 
            }
     }
     
     
     if (_pickdropFlagValue==1 || _pickdropFlagValue==3)
     {
     
            if(_ddlReturnPickLocation!=null)
            { 
              for(var i=0; i<_ddlReturnPickLocation.length;i++)
                { 
                    //If it matches
                   if(_value == _ddlReturnPickLocation.options[i].value)
                   { 
                        //Assign it
                        _ddlReturnPickLocation.options[i].selected = true;
                        break;
                   } 
                } 
             }
             
      }
             
             
      if (_pickdropFlagValue==2 || _pickdropFlagValue==4)
      {            
             
            if(_ddlReturnDropOffLocation!=null)
            { 
                 for(var i=0; i<_ddlReturnDropOffLocation.length;i++)
                { 
                    //If it matches
                   if(_value == _ddlReturnDropOffLocation.options[i].value)
                   { 
                        //Assign it
                        _ddlReturnDropOffLocation.options[i].selected = true;
                        break;
                   } 
                } 
            }
            
       }    //Close the Google Map Popup 
    CloseGMAPPopUp();
 }  

//To hide the google map popup
function CloseGMAPPopUp()
{
    //Get the object div where google map is shown
    var shadow = document.getElementById('dvGmapFrame'); // iframe div
    var question = document.getElementById('dvGmapMain'); // Google map & list div

    //Hide both div
    shadow.style.display = 'none'; 
    question.style.display = 'none';

}
function CloseGMAPDir()
{
  

    //Hide both div
    document.getElementById('dvGmapDirection').style.display = 'none'; 
   

}

//To get the relative path as per local, live , test site etc
function RelativePathGMP()
{
    var url = self.location.href;
    url = url.toLowerCase();
    var path = '';
    
    // determine the server   
//    var local = '/localhost/';
//    var server = 'server/';
//    var live  = 'perimeter-com.sitepreview.ca/';
    var live1='http://perimeterbus.com/'
    
//    if(url.lastIndexOf(local) > 1)
//        path = "http://localhost/perimeterbusphase2/";
//    else if(url.lastIndexOf(server) > 1)
//        path = "http://server/perimeterbusphase2/";
//    else if(url.lastIndexOf(live) > 1)
//        path = "http://perimeter-com.sitepreview.ca/";
    if(url.lastIndexOf(live1) > 1)
        path = "http://perimeterbus.com/";

    return path;
}

//Called when response comes back from server
function HandleResponseGoogleMap()
{  
    // To make sure receiving response data from server is completed	
    if(XmlHttpGoogleMap.readyState == 4)
    {	 // To make sure valid response is received from the server, 200 means response received is OK
        if(XmlHttpGoogleMap.status == 200)
        {		
            //To mark all points in googlemap and fill the hotel list
            fillGoogleMapList(XmlHttpGoogleMap.responseXML.documentElement); 
        }
        else
        {
            alert("There was a problem retrieving data from the server." );
        }
    }
}

function GetInnerText (node)
{
    if(node!=null)
        return (node.textContent || node.innerText || node.text) ;
    else
        return "";
}

function SetInnerText (node,val)
{
    if(node.textContent) 
        node.textContent=val; 
    else if(node.innerText)
        node.innerText=val;
    else if(node.text)
        node.text=val;
} 

var map = null;
var mapDir = null;
var _tbl = null;
function fillGoogleMapList(responseData)
{   
    var _tblMain = responseData.getElementsByTagName('Table')[0];
    ShowDefaultPinPopUp(_tblMain);
      
    _tbl = responseData.getElementsByTagName('Table1'); 
    ShowAllPinUpLocatins(_tbl);
    
    
    
    
}

//To show default PinUp Popup
function ShowDefaultPinPopUp(_tblMain)
{
    var _latCenterPoint = GetInnerText(_tblMain.getElementsByTagName('GMP_Latitude')[0]);
    var _longCenterPoint = GetInnerText(_tblMain.getElementsByTagName('GMP_Longitude')[0]);
    var _PontId=GetInnerText(_tblMain.getElementsByTagName('GMP_Id')[0]);
    var _htmlCenterPoint = '';
   
    var _tblImage = ''
    
    if(_tblMain.getElementsByTagName('GMP_Images')[0]!=null)
    {
        _tblImage = '<table cellpadding=0 cellspacing=0 border=0>';
        _tblImage += '<tr><td colspan=2 align=left><img src=Images/GMapImages/' + GetInnerText(_tblMain.getElementsByTagName('GMP_Images')[0]) + ' border=0></td></tr>';
        _tblImage += '</table>';
    }
    
    var _html = '';
    
    _html = '<table cellpadding=0 cellspacing=0 border=0 align=left>';   
    _html += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tblMain.getElementsByTagName('GMP_StreetAddress')[0]) + '</td></tr>';
    _html += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tblMain.getElementsByTagName('GMP_MapCity')[0]) + '';
    _html += ',&nbsp;'+ GetInnerText(_tblMain.getElementsByTagName('GMP_State')[0]);
    
    if(_tblMain.getElementsByTagName('GMP_ZipCode')[0]!=null)
        _html += '&nbsp;&nbsp;'+ GetInnerText(_tblMain.getElementsByTagName('GMP_ZipCode')[0]);
        
    //_html += ','+ GetInnerText(_tblMain.getElementsByTagName('GMP_Country')[0]) + '</td></tr>';    
         
     if(_tblMain.getElementsByTagName('GMP_Phone')[0]!=null)
        _html += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tblMain.getElementsByTagName('GMP_Phone')[0]) + '</td></tr>'; 
        
        
     if(_tblMain.getElementsByTagName('GMP_bubblepopupMsg1')[0]!=null)
        _html += '<tr><td height=10px></td></tr><tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tblMain.getElementsByTagName('GMP_bubblepopupMsg1')[0]) + '</td></tr>'; 
          
          
          
     
        
        
//     if(_tblMain.getElementsByTagName('GMP_Url')[0]!=null)       
//        _html += '<tr><td colspan=2 align=left class=GmapAddress><a href='+ GetInnerText(_tblMain.getElementsByTagName('GMP_Url')[0]) + '>' +  GetInnerText(_tblMain.getElementsByTagName('GMP_UrlText')[0]) + '</a></td></tr>'; 
//    
    //_html += '<tr><td ></td></tr><tr><td colspan=2 align=left class=GmapLink style="cursor:pointer;" onclick=javascript:setSelectThisHotel("' + GetInnerText(_tblMain.getElementsByTagName('GMP_IDFromLocation')[0]) + '");>I want to be picked up/dropped off here</td></tr>';
     
    _html += '</table>';  
    
    
    
    var _htmlItalic = '';
    
    if(_tblMain.getElementsByTagName('GMP_bubblepopupMsg2')[0]!=null)
        _htmlItalic= '<tr><td colspan=2 align=left class=GmapAddress style=font-style:italic >'+ GetInnerText(_tblMain.getElementsByTagName('GMP_bubblepopupMsg2')[0]) + '</td></tr>'; 
               
    
        var _pickdropMessage;
         
             
    if(_globalpickdropFlag==1 || _globalpickdropFlag==3)
    {
       _pickdropMessage="I want to be picked up here";   
       
    }
    else if(_globalpickdropFlag==2 || _globalpickdropFlag==4)
    {
       _pickdropMessage="I want to be dropped off here";       
       
    }
    
    
    
    
    
    _htmlCenterPoint = '<table cellpadding=0 cellspacing=0 height=130px width=330px border=0><tr><td colspan=2 align=left class=GmapHeading>'+ GetInnerText(_tblMain.getElementsByTagName('GMP_Title')[0]) + '</td></tr> ' +  _htmlItalic  + '      <tr><td height=10px></td></tr><tr><td valign=top>' +  _html  + '</td><td valign=top>' + _tblImage + '</td></tr><tr><td height=10px></td></tr><tr><td ></td></tr><tr><td colspan=2 align=center class=GmapLink style="cursor:pointer;" onclick=javascript:setSelectThisHotel("' + GetInnerText(_tblMain.getElementsByTagName('GMP_IDFromLocation')[0]) + '","' + _globalpickdropFlag + '");>'+ _pickdropMessage +'</td></tr></table>';
 
    //Initialize Google Map
    
     // _htmlCenterPoint=newHtml(_PontId,_latCenterPoint,_longCenterPoint,_htmlCenterPoint);
       
    initializeGoogleMap(_latCenterPoint,_longCenterPoint,_htmlCenterPoint);
   
}

//To Show all pinup locations
function ShowAllPinUpLocatins(_tbl)
{
    var _listHTML = '';        
    _listHTML =  '<table cellpadding=4 cellspacing=4 border=0 align=left>';
        
    for(var i=0; i<_tbl.length;i++)
    {
        var _latPoint = GetInnerText(_tbl[i].getElementsByTagName('GMP_Latitude')[0])
        var _longPoint =  GetInnerText(_tbl[i].getElementsByTagName('GMP_Longitude')[0]);
        var _PointId=GetInnerText(_tbl[i].getElementsByTagName('GMP_Id')[0]);
        var myPoint = new GLatLng(_latPoint, _longPoint);            
        myIcon_google = null;   
        
        var _htmlPoint = '';
        var _toolTip = GetInnerText(_tbl[i].getElementsByTagName('GMP_Title')[0]);
       
         
        var _tblImageAll = ''
    
        if(_tbl[i].getElementsByTagName('GMP_Images')[0]!=null)
        {
            _tblImageAll = '<table cellpadding=0 cellspacing=0 border=0>';
            _tblImageAll += '<tr><td colspan=2 align=left><img src=Images/GMapImages/' + GetInnerText(_tbl[i].getElementsByTagName('GMP_Images')[0]) + '  ></td></tr>';
            _tblImageAll += '</table>';
        }
    
        _htmlPoint = '<table cellpadding=0 cellspacing=0 border=0 align=left>';
        _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_StreetAddress')[0]) + '</td></tr>';
        _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_MapCity')[0]) + '';
        _htmlPoint += ',&nbsp;'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_State')[0]);
        
        if(_tbl[i].getElementsByTagName('GMP_ZipCode')[0]!=null)
            _htmlPoint += '&nbsp;&nbsp;'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_ZipCode')[0]);
            
          if(_tbl[i].getElementsByTagName('GMP_Phone')[0]!=null)
           _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_Phone')[0]) + '</td></tr>'; 

          if(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg1')[0]!=null)
          _htmlPoint += '<tr><td height=10px></td></tr><tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg1')[0]) + '</td></tr>'; 
     
          
              
         _htmlPoint += '</table>';
         
         
         
         
         var _htmlItalic = '';
    
        if(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg2')[0]!=null)
        _htmlItalic= '<tr><td colspan=2 align=left class=GmapAddress style=font-style:italic >'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg2')[0]) + '</td></tr>'; 
    
         
         
         var _pickdropMessage;
         
         var _pickdroplocationHeadingHtml;
    
    if(_globalpickdropFlag==1 || _globalpickdropFlag==3)
    {
       _pickdropMessage="I want to be picked up here";
       
       _pickdroplocationHeadingHtml="Pick Up Locations";
    }
    else if(_globalpickdropFlag==2 || _globalpickdropFlag==4)
    {
       _pickdropMessage="I want to be dropped off here";
       
       _pickdroplocationHeadingHtml="Drop Off Locations";
    }        
         
        
        _htmlPoint = '<table cellpadding=0 cellspacing=0 border=0 height=130px width=330px><tr><td colspan=2 align=left  class=GmapHeading>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_Title')[0]) + '</td></tr>' +  _htmlItalic  + ' <tr><td height=10px></td></tr><tr><td valign=top>' + _htmlPoint +  '</td><td valign=top>' + _tblImageAll + '</td></tr><tr><td height=10px></td></tr><tr><td colspan=2 align=center class=GmapLink style="cursor:pointer;" onclick=javascript:setSelectThisHotel("' + GetInnerText(_tbl[i].getElementsByTagName('GMP_IDFromLocation')[0]) + '","' + _globalpickdropFlag + '");>'+ _pickdropMessage +'</td></tr></table>';
    
        // _htmlPoint=newHtml(_PointId,_latPoint,_longPoint,_htmlPoint);
        var marker = CreateMarker(myPoint,myIcon_google,_htmlPoint,false,_toolTip);
        marker.value = GetInnerText(_tbl[i].getElementsByTagName('GMP_Id')[0]);
        //markers.pushValue(marker);
        map.addOverlay(marker);  
        //Create List
        
        
        
        
         
        _listHTML += '<tr><td class=GmapAddress style="cursor:pointer;" onclick=javascript:ShowCallout("' + GetInnerText(_tbl[i].getElementsByTagName('GMP_Id')[0]) + '");>' + GetInnerText(_tbl[i].getElementsByTagName('GMP_Title')[0]) + '</td></tr>';
          
    } 
    _listHTML += '</table>'; 
    
    
    
     document.getElementById("dvGmapListHeading").innerHTML = _pickdroplocationHeadingHtml;   
    
    
    document.getElementById("dvGmapList").innerHTML = _listHTML; 
}

function initializeGoogleMap(_latCenter,_longCenter,_htmlCenter)
{
    if (GBrowserIsCompatible())
    {
        document.getElementById("map").style.display = 'block';  
        document.getElementById("dvGmapList").style.display = 'block'; 
        
        document.getElementById("dvGmapListHeading").style.display = 'block'; 
        
        //Show iframe and Main Map Div
        showLayer();
        
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(_latCenter,_longCenter), 13); 
        map.openInfoWindowHtml(new GLatLng(_latCenter,_longCenter),_htmlCenter); 
        
        document.getElementById("mapDir").style.display = 'block';  
        mapDir = new GMap2(document.getElementById("mapDir"));
         mapDir.addControl(new GLargeMapControl());
        mapDir.addControl(new GMapTypeControl());
        mapDir.setCenter(new GLatLng(_latCenter,_longCenter), 13); 
        mapDir.openInfoWindowHtml(new GLatLng(_latCenter,_longCenter),_htmlCenter); 
    }
}

function ShowCallout(_value)
{
    for(var i=0; i<_tbl.length;i++)
    {
        if(GetInnerText(_tbl[i].getElementsByTagName('GMP_Id')[0]) == _value)
        {
            var _latPoint = GetInnerText(_tbl[i].getElementsByTagName('GMP_Latitude')[0])
            var _longPoint =  GetInnerText(_tbl[i].getElementsByTagName('GMP_Longitude')[0]);
        
        
            var _htmlPoint = '';
            var _toolTip = GetInnerText(_tbl[i].getElementsByTagName('GMP_Title')[0]);
       
         
            var _tblImageAll = ''
        
            if(_tbl[i].getElementsByTagName('GMP_Images')[0]!=null)
            {
                _tblImageAll = '<table cellpadding=0 cellspacing=0 border=0>';
                _tblImageAll += '<tr><td colspan=2 align=left><img src=Images/GMapImages/' + GetInnerText(_tbl[i].getElementsByTagName('GMP_Images')[0]) + ' ></td></tr>';
                _tblImageAll += '</table>';
            }
        
            _htmlPoint = '<table cellpadding=0 cellspacing=0 border=0 align=left>';
            _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_StreetAddress')[0]) + '</td></tr>';
            _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_MapCity')[0]) + '';
            _htmlPoint += ',&nbsp;'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_State')[0]);
            
            if(_tbl[i].getElementsByTagName('GMP_ZipCode')[0]!=null)
                _htmlPoint += '&nbsp;&nbsp;'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_ZipCode')[0]);
                
              
            if(_tbl[i].getElementsByTagName('GMP_Phone')[0]!=null)
                _htmlPoint += '<tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_Phone')[0]) + '</td></tr>'; 

             
            if(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg1')[0]!=null)
          _htmlPoint += '<tr><td height=10px></td></tr><tr><td colspan=2 align=left class=GmapAddress>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg1')[0]) + '</td></tr>'; 
      
             
             
             
             _htmlPoint += '</table>';
             
             
             
             var _htmlItalic = '';
    
        if(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg2')[0]!=null)
        _htmlItalic= '<tr><td colspan=2 align=left class=GmapAddress style=font-style:italic >'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_bubblepopupMsg2')[0]) + '</td></tr>'; 
    
            
            
    var _pickdropMessage;
    
    if(_globalpickdropFlag==1 || _globalpickdropFlag==3)
    {
       _pickdropMessage="I want to be picked up here";
    }
    else if(_globalpickdropFlag==2 || _globalpickdropFlag==4)
    {
       _pickdropMessage="I want to be dropped off here";
    }
            
            
            _htmlPoint = '<table cellpadding=0 cellspacing=0 border=0 height=130px width=330px><tr><td colspan=2 align=left  class=GmapHeading>'+ GetInnerText(_tbl[i].getElementsByTagName('GMP_Title')[0]) + '</td></tr>' +  _htmlItalic  + '<tr><td height=10px></td></tr><tr><td valign=top>' + _htmlPoint +  '</td><td valign=top>' + _tblImageAll + '</td></tr><tr><td height=10px></td></tr><tr><td colspan=2 align=center class=GmapLink style="cursor:pointer;" onclick=javascript:setSelectThisHotel("' + GetInnerText(_tbl[i].getElementsByTagName('GMP_IDFromLocation')[0]) + '","' + _globalpickdropFlag + '");>'+ _pickdropMessage +'</td></tr></table>';
   
             //_htmlPoint=newHtml(_value,_latPoint,_longPoint,_htmlPoint);     
            map.openInfoWindowHtml(new GLatLng(_latPoint,_longPoint),_htmlPoint); 
            mapDir.openInfoWindowHtml(new GLatLng(_latPoint,_longPoint),_htmlPoint); 
        } 
    }
}
 
function CreateMarker(point,icon1,InfoHTML,bDraggable,sTitle)
{
    var marker;
    marker = new GMarker(point,{icon:icon1,draggable:bDraggable,title: sTitle});
    if(InfoHTML!='')
    {
        GEvent.addListener(marker, "click", function() {map.enableInfoWindow(); map.openInfoWindowHtml(point,InfoHTML); });
        //GEvent.addListener(marker, "dragend", function() {  GService.SetLatLon(this.value,this.getLatLng().y,this.getLatLng().x);RaiseEvent('PushpinMoved',this.value);  });
    // GEvent.addListener(marker, "click", function() {mapDir.enableInfoWindow(); mapDir.openInfoWindowHtml(point,InfoHTML); });
     
    }
    return marker;
}

//Window Set Up
function getBrowserHeight() {
var intH = 0;
var intW = 0;

if(typeof window.innerWidth  == 'number' ) {
   intH = window.innerHeight;
   intW = window.innerWidth;
} 
else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    intH = document.documentElement.clientHeight;
    intW = document.documentElement.clientWidth;
}
else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    intH = document.body.clientHeight;
    intW = document.body.clientWidth;
}

return { width: parseInt(intW), height: parseInt(intH) };
}  

function setLayerPosition() {
var shadow = document.getElementById('dvGmapFrame');
var question = document.getElementById('dvGmapMain');

var bws = getBrowserHeight();
if(shadow!=null)
{
shadow.style.width = bws.width + 'px';
shadow.style.height = document.body.scrollHeight + 'px';
}
var GMAP_browser =window.navigator.userAgent; 
GMAP_browser = GMAP_browser.toLowerCase(); 

 question.style.left =  (parseInt(bws.width/2)- parseInt(question.style.width)/2)-15+'px';
 question.style.top =document.documentElement.scrollTop+'px';
  document.getElementById('dvGmapDirection').style.top =document.documentElement.scrollTop+'px';
   document.getElementById('dvGmapDirection').style.left =(parseInt(bws.width/2)- parseInt(question.style.width)/2)-20+'px';
if (GMAP_browser.indexOf("ie") <= -1)  // Mozilla 
{
    question.style.left =  (parseInt(bws.width/2)- parseInt(question.style.width)/2)-22+'px';
}


shadow = null;
question = null;
}

function showLayer() {
setLayerPosition();

var shadow = document.getElementById('dvGmapFrame');
var question = document.getElementById('dvGmapMain');

shadow.style.display = 'block'; 
question.style.display = 'block';

shadow = null;
question = null;             
}

function hideLayer() {
var shadow = document.getElementById('dvGmapFrame');
var question = document.getElementById('dvGmapMain');

shadow.style.display = 'none'; 
question.style.display = 'none';

shadow = null;
question = null; 
}
function newHtml(id,lat,lon,htm)
{
    to_htmls[id] = htm + '<div class=GmapAddress>Get Directions: <b>To here<\/b> - <a href="javascript:fromhere('+lat + ',' + lon+','+id+')">From here<\/a>' +
    '<br>Start address:<form method=post action=GoogleMapDirection.aspx?latitude='+lat+'&longitude='+lon+'&locationId='+id+'&_ddlReferenceObject='+_ddlReferenceObject+' target=_blank>' +
    '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
    '<INPUT value="Get Directions" TYPE="SUBMIT" id="toSubmit"><br>' +
    '<input type="hidden" id="daddr" value="'+ lat+ ',' + lon +'"/></div>';

    from_htmls[id] = htm + '<div  class=GmapAddress>Get Directions: <a href="javascript:tohere('+lat + ',' + lon+','+id+')">To here<\/a> - <b>From here<\/b>' +
    '<br>End address:<form method=post action=GoogleMapDirection.aspx?latitude='+lat+'&longitude='+lon+'&locationId='+id+'&_ddlReferenceObject='+_ddlReferenceObject+' target=_blank>' +
    '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
    '<INPUT value="Get Directions" TYPE="SUBMIT" id="frmSubmit"><br>' +
    '<input type="hidden" id="saddr" value="'+ lat + ',' + lon +
    '"/></div>';

    htm = htm + '<div class=GmapAddress>Get Directions: <a href="javascript:tohere('+lat + ',' + lon+','+id+')">To here</a> - <a href="javascript:fromhere('+lat + ',' + lon+','+id+')">From here</a></div>';
    return htm;
} 

function setCen(latval,lonval)
{   
    var myPoint = new GLatLng(latval, lonval);
    mapDir.setCenter(myPoint,11);
}
function getDirections() 
{
    isDragZoom=0;
    if(prevDir)
    {
     prevDir.clear();
    }
document.getElementById("dvGmapDirection").style.display='block';
    var gdir=new GDirections(mapDir,document.getElementById("divDir"));

    var saddr = document.getElementById("saddr").value;
    var daddr = document.getElementById("daddr").value;                      
     
    gdir.load("from: "+saddr+" to: "+daddr);
    prevDir=gdir;

    var reasons=[];
    reasons[G_GEO_SUCCESS]            = "Success";
    reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
    reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
    reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
    reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
    reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
    reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
    reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
    reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
    reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

    GEvent.addListener(gdir, "error", function() {
    var code = gdir.getStatus().code;
    var reason="Code "+code;
    if (reasons[code]) {
      reason = reasons[code]
    } 
    isDragZoom=1;
    alert("Failed to obtain directions, "+reason);
    });     
}

function tohere(lat,lon,id) {
    //document.getElementById('SubmitButtonID').value='toSubmit';         
    var point = new GLatLng(lat, lon);            
    map.openInfoWindowHtml(point,to_htmls[id]);
    }
function fromhere(lat,lon,id) {
    // document.getElementById('SubmitButtonID').value='frmSubmit';
    var point = new GLatLng(lat, lon);
    map.openInfoWindowHtml(point,from_htmls[id]);
    }


 
window.onresize = setLayerPosition;   

 