﻿
var googleMap = null;

var MAP_MODE = "";

//var allLayers = new Array();
//allLayers[0] = "Incidents";
//allLayers[1] = "Construction";
//allLayers[2] = "Events";
//allLayers[3] = "Cameras";
//allLayers[4] = "Traffic";
//allLayers[5] = "Base Map";

var baseIcon = new GIcon();

var startIcon = new GIcon(baseIcon);
startIcon.image = "images/startflag.png";
startIcon.iconSize = new GSize(48, 48);
startIcon.iconAnchor = new GPoint(22, 52);

var endIcon = new GIcon(baseIcon);
endIcon.image = "images/endflag.png";
endIcon.iconSize = new GSize(48, 48);
endIcon.iconAnchor = new GPoint(22, 52)

var point;
var lat;
var lon;
var z;

var startMarker;
var endMarker;

var markerTooltip;
var infoWindowOpen;
var infoWindowClosed;
//var eventsFlag;
//var theCount = allLayers.length;
//var Markers1 = new Array();

var cLat = 32.908;
var cLon = -116.8190;
var cZoom = 10;

var curLat;
var curLon;
var clickedLat;
var clickedLon;

//var lPoints = [];

var DTMode = false;
var DTInfoFrom = false;
var DTInfoTo = false;
var DTFlag = false;

var htmlFrom = "";
var htmlTo = "";

var TRIP_ARR = new Array(); // defaultPath, pathOrder, startNodeID, endNodeID, LinkList
var LINK_LIST = "";

var NODE_FROM = "";
var CITY_FROM = "";
var START_NODE_LAT = 0;
var END_NODE_LAT = 0;
var START_NODE_LON = 0;
var END_NODE_LON = 0;
var START_NODE_ID = 0;
var END_NODE_ID = 0;

var ZOOM_LEVEL = 10;
var TT_FLAG = false;

var THEME_COLOR = "standard";

var startMarkerID = -1;
var endMarkerID = -1;

var southWestX = 0;
var southWestY = 0;
var northEastX = 0;
var northEastY = 0;

//* geoserver layers
var incFeatureType = "topp:vwIncident";
var constFeatureType = "topp:vwConstruction";
var eventFeatureType = "topp:vwEvent";
var camFeatureType = "topp:vwCamera";

var vwLink = "topp:vwLink";
var vwLink1 = "topp:vwLink1";
var vwLink2 = "topp:vwLink2";
var vwLink3 = "topp:vwLink3";
var vwLink15 = "topp:vwLink15";
var vwLink16 = "topp:vwLink16";

var vwLinkContrast = "topp:vwLinkContrast";
var vwLinkContrast1 = "topp:vwLinkContrast1";
var vwLinkContrast2 = "topp:vwLinkContrast2";
var vwLinkContrast3 = "topp:vwLinkContrast3";
var vwLinkContrast15 = "topp:vwLinkContrast15";
var vwLinkContrast16 = "topp:vwLinkContrast16";

var vwLinkDeutan = "topp:vwLinkDeutan";
var vwLinkDeutan1 = "topp:vwLinkDeutan1";
var vwLinkDeutan2 = "topp:vwLinkDeutan2";
var vwLinkDeutan3 = "topp:vwLinkDeutan3";
var vwLinkDeutan15 = "topp:vwLinkDeutan15";
var vwLinkDeutan16 = "topp:vwLinkDeutan16";

var vwLinkTritan = "topp:vwLinkTritan";
var vwLinkTritan1 = "topp:vwLinkTritan1";
var vwLinkTritan2 = "topp:vwLinkTritan2";
var vwLinkTritan3 = "topp:vwLinkTritan3";
var vwLinkTritan15 = "topp:vwLinkTritan15";
var vwLinkTritan16 = "topp:vwLinkTritan16";

var vwTripNodes = "topp:vwTripNodes";
var vwTripSelected = "topp:vwTripSelected";
var vwTripSelected1 = "topp:vwTripSelected1";
var vwTripSelected2 = "topp:vwTripSelected2";
var vwTripSelected3 = "topp:vwTripSelected3";
var vwIncidentDetail = "topp:vwIncidentDetail";
var vwConstructionDetail = "topp:vwConstructionDetail";
var vwEventDetail = "topp:vwEventDetail";
var vwShield9 = "topp:vwShield9";
var vwShield10 = "topp:vwShield10";
var vwShield11 = "topp:vwShield11";
var vwShield12 = "topp:vwShield12";

var vwGetAlerts = "topp:vwGetAlerts";

var alertBoxMessages = new Array();

var showShields = false;

var linkImage = null;
var eventImage = null;
var tripImage = null;

var ttLinkRequest = null;
var ttEventRequest = null;
var clickEventRequest = null;
var camRequest = null;
var alertRequest = null;

//* Geoserver ip address and port
var HOST_GEO_SERVER = "GEOSERVER_IP";
//var PORT = ":8080";
var PORT = ":PORT";

//* geoserver credentials
var UID = "admin"; 
var PWD = "geoserver"

var wOpenFlag = false;
var dtWindowON = false;
var divRefresh;
var divNorthArrow;
var dtCheckbox;
var statMapImage;

var STATIC_ZOOM = 9;
var STATIC_LAT = 33;
var STATIC_LON = -116.9990;

var REFRESH_RATE = "";
var timerID;

//var ALERT_MESSAGE = "";

var statMapImageSrc = "images/sdoverview.png";
//var statMapImageSrc = "C:/Inetpub/wwwroot/TF/images/sdoverview.png";

var blindBkgnd = "images/blueyellow_bkgrnd.png";
//var blindBkgnd = "D:/MDI/SD Public Web~kozikov/SD Public Web/511sdTraffic/web/images/blueyellow_bkgrnd.png";


function addMap(mode)
{                      
    
    REFRESH_RATE = document.getElementById("hidRefreshRate").value;
    //REFRESH_RATE="60"; //TESTTTTTTTTTTTTTTTTTTTTTT!

    if (REFRESH_RATE == 'undefined' || REFRESH_RATE == '')
        REFRESH_RATE="300"; 
    
    if (REFRESH_RATE == "-1")
        REFRESH_RATE = "";
    
    var opts = {
            suppressInitialResultSelection: true,
            showOnLoad: true
    };
    
    googleMap = new GMap2(document.getElementById("MapFrame"), 
                        { googleBarOptions: opts, draggableCursor: "auto", draggingCursor: "auto" });   
         
    googleMap.setCenter(new GLatLng(parseFloat(cLat), parseFloat(cLon)), parseInt(cZoom));

    googleMap.addControl(new GLargeMapControl3D());
    googleMap.addControl(new GMapTypeControl());

    var mt = googleMap.getMapTypes();
    for (var i = 0; i < mt.length; i++) {
        mt[i].getMinimumResolution = function() { return 8; }
        mt[i].getMaximumResolution = function() { return 16; }
    }
    
    // ========= Add Scale Control ===========
    googleMap.addControl(new GScaleControl());
    
    //  ======== Add a map overview ==========
    /* // minimize overview on map load
    var ov = new GOverviewMapControl(new GSize(200,200));              
    setTimeout(function() {
    googleMap.addControl(ov);
    ov.hide(true); }, 500);
    */      
    googleMap.addControl(new GOverviewMapControl(new GSize(200,200)));
               
                        
    //googleMap.enableScrollWheelZoom(); 
    
    /*
    GEvent.addListener(googleMap, "infowindowclose", function() { 
        alert("infowindowclose event"); 
    }); 
    */
    
    
    GEvent.addListener(googleMap.getInfoWindow(), 'closeclick', function () { 
        curLon = 0; 
        curLat = 0; 
        //alert("infowindowclose event");
    } );
    
    
    /*
    GEvent.addListener(googleMap.getInfoWindow(), 'click', function () { 
        //curLon = 0; 
        //curLat = 0; 
        alert("click event");
    } );
    */
       
    GEvent.addListener(googleMap, "mousemove", function(point) {                     
        curLat = point.lat();
        curLon = point.lng();       
                        
        if (TT_FLAG==false || document.getElementById("hdnFlag").value == "false")
        { 
            hideEventTooltip(); 
	        hideNodeTooltip();
	    }	    
	    
        //showEventTooltip(curLat, curLon, "");          
        setTimeout("showEventTooltip(curLat, curLon, '')", 300);         
              
    });   
    
    GEvent.addListener(googleMap, "click", function() {       
         //GLog.write(googleMap.getZoom() + ';' + curLat + ';' + curLon);      
               
         //if (wOpenFlag == false)
         if (dtWindowON == false)
         {  
            //GLog.write(curLon + ';' + curLat);         
            onEventClick(curLat, curLon, "info");  
         }                                                                                                          
                               
    });  
    
    GEvent.addListener(googleMap, "drag", function() {                          
        googleMap.getDragObject().setDraggingCursor("move");
        hideEventTooltip(); 
	    hideNodeTooltip();
    }); 
    
    GEvent.addListener(googleMap, "moveend", function() {                                                                                                
        var myFlag = false;      
        hideEventTooltip(); 
	    hideNodeTooltip(); 
	    
	    //***********************************************
	    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || 
	        navigator.userAgent.toLowerCase().indexOf("safari") > -1)
	    {
	        var bBox = googleMap.getBounds();       
            var southWest = bBox.getSouthWest();
            var northEast = bBox.getNorthEast();
                                    
            if (southWestX == southWest.x && southWestY == southWest.y && 
                northEastX == northEast.x && northEastY == northEast.y)
            {
                myFlag = true;
            }
            
            southWestX = southWest.x;
            southWestY = southWest.y;
            northEastX = northEast.x;
            northEastY = northEast.y;

            //GLog.write(southWest.x + ' ' + southWest.y + ',' + northEast.x + ' ' + northEast.y);
	    }
	    //***********************************************
	    
	    //setTimeout("showPleaseWaitScreen('')",100);   
	    if (wOpenFlag == false && myFlag == false)
	        showPleaseWaitScreen('');     
        
        if (ZOOM_LEVEL != googleMap.getZoom())
        {
            clearMap();            
        }
        
        if (myFlag == false)
        {
        setTimeout("addEventsToMap()", 200);             
        
        setTimeout("addDTMarkers()", 300);  
        }                      
        
        ZOOM_LEVEL = googleMap.getZoom();
        //GLog.write(ZOOM_LEVEL);
        
        refreshDateTimeStamp();          
                             
        //GLog.write(ALERT_MESSAGE);               
                                                   
    });    
    
    GEvent.addListener(googleMap, "mouseout", function() {       
             
        hideEventTooltip(); 
	    hideNodeTooltip();  	    	                                                                                                 
                               
    });    
        
    setChkDefaultValues();               
    
    dtCheckbox = window.frames['frameToolbar'].window.frames['TOCFrame'].document.forms['layers'].elements['DrivingTime'];   
    
    //* add points
    if (mode == "drivingtimes")
    {    
        DTMode = true;  
        parent.parent.document.getElementById("hdnDrivingTime").value=true;  
        dtCheckbox.checked = true;                      
    }
    else
    {         
        parent.parent.document.getElementById("hdnDrivingTime").value=false;                
        //alert(window.frames['frameToolbar'].window.frames['TOCFrame'].document.forms['layers'].elements['DrivingTime'].checked);
        
    }
    
    //* shows layers on map opening
    showEventLayers(getLayers(), "", "load"); 
    
    addNorthArrow();
    
    //* show alert ticker message if any
    getAlertMessage();    
                                                             
}

function addEventsToMap()
{
    showEventLayers(getLayers(), "", "");
}

function addDTMarkers()
{
    if (DTFlag == true && dtCheckbox.checked == true)
    {
        addStartMarker(START_NODE_LAT, START_NODE_LON);
        addEndMarker(END_NODE_LAT, END_NODE_LON);                    
    } 
    
    if (DTFlag == false && DTInfoFrom == true && DTInfoTo == false && dtCheckbox.checked == true)        
        addStartMarker(START_NODE_LAT, START_NODE_LON);
        
    hidePleaseWaitScreen();
}

function createStaicImage()
{          
    statMapImage = document.getElementById("staticMap"); 
      
    try 
	{			      
	    var Request = null;       	   	    	    		 				             
        
        if (Request == null)
        {                                            
          if(navigator.appName == "Microsoft Internet Explorer")              
              Request = new ActiveXObject("Msxml2.XMLHTTP");                            
          else         
              Request = new XMLHttpRequest();                                                                  
                                        
            		
  	      var pathUrl="/GSHandler/GSHandler/staticImage.ashx?zoom=" + STATIC_ZOOM + "&lat=" + STATIC_LAT + 
  	                    "&lon=" + STATIC_LON + "&layer=" + vwLink + "," + vwShield9 + "&ms=" + new Date().getTime();		                                                 
          //alert(pathUrl);               
          Request.open("GET", pathUrl, true);
           
          Request.onreadystatechange = function() {   
          
          if (Request != null)
          {
              if (Request.readyState == 4) { //alert(Request.status);
                if (Request.status == 200) {      //alert(Math.floor(Math.random()*101));                                                                  
                    //statMapImage.src = statMapImageSrc + "?" + Math.floor(Math.random()*101);                                                                                                                                                           
                    statMapImage.src = statMapImageSrc;                                                                                                                   
                    Request = null;   	               	                  	                          
                }             
              }
          }                             
        }              
        Request.send(null);                
        }                          							
	}
	catch (ee) {
		alert(ee.message);
		return;
	}    

}

function setChkDefaultValues()
{
    document.getElementById("hdnChkIncident").value = "true";
    document.getElementById("hdnChkConstr").value = "true";
    document.getElementById("hdnChkEvent").value = "true";
    document.getElementById("hdnChkCamera").value = "false";
    document.getElementById("hdnChkLink").value = "true";
    
    document.getElementById("hdnFlag").value = "false";
    
    //parent.document.getElementById("hidAlertMessage").value = "";
    //alert(document.getElementById("hidAlertMessage").value + ';' + parent.document.getElementById("hidAlertMessage").value);
    
}

function getLinkSelected()
{
    if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
        return vwTripSelected;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
        return vwTripSelected1;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
        return vwTripSelected2;
    else
        return vwTripSelected3;
}

function getLinkLayer()
{
    /*
    if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
        return vwLink;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
        return vwLink1;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
        return vwLink2;
    else
        return vwLink3;
    */
    
    
    if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
        return vwLink;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
        return vwLink1;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
        return vwLink2;        
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 14)    
        return vwLink3;
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 15)    
        return vwLink15;   
    else if (parseInt(parent.parent.ZOOM_LEVEL) == 16)    
        return vwLink16;     
    else
        return vwLink3;    
       
}

function getLinkLayerTheme(theme)
{
    /*
    switch (theme) {
		case "contrast":					
			if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkContrast;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkContrast1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkContrast2;
            else
                return vwLinkContrast3;			
			//break;
		case "deutan":			
			if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkDeutan;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkDeutan1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkDeutan2;
            else
                return vwLinkDeutan3;	
			//break;		
		default:
		    if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkTritan;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkTritan1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkTritan2;
            else
                return vwLinkTritan3;
    }
    */
    
    switch (theme) {
		case "contrast":					
			if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkContrast;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkContrast1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkContrast2;                
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 14)    
                return vwLinkContrast3;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 15)    
                return vwLinkContrast15;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 16)    
                return vwLinkContrast16;            
            else
                return vwLinkContrast3;			
			//break;
		case "deutan":			
			if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkDeutan;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkDeutan1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkDeutan2;                
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 14)    
                return vwLinkDeutan3;    
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 15)    
                return vwLinkDeutan15;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 16)    
                return vwLinkDeutan16;                       
            else
                return vwLinkDeutan3;	
			//break;		
		default:
		    if (parseInt(parent.parent.ZOOM_LEVEL) <= 11)
                return vwLinkTritan;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 12)    
                return vwLinkTritan1;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 13)    
                return vwLinkTritan2;                
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 14)    
                return vwLinkTritan3;    
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 15)    
                return vwLinkTritan15;
            else if (parseInt(parent.parent.ZOOM_LEVEL) == 16)    
                return vwLinkTritan16;        
            else
                return vwLinkTritan3;
    }	    
        
}

function getLayers()
{
    var ret = "";
    var shield = "";            
            
    if (document.getElementById("hdnChkLink").value == "true")
    {   
        
        var linkLayer = getLinkLayer();
        //GLog.write(lLayer);
    
        if (document.getElementById("hdnTheme").value == "" || document.getElementById("hdnTheme").value == "standard")
            ret = linkLayer;  
            //ret = vwLink;
        else
            ret = getColorTheme(document.getElementById("hdnTheme").value);
        
        //GLog.write(ret);    
        
        if (showShields == true)
        {    
        //* add highway shields
        if (googleMap.getZoom() == 10)
            shield = vwShield10;
        else if (googleMap.getZoom() == 11)
            shield = vwShield11;
        else if (googleMap.getZoom() == 12)
            shield = vwShield12;  
        }
        else
            shield = "";       
            
        if (shield != "")
        {
            if (ret != "")
                ret = ret + "," + shield;
            else
                ret = shield;  
        }  
    }      
                  
    if (document.getElementById("hdnChkCamera").value == "true")
    {
        if (ret != "")
            ret = ret + "," + camFeatureType;
        else
            ret = camFeatureType;
    }
        
    if (document.getElementById("hdnChkEvent").value == "true")
    {
        if (ret != "")
            ret = ret + "," + eventFeatureType;
        else
            ret = eventFeatureType;
    }           
       
    if (document.getElementById("hdnChkConstr").value == "true")
    {
        if (ret != "")
            ret = ret + "," + constFeatureType;
        else
            ret = constFeatureType;
    }       
    
    if (document.getElementById("hdnChkIncident").value == "true")
    {
        if (ret != "")
            ret = ret + "," + incFeatureType;
        else
            ret = incFeatureType;
    }  
       
    //alert('1=' + parent.parent.DTMode + ';' + DTMode + ';' + document.getElementById("hdnDrivingTime").value + ';' + parent.parent.document.getElementById("hdnDrivingTime").value);
    //alert('2=' + dtCheckbox.checked + ';' + DTMode + ';' + parent.parent.DTMode);
    //if (DTMode == true || parent.parent.document.getElementById("hdnDrivingTime").value == "true")
    if (dtCheckbox.checked == true)
    {
        if (ret != "")
            ret = ret + "," + vwTripNodes;
        else
            ret = vwTripNodes;
    }
    
    //alert(ret);
    return ret;
}

function getTooltipLayers()
{
    var ret = "";
          
    if (document.getElementById("hdnChkLink").value == "true")
        ret = getLinkLayer(); 
        //ret = vwLink;      
          
    if (document.getElementById("hdnChkCamera").value == "true")
    {
        if (ret != "")
            ret = ret + "," + camFeatureType;
        else
            ret = camFeatureType;
    }
        
    if (document.getElementById("hdnChkEvent").value == "true")
    {
        if (ret != "")
            ret = ret + "," + vwEventDetail;
        else
            ret = vwEventDetail;
    }           
       
    if (document.getElementById("hdnChkConstr").value == "true")
    {
        if (ret != "")
            ret = ret + "," + vwConstructionDetail;
        else
            ret = vwConstructionDetail;
    }       
    
    if (document.getElementById("hdnChkIncident").value == "true")
    {
        if (ret != "")
            ret = ret + "," + vwIncidentDetail;
        else
            ret = vwIncidentDetail;
    }  
    // alert(parent.parent.DTMode + ';' + DTMode + ';' + document.getElementById("hdnDrivingTime").value + ';' + parent.parent.document.getElementById("hdnDrivingTime").value);
    //if (DTMode == true || parent.parent.document.getElementById("hdnDrivingTime").value == "true")
    if (parent.parent.document.getElementById("hdnDrivingTime").value == "true")
    {//alert(parent.parent.DTMode + ';' + DTMode + ';' + document.getElementById("hdnDrivingTime").value + ';' + parent.parent.document.getElementById("hdnDrivingTime").value);
        if (ret != "")
            ret = ret + "," + vwTripNodes;
        else
            ret = vwTripNodes;
    }

    return ret;
}

function getParentLayers()
{
    var ret = "";
    var shield = "";
               
    if (parent.parent.document.getElementById("hdnChkLink").value == "true")
    {    
        if (parent.parent.document.getElementById("hdnTheme").value == "" || parent.parent.document.getElementById("hdnTheme").value == "standard")
            ret = getLinkLayer();
            //ret = vwLink;  
        else
            ret = getColorTheme(parent.parent.document.getElementById("hdnTheme").value);  
        //GLog.write(ret);     
        if (showShields == true)
        {
        //* add highway shields
        if (parent.parent.googleMap.getZoom() == 10)
            shield = vwShield10;
        else if (parent.parent.googleMap.getZoom() == 11)
            shield = vwShield11;
        else if (parent.parent.googleMap.getZoom() == 12)
            shield = vwShield12;     
        }
        else
            shield = "";
            
        if (shield != "")
        {
            if (ret != "")
                ret = ret + "," + shield;
            else
                ret = shield;    
        }     
    }             
          
    if (parent.parent.document.getElementById("hdnChkCamera").value == "true")
    {
        if (ret != "")
            ret = ret + "," + camFeatureType;
        else
            ret = camFeatureType;
    }
        
    if (parent.parent.document.getElementById("hdnChkEvent").value == "true")
    {
        if (ret != "")
            ret = ret + "," + eventFeatureType;
        else
            ret = eventFeatureType;
    }           
       
    if (parent.parent.document.getElementById("hdnChkConstr").value == "true")
    {
        if (ret != "")
            ret = ret + "," + constFeatureType;
        else
            ret = constFeatureType;
    }       
    
    if (parent.parent.document.getElementById("hdnChkIncident").value == "true")
    {
        if (ret != "")
            ret = ret + "," + incFeatureType;
        else
            ret = incFeatureType;
    }  
    
    //alert('here=' + parent.parent.DTMode  + ';' + DTMode+ ';' + parent.parent.document.getElementById("hdnDrivingTime").value);
    //if (DTMode == true || parent.parent.document.getElementById("hdnDrivingTime").value == "true")
    if (parent.parent.document.getElementById("hdnDrivingTime").value == "true")
    {
        if (ret != "")
            ret = ret + "," + vwTripNodes;
        else
            ret = vwTripNodes;
    }

    return ret;
}

function refreshMap()
{   
    //showPleaseWaitScreen(""); 
    
    showEventLayers(getParentLayers(), "refresh", "");      
    
    //hideEventTooltip();
    hideEventTooltipP();
    //hideNodeTooltip();
    hideNodeTooltipP();        
		
    refreshDateTimeStampP();	
    refreshDateTimeStamp();	
    
    hidePleaseWaitScreen(); 
    
    //addNorthArrow();
}

function autoRefreshMap()
{   //GLog.write(parent.parent.document.getElementById("hdnDrivingTime").value + ';' + document.getElementById("hdnDrivingTime").value);
    //alert(parent.parent.document.getElementById("hdnDrivingTime").value);
    //alert(REFRESH_RATE);
    if (parent.parent.document.getElementById("hdnDrivingTime").value == "false")
    {
        //showPleaseWaitScreen(""); 
    
        //GLog.write("1.autoRefreshMap: " + new Date());
        showEventLayers(getParentLayers(), "refresh", "");           
                  
        //hideEventTooltip();
        hideEventTooltipP();
        //hideNodeTooltip();
        hideNodeTooltipP();
        
        //hidePleaseWaitScreen(); 
        
        if (timerID != null && timerID != undefined)
            clearTimeout(timerID);
        
        if (parent.parent.timerID != null && parent.parent.timerID != undefined)
            clearTimeout(parent.parent.timerID);
        
        //* set refresh timer
        if (REFRESH_RATE != "" && parent.parent.REFRESH_RATE != "" && REFRESH_RATE != "-1" && REFRESH_RATE != -1)
        {   //showPleaseWaitScreen('');
		    timerID = setTimeout("autoRefreshMap()", parseInt(parent.parent.REFRESH_RATE)*1000);
		}    
    		
        refreshDateTimeStampP();	
        refreshDateTimeStamp();	
        
        //hidePleaseWaitScreen();         
        
    }
    else
    {
        if (timerID != null && timerID != undefined)
            clearTimeout(timerID);
    
        if (parent.parent.timerID != null && parent.parent.timerID != undefined)
            parent.parent.clearTimeout(parent.parent.timerID);
    }
    
    //hidePleaseWaitScreen(); 
}

function updateLayers(element) {
	//var theForm = document.forms[0];
	var j = 0;
	var name;	
	var selElement = element;
	//alert(element);	
	element = document.getElementById(element);
	//alert(element);	
	
	hideEventTooltipP(); 
	hideNodeTooltipP();
			
	if (element != undefined)
	{	
	    name = element.id;
	    
	    if (name == "Incidents")
	        parent.parent.document.getElementById("hdnChkIncident").value=element.checked;
	    else if (name == "Construction")
	        parent.parent.document.getElementById("hdnChkConstr").value=element.checked;
	    else if (name == "Events")
	        parent.parent.document.getElementById("hdnChkEvent").value=element.checked;
	    else if (name == "Cameras")
	        parent.parent.document.getElementById("hdnChkCamera").value=element.checked;
	    else if (name == "Traffic")
	        parent.parent.document.getElementById("hdnChkLink").value=element.checked;
	    else if (name == "DrivingTime")
	    {
	        parent.parent.document.getElementById("hdnDrivingTime").value=element.checked;
	        //GLog.write('in click: id=' + timerID + '; parent=' + parent.parent.timerID);
	        if (timerID != null && timerID != undefined) 
                clearTimeout(timerID);	            
            if (parent.parent.timerID != null && parent.parent.timerID != undefined)
                parent.parent.clearTimeout(parent.parent.timerID);                	        
	        
	        if (element.checked == true)
	        {
	            DTMode = true;  	                  	                	            
	        }
	        else
	        {
	            DTMode = false;  	                
	        }     
	    }    
	    else 
	        parent.parent.document.getElementById("hdnChkLink").value=element.checked;    
	        	    	   
	    	    
        if (element.checked == true)
        {                                
            showEventLayers(getParentLayers(), "", "");            
        }
        else
        {                        
            clearParentOverlay();     
               
            LINK_LIST = "";
            parent.parent.LINK_LIST = "";
            
            START_NODE_LAT = 0;
            START_NODE_LON = 0;
            START_NODE_LAT = 0;
            START_NODE_LON = 0;
            END_NODE_LAT = 0;
            END_NODE_LON = 0;      
            START_NODE_ID = 0;
            END_NODE_ID = 0;
            
            parent.parent.DTInfoFrom = false;
            parent.parent.DTInfoTo = false;
            
            parent.parent.START_NODE_ID = 0;
            parent.parent.END_NODE_ID = 0;
            
            parent.parent.START_NODE_LAT = 0;
            parent.parent.START_NODE_LON = 0;
            parent.parent.END_NODE_LAT = 0;
            parent.parent.END_NODE_LON = 0;      
            
            showEventLayers(getParentLayers(), "", "");	           
            		      
        }
        
        if (REFRESH_RATE != "" && parent.parent.REFRESH_RATE != "" && REFRESH_RATE != "-1" && REFRESH_RATE != -1)
        {	                
            //alert(parent.parent.document.getElementById("hdnDrivingTime").value);
            if (parent.parent.document.getElementById("hdnDrivingTime").value == "false") 
            {   
                timerID = setTimeout("parent.parent.autoRefreshMap()", parseInt(parent.parent.REFRESH_RATE )*1000);   
                //alert('click=' + timerID);
                //alert(parent.parent.REFRESH_RATE);
            }
        }
        
    }         

    hidePleaseWaitScreen();
	//t.reloadMap();
	
	if (DTMode == true && selElement == "DrivingTime")
        alert("You have selected the Driving Times feature.  For your starting point, click on any blue circle where we provide driving times."); 
}

