﻿// JScript File

var AccessibleshapeLayer;
var AdvisoryshapeLayer;
var sponsorshapeLayer;
var BNlocations;


function loadCommentMarkers()
{
map.SetZoomLevel(11)
var commentOLat
var commentOLon
var commentDLat
var commentDLon
commentOLat = commentOrigin.split(",")[0]
commentOLon = commentOrigin.split(",")[1]
commentDLat = commentDestination.split(",")[0]
commentDLon = commentDestination.split(",")[1]

var commentCenterLat
commentCenterLat = ((commentOLat*1) + (commentDLat*1))/2

var commentCenterLon
commentCenterLon = ((commentOLon*1) + (commentDLon*1))/2

map.SetCenter(new VELatLong(commentCenterLat,commentCenterLon));
makeNewMarker(commentOLat + "," + commentOLon + ";" + "Origin" + ";" + "" + ";" + "", "customMarker")
makeNewMarker(commentDLat + "," + commentDLon + ";" + "Destination" + ";" + "" + ";" + "", "customMarker")
}

function CheckSubwayMode(e)
{
document.forms["tripPlanner2"].elements["lineStart"].selectedIndex = 0
document.forms["tripPlanner2"].elements["lineEnd"].selectedIndex = 0
if(e.checked)
{
document.getElementById("RoutePref").style.visibility = "visible"
}
else
{
document.getElementById("RoutePref").style.visibility = "hidden"
}
}



function subRoutesOnNewLogIn()
{
   if(savedSubRoutesOnLoad == "yes")
    {
      showHideSubRoutes('test')
    if(savedSubLabelsOnLoad == "no")
     {
       showHideSubLabels('test')
     }
    }
}

function printMapTest()
{
 document.getElementById("printPreview").style.visibility = "visible"
 document.getElementById("myMap").style.width = "7in"
 document.getElementById("myMap").style.height = "7in"
 document.getElementById("myMap").style.top = "50px"
 document.getElementById("myMap").style.border = "solid blue 2px"
 map.HideDashboard()
 document.getElementById("mapControls3").style.display = "none"
 document.getElementById("mapControls5").style.display = "none"
 document.getElementById("key").style.display = "none"
 document.getElementById("showAccessibleStationsButtonDiv1").style.display = "none"
 document.getElementById("stationLocator").style.display = "none"
 document.getElementById("placeFinderForm").style.display = "none"
 document.getElementById("addressFinderForm").style.display = "none"
 document.getElementById("stepsDiv").style.visibility = "hidden"
 document.getElementById("userNameLabel").style.display = "none"

 document.getElementById("mapControls4").style.display = "none"
 document.getElementById("menuBackground").style.display = "none"
 document.getElementById("topMenuBackground").style.display = "none"
 document.getElementById("compassDiv").style.display = "none"
 document.getElementById("zoomInImage").style.display = "none"
 document.getElementById("zoomOutImage").style.display = "none"
 document.getElementById("tripPlannerLogo").style.display = "none"
 map.Resize();
}

function cancelPrint()
{
 document.getElementById("myMap").style.border = "solid blue 0px"
 setMapSize()
 document.getElementById("myMap").style.top = "0px"
 document.getElementById("printPreview").style.visibility = "hidden"
 document.getElementById("mapControls3").style.display = "inline"
 document.getElementById("mapControls5").style.display = "inline"
 document.getElementById("key").style.display = "inline"
 document.getElementById("showAccessibleStationsButtonDiv1").style.display = "inline"
 document.getElementById("stationLocator").style.display = "inline"
 document.getElementById("placeFinderForm").style.display = "inline"
 document.getElementById("addressFinderForm").style.display = "inline"
 document.getElementById("stepsDiv").style.visibility = "visible"

 document.getElementById("mapControls4").style.display = "inline"
 document.getElementById("menuBackground").style.display = "inline"
 document.getElementById("topMenuBackground").style.display = "inline"
 document.getElementById("compassDiv").style.display = "inline"
 document.getElementById("zoomInImage").style.display = "inline"
 document.getElementById("zoomOutImage").style.display = "inline"
 document.getElementById("tripPlannerLogo").style.display = "inline"

 if(logInUser != "")
 {
  document.getElementById("userNameLabel").style.display = "inline"
 }
 map.Resize();
}

//*****************************************************************
//For the info boxes in the Transit Directions Route Map Module
//*****************************************************************
var infoBoxTry
infoBoxTry = 0
var currentCenterPoint
var currentPin
function showInfo(centerPoint,pin)
{
 currentCenterPoint = centerPoint
 currentPin = pin
 infoBoxTry = 0
 setTimeout("showInfo2()",500)
 showInfo2()
}

function showInfo2()
{
 if(map.GetZoomLevel() == 16 && map.GetCenter().Longitude.toString().substring(0,8) == currentCenterPoint.Longitude.toString().substring(0,8) &&  map.GetCenter().Latitude.toString().substring(0,7) == currentCenterPoint.Latitude.toString().substring(0,7))
 {
  map.ShowInfoBox(currentPin, currentCenterPoint, new VEPixel(15, 0))
  infoBoxTry = 10
 }
 else
 {
  if(infoBoxTry < 10)
  {
   setTimeout("showInfo2()",500)
   infoBoxTry = infoBoxTry + 1
  }
 }
}

function showPrintTextDiv()
{
document.getElementById("stepTextDivHolder").style.visibility = "visible"
}
//********************************************************************************

function showMarkerEditForm(id)
{ 
 document.getElementById("editMarkerDiv").style.top = (pageHeight()/2 - document.getElementById("editMarkerDiv").clientHeight/2) + "px"
 document.getElementById("editMarkerDiv").style.left = (pageWidth()/2 - document.getElementById("editMarkerDiv").clientWidth/2) + "px"
 document.getElementById("editMarkerDiv").style.visibility = "visible"
 document.forms["editMarkerform"].elements["editMarkerLabel1"].value = ""
 document.forms["editMarkerform"].elements["editMarkerLabel2"].value = ""
 document.forms["editMarkerform"].elements["editMarkerLabel3"].value = ""
 document.forms["editMarkerform"].elements["id"].value = id
 setTimeout("prePopulateEditMarkerForm('" + id + "')",1)
}