function createEventTooltipDiv()
{
    divTooltipEvent = document.createElement("div");
    googleMap.getPane(G_MAP_FLOAT_PANE).appendChild(divTooltipEvent); 
    divTooltipEvent.style.zIndex="100";   
    divTooltipEvent.style.visibility="hidden";
    divTooltipEvent.onmouseover=hide;   
        
    divTooltipNode = document.createElement("div");
    googleMap.getPane(G_MAP_FLOAT_PANE).appendChild(divTooltipNode);
    
    divTooltipNode.style.zIndex="100";
    
    divTooltipNode.style.visibility="hidden";
}

function hide()
{
    divTooltipEvent.style.visibility="hidden";
}

function addNorthArrow()
{    
    var frameToolbar = document.getElementById("frameToolbar");
    //var divMap = document.getElementById("MapFrame");
    var mapHeight;
    var mapWidth;      
    
    if (frameToolbar != null  && frameToolbar != undefined)
    {
        var width = frameToolbar.contentWindow.document.body.scrollWidth;       
        var top = frameToolbar.contentWindow.document.body.scrollHeight;
        
        if (parent.parent.document.getElementById("MapFrame").style.pixelHeight && parent.parent.document.getElementById("MapFrame").style.pixelWidth)
	    {   
	        mapHeight = parent.parent.document.getElementById("MapFrame").style.pixelHeight;
	        //mapWidth = parent.parent.document.getElementById("MapFrame").style.pixelWidth;        
         }
        else
        {                   
	        mapHeight = parent.parent.document.getElementById("MapFrame").clientHeight;
	        //mapWidth = parent.parent.document.getElementById("MapFrame").clientWidth;   		              
        }     
        
        //alert(mapWidth + ';' + mapHeight);
        divNorthArrow = document.getElementById("northArrow");
        divNorthArrow.style.left = (width+30) + "px";  
        divNorthArrow.style.top = (mapHeight-100) + "px";       
    } 

 

}

function refreshDateTimeStamp()
{
    var frameToolbar = document.getElementById("frameToolbar");
    //alert(parent.parent.document.getElementById("frameToolbar"));
    //alert(frameToolbar.contentWindow.document.body.scrollWidth + ';' + frameToolbar.contentWindow.document.body.scrollHeight);
    //GLog.write("refreshDateTimeStamp=" + frameToolbar);
    
    if (frameToolbar != null  && frameToolbar != undefined)
    {
        var width = frameToolbar.contentWindow.document.body.scrollWidth;

        var d = new Date();
        //var d = formatDate(d, "M/dd/yyyy HH:mm a");  
        var d = formatDate(d, "M/dd/yyyy h:mm a");
        
        divRefresh = document.getElementById("refreshData");
        divRefresh.style.left = (width+10) + "px";
        divRefresh.innerHTML = "Last refreshed: " + d;
    } 
}

function refreshDateTimeStampP()
{
    var frameToolbar = parent.parent.document.getElementById("frameToolbar");
    //GLog.write("refreshDateTimeStampP=" + frameToolbar);
    //alert(parent.parent.document.getElementById("frameToolbar"));
    //alert(frameToolbar.contentWindow.document.body.scrollWidth + ';' + frameToolbar.contentWindow.document.body.scrollHeight);
    if (frameToolbar != null  && frameToolbar != undefined)
    {
        var width = frameToolbar.contentWindow.document.body.scrollWidth;

        var d = new Date();
        //var d = formatDate(d, "M/dd/yyyy HH:mm a");  
        var d = formatDate(d, "M/dd/yyyy h:mm a");
        
        divRefresh = parent.parent.document.getElementById("refreshData");
        divRefresh.style.left = (width+10) + "px";
        divRefresh.innerHTML = "Last refreshed: " + d; 
    }
}

function clearParentOverlay()
{
    if (parent.parent.googleMap != null)
       parent.parent.googleMap.clearOverlays();	
       
    if (googleMap != null)
       googleMap.clearOverlays();	   
                           
    //if (parent.parent.googleMap != null && parent.parent.eventImage != null)
	//    parent.parent.googleMap.removeOverlay(parent.parent.eventImage);	                   	        
    
}

function addStartMarker(lat, lon)
{   //GLog.write('1.start=' + lat + ';' + lon);
    remStartMarker(); 
    remEndMarker();   

    if (lat != 0 && lon != 0)
    {
    point = new GLatLng(parseFloat(lat), parseFloat(lon));
    startMarker = new PdMarker(point, startIcon);     
    googleMap.addOverlay(startMarker);  
    }
}

function addEndMarker(lat, lon)
{   //GLog.write('1.end=' + curLat + ';' + curLon);
    remEndMarker();

    if (lat != 0 && lon != 0)
    {
    point = new GLatLng(parseFloat(lat), parseFloat(lon));
    endMarker = new PdMarker(point, endIcon);     
    googleMap.addOverlay(endMarker);   
    }
    //getDrivingTimeTrip();
    //addDTLink();
}

function addStartMarkerP(lat, lon)
{   //GLog.write('2.start=' + lat + ';' + lon);
    remStartMarkerP(); 
    remEndMarkerP();   

    point = new GLatLng(parseFloat(lat), parseFloat(lon));
    startMarker = new PdMarker(point, startIcon);     
    parent.parent.googleMap.addOverlay(startMarker);  
}

function addEndMarkerP(lat, lon)
{   //GLog.write('end=' + parent.parent.curLat + ';' + curLon);
    //GLog.write('end=' + parent.parent.lat + ';' + lat);
    //GLog.write('2.end=' + curLat + ';' + curLon);
    remEndMarkerP();

    point = new GLatLng(parseFloat(lat), parseFloat(lon));
    endMarker = new PdMarker(point, endIcon);     
    parent.parent.googleMap.addOverlay(endMarker);      
 
}

function remStartMarker()
{
    if (startMarker != undefined)
        googleMap.removeOverlay(startMarker);
}

function remEndMarker()
{//GLog.write('remEndMarker');
    if (endMarker != undefined)
        googleMap.removeOverlay(endMarker);
}

function remStartMarkerP()
{//GLog.write('remEndMarkerP');
    if (startMarker != undefined)
        parent.parent.googleMap.removeOverlay(startMarker);
}

function remEndMarkerP()
{
    if (endMarker != undefined)
        parent.parent.googleMap.removeOverlay(endMarker);
}

function cancelDT()
{
    DTInfoFrom = false;
    DTInfoTo = false;
    
    remStartMarker();
    remEndMarker();
    
    startMarkerID = 0;
    endMarkerID = 0;
    
    googleMap.closeInfoWindow();
} 

function closeDTWindow()
{
    //alert(parent.parent.googleMap);
    googleMap.closeInfoWindow();
}

function randomFromTo(from, to){
       return Math.floor(Math.random() * (to - from + 1) + from);
}

function showEventLayers(sLayers, refresh, onload)
{
   //*****************************************************
   //* This function makes incident request to GeoServer
   //*****************************************************
   //alert(sLayers);
   //GLog.write(sLayers);
   if (sLayers != "")
   {            
       if (getObject(googleMap, "map") != undefined && getObject(googleMap, "map") != null)
       {
        var boundingBox = parent.parent.googleMap.getBounds();       
        var southWest = boundingBox.getSouthWest();
        var northEast = boundingBox.getNorthEast();
        var thisZoom = getObject(googleMap, "map").getZoom();
        
        var mapHeight;
        var mapWidth;
        
        var pathUrl;
        
        //showPleaseWaitScreen("");
        
        var thisExtents = southWest.x + ' ' + southWest.y + ',' + northEast.x + ' ' + northEast.y;
   
        try 
        {                    
            var coords = thisExtents.split(",");
		    var coords1 = coords[0].split(" ");
		    var coords2 = coords[1].split(" ");
    		
		    var boundaries = new GLatLngBounds(new GLatLng(parseFloat(coords1[1]),parseFloat(coords1[0])), 
		                                        new GLatLng(parseFloat(coords2[1]),parseFloat(coords2[0])));                                        	                                       
	          	    
		    //* get size of "map_canvas" div                               
		    //if (getObject(parent.parent.MapFrame, "mapframe").style.pixelHeight && getObject(parent.parent.MapFrame, "mapframe").style.pixelWidth)
		    if (parent.parent.document.getElementById("MapFrame").style.pixelHeight && parent.parent.document.getElementById("MapFrame").style.pixelWidth)
		    {   //alert(parent.parent.MapFrame.style.pixelHeight + ';' + parent.parent.MapFrame.clientHeight + ';' + parent.parent.MapFrame.clientWidth);		           
		        mapHeight = parent.parent.document.getElementById("MapFrame").style.pixelHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").style.pixelWidth;        
             }
            else
            {                   
		        mapHeight = parent.parent.document.getElementById("MapFrame").clientHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").clientWidth;   		              
            }                                  	                                  
    		//alert(mapHeight + ';' + mapWidth + ';' + document.getElementById("MapFrame").clientWidth);
    		if (wOpenFlag == false)	
    		{
	            if (parent.parent.googleMap != null && parent.parent.eventImage != null)
	            {
	                //parent.parent.googleMap.removeOverlay(parent.parent.eventImage);
	                //parent.parent.googleMap.removeOverlay(eventImage);
	                
	                parent.parent.googleMap.clearOverlays();    
                }        
                if (googleMap != null && eventImage != null)
                {   //alert('clear');
                    //googleMap.removeOverlay(eventImage);
                    //googleMap.removeOverlay(parent.parent.eventImage);
                    
                    googleMap.clearOverlays();	 
                }           
    	     }   
	                	       	   	       	
	        //* create URL for GeoServer				
	        var geoServerUrl = "http://" + HOST_GEO_SERVER + PORT + "/geoserver/wms?bbox=" + 
	                        coords1[0] + "," + coords1[1] + "," + coords2[0] + "," + coords2[1] + 
                            "$tiled=true$styles=$Format=image/png$request=GetMap$layers=" + sLayers + 
                            "$width=" + mapWidth + "$height=" + mapHeight + 
                            "$srs=EPSG:4326$TRANSPARENT=TRUE$count=0$tilesorigin=" + 
                            coords1[0] + "," + coords2[1] + "$CQL_FILTER=INCLUDE"; 
            // alert(geoServerUrl);  
            
            //* check for Chrome browser
            var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome');
            
            if (refresh == "") 
                pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl + "&is_chrome=" + is_chrome;
            else
                pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl + "&is_chrome=" + is_chrome + "&ms=" + new Date().getTime(); 
                                    
            /*                       
            if (is_chrome > -1)
            {
                if (refresh == "") 
                    pathUrl = "/GSHandler/GSHandler/staticImage.ashx?command=GetMap&geoUrl=" + geoServerUrl;
                else
                    pathUrl = "/GSHandler/GSHandler/staticImage.ashx?command=GetMap&geoUrl=" + geoServerUrl + "&ms=" + new Date().getTime();
            }    
            else
            {
                if (refresh == "") 
                    pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl;
                else
                    pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl + "&ms=" + new Date().getTime();
            }
            */
            
            //alert(pathUrl);
            
            //* SK 1/12/2012: added transparent background for blind colors
            if (sLayers.indexOf("vwLinkDeutan") != -1 || sLayers.indexOf("vwLinkTritan") != -1 || sLayers.indexOf("vwLinkContrast") != -1)
            {
                eventImage = EInsert.groundOverlay(blindBkgnd, boundaries);
                
                if (googleMap != null) 
                    googleMap.addOverlay(eventImage);      
                else
                    parent.parent.googleMap.addOverlay(eventImage);     
                }    
            //***************************************************    
        
            //* create all images            
            eventImage = EInsert.groundOverlay(pathUrl, boundaries);   
                              
            //* add all images to GMap
            //parent.parent.googleMap.addOverlay(eventImage);  
            
            if (googleMap != null) 
                googleMap.addOverlay(eventImage);      
            else
                parent.parent.googleMap.addOverlay(eventImage);     
                
            
            if (parent.parent.dtCheckbox.checked == true)
            {
                if (DTFlag == true || parent.parent.DTFlag == true)
                {
                    if (LINK_LIST != "" || parent.parent.LINK_LIST != "")
                    {
                        var filter = "";
                        if (LINK_LIST != "")
                            filter = getFilter(LINK_LIST);
                        else
                            filter = getFilter(parent.parent.LINK_LIST);    
                        
                        geoServerUrl = "http://" + HOST_GEO_SERVER + PORT + "/geoserver/wms?bbox=" + 
	                                    coords1[0] + "," + coords1[1] + "," + coords2[0] + "," + coords2[1] + 
                                        "$tiled=null$styles=$Format=image/png$request=GetMap$layers=" + getLinkSelected() + 
                                        "$width=" + mapWidth + "$height=" + mapHeight + 
                                        "$srs=EPSG:4326$TRANSPARENT=TRUE$count=0$tilesorigin=" + 
                                        coords1[0] + "," + coords2[1] + "$CQL_FILTER=" + filter;
                        
                        pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl;
                        
                        tripImage = EInsert.groundOverlay(pathUrl, boundaries);   
                                
                        if (googleMap != null) 
                            googleMap.addOverlay(tripImage);      
                        else
                            parent.parent.googleMap.addOverlay(tripImage);         
                    
                    }
                    
                }                
            }
            else
            {
                remStartMarker();
                remEndMarker();
                remStartMarkerP();
                remEndMarkerP();
            }
            
            refreshDateTimeStampP();	
            refreshDateTimeStamp();
            
            //hidePleaseWaitScreen();              
                        
            //GLog.write('id=' + timerID + '; parent=' + parent.parent.timerID);
            //GLog.write('onload=' + onload);
	        //if (REFRESH_RATE != "" || parent.parent.REFRESH_RATE != "" && onload != "")
	        if (REFRESH_RATE != "" && parent.parent.REFRESH_RATE != "" && REFRESH_RATE != "-1" && REFRESH_RATE != -1)
	        {
	            if (timerID != null && timerID != undefined) 
	                clearTimeout(timerID);	            
	            if (parent.parent.timerID != null && parent.parent.timerID != undefined)
	                parent.parent.clearTimeout(parent.parent.timerID);
	                //alert(parent.parent.document.getElementById("hdnDrivingTime").value);
	            if (parent.parent.document.getElementById("hdnDrivingTime").value == "false") 
	            {   
		            timerID = setTimeout("autoRefreshMap()", parseInt(parent.parent.REFRESH_RATE )*1000);   
		            //alert(timerID);
		        }
		    } 
		    
		    //hidePleaseWaitScreen();       
            
        }
	    catch (ee) {
	        hidePleaseWaitScreen();   
		    alert(ee.message);
		    return false;
	    }
    	    
	    return true;
	    }
	    else
	        return false;
    }	        
	  	    
}

function showEventTooltip(Lat, Lon, showInfo)
{
    try 
	{			      
	    var Coords; 
	    var featureType; 
	    var Zoom = googleMap.getZoom(); 
	        
	    //* check for Chrome browser	    
	    //var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	    
	    var propName = "*"; 
	    	   
	    featureType = getTooltipLayers();	
	    //GLog.write('1:' + featureType);
	    featureType = featureType.replace("vwLink15", "vwLink3");
	    featureType = featureType.replace("vwLink16", "vwLink3");
	    //GLog.write('2:' + featureType);
	   
	    if (TT_FLAG==false)
        { 
            hideEventTooltip(); 
            hideNodeTooltip();
        } 
	    				
        if (ttEventRequest != null)
        {
          if (ttEventRequest.readyState == 4)          
              ttEventRequest=null;          
        }      
        
        if (ttEventRequest == null)
        {                                            
          if(navigator.appName == "Microsoft Internet Explorer")              
              ttEventRequest = new ActiveXObject("Msxml2.XMLHTTP");                            
          else         
              ttEventRequest = new XMLHttpRequest();  
                              
          var bufferX = getEventsBufferValueX();
          var bufferY = getEventsBufferValueY();
         
          var coords = (parseFloat(Lon)-bufferX)+","+
                       (parseFloat(Lat)-bufferY)+","+
                       (parseFloat(Lon)+bufferX)+","+
                       (parseFloat(Lat)+bufferY);
                      
          coords = coords + ",EPSG:4326"; 
            
          var strUrl = "http://" + HOST_GEO_SERVER + PORT + 
                        "/geoserver/wfs?request=GetFeature$version=1.1.0$bbox=" + coords + 
                        "$typeName=" + featureType + 
                        "$propertyname=" + propName + "$count=~geocount";                                
            		
  	      pathUrl="/GSHandler/GSHandler/GSHandler.ashx?command=GetFeature&geoUrl=" + strUrl;	
  	        
          //GLog.write(pathUrl);            
          ttEventRequest.open("GET", pathUrl, true);          
           
          ttEventRequest.onreadystatechange = function() {   
          
          if (ttEventRequest != null)
          {                             
              //* check for Chrome browser
              var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome');              
              var is_safari = navigator.userAgent.toLowerCase().indexOf("safari");              
                          
              if (ttEventRequest.readyState == 4) {//GLog.write(ttEventRequest.status + ';' + ttEventRequest.responseText);
                if (ttEventRequest.status == 200) {    //GLog.write(showInfo);  	        
                    var xmlhttp = ttEventRequest.responseText; 	 //GLog.write(xmlhttp);  
                    if (is_chrome > -1 || is_safari > -1)  
                        processEventTooltipChrome(GXml.parse(xmlhttp), Lat, Lon, featureType, showInfo); 	
                        //processEventTooltipChrome(parseIt(xmlhttp), Lat, Lon, featureType, showInfo); 
                    else                                                   
                        processEventTooltip(GXml.parse(xmlhttp), Lat, Lon, featureType, showInfo); 
                                            
                    if (TT_FLAG==false)
                    { 
                        hideEventTooltip(); 
	                    hideNodeTooltip();
	                }   
	                                                                                                          
                    ttEventRequest = null;   	               	                  	                          
                }             
              }                           
          }                             
        }              
        ttEventRequest.send(null);                
        }                          							
	}
	catch (ee) {
		alert(ee.message);
		return;
	}    
}

function getAlertMessage()
{
    var coords = "-117.416382,32.481963,-116.222992,33.332823";
   
    try 
	{		      	    	    	    	    	    
	    				
        if (alertRequest != null)
        {
          if (alertRequest.readyState == 4)          
              alertRequest=null;          
        }      
        
        if (alertRequest == null)
        {                                            
          if(navigator.appName == "Microsoft Internet Explorer")              
              alertRequest = new ActiveXObject("Msxml2.XMLHTTP");                            
          else         
              alertRequest = new XMLHttpRequest();  
                              
          //var bufferX = getEventsBufferValueX();
          //var bufferY = getEventsBufferValueY();         
                       
          coords = coords + ",EPSG:4326"; 
            
          var strUrl = "http://" + HOST_GEO_SERVER + PORT + 
                        "/geoserver/wfs?request=GetFeature$version=1.1.0$bbox=" + coords + 
                        "$typeName=vwGetAlerts" + 
                        "$propertyname=*$count=~geocount";                                
            		
  	      pathUrl="/GSHandler/GSHandler/GSHandler.ashx?command=GetFeature&geoUrl=" + strUrl;	
  	        
          //GLog.write(pathUrl);            
          alertRequest.open("GET", pathUrl, true);          
         
          alertRequest.onreadystatechange = function() {   
          
          if (alertRequest != null)
          {                             
              //* check for Chrome browser
              var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome');              
              var is_safari = navigator.userAgent.toLowerCase().indexOf("safari");              
                          
              if (alertRequest.readyState == 4) {//GLog.write(alertRequest.status + ';' + alertRequest.responseText);
                if (alertRequest.status == 200) {    //GLog.write(showInfo);  	        
                    var xmlhttp = alertRequest.responseText; 	 //GLog.write(xmlhttp);  
                    if (is_chrome > -1 || is_safari > -1)  
                        processAlertChrome(GXml.parse(xmlhttp), "vwGetAlerts"); 	                        
                    else                                                   
                        processAlert(GXml.parse(xmlhttp), "vwGetAlerts"); 
                       
                    alertBoxDisplayNextMessage();    
                                                               	                                                                                                          
                    alertRequest = null;   	               	                  	                          
                }             
              }                           
          }                             
        }              
        alertRequest.send(null);                
        }                          							
	}
	catch (ee) {
		alert(ee.message);
		return;
	}    
}

function onEventClick(Lat, Lon, showInfo)
{
    try 
	{			      
	    var Coords; 
	    var featureType; 
	    var Zoom = googleMap.getZoom();  
	    
	    var propName = "*"; 
	    
	    //* check for Chrome browser
        var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome');
        var is_safari = navigator.userAgent.toLowerCase().indexOf("safari");
	    	    
	    featureType = getTooltipLayers();	
	    
	    featureType = featureType.replace("vwLink15", "vwLink3");
	    featureType = featureType.replace("vwLink16", "vwLink3");
	    
	    //featureType = getLayers();			
		 					
        if (clickEventRequest != null)
        {
          if (clickEventRequest.readyState == 4)          
              clickEventRequest=null;          
        }      
        
        if (clickEventRequest == null)
        {                                            
          if(navigator.appName == "Microsoft Internet Explorer")              
              clickEventRequest = new ActiveXObject("Msxml2.XMLHTTP");                            
          else         
              clickEventRequest = new XMLHttpRequest();  
                              
          var bufferX = getEventsBufferValueX();
          var bufferY = getEventsBufferValueY();
         
          var coords = (parseFloat(Lon)-bufferX)+","+
                       (parseFloat(Lat)-bufferY)+","+
                       (parseFloat(Lon)+bufferX)+","+
                       (parseFloat(Lat)+bufferY);
                       
          coords = coords + ",EPSG:4326"; 
            
          var strUrl = "http://" + HOST_GEO_SERVER + PORT + 
                        "/geoserver/wfs?request=GetFeature$version=1.1.0$bbox=" + coords + 
                        "$typeName=" + featureType + 
                        "$propertyname=" + propName + "$count=~geocount";
                                
            		
  	      pathUrl="/GSHandler/GSHandler/GSHandler.ashx?command=GetFeature&geoUrl=" + strUrl;		                                                 
          //alert(pathUrl); 
          //GLog.write(pathUrl);              
          clickEventRequest.open("GET", pathUrl, true);
           
          clickEventRequest.onreadystatechange = function() {   
          
          if (clickEventRequest != null)
          {
              if (clickEventRequest.readyState == 4) {
                if (clickEventRequest.status == 200) {    //GLog.write(showInfo);  	        
                    var xmlhttp = clickEventRequest.responseText; 	//GLog.write(xmlhttp); 
                    if (is_chrome > -1 || is_safari > -1)
                        processEventClickChrome(GXml.parse(xmlhttp), Lat, Lon, featureType, showInfo);  
                    else                              
                        processEventClick(GXml.parse(xmlhttp), Lat, Lon, featureType, showInfo);   
                                                                                                                                                      
                    clickEventRequest = null;   	               	                  	                          
                }             
              }
          }                             
        }              
        clickEventRequest.send(null);                
        }                          							
	}
	catch (ee) {
		alert(ee.message);
		return;
	}    
}

//function parseIt(xml)
//{
//    if (window.DOMParser)
//      {
//      parser = new DOMParser();
//      xmlDoc = parser.parseFromString(xml, "text/xml");
//      }
//    else // Internet Explorer
//      {
//      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//      xmlDoc.async = "false";
//      xmlDoc.loadXML(xml); 
//      } 
//      
//      return xmlDoc;
//}

function processEventTooltipChrome(xmlhttp, lat, lon, featureType, showInfo)
{
    var ttValue = "";
    var delimiter = "><";   
  
    //var fc_node = xmlhttp.childNodes[0].getElementsByTagName("wfs:FeatureCollection").childNodes;
    var fc_node = xmlhttp.childNodes[0].childNodes; // "wfs:FeatureCollection"
    var fm_nodes;
    
    var flag = false;
        
    if (fc_node == null)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;
    }    
    
    if (fc_node.length == 0)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;
    }    
        
    if (fc_node[0].childNodes.length == 0)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;  
    }      
 
    for(var i = fc_node[0].childNodes.length - 1; i >= 0; i--)
    {
        fm_nodes = fc_node[0].childNodes[i].childNodes;  // "gml:featureMembers"
    
        if (fm_nodes == null)
        {
            hideEventTooltip(); 
	        hideNodeTooltip();
	        TT_FLAG = false; 
	        document.getElementById("hdnFlag").value = "false";
            return;
        }
        
        if (fm_nodes.length == 0)
        {
            hideEventTooltip(); 
	        hideNodeTooltip();
	        TT_FLAG = false; 
	        document.getElementById("hdnFlag").value = "false";
            return;            
        }
        
        //* Incidents
        var eventID = "";
        var linkRoadDesignator = "";
        var crossStreet = "";
        var Description1 = "";
	    var Description2 = "";				
        var Description3 = "";		    
        var Description4 = "";	
        var incidentResponseStatus = "";
        var eventIndicatorStatus = "";
        var estimatedDuration = "Unknown";	 
        var affectedLanesCount = "0";
        var lanesAffected = "0";
        var totalLanesCount = "0";   	    
        var startTime = "";
        var infoSourceOrganizationName = "";
        var assocDeviceID = "";
        var assocDeviceType = "";
        var iconImage = "";
        var cameraPath = "";
        var appImgBaseUrl = "";
        var displayName = "";
        var lanesAffectedGraphic = "";
        var laneCount = "";
        var laneIndex;    
        var endTime = "";              
        
        //* Links
        var LinkID = "";
        var SpeedLimitMPH = "";
        var SpeedMPH = "";
        var SpeedPercent = "";
        var SpeedBand = "";
        var linkOnStreetName = "";
        var FromRoad = "";
        var ToRoad = "";
        var CityName = "";
               
        //* Cameras        
        var deviceID = "";
        var displayName = "";
        var cctvFileName = "";
        var routeDesignator = "";
        var routeDirection = "";
        
        //* Node
        var NodeID = "";
        var nodeDesc = "";
        var nodeCity = "";
        
        var LastUpdated = "";
        
        var htmlInfoWindow = "";
        var layerName = "";         
       
        var exitFlag = false; 
        
        var tagValue = "";
        var tagValue1 = "";
        
        var textColor = "";   	                      
        
        //topp:vwLink,topp:vwEventDetail,topp:vwConstructionDetail,topp:vwIncidentDetail,topp:vwTripNodes
        
        /*
        SELECT incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, incidentResponseStatus, eventIndicatorStatus, 
                      estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, infoSourceOrganizationName, assocDeviceID, assocDeviceType, 
                      iconImage, cameraPath, appImgBaseUrl, displayName, updateTime
        FROM vwIncidentDetail

        SELECT incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, incidentResponseStatus, eventIndicatorStatus, 
                              estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, infoSourceOrganizationName, assocDeviceID, assocDeviceType, 
                              iconImage, cameraPath, appImgBaseUrl, displayName, updateTime
        FROM vwConstructionDetail

        SELECT incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, incidentResponseStatus, eventIndicatorStatus, 
                              estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, infoSourceOrganizationName, endTime, assocDeviceID, 
                              assocDeviceType, iconImage, cameraPath, appImgBaseUrl, displayName, updateTime
        FROM vwEventDetail

        SELECT NodeID, CrossRoad, Description, City, County, OnRoad, lon, lat
        FROM vwTripNodes
        
        SELECT deviceID, displayName, cctvFileName, routeDesignator, routeDirection, routeType, appImgBaseUrl
        FROM  vwCamera

        SELECT LinkID, SpeedLimitMPH, SpeedMPH, SpeedPercent, SpeedBand, linkOnStreetName, FromRoad, ToRoad, CityName, LastUpdated, BEGIN_LON, 
                BEGIN_LAT, END_LON, END_LAT
        */
	  
	    for(var j = 0; j < fm_nodes.length; j++)
	    {
	        tagValue = fc_node[0].childNodes[i].tagName;	        
	        tagValue1 = fm_nodes[j].tagName;
	    
            switch (fc_node[0].childNodes[i].tagName) {
	        case "topp:vwLink": case "topp:vwLink1": case "topp:vwLink2": case "topp:vwLink3": case "topp:vwLink15": case "topp:vwLink16":
		        switch (fm_nodes[j].tagName) {
	            case "topp:LinkID":
        		    LinkID = fm_nodes[j].textContent;                                  
		            break;    		
	            case "topp:SpeedLimitMPH":
        		    SpeedLimitMPH = fm_nodes[j].textContent;
		            break;		
		        case "topp:SpeedMPH":
        		    SpeedMPH = fm_nodes[j].textContent;
		            break;
		        case "topp:SpeedPercent":
        		    SpeedPercent = fm_nodes[j].textContent;
		            break;
		        case "topp:SpeedBand":
        		    SpeedBand = fm_nodes[j].textContent;
		            break;
		        case "topp:linkOnStreetName":
        		    linkOnStreetName = fm_nodes[j].textContent;
		            break;
		        case "topp:FromRoad":
        		    FromRoad = fm_nodes[j].textContent;
		            break;
		        case "topp:ToRoad":
        		    ToRoad = fm_nodes[j].textContent;
		            break;
	            case "topp:CityName":
    		        CityName = fm_nodes[j].textContent;
	                break;
	            case "topp:LastUpdated":
    		        LastUpdated = fm_nodes[j].textContent;
	                break;	                                  
	            default:        		    
                }   
		        break;    		
	        case "topp:vwTripNodes":
    		    switch (fm_nodes[j].tagName) {
	            case "topp:NodeID":
        		    NodeID = fm_nodes[j].textContent;                                  
		            break;    		
	            case "topp:Description":
        		    nodeDesc = fm_nodes[j].textContent;
		            break;		
		        case "topp:City":
        		    nodeCity = fm_nodes[j].textContent;
		            break;		                                          
	            default:        		    
                }   
		        break;	
		    case "topp:vwCamera":
    		    switch (fm_nodes[j].tagName) {
	            case "topp:deviceID":
        		    deviceID = fm_nodes[j].textContent;                                  
		            break;    		
	            case "topp:displayName":
        		    displayName = fm_nodes[j].textContent;
		            break;		
		        case "topp:cctvFileName":
        		    cctvFileName = fm_nodes[j].textContent;
		            break;		
		        case "topp:routeDesignator":
        		    routeDesignator = fm_nodes[j].textContent;
		            break;
		        case "topp:routeDirection":
        		    routeDirection = fm_nodes[j].textContent;
		            break;                                                  
	            default:        		    
                }   
		        break;    		       		        	
	        default:        	        
    		    switch (fm_nodes[j].tagName) {
	            case "topp:incidentID":
        		    eventID = fm_nodes[j].textContent;                                  
		            break;    		
	            case "topp:linkRoadDesignator":
        		    linkRoadDesignator = fm_nodes[j].textContent;
		            break;		
		        case "topp:crossStreet":
        		    crossStreet = fm_nodes[j].textContent;
		            break;		
		        case "topp:Description1":
        		    Description1 = fm_nodes[j].textContent;
		            break;
		        case "topp:Description2":
        		    Description2 = fm_nodes[j].textContent;
		            break;     
		        case "topp:Description3":
        		    Description3 = fm_nodes[j].textContent;
		            break; 
		        case "topp:Description4":
        		    Description4 = fm_nodes[j].textContent;
		            break; 
		        case "topp:incidentResponseStatus":
        		    incidentResponseStatus = fm_nodes[j].textContent;
		            break; 
		        case "topp:eventIndicatorStatus":
        		    eventIndicatorStatus = fm_nodes[j].textContent;
		            break; 
		        case "topp:estimatedDuration":
        		    estimatedDuration = fm_nodes[j].textContent;
		            break; 
		        case "topp:affectedLanesCount":
        		    affectedLanesCount = fm_nodes[j].textContent;
		            break; 
		        case "topp:lanesAffected":
        		    lanesAffected = fm_nodes[j].textContent;
		            break; 
		        case "topp:totalLanesCount":
        		    totalLanesCount = fm_nodes[j].textContent;
		            break; 
		        case "topp:startTime":
        		    startTime = fm_nodes[j].textContent;
		            break; 
		        case "topp:infoSourceOrganizationName":
        		    infoSourceOrganizationName = fm_nodes[j].textContent;
		            break; 
		        case "topp:endTime":
        		    endTime = fm_nodes[j].textContent;
		            break; 
		        case "topp:assocDeviceID":
        		    assocDeviceID = fm_nodes[j].textContent;
		            break; 
		        case "topp:assocDeviceType":
        		    assocDeviceType = fm_nodes[j].textContent;
		            break; 
		        case "topp:iconImage":
        		    iconImage = fm_nodes[j].textContent;
		            break;   
		        case "topp:cameraPath":
        		    cameraPath = fm_nodes[j].textContent;
		            break;
		        case "topp:appImgBaseUrl":
        		    appImgBaseUrl = fm_nodes[j].textContent;
		            break;
		        case "topp:displayName":
        		    displayName = fm_nodes[j].textContent;
		            break;
		        case "topp:updateTime":
        		    //updateTime = fm_nodes[j].textContent;
        		    LastUpdated = fm_nodes[j].textContent;
		            break;		                                                
	            default:        		    
                }   
            }                                                                                        
	    } 
	   
	    if (eventID != "")			        
	       layerName = "event";    // incidents, events, construction
        if (LinkID != "")			        
	       layerName = "link";     
	    if (deviceID != "")			        
	       layerName = "camera"; 
	    if (NodeID != "")			        
	       layerName = "node";                                                                   
                                                                         	          
        if (showInfo == "")		
        {	 			    
            if (crossStreet != "")
                crossStreet = " at " + crossStreet;		
	        
            if (NodeID == "")
            {    
                if (eventID != "")
                {
                    //layerName = "event";    // incidents, events, construction
                    textColor = "#000000";	// black color			            			            
		            
                    if (ttValue == "")    
                        ttValue = linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;    
                    else
                        ttValue = ttValue + delimiter + linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;
                }    
                if (LinkID != "")
                {
                    //layerName = "link";       
                    textColor = "#000099";  //blue color
		            	                   
                    var speed = "";
                    if (parseInt(Math.round(SpeedMPH)) < parseInt(SpeedLimitMPH)-5)
	                    speed = parseInt(Math.round(SpeedMPH));
	                else
	                    speed = parseInt(SpeedLimitMPH)-5 + " mph or higher";    
	                
                    if (ttValue == "")    
                        ttValue = "Route: " + linkOnStreetName + "~" + " from: " + FromRoad + " to: " + ToRoad + "; Speed: " + speed + "~" + "" + "~" + textColor + "~" + layerName;    
                    else
                        ttValue = ttValue + delimiter + "Route: " + linkOnStreetName + "~" + " from: " + FromRoad + " to: " + ToRoad + "; Speed: " + speed + "~" + "" + "~" + textColor + "~" + layerName;
                                                                        
                }      
                if (deviceID != "")
                {
                    //layerName = "camera";
                    textColor = "#009900";	// green color
		            
                    if (ttValue == "")    
                        ttValue = "Camera: " + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;    
                    else
                        ttValue = ttValue + delimiter + "Camera: " + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;
                }  
            }			            
            else //if (NodeID != "")
            {
                hideEventTooltip();
                ttValue = "";
	            
                textColor = "#2F4F4F";	// DarkSlateGray  color     	            
                   
                ttValue = "Node: " + nodeDesc + "~" + nodeCity + "~" + textColor + "~" + layerName;                        
                exitFlag = true;
                break;
            }  
            
            flag = true;                
            document.body.style.cursor = 'pointer';		               	        			      
	        			                             
        }    	            
        
        if (exitFlag == true)		
	 	    break;                   
    }
       
    //* show Event tooltip     
    if (showInfo == "")		
    {	
        if (layerName != "node")
        {
            if (ttValue != "")   
            {
                hideNodeTooltip();	
                hideEventTooltip(); 	                                  
                showMultiTooltipEvent(ttValue, lon, lat);	
            }
            else
            {	//GLog.write('here');
	            hideEventTooltip(); 
	            hideNodeTooltip();
	            TT_FLAG = false;
	            document.getElementById("hdnFlag").value = "false";
	        }  	        
        }
        else //* display node tooltip
        {
            if (ttValue != "") 
            {
                flag = true;  
                hideEventTooltip(); 		                                  
                showTooltipNode(ttValue, lon, lat);
            }            
        }                         
                                   
    }             
	
	if (flag == false && showInfo == "")	
	{	//GLog.write('here');
	    hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false;
	    document.getElementById("hdnFlag").value = "false";
	}  
	else
	{
	    TT_FLAG = true;     
	    document.getElementById("hdnFlag").value = "true";
	}      
        
}

function processAlert(xmlhttp, featureType) 
{
    //***************************************************************************
    //* This function processes response from Geoserver to display Alerts 
    //***************************************************************************
    //var ttValue = "";
    //var arrAlert = new Array();
    //var delimiter = "][";
    
    //var point = null; 
    //var bounds = new GLatLngBounds();  
    
    alertBoxMessages = [];     
 
    fc_node =  getElements(xmlhttp, "wfs", "FeatureCollection")[0];
	//GLog.write(fc_node);			
											
	if (fc_node == null)
	{	    
	    return;
	}    
 		
	fm_nodes = getElements(fc_node,"gml","featureMembers");
	
	if (fm_nodes == null)
	{	    
	    return;
	} 
	
	if (fm_nodes.length ==0)
	{	   
	    return;
	} 
	
	fm = fm_nodes[0];
    //GLog.write(xmlhttp.xml); 	
	var geoLayers = featureType;	
	
	//for(var i = geoLayers.length-1; i >= 0; i--)
	//{		    
    	   
   
    //var exitFlag = false;                                
  		    		
	var	poi_nodes = getElements(fm,"topp",geoLayers); 				
											
	if ( poi_nodes != null && poi_nodes.length > 0)
	{		
		for(var j = 0; j < poi_nodes.length; j++)
		{
		    var	AlertID = "";
            var AlertText = "";
            var LinkURL = "";
            var TextLinkColor = "";
	        var Priority = "";				
            var MessageDetails = "";
		
		    poi_feature = poi_nodes[j];	
	        //GLog.write(xmlhttp.xml);			        		        	         			    		     
	   
            //******************** Alerts *************************************************************
            //* AlertID, AlertText, LinkURL, TextLinkColor, Priority, MessageDetails                   
		    
	        if (getElements(poi_feature, "topp", "AlertID")[0] != null)
            {      
                if (getElements(poi_feature, "topp", "AlertID")[0].firstChild != null)
                    AlertID = getElements(poi_feature, "topp", "AlertID")[0].firstChild.nodeValue;
            }    
                        
            if (getElements(poi_feature, "topp", "AlertText")[0] != null)
            {        
                if (getElements(poi_feature, "topp", "AlertText")[0].firstChild != null)
                    AlertText = getElements(poi_feature, "topp", "AlertText")[0].firstChild.nodeValue;   
            } 
            if (getElements(poi_feature, "topp", "LinkURL")[0] != null)
            {            
                if (getElements(poi_feature, "topp", "LinkURL")[0].firstChild != null)
                    LinkURL = getElements(poi_feature, "topp", "LinkURL")[0].firstChild.nodeValue;        
            } 
            if (getElements(poi_feature, "topp", "TextLinkColor")[0] != null)
            {            
                if (getElements(poi_feature, "topp", "TextLinkColor")[0].firstChild != null)
                    TextLinkColor = getElements(poi_feature, "topp", "TextLinkColor")[0].firstChild.nodeValue;        
            } 
            if (getElements(poi_feature, "topp", "Priority")[0] != null)
            {        
                if (getElements(poi_feature, "topp", "Priority")[0].firstChild != null)
                    Priority = getElements(poi_feature, "topp", "Priority")[0].firstChild.nodeValue;
            }    			    
	        if (getElements(poi_feature, "topp", "MessageDetails")[0] != null)
            {        
                if (getElements(poi_feature, "topp", "MessageDetails")[0].firstChild != null)
                    MessageDetails = getElements(poi_feature, "topp", "MessageDetails")[0].firstChild.nodeValue;
            }                	               		                                                                                  
                                   
            //GLog.write(LinkURL);	
            if (LinkURL != "")
            {
                alertBoxMessages[j] = '<a href=' + LinkURL + ' style="color:' + TextLinkColor + ';text-decoration:none;" target="_blank">' + AlertText + ' <span style="font-size:10px;">(Click here for more details)</span></a>';
                
            }
            else
            {
                alertBoxMessages[j] = '<span style="color:' + TextLinkColor + '">' + AlertText + '</span>';
                
            }
            //GLog.write(alertBoxMessages[j]);           		          		    
	    }		   	    		        
	}		
	
	fc_node=null;
	poi_nodes=null;						    	    					
	                     		
}

function processAlertChrome(xmlhttp, featureType)
{
    var fc_node = xmlhttp.childNodes[0].childNodes; // "wfs:FeatureCollection"
    var fm_nodes;   
    
    alertBoxMessages = [];      
        
    if (fc_node == null)
    {        
        return;
    }    
    
    if (fc_node.length == 0)
    {        
        return;
    }    
        
    if (fc_node[0].childNodes.length == 0)
    {        
        return;  
    }      
 
    for(var i = fc_node[0].childNodes.length - 1; i >= 0; i--)
    {
        fm_nodes = fc_node[0].childNodes[i].childNodes;  // "gml:featureMembers"
    
        if (fm_nodes == null)
        {           
            return;
        }
        
        if (fm_nodes.length == 0)
        {
            return;            
        }                               
                
        var	AlertID = "";
        var AlertText = "";
        var LinkURL = "";
        var TextLinkColor = "";
        var Priority = "";				
        var MessageDetails = "";  	                     
                 	    
	    for(var j = 0; j < fm_nodes.length; j++)
	    {	 
	        if (fc_node[0].childNodes[i].tagName == "topp:vwGetAlerts")
	        {
	            switch (fm_nodes[j].tagName) {
	            case "topp:AlertID":
        		    AlertID = fm_nodes[j].textContent;                                  
		            break; 
		        case "topp:AlertText":
        		    AlertText = fm_nodes[j].textContent;
		            break;		
		        case "topp:LinkURL":
        		    LinkURL = fm_nodes[j].textContent;
		            break;  
		        case "topp:TextLinkColor":
        		    TextLinkColor = fm_nodes[j].textContent;
		            break;
		        case "topp:Priority":
        		    Priority = fm_nodes[j].textContent;
		            break;
		        case "topp:MessageDetails":
        		    MessageDetails = fm_nodes[j].textContent;
		            break;                 			            	                                          
	            default:        		    
                } 		        
	        }	        	                                                                                                                                
	    } 	
	    
	    if (LinkURL != "")            
            alertBoxMessages[i] = '<a href=' + LinkURL + ' style="color:' + TextLinkColor + ';text-decoration:none;" target="_blank">' + AlertText + ' <span style="font-size:10px;">(Click here for more details)</span></a>';                            
        else            
            alertBoxMessages[i] = '<span style="color:' + TextLinkColor + '">' + AlertText + '</span>';                                  	    
        
        //GLog.write(alertBoxMessages[j]);   	    	    	           	    
    }	                               	
	
}

function processEventTooltip(xmlhttp, lat, lon, featureType, showInfo)
{
    //***************************************************************************
    //* This function processes response from Geoserver to display Event tooltip 
    //***************************************************************************
    var ttValue = "";
    var delimiter = "><";
    
    var point = null; 
    var bounds = new GLatLngBounds();       
 
    fc_node =  getElements(xmlhttp, "wfs", "FeatureCollection")[0];
	//GLog.write(fc_node);			
	//GLog.write(xmlhttp.xml);										
	if (fc_node == null)
	{
	    hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
	    return;
	}    
 		
	fm_nodes = getElements(fc_node,"gml","featureMembers");
	
	if (fm_nodes == null)
	{
	    hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
	    return;
	} 
	
	if (fm_nodes.length ==0)
	{
	    hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
	    return;
	} 
	
	fm = fm_nodes[0];
    //GLog.write(xmlhttp.xml); 	
	var geoLayers = featureType.split(",");

	var flag = false;
	
	var scheduledDate = new Date();
    var currentDate  = new Date();       
	//GLog.write(geoLayers.length);
	for(var i = geoLayers.length-1; i >= 0; i--)
	{	
	    //* Incidents, Events, Construction
	    var	eventID = "";
	    var linkRoadDesignator = "";
	    var crossStreet = "";
	    var Description1 = "";
		var Description2 = "";				
	    var Description3 = "";		    
	    var Description4 = "";	
	    var incidentResponseStatus = "";
	    var eventIndicatorStatus = "";
	    var estimatedDuration = "";	 
	    var affectedLanesCount = 0;
	    var lanesAffected = 0;
	    var totalLanesCount = 0;   	    
	    var startTime = "";
	    var infoSourceOrganizationName = "";
	    var assocDeviceID = "";
	    var assocDeviceType = "";
	    var iconImage = "";   
	      	    
	    // incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, 
	    // incidentResponseStatus, eventIndicatorStatus, 
        // estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, 
        // infoSourceOrganizationName, assocDeviceID, assocDeviceType, 
        // iconImage 
         
        
        //incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, 
        // incidentResponseStatus, eventIndicatorStatus, 
        // estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, 
        // infoSourceOrganizationName, assocDeviceID, assocDeviceType, 
        // iconImage
        
        //incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, Description4, 
        // incidentResponseStatus, eventIndicatorStatus, 
        // estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, 
        // infoSourceOrganizationName, endTime, assocDeviceID, 
        // assocDeviceType, iconImage       
                 
        
        //* Links        
        var	LinkID = "";
        var	linkLength = "";
        var	linkOnStreetName = "";
        var	linkDataType = "";
        var	linkSpeed = "";
        var	linkSpeedLimit = "";
        var	linkTravelTime = "";
        var	SpeedLimitTravelTime = "";
        var	LastUpdated = "";                 
        var SpeedLimitMPH = "";
        var SpeedMPH = "";
        var SpeedPercent = "";
        var SpeedBand = "";
        var linkOnStreetName = "";
        var FromRoad = "";
        var ToRoad = "";
        var CityName = "";
        
        //* Cameras        
        var deviceID = "";
        var displayName = "";
        var cctvFileName = "";
        var routeDesignator = "";
        var routeDirection = "";
        
        //* Node
        var NodeID = "";
        var nodeDesc = "";
        var nodeCity = "";
        
        var htmlInfoWindow = "";
        var layerName = ""; 
        
        var linkNameArr = new Array();
        var arrIndex = 0;
        var exitFlag = false;                                
        		    		
		var	poi_nodes = getElements(fm,"topp",geoLayers[i].split(":")[1]); 				
											
		if ( poi_nodes != null && poi_nodes.length > 0)
		{			
			for(var j = poi_nodes.length-1; j >= 0; j--)
			{
			    poi_feature = poi_nodes[j];	
		        //GLog.write(xmlhttp.xml); 	
		        //GLog.write(geoLayers[i].split(":")[1]); 	 
		        
		        if (getElements(poi_feature, "topp", "incidentID")[0] != null)
		           eventID = getElements(poi_feature, "topp", "incidentID")[0].firstChild.nodeValue;  
		           
		        if(getElements(poi_feature, "topp", "LinkID")[0] != null)	    		   			        		    
		           LinkID = getElements(poi_feature, "topp", "LinkID")[0].firstChild.nodeValue;   
		           
		        if(getElements(poi_feature, "topp", "deviceID")[0] != null)	    		   			        		    
		           deviceID = getElements(poi_feature, "topp", "deviceID")[0].firstChild.nodeValue;   
		           
		        if(getElements(poi_feature, "topp", "NodeID")[0] != null)	    		   			        		    
		           NodeID = getElements(poi_feature, "topp", "NodeID")[0].firstChild.nodeValue;   
		         
		         
		        if (eventID != "")			        
			       layerName = "event";    // incidents, events, construction
                if (LinkID != "")			        
			       layerName = "link";     
			    if (deviceID != "")			        
			       layerName = "camera"; 
			    if (NodeID != "")			        
			       layerName = "node";     			    
		     
		        if (showInfo == "")
		        {
		            //******************** Incidents, Events, Constructions *************************************************************
		            // incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, 
		            // Description4, incidentResponseStatus, eventIndicatorStatus, 
                    // estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, 
                    // infoSourceOrganizationName, assocDeviceID, assocDeviceType, iconImage
                    
//	                if (getElements(poi_feature, "topp", "incidentID")[0] != null)
//		                eventID = getElements(poi_feature, "topp", "incidentID")[0].firstChild.nodeValue;
    			    
			        if (getElements(poi_feature, "topp", "linkRoadDesignator")[0] != null)
	                {      
                        if (getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild != null)
                            linkRoadDesignator = getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild.nodeValue;
	                }     	            
	                if (getElements(poi_feature, "topp", "crossStreet")[0] != null)
	                {        
                        if (getElements(poi_feature, "topp", "crossStreet")[0].firstChild != null)
                            crossStreet = getElements(poi_feature, "topp", "crossStreet")[0].firstChild.nodeValue;   
	                } 
	                if (getElements(poi_feature, "topp", "Description1")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "Description1")[0].firstChild != null)
		                    Description1 = getElements(poi_feature, "topp", "Description1")[0].firstChild.nodeValue;        
	                } 
	                if (getElements(poi_feature, "topp", "Description2")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "Description2")[0].firstChild != null)
		                    Description2 = getElements(poi_feature, "topp", "Description2")[0].firstChild.nodeValue;        
	                } 
	                if (getElements(poi_feature, "topp", "Description3")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "Description3")[0].firstChild != null)
                            Description3 = getElements(poi_feature, "topp", "Description3")[0].firstChild.nodeValue;
	                }    			    
			        if (getElements(poi_feature, "topp", "Description4")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "Description4")[0].firstChild != null)
                            Description4 = getElements(poi_feature, "topp", "Description4")[0].firstChild.nodeValue;
	                }   	                	               			    
		            if(getElements(poi_feature, "topp", "incidentResponseStatus")[0] != null)
		            {			    
		                if(getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild != null)			    
		                    incidentResponseStatus = getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild.nodeValue;
		            }    			       		        			    
		            if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0] != null)
		            {
		                if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild != null)
		                    eventIndicatorStatus = getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild.nodeValue;
		            }      
    		        if (getElements(poi_feature, "topp", "estimatedDuration")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild != null)
                            estimatedDuration = getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild.nodeValue; 
                    }         		            		    
		            if (getElements(poi_feature, "topp", "affectedLanesCount")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild != null)
                            affectedLanesCount = getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild.nodeValue;
	                }                	                   	           	                   	                
                    if (getElements(poi_feature, "topp", "lanesAffected")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "lanesAffected")[0].firstChild != null)
                            lanesAffected = getElements(poi_feature, "topp", "lanesAffected")[0].firstChild.nodeValue;
	                }    	            
	                if (getElements(poi_feature, "topp", "totalLanesCount")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild != null)
                            totalLanesCount = getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "startTime")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "startTime")[0].firstChild != null)
                            startTime = getElements(poi_feature, "topp", "startTime")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild != null)
                            infoSourceOrganizationName = getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "assocDeviceID")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild != null)
                            assocDeviceID = getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "assocDeviceType")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild != null)
                            assocDeviceType = getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "iconImage")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "iconImage")[0].firstChild != null)
                            iconImage = getElements(poi_feature, "topp", "iconImage")[0].firstChild.nodeValue;
	                }    
                    
                    //********************************** vwLink **************************************
                    //LinkID, SpeedLimitMPH, SpeedMPH, SpeedPercent, SpeedBand, linkOnStreetName, FromRoad, ToRoad, CityName
                    if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild != null)
                            SpeedLimitMPH = getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedMPH")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild != null)
                            SpeedMPH = getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedPercent")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild != null)
                            SpeedPercent = getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedBand")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedBand")[0].firstChild != null)
                            SpeedBand = getElements(poi_feature, "topp", "SpeedBand")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "linkOnStreetName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild != null)
                            linkOnStreetName = getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "FromRoad")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "FromRoad")[0].firstChild != null)
                            FromRoad = getElements(poi_feature, "topp", "FromRoad")[0].firstChild.nodeValue; 
                    }
                    if (getElements(poi_feature, "topp", "ToRoad")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "ToRoad")[0].firstChild != null)
                            ToRoad = getElements(poi_feature, "topp", "ToRoad")[0].firstChild.nodeValue; 
                    }
                    if (getElements(poi_feature, "topp", "CityName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "CityName")[0].firstChild != null)
                            CityName = getElements(poi_feature, "topp", "CityName")[0].firstChild.nodeValue; 
                    }                                       
                                        
                    //**************************** Cameras **************************************
                    //deviceID, displayName, cctvFileName, routeDesignator, routeDirection
//                    if(getElements(poi_feature, "topp", "deviceID")[0] != null)	    		   			        		    
//		                deviceID = getElements(poi_feature, "topp", "deviceID")[0].firstChild.nodeValue;
    			    
                    if (getElements(poi_feature, "topp", "displayName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "displayName")[0].firstChild != null)
                            displayName = getElements(poi_feature, "topp", "displayName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "cctvFileName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "cctvFileName")[0].firstChild != null)
                            cctvFileName = getElements(poi_feature, "topp", "cctvFileName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "routeDesignator")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "routeDesignator")[0].firstChild != null)
                            routeDesignator = getElements(poi_feature, "topp", "routeDesignator")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "routeDirection")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "routeDirection")[0].firstChild != null)
                            routeDirection = getElements(poi_feature, "topp", "routeDirection")[0].firstChild.nodeValue; 
                    }   
                    
                    // ******************************* nodes ****************************************
                    if (getElements(poi_feature, "topp", "Description")[0] != null)
	                {        
                        if (getElements(poi_feature, "topp", "Description")[0].firstChild != null)
                            nodeDesc = getElements(poi_feature, "topp", "Description")[0].firstChild.nodeValue;   
	                } 
	                if (getElements(poi_feature, "topp", "City")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "City")[0].firstChild != null)
		                    nodeCity = getElements(poi_feature, "topp", "City")[0].firstChild.nodeValue;        
	                }                                                                             	                
                    //******************************************************************************* 
                }
                else    // showInfo != ""
                {
                    
                    if (layerName != "link")
                    {                    
                    if (htmlInfoWindow == "")
                        htmlInfoWindow = createEventInfoWindow(poi_feature, layerName);
                    else
                        htmlInfoWindow = htmlInfoWindow + "~" + createEventInfoWindow(poi_feature, layerName);
                    }                                                               
                     
                }

                var textColor = "";   //"#000000";	black	                                 
                                                                         	          
			    if (showInfo == "")		
			    {	 			    
			        if (crossStreet != "")
			            crossStreet = " at " + crossStreet;		
			        
			        if (NodeID == "")
			        {    
			            if (eventID != "")
			            {
			                //layerName = "event";    // incidents, events, construction
			                textColor = "#000000";	// black color			            			            
    			            
			                if (ttValue == "")    
	                            ttValue = linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;    
	                        else
	                            ttValue = ttValue + delimiter + linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;
			            }    
			            if (LinkID != "")
			            {
			                //layerName = "link";       
			                textColor = "#000099";  //blue color
    			            
			                /*
			                if (arrIndex == 0)
			                {
			                    linkNameArr[arrIndex] = linkOnStreetName;
			                    arrIndex++;
    			                
			                    addFlag = true;			                
			                }    
			                if (canAdd(linkNameArr, linkOnStreetName) == true)
			                {
			                    linkNameArr[arrIndex] = linkOnStreetName;
			                    arrIndex++;
    			                
			                    addFlag = true;
			                }  
			                else
			                    addFlag = false;  
			                */    
			                var speed = "";
			                if (parseInt(Math.round(SpeedMPH)) < parseInt(SpeedLimitMPH)-5)
    			                speed = parseInt(Math.round(SpeedMPH));
    			            else
    			                speed = parseInt(SpeedLimitMPH)-5 + " mph or higher";    
			                //if (addFlag == true)
			                //{
    			            
			                //if (ZOOM_LEVEL > 10)
			                //{
		                    if (ttValue == "")    
                                ttValue = "Route: " + linkOnStreetName + "~" + " from: " + FromRoad + " to: " + ToRoad + "; Speed: " + speed + "~" + "" + "~" + textColor + "~" + layerName;    
                            else
                                ttValue = ttValue + delimiter + "Route: " + linkOnStreetName + "~" + " from: " + FromRoad + " to: " + ToRoad + "; Speed: " + speed + "~" + "" + "~" + textColor + "~" + layerName;
                                //ttValue = ttValue + delimiter + "Link: " + linkOnStreetName + "~" + "; Speed: " + Math.round(SpeedMPH) + "~" + "" + "~" + textColor + "~" + layerName;
	                        //}  
	                          
			            }      
			            if (deviceID != "")
			            {
			                //layerName = "camera";
			                textColor = "#009900";	// green color
    			            
			                if (ttValue == "")    
	                            ttValue = "Camera: " + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;    
	                        else
	                            ttValue = ttValue + delimiter + "Camera: " + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;
			            }  
			        }			            
			        else //if (NodeID != "")
			        {
			            hideEventTooltip();
			            ttValue = "";
			            
			            textColor = "#2F4F4F";	// DarkSlateGray  color 
			            
			            //if (ttValue == "")    
	                    ttValue = "Node: " + nodeDesc + "~" + nodeCity + "~" + textColor + "~" + layerName;    
	                    //else
	                    //    ttValue = ttValue + delimiter + "Node: " + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;
			            exitFlag = true;
			            break;
			        }  			           
			        			      
			        			                             
                }                                                     
			        
                //hideLinkTooltip();
                //GLog.write(ttValue);
                flag = true;
                
                document.body.style.cursor = 'pointer';		          		    
		    }		   	    		        
		}		
		
		fc_node=null;
		poi_nodes=null;		
		
		if (exitFlag == true)		
		    break;
		    	    					
	}    
            
    //GLog.write(ttValue); 	
    if (showInfo == "")		
    {	//* show Event tooltip  
        if (layerName != "node")
        {
            if (ttValue != "")   
            {
                hideNodeTooltip();	
                hideEventTooltip(); 	                                  
                showMultiTooltipEvent(ttValue, lon, lat);	
            }
            else
            {	//GLog.write('here');
	            hideEventTooltip(); 
	            hideNodeTooltip();
	            TT_FLAG = false;
	            document.getElementById("hdnFlag").value = "false";
	        }  	        
        }
        else //* display node tooltip
        {
            if (ttValue != "") 
            {
                flag = true;  
                hideEventTooltip(); 		                                  
                showTooltipNode(ttValue, lon, lat);
            }            
        }                         
                                   
    }         
             
	
	if (flag == false && showInfo == "")	
	{	//GLog.write('here');
	    hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false;
	    document.getElementById("hdnFlag").value = "false";
	}  
	else
	{
	    TT_FLAG = true;     
	    document.getElementById("hdnFlag").value = "true";
	}  
	 	
	/*
	if (ttValue != "" && showInfo == "")        
        TT_FLAG = true;
    else
        TT_FLAG = false; 				
	*/		   	   	       
}