function prePopulateEditMarkerForm(id)
{
 var L
 var L2
 var L3
 //document.getElementById("editMarkerDiv").style.visibility = "visible"
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i].split("!")[0] == id)
  {
   L = markers[i].split("!")[2]
   L = L.replace(/&#33;/g, "!")
   L = L.replace(/&#124;/g, "|")
   L = L.replace(/&#58;/g, ":")
   L = L.replace(/&#34;/g, '"')
   L = L.replace(/&#44;/g, ',')
   L = L.replace(/&#39;/g, "'")


   L2 = markers[i].split("!")[3]
   L2 = L2.replace(/&#33;/g, "!")
   L2 = L2.replace(/&#124;/g, "|")
   L2 = L2.replace(/&#58;/g, ":")
   L2 = L2.replace(/&#34;/g, '"')
   L2 = L2.replace(/&#44;/g, ',')
   L2 = L2.replace(/&#39;/g, "'")

   L3 = markers[i].split("!")[4]
   L3 = L3.replace(/&#33;/g, "!")
   L3 = L3.replace(/&#124;/g, "|")
   L3 = L3.replace(/&#58;/g, ":")
   L3 = L3.replace(/&#34;/g, '"')
   L3 = L3.replace(/&#44;/g, ',')
   L3 = L3.replace(/&#39;/g, "'")
   setMarkerBackColor(markers[i].split("!")[5])
   document.forms["editMarkerform"].elements["editMarkerLabel1"].value = L
   document.forms["editMarkerform"].elements["editMarkerLabel2"].value = L2
   document.forms["editMarkerform"].elements["editMarkerLabel3"].value = L3
   //document.forms["editMarkerform"].elements["id"].value = id
   //document.getElementById("editMarkerDiv").style.top = (pageHeight()/2 - document.getElementById("editMarkerDiv").clientHeight/2) + "px"
   //document.getElementById("editMarkerDiv").style.left = (pageWidth()/2 - document.getElementById("editMarkerDiv").clientWidth/2) + "px"
  }
 }
}

function updateMarker(id,L,L2,L3)
{
  if(L == "")
  {
  alert("Label Line 1 cannot be blank")
  }
  else
  {

  labelLine1 = L.replace(/x_x/g, ";")
  labelLine1 = labelLine1.replace(/__/g, "_")
  labelLine1 = labelLine1.replace(/:/g, "&#58;")
  labelLine1 = labelLine1.replace(/"/g, "&#34;")
  labelLine1 = labelLine1.replace(/,/g, ".")
  labelLine1 = labelLine1.replace(/'/g, "&#39;")
  labelLine1 = labelLine1.replace(/!/g, "&#33;")
  labelLine2 = L2.replace(/x_x/g, ";")
  labelLine2 = labelLine2.replace(/__/g, "_")
  labelLine2 = labelLine2.replace(/:/g, "&#58;")
  labelLine2 = labelLine2.replace(/'/g, "&#39;")
  labelLine2 = labelLine2.replace(/"/g, "&#34;")
  labelLine2 = labelLine2.replace(/,/g, ".")
  labelLine2 = labelLine2.replace(/!/g, "&#33;")
  labelLine3 = L3.replace(/x_x/g, ";")
  labelLine3 = labelLine3.replace(/__/g, "_")
  labelLine3 = labelLine3.replace(/:/g, "&#58;")
  labelLine3 = labelLine3.replace(/'/g, "&#39;")
  labelLine3 = labelLine3.replace(/"/g, "&#34;")
  labelLine3 = labelLine3.replace(/,/g, ".")
  labelLine3 = labelLine3.replace(/!/g, "&#33;")

 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i].split("!")[0] == id)
  {
   lat = markers[i].split("!")[1].split("|")[0]
   lon = markers[i].split("!")[1].split("|")[1]
   lineList = markers[i].split("!")[6]
   markerColor  = MC
   AddPushPin(lat,lon,labelLine1,labelLine2,labelLine3,markerColor,"customMarker",lineList)
   deletePushpin(id)
  }
 }
 document.getElementById('editMarkerDiv').style.visibility = 'hidden'
 }
}

var MC
MC = 0
function setMarkerBackColor(c)
{
 MC = c
 document.getElementById("labelSample").style.backgroundColor = "#" + pointerColor[c].split(",")[0]
 document.getElementById("labelEditSample").style.backgroundColor = "#" + pointerColor[c].split(",")[0]
}

function GetMap()
{
 var ffv = 0;
 var ffn = "Firefox/"
 var ffp = navigator.userAgent.indexOf(ffn);
 // If the browser is Firefox get the version number
 if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
 // If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
 if (ffv >= 1.5)
 {
  Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
 }
 // Put your own code below this line
 map = new VEMap('myMap');
 //map.SetClientToken(token);
 //map.SetDashboardSize(VEDashboardSize.Normal); 
 map.LoadMap(new VELatLong(mapCenterLat, mapCenterLon), mapZoomLevel ,mapStyle , false);
 //map.ShowDashboard();
   map.HideDashboard();
 map.AttachEvent("onendzoom", showRoutesNotAvailableMessage);
 if(subRoutesOnLoad == "yes")
 {
  showHideSubRoutes('onLoad')
  if(subLabelsOnLoad == "no")
  {
   showHideSubLabels('onLoad')
  }
 }
 map.AttachEvent("onmouseover", rollover);
 map.AttachEvent("onmouseout", rollout);
 map.AttachEvent("onstartpan", startPan);
 map.AttachEvent("onclick", clickInfo);
 map.AttachEvent("onendpan", checkMapLimits);
 map.HideInfoBox();
 map.SetPrintOptions(new VEPrintOptions(true)); 



 if(map.GetZoomLevel() == 15)
   {
   document.getElementById("HideLabelsText").style.display = "inline"
   }
 else
   {
   document.getElementById("HideLabelsText").style.display = "none"
   }


} 

function zoomIn()
{
map.SetZoomLevel(map.GetZoomLevel()+1)
}

function zoomOut()
{
map.SetZoomLevel(map.GetZoomLevel()-1)
}


//***********************************************************
//Compass Pan Control
//***********************************************************


function showCompassPoints(x,y)
{
var compassXOffset
var compassYOffset
var compassHeight
var compassWidth


compassXOffset = 30;
compassYOffset = 30;
compassHeight = 78;
compassWidth = 78;


var compassXclick
var compassYclick


compassXclick = x-(compassXOffset+(compassWidth/2))
compassYclick = y-(compassYOffset+(compassHeight/2))


var radius
radius = 39


var percentX
var percentY
percentX = parseInt((compassXclick*100)/radius)
percentY = parseInt((compassYclick*100)/radius)


if(((compassXclick*compassXclick) + (compassYclick*compassYclick)) <= radius*radius)
{
//alert(percentX + "," + percentY)
map.StartContinuousPan(percentX,percentY);
}
}




function showitMOZ(e) {
  showCompassPoints(e.pageX,e.pageY)


}


function showit(x,y) {
  showCompassPoints(x,y)
}


function getMouseEvents()
{
if(!document.all)
{
  window.captureEvents(Event.CLICK);
  document.getElementById('compassDiv').onmousedown=showitMOZ;
}
else
{
document.getElementById('compassDiv').onmousedown = function(){showit(event.x,event.y)}
}
}


function endCompassPan()
{
map.EndContinuousPan();
}



//***********************************************************


function checkMapLimits()
{
if(map.GetCenter().Latitude > MapLimitNorth)
{
 map.SetCenter(new VELatLong(40.771686,-73.9848875));
}

if(map.GetCenter().Latitude < MapLimitSouth)
{
 map.SetCenter(new VELatLong(40.771686,-73.9848875));
}

if(map.GetCenter().Longitude > MapLimitEast)
{
 map.SetCenter(new VELatLong(40.771686,-73.9848875));
}

if(map.GetCenter().Longitude < MapLimitWest)
{
 map.SetCenter(new VELatLong(40.771686,-73.9848875));
}
} 


function startPan()
{
 document.getElementById("infoBox").style.visibility = "hidden"
}
 
function addStationRollovers()
{
 for(i = 0; i <  stations.length; i++)
 {
  if(stations[i])
  {
   AddShape("stations",i,stations[i].split(";")[0].split(",")[0]*1,stations[i].split(";")[0].split(",")[1]*1,0.00040000)
  }
 }  
 AccessibleshapeLayer= new VEShapeLayer();
 AccessibleshapeLayer.SetTitle("Accessible Stations");
 map.AddShapeLayer(AccessibleshapeLayer);
 AccessibleshapeLayer.Hide();
 for(i = 0; i <  accessibleStations.length; i++)
 {
  if(accessibleStations[i])
  {
   makeAccessiblePuspins(accessibleStations[i].split(";")[0].split(",")[0]*1,accessibleStations[i].split(";")[0].split(",")[1]*1,i)
  }
 }
} 

function clickInfo(e)
{
 map.HideInfoBox();
 if(map.GetShapeByID(e.elementID) != null)
 {
  if(advisoryStationInfo[map.GetShapeByID(e.elementID).GetID()])
  {
   map.HideInfoBox();
   latitude = map.GetShapeByID(e.elementID).Latitude;
   Longitude = map.GetShapeByID(e.elementID).Longitude;
   document.getElementById("stationName").innerHTML = stations[advisoryStationInfo[map.GetShapeByID(e.elementID).GetID()]].split(";")[1];
  }
 }
}

function rollover(e)
{
 map.HideInfoBox();
 if(e.elementID != null)
 {
  if(map.GetShapeByID(e.elementID) != null)
  {
   if(subwayMapVisible)
   {
    if(map.GetShapeByID(e.elementID).GetType() == "Polygon")
    {
     map.HideInfoBox();
     currentInfoBoxId = map.GetShapeByID(e.elementID).GetID();
     var infoBoxHTML
     infoBoxHTML = ""
     infoBoxHTML = infoBoxHTML + map.GetShapeByID(e.elementID).GetDescription();
     document.getElementById("infoBoxCell").innerHTML = infoBoxHTML 
     document.getElementById("infoBox").style.top = ((parseInt(map.LatLongToPixel(map.GetShapeByID(e.elementID).GetPoints()[0]).y)+parseInt(map.LatLongToPixel(map.GetShapeByID(e.elementID).GetPoints()[3]).y))/2)-(parseInt(document.getElementById("infoBox").clientHeight)/2) + "px"
     document.getElementById("infoBox").style.left = (parseInt(map.LatLongToPixel(map.GetShapeByID(e.elementID).GetPoints()[1]).x)*1) -(parseInt(document.getElementById("infoBox").clientWidth)) + "px"
     document.getElementById("infoBox").style.visibility = "visible"
    }
   }
   if(accessibleStationInfo[map.GetShapeByID(e.elementID).GetID()])
   {
    map.HideInfoBox();
    var infoBoxHTML
    infoBoxHTML = ""
    infoBoxHTML = infoBoxHTML + stations[accessibleStationInfo[map.GetShapeByID(e.elementID).GetID()]].split(";")[2];
    document.getElementById("infoBoxCell").innerHTML = infoBoxHTML 
    document.getElementById("infoBox").style.top = ((parseInt(map.LatLongToPixel(map.GetShapeByID(e.elementID).GetPoints()[0]).y)*1)-(parseInt(document.getElementById("infoBox").clientHeight)/2) )+ "px"
    document.getElementById("infoBox").style.left = ((parseInt(map.LatLongToPixel(map.GetShapeByID(e.elementID).GetPoints()[0]).x)*1) -(parseInt(document.getElementById("infoBox").clientWidth))) + "px"
    document.getElementById("infoBox").style.visibility = "visible"
   }
  }
 }
}

function positionInfoBox()
{
 document.getElementById("infoBox").style.top = ((parseInt(map.LatLongToPixel(map.GetShapeByID(currentInfoBoxId).GetPoints()[0]).y)+parseInt(map.LatLongToPixel(map.GetShapeByID(currentInfoBoxId).GetPoints()[3]).y))/2)-(parseInt(document.getElementById("infoBox").clientHeight)/2) + "px"
}

function rollout(e)
{
 if(e.elementID != null)
 {
  map.HideInfoBox();
  document.getElementById("infoBox").style.visibility = "hidden"
  document.getElementById("infoBoxSB").style.visibility = "hidden"
 }
}

function pageWidth()
{
 return document.getElementById("pageSizer").clientWidth
}

function pageHeight()
{
 if(window.innerHeight)
 {
 return window.innerHeight
 }
 else
 {
 return document.documentElement.clientHeight
 }
}

function setMapSize()
{
 document.getElementById("myMap").style.width = pageWidth() + "px"
 document.getElementById("myMap").style.height = pageHeight() + "px"
}

function showRoutesNotAvailableMessage()
{
 if((map.GetZoomLevel() > 15 || map.GetZoomLevel() < 14) && subwayMapVisible)
 {
  DeleteTileLayer()
  subwayMapVisible = false
 }
 if((map.GetZoomLevel() == 15 || map.GetZoomLevel() == 14) && !subwayMapVisible && subwayMapSelected)
 {
  showHideSubRoutes()
 }

 if(map.GetZoomLevel() == 15)
   {
   document.getElementById("HideLabelsText").style.display = "inline"
   }
 else
   {
   document.getElementById("HideLabelsText").style.display = "none"
   }
}

var stationText = new Array()
function AddShape(line,id,lat,lon,r)
{
 var shape  = null;
 var centerPointLat = lat
 var centerPointLon = lon
 var radius = r
 var cornerOne   = new VELatLong(centerPointLat-radius,centerPointLon-radius);
 var cornerTwo   = new VELatLong(centerPointLat+radius,centerPointLon-radius);
 var cornerThree = new VELatLong(centerPointLat+radius,centerPointLon+radius);
 var cornerFour  = new VELatLong(centerPointLat-radius,centerPointLon+radius);

 // Create the VEShape object and assign parameters.
 var points = new Array(cornerFour, cornerOne, cornerTwo, cornerThree);
 shape = new VEShape(VEShapeType.Polygon, points);
 shape.SetLineWidth(1);
 shape.SetLineColor(new VEColor(0,150,100,0.0));
 shape.SetFillColor(new VEColor(0,150,100,0.0));
 shape.SetTitle(eval(line)[id].split(";")[1]);
 shape.SetDescription(eval(line)[id].split(";")[2]);
 shape.HideIcon();
 shape.SetZIndex(3000,3000)
 map.AddShape(shape);
}


function showHideAccessiblePushpins()
{
 if (AccessibleshapeLayer.IsVisible())
 {
  document.getElementById("showAccessibleStationsButtonDiv1").style.backgroundColor = "silver"
  AccessibleshapeLayer.Hide();
 }
 else
 {
  document.getElementById("showAccessibleStationsButtonDiv1").style.backgroundColor = "blue"
  AccessibleshapeLayer.Show();
  map.HideInfoBox();
 }
}

function makeAccessiblePuspins(Lat,Lon,stationIndex)
{
 var shape   = null;
 var pushPinLocation   = new VELatLong(Lat,Lon);
 shape = new VEShape(VEShapeType.Pushpin, pushPinLocation);
 pushPinHTML = "<img style='position:relative; left:12px; top:12px' src='mapImages/accessibleIcon.gif'>"
 shape.SetCustomIcon(pushPinHTML)
 AccessibleshapeLayer.AddShape(shape);
 accessibleStationInfo[shape.GetID()] = stationIndex
 accessibleStationpPushPinIDs.push(shape.GetID())
}

function hideAccessiblePushpins()
{
 if(AccessibleshapeLayer)
 {
  document.getElementById("showAccessibleStationsButtonDiv1").style.backgroundColor = "silver"
  AccessibleshapeLayer.Hide();
 } 
}

function loadSavedMarkers()
{
 if(savedMarkers != "")
 {
  var lat
  var lon
  var L
  var L2
  var L3
  var markerColor
  var type
  var LineList
  var markerList
  markerList = savedMarkers.split("::")
  for(i = 0; i <  markerList.length; i++)
  {
   lat = markerList[i].split("!")[1].split("|")[0]
   lon = markerList[i].split("!")[1].split("|")[1]
   L = markerList[i].split("!")[2]
   L2 = markerList[i].split("!")[3]
   L3 = markerList[i].split("!")[4]
   markerColor = markerList[i].split("!")[5]
   LineList =  markerList[i].split("!")[6]
   type = markerList[i].split("!")[7]
   AddPushPin(lat,lon,L,L2,L3,markerColor,type,LineList)
  }
 }
}

function AddPushPin(lat,lon,L,L2,L3,markerColor,type,lineList)
{
 var L2style
 var L3style
 L2style = 'font-weight:normal'
 L3style = 'font-weight:normal:bold'
 if(type == "station")
 {
  L2style = 'font-weight:normal'
  L3style = 'font-weight:normal:bold'
 }
 if(type == "landmark")
 { 
  L2style = 'font-weight:normal'
 }
 if(type == "addressFinder")
 { 
  L2style = 'font-weight:normal'
 }
 var LL
 var LL2
 var LL3


 LL = L
 LL2 = L2
 LL3 = L3


 if(L2 != "")
 {
  LL2 = "<br /><span style='" + L2style + "'>" + LL2 + "</span>"
 }
 else
 {
  LL2 = ""
 }
 if(L3 != "")
 {
  LL3 = "<br /><span style='" + L3style + "'>" + LL3 + "</span>"
 }
 else
 {
  LL3 = ""
 }
 document.getElementById("pushPinLabel").innerHTML = "<span style='font-size:12px; font-weight:bold; font-family:arial;'><nobr>" + LL + "</span></nobr><nobr>" + LL2 + "</nobr><nobr>" + LL3 + "</nobr>"
 var W
 var H
 H = document.getElementById("pushPinTemplate").clientHeight
 W = document.getElementById("pushPinTemplate").clientWidth
 var BC
 var SC
 var FC
 BC = pointerColor[markerColor].split(",")[0]
 SC = pointerColor[markerColor].split(",")[1]
 FC = pointerColor[markerColor].split(",")[2]
 var browser = "notIE"
 if(navigator.appVersion.indexOf("MSIE")!=-1)
 {
  browser = "IE"
 }
 var ww
 var size
 size = "0"
 ww = 76

 var pt
 pt = 3

 if(H < 90)
 {
  pt = 12
 }

 if(H < 75)
 {
  pt = 18
 }

var LOffset
LOffset = 36

if(W > 57)
{
size = 1
ww = 81
}

if(W > 63)
{
size = 2
ww = 90
}

if(W > 72)
{
size = 3
ww = 95
}

if(W > 77)
{
size = 4
ww = 100
}

if(W > 82)
{
size = 5
ww = 105
}

if(W > 87)
{
size = 6
ww = 109
}

if(W > 91)
{
size = 7
ww = 114
}

if(W > 96)
{
size = 8
ww = 119
}

if(W > 101)
{
size = 9
ww = 124
}
if(W > 106)
{
size = 10
ww = 129
}

if(W > 111)
{
size = 11
ww = 133
}

if(W > 115)
{
size = 12
ww = 138
}

if(W > 120)
{
size = 13
ww = 143
}

if(W > 125)
{
size = 14
ww = 148
}

if(W > 130)
{
size = 15
ww = 153
}

if(W > 135)
{
size = 16
ww = 157
}

if(W > 139)
{
size = 17
ww = 162
}

if(W > 149)
{
size = 18
ww = 179
}

if(W > 159)
{
size = 19
ww = 193
}

if(W > 175)
{
size = 20
ww = 225
}

if(W > 207)
{
size = 21
ww = 249
}

if(W > 231)
{
size = 22
ww = 281
}

if(W > 263)
{
size = 23
ww = 337
}

 var hh
 hh = 92

 var ew
 ew = parseInt((ww-48)/2)
 var shape   = null;
 var pushPinLocation   = new VELatLong(lat,lon);
 shape = new VEShape(VEShapeType.Pushpin, pushPinLocation);
 shape.SetZIndex(10000, 10000);
 map.AddShape(shape);
 var pushPinHTML
 pushPinHTML = ""
 pushPinHTML = pushPinHTML + "<div style='z-index:10000; border:solid black 0px; position:relative; top:-" + 78 + "px; left:-" + LOffset + "px; padding:0px; background-color:transparent; width:" + ww + "px; height:" + hh + "px; overflow:hidden;'>"
 if(browser == "IE")
 {
  pushPinHTML = pushPinHTML + "<style>v\: * { behavior:url(#default#VML);display:inline-block }</style>"
  pushPinHTML = pushPinHTML + "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />"
  pushPinHTML = pushPinHTML + "<v:image style='position:absolute; top:0px; left:0px; width:" + ww + "px; height:92px;' src='pointerImages/" + BC + "/" + size + ".gif' />"
 }
 else
 {
  pushPinHTML = pushPinHTML + "<img style='position:absolute; top:0px; left:0px; width:" + ww + "px; height:92px;' src='pointerImages/" + BC + "/" + size + ".gif' />"
 }
 pushPinHTML = pushPinHTML + "<div onclick='showMarkerEditForm(" + '"' + shape.GetID() + '"' + ")' id='" + shape.GetID() + "DIV' style='z-index:10000; cursor:pointer; padding-left:3px; padding-top:" + pt + "px; position:absolute; top:2px; left:4px; height:50px; width:" + (ww-10) + "px; color:#" + FC + "; font-size:12px; font-weight:bold; font-family:arial;'><nobr>" + LL + "</nobr><nobr>" + LL2 + "</nobr><nobr>" + LL3 + "</nobr></div>"
 pushPinHTML = pushPinHTML + "<div style='z-index:10001; position:absolute; top:7px; left:" + (ww-22) + "px; height:8px; width:18px;'><img onclick='javascript:hideMarker(" + '"' + shape.GetID() + '"' + ")' src='pointerImages/minMarker.gif' width='8' height='8' style='cursor:pointer;'><img onclick='javascript:deletePushpin(" + '"' + shape.GetID() + '"' + ")' src='pointerImages/closeButton.gif' width='8' height='8' style='cursor:pointer; position:relative; left:2px;'></div>"
 pushPinHTML = pushPinHTML + "</div>"
 shape.SetCustomIcon(pushPinHTML);
 markers.push(shape.GetID() + "!" + lat + "|" + lon + "!" + L + "!" + L2 + "!" + L3 + "!" + markerColor + "!" + lineList + "!" + type)
}

function deletePushpin(id)
{
 map.DeleteShape(map.GetShapeByID(id));
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i].split("!")[0] == id)
  {
   markers[i] = "deleted"
  }
 }
}

function hideMarker(id)
{
map.GetShapeByID(id).Hide()
document.getElementById("restoreMarkersDiv").style.display = "inline"
}

function hideAllMarkers()
{
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i] != "deleted")
  {
   map.GetShapeByID(markers[i].split("!")[0]).Hide()
  }
 }
}


function hideAllMarkers()
{
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i] != "deleted")
  {
   map.GetShapeByID(markers[i].split("!")[0]).Hide()
  }
 }
}

function showAllMarkers()
{
 document.getElementById("restoreMarkersDiv").style.display = "none"
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i] != "deleted")
  {
   map.GetShapeByID(markers[i].split("!")[0]).Show()
  }
 }
}

function hideShowAllMarkers(e)
{
 if(e.innerText == "Hide markers")
 {
  hideAllMarkers()
  e.innerText = "Show markers"
 }
 else
 {
  showAllMarkers()
  e.innerText = "Hide markers"
 }
}

function hidePushpin(element)
{
 element.style.display = "none"
}

function showKey()
{
 if(document.getElementById("key").style.visibility == "hidden")
 {
  document.getElementById("keyButton3").innerHTML = "&nbsp;Key&nbsp;"
  document.getElementById("keyButton3").innerHTML = "&nbsp;Key&nbsp;"
  document.getElementById("key").style.visibility = "visible"
 }
 else
 {
  document.getElementById("keyButton3").innerHTML = "&nbsp;Key&nbsp;"
  document.getElementById("keyButton3").innerHTML = "&nbsp;Key&nbsp;"
  document.getElementById("key").style.visibility = "hidden"
 }
}

function showStationLocator()
{
var startLocation = parseInt(document.getElementById("stationFinderForm").clientWidth)
if(parseInt(document.getElementById("stationFinderForm").style.left) < (166 - startLocation))
{
document.getElementById("stationFinderForm").style.left = (166 - startLocation) + "px"
}

 if(parseInt(document.getElementById("stationFinderForm").style.left) < 166)
 {
  document.getElementById("stationFinderForm").style.left = (parseInt(document.getElementById("stationFinderForm").style.left) + 10) + "px"
  setTimeout("showStationLocator()",15)
 } 
 else
 {
  document.getElementById("stationFinderForm").style.left = "166px"
  document.getElementById("stationFinderForm").style.zIndex = 1000
 } 
}

function showLineMapSelector()
{
var startLocation = parseInt(document.getElementById("lineMapForm").clientWidth)
if(parseInt(document.getElementById("lineMapForm").style.left) < (166 - startLocation))
{
document.getElementById("lineMapForm").style.left = (166 - startLocation) + "px"
}

 if(parseInt(document.getElementById("lineMapForm").style.left) < 166)
 {
  document.getElementById("lineMapForm").style.left = (parseInt(document.getElementById("lineMapForm").style.left) + 10) + "px"
  setTimeout("showLineMapSelector()",15)
 } 
 else
 {
  document.getElementById("lineMapForm").style.left = "166px"
 } 
}

function showPlaceFinder()
{
var startLocation = parseInt(document.getElementById("placeFinderForm").clientWidth)
if(parseInt(document.getElementById("placeFinderForm").style.left) < (166 - startLocation))
{
document.getElementById("placeFinderForm").style.left = (166 - startLocation) + "px"
}
 if(parseInt(document.getElementById("placeFinderForm").style.left) < 166)
 {
  document.getElementById("placeFinderForm").style.left = (parseInt(document.getElementById("placeFinderForm").style.left) + 10) + "px"
  setTimeout("showPlaceFinder()",15)
 }
 else
 {
  document.getElementById("placeFinderForm").style.left = "166px"
  document.getElementById("placeFinderForm").style.zIndex = 1000
 } 
}

function showAddressFinder()
{
var startLocation = parseInt(document.getElementById("addressFinderForm").clientWidth)
if(parseInt(document.getElementById("addressFinderForm").style.left) < (166 - startLocation))
{
document.getElementById("addressFinderForm").style.left = (166 - startLocation) + "px"
}
 if(parseInt(document.getElementById("addressFinderForm").style.left) < 166)
 {
  document.getElementById("addressFinderForm").style.left = (parseInt(document.getElementById("addressFinderForm").style.left) + 10) + "px"
  setTimeout("showAddressFinder()",15)
 }
 else
 {
  document.getElementById("addressFinderForm").style.left = "166px"
  document.getElementById("addressFinderForm").style.zIndex = 1000
 }
}

function hideMenuSliders()
{
hideStationLocator2()

hidePlaceFinder2()
hideAddressFinder2()
hideLineMapSelector2()
}

function getNumberOfMarkers()
{
 var count
 count = 0
 for(i=0; i < markers.length; i++)
 {
  if(markers[i] != "deleted")
  {
   count = count + 1
  }
 }
 return count
}

function showTripPlannerForm()
{
 document.forms["tripPlanner2"].elements["lineStart"].selectedIndex = 0
 document.forms["tripPlanner2"].elements["lineEnd"].selectedIndex = 0
 if(getNumberOfMarkers() < 2)
 {
  document.getElementById('tripPlannerAlertBox').style.display='inline'
  centerDiv(document.getElementById('tripPlannerAlertBox'))
 }
 else
 {
  if(parseInt(document.getElementById("tripPlanner2Table").style.left) < 0)
  {
   document.getElementById("tripPlanner2Table").style.left = (parseInt(document.getElementById("tripPlanner2Table").style.left) + 10) + "px"
   setTimeout("showTripPlannerForm()",15)
  } 
 }
}

function hideStationLocator()
{
 document.getElementById("stationFinderForm").style.zIndex = 498
 document.getElementById("stationSelector").innerHTML = ""
 document.forms["stationLocator"].elements["line"].selectedIndex = 0
 if(parseInt(document.getElementById("stationFinderForm").style.left) > (document.getElementById("stationFinderForm").clientWidth * -1)-20)
 {
  document.getElementById("stationFinderForm").style.left = (parseInt(document.getElementById("stationFinderForm").style.left) - 10) + "px"
  setTimeout("hideStationLocator()",15)
 } 
}

function hideLineMapSelector()
{
 document.getElementById("lineMapSelector").innerHTML = ""
 document.forms["stationLocator"].elements["lineMapLine"].selectedIndex = 0
 if(parseInt(document.getElementById("lineMapForm").style.left) > (document.getElementById("lineMapForm").clientWidth * -1)-20)
 {
  document.getElementById("lineMapForm").style.left = (parseInt(document.getElementById("lineMapForm").style.left) - 10) + "px"
  setTimeout("hideLineMapSelector()",15)
 } 
}


function hidePlaceFinder()
{
 document.getElementById("placeFinderForm").style.zIndex = 498
 document.forms["stationLocator"].elements["landmarkSubCategory"].selectedIndex = 0
 if(parseInt(document.getElementById("placeFinderForm").style.left) > (document.getElementById("placeFinderForm").clientWidth * -1)-20)
 {
  document.getElementById("placeFinderForm").style.left = (parseInt(document.getElementById("placeFinderForm").style.left) - 10) + "px"
  setTimeout("hidePlaceFinder()",15)
 } 
}

function hideAddressFinder()
{
 document.getElementById("ambibousAddress").style.display = "none"
 document.getElementById("addressFinderForm").style.zIndex = 498
 if(parseInt(document.getElementById("addressFinderForm").style.left) > (document.getElementById("addressFinderForm").clientWidth * -1)-20)
 {
  document.getElementById("addressFinderForm").style.left = (parseInt(document.getElementById("addressFinderForm").style.left) - 10) + "px"
  setTimeout("hideAddressFinder()",15)
 } 
}

function hideTripPlannerForm()
{
 if(parseInt(document.getElementById("tripPlanner2Table").style.left) > (document.getElementById("tripPlanner2Table").clientWidth * -1)-20)
 {
  document.getElementById("tripPlanner2Table").style.left = (parseInt(document.getElementById("tripPlanner2Table").style.left) - 10) + "px"
  setTimeout("hideTripPlannerForm()",15)
 } 
}

function quickCloseTripPlannerForm()
{
 document.getElementById("tripPlanner2Table").style.left = "-550px"
}

function hideStationLocator2()
{
 document.getElementById("stationFinderForm").style.zIndex = 498
 document.getElementById("stationSelector").innerHTML = ""
 document.forms["stationLocator"].elements["line"].selectedIndex = 0
 document.getElementById("stationFinderForm").style.left = "-" + (document.getElementById("stationFinderForm").clientWidth + 20) + "px"
}

function hidePlaceFinder2()
{
 document.getElementById("placeFinderForm").style.zIndex = 498
 document.getElementById("landmarkSelector").innerHTML = ""
 document.forms["stationLocator"].elements["landmarkSubCategory"].selectedIndex = 0
 document.getElementById("placeFinderForm").style.left = "-" + (document.getElementById("placeFinderForm").clientWidth + 20) + "px"
}

function hideAddressFinder2()
{
document.getElementById("ambibousAddress").style.display = "none"
document.getElementById("addressFinderForm").style.zIndex = 498
document.getElementById("addressFinderForm").style.left = "-" + (document.getElementById("addressFinderForm").clientWidth + 20) + "px"
}


function hideLineMapSelector2()
{
document.getElementById("lineMapSelector").innerHTML = ""
document.forms["stationLocator"].elements["lineMapLine"].selectedIndex = 0
document.getElementById("lineMapForm").style.left = "-" + (document.getElementById("lineMapForm").clientWidth + 20) + "px"
}


function loadStationSelect(line)
{
 var stationSelect
 stationSelect = "<select  onchange=" + "javascript:panToLocation(stations[this.options[this.selectedIndex].value]" + ",'" + "station" + "')" + ";" + "hideStationLocator2()>"
 stationSelect = stationSelect + "<option value='0' style='background-color:white'>Select Station</option>"
 for(i = 0; i <  stationsByLine[line].split(",").length-1; i++)
 {
  stationSelect = stationSelect + "<option value='" + stationsByLine[line].split(",")[i] + "'>" + stations[stationsByLine[line].split(",")[i]].split(";")[1] + "</option>"
 }
 stationSelect = stationSelect + "</select>"
 document.getElementById("stationSelector").innerHTML = stationSelect
}



function loadLandmarks(subCat)
{
 if(subCat.split("_")[0] == "ATIS")
 {
 window.frames["ajaxIframe"].location.href="ATISLandmarks/" + subCat.split("_")[1] + ".html?2_18_3"
 }
 else
 {
 var landmarkSelectString
 landmarkSelectString = "<select name='landmarksSelect' onchange='javascript:panToLocation(" + subCat + "[this.selectedIndex-1]," + '"landmark"' + "); hidePlaceFinder2()'>"
 landmarkSelectString = landmarkSelectString + "<option value='0' style='background-color:white'>Select from list below</option>"
 for(i = 0; i <  eval(subCat).length; i++)
 {
  landmarkSelectString = landmarkSelectString + "<option >" + eval(subCat)[i].split(";")[1] + "</option>"
 }
 landmarkSelectString = landmarkSelectString + "</select>"
 document.getElementById("landmarkSelector").innerHTML = landmarkSelectString
 }
}



function loadAtisLandmarks(selectHTML)
{
 document.getElementById("landmarkSelector").innerHTML = selectHTML
}





function loadTripPlanToList()
{
 var markerSelect
 markerSelect = "<select name='destinationCoordinates'>"
 var LineList
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i] != "deleted")
 {
  LineList = ""
  if(markers[i].split("!")[6] != "")
  {
   LineList = "(" + markers[i].split("!")[6] + ")"
  }
  markerSelect = markerSelect + "<option value='" + markers[i].split("!")[1].split("|")[0].substr(0,11) + "," + markers[i].split("!")[1].split("|")[1].substr(0,12) + ",," + markers[i].split("!")[2] + ",Located on Map," + "'>" + markers[i].split("!")[2] + LineList + "</option>"
  }
 }
 markerSelect = markerSelect + "</select>"
 document.getElementById("TripPlanToList").innerHTML = markerSelect
}

function loadTripPlanFromList()
{
 var markerSelect
 markerSelect = "<select name='originCoordinates'>"
 var LineList
 for(i = 0; i <  markers.length; i++)
 {
  if(markers[i] != "deleted")
  {
  LineList = ""
  if(markers[i].split("!")[6] != "")
  {
   LineList = "(" + markers[i].split("!")[6] + ")"
  }
  markerSelect = markerSelect + "<option value='" + markers[i].split("!")[1].split("|")[0].substr(0,11) + "," + markers[i].split("!")[1].split("|")[1].substr(0,12) + ",," + markers[i].split("!")[2] + ",Located on Map," + "'>" + markers[i].split("!")[2] + LineList + "</option>"
  }
 }
 markerSelect = markerSelect + "</select>"
 document.getElementById("TripPlanFromList").innerHTML = markerSelect
}

var pushPinLatLon
pushPinLatLon = ""
var pushPinClosed
pushPinClosed = "no"
function panToLocation(stationData,type)
{
 recenterMap(stationData,type)
}

function recenterMap(stationData,type)
{
 var latLon
 latLon = stationData.split(";")[0]
 var latLong = new VELatLong(latLon.split(",")[0],latLon.split(",")[1]);
 map.SetCenter(latLong)
 makeNewMarker(stationData,type)
}

function makeNewMarker(stationData,type)
{
 var latLon
 latLon = stationData.split(";")[0]
 pushPinClosed = "no"
 var labelLine1
 labelLine1 = stationData.split(";")[1]
 var labelLine2
 labelLine2 = ""
 var labelLine3
 labelLine3 = ""

 if(type == "customMarker")
 { 
  labelLine2 = stationData.split(";")[2]
  labelLine3 = stationData.split(";")[3]
 }

 var markerColor
 markerColor = MC
 var LineList = ""
 if(type == "station")
 {
  LineList = stationData.split(";")[3]
  labelLine2 = "Station"
  labelLine3 = LineList
  markerColor = 1
 }
 if(type == "landmark")
 { 
  labelLine2 = stationData.split(";")[2]
  markerColor = 0
 }
 if(type == "addressFinder")
 { 
  labelLine2 = stationData.split(";")[2]
  markerColor = 2
 }

  labelLine1 = labelLine1.replace(/x_x/g, ";")
  labelLine1 = labelLine1.replace(/__/g, "_")
  labelLine1 = labelLine1.replace(/:/g, "&#58;")
  labelLine1 = labelLine1.replace(/'/g, "&#39;")
  labelLine1 = labelLine1.replace(/"/g, "&#34;")
  labelLine1 = labelLine1.replace(/,/g, ".")
  labelLine1 = labelLine1.replace(/!/g, "&#33;")
  labelLine1 = labelLine1.replace(/\|/g, "&#124;")
  //labelLine1 = labelLine1.replace(/;/g, "&#59;")


  labelLine2 = labelLine2.replace(/x_x/g, ";")
  labelLine2 = labelLine2.replace(/__/g, "_")
  labelLine2 = labelLine2.replace(/:/g, "&#58;")
  labelLine2 = labelLine2.replace(/'/g, "&#39;")
  labelLine2 = labelLine2.replace(/"/g, "&#34;")
  labelLine2 = labelLine2.replace(/,/g, ".")
  labelLine2 = labelLine2.replace(/!/g, "&#33;")
  labelLine2 = labelLine2.replace(/\|/g, "&#124;")
  //labelLine2 = labelLine2.replace(/;/g, "&#59;")

  labelLine3 = labelLine3.replace(/x_x/g, ";")
  labelLine3 = labelLine3.replace(/__/g, "_")
  labelLine3 = labelLine3.replace(/:/g, "&#58;")
  labelLine3 = labelLine3.replace(/'/g, "&#39;")
  labelLine3 = labelLine3.replace(/"/g, "&#34;")
  labelLine3 = labelLine3.replace(/,/g, ".")
  labelLine3 = labelLine3.replace(/!/g, "&#33;")
  labelLine3 = labelLine3.replace(/\|/g, "&#124;")
  //labelLine3 = labelLine3.replace(/;/g, "&#59;")

 document.getElementById("pushPinLabel").innerHTML = "<nobr>" + labelLine1 + labelLine2 + labelLine3 + "</nobr>"
 var W
 var H
 H = document.getElementById("pushPinTemplate").clientHeight
 W = document.getElementById("pushPinTemplate").clientWidth
 if(centerOnMarker == "False" || itineraryFormOn == "no")
 {
 AddPushPin(latLon.split(",")[0],latLon.split(",")[1],labelLine1,labelLine2,labelLine3,markerColor,type,LineList)
 }
}

function addressFinder(coordinateString)
{
 hideAddressFinder2()
 var lat
 var lon
 var text1
 var text2
 var text3
 lat = coordinateString.split(",")[0]
 lon = coordinateString.split(",")[1]
 text1 = coordinateString.split(",")[2]
 text2 = coordinateString.split(",")[3]
 text3 = coordinateString.split(",")[4]
 var locationString
 locationString = ""
 locationString = locationString + lat
 locationString = locationString + ","
 locationString = locationString + lon
 locationString = locationString + ";"
 locationString = locationString + text1
 locationString = locationString + " "
 locationString = locationString + text2
 locationString = locationString + ";"
 locationString = locationString + " "
 locationString = locationString + ";"
 panToLocation(locationString, "addressFinder")
}

function showAddressList(list)
{
 document.getElementById("addressSelect").innerHTML = list
 document.getElementById("ambibousAddress").style.display = "inline"
}

function positionCrosshairs()
{
 document.getElementById("customMarker").style.left = parseInt((pageWidth()/2)-(document.getElementById("customMarker").clientWidth/2))+2 + "px"
 document.getElementById("customMarker").style.top = parseInt((pageHeight()/2)-(document.getElementById("customMarker").clientHeight + document.getElementById('customMarkerText').clientHeight)/2)-5 + "px"
 document.getElementById("getCoordinates").style.left = parseInt((pageWidth()/2)-(document.getElementById("getCoordinates").clientWidth/2))+2 + "px"
 document.getElementById("getCoordinates").style.top = parseInt((pageHeight()/2)-(document.getElementById("getCoordinates").clientHeight + document.getElementById('getCoordinatesText').clientHeight)/2)-5 + "px"
}

function setCustomMarker(L1,L2,L3)
{
 if(L1 == "")
 {
 alert("Label Line 1 cannot be blank")
 }
 else
 {
 var l
 l = parseInt(document.getElementById("customMarker").style.left)+175
 var t
 t = parseInt(document.getElementById("customMarker").style.top)+262
 var pixel  = new VEPixel(l, t);
 var lat
 var lon
 lat = map.PixelToLatLong(pixel).Latitude;
 lon = map.PixelToLatLong(pixel).Longitude;
 var ml1
 ml1 = L1
 ml1 = ml1.replace(/!/g, "&#33;")
 ml1 = ml1.replace(/\|/g, "&#124;")
 ml1 = ml1.replace(/:/g, "&#58;")
 ml1 = ml1.replace(/_/g, "__")
 ml1 = ml1.replace(/;/g, "x_x")


 var ml2
 ml2 = L2
 ml2 = ml2.replace(/!/g, "&#33;")
 ml2 = ml2.replace(/\|/g, "&#124;")
 ml2 = ml2.replace(/:/g, "&#58;")
 ml2 = ml2.replace(/_/g, "__")
 ml2 = ml2.replace(/;/g, "x_x")


 var ml3
 ml3 = L3
 ml3 = ml3.replace(/!/g, "&#33;")
 ml3 = ml3.replace(/\|/g, "&#124;")
 ml3 = ml3.replace(/:/g, "&#58;")
 ml3 = ml3.replace(/_/g, "__")
 ml3 = ml3.replace(/;/g, "x_x")


 makeNewMarker(lat + "," + lon + ";" + ml1 + ";" + ml2 + ";" + ml3, "customMarker")
 hidecustomMarker()
 }
}

function getTripPlan()
{
 if(document.forms["tripPlanner2"].elements["originCoordinates"].selectedIndex == document.forms["tripPlanner2"].elements["destinationCoordinates"].selectedIndex)
 {
  alert("The origin and destination cannot be the same.")
 }
 else
 {
  if(!document.forms["tripPlanner2"].elements["xmodeR"].checked && !document.forms["tripPlanner2"].elements["xmodeB"].checked && !document.forms["tripPlanner2"].elements["xmodeX"].checked)
  {
   alert("You must select at least one mode of travel. Subway, Local Bus, or Express Bus")
  }
  else
  {
   showTripPlannerDiv()
   if(window.frames["tripPlannerIFrame"].document.getElementById('slider1'))
   {
   window.frames["tripPlannerIFrame"].start()
   }
   document.forms["tripPlanner2"].submit()
  }
 }
}

function hidecustomMarker()
{
 document.getElementById("customMarker").style.visibility = "hidden"
}

function showCustomMarker()
{
 document.getElementById("customMarker").style.visibility = "visible"
 document.forms['stationLocator'].elements['customMarkerLabel1'].value = ""
 document.forms['stationLocator'].elements['customMarkerLabel2'].value = ""
 document.forms['stationLocator'].elements['customMarkerLabel3'].value = ""
 positionCrosshairs()
}

function quickShrinkTripPlannerDiv()
{
 shrinkTripPlannerDiv()
}

function expandTripPlannerDiv(i)
{
 var j
 if(i==0)
 {
  centerTripPlannerDiv()
  j = i + 1
  expandTripPlannerDiv(j)
 }
 else
 {
  expandTripPlannerDivWidth(i)
  expandTripPlannerDivHeight(i)
  j = i + 10
  if(j < 300)
  {
   setTimeout("expandTripPlannerDiv(" + j + ")",5)
  }
  else
  {
   document.getElementById("tripPlannerIFrame").style.visibility="visible"
  }
 }
}

function centerTripPlannerDiv()
{
 quickCloseTripPlannerForm()
 document.getElementById("tripPlannerIFrame").style.visibility="hidden"
 document.getElementById("tripPlannerDiv").style.backgroundColor="white"
 document.getElementById("tripPlannerDiv").style.border = "solid blue 5px"
}

function shrinkTripPlannerDiv()
{
 document.getElementById("tripPlannerIFrame").style.visibility = "hidden"
 document.getElementById("tripPlannerDiv").style.width = "200px"
 document.getElementById("tripPlannerDiv").style.height = "100px"
 document.getElementById("tripPlannerDiv").style.left = "150px"
 document.getElementById("tripPlannerDiv").style.top = "150px"
}

function closeTripPlannerDiv()
{
 window.frames["tripPlannerIFrame"].location.replace("mapTripPlannerSplash.html")
 document.getElementById("tripPlannerDiv").style.visibility="hidden";
 document.getElementById("tripPlannerIFrame").style.visibility="hidden"
}

function hideTripPlannerDiv()
{
 document.getElementById("tripPlannerDiv").style.visibility="hidden";
 document.getElementById("tripPlannerIFrame").style.visibility="hidden"
}

function showTripPlannerDiv()
{
 document.getElementById("tripPlannerDiv").style.visibility="visible";
 document.getElementById("tripPlannerIFrame").style.visibility="visible";
 setTimeout("quickCloseTripPlannerForm()",100)
}


function getCoordinates()
{
 var lat
 var lon
 lat = map.GetCenter().Latitude.toString().substr(0,9)
 lon = map.GetCenter().Longitude.toString().substr(0,10)
 return lat + "," + lon
}

function saveMap()
{
 if(logInUser == "")
 {
  openCanNotSaveDiv()
 }
 else
 {
  document.forms["saveMapForm"].elements["zoomLevel"].value = map.GetZoomLevel()
  document.forms["saveMapForm"].elements["centerLat"].value = map.GetCenter().Latitude
  document.forms["saveMapForm"].elements["centerLon"].value = map.GetCenter().Longitude
  document.forms["saveMapForm"].elements["mapStyle"].value = map.GetMapStyle()
  document.forms["saveMapForm"].elements["subwayRoutes"].value = subLayer
  document.forms["saveMapForm"].elements["subwayLabels"].value = labelLayer
  document.forms["saveMapForm"].elements["userID"].value = logInUser
  document.forms["saveMapForm"].elements["mapMarkers"].value = markers.join("::")
  document.forms["saveMapForm"].submit()
 }
}

function centerDiv(e)
{
 e.style.left = (pageWidth()/2) - (parseInt(e.clientWidth)/2) + "px"
 e.style.top = (pageHeight()/2) - (parseInt(e.clientHeight)/2) + "px"
}

function logIn()
{
 if(logInUser == "")
 {
  document.getElementById('logInDiv').style.display='inline'
  centerDiv(document.getElementById('logInDiv'))
 }
 else
 {
  var logOutUser
  logOutUser = logInUserEmailAddress
  logInUser = ""
  logInUserEmailAddress = ""
  makeLogInButton()
  openConfirmLogOutDiv(logOutUser)
 }
}

function email()
{
 document.getElementById('emailDiv').style.display='inline'
 centerDiv(document.getElementById('emailDiv'))
 document.forms["emailForm"].elements["senderName"].value = logInName
}

function contactUs()
{
 document.getElementById('contactUsDiv').style.display='inline'
 centerDiv(document.getElementById('contactUsDiv'))
 document.forms["contactUsForm"].elements["senderName"].value = logInName
 document.forms["contactUsForm"].elements["emailAddress"].value = logInUserEmailAddress
}

function closeEmailForm()
{
 document.getElementById('emailDiv').style.display='none'
 document.forms["emailForm"].elements["senderName"].value = ""
 document.forms["emailForm"].elements["emailAddress"].value = ""
 document.forms["emailForm"].elements["message"].value = ""
}

function closeContactUsForm()
{
 document.getElementById('contactUsDiv').style.display='none'
 document.forms["contactUsForm"].elements["senderName"].value = ""
 document.forms["contactUsForm"].elements["emailAddress"].value = ""
 document.forms["contactUsForm"].elements["message"].value = ""
}

function submitEmailForm()
{
 if(document.forms["emailForm"].elements["emailAddress"].value.length < 5 || document.forms["emailForm"].elements["emailAddress"].value.indexOf("@") < 1)
 {
  alert("Enter an email address")
 }
 else
 {
  var markersString
  document.forms["emailForm"].elements["zoomLevel"].value = map.GetZoomLevel()
  document.forms["emailForm"].elements["centerLat"].value = map.GetCenter().Latitude
  document.forms["emailForm"].elements["centerLon"].value = map.GetCenter().Longitude
  document.forms["emailForm"].elements["mapStyle"].value = map.GetMapStyle()
  document.forms["emailForm"].elements["subwayRoutes"].value = subLayer
  document.forms["emailForm"].elements["subwayLabels"].value = labelLayer
  markersString = markers.join("::")
  if(markersString == "deleted")
  {
   markersString = ""
  }
  markersString = markersString.replace(/::deleted/g, "")
  markersString = markersString.replace(/deleted::/g, "")
  document.forms["emailForm"].elements["mapMarkers"].value = markersString
  document.forms["emailForm"].submit()
 }
}

function submitContactUsForm()
{
 if(document.forms["contactUsForm"].elements["message"].value == "")
 {
  alert("Message cannot be empty")
 }
 else
 {
  document.forms["contactUsForm"].submit()
 }
}

function clearLogInForm()
{
document.forms["loginForm"].elements["emailAddress"].value = ""
document.forms["loginForm"].elements["password"].value = ""
document.forms["registerForm"].elements["emailAddress"].value = ""
document.forms["registerForm"].elements["password"].value = ""
document.forms["registerForm"].elements["name"].value = ""
}

function submitNewRegistration()
{
 if(validateNewRegistrationForm())
 {
  document.forms["registerForm"].submit()
 }
}

function validateNewRegistrationForm()
{

if(document.forms["registerForm"].elements["emailAddress"].value.length < 5 || document.forms["registerForm"].elements["emailAddress"].value.indexOf("@") < 1)
{
alert("Invalid email address. Please re-enter and try again")
return false
}
if(document.forms["registerForm"].elements["name"].value.length < 1)
{
alert("Name cannot be blank")
return false
}
if(document.forms["registerForm"].elements["password"].value.length < 6)
{
alert("Password must be at least 6 characters")
return false
}

return true

}

function openLogInGetMapMessageDiv()
{
 document.getElementById("logInGetMapMessageDiv").style.display = "inline"
 centerDiv(document.getElementById('logInGetMapMessageDiv'))
 showAccountSettingMenuOption()
 showUserLabel()
}

function loadSavedMap()
{
 logInIframe.loadSavedMap()
 closeLogInGetMapMessageDiv()
 hideAccountSettingDiv()
}

function closeLogInGetMapMessageDiv()
{
 document.getElementById("logInGetMapMessageDiv").style.display = "none"
}

function openLogInSuccessMessageDiv()
{
 document.getElementById("logInSuccessMessageDiv").style.display = "inline"
 centerDiv(document.getElementById('logInSuccessMessageDiv'))
 showAccountSettingMenuOption()
 showUserLabel()
}



function closeLogInSuccessMessageDiv()
{
 document.getElementById("logInSuccessMessageDiv").style.display = "none"
}

function openLogInFailedMessageDiv()
{
 document.getElementById("logInFailedMessageDiv").style.display = "inline"
 centerDiv(document.getElementById('logInFailedMessageDiv'))
}

function closeLogInFailedMessageDiv()
{
 document.getElementById("logInFailedMessageDiv").style.display = "none"
}

function openCanNotSaveDiv()
{
 document.getElementById("canNotSaveDiv").style.display = "inline"
 centerDiv(document.getElementById('canNotSaveDiv'))
}

function closetestdiv()
{
 document.getElementById("testdiv").style.display = "none"
}

function closeCanNotSaveDiv()
{
 document.getElementById("canNotSaveDiv").style.display = "none"
}

function openConfirmSavedDiv()
{
 hideAccountSettingDiv()
 document.getElementById("confirmSavedMessageTxt").innerHTML = "Your map settings have been saved to account: " + logInUserEmailAddress
 document.getElementById("confirmSavedDiv").style.display = "inline"
 centerDiv(document.getElementById('confirmSavedDiv'))
}

function closeConfirmSavedDiv()
{
 document.getElementById("confirmSavedDiv").style.display = "none"
}


function openConfirmLogOutDiv(emailAddress)
{
 document.getElementById("confirmLogOutMessageTxt").innerHTML = "Logged Out: " + emailAddress
 document.getElementById("confirmLogOutDiv").style.display = "inline"
 centerDiv(document.getElementById('confirmLogOutDiv'))
 hideAccountSettingMenuOption()
 hideUserLabel()
 logInUser = ""
 logInUserEmailAddress = ""
 logInName = ""
}

function closeConfirmLogOutDiv()
{
 document.getElementById("confirmLogOutDiv").style.display = "none"
}

function openConfirmRegistrationDiv(name,emailAddress)
{
 //makeLogOutButton()
 document.getElementById("confirmRegistrationMessageTxt").innerHTML = "A confirmation email has been sent to:<br />" + emailAddress + "<br /><br />Follow the instructions in that email to complete your registration.<br />You can then log-in and save your map setting."
 document.getElementById("confirmRegistrationDiv").style.display = "inline"
 centerDiv(document.getElementById('confirmRegistrationDiv'))
}


function registrationNotYetConfirmed(emailAddress)
{
 document.getElementById("RegistrationNotYetConfirmedDiv").style.display = "inline"
 centerDiv(document.getElementById('RegistrationNotYetConfirmedDiv'))
 document.getElementById('logInDiv').style.display='none'
 document.forms["resendRegistrationConfirmationForm"].elements["emailAddress"].value = emailAddress
}

function showLineMapDiv(line)
{
if(line != 0)
{
hideLineMapSelector2();
document.getElementById("lineMapDiv").style.height = (pageHeight() - 50) + "px";
document.getElementById("lineMapIframe").style.height = (pageHeight() - 74) + "px";
document.getElementById("lineMapDiv").style.visibility = "visible";
window.frames["lineMapIframe"].location.href="lineMaps/" + line + "" ;
}

}


function hideLineMapDiv()
{
document.getElementById("lineMapIframe").src = "lineMaps/loadingLineMap.htm"
document.getElementById("lineMapDiv").style.visibility = "hidden"
}


function showHowToUseDiv()
{
document.getElementById("howToUseDiv").style.display = "inline"
document.getElementById("howToUseDiv").style.height = (pageHeight() - 50) + "px"
document.getElementById("howToUseIframe").style.height = (pageHeight() - 74) + "px"
}

function hideHowToUseDiv()
{
document.getElementById("howToUseDiv").style.display = "none"
}



function closeRegistrationNotYetConfirmedDiv()
{
 document.getElementById("RegistrationNotYetConfirmedDiv").style.display = "none"
}

function closeConfirmRegistrationDiv()
{
 document.getElementById("confirmRegistrationDiv").style.display = "none"
}

function openConfirmEmailSentDiv(recipient)
{
document.getElementById("confirmEmailSentMessageTxt").innerHTML = "This map view has been sent to:  <br />" + recipient
document.getElementById("confirmEmailSentDiv").style.display = "inline"
centerDiv(document.getElementById('confirmEmailSentDiv'))
}

function openConfirmContactUsSentDiv()
{
document.getElementById("confirmContactUsSentDiv").style.display = "inline"
centerDiv(document.getElementById('confirmContactUsSentDiv'))
}

function closeConfirmEmailSentDiv()
{
 document.getElementById("confirmEmailSentDiv").style.display = "none"
}

function closeConfirmContactUsSentDiv()
{
 document.getElementById("confirmContactUsSentDiv").style.display = "none"
}

function makeLogOutButton()
{
 document.getElementById("logInButton3").innerHTML = "&nbsp;LOGOUT&nbsp;"
}

function makeLogInButton()
{
 document.getElementById("logInButton3").innerHTML = "&nbsp;LOGIN&nbsp;"
}


//***************************************************
//***************************************************
//***************************************************


function sendForgottenPassword()
{
 if(document.forms["loginForm"].elements["emailAddress"].value.length < 5 || document.forms["loginForm"].elements["emailAddress"].value.indexOf("@") < 1)
 {
  alert("Enter an email address")
 }
 else
 {
  document.forms["forgotPasswordForm"].elements["emailAddress"].value = document.forms["loginForm"].elements["emailAddress"].value
  document.forms["forgotPasswordForm"].submit()
 }
}


function showAccountSettingMenuOption()
{
document.getElementById("accountSettingMenuOption").style.display = "none"
//document.getElementById("mapControls5").style.height = "235px"
}

function hideAccountSettingMenuOption()
{
document.getElementById("accountSettingMenuOption").style.display = "none"
document.getElementById("mapControls5").style.height = "205px"
}

function showAccountSettingDiv()
{
document.getElementById("accountSettingsDiv").style.display = "inline"
centerDiv(document.getElementById('accountSettingsDiv'))
document.forms["changeAccountSettingsForm"].elements["emailAddress"].value = logInUserEmailAddress
document.forms["changeAccountSettingsForm"].elements["name"].value = logInName
if(hasSavedMap)
{
document.getElementById("LoadSavedMapButton").style.display = "inline"
}
else
{
document.getElementById("LoadSavedMapButton").style.display = "none"
}
}

function hideAccountSettingDiv()
{
document.forms["changeAccountSettingsForm"].elements["emailAddress"].value = ""
document.forms["changeAccountSettingsForm"].elements["name"].value = ""
document.forms["changeAccountSettingsForm"].elements["password"].value = ""
document.getElementById("accountSettingsDiv").style.display = "none"
}

function showChangePasswordDiv()
{
hideAccountSettingDiv()
document.getElementById("changePasswordDiv").style.display = "inline"
centerDiv(document.getElementById('changePasswordDiv'))
document.forms["changePasswordForm"].elements["password"].value=""
document.forms["changePasswordForm"].elements["newPassword"].value=""
}

function hideChangePasswordDiv()
{
document.forms["changePasswordForm"].elements["password"].value=""
document.forms["changePasswordForm"].elements["newPassword"].value=""
hideAccountSettingDiv()
document.getElementById("changePasswordDiv").style.display = "none"
}

function confirmChangePasswordSuccessful()
{
hideChangePasswordDiv()
setTimeout("alert('Password has been changed.')",100)
}

function changeAccountSettings()
{
if(validateChangeAccountSettingsForm())
{
document.forms["changeAccountSettingsForm"].elements["UID"].value = logInUser
document.forms["changeAccountSettingsForm"].submit()
}
}

function changePassword()
{
if(validateChangePasswordForm())
{
document.forms["changePasswordForm"].elements["UID"].value = logInUser
document.forms["changePasswordForm"].submit()
}
}


function changedAccountSettingsSuccessful(name,emailAddress)
{
logInUserEmailAddress = emailAddress
logInName = name
hideAccountSettingDiv()
showUserLabel()
alert("Account Update Successful")
}

function validateChangePasswordForm()
{
if(document.forms["changePasswordForm"].elements["password"].value.length < 6)
{
alert("Password must be at least 6 characters")
return false
}

if(document.forms["changePasswordForm"].elements["newPassword"].value.length < 6)
{
alert("New Password must be at least 6 characters")
return false
}
return true
}


function validateChangeAccountSettingsForm()
{

if(document.forms["changeAccountSettingsForm"].elements["emailAddress"].value.length < 5 || document.forms["changeAccountSettingsForm"].elements["emailAddress"].value.indexOf("@") < 1)
{
alert("Invalid email address. Please re-enter and try again")
return false
}
if(document.forms["changeAccountSettingsForm"].elements["name"].value.length < 1)
{
alert("Name cannot be blank")
return false
}
if(document.forms["changeAccountSettingsForm"].elements["password"].value.length < 6)
{
alert("Password must be at least 6 characters")
return false
}
return true
}

function showUserLabel()
{
document.getElementById("userNameLabel").innerHTML = "<nobr>&nbsp;&nbsp;Logged-in: " + logInName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + logInUserEmailAddress + "&nbsp;&nbsp;</nobr>"
document.getElementById("userNameLabel").style.display = "inline"
}

function hideUserLabel()
{
document.getElementById("userNameLabel").innerHTML = "<nobr>Logged-in:</nobr>"
document.getElementById("userNameLabel").style.display = "none"
}








//***************************************************
//***************************************************
//***************************************************









//validate address functions
//****************************************************************
function validateAddress()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkLocationFields())
 {
  submitForm2()
 }
}

function submitForm2()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkDirectionalWords())
 {
  submitForm3()
 }
 else
 {
  openMessageWindow()
 }
}

function submitForm3()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkIntersectionWords())
 {
  document.forms["stationLocator"].submit()
 }
 else
 {
  openMessageWindow()
 }
}

function removeInvalidCharacterStrings()
{
 var trimmedOriginInput
 trimmedOriginInput = document.forms["stationLocator"].elements["address"].value
 trimmedOriginInput = trimmedOriginInput.replace(/\\/g, '')
 trimmedOriginInput = trimmedOriginInput.replace(/ /g, '')
 if(trimmedOriginInput == "")
 {
 document.forms["stationLocator"].elements["address"].value = ""
 }
}

function checkLocationFields()
{
if(document.forms["stationLocator"].elements["address"].value != "")
   {
   return true
   }
else
   {
   alert("Enter an address, intersection or place name")
   return false
   }
}

function checkDirectionalWords()
{
 var addressInput
 addressInput = " " + document.forms["stationLocator"].elements["address"].value + " "
 if(addressInput.toLowerCase().indexOf(" west ") != -1 || addressInput.toLowerCase().indexOf(" north ") != -1 || addressInput.toLowerCase().indexOf(" east ") != -1  || addressInput.toLowerCase().indexOf(" south ") != -1)
 {
  var messageHTML
  messageHTML = ""
  messageHTML = messageHTML + '<div style="padding:10px; text-align:left; font-size:12px">When the words "North", "East", "South" and "West" are used as a prefix or suffix to a street name, the abbreviated form "N", "E", "W" or "S"  must be used.<br /><br />SEE EXAMPLES BELOW:'
  messageHTML = messageHTML + '<br /><br /><span style="color:red; font-size:14px; font-weight:bold; font-family:arial">WRONG:<br />EAST 72ND STREET <img src="../../images/redXMark.gif" alt="red X mark" /><br />CENTRAL PARK WEST <img src="../../images/redXMark.gif" alt="red X mark" /></span><br /><br /><span style="color:green; font-size:14px; font-weight:bold; font-family:arial;">RIGHT:<br />E 72ND STREET <img src="../../images/greenCheckMark.gif" alt="green check mark" /><br />CENTRAL PARK W <img src="../../images/greenCheckMark.gif" alt="green check mark" /></span>'
  messageHTML = messageHTML + '<br /><br />However when used as part of the proper name as in "SOUTH STREET SEAPORT"<br /> or "WEST STREET" use the full word.'
  messageHTML = messageHTML + '<br /><br />How do you want to proceed?'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:300px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Automatically convert to abbrievated format and submit" onclick="javascript:fixAndSubmit()">'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:180px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Leave it as I typed it and submit" onclick="javascript:leaveAndSubmit()">'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:320px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Close this message. I will check my address and try again." onclick="javascript:closeMessageWindow()"></div>'

  document.getElementById("messageDiv").innerHTML = messageHTML
  return false
 }
 else
 {
  return true
 }
}

function checkIntersectionWords()
{
 var addressInput
 addressInput = " " + document.forms["stationLocator"].elements["address"].value + " "
 if(addressInput.toLowerCase().indexOf(" and ") != -1 || addressInput.toLowerCase().indexOf(" at ") != -1)
 {
  var messageHTML
  messageHTML = ""
  messageHTML = messageHTML + '<div style="padding:10px; text-align:left; font-size:12px">To indicate an intersection use the "&" or "@" symbols in place of the words "AND" or "AT".<br /><br />SEE EXAMPLES BELOW:'
  messageHTML = messageHTML + '<br /><br /><span style="color:red; font-size:14px; font-weight:bold; font-family:arial;">WRONG:<br />E 42ND STREET AND 3RD AVE <img src="../../images/redXMark.gif" alt="red X mark" /><br />E 42ND STREET AT 3RD AVE <img src="../../images/redXMark.gif" alt="red X mark" /></span><br /><br /><span style="color:green; font-size:14px; font-weight:bold; font-family:arial;">RIGHT:<br />E 42ND STREET & 3RD AVE <img src="../../images/greenCheckMark.gif" alt="green check mark" /><br />E 42ND STREET @ 3RD AVE <img src="../../images/greenCheckMark.gif" alt="green check mark" /></span>'
  messageHTML = messageHTML + '<br /><br />How do you want to proceed?'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:300px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Automatically convert to proper intersection format and submit" onclick="javascript:fixAndSubmit2()">'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:180px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Leave it as I typed it and submit" onclick="javascript: leaveAndSubmit2()">'
  messageHTML = messageHTML + '<br /><br /><input style="cursor:pointer; font-size:10px; font-weight:bold; width:320px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Close this message window. I will check my inputs and try again." onclick="javascript:closeMessageWindow()"></div>'

  document.getElementById("messageDiv").innerHTML = messageHTML
  return false
 }
 else
 {
  return true
 }
}

function openMessageWindow()
{
 document.getElementById("messageDiv").style.visibility = "visible"
}

function closeMessageWindow()
{
 document.getElementById("messageDiv").style.visibility = "hidden"
}

function fixAndSubmit()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 var correctedInput
 correctedInput = "%%% " + document.forms["stationLocator"].elements["address"].value + " %%%"
 correctedInput = correctedInput.toUpperCase().replace(/ WEST /g, ' W ')
 correctedInput = correctedInput.toUpperCase().replace(/ EAST /g, ' E ')
 correctedInput = correctedInput.toUpperCase().replace(/ NORTH /g, ' N ')
 correctedInput = correctedInput.toUpperCase().replace(/ SOUTH /g, ' S ')
 correctedInput = correctedInput.toUpperCase().replace(/%%% /g, '')
 correctedInput = correctedInput.toUpperCase().replace(/ %%%/g, '')
 document.forms["stationLocator"].elements["address"].value = correctedInput
 closeMessageWindow()
 submitForm3()
}

function fixAndSubmit2()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 var correctedInput
 correctedInput = "%%% " + document.forms["stationLocator"].elements["address"].value + " %%%"
 correctedInput = correctedInput.toUpperCase().replace(/ AND /g, ' & ')
 correctedInput = correctedInput.toUpperCase().replace(/ AT /g, ' @ ')
 correctedInput = correctedInput.toUpperCase().replace(/%%% /g, '')
 correctedInput = correctedInput.toUpperCase().replace(/ %%%/g, '')
 document.forms["stationLocator"].elements["address"].value = correctedInput
 closeMessageWindow()
 document.forms["stationLocator"].submit()
}

function leaveAndSubmit()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 closeMessageWindow()
 submitForm3()
}


function leaveAndSubmit2()
{
 document.forms["stationLocator"].elements["address"].value = document.forms["stationLocator"].elements["address"].value.replace(/"/g, '')
 closeMessageWindow()
 document.forms["stationLocator"].submit()
}


/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};



//********************************************************************
//Functions that handle the subway route and station label overlays
//**********************************************************************


var map = null;
var subLayer = "no"
var labelLayer = "no"
var disableLableButton = "false"
var disableRouteButton = "false"
var routeButtonOn = "yes"
var labelButtonOn = "yes"



function showHideSubRoutes(IsOnLoad)
{

    if(map.GetZoomLevel() > 15 && !subwayMapVisible)
    {
    map.SetZoomLevel(15)
    }

    if(map.GetZoomLevel() < 14 && !subwayMapVisible)
    {
    map.SetZoomLevel(14)
    }


    if(document.getElementById("subRouteButton3").innerHTML.indexOf("Show") > -1)
    {subwayMapSelected = true
     if (!subwayMapOn)
     {
     GetRouteLayers()
     subwayMapVisible = true 
     if(!stationLabelsOn)
     {GetLabelLayers()}
     else {ShowLabelLayers()}
     }
     else
     {
      showRouteLayers()
      subwayMapVisible = true
     if(!stationLabelsOn)
     {GetLabelLayers()}
     else {ShowLabelLayers()}
     }
     
     document.getElementById("subRouteButton3").innerHTML = "&nbsp;Hide Subway Map&nbsp;"
     document.getElementById("subRouteButton3").innerHTML = "&nbsp;Hide Subway Map&nbsp;"
     document.getElementById("subLabelButton3").style.display = "inline";
     document.getElementById("subLabelButton3").style.display = "inline";
     document.getElementById("showAccessibleStationsButtonDiv1").style.display = "inline";
     
     subLayer = "yes"
     labelLayer = "yes"
     labelButtonOn = "yes"
     routeButtonOn = "yes"
    }
    else
    {
     subwayMapSelected = false
     DeleteTileLayer()
     subwayMapVisible = false 
     labelButtonOn = "no"
     routeButtonOn = "no"
    }
}



function GetRouteLayers()
{
     GetRouteTiles("Sub", "http://tripplanner.mta.info/maps/SystemRoutes/%4.png", "3",  20, 40.92862373397717,-74.28397178649902,40.48801936882241,-73.68182659149171)
 }

function showRouteLayers()
{
     map.ShowTileLayer("Sub");
     subwayMapOn = true
}



function GetLabelLayers()
{
   GetLabelTiles("subLabels", "http://tripplanner.mta.info/maps/subwayLabels/%4.png?709", "9", 25,  40.92862373397717,-74.28397178649902,40.48801936882241,-73.68182659149171)
  }



function showHideSubLabels(IsOnLoad)
{
    if(document.getElementById("HideLabelsText").innerHTML.indexOf("Show") > -1 && disableLableButton == "false")
    {
        if (IsOnLoad == "onLoad")
        {
            GetLabelLayers()
        }
        else
        {
            ShowLabelLayers()
        }
         document.getElementById("HideLabelsText").innerHTML = "&nbsp;Hide labels&nbsp;"
         labelLayer = "yes"
         labelButtonOn = "yes"
        }
    else
    {
         DeleteLabelLayer()
         labelButtonOn = "no"
    }
}




function removeRouteLayers()
{    
     map.HideTileLayer("Sub");
     //subwayMapOn = false
}



function DeleteTileLayer()
{
    if(subLayer == "yes")
    {
    removeRouteLayers()

  DeleteLabelLayer()
    }
    subLayer = "no"
    document.getElementById("subRouteButton3").innerHTML = "&nbsp;Show Subway Map&nbsp;"
    document.getElementById("HideLabelsText").innerHTML = "&nbsp;Hide labels&nbsp;"
    document.getElementById("subLabelButton3").style.display = "none"
    document.getElementById("showAccessibleStationsButtonDiv1").style.display = "none";
//    document.getElementById("showAccessibleStationsButtonDiv2").style.display = "none";
    //document.getElementById("showAdvisoryStationsButtonDiv1").style.display = "none";
//    document.getElementById("showAdvisoryStationsButtonDiv2").style.display = "none";
    
    hideAccessiblePushpins()
    //hideadvisoryPushpins()
} 


function GetRouteTiles(ID, Source, layerNumber, zIndex, lat1,lon1,lat2,lon2)
{   
    var tileSource = new VETileSourceSpecification(ID, Source);
    tileSource.Bounds = new Array();
    tileSource.Bounds[0] = new VELatLongRectangle(new VELatLong(lat1,lon1),new VELatLong(lat2,lon2))
    tileSource.MinZoomLevel = 13;
    tileSource.MaxZoomLevel = 15;
    tileSource.Opacity = 1.0;
    tileSource.ZIndex = zIndex;
    map.AddTileLayer(tileSource, true);
    subwayMapOn = true
}



function GetLabelTiles(ID, Source, layerNumber, zIndex, lat1,lon1,lat2,lon2)
{   
    var tileSource = new VETileSourceSpecification(ID, Source);
    tileSource.Bounds = new Array();
    tileSource.Bounds[0] = new VELatLongRectangle(new VELatLong(lat1,lon1),new VELatLong(lat2,lon2))
    tileSource.MinZoomLevel = 14;
    tileSource.MaxZoomLevel = 15;
    tileSource.Opacity = 1.0;
    tileSource.ZIndex = zIndex;
    map.AddTileLayer(tileSource, true);
    stationLabelsOn = true
}



function removeLabelLayers()
{     
     map.HideTileLayer("subLabels");
     
 
}

function ShowLabelLayers()
{
 
     map.ShowTileLayer("subLabels");
   
}


function DeleteLabelLayer()
{
    if(labelLayer == "yes")
    {
    removeLabelLayers()
    labelLayer = "no"
    document.getElementById("HideLabelsText").innerHTML = "&nbsp;Show labels&nbsp;"
    } 
}

function TemporaryRemoveLabelLayer()
{   
    if(labelLayer == "yes")
    {
     disableLableButton = "true"
     removeLabelLayers()
     labelLayer = "no"
     }
}

function restoreLabelLayers()
{
if(labelLayer == "no" && subLayer == "yes" && labelButtonOn == "yes")
{
GetLabelLayers()
disableLableButton = "false"
labelLayer = "yes"
}
}

function TemporaryRemoveSubwayRoutes()
{
    if(subLayer == "yes")
    {
     disableRouteButton = "true"
     removeRouteLayers()
     subLayer = "no"
     }
}


function restoreRouteLayers()
{
if(subLayer == "no" && routeButtonOn == "yes")
{
GetRouteLayers()
disableRouteButton = "false"
subLayer = "yes"
}
}