function processEventClickChrome(xmlhttp, lat, lon, featureType, showInfo)
{
    var ttValue = "";
    var delimiter = "><";
    var htmlInfoWindow = "";
    
    var fc_node = xmlhttp.childNodes[0].childNodes; // "wfs:FeatureCollection"
    var fm_nodes;
    
    var flag = false;
        
    if (fc_node == null)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;
    }    
    
    if (fc_node.length == 0)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;
    }    
        
    if (fc_node[0].childNodes.length == 0)
    {
        hideEventTooltip(); 
	    hideNodeTooltip();
	    TT_FLAG = false; 
	    document.getElementById("hdnFlag").value = "false";
        return;  
    }      
 
    for(var i = fc_node[0].childNodes.length - 1; i >= 0; i--)
    {
        fm_nodes = fc_node[0].childNodes[i].childNodes;  // "gml:featureMembers"
    
        if (fm_nodes == null)
        {
            hideEventTooltip(); 
	        hideNodeTooltip();
	        TT_FLAG = false; 
	        document.getElementById("hdnFlag").value = "false";
            return;
        }
        
        if (fm_nodes.length == 0)
        {
            hideEventTooltip(); 
	        hideNodeTooltip();
	        TT_FLAG = false; 
	        document.getElementById("hdnFlag").value = "false";
            return;            
        }
        
        //* Incidents
        var eventID = "";                   
        
        //* Links
        var LinkID = "";        
               
        //* Cameras        
        var deviceID = "";
                
        //* Node
        var NodeID = ""; 
        var nodeDesc = "";
        var nodeCity = "";               
        
        var layerName = "";         
       
        var exitFlag = false; 
                        
        var textColor = "";   	                      
             	    
	    for(var j = 0; j < fm_nodes.length; j++)
	    {	        	    
            switch (fc_node[0].childNodes[i].tagName) {
	        //case "topp:vwLink","topp:vwLink1","topp:vwLink2","topp:vwLink3":
	        case "topp:vwLink": case "topp:vwLink1": case "topp:vwLink2": case "topp:vwLink3": case "topp:vwLink15": case "topp:vwLink16":
		        switch (fm_nodes[j].tagName) {
	            case "topp:LinkID":
        		    LinkID = fm_nodes[j].textContent;                                  
		            break;    		            	                                  
	            default:        		    
                }   
		        break;    		
	        case "topp:vwTripNodes":
    		    switch (fm_nodes[j].tagName) {
	            case "topp:NodeID":
        		    NodeID = fm_nodes[j].textContent;                                  
		            break; 
		        case "topp:Description":
        		    nodeDesc = fm_nodes[j].textContent;
		            break;		
		        case "topp:City":
        		    nodeCity = fm_nodes[j].textContent;
		            break;       			            	                                          
	            default:        		    
                }   
		        break;	
		    case "topp:vwCamera":
    		    switch (fm_nodes[j].tagName) {
	            case "topp:deviceID":
        		    deviceID = fm_nodes[j].textContent;                                  
		            break;    		                                                            
	            default:        		    
                }   
		        break;    		       		        	
	        default:        	        
    		    switch (fm_nodes[j].tagName) {
	            case "topp:incidentID":
        		    eventID = fm_nodes[j].textContent;                                  
		            break;   			            	                                                
	            default:        		    
                }   
            }                                                                                                                            
	    } 
	    
	    if (eventID != "")			        
           layerName = "event";    // incidents, events, construction
        if (LinkID != "")			        
           layerName = "link";     
        if (deviceID != "")			        
           layerName = "camera"; 
        if (NodeID != "")			        
           layerName = "node";  
	     
	       
        if (layerName == "node")
        {	        
            break;   
        }    
	    else
	    {
	        if (htmlInfoWindow == "")
                htmlInfoWindow = createEventInfoWindowChrome(fm_nodes, layerName, fc_node[0].childNodes[i]);
            else
                htmlInfoWindow = htmlInfoWindow + "~" + createEventInfoWindowChrome(fm_nodes, layerName, fc_node[0].childNodes[i]);
	    }  
	    
    }	   
      
    if (layerName != "node")
    {             	
//        if (showInfo == "")		
//        {	//* show Event tooltip  
//            if (ttValue != "")   		                                  
//                showMultiTooltipEvent(ttValue, lon, lat);	
//        }    
//        else
//        {   //GLog.write('final=' + htmlInfoWindow);

          //* show Event Info
          if (htmlInfoWindow != "")
          {
            var arr1 = new Array();
            var arr2 = new Array();
            var legend = "";
            var incCaption = "";
            var linkCaption = "";
            var camCaption = "";
            
            var outputHeader = '<div style="width:100%; background-color:#9cbdde">';
            outputHeader += '<img src="images/sandag511-logo-popup.jpg" alt="San Diego 511 Logo" width="100" height="49">';
            outputHeader += '</div>';
            //outputHeader += '</div><br />';
         
            //if (legend != "" && legend != undefined)
            legend = getLaneViewLegend("400px");
            //else
            //    legend = "";
            
            arr1 = htmlInfoWindow.split("~"); 
                      
            htmlInfoWindow = "";
            //alert(arr1.length);   
            for(j = 0; j < arr1.length; j++)
            {
                if (arr1[j] != "")
                {
                    arr2 = arr1[j].split("^");                    
                                        
                    //alert(arr2[2]);   
                    if (arr2[2] == "incident")
                    {
                        if (incCaption == "")
                        {
                            //incCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Incidents</h5></div>';
                            incCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Incidents</u></div>';
                            htmlInfoWindow = incCaption + legend + arr2[0];
                        }                                                  
                        else
                            htmlInfoWindow = htmlInfoWindow + arr2[0]; 
                    }    
                    else if (arr2[2] == "camera")
                    {
                        if (camCaption == "")
                        {
                            //camCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Cameras</h5></div>';
                            camCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Cameras</u></div>'; 
                            htmlInfoWindow = htmlInfoWindow + camCaption + arr2[0];
                        }   
                        else
                            htmlInfoWindow = htmlInfoWindow + arr2[0];                   
                    }
                    else  //* link
                    {
                        if (linkCaption == "")
                        {
                            //linkCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Speed Information</h5></div>';
                            linkCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Speed Information</u></div>';
                            
                            htmlInfoWindow = htmlInfoWindow + linkCaption + arr2[0];                            
                        }
                        else
                            htmlInfoWindow = htmlInfoWindow + arr2[0];                        
                        
                    }                      
                                                
                    //htmlInfoWindow = htmlInfoWindow + arr2[0];   
                    //break;                
                }               
                
            }                   
                        
            showEventInfoWindow(outputHeader + htmlInfoWindow, lon, lat, arr1.length);   
                          
         }                             
        //}    
    }
    else
    {
        showDrivingTimeStartEndWindow(NodeID, nodeDesc, nodeCity, lat, lon);
    }
                     
	
	if (flag == false && showInfo == "")	
	{	
	    hideEventTooltip();  	   
	    hideNodeTooltip();
	}	  
    
}

function processEventClick(xmlhttp, lat, lon, featureType, showInfo)
{
    //***************************************************************************
    //* This function processes response from Geoserver to display Event tooltip 
    //***************************************************************************
    var ttValue = "";
    var delimiter = "><";
    var htmlInfoWindow = "";
    
    var point = null; 
    var bounds = new GLatLngBounds();
 
    fc_node =  getElements(xmlhttp, "wfs", "FeatureCollection")[0];
													
	if (fc_node == null)
	    return;
	
	fm_nodes = getElements(fc_node,"gml","featureMembers");
	
	if (fm_nodes == null)
	    return;
	
	if (fm_nodes.length ==0)
	    return;
	
	fm = fm_nodes[0];
    //GLog.write(xmlhttp.xml); 	
	var geoLayers = featureType.split(",");
	
	var flag = false;
	
	var scheduledDate = new Date();
    var currentDate  = new Date();       
	
	for(var i = geoLayers.length-1; i >= 0; i--)
	{	
	    //* Incidents, Events, Construction
	    var	eventID = "";
	    var linkRoadDesignator = "";
	    var crossStreet = "";
	    var Description1 = "";
		var Description2 = "";				
	    var Description3 = "";		    
	    var Description4 = "";	
	    var incidentResponseStatus = "";
	    var eventIndicatorStatus = "";
	    var estimatedDuration = "";	 
	    var affectedLanesCount = 0;
	    var lanesAffected = 0;
	    var totalLanesCount = 0;   	    
	    var startTime = "";
	    var infoSourceOrganizationName = "";
	    var assocDeviceID = "";
	    var assocDeviceType = "";
	    var iconImage = "";   	      	             
                        
        //* Links        
        var	LinkID = "";
        var	linkLength = "";
        var	linkOnStreetName = "";
        var	linkDataType = "";
        var	linkSpeed = "";
        var	linkSpeedLimit = "";
        var	linkTravelTime = "";
        var	SpeedLimitTravelTime = "";
        var	LastUpdated = ""; 
                
        var SpeedLimitMPH = "";
        var SpeedMPH = "";
        var SpeedPercent = "";
        var SpeedBand = "";
        var linkOnStreetName = "";
        var FromRoad = "";
        var ToRoad = "";
        var CityName = "";
        
        //* Cameras        
        var deviceID = "";
        var displayName = "";
        var cctvFileName = "";
        var routeDesignator = "";
        var routeDirection = "";
        
        //* Node
        var NodeID = "";
        var nodeDesc = "";
        var nodeCity = "";
                
        var layerName = "";                                        		    
		
		var	poi_nodes = getElements(fm,"topp",geoLayers[i].split(":")[1]); 				
										
		if ( poi_nodes != null && poi_nodes.length > 0)
		{			
			for(var j = poi_nodes.length-1; j >= 0; j--)
			{
			    poi_feature = poi_nodes[j];	
		         	
		        //GLog.write(geoLayers[i].split(":")[1]); 	 
		        
		        if (getElements(poi_feature, "topp", "incidentID")[0] != null)
		           eventID = getElements(poi_feature, "topp", "incidentID")[0].firstChild.nodeValue;  
		           
		        if(getElements(poi_feature, "topp", "LinkID")[0] != null)	    		   			        		    
		           LinkID = getElements(poi_feature, "topp", "LinkID")[0].firstChild.nodeValue;   
		           
		        if(getElements(poi_feature, "topp", "deviceID")[0] != null)	    		   			        		    
		           deviceID = getElements(poi_feature, "topp", "deviceID")[0].firstChild.nodeValue;   
		           
		        if(getElements(poi_feature, "topp", "NodeID")[0] != null)	    		   			        		    
		           NodeID = getElements(poi_feature, "topp", "NodeID")[0].firstChild.nodeValue;   
		         
	         
		        if (eventID != "")			        
			       layerName = "event";    // incidents, events, construction
                if (LinkID != "")			        
			       layerName = "link";     
			    if (deviceID != "")			        
			       layerName = "camera"; 
			    if (NodeID != "")			        
			       layerName = "node";   
			       
			       
			    if (layerName == "node")
			    {
			        if (getElements(poi_feature, "topp", "Description")[0] != null)
	                {        
                        if (getElements(poi_feature, "topp", "Description")[0].firstChild != null)
                            nodeDesc = getElements(poi_feature, "topp", "Description")[0].firstChild.nodeValue;   
	                } 
	                if (getElements(poi_feature, "topp", "City")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "City")[0].firstChild != null)
		                    nodeCity = getElements(poi_feature, "topp", "City")[0].firstChild.nodeValue;        
	                } 
			        break;   
			    }     			    
		     
		        if (showInfo == "")
		        {
		            //******************** Incidents, Events, Constructions *************************************************************
		            // incidentID, linkRoadDesignator, crossStreet, Description1, Description2, Description3, 
		            // Description4, incidentResponseStatus, eventIndicatorStatus, 
                    // estimatedDuration, affectedLanesCount, lanesAffected, totalLanesCount, startTime, 
                    // infoSourceOrganizationName, assocDeviceID, assocDeviceType, iconImage
                        			    
			        if (getElements(poi_feature, "topp", "linkRoadDesignator")[0] != null)
	                {      
                        if (getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild != null)
                            linkRoadDesignator = getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild.nodeValue;
	                }     	            
	                if (getElements(poi_feature, "topp", "crossStreet")[0] != null)
	                {        
                        if (getElements(poi_feature, "topp", "crossStreet")[0].firstChild != null)
                            crossStreet = getElements(poi_feature, "topp", "crossStreet")[0].firstChild.nodeValue;   
	                } 
	                if (getElements(poi_feature, "topp", "Description1")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "Description1")[0].firstChild != null)
		                    Description1 = getElements(poi_feature, "topp", "Description1")[0].firstChild.nodeValue;        
	                } 
	                if (getElements(poi_feature, "topp", "Description2")[0] != null)
	                {            
                        if (getElements(poi_feature, "topp", "Description2")[0].firstChild != null)
		                    Description2 = getElements(poi_feature, "topp", "Description2")[0].firstChild.nodeValue;        
	                } 
	                if (getElements(poi_feature, "topp", "Description3")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "Description3")[0].firstChild != null)
                            Description3 = getElements(poi_feature, "topp", "Description3")[0].firstChild.nodeValue;
	                }    			    
			        if (getElements(poi_feature, "topp", "Description4")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "Description4")[0].firstChild != null)
                            Description4 = getElements(poi_feature, "topp", "Description4")[0].firstChild.nodeValue;
	                }   	                	               			    
		            if(getElements(poi_feature, "topp", "incidentResponseStatus")[0] != null)
		            {			    
		                if(getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild != null)			    
		                    incidentResponseStatus = getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild.nodeValue;
		            }    			       		        			    
		            if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0] != null)
		            {
		                if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild != null)
		                    eventIndicatorStatus = getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild.nodeValue;
		            }      
    		        if (getElements(poi_feature, "topp", "estimatedDuration")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild != null)
                            estimatedDuration = getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild.nodeValue; 
                    }         		            		    
		            if (getElements(poi_feature, "topp", "affectedLanesCount")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild != null)
                            affectedLanesCount = getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild.nodeValue;
	                }                	                   	           	                   	                
                    if (getElements(poi_feature, "topp", "lanesAffected")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "lanesAffected")[0].firstChild != null)
                            lanesAffected = getElements(poi_feature, "topp", "lanesAffected")[0].firstChild.nodeValue;
	                }    	            
	                if (getElements(poi_feature, "topp", "totalLanesCount")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild != null)
                            totalLanesCount = getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "startTime")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "startTime")[0].firstChild != null)
                            startTime = getElements(poi_feature, "topp", "startTime")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild != null)
                            infoSourceOrganizationName = getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "assocDeviceID")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild != null)
                            assocDeviceID = getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "assocDeviceType")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild != null)
                            assocDeviceType = getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild.nodeValue;
	                }    	                	            
	                if (getElements(poi_feature, "topp", "iconImage")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "iconImage")[0].firstChild != null)
                            iconImage = getElements(poi_feature, "topp", "iconImage")[0].firstChild.nodeValue;
	                }  
	                if (getElements(poi_feature, "topp", "updateTime")[0] != null)
		            {        
                        if (getElements(poi_feature, "topp", "updateTime")[0].firstChild != null)
                            LastUpdated = getElements(poi_feature, "topp", "updateTime")[0].firstChild.nodeValue;
	                }                 	               
                    
                    //********************************** vwLink **************************************
                    //LinkID, SpeedLimitMPH, SpeedMPH, SpeedPercent, SpeedBand, linkOnStreetName, FromRoad, ToRoad, CityName
                    if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild != null)
                            SpeedLimitMPH = getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedMPH")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild != null)
                            SpeedMPH = getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedPercent")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild != null)
                            SpeedPercent = getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "SpeedBand")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "SpeedBand")[0].firstChild != null)
                            SpeedBand = getElements(poi_feature, "topp", "SpeedBand")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "linkOnStreetName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild != null)
                            linkOnStreetName = getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "FromRoad")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "FromRoad")[0].firstChild != null)
                            FromRoad = getElements(poi_feature, "topp", "FromRoad")[0].firstChild.nodeValue; 
                    }
                    if (getElements(poi_feature, "topp", "ToRoad")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "ToRoad")[0].firstChild != null)
                            ToRoad = getElements(poi_feature, "topp", "ToRoad")[0].firstChild.nodeValue; 
                    }
                    if (getElements(poi_feature, "topp", "CityName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "CityName")[0].firstChild != null)
                            CityName = getElements(poi_feature, "topp", "CityName")[0].firstChild.nodeValue; 
                    }                                                                               
                    if (getElements(poi_feature, "topp", "LastUpdated")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "LastUpdated")[0].firstChild != null)
                            LastUpdated = getElements(poi_feature, "topp", "LastUpdated")[0].firstChild.nodeValue; 
                    }                      
                    //**************************** Cameras **************************************
                    //deviceID, displayName, cctvFileName, routeDesignator, routeDirection
//                    if(getElements(poi_feature, "topp", "deviceID")[0] != null)	    		   			        		    
//		                deviceID = getElements(poi_feature, "topp", "deviceID")[0].firstChild.nodeValue;
    			    
                    if (getElements(poi_feature, "topp", "displayName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "displayName")[0].firstChild != null)
                            displayName = getElements(poi_feature, "topp", "displayName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "cctvFileName")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "cctvFileName")[0].firstChild != null)
                            cctvFileName = getElements(poi_feature, "topp", "cctvFileName")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "routeDesignator")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "routeDesignator")[0].firstChild != null)
                            routeDesignator = getElements(poi_feature, "topp", "routeDesignator")[0].firstChild.nodeValue; 
                    } 
                    if (getElements(poi_feature, "topp", "routeDirection")[0] != null)
	                {        	                
                        if (getElements(poi_feature, "topp", "routeDirection")[0].firstChild != null)
                            routeDirection = getElements(poi_feature, "topp", "routeDirection")[0].firstChild.nodeValue; 
                    }                                                                               
    	                
                    //******************************************************************************* 
                }
                else    // showInfo != ""
                {                                        
                    if (htmlInfoWindow == "")
                        htmlInfoWindow = createEventInfoWindow(poi_feature, layerName);
                    else
                        htmlInfoWindow = htmlInfoWindow + "~" + createEventInfoWindow(poi_feature, layerName);
                                              
                }

                var textColor = "";   //"#000000";	black	                                                                       				                             
                                                                                           	          
			    if (showInfo == "")		
			    {	 			    
			        if (crossStreet != "")
			            crossStreet = " at " + crossStreet;		
			            
			        if (eventID != "")
			        {
			            //layerName = "event";    // incidents, events, construction
			            textColor = "#000000";	// black color
			            
			            if (ttValue == "")    
	                        ttValue = linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;    
	                    else
	                        ttValue = ttValue + delimiter + linkRoadDesignator + "~" + Description1 + "~" + crossStreet + "~" + textColor + "~" + layerName;
			        }    
			        if (LinkID != "")
			        {
			            //layerName = "link";       
			            textColor = "#000099";  //blue color
			            
			            if (ttValue == "")    
	                        ttValue = "Link: " + linkOnStreetName + "~" + "; Speed: " + Math.round(SpeedMPH) + "~" + "" + "~" + textColor + "~" + layerName;    
	                    else
	                        ttValue = ttValue + delimiter + "Link: " + linkOnStreetName + "~" + "; Speed: " + Math.round(SpeedMPH) + "~" + "" + "~" + textColor + "~" + layerName;
			        }      
			        if (deviceID != "")
			        {
			            //layerName = "camera";
			            textColor = "#009900";	// green color
			            
			            if (ttValue == "")    
	                        ttValue = displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;    
	                    else
	                        ttValue = ttValue + delimiter + displayName + "~" + " " + routeDirection + "~" + "" + "~" + textColor + "~" + layerName;
			        }    			           			        		     
			        			                             
                }                                                			                      
                
                flag = true;
                
                document.body.style.cursor = 'pointer';		          		    
		    }		   	    		        
		}		
		//GLog.write('3=' + htmlInfoWindow);
		fc_node=null;
		poi_nodes=null;		
		
		if (layerName == "node")
		    break;
					
	}    
  
    if (layerName != "node")
    {        
     	
        if (showInfo == "")		
        {	//* show Event tooltip  
            if (ttValue != "")   		                                  
                showMultiTooltipEvent(ttValue, lon, lat);	
        }    
        else
        {   //GLog.write('final=' + htmlInfoWindow);
              //* show Event Info
              if (htmlInfoWindow != "")
              {
                var arr1 = new Array();
                var arr2 = new Array();
                var legend = "";
                var incCaption = "";
                var linkCaption = "";
                var camCaption = "";
                
                var outputHeader = '<div style="width:100%; background-color:#9cbdde">';
                outputHeader += '<img src="images/sandag511-logo-popup.jpg" alt="San Diego 511 Logo" width="100" height="49">';
                outputHeader += '</div>';
                //outputHeader += '</div><br />';
             
                //if (legend != "" && legend != undefined)
                legend = getLaneViewLegend("400px");
                //else
                //    legend = "";
                
                arr1 = htmlInfoWindow.split("~"); 
                          
                htmlInfoWindow = "";
                //alert(arr1.length);   
                for(j = 0; j < arr1.length; j++)
                {
                    if (arr1[j] != "")
                    {
                        arr2 = arr1[j].split("^");                    
                                            
                        //alert(arr2[2]);   
                        if (arr2[2] == "incident")
                        {
                            if (incCaption == "")
                            {
                                //incCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Incidents</h5></div>';
                                incCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Incidents</u></div>';
                                
                                htmlInfoWindow = incCaption + legend + arr2[0];
                            }                                                  
                            else
                                htmlInfoWindow = htmlInfoWindow + arr2[0]; 
                        }    
                        else if (arr2[2] == "camera")
                        {
                            if (camCaption == "")
                            {
                                //camCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Cameras</h5></div>';  
                                camCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Cameras</u></div>';
                                
                                htmlInfoWindow = htmlInfoWindow + camCaption + arr2[0];
                            }   
                            else
                                htmlInfoWindow = htmlInfoWindow + arr2[0];                   
                        }
                        else  // link
                        {
                            if (linkCaption == "")
                            {
                                //linkCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center"><h5>Speed Information</h5></div>';
                                linkCaption = '<div style="font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;font-weight:bold;font-size:13px;"><u>Speed Information</u></div>';
                                htmlInfoWindow = htmlInfoWindow + linkCaption + arr2[0];                                
                            }
                            else
                                htmlInfoWindow = htmlInfoWindow + arr2[0];
                            //camCaption = '<div style="text-align:center"><h5>Speed Information</h5></div><br />';
                            //outputHTML += "<br /><div style='text-align:center;font-weight:bold;font-size:12px;'>Speed Information</div><br />";
                            
                        }
                          
                                                    
                        //htmlInfoWindow = htmlInfoWindow + arr2[0];   
                        //break;                
                    }               
                    
                }                   
                 
                showEventInfoWindow(outputHeader + htmlInfoWindow, lon, lat, arr1.length);   
                //showEventInfoWindow(outputHeader + legend + htmlInfoWindow, lon, lat);               
              }                             
        }    
    }
    else
    {
        showDrivingTimeStartEndWindow(NodeID, nodeDesc, nodeCity, lat, lon);
    }
                     
	
	if (flag == false && showInfo == "")	
	{	
	    hideEventTooltip();  	   
	    hideNodeTooltip();
	}						  
					   	   	       
}

function createEventInfoWindowChrome(fm_nodes, eventType, geoLayer)
{
    //* Incidents
    var linkRoadDesignator = "";
    var crossStreet = "";
    var Description1 = "";
	var Description2 = "";				
    var Description3 = "";		    
    var Description4 = "";	
    var incidentResponseStatus = "";
    var eventIndicatorStatus = "";
    var estimatedDuration = "Unknown";	 
    var affectedLanesCount = "0";
    var lanesAffected = "0";
    var totalLanesCount = "0";   	    
    var startTime = "";
    var infoSourceOrganizationName = "";
    var assocDeviceID = "";
    var assocDeviceType = "";
    var iconImage = "";
    var cameraPath = "";
    var appImgBaseUrl = "";
    var displayName = "";
    var lanesAffectedGraphic = "";
    var laneCount = "";
    var laneIndex;
    var eventID = "";
    var endTime = "";
    
    var LastUpdated = "";
    
    //* Links
    var LinkID = "";
    var SpeedLimitMPH = "";
    var SpeedMPH = "";
    var SpeedPercent = "";
    var SpeedBand = "";
    var linkOnStreetName = "";
    var FromRoad = "";
    var ToRoad = "";
    var CityName = "";
    
    //* Camera
    var deviceID = "";
    var displayName = "";
    var cctvFileName = "";
    
    //* Node
    var NodeID = "";
    
    var camNameArr = new Array();
    var camDisplayNameArr = new Array();
    
    var incidentDescription = "Description unavailable";
    var status = "Not Specified";
    var camerasHtml = "";
    
    var makeCollapsable = true;
    var showLegend = true;
    
    var outputHTML = "";	
    var returnHtml = "";   
       
    if (eventType == "event")
        eventType = "incident";   
     
    
    for(var j = 0; j < fm_nodes.length; j++)
    {
        //tagValue = fc_node[0].childNodes[i].tagName;        
        //tagValue1 = fm_nodes[j].tagName;
    
        switch (geoLayer.tagName) {
        //case "topp:vwLink","topp:vwLink1","topp:vwLink2","topp:vwLink3":
        case "topp:vwLink": case "topp:vwLink1": case "topp:vwLink2": case "topp:vwLink3": case "topp:vwLink15": case "topp:vwLink16":
	        switch (fm_nodes[j].tagName) {
            case "topp:LinkID":
    		    LinkID = fm_nodes[j].textContent;                                  
	            break;    		
            case "topp:SpeedLimitMPH":
    		    SpeedLimitMPH = fm_nodes[j].textContent;
	            break;		
	        case "topp:SpeedMPH":
    		    SpeedMPH = fm_nodes[j].textContent;
	            break;
	        case "topp:SpeedPercent":
    		    SpeedPercent = fm_nodes[j].textContent;
	            break;
	        case "topp:SpeedBand":
    		    SpeedBand = fm_nodes[j].textContent;
	            break;
	        case "topp:linkOnStreetName":
    		    linkOnStreetName = fm_nodes[j].textContent;
	            break;
	        case "topp:FromRoad":
    		    FromRoad = fm_nodes[j].textContent;
	            break;
	        case "topp:ToRoad":
    		    ToRoad = fm_nodes[j].textContent;
	            break;
            case "topp:CityName":
		        CityName = fm_nodes[j].textContent;
                break;
            case "topp:LastUpdated":
		        LastUpdated = fm_nodes[j].textContent;
                break;	                                  
            default:        		    
            }   
	        break;    		
        case "topp:vwTripNodes":
		    switch (fm_nodes[j].tagName) {
            case "topp:NodeID":
    		    NodeID = fm_nodes[j].textContent;                                  
	            break;    		
            case "topp:Description":
    		    nodeDesc = fm_nodes[j].textContent;
	            break;		
	        case "topp:City":
    		    nodeCity = fm_nodes[j].textContent;
	            break;		                                          
            default:        		    
            }   
	        break;	
	    case "topp:vwCamera":
		    switch (fm_nodes[j].tagName) {
            case "topp:deviceID":
    		    deviceID = fm_nodes[j].textContent;                                  
	            break;    		
            case "topp:displayName":
    		    displayName = fm_nodes[j].textContent;
	            break;		
	        case "topp:cctvFileName":
    		    cctvFileName = fm_nodes[j].textContent;
		    if (cctvFileName != "")            
                	cctvFileName = cctvFileName + '?' + new Date().getTime(); 
	            break;		
	        case "topp:routeDesignator":
    		    routeDesignator = fm_nodes[j].textContent;
	            break;
	        case "topp:routeDirection":
    		    routeDirection = fm_nodes[j].textContent;
	            break; 
	        case "topp:appImgBaseUrl":
    		    appImgBaseUrl = fm_nodes[j].textContent;
	            break;                                                     
            default:        		    
            }   
	        break;    		       		        	
        default:        	        
		    switch (fm_nodes[j].tagName) {
            case "topp:incidentID":
    		    eventID = fm_nodes[j].textContent;                                  
	            break;    		
            case "topp:linkRoadDesignator":
    		    linkRoadDesignator = fm_nodes[j].textContent;
	            break;		
	        case "topp:crossStreet":
    		    crossStreet = fm_nodes[j].textContent;
	            break;		
	        case "topp:Description1":
    		    Description1 = fm_nodes[j].textContent;
	            break;
	        case "topp:Description2":
    		    Description2 = fm_nodes[j].textContent;
	            break;     
	        case "topp:Description3":
    		    Description3 = fm_nodes[j].textContent;
	            break; 
	        case "topp:Description4":
    		    Description4 = fm_nodes[j].textContent;
	            break; 
	        case "topp:incidentResponseStatus":
    		    incidentResponseStatus = fm_nodes[j].textContent;
	            break; 
	        case "topp:eventIndicatorStatus":
    		    eventIndicatorStatus = fm_nodes[j].textContent;
	            break; 
	        case "topp:estimatedDuration":
    		    estimatedDuration = fm_nodes[j].textContent;
	            break; 
	        case "topp:affectedLanesCount":
    		    affectedLanesCount = fm_nodes[j].textContent;
	            break; 
	        case "topp:lanesAffected":
    		    lanesAffected = fm_nodes[j].textContent;
	            break; 
	        case "topp:totalLanesCount":
    		    totalLanesCount = fm_nodes[j].textContent;
	            break; 
	        case "topp:startTime":
    		    startTime = fm_nodes[j].textContent;
	            break; 
	        case "topp:infoSourceOrganizationName":
    		    infoSourceOrganizationName = fm_nodes[j].textContent;
	            break; 
	        case "topp:endTime":
    		    endTime = fm_nodes[j].textContent;
	            break; 
	        case "topp:assocDeviceID":
    		    assocDeviceID = fm_nodes[j].textContent;
	            break; 
	        case "topp:assocDeviceType":
    		    assocDeviceType = fm_nodes[j].textContent;
	            break; 
	        case "topp:iconImage":
    		    iconImage = fm_nodes[j].textContent;
	            break;   
	        case "topp:cameraPath":
    		    cameraPath = fm_nodes[j].textContent;
	            break;
	        case "topp:appImgBaseUrl":
    		    appImgBaseUrl = fm_nodes[j].textContent;
	            break;
	        case "topp:displayName":
    		    displayName = fm_nodes[j].textContent;
	            break;
	        case "topp:updateTime":
    		    //updateTime = fm_nodes[j].textContent;
    		    LastUpdated = fm_nodes[j].textContent;
	            break;		                                                
            default:        		    
            }   
        }                                                                                        
    }      
        
    //**************************************************************************************************
    if (LinkID == "" && deviceID == "")
    {
        if (Description1 != "")
            incidentDescription = Description1;
        else if (Description2 != "")
            incidentDescription = Description2;
        else if (Description3 != "")
        {
            //For incidents, Description3 is incidentCategory, and if this is = "closures" then we change the text
            incidentDescription = Description3;
            if (eventType == "incident") 
                incidentDescription = "Closure of a Road";
        }
        else if (Description4 != "")
            incidentDescription = Description4;                        
       
        if (incidentResponseStatus != "")
            status = incidentResponseStatus;
        else if (eventIndicatorStatus != "")
            status = eventIndicatorStatus;   
                        
        if (estimatedDuration != "Unknown" && estimatedDuration != "0")
            estimatedDuration = (estimatedDuration/60) + " min.";
                   
                
       //alert(appImgBaseUrl + ',' + cameraPath);
        //If Not IsNull(detailRecordset("assocDeviceID")) And Not IsNull(detailRecordset("assocDeviceType")) And Len(Trim(detailRecordset("assocDeviceID"))) > 0 And Len(Trim(detailRecordset("assocDeviceType"))) > 0 Then
        //if (assocDeviceID != "" && assocDeviceType != "")  
        if (cameraPath != "" && displayName != "")
        {      
            //Call getCameraData.  Send makeCollapsable as the value for getCameraData's "newWindow"
            //variable because if makeCollapsable is true (text incident pages), then we want images to
            //open in a new window.  Otherwise, if makeCollapsable is false (event_popup), we want images
            //to appear in the popup window.
            //camerasHtml = getCameraData(assocDeviceID, assocDeviceType);
            
            camNameArr = cameraPath.split(";");
            camDisplayNameArr = displayName.split(";");
                    
            for (var i = 0; i < camNameArr.length; i++)
            {       
                camerasHtml = camerasHtml + '<strong>' + camDisplayNameArr[i] + '</strong><br />';
		        camerasHtml = camerasHtml + '<img style="border-style:solid; border-width:1px; border-color:blue" src="' + 
		                    appImgBaseUrl + camNameArr[i] + '" alt="' + camDisplayNameArr[i] + 
		                    '" width="160" height="120" /> <br />';                
            }            
        }
        //alert(camerasHtml);
        //**********************************
         //alert('affectedLanesCount=' + affectedLanesCount);
         
        if (affectedLanesCount != "" && affectedLanesCount != "0")
        {    
            //lanesAffected = detailRecordset("lanesAffected")
            laneCount = parseInt(totalLanesCount);
                
            lanesAffectedGraphic = lanesAffectedGraphic + '<table class="LaneInfo" style="border-collapse: collapse;" >';
            lanesAffectedGraphic = lanesAffectedGraphic + '<tr class="LaneInfo" style="border: none;padding: 0px;margin: 0px;">';
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">SHLDR</span></td>';
            
            for (laneIndex = 0; laneIndex < laneCount; laneIndex++)   
            {             
                if (laneIndex > 0) 
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"></td>';
                
                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">LANE<br/># ' + (laneIndex+1) + '</span></td>';                
            } 
               
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">OFF<br/>RAMP</span></td>';
            lanesAffectedGraphic = lanesAffectedGraphic + '</tr>';
            lanesAffectedGraphic = lanesAffectedGraphic + '<tr class = "LaneInfo" style="border: none;padding: 0px;margin: 0px;">';
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_shoulder.jpg" alt="Open Shoulder" /></td>';
                
            //For laneIndex = 0 to (laneCount-1) 
            for (laneIndex = 0; laneIndex < laneCount; laneIndex++) 
            {
                if (laneIndex > 0) 
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" alt="Lane Striping" /></td>';
                   
                if (lanesAffected != "" && lanesAffected != "0")  
                {
                    switch (lanesAffected) {
		            case "1":
			            if (laneIndex == 0)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
		            case "2":
			            if (laneIndex == 1)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
		            case "3":
			            if (laneIndex == 0 || laneIndex == 1)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
			        case "4":
			            if (laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;  
			        case "6":
			            if (laneIndex == 1 || laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;        
			        case "7":
			            if (laneIndex == 0 || laneIndex == 1 || laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break; 
			        case "8":
			            if (laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;       
			        case "12":
			            if (laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;    
			        case "14":
			            if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;      
			        case "15":
			            if (laneIndex == 0 || laneIndex == 1 || laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;   
			        case "16":
			            if (laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;       
			        case "24":
			            if (laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;    
			        case "28":
			            if (laneIndex == 2 || laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;     
			        case "30":
			            if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;           
		            default: //"31"
		                if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3 || laneIndex == 4 || laneIndex == 5)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break; 
    			        
	                }	            
	            }	            
	            
            }
            
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_ramp.jpg" alt="Open Ramp" /></td>';
            lanesAffectedGraphic = lanesAffectedGraphic + '</tr></table>';

	        //If this graphic is being displayed on event_popup.asp, widen the window if necessary
    	    
	        /*
		    if (laneCount > 3) 
		    {
		         //Default popup window size is 425.  Add width for each lane over 3
		         Dim newWidth
		         newWidth = ((laneCount - 3) * 31) + 425
		         outputHTML = outputHTML & "<script type=""text/javascript"">"
		         outputHTML = outputHTML & "if (document.body.clientWidth < " & newWidth & ") { window.resizeTo(" & newWidth & ",450);}"
		         outputHTML = outputHTML & "</script>"
		    }
	        */
        }                       
             
        //For incidents, Description4 = incidentType
        if (eventType == "incident" && Description4 == "closed") 
	        iconImage = '<img src="images/icon_closures.gif" width="16" height="16" alt="Closure">';	    
           	
        outputHTML = outputHTML + iconImage + ' &nbsp; <span class="IncidentTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;font-weight:bold;">' + linkRoadDesignator + '</span><br />';
        
        if (makeCollapsable == true) 
            outputHTML = outputHTML + '<div class="expandCCTVHeader" style="font-size: 9pt;font-family:Arial,Verdana,Helvetica,sans-serif;" id="' + eventID + '">';
        else
            outputHTML = outputHTML + '<div style="font-size:12px;">';
        
        if (incidentDescription == "Description unavailable" || crossStreet == "")
            outputHTML = outputHTML + incidentDescription;
        else
            outputHTML = outputHTML + incidentDescription + " at " + crossStreet;
        
        outputHTML = outputHTML + '</div>';
            
        //Status box
        if (makeCollapsable == true)
            outputHTML = outputHTML + '<div class="collapsibleCCTVSection">';
            //outputHTML = outputHTML + '<div class="collapsibleCCTVSection" style="width:600px;">';
        
        outputHTML = outputHTML + '<div style="float:left; padding-right:25px;font-size:9pt;font-family: Arial, Verdana, Helvetica, sans-serif;">';
       
        //If LCase(queryType) = "incident" OR LCase(queryType) = "construction" Then
        if (Description3 != "") // incident or construction
        {
            outputHTML = outputHTML + "Status: " + status + "<br />";
            outputHTML = outputHTML + "Start Time: " + getFormattedDate(startTime) + "<br />";
            outputHTML = outputHTML + "Estimated Duration: " + estimatedDuration + "<br />";
            outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<hr />";
            //outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<br />";
        }    
        else    // event
        {
            outputHTML = outputHTML + "Start Time: " + getFormattedDate(startTime) + "<br />";
            outputHTML = outputHTML + "End Time: ";
            if (parseInt(estimatedDuration) > 0)
                outputHTML = outputHTML + getFormattedDate(endTime);
            else
                outputHTML = outputHTML + "Unknown<br />";
           
            outputHTML = outputHTML + "Status: " + status + "<br />";
            outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<hr />";
            //outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<br />";
            
        }
        //outputHTML = outputHTML & "Information Source: " & detailRecordset("infoSourceOrganizationName") & "<br />"
        if (camerasHtml != "")
            outputHTML = outputHTML + "Nearest Camera(s): <br />" + camerasHtml;
        
        outputHTML = outputHTML + "</div>";

        //Lanes Affected Graphic
        if (lanesAffectedGraphic != "") 
        {
            outputHTML = outputHTML + "<div>";            
            outputHTML = outputHTML + '<span style="font-weight:bold; text-decoration:underline;font-size:9pt;font-family:Arial,Verdana,Helvetica,sans-serif;">Incident Location</span><br />';
            outputHTML = outputHTML + lanesAffectedGraphic;
            outputHTML = outputHTML + "</div>";            
        }           
                        
        //Close expand/collapse div
        outputHTML = outputHTML + '<br clear="left" />';
        
        if (makeCollapsable == true) 
            outputHTML = outputHTML + "</div><br />";
            
        //alert(outputHTML);
      
    } 
       
    if (LinkID != "")
    {             
        var speed = "";
        
        if (parseInt(Math.round(SpeedMPH)) < parseInt(SpeedLimitMPH)-5)
            speed = parseInt(Math.round(SpeedMPH));
        else
            speed = parseInt(SpeedLimitMPH)-5 + " mph or higher"; 
       
        //* Check for speed information
        //outputHTML += "<br /><div style='text-align:center;font-weight:bold;font-size:12px;'>Speed Information</div><br />";
        outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Route:</b> " + linkOnStreetName + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>From:</b> " + FromRoad + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>To:</b> " + ToRoad + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>City:</b> " + CityName + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Speed limit:</b> " + SpeedLimitMPH + "<br />";
		if (SpeedMPH != "")
            outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Traffic speed:</b> " + speed + "<br />";
        else
            outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Traffic speed:</b> " + "No data" + "<br />";
    
        outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Last Updated:</b> " + getFormattedDate(LastUpdated) + "</div><hr />";
        //outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Last Updated:</b> " + getFormattedDate(LastUpdated) + "</div><br />";
    }
    
    if (deviceID != "")
    {        
        outputHTML += "<table align='center' style='text-align:left;'><tr><td><img src='images/icon_camera.gif' width='18' height='18' /></td>";
        outputHTML += "<td><div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-weight: bold;font-size:12px;'>" + displayName + "</div></td></tr></table>";
    	outputHTML += "<div style='font-size:12px;text-align:center;'><img src='" + appImgBaseUrl + cctvFileName + "' width='320' height='240' border='1' alt='image' ></div><br /><br />";
    
    }                                          
                
    return outputHTML + "^" + lanesAffectedGraphic + "^" + eventType;         
                

}

function createEventInfoWindow(poi_feature, eventType)
{    
    //* Incidents
    var linkRoadDesignator = "";
    var crossStreet = "";
    var Description1 = "";
	var Description2 = "";				
    var Description3 = "";		    
    var Description4 = "";	
    var incidentResponseStatus = "";
    var eventIndicatorStatus = "";
    var estimatedDuration = "Unknown";	 
    var affectedLanesCount = "0";
    var lanesAffected = "0";
    var totalLanesCount = "0";   	    
    var startTime = "";
    var infoSourceOrganizationName = "";
    var assocDeviceID = "";
    var assocDeviceType = "";
    var iconImage = "";
    var cameraPath = "";
    var appImgBaseUrl = "";
    var displayName = "";
    var lanesAffectedGraphic = "";
    var laneCount = "";
    var laneIndex;
    var eventID = "";
    var endTime = "";
    
    var LastUpdated = "";
    
    //* Links
    var LinkID = "";
    var SpeedLimitMPH = "";
    var SpeedMPH = "";
    var SpeedPercent = "";
    var SpeedBand = "";
    var linkOnStreetName = "";
    var FromRoad = "";
    var ToRoad = "";
    var CityName = "";
    
    //* Camera
    var deviceID = "";
    var displayName = "";
    var cctvFileName = "";
    
    //* Node
    var NodeID = "";
    
    var camNameArr = new Array();
    var camDisplayNameArr = new Array();
    
    var incidentDescription = "Description unavailable";
    var status = "Not Specified";
    var camerasHtml = "";
    
    var makeCollapsable = true;
    var showLegend = true;
    
    var outputHTML = "";	
    var returnHtml = "";   
        
    if (eventType == "event")
        eventType = "incident";        

    //*********************************************************************************************
    if (getElements(poi_feature, "topp", "incidentID")[0] != null)
		 eventID = getElements(poi_feature, "topp", "incidentID")[0].firstChild.nodeValue;  
		           
    if (getElements(poi_feature, "topp", "linkRoadDesignator")[0] != null)
    {      
        if (getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild != null)
            linkRoadDesignator = getElements(poi_feature, "topp", "linkRoadDesignator")[0].firstChild.nodeValue;
    }     	            
    if (getElements(poi_feature, "topp", "crossStreet")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "crossStreet")[0].firstChild != null)
            crossStreet = getElements(poi_feature, "topp", "crossStreet")[0].firstChild.nodeValue;   
    } 
    if (getElements(poi_feature, "topp", "Description1")[0] != null)
    {            
        if (getElements(poi_feature, "topp", "Description1")[0].firstChild != null)
            Description1 = getElements(poi_feature, "topp", "Description1")[0].firstChild.nodeValue;        
    } 
    if (getElements(poi_feature, "topp", "Description2")[0] != null)
    {            
        if (getElements(poi_feature, "topp", "Description2")[0].firstChild != null)
            Description2 = getElements(poi_feature, "topp", "Description2")[0].firstChild.nodeValue;        
    } 
    if (getElements(poi_feature, "topp", "Description3")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "Description3")[0].firstChild != null)
            Description3 = getElements(poi_feature, "topp", "Description3")[0].firstChild.nodeValue;
    }    			    
    if (getElements(poi_feature, "topp", "Description4")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "Description4")[0].firstChild != null)
            Description4 = getElements(poi_feature, "topp", "Description4")[0].firstChild.nodeValue;
    }   	                	               			    
    if(getElements(poi_feature, "topp", "incidentResponseStatus")[0] != null)
    {			    
        if(getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild != null)			    
            incidentResponseStatus = getElements(poi_feature, "topp", "incidentResponseStatus")[0].firstChild.nodeValue;
    }    			       		        			    
    if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0] != null)
    {
        if (getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild != null)
            eventIndicatorStatus = getElements(poi_feature, "topp", "eventIndicatorStatus")[0].firstChild.nodeValue;
    }      
    if (getElements(poi_feature, "topp", "estimatedDuration")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild != null)
            estimatedDuration = getElements(poi_feature, "topp", "estimatedDuration")[0].firstChild.nodeValue;       
            
        if (estimatedDuration == "0")
            estimatedDuration = "Unknown";       
             
    }             		            		    
    if (getElements(poi_feature, "topp", "affectedLanesCount")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild != null)
            affectedLanesCount = getElements(poi_feature, "topp", "affectedLanesCount")[0].firstChild.nodeValue;
    }                	                   	           	                   	                
    if (getElements(poi_feature, "topp", "lanesAffected")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "lanesAffected")[0].firstChild != null)
            lanesAffected = getElements(poi_feature, "topp", "lanesAffected")[0].firstChild.nodeValue;
    }    	            
    if (getElements(poi_feature, "topp", "totalLanesCount")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild != null)
            totalLanesCount = getElements(poi_feature, "topp", "totalLanesCount")[0].firstChild.nodeValue;
    }    	                	            
    if (getElements(poi_feature, "topp", "startTime")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "startTime")[0].firstChild != null)
            startTime = getElements(poi_feature, "topp", "startTime")[0].firstChild.nodeValue;
    }    	                	            
    if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild != null)
            infoSourceOrganizationName = getElements(poi_feature, "topp", "infoSourceOrganizationName")[0].firstChild.nodeValue;
    }    	                	            
    if (getElements(poi_feature, "topp", "assocDeviceID")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild != null)
            assocDeviceID = getElements(poi_feature, "topp", "assocDeviceID")[0].firstChild.nodeValue;
    }    	                	            
    if (getElements(poi_feature, "topp", "assocDeviceType")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild != null)
            assocDeviceType = getElements(poi_feature, "topp", "assocDeviceType")[0].firstChild.nodeValue;
    }    	                	            
    if (getElements(poi_feature, "topp", "iconImage")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "iconImage")[0].firstChild != null)
            iconImage = getElements(poi_feature, "topp", "iconImage")[0].firstChild.nodeValue;
    }   
    if (getElements(poi_feature, "topp", "cameraPath")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "cameraPath")[0].firstChild != null)
            cameraPath = getElements(poi_feature, "topp", "cameraPath")[0].firstChild.nodeValue;
    } 
    if (getElements(poi_feature, "topp", "appImgBaseUrl")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "appImgBaseUrl")[0].firstChild != null)
            appImgBaseUrl = getElements(poi_feature, "topp", "appImgBaseUrl")[0].firstChild.nodeValue;
    } 
    if (getElements(poi_feature, "topp", "displayName")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "displayName")[0].firstChild != null)
            displayName = getElements(poi_feature, "topp", "displayName")[0].firstChild.nodeValue;
    } 
    if (getElements(poi_feature, "topp", "endTime")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "endTime")[0].firstChild != null)
            endTime = getElements(poi_feature, "topp", "endTime")[0].firstChild.nodeValue;
    }    
    if (getElements(poi_feature, "topp", "updateTime")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "updateTime")[0].firstChild != null)
            LastUpdated = getElements(poi_feature, "topp", "updateTime")[0].firstChild.nodeValue;
    }
    
    //********************************** vwLink **************************************
    //LinkID, SpeedLimitMPH, SpeedMPH, SpeedPercent, SpeedBand, linkOnStreetName, FromRoad, ToRoad, CityName
    if(getElements(poi_feature, "topp", "LinkID")[0] != null)	    		   			        		    
		LinkID = getElements(poi_feature, "topp", "LinkID")[0].firstChild.nodeValue;   
    //alert(LinkID);		
    if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild != null)
            SpeedLimitMPH = getElements(poi_feature, "topp", "SpeedLimitMPH")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "SpeedMPH")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild != null)
            SpeedMPH = getElements(poi_feature, "topp", "SpeedMPH")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "SpeedPercent")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild != null)
            SpeedPercent = getElements(poi_feature, "topp", "SpeedPercent")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "SpeedBand")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "SpeedBand")[0].firstChild != null)
            SpeedBand = getElements(poi_feature, "topp", "SpeedBand")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "linkOnStreetName")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild != null)
            linkOnStreetName = getElements(poi_feature, "topp", "linkOnStreetName")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "FromRoad")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "FromRoad")[0].firstChild != null)
            FromRoad = getElements(poi_feature, "topp", "FromRoad")[0].firstChild.nodeValue; 
    }
    if (getElements(poi_feature, "topp", "ToRoad")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "ToRoad")[0].firstChild != null)
            ToRoad = getElements(poi_feature, "topp", "ToRoad")[0].firstChild.nodeValue; 
    }
    if (getElements(poi_feature, "topp", "CityName")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "CityName")[0].firstChild != null)
            CityName = getElements(poi_feature, "topp", "CityName")[0].firstChild.nodeValue; 
    }   
    if (getElements(poi_feature, "topp", "LastUpdated")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "LastUpdated")[0].firstChild != null)
            LastUpdated = getElements(poi_feature, "topp", "LastUpdated")[0].firstChild.nodeValue; 
    }
    //**************************** Cameras ***********************************************************                   
    if(getElements(poi_feature, "topp", "deviceID")[0] != null)	    		   			        		    
        deviceID = getElements(poi_feature, "topp", "deviceID")[0].firstChild.nodeValue;
    
    if (getElements(poi_feature, "topp", "displayName")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "displayName")[0].firstChild != null)
            displayName = getElements(poi_feature, "topp", "displayName")[0].firstChild.nodeValue; 
    } 
    if (getElements(poi_feature, "topp", "cctvFileName")[0] != null)
    {        	                
        if (getElements(poi_feature, "topp", "cctvFileName")[0].firstChild != null)
        {
            cctvFileName = getElements(poi_feature, "topp", "cctvFileName")[0].firstChild.nodeValue; 
            if (cctvFileName != "")            
                cctvFileName = cctvFileName + '?' + new Date().getTime();
            
        } 
    }   
    if (getElements(poi_feature, "topp", "appImgBaseUrl")[0] != null)
    {        
        if (getElements(poi_feature, "topp", "appImgBaseUrl")[0].firstChild != null)
            appImgBaseUrl = getElements(poi_feature, "topp", "appImgBaseUrl")[0].firstChild.nodeValue;
    }                                                                    
    	                  
    //**************************************************************************************************
    if (LinkID == "" && deviceID == "")
    {
        if (Description1 != "")
            incidentDescription = Description1;
        else if (Description2 != "")
            incidentDescription = Description2;
        else if (Description3 != "")
        {
            //For incidents, Description3 is incidentCategory, and if this is = "closures" then we change the text
            incidentDescription = Description3;
            if (eventType == "incident") 
                incidentDescription = "Closure of a Road";
        }
        else if (Description4 != "")
            incidentDescription = Description4;                        
       
        if (incidentResponseStatus != "")
            status = incidentResponseStatus;
        else if (eventIndicatorStatus != "")
            status = eventIndicatorStatus;   
                        
        if (estimatedDuration != "Unknown" && estimatedDuration != "0")
            estimatedDuration = (estimatedDuration/60) + " min.";
                   
                
       //alert(appImgBaseUrl + ',' + cameraPath);
        //If Not IsNull(detailRecordset("assocDeviceID")) And Not IsNull(detailRecordset("assocDeviceType")) And Len(Trim(detailRecordset("assocDeviceID"))) > 0 And Len(Trim(detailRecordset("assocDeviceType"))) > 0 Then
        //if (assocDeviceID != "" && assocDeviceType != "")  
        if (cameraPath != "" && displayName != "")
        {      
            //Call getCameraData.  Send makeCollapsable as the value for getCameraData's "newWindow"
            //variable because if makeCollapsable is true (text incident pages), then we want images to
            //open in a new window.  Otherwise, if makeCollapsable is false (event_popup), we want images
            //to appear in the popup window.
            //camerasHtml = getCameraData(assocDeviceID, assocDeviceType);
            
            camNameArr = cameraPath.split(";");
            camDisplayNameArr = displayName.split(";");
                    
            for (var i = 0; i < camNameArr.length; i++)
            {       
                camerasHtml = camerasHtml + '<strong>' + camDisplayNameArr[i] + '</strong><br />';
		        camerasHtml = camerasHtml + '<img style="border-style:solid; border-width:1px; border-color:blue" src="' + 
		                    appImgBaseUrl + camNameArr[i] + '" alt="' + camDisplayNameArr[i] + 
		                    '" width="160" height="120" /> <br />';                
            }            
        }
        //alert(camerasHtml);
        //**********************************
         //alert('affectedLanesCount=' + affectedLanesCount);
         
        if (affectedLanesCount != "" && affectedLanesCount != "0")
        {    
            //lanesAffected = detailRecordset("lanesAffected")
            laneCount = parseInt(totalLanesCount);
                
            lanesAffectedGraphic = lanesAffectedGraphic + '<table class="LaneInfo" style="border-collapse: collapse;" >';
            lanesAffectedGraphic = lanesAffectedGraphic + '<tr class="LaneInfo" style="border: none;padding: 0px;margin: 0px;">';
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">SHLDR</span></td>';
            
            for (laneIndex = 0; laneIndex < laneCount; laneIndex++)   
            {             
                if (laneIndex > 0) 
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"></td>';
                
                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">LANE<br/># ' + (laneIndex+1) + '</span></td>';                
            } 
               
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfoCentered"><span class="LaneTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-weight:normal;font-size:6pt;">OFF<br/>RAMP</span></td>';
            lanesAffectedGraphic = lanesAffectedGraphic + '</tr>';
            lanesAffectedGraphic = lanesAffectedGraphic + '<tr class = "LaneInfo" style="border: none;padding: 0px;margin: 0px;">';
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_shoulder.jpg" alt="Open Shoulder" /></td>';
                
            //For laneIndex = 0 to (laneCount-1) 
            for (laneIndex = 0; laneIndex < laneCount; laneIndex++) 
            {
                if (laneIndex > 0) 
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" alt="Lane Striping" /></td>';
                   
                if (lanesAffected != "" && lanesAffected != "0")  
                {
                    switch (lanesAffected) {
		            case "1":
			            if (laneIndex == 0)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
		            case "2":
			            if (laneIndex == 1)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
		            case "3":
			            if (laneIndex == 0 || laneIndex == 1)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;
			        case "4":
			            if (laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;  
			        case "6":
			            if (laneIndex == 1 || laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;        
			        case "7":
			            if (laneIndex == 0 || laneIndex == 1 || laneIndex == 2)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break; 
			        case "8":
			            if (laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;       
			        case "12":
			            if (laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;    
			        case "14":
			            if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;      
			        case "15":
			            if (laneIndex == 0 || laneIndex == 1 || laneIndex == 2 || laneIndex == 3)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;   
			        case "16":
			            if (laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;       
			        case "24":
			            if (laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;    
			        case "28":
			            if (laneIndex == 2 || laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;     
			        case "30":
			            if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3 || laneIndex == 4)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break;           
		            default: //"31"
		                if (laneIndex == 1 || laneIndex == 2 || laneIndex == 3 || laneIndex == 4 || laneIndex == 5)
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
			            else
			                lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
			            break; 
    			        
	                }	            
	            }
	            
	            //* convert decimal number to binary bit-string (base 2)
	            //var x = 24;
                //alert(x.toString(2));
                
                /*                 
                //if (lanesAffected != "" && lanesAffected != "0" && 2^laneIndex)  
                if (lanesAffected != "" && lanesAffected != "0" && laneIndex == 0)  
                {     
                    //if (lanesAffected and (2^laneIndex)) Then
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" alt="Trouble Lane" /></td>';
                //alert('2.here=' + (2^laneIndex)); 
                }
                else
                    lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" alt="Open Lane" /></td>';
                */
            //Next
            }
            
            lanesAffectedGraphic = lanesAffectedGraphic + '<td class="LaneInfo" style="border: none;padding: 0px;margin: 0px;"><img src="images/LaneImages/511_LaneGraphic_open_ramp.jpg" alt="Open Ramp" /></td>';
            lanesAffectedGraphic = lanesAffectedGraphic + '</tr></table>';

	        //If this graphic is being displayed on event_popup.asp, widen the window if necessary
    	    
	        /*
		    if (laneCount > 3) 
		    {
		         //Default popup window size is 425.  Add width for each lane over 3
		         Dim newWidth
		         newWidth = ((laneCount - 3) * 31) + 425
		         outputHTML = outputHTML & "<script type=""text/javascript"">"
		         outputHTML = outputHTML & "if (document.body.clientWidth < " & newWidth & ") { window.resizeTo(" & newWidth & ",450);}"
		         outputHTML = outputHTML & "</script>"
		    }
	        */
        }                       
             
        //For incidents, Description4 = incidentType
        if (eventType == "incident" && Description4 == "closed") 
	        iconImage = '<img src="images/icon_closures.gif" width="16" height="16" alt="Closure">';	    
           	
        outputHTML = outputHTML + iconImage + ' &nbsp; <span class="IncidentTitle" style="font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;font-weight:bold;">' + linkRoadDesignator + '</span><br />';
        
        if (makeCollapsable == true) 
            outputHTML = outputHTML + '<div class="expandCCTVHeader" style="font-size: 9pt;font-family:Arial,Verdana,Helvetica,sans-serif;" id="' + eventID + '">';
        else
            outputHTML = outputHTML + '<div style="font-size:12px;">';
        
        if (incidentDescription == "Description unavailable" || crossStreet == "")
            outputHTML = outputHTML + incidentDescription;
        else
            outputHTML = outputHTML + incidentDescription + " at " + crossStreet;
        
        outputHTML = outputHTML + '</div>';
            
        //Status box
        if (makeCollapsable == true)
            outputHTML = outputHTML + '<div class="collapsibleCCTVSection">';
            //outputHTML = outputHTML + '<div class="collapsibleCCTVSection" style="width:600px;">';
        
        outputHTML = outputHTML + '<div style="float:left; padding-right:25px;font-size:9pt;font-family: Arial, Verdana, Helvetica, sans-serif;">';
        
        //If LCase(queryType) = "incident" OR LCase(queryType) = "construction" Then
        if (Description3 != "") // incident or construction
        {
            outputHTML = outputHTML + "Status: " + status + "<br />";
            outputHTML = outputHTML + "Start Time: " + getFormattedDate(startTime) + "<br />";
            outputHTML = outputHTML + "Estimated Duration: " + estimatedDuration + "<br />";
            outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<hr />";
            //outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<br />";
        }    
        else    // event
        {
            outputHTML = outputHTML + "Start Time: " + getFormattedDate(startTime) + "<br />";
            outputHTML = outputHTML + "End Time: ";
            if (parseInt(estimatedDuration) > 0)
                outputHTML = outputHTML + getFormattedDate(endTime);
            else
                outputHTML = outputHTML + "Unknown<br />";
           
            outputHTML = outputHTML + "Status: " + status + "<br />";
            outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<hr />";
            //outputHTML = outputHTML + "Last Updated: " + getFormattedDate(LastUpdated) + "<br />";
            
        }
        //outputHTML = outputHTML & "Information Source: " & detailRecordset("infoSourceOrganizationName") & "<br />"
        if (camerasHtml != "")
            outputHTML = outputHTML + "Nearest Camera(s): <br />" + camerasHtml;
        
        outputHTML = outputHTML + "</div>";

        //Lanes Affected Graphic
        if (lanesAffectedGraphic != "") 
        {
            outputHTML = outputHTML + "<div>";            
            outputHTML = outputHTML + '<span style="font-weight:bold; text-decoration:underline;font-size:9pt;font-family:Arial,Verdana,Helvetica,sans-serif;">Incident Location</span><br />';
            outputHTML = outputHTML + lanesAffectedGraphic;
            outputHTML = outputHTML + "</div>";            
        }           
                        
        //Close expand/collapse div
        outputHTML = outputHTML + '<br clear="left" />';
        
        if (makeCollapsable == true) 
            outputHTML = outputHTML + "</div><br />";
            
        //alert(outputHTML);
      
    } 
       
    if (LinkID != "")
    {             
        var speed = "";
        
        if (parseInt(Math.round(SpeedMPH)) < parseInt(SpeedLimitMPH)-5)
            speed = parseInt(Math.round(SpeedMPH));
        else
            speed = parseInt(SpeedLimitMPH)-5 + " mph or higher"; 
       
        //* Check for speed information
        //outputHTML += "<br /><div style='text-align:center;font-weight:bold;font-size:12px;'>Speed Information</div><br />";
        outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Route:</b> " + linkOnStreetName + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>From:</b> " + FromRoad + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>To:</b> " + ToRoad + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>City:</b> " + CityName + "<br />";
		outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Speed limit:</b> " + SpeedLimitMPH + "<br />";
		if (SpeedMPH != "")
            outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Traffic speed:</b> " + speed + "<br />";
        else
            outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Traffic speed:</b> " + "No data" + "<br />";
    
        outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Last Updated:</b> " + getFormattedDate(LastUpdated) + "</div><hr />";
        //outputHTML += "<div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-size:10pt;'><b>Last Updated:</b> " + getFormattedDate(LastUpdated) + "</div><br />";
    }
    
    if (deviceID != "")
    {        
        outputHTML += "<table align='center' style='text-align:left;'><tr><td><img src='images/icon_camera.gif' width='18' height='18' /></td>";
        outputHTML += "<td><div style='font-family:Arial,Verdana,Helvetica,sans-serif;font-weight: bold;font-size:12px;'>" + displayName + "</div></td></tr></table>";
    	outputHTML += "<div style='font-size:12px;text-align:center;'><img src='" + appImgBaseUrl + cctvFileName + "' width='320' height='240' border='1' alt='image' ></div><br /><br />";
    
    }                                          
                
    return outputHTML + "^" + lanesAffectedGraphic + "^" + eventType;        
}

function showDrivingTimeStartEndWindow(nodeID, nodeDesc, nodeCity, lat, lon)
{
    clickedLat = lat;
    clickedLon = lon;

    if (DTMode == true || dtCheckbox.checked == true)
    {
      if (DTInfoFrom == false && DTInfoTo == false)
      {  
         NODE_FROM = nodeDesc;
         CITY_FROM = nodeCity;
         
         START_NODE_ID = nodeID;
         
         START_NODE_LAT = lat;    
         START_NODE_LON = lon;
         
         html = getHtmlFrom(nodeDesc, nodeCity);
         
         DTInfoFrom = true;
         DTInfoTo = false;
         
         DTFlag = false;
         
         //startMarkerID = marker.id;
         addStartMarker(lat, lon);
         
         popupStartDTWindow(html, lat, lon)
      }
      else
      { 
                             
         END_NODE_LAT = lat;
         END_NODE_LON = lon;
         
         END_NODE_ID = nodeID;
         
         if (START_NODE_ID == END_NODE_ID)
         {
            alert("Please select another destination node.");
            return;
         }                        
         
         DTInfoFrom = false;
         DTInfoTo = true;
         
         DTFlag = true;
         
         //endMarkerID = marker.id;

         addEndMarker(lat, lon); 
         //GLog.write(START_NODE_ID + ',' + END_NODE_ID);
         getDrivingTimeTrip(START_NODE_ID, END_NODE_ID, NODE_FROM, CITY_FROM, nodeDesc, nodeCity, lat, lon);
         
      }      	                                       
      
   }
    
}

function getHtmlFrom(nodeFrom, nodeCity)
{
    //*********************************** Info window START   ******************************
    var htmlFrom = '<div style="width:100%; background-color:#9cbdde">';
    htmlFrom += '<img src="images/sandag511-logo-popup.jpg" alt="San Diego 511 Logo" width="100" height="49">';
    htmlFrom += '</div><br />';            
        
    htmlFrom += '<div align="left" style="width: 375px;">';           	
	//html += '<div style="color: ' + textColor + '; width: 375px;">';
	//<asp:LinkButton Text="Click me!" OnClick="lblClick" runat="server" />    		
	//htmlFrom += '<p class="instructions" style="float:right; padding-right:10px"><a href="#" onclick="javascript:cancelDT(); return false;" >Cancel driving time calculation</a></p>';
	//htmlFrom += '<p class="instructions" style="float:right; padding-right:10px"><a href="#" onclick="javascript:cancelDT();">Cancel driving time calculation</a></p>';    
	htmlFrom += '<h1 class="texthead" style="font-family:Arial,Verdana,Helvetica,sans-serif;">Driving Times</h1>';
	htmlFrom += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;"><b>From:</b> ' + nodeFrom + ' (' + nodeCity + ')</p>';
	//htmlFrom += '<p class="instructions">To select your destination, click on a magenta ';
	//htmlFrom += 'circle where we provide driving times as shown on the ';
    htmlFrom += '<p class="instructions" style="font-family:Arial,Verdana,Helvetica,sans-serif;">Select your destination point ';
    htmlFrom += 'where we provide driving times as shown on the ';
	htmlFrom += '<a	href="coverage.asp" target="parent">coverage map</a>.</p>';
	
	//htmlFrom += '<br />';	
	htmlFrom += '<div ><table style="width:100%;text-align:center;font-family:Arial,Verdana,Helvetica,sans-serif;"><tr><td><a href="#" onclick="javascript:closeDTWindow();return false;">Next</a></p></td>';
	htmlFrom += '<td><a href="#" onclick="javascript:cancelDT();return false;">Cancel</a></p></td></tr></table></div>';
	
	//htmlFrom += '<br />';	
   		
	//html += '</div>';    	
    htmlFrom += '</div>';
    //************************************************************************************
    
    return htmlFrom;
}

function getHtmlTo(nodeFrom, cityFrom, nodeTo, cityTo, tripHtml, startNodeID, endNodeID)
{
    //***************************   Info window  DESTINATION   ***************************
    var htmlTo = '<div style="width:100%; background-color:#9cbdde">';
    htmlTo += '<img src="images/sandag511-logo-popup.jpg" alt="San Diego 511 Logo" width="100" height="49">';
    htmlTo += '</div><br />';
    //htmlTo += '<script type="text/javascript">';
	//htmlTo += '<!--';
	//htmlTo += 't.clearTravelTimeRoutes();';
	//htmlTo += '// -->';
	//htmlTo += '</script>';
    htmlTo += '<p class="instructions" style="float:right;padding-right:10px;width:200px;text-align:right;font-family:Arial,Verdana,Helvetica,sans-serif;"><a target="_self" href="#" onclick="javascript:closeDTWindow();">Close driving time results and display traffic data</a></p>'; 
	htmlTo += '<h1 class="texthead" style="font-family:Arial,Verdana,Helvetica,sans-serif;">Driving Times</h1>';
	htmlTo += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;">';
	htmlTo += '<b>From:</b> ' + nodeFrom + ' (' + cityFrom + ')<br>';
	htmlTo += '<b>To:</b> ' + nodeTo + ' (' + cityTo + ')';
	htmlTo += '</p>';		
	htmlTo += '<p>';
	//htmlTo += '<script type="text/javascript">';
	//htmlTo += '<!--';
	//htmlTo += document.write('<span style="border: 1px solid black; background-color: rgb(0,255,255)">&nbsp;&nbsp;&nbsp;<\/span> ');
	//htmlTo += '// -->';
	//htmlTo += '</script>';	
	
	htmlTo += tripHtml;
					
	//htmlTo += '<script type="text/javascript">';
	//htmlTo += '<!--';
	//htmlTo += 't.addTravelTimeRoute(1, "100090,100100,100110,100120,100130,100140,100150,100160,100170,100180,100190,100200,100210,100220,100230,100240,100250,100255,100260,100270");';
	//htmlTo += '// -->';
	//htmlTo += '</script>';	
	
    //<p><a href="traffic_map_travelTimeDetail.asp?origin=10&amp;destination=28" onclick="var win = window.open('traffic_map_travelTimeDetail.asp?refresh=' + t.refreshRate + '&origin=10&destination=28', 'traveltimes', 'width=400,height=400,scrollbars=1,resizable=1'); win.focus(); return false;">More details on the trip(s)...</a></p>	
					
	htmlTo += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;"><a href="traffic_map_travelTimeDetail.asp?origin=10&amp;destination=28" onclick="var win = window.open(\'traffic_map_travelTimeDetail.asp?refresh=3&origin='+ startNodeID + '&destination=' + endNodeID + '\',\'traveltimes\',\'width=400,height=400,scrollbars=1,resizable=1\'); win.focus(); return false;">More details on the trip(s)...</a></p>';			 
	htmlTo += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;font-style:italic;">To look up driving times for a new route, close the window by selecting the "Close driving time results and display traffic data" link or [x] box and then select a different set of starting and ending points.</p>';
	htmlTo += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;">Don&#39;t forget to call 511 to get driving times when you&#39;re not at your computer!</p>';
	//htmlTo += '<script type="text/javascript">';
	//htmlTo += '<!--';
	//htmlTo += 't.selectTravelTimeRoute(1);';
	//htmlTo += '// -->';
	//htmlTo += '</script>';		
    htmlTo += '</div><br />';    
    //**********************************************************************************
    //GLog.write(htmlTo);
    return htmlTo;
}

function popupStartDTWindow(innerHtml, lat, lon)
{
    //*******************************************************
    //* This function shows from Node to Node window
    //*******************************************************
    
    //var infoHtmls = '<div style="font-size:medium;width:550px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");>';	
    var infoHtmls = '<div style="font-size:medium;width:400px;height:220px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';	
	
	//var divTooltipInfo = document.getElementById("divTooltipInfo");	
	var divStartEndDT = document.createElement('div');
	divStartEndDT.setAttribute("id", "divStartEndDT");
	//divEventPopInfo.style.width="700px"; 
    divStartEndDT.innerHTML = infoHtmls + innerHtml + "</div>";
    
    //saveMapPosition();    
         
    wOpenFlag = true;         
      
    googleMap.openInfoWindowHtml(new GLatLng(lat, lon), divStartEndDT.innerHTML, {onCloseFn: function() { 
    googleMap.closeInfoWindow();  
    //if (DTInfoTo == true){DTInfoFrom = false;DTInfoTo = false;}; wOpenFlag = false; curLon = 0; curLat = 0;}}); 
    if (DTInfoTo == true){DTInfoFrom = false;DTInfoTo = false;}; wOpenFlag = false;}}); 
}

function popupEndDTWindow(innerHtml, lat, lon)
{
    //*******************************************************
    //* This function shows from Node to Node window
    //*******************************************************
    
    //var infoHtmls = '<div style="font-size:medium;width:550px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");>';	
    var infoHtmls = '<div style="font-size:medium;width:420px;height:350px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';	
	
	//var divTooltipInfo = document.getElementById("divTooltipInfo");	
	var divStartEndDT = document.createElement('div');
	divStartEndDT.setAttribute("id", "divStartEndDT");
	//divEventPopInfo.style.width="700px"; 
    divStartEndDT.innerHTML = infoHtmls + innerHtml + "</div>";
    
    //saveMapPosition();    
         
    wOpenFlag = true;    
    
    dtWindowON = true;     
    
    googleMap.openInfoWindowHtml(new GLatLng(lat, lon), divStartEndDT.innerHTML, {onCloseFn: function() { 
    googleMap.closeInfoWindow();  
    if (DTInfoTo == true){DTInfoFrom = false;DTInfoTo = false;}; dtWindowON = false; wOpenFlag = false;}}); 
    //if (DTInfoTo == true){DTInfoFrom = false;DTInfoTo = false;}; dtWindowON = false; wOpenFlag = false; curLon = 0; curLat = 0;}});
            
}

function getLaneViewLegend(legendWidth)
{
     var outputHTML = "";
     
     outputHTML = outputHTML + '<table style="font-family:Arial,Verdana,Helvetica,sans-serif;" width="100%" ><tr align="center"><td><div id="affectedLanesLegend" style="width:' + legendWidth + ';font-weight:bold;font-size:12px;">';
     outputHTML = outputHTML + '<div style="background-color:#EEEEEE; text-align:center; margin-right:10px; padding-top:5px; padding-bottom:5px">';
     outputHTML = outputHTML + '<span style="text-decoration:underline;font-family:Arial,Verdana,Helvetica,sans-serif; font-weight:bold">Incident Legend</span> &nbsp; &nbsp; &nbsp;';
     outputHTML = outputHTML + '<img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" width="2" height="35" style="vertical-align:middle" alt="Lane Striping" /><img src="images/LaneImages/511_LaneGraphic_trouble_lane.jpg" width="10" height="35" border="0" style="vertical-align:middle;" alt="Trouble Lane Graphic" /><img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" width="2" height="35" style="vertical-align:middle;" alt="Lane Striping" /> Affected Lane &nbsp; &nbsp;';
     outputHTML = outputHTML + '<img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" width="2" height="35" style="vertical-align:middle" alt="Lane Striping" /><img src="images/LaneImages/511_LaneGraphic_open_lane.jpg" width="10" height="35" border="0" style="vertical-align:middle;" alt="Open Lane Graphic" /><img src="images/LaneImages/511_LaneGraphic_yellow_lines.jpg" width="2" height="35" style="vertical-align:middle;" alt="Lane Striping" /> Unaffected Lane &nbsp;';
     outputHTML = outputHTML + "</div>";
     outputHTML = outputHTML + "</div></td></tr></table><br />";
    //alert('outputHTML=' + outputHTML);
     return outputHTML;
}

function canAdd(arr, name)
{
    var flag = false;
    
    for(var j = 0; j < arr.length; j++)
    {//alert(arr[j] + ';' + name);
        if (arr[j] == name)                 
            break;
                
        flag = true;
    }
    //alert(flag);
    return flag;
}

function getDrivingTimeTrip(startNodeID, endNodeID, nodeFrom, cityFrom, nodeTo, cityTo, lat, lon)
{
    //var camRequest = null;

    try
	{
        if (camRequest != null)
        {
            if (camRequest.readyState == 4)
                camRequest=null;
        }

        if (camRequest == null)
        {                   
            if(navigator.appName == "Microsoft Internet Explorer")
                camRequest = new ActiveXObject("Msxml2.XMLHTTP");
            else
                camRequest = new XMLHttpRequest();
  	        
  	        var pathUrl = "/GSHandler/GSHandler/DBHandler.ashx?startNodeID=" + startNodeID + "&endNodeID=" + endNodeID + "&planType=0";
            
            camRequest.open("GET", pathUrl, true);

            camRequest.onreadystatechange = function() {   

            if (camRequest != null)
            { //GLog.write(camRequest.readyState + ';' + camRequest.status);
                if (camRequest.readyState == 4) {
                    if (camRequest.status == 200) {
                        var xmlhttp = camRequest.responseText; //alert('xmlhttp=' + xmlhttp)
                        processDrivingTimeTrip(GXml.parse(xmlhttp), nodeFrom, cityFrom, nodeTo, cityTo, lat, lon, startNodeID, endNodeID);
                        camRequest = null;   	               	                  	                          
                    }             
                }
            }                             
        }              
        camRequest.send(null);                
        }                          							
	}
	catch (ee) {
		alert(ee.message);
		return;
	}   
}

function processDrivingTimeTrip(xmlhttp, nodeFrom, cityFrom, nodeTo, cityTo, lat, lon, startNodeID, endNodeID)
{
    var outputHTML = "";
    
    if (xmlhttp.documentElement.getElementsByTagName("errorDesc").length != 0)
    {
        //alert("An error occured while retreiving weather forecast data.\nPlease try again later.");
        //return;
    }

    var node = xmlhttp.documentElement.getElementsByTagName("node");   
          
    //var TRIP_ARR = new Array(); // defaultPath, pathOrder, startNodeID, endNodeID, LinkList
    
    TRIP_ARR = [];
    LINK_LIST = "";
    
	var numValidTrips = 0;
	var currentTrip = 65;   // "A" char
	var route = 1;
	var color = "#00FFFF";  // cyan
	var j = 1;
		    
	//GLog.write(xmlhttp.xml);
   //GLog.write(node.length); 
    for (var i = 0; i < node.length; i++)
    {        
        if (node[i].getAttribute("TravelTime") != "0")
        {
            numValidTrips = numValidTrips + 1;
		    //currentTrip = currentTrip + 1;
		    if (parseInt(route) == parseInt(currentTrip)-64)
		    {
		        outputHTML = '<p id="trip_' + i + '" class="trip" style="display:table-cell;font-family:Arial,Verdana,Helvetica,sans-serif;">';				
			    outputHTML += '<span style="border: 1px solid black; background-color:' + color + '">&nbsp;&nbsp;&nbsp;<\/span> ';				
			    outputHTML += '<b>Trip ' + Letter(currentTrip) + ':' + Minutes(node[i].getAttribute("TravelTime"), 0) + ' min.</b> (' + Math.round(node[i].getAttribute("PathLengthMiles")*10/10) + ' mi.)</p>'; 
			    
			    outputHTML += '<p id="trip' + i + '" class="trip" style="display:none;font-family:Arial,Verdana,Helvetica,sans-serif;"><a target="_self" href="#" onclick="showTrip(' + i + ');showTripPath(TRIP_ARR, ' + j + ');return false;"><b>Trip ' + Letter(currentTrip) + ':' + Minutes(node[i].getAttribute("TravelTime"), 0) + ' min.</b> (' + Math.round(node[i].getAttribute("PathLengthMiles")*10/10) + ' mi.)</p>';  	
			    
			    outputHTML += '<br />';	
		    }
		    else
		    {
		        //* display selected route on map 		       		        
		        outputHTML += '<p id="trip' + i + '" class="trip" style="display:table-cell;font-family:Arial,Verdana,Helvetica,sans-serif;"><a target="_self" href="#" onclick="showTrip(' + i + ');showTripPath(TRIP_ARR, ' + j + ');return false;">Trip ' + Letter(currentTrip) + ':' + Minutes(node[i].getAttribute("TravelTime"), 0) + ' min.</a> (' + Math.round(node[i].getAttribute("PathLengthMiles")*10/10) + ' mi.)</p>';
		        
		        outputHTML += '<p id="trip_' + i + '" class="trip" style="display:none;font-family:Arial,Verdana,Helvetica,sans-serif;">';
                outputHTML += '<span style="border: 1px solid black; background-color:#00FFFF">&nbsp;&nbsp;&nbsp;</span>';
                outputHTML += '<b>Trip ' + Letter(currentTrip) + ':' + Minutes(node[i].getAttribute("TravelTime"), 0) + ' min.</b> (' + Math.round(node[i].getAttribute("PathLengthMiles")*10/10) + ' mi.)</p>';
		    
		        outputHTML += '<br />';	
		    }
        
            if (node[i].getAttribute("Notes") != "" && 
                node[i].getAttribute("Notes") != "0" && 
                node[i].getAttribute("Notes") != "&amp;amp;#32" && 
                node[i].getAttribute("Notes") != "&#32" && 
                node[i].getAttribute("Notes") != "&amp;#32")
                {
			    outputHTML += '<p><b>Note:</b> ' + node[i].getAttribute("Notes") + '</p>';
			    }
    			
            currentTrip = currentTrip + 1;            
            //GLog.write(node[i].getAttribute("DefaultPath") + ';' + node[i].getAttribute("PathOrder") + 
            //                                    ';' + node[i].getAttribute("StartingNode") + 
            //                                    ';' + node[i].getAttribute("EndingNode") + 
            //                                    ';' + node[i].getAttribute("LinkList"));
            TRIP_ARR.push(node[i].getAttribute("DefaultPath") + ';' + node[i].getAttribute("PathOrder") + 
                                                ';' + node[i].getAttribute("StartingNode") + 
                                                ';' + node[i].getAttribute("EndingNode") + 
                                                ';' + node[i].getAttribute("LinkList"));
        }
        else
        {
            //We cannot calculate a driving time because your trip includes roads not covered.
            if (node[i].getAttribute("Notes") != "" && 
                node[i].getAttribute("Notes") != "0" && 
                node[i].getAttribute("Notes") != "&amp;amp;#32" && 
                node[i].getAttribute("Notes") != "&#32" && 
                node[i].getAttribute("Notes") != "&amp;#32")
            {
            
                if (node[i].getAttribute("Notes").indexOf("roads not covered") > 0)            
                    //outputHTML += '<p><b>Note:</b> ' + node[i].getAttribute("Notes") + '</p>';
                    outputHTML += "<p style='font-family:Arial,Verdana,Helvetica,sans-serif;'><b>We cannot calculate a driving time because your trip includes roads not covered.  Click <a href='coverage.asp'>Driving Times Coverage</a> for roads where we do provide driving times.</b></p>";
                else
                    outputHTML += '<p style="font-family:Arial,Verdana,Helvetica,sans-serif;"><b>Note:</b> ' + node[i].getAttribute("Notes") + '</p>';
            
            }
            else
            {
                outputHTML = "<p style='font-family:Arial,Verdana,Helvetica,sans-serif;'><b>We don't have a current estimate for this trip. " + 
                            "It may be because your trip includes roads not covered.  " + 
                            "You can click <a href='coverage.asp' target='parent'>" + 
                            "511 Driving Times<SMALL><SUP>SM</SUP></SMALL> Coverage</a> " + 
                            "for roads where we do provide driving times.</b></p>";
            }
        }

        j++;  
           
    }
    //alert(outputHTML);
    
    // We cannot calculate a driving time because your trip includes roads not covered.  
    // Click <a href="coverage.asp">Driving Times Coverage</a> for roads where we do provide driving times.
    
    if (node.length ==0)
    {
        outputHTML = "<p style='font-family:Arial,Verdana,Helvetica,sans-serif;'><b>We don't have a current estimate for this trip. " + 
                        "It may be because your trip includes roads not covered.  " + 
                        "You can click <a href='coverage.asp' target='parent'>" + 
                        "511 Driving Times<SMALL><SUP>SM</SUP></SMALL> Coverage</a> " + 
                        "for roads where we do provide driving times.</b></p>";
    }
    //GLog.write(outputHTML);   
    var html = getHtmlTo(nodeFrom, cityFrom, nodeTo, cityTo, outputHTML, startNodeID, endNodeID);
    
    //* popup DT window
    popupEndDTWindow(html, lat, lon);    
    
    //* show selected trip
    showTripPath(TRIP_ARR, route);

}

function showTripPath(tripArray, index)
{//alert('index=' + index + ';' + tripArray.length);
    if (tripArray != null && tripArray != undefined)
    {            
        for (var j = 0; j < tripArray.length; j++)
        {    
            var tripList = new Array();
              
            tripList = tripArray[j].split(";");            
            //alert('tripList[1]=' + tripList[1]);
            //alert(tripList[1] + ';' + index);
            if (tripList[1] == index)
            //if ((intParse(tripList[1])-1) == index)
            {
                LINK_LIST = tripList[4];
                //alert('LINK_LIST=' + LINK_LIST);
                break;
            }            
            
            
        }  
        //GLog.write(LINK_LIST);
        addTripOnMap(LINK_LIST);   
    
    }

}

function addTripOnMap(linkList)
{
   //*****************************************************
   //* This function add selected trip on map
   //*****************************************************
   //alert(linkList);
    
   if (linkList != "")
   {             
       if (getObject(googleMap, "map") != undefined && getObject(googleMap, "map") != null)
       {
        var boundingBox = parent.parent.googleMap.getBounds();       
        var southWest = boundingBox.getSouthWest();
        var northEast = boundingBox.getNorthEast();
        var thisZoom = getObject(googleMap, "map").getZoom();
        
        var mapHeight;
        var mapWidth;
        
        var filter = getFilter(linkList);
       
        var thisExtents = southWest.x + ' ' + southWest.y + ',' + northEast.x + ' ' + northEast.y;
    
        try 
        {                  
            var coords = thisExtents.split(",");
		    var coords1 = coords[0].split(" ");
		    var coords2 = coords[1].split(" ");
    		
		    var boundaries = new GLatLngBounds(new GLatLng(parseFloat(coords1[1]),parseFloat(coords1[0])), 
		                                        new GLatLng(parseFloat(coords2[1]),parseFloat(coords2[0])));
	        	 
		    //* get size of "map_canvas" div 		    
            if (parent.parent.document.getElementById("MapFrame").style.pixelHeight && parent.parent.document.getElementById("MapFrame").style.pixelWidth)
		    {   		          
		        mapHeight = parent.parent.document.getElementById("MapFrame").style.pixelHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").style.pixelWidth;        
             }
            else
            {                
		        mapHeight = parent.parent.document.getElementById("MapFrame").clientHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").clientWidth;   		              
            }                               	                                  
    		//GLog.write('tripImage=' + tripImage + ';' + parent.parent.tripImage + ';' + parent.tripImage);
    		//if (wOpenFlag == false)	
    		//{    		                    
            if (parent.parent.googleMap != null && parent.parent.tripImage != null)
                parent.parent.googleMap.removeOverlay(parent.parent.tripImage);
                
            //if (parent.googleMap != null && parent.tripImage != null)
            //    parent.googleMap.removeOverlay(parent.tripImage);    
            
            if (googleMap != null && tripImage != null)    
                googleMap.removeOverlay(tripImage);   
                    
    	     //}   	    	    	      	   	   
    	
	        //* create URL for GeoServer	        	        	        			
	        var geoServerUrl = "http://" + HOST_GEO_SERVER + PORT + "/geoserver/wms?bbox=" + 
	                        coords1[0] + "," + coords1[1] + "," + coords2[0] + "," + coords2[1] + 
                            "$tiled=null$styles=$Format=image/png$request=GetMap$layers=" + getLinkSelected() + 
                            "$width=" + mapWidth + "$height=" + mapHeight + 
                            "$srs=EPSG:4326$TRANSPARENT=TRUE$count=0$tilesorigin=" + 
                            coords1[0] + "," + coords2[1] + "$CQL_FILTER=" + filter; 
             //alert(geoServerUrl);    
            var pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl;
          
            //* create trip image           
            tripImage = EInsert.groundOverlay(pathUrl, boundaries);   
                     
            //* add all images to GMap
            //parent.parent.googleMap.addOverlay(eventImage);  
            
            if (googleMap != null) 
                googleMap.addOverlay(tripImage);      
            else
                parent.parent.googleMap.addOverlay(tripImage);                
        
        }
	    catch (ee) {
		    alert(ee.message);
		    return false;
	    }
    	    
	    return true;
	    }
	    else
	        return false;
    }	
}

function getFilter(linkList)
{			
	var segmArray = new Array();	
	var filter = "";			

	//linkList = "100090,100100,100110,100120,100130,100140,100150,100160,100170,100180,100190,100200,100210,100220,100230,100240,100250,100255";
		
	segmArray = new Array();
	
	segmArray = linkList.split(",");			
	
	for(var j=0; j < segmArray.length; j++) {
		if (filter == "")
		{
			filter = "LinkID=" + segmArray[j];
		}
		else
		{
			filter = filter + " Or LinkID=" + segmArray[j];
		}						
	}
	
	return filter;
	
}

function Asc(String)
{
	return String.charCodeAt(0);
}

function Letter(AsciiNum)
{
	return String.fromCharCode(AsciiNum)
}

//function Chr(AsciiNum)
//{

//	return String.fromCharCode(AsciiNum)

//}

function hideTooltips()
{
    //GLog.write('1' + parent.divTooltipNode);
    if (parent.divTooltipEvent != null && parent.divTooltipEvent != undefined)
        parent.divTooltipEvent.style.visibility = "hidden";
        
    if (parent.divTooltipNode != null && parent.divTooltipNode != undefined)
        parent.divTooltipNode.style.visibility = "hidden";    
        
    //hideNodeTooltip();
    //hideEventTooltip();       
       
}

function hideEventTooltip()
{   //GLog.write("before=" + divTooltipEvent.style.visibility);
    //markerTooltip.style.visibility = "hidden";
    
    if (divTooltipEvent != null && divTooltipEvent != undefined)
        divTooltipEvent.style.visibility = "hidden";
        
       //alert("after=" + divTooltipEvent.style.visibility); 
}

function hideNodeTooltip()
{//GLog.write('2' + divTooltipNode);
    //markerTooltip.style.visibility = "hidden";
    if (divTooltipNode != null && divTooltipNode != undefined)
        divTooltipNode.style.visibility = "hidden";
}

function hideEventTooltipP()
{   //GLog.write('here');
    //markerTooltip.style.visibility = "hidden";
    if (parent.parent.divTooltipEvent != null && parent.parent.divTooltipEvent != undefined)
        parent.parent.divTooltipEvent.style.visibility = "hidden";
}

function hideNodeTooltipP()
{//alert('3');
    //markerTooltip.style.visibility = "hidden";
    if (parent.parent.divTooltipNode != null && parent.parent.divTooltipNode != undefined)
        parent.parent.divTooltipNode.style.visibility = "hidden";
}

function showMultiTooltipEvent(ttValue, x, y)
{
    //*******************************************************
    //* This function shows multiple event tooltips
    //*******************************************************
    var splitTooltip = new Array();
    var splitElem = new Array();
    var name = "";
    var tooltip = "";
    var value = "";
    //  GLog.write(ttValue);
    splitTooltip = ttValue.split("><"); 
               
    //var tooltip = "<b class='b1'></b><b class='b2'></b><b class='b3'></b><b class='b4'></b><div class='contentb'><div>";
   
    for (var j = 0; j < splitTooltip.length; j++)
    {    
        //var tooltip = "<b class='b1'></b><b class='b2'></b><b class='b3'></b><b class='b4'></b><div class='contentb'><div>";
                                                                                        
        if (splitTooltip[j] != "")
        {                
            splitElem = splitTooltip[j].split("~");     
           
            if (splitTooltip.length == 1)
            {
                if (tooltip == "")
                    //tooltip = "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif; text-align:center;'>";
                    tooltip = "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif;padding:7px;'>";
                else
                    //tooltip = tooltip + "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif; text-align:center;'>";  
                    tooltip = tooltip + "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif;padding:7px;'>";                               
            }
            else
            {
                if (tooltip == "")
                    //tooltip = "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-bottom-style:none; border-right-style:solid; border-top-style:solid; border-left-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif; text-align:center;'>";
                    tooltip = "<div style='color:" + splitElem[3] + ";font-weight:bold;background-color: #FFFFFF; border-bottom-style:none; border-right-style:solid; border-top-style:solid; border-left-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif;padding:7px;'>";
                else
                {
                    if (j == splitTooltip.length-1)
//                          tooltip = tooltip + "<div style='color:" + splitElem[3] + 
//                                            "; font-weight:bold;background-color:#FFFFFF;border-bottom-style:solid;" + 
//                                            "border-right-style:solid;border-top-style:solid;border-top-color:LightGrey;border-left-style:solid;" + 
//                                            "border-width:1px;border-color:Black; font-size:9pt;" + 
//                                            "font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;'>"; 
                    tooltip = tooltip + "<div style='color:" + splitElem[3] + 
                                            "; font-weight:bold;background-color:#FFFFFF;border-bottom-style:solid;" + 
                                            "border-right-style:solid;border-top-style:solid;border-top-color:LightGrey;border-left-style:solid;" + 
                                            "border-width:1px;border-color:Black; font-size:9pt;" + 
                                            "font-family:Arial,Verdana,Helvetica,sans-serif;padding:7px;'>";  
                    else                   
//                        tooltip = tooltip + "<div style='color:" + splitElem[3] + 
//                                            ";font-weight:bold;background-color: #FFFFFF;border-bottom-style:none;" + 
//                                            "border-right-style:solid;border-top-style:solid;border-top-color:LightGrey;border-left-style:solid;" + 
//                                            "border-width:1px;border-color:Black; font-size:9pt;" + 
//                                            "font-family:Arial,Verdana,Helvetica,sans-serif;text-align:center;'>"   
                          tooltip = tooltip + "<div style='color:" + splitElem[3] + 
                                            ";font-weight:bold;background-color: #FFFFFF;border-bottom-style:none;" + 
                                            "border-right-style:solid;border-top-style:solid;border-top-color:LightGrey;border-left-style:solid;" + 
                                            "border-width:1px;border-color:Black; font-size:9pt;" + 
                                            "font-family:Arial,Verdana,Helvetica,sans-serif;padding:7px;'>"                           
                }
            }
            
            if (splitElem[4] == "event")
            {             
                if (splitElem[0] != '' &&                
                    splitElem[0] != '&#32' &&
                    splitElem[0] != '&amp;#32') 
                {           
                    //var incType = splitElem[0].replace(/\-/g, ' ');                
                    value = splitElem[0].replace(/ {2,}/g, '&nbsp;');   
                    tooltip += value + '<br />'; 
                    //desc = desc.replace(/\s+/g, '&nbsp;');     
                    //tooltip += Capitalize(desc) + '<br />';                
                }     
                if (splitElem[1] != '' &&                
                    splitElem[1] != '&#32' &&
                    splitElem[1] != '&amp;#32') 
                {           
                    var eventType = splitElem[1].replace(/\-/g, ' ');                
                    eventType = eventType.replace(/ {2,}/g, '&nbsp;');   
                    tooltip += eventType;  
                    //tooltip += eventType + '<br />';                             
                }
                if (splitElem[2] != '' &&                
                    splitElem[2] != '&#32' &&
                    splitElem[2] != '&amp;#32') 
                {           
                    var facilityName = splitElem[2].replace(/\-/g, ' ');                
                    facilityName = facilityName.replace(/ {2,}/g, '&nbsp;'); 
                    tooltip += facilityName;    
                    //tooltip += facilityName + '<br />';                               
                }
                
                //if (j < splitTooltip.length-1)
                //    tooltip = tooltip + "<hr />";                                        
            }
            else
            {//GLog.write(splitElem[4]);
                                            
                if (splitElem[0] != '' &&         
                    splitElem[0] != '&#32' &&
                    splitElem[0] != '&amp;#32') 
                {           
                    //value = splitElem[0].replace(/\-/g, ' ');  
                    //value = value.replace(/ {2,}/g, '&nbsp;');                 
                    value = splitElem[0].replace(/ {2,}/g, '&nbsp;');   
                    tooltip += value; 
                    if (splitElem[4] == "link")
                        tooltip +=  '<br />';
                    //else if (splitElem[4] == "camera")
                        
                    //GLog.write(splitElem[0]);
                    //desc = desc.replace(/\s+/g, '&nbsp;');     
                    //tooltip += Capitalize(desc) + '<br />';                
                }     
                
                if (splitElem[1] != '' &&                
                    splitElem[1] != '&#32' &&
                    splitElem[1] != '&amp;#32') 
                {           
                    value = splitElem[1].replace(/\-/g, ' ');                
                    value = value.replace(/ {2,}/g, '&nbsp;');  
                    
                    if (splitElem[4] == "camera")   
                        tooltip += "; direction: " + value;
                    else                                                      
                        tooltip += value; 
                    //desc = desc.replace(/\s+/g, '&nbsp;');     
                    //tooltip += Capitalize(desc) + '<br />';                
                }                                   
                                
            }                                           
                
         }
         
         tooltip += "</div>"; 	
	}	              
    	    	
	//GLog.write(tooltip);
    divTooltipEvent.innerHTML = tooltip;      
            
    var point = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(googleMap.fromDivPixelToLatLng(new GPoint(0,0),true), googleMap.getZoom());	
    var offset = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(y,x), googleMap.getZoom());
    
    var height = divTooltipEvent.clientHeight;
    var width = divTooltipEvent.clientWidth;
	
    var center = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(googleMap.getBounds().getCenter(), googleMap.getZoom());
    
    var posY, posX;
    
    if(offset.y < center.y)    
        posY = offset.y - point.y; // top    
    else    
        posY = offset.y - point.y - height+24; // bottom    
    
    if(offset.x < center.x)
        posX = offset.x - point.x+100; // left    
    else
        posX = offset.x - point.x - width-100; // right    
    	
    var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(posX, posY)); 
	
    pos.apply(divTooltipEvent);
    divTooltipEvent.style.visibility="visible";	 
    divTooltipEvent.style.width="170px";  	
}

function showTooltipNode(ttValue, x, y)
{
    //*******************************************************
    //* This function shows multiple event tooltips
    //*******************************************************
    //var splitTooltip = new Array();
    var splitElem = new Array();
    var name = "";
    var tooltip = "";
    var value = "";
      //GLog.write(ttValue);
      
    splitElem = ttValue.split("~");     
       
    if (tooltip == "")
        tooltip = "<div style='color:" + splitElem[2] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif; text-align:center;padding:7px;'>";
    else
        tooltip = tooltip + "<div style='color:" + splitElem[2] + ";font-weight:bold;background-color: #FFFFFF; border-style:solid; border-width:1px; border-color:Black; font-size: 9pt;font-family: Arial, Verdana, Helvetica, sans-serif; text-align:center;padding:7px;'>";                                 
          
    //if (splitElem[3] == "node")
    //{             
    if (splitElem[0] != '' &&                
        splitElem[0] != '&#32' &&
        splitElem[0] != '&amp;#32') 
    {          
        //value = splitElem[0].replace(/\-/g, ' ');                
        value = splitElem[0].replace(/ {2,}/g, '&nbsp;');   
        tooltip += value + '<br />'; 
        //desc = desc.replace(/\s+/g, '&nbsp;');     
        //tooltip += Capitalize(desc) + '<br />';                
    }     
    if (splitElem[1] != '' &&                
        splitElem[1] != '&#32' &&
        splitElem[1] != '&amp;#32') 
    {           
        value = splitElem[1].replace(/\-/g, ' ');                
        value = value.replace(/ {2,}/g, '&nbsp;');   
        tooltip += " (" + value + ")";  
        //tooltip += eventType + '<br />';                             
    }                                                       
           
    //}                                                              
         
    tooltip += "</div>"; 	
	
	//GLog.write(tooltip);
    divTooltipNode.innerHTML = tooltip;      
            
    var point = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(googleMap.fromDivPixelToLatLng(new GPoint(0,0),true), googleMap.getZoom());	
    var offset = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(y,x), googleMap.getZoom());
    
    var height = divTooltipNode.clientHeight;
    var width = divTooltipNode.clientWidth;
	
    var center = googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(googleMap.getBounds().getCenter(), googleMap.getZoom());
    
    var posY, posX;
    
    if(offset.y < center.y)    
        posY = offset.y - point.y; // top    
    else    
        posY = offset.y - point.y - height+24; // bottom    
    
    if(offset.x < center.x)
        posX = offset.x - point.x+90; // left    
    else
        posX = offset.x - point.x - width-90; // right    
    	
    var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(posX, posY)); 
	
    pos.apply(divTooltipNode);
    divTooltipNode.style.visibility="visible";	 
    divTooltipNode.style.width="170px";  	
}


function showEventInfoWindow(innerHtml, lon, lat, size)
{
    //*******************************************************
    //* This function shows Event Info Window
    //*******************************************************
    var infoHtmls;
    
    //alert(innerHtml);        
    //var infoHtmls = '<div style="font-size:medium;width:550px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");>';	
    //var infoHtmls = '<div style="font-size:medium;width:500px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';	
    if (parseInt(size) < 2)
    {
        if (innerHtml.indexOf("affectedLanesLegend") != -1)
            //infoHtmls = '<div style="font-size:medium;width:450px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
            infoHtmls = '<div style="font-size:medium;width:450px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
	    else
	        //infoHtmls = '<div style="font-size:medium;width:350px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
	        infoHtmls = '<div style="font-size:medium;width:350px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
    }
    else if (parseInt(size) == 2)
        if (innerHtml.indexOf("affectedLanesLegend") != -1)
            //infoHtmls = '<div style="font-size:medium;width:450px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
            infoHtmls = '<div style="font-size:medium;width:450px;height:380px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
	    else
	        //infoHtmls = '<div style="font-size:medium;width:350px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
	        infoHtmls = '<div style="font-size:medium;width:350px;height:320px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
    else
    {    
        if (innerHtml.indexOf("affectedLanesLegend") != -1)
            //infoHtmls = '<div style="font-size:medium;width:450px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
            infoHtmls = '<div style="font-size:medium;width:450px;height:380px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
	    else
	        //infoHtmls = '<div style="font-size:medium;width:350px;height:450px;overflow:auto;" onmouseover=hideEventTooltip("");hideNodeTooltip();>';
	        infoHtmls = '<div style="font-size:medium;width:350px;height:380px;overflow:auto;" onmouseover=hideEventTooltip();hideNodeTooltip();>';
	}		
	//var divTooltipInfo = document.getElementById("divTooltipInfo");	
	var divEventPopInfo = document.createElement('div');
	divEventPopInfo.setAttribute("id", "divEventPopInfo");
	//divEventPopInfo.style.width="700px"; 
    divEventPopInfo.innerHTML = infoHtmls + innerHtml + "</div>";
            
    saveMapPosition(); 
    
    //isWindowOpen(true);  
    
    wOpenFlag = true; 
    
    googleMap.openInfoWindowHtml(new GLatLng(lat, lon), divEventPopInfo.innerHTML, {onCloseFn: function() { 
    googleMap.closeInfoWindow(); returnToSavedPosition(); wOpenFlag = false; } });   
                 
    //googleMap.openInfoWindowHtml(new GLatLng(lat, lon), divEventPopInfo.innerHTML, {onCloseFn: function() { 
    //googleMap.closeInfoWindow(); returnToSavedPosition(); wOpenFlag = false; curLon = 0; curLat = 0;}}); 
    
    /* test
    var offset = new GSize(300,0); 
    googleMap.openInfoWindow(new GLatLng(lat, lon), divEventPopInfo.innerHTML, {pixelOffset:offset,onCloseFn: function() { 
    googleMap.closeInfoWindow(); returnToSavedPosition(); wOpenFlag = false; curLon = 0; curLat = 0;}}); 
    */
}

function saveMapPosition()
{
    googleMap.savePosition();
} 

function returnToSavedPosition()
{
    googleMap.returnToSavedPosition();

}

function removeImageLayer(layerImage, map)
{
    //GLog.write('layerImage=' + layerImage + ';map=' +  map);
    if (layerImage != null)
	    map.removeOverlay(layerImage);	
}

function getObject(obj, typeobj)
{
    var ret;
    
    if (obj == null || obj == undefined)
    {
        if (typeobj == "eventimage")
            ret = parent.parent.eventImage;
        else if (typeobj == "mapframe")
            ret = parent.parent.MapFrame;
        else
            ret = parent.parent.googleMap; 
    }        
    else
        ret = obj;
        
     //GLog.write('ret=' + ret);   
    return ret;       
}

function changeLinkColorOnMap(featureName)
{
    //*****************************************************
   //* This function add event layers to map
   //*****************************************************
   //alert(featureName);
   if (featureName != "")
   {            
       if (getObject(googleMap, "map") != undefined && getObject(googleMap, "map") != null)
       {
        var boundingBox = parent.parent.googleMap.getBounds();       
        var southWest = boundingBox.getSouthWest();
        var northEast = boundingBox.getNorthEast();
        var thisZoom = getObject(googleMap, "map").getZoom();
        
        var mapHeight;
        var mapWidth;
        
        var thisExtents = southWest.x + ' ' + southWest.y + ',' + northEast.x + ' ' + northEast.y;
   
        try 
        {                    
            var coords = thisExtents.split(",");
		    var coords1 = coords[0].split(" ");
		    var coords2 = coords[1].split(" ");
    		
		    var boundaries = new GLatLngBounds(new GLatLng(parseFloat(coords1[1]),parseFloat(coords1[0])), 
		                                        new GLatLng(parseFloat(coords2[1]),parseFloat(coords2[0])));		                                       		                                       
	    
		    //* get size of "map_canvas" div                               
		    //if (getObject(parent.parent.MapFrame, "mapframe").style.pixelHeight && getObject(parent.parent.MapFrame, "mapframe").style.pixelWidth)
		    if (parent.parent.document.getElementById("MapFrame").style.pixelHeight && parent.parent.document.getElementById("MapFrame").style.pixelWidth)
		    {   //alert(parent.parent.MapFrame.style.pixelHeight + ';' + parent.parent.MapFrame.clientHeight + ';' + parent.parent.MapFrame.clientWidth);		         
		        mapHeight = parent.parent.document.getElementById("MapFrame").style.pixelHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").style.pixelWidth;        
             }
            else
            {                 
		        mapHeight = parent.parent.document.getElementById("MapFrame").clientHeight;
		        mapWidth = parent.parent.document.getElementById("MapFrame").clientWidth;   		              
            }                                  	                                  
    		//alert(mapHeight + ';' + mapWidth + ';' + document.getElementById("MapFrame").clientWidth);
    		if (wOpenFlag == false)	
    		{
	            if (parent.parent.googleMap != null && parent.parent.eventImage != null)
	            {
	                //parent.parent.googleMap.removeOverlay(parent.parent.eventImage);
	                //parent.parent.googleMap.removeOverlay(eventImage);
	                parent.parent.googleMap.clearOverlays();    
                }        
                if (googleMap != null && eventImage != null)
                {//alert('clear');
                    //googleMap.removeOverlay(eventImage);
                    //googleMap.removeOverlay(parent.parent.eventImage);
                    googleMap.clearOverlays();	 
                }           
    	     }   	    	    	       	   	   
    	
	        //* create URL for GeoServer				
	        var geoServerUrl = "http://" + HOST_GEO_SERVER + PORT + "/geoserver/wms?bbox=" + 
	                        coords1[0] + "," + coords1[1] + "," + coords2[0] + "," + coords2[1] + 
                            "$tiled=null$styles=$Format=image/png$request=GetMap$layers=" + featureName + 
                            "$width=" + mapWidth + "$height=" + mapHeight + 
                            "$srs=EPSG:4326$TRANSPARENT=TRUE$count=0$tilesorigin=" + 
                            coords1[0] + "," + coords2[1] + "$CQL_FILTER=INCLUDE"; 
            // alert(geoServerUrl);    
            var pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl;
            //alert(pathUrl);
            //alert(parent.EInsert);
            //* create all images            
            eventImage = EInsert.groundOverlay(pathUrl, boundaries);   
                     
            //* add all images to GMap
            //parent.parent.googleMap.addOverlay(eventImage);  
            
            if (googleMap != null) 
                googleMap.addOverlay(eventImage);      
            else
                parent.parent.googleMap.addOverlay(eventImage);     
                
            //GLog.write('LINK_LIST=' + LINK_LIST + '   ;   parent.parent.LINK_LIST=' + parent.parent.LINK_LIST);    
            //GLog.write(DTFlag + ';' + parent.parent.DTFlag);
            //GLog.write(DTFlag + ';' + LINK_LIST);
            if (DTFlag == true || parent.parent.DTFlag == true)
            {
                if (LINK_LIST != "" || parent.parent.LINK_LIST != "")
                {
                    var filter = "";
                    if (LINK_LIST != "")
                        filter = getFilter(LINK_LIST);
                    else
                        filter = getFilter(parent.parent.LINK_LIST);    
                    
                    geoServerUrl = "http://" + HOST_GEO_SERVER + PORT + "/geoserver/wms?bbox=" + 
	                                coords1[0] + "," + coords1[1] + "," + coords2[0] + "," + coords2[1] + 
                                    "$tiled=null$styles=$Format=image/png$request=GetMap$layers=" + getLinkSelected() + 
                                    "$width=" + mapWidth + "$height=" + mapHeight + 
                                    "$srs=EPSG:4326$TRANSPARENT=TRUE$count=0$tilesorigin=" + 
                                    coords1[0] + "," + coords2[1] + "$CQL_FILTER=" + filter;
                    
                    pathUrl = "/GSHandler/GSHandler/GSHandler.ashx?command=GetMap&geoUrl=" + geoServerUrl;
                    
                    tripImage = EInsert.groundOverlay(pathUrl, boundaries);   
                            
                    if (googleMap != null) 
                        googleMap.addOverlay(tripImage);      
                    else
                        parent.parent.googleMap.addOverlay(tripImage);         
                
                }
            }                
        
        }
	    catch (ee) {
		    alert(ee.message);
		        return false;
	    }
    	    
	    return true;
	    }
	    else
	        return false;
    }	  
}

function setThemeColor(themeColor)
{
    //THEME_COLOR = themeColor;
    
    parent.document.getElementById("hdnTheme").value = themeColor;
    //alert(document.getElementById('ThemeName').value);
    //alert(parent.document.getElementById('hdnTheme').value);
    /*
    switch (themeColor) {
		case "contrast":
			document.i1.src="images/color-green.gif"; // #63d663
			document.i2.src="images/color-aqua.gif";    // #00ffcc
			document.i3.src="images/color-yellow.gif"; // #ffff00
			document.i4.src="images/color-red.gif";    // #ff0033
			document.i5.src="images/color-white.gif";   // #ffffff
			break;
		case "deutan":
			document.i1.src="images/color-blue.gif";    // #3300ff
			document.i2.src="images/color-yellow.gif"; // #ffff00
			document.i3.src="images/color-red.gif";    // #ff0033
			document.i4.src="images/color-black.gif";   // #000000
			document.i5.src="images/color-white.gif";   // #ffffff
			break;
		case "tritan":
			document.i1.src="images/color-blue.gif";    // #3300ff
			document.i2.src="images/color-aqua.gif";    // #00ffcc
			document.i3.src="images/color-red.gif";     // #ff0033
			document.i4.src="images/color-pink.gif";    // #ffccff
			document.i5.src="images/color-white.gif";   // #ffffff
			break;
		default:
			document.i1.src="images/color-green.gif";  // #63d663
			document.i2.src="images/color-yellow.gif"; // #ffff00
			document.i3.src="images/color-red.gif";    // #ff0033
			document.i4.src="images/color-black.gif";   // #000000
			document.i5.src="images/color-lightblue.gif";   // #ccccff
	}
	*/	
	
	//changeLinkColorOnMap(getColorTheme(themeColor));
	
	showEventLayers(getParentLayers(), "", "");
	
	//hidePleaseWaitScreen();
}

function getColorTheme(themeColor)
{
    var themeFeature = "";
	
	switch (themeColor) {
		case "contrast":
			//themeFeature = vwLinkContrast;
			themeFeature = getLinkLayerTheme("contrast");
			break;
		case "deutan":
			//themeFeature = vwLinkDeutan;
			themeFeature = getLinkLayerTheme("deutan");
			break;
		case "tritan":
			//themeFeature = vwLinkTritan;
			themeFeature = getLinkLayerTheme("tritan");
			break;
		default:
			//themeFeature = vwLink;
			themeFeature = getLinkLayer();
	}
	
	return themeFeature;
}

function getElements(node,tag_prefix,tag_name)
{ 
   return node.getElementsByTagName(tag_prefix+":"+tag_name);
}

function showTrip(item) {
	var el = getElementsByClass(document,'trip','*', item);
	//alert(el.length);
}

function clearMap()
{

    if (parent.parent.googleMap != null && parent.parent.eventImage != null)
    {
        //parent.parent.googleMap.removeOverlay(parent.parent.eventImage);
        //parent.parent.googleMap.removeOverlay(eventImage);
        parent.parent.googleMap.clearOverlays();    
    }        
    if (googleMap != null && eventImage != null)
    {  
        //googleMap.removeOverlay(eventImage);
        //googleMap.removeOverlay(parent.parent.eventImage);
        googleMap.clearOverlays();	 
    }   
        
}

function getElementsByClass(node, searchClass,tag, item) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");

	for (i = 0, j = 0; i < elsLen; i++)
	{
		 if ( pattern.test(els[i].className) )
		 {//alert(els[i].id);
			
			var id = getId(els[i].id);
			//alert(id);

			//if (els[i].id == "trip" + item)
			if (id == item)
			{			
				//alert(els[i].id);
				if (els[i].style.display == "table-cell")
				{
					els[i].style.display = "none";
				}
				else
				{
					els[i].style.display = "table-cell";
				}
			}
			else
			{
				if (els[i].id.indexOf("trip_") != -1)
					els[i].style.display = "none";
				else
					els[i].style.display = "table-cell";

			}			
			 
		 }
	}
	
	return classElements;
}

function getId(itemId)
{
	//var index = itemId.indexOf("trip_");
	var ret = "";

	if (itemId.indexOf("trip_") != -1)
	{
		ret = itemId.substring(itemId.indexOf("trip_")+5);
	}
	else if (itemId.indexOf("trip") != -1)
	{
		ret = itemId.substring(itemId.indexOf("trip")+4);;
	}
	
	//alert(ret);

	return ret;
}

//function getEventsBufferValueX()
//{
//    var zlevel = googleMap.getZoom();		
//	var bufferValue=0.00001;
//	//alert(zlevel);
//	GLog.write(zlevel);
//	if(zlevel>15){
//		bufferValue=0.00001;	
//	}else if(zlevel==15){
//		bufferValue=0.0004;
//	}else if(zlevel==14){
//		bufferValue=0.0009;
//	}else if(zlevel==13){
//		bufferValue=0.002;
//	}else if(zlevel==12){
//		bufferValue=0.0035;
//	}else if(zlevel==11){
//		bufferValue=0.0065;
//	}else if(zlevel==10){
//		bufferValue=0.015;
//	}else if(zlevel==9){
//		bufferValue=0.03;
//	}else if(zlevel==8){
//		bufferValue = 0.06;
//	}else if(zlevel<=7){
//		bufferValue = 0.01;
//	}
//	
//    return 	 bufferValue;  
//}

//function getEventsBufferValueY()
//{
//    var zlevel = googleMap.getZoom();		
//	var bufferValue=0.00001;
//	
//	if(zlevel>15){
//		bufferValue=0.00001;	
//	}else if(zlevel==15){
//		bufferValue=0.0002;
//	}else if(zlevel==14){
//		bufferValue=0.0004;
//	}else if(zlevel==13){
//		bufferValue=0.0007;
//	}else if(zlevel==12){
//		bufferValue=0.0015;
//	}else if(zlevel==11){
//		bufferValue=0.003;
//	}else if(zlevel==10){
//		bufferValue=0.005;
//	}else if(zlevel==9){
//		bufferValue=0.02;
//	}else if(zlevel==8){
//		bufferValue = 0.035;
//	}else if(zlevel<=7){
//		bufferValue = 0.01;
//	}
//	
//    return 	 bufferValue;  
//}

function getEventsBufferValueX()
{
    var zlevel = googleMap.getZoom();		
	var bufferValue=0.00001;
	//alert(zlevel);
	//GLog.write(zlevel);
	if(zlevel>15){
		bufferValue=0.000005;	
	}else if(zlevel==15){
		//bufferValue=0.0004;
		bufferValue=0.00001;
	}else if(zlevel==14){
		bufferValue=0.0009;
	}else if(zlevel==13){
		bufferValue=0.002;
	}else if(zlevel==12){
		bufferValue=0.0035;
	}else if(zlevel==11){
		//bufferValue=0.0065;
		bufferValue=0.006;
	}else if(zlevel==10){
		//bufferValue=0.015;
		bufferValue=0.007;
	}else if(zlevel==9){
		bufferValue=0.03;
	}else if(zlevel==8){
		bufferValue = 0.06;
	}else if(zlevel<=7){
		bufferValue = 0.01;
	}
	
    return 	 bufferValue;  
}

function getEventsBufferValueY()
{
    var zlevel = googleMap.getZoom();		
	var bufferValue=0.00001;
	
	if(zlevel>15){
		//bufferValue=0.00002;
		bufferValue=0.000005;	
	}else if(zlevel==15){
		//bufferValue=0.0002;
		bufferValue=0.00001;
	}else if(zlevel==14){
		bufferValue=0.0004;
	}else if(zlevel==13){
		bufferValue=0.0007;
	}else if(zlevel==12){
		bufferValue=0.0015;
	}else if(zlevel==11){
		bufferValue=0.003;
	}else if(zlevel==10){
		//bufferValue=0.005;
		bufferValue=0.004;
	}else if(zlevel==9){
		bufferValue=0.02;
	}else if(zlevel==8){
		bufferValue = 0.035;
	}else if(zlevel<=7){
		bufferValue = 0.01;
	}
	
    return 	 bufferValue;  
}

function getEventsBufferValueX1()
{
    var zlevel = googleMap.getZoom();		
	var bufferValue=0.00001;
	
	if(zlevel>15){
		bufferValue=0.000005;	
	}else if(zlevel==15){
		bufferValue=0.0001;
	}else if(zlevel==14){
		bufferValue=0.0005;
	}else if(zlevel==13){
		bufferValue=0.001;
	}else if(zlevel==12){
		bufferValue=0.002;
	}else if(zlevel==11){
		bufferValue=0.004;
	}else if(zlevel==10){
//		bufferValue=0.010;
        bufferValue=0.012;
	}else if(zlevel==9){
		bufferValue=0.02;
	}else if(zlevel==8){
		bufferValue = 0.03;
	}else if(zlevel<=7){
		bufferValue = 0.01;
	}
	
    return 	 bufferValue;  
}

function showPleaseWaitScreen(waitText){
    //show please wait screen depending on what user does - either for 
    //first time or to update map
    
    var pleaseWaitScreen = new getObj("pleaseWaitScreen");    
    
    //var spanPleaseWaitText = new getObj('pleaseWaitText');
    //spanPleaseWaitText.obj.firstChild.nodeValue = waitText;
    
    if (pleaseWaitScreen.obj != null)
        pleaseWaitScreen.obj.style.visibility = "visible";   
    else
    {
        pleaseWaitScreen = parent.parent.document.getElementById("pleaseWaitScreen");
        if (pleaseWaitScreen != null)
            pleaseWaitScreen.style.visibility = "visible";
    }          
}

function hidePleaseWaitScreen(){
    //hide and reset please wait screen    
    
    var pleaseWaitScreen = new getObj("pleaseWaitScreen");    
    
    if (pleaseWaitScreen.obj != null)
        pleaseWaitScreen.obj.style.visibility = "hidden";    
    else
    {
        pleaseWaitScreen = parent.parent.document.getElementById("pleaseWaitScreen");
        
        if (pleaseWaitScreen != null)
            pleaseWaitScreen.style.visibility = "hidden";    
    }    
       
}

function getObj(name) {
	if (document.getElementById) {
	    if (document.getElementById(name) != null) {
        this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
		} else {
		    this.obj = null;
		    this.style = null;
		}
	}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
        this.obj = document.layers[name];
        this.style = document.layers[name];
	}
}

function getEventsBufferValueY1()
{
    var zlevel = googleMap.getZoom();		
	var bufferValue=0.00001;
	
	if(zlevel>15){
		bufferValue=0.000005;	
	}else if(zlevel==15){
		bufferValue=0.0001;
	}else if(zlevel==14){
		bufferValue=0.0002;
	}else if(zlevel==13){
		bufferValue=0.0004;
	}else if(zlevel==12){
		bufferValue=0.0010;
	}else if(zlevel==11){
		bufferValue=0.002;
	}else if(zlevel==10){
//		bufferValue=0.003;
		bufferValue=0.004;
	}else if(zlevel==9){
		bufferValue=0.01;
	}else if(zlevel==8){
		bufferValue = 0.020;
	}else if(zlevel<=7){
		bufferValue = 0.01;
	}
	
    return 	 bufferValue;  
}

function Minutes(seconds, places)
{
    var ret = "N/A";
    
	if (seconds != "" && seconds != "0")
		ret = Math.round(parseInt(seconds)/60, parseInt(places))
		
	return ret;
}

function getFormattedDate(d)
{
    //var ymdDelimiter = "-";  
    var date;
    var time;
    var h;
    var m;
    var splitArr = new Array();
    
    if (d == "")
        return "";
    
    //2011-05-03T08:28:40-04:00   
    splitArr = d.split("T"); 
       
    date = splitArr[0];
    time = splitArr[1]; 
    
    splitArr = date.split("-"); 
    date = parseInt(splitArr[1], 10) + "/" + splitArr[2] + "/" + splitArr[0];  
    
    splitArr = time.split("-"); 
    time = splitArr[0];
    
    splitArr = time.split(":");
    
    h = parseInt(splitArr[0], 10);
    m = splitArr[1];       
    
    var a_p = "";
    
    if (h < 12)
       {
       a_p = "AM";
       }
    else
       {
       a_p = "PM";
       }       
    
    if (h > 12)
    {
       h = h - 12;
    }   

    m = m + "";

    if (m.length == 1)
    {
       m = "0" + m;
    }

    
    
    return date + " " + h + ":" + m + " " + a_p;   
}

function Capitalize(word)
{
   return word.charAt(0).toUpperCase() + word.slice(1);
}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date, format) {

    var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;		
	
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	
	
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
		
	return result;
}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
}

// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
}

function whichBrs() {
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
    if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
    return navigator.userAgent.substr(0,agt.indexOf('\/'));}
    else return 'Netscape';} else if (agt.indexOf(' ') != -1)
    return navigator.userAgent.substr(0,agt.indexOf(' '));
    else return navigator.userAgent;
}

// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
}


function LZ(x) {return(x<0||x>9?"":"0")+x}

//-----------------------------------------------------------------------

//-------------- for Alert Messages on Map ------------------------------
var alertBoxChangeTimeout;
var alertBoxCurrentMessage = -1;
//var alertBoxMessages = new Array();
//alertBoxMessages[0] = "<SPAN style='COLOR: #000000'>Caltrans Highway Road Closures Reported Hourly</SPAN>";
//alertBoxMessages[1] = "<SPAN style='COLOR: #000000'>Information on October fires is available from the Office of Emergency Services</SPAN>";

function alertBoxDisplayNextMessage() {
    /// <summary>Rotates current Alert Box message to the next message in the cycle and displays it.</summary>
    //GLog.write(alertBoxMessages.length);
    //GLog.write(alertBoxMessages.length);
    
    
    alertBoxCurrentMessage++;
    if (alertBoxCurrentMessage >= alertBoxMessages.length) {
        alertBoxCurrentMessage = 0;
    }

    if (alertBoxMessages.length == 1) {
        alertBoxShowMessage();
    }
    else if (alertBoxMessages.length > 1) {
        if ($("#AlertBoxContent").html() != "") {
            alertBoxHideMessage(alertBoxShowMessage);
        }
        else {
            alertBoxShowMessage();
        }
    }
    
    //* SK
    //if (alertBoxMessages.length == 0) {
    //    alertBoxHide();              
        //document.getElementById("frameToolbar").height = "500px";
    //}   
         
    //alert(alertBoxMessages.length + ';' + alertBoxChangeTimeout);
    if (alertBoxMessages.length > 1 && alertBoxChangeTimeout == null) {
        alertBoxChangeTimeout = setInterval("alertBoxDisplayNextMessage();", 8 * 1000);
    }
}

function alertBoxHideMessage(callbackFunction) {
    /// <summary>Hides message currently in Alert Box and optionally calls another function when complete.</summary>
    /// <param name='callbackFunction' type='Function'>Optional.  Function to call when hiding is complete.</param>
    if (callbackFunction == null) {
        $("#AlertBoxContent").hide("slow");
    }
    else {
        $("#AlertBoxContent").hide("slow", callbackFunction);
    }
}

function alertBoxShowMessage() {
    /// <summary>Shows the current message in the Alert Box.</summary>
    $("#AlertBoxContent").html(alertBoxMessages[alertBoxCurrentMessage]);
    if (alertBoxMessages.length > 1) {
        $("#AlertBoxCount").html("(" + (alertBoxCurrentMessage + 1) + " of " + alertBoxMessages.length + ")");
    }
    $("#AlertBoxContent").show("slow");
}

//function alertBoxShow() {
//    /// <summary>Sets display=block to all DOM components of the AlertBox.</summary>
//    var alertBoxComponents = new Array("Div", "TitleBar", "Title", "Count", "ContentHolder", "Content");
//    for (var i = 0; i < alertBoxComponents.length; i++) {
//        $("#AlertBox" + alertBoxComponents[i]).show();
//    }
//    //$("#AlertBoxDiv").corner();
//    //$("#AlertBoxContentHolder").corner();
//}

function alertBoxShow() {
    /// <summary>Sets display=block to all DOM components of the AlertBox.</summary>
    var alertBoxComponents = new Array("Div", "TitleBar", "Title", "Count", "ContentHolder", "Content");    
    for (var i = 0; i < alertBoxComponents.length; i++) {
        //$("#AlertBox" + alertBoxComponents[i]).show();        
        document.getElementById("AlertBox" + alertBoxComponents[i]).style.display = "block";
    }
    //$("#AlertBoxDiv").corner();
    //$("#AlertBoxContentHolder").corner();
}

function alertBoxHide() {
    /// <summary>Sets display=block to all DOM components of the AlertBox.</summary>
    var alertBoxComponents = new Array("Div", "TitleBar", "Title", "Count", "ContentHolder", "Content");    
    for (var i = 0; i < alertBoxComponents.length; i++) {
        //$("#AlertBox" + alertBoxComponents[i]).show();        
        document.getElementById("AlertBox" + alertBoxComponents[i]).style.display = "none";
    }
    //$("#AlertBoxDiv").corner();
    //$("#AlertBoxContentHolder").corner();
}
//----------------------------------------------------------------------


//* FOR TESTING ONLY 
//function XHConn()
//{
//  var xmlhttp, bComplete = false;
//  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
//  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
//  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
//  catch (e) { xmlhttp = false; }}}
//  if (!xmlhttp) return null;
//  this.connect = function(sURL, sMethod, sVars, fnDone)
//  {
//    if (!xmlhttp) return false;
//    bComplete = false;
//    sMethod = sMethod.toUpperCase();
//    try {
//      if (sMethod == "GET")
//      {
//        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
//        sVars = "";
//      }
//      else
//      {
//        xmlhttp.open(sMethod, sURL, true);
//        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
//        xmlhttp.setRequestHeader("Content-Type",
//          "application/x-www-form-urlencoded");
//      }
//      xmlhttp.onreadystatechange = function(){
//        if (xmlhttp.readyState == 4 && !bComplete)
//        {
//          bComplete = true;
//          fnDone(xmlhttp);
//        }};
//      xmlhttp.send(sVars);
//    }
//    catch(z) { return false; }
//    return true;
//  };
//  return this;
//}

//// doAJAXCall : Generic AJAX Handler, used with XHConn
//// Author : Bryce Christensen (www.esonica.com)
//// PageURL : the server side page we are calling
//// ReqType : either POST or GET, typically POST
//// PostStr : parameter passed in a query string format 'param1=foo&param2=bar'
//// FunctionName : the JS function that will handle the response

//var doAJAXCall = function (PageURL, ReqType, PostStr, FunctionName) {

//	// create the new object for doing the XMLHTTP Request
//	var myConn = new XHConn();

//	// check if the browser supports it
//	if (myConn)	{
//	    
//	    // XMLHTTPRequest is supported by the browser, continue with the request
//	    myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);    
//	} 
//	else {
//	    // Not support by this browser, alert the user
//	    alert("XMLHTTP not available. Try a newer/better browser, this application will not work!");   
//	}
//}

//// launched from button click 
//var getMessage = function () {
//	alert();
//	// build up the post string when passing variables to the server side page
//	var PostStr = "";
//	
//	// use the generic function to make the request
//	doAJAXCall('requestGS.asp', 'POST', '', showMessageResponse);
//}

//// The function for handling the response from the server
//var showMessageResponse = function (oXML) { 
//    
//    // get the response text, into a variable
//    var response = oXML.responseText;
//    
//    alert(response);
//    // update the Div to show the result from the server
//	//document.getElementById("responseDiv").innerHTML = response;
//};
//***********************************************************************
