var incMarkers = new Array();
var constMarkers = new Array();
var specevtMarkers = new Array();
var busMarkers = new Array();

var eventMarkers = new Array();
var existingArray = new Array();
var addFlag = true;
var checkExisting = false; //flag to check existing array - only changes if we've already gotten data

var incVisible = false;
var constVisible = false;
var specevtVisible = false;
var busVisible = false;

//3-29-07 added to fix events that overlap
var previousLat = 0;
var previousLon = 0;
var appendDesc = false;
var lastIndex = 0;
var htmlDescs = new Array();
var idArray = new Array();
//end 3-29-07

function createPopups(elem, xmlDoc) {
	//create popups from XML data
	
	//initialize markers to display false - send type to display false
	initializeEventMarkers(eventMarkers);
	
	var incChecked = document.main.incCheck.checked;
	var constChecked = document.main.constCheck.checked;
	var specevtChecked = document.main.specevtCheck.checked;
	var busChecked = document.main.busCheck.checked;
	
	//3-29-07 
	//keep track of new markers added
	var addCount = 0;
	//end 3-29-07
	
	for (var i = 0; i < elem.length; i++) {

	    //loop through and create markers	
		
		//since we have layer checkboxes, we wont want to display the marker if the
		//checkbox is unchecked, or layer is toggled off - we can store the marker 
		//for later use - just don't add the overlay
		var displayMarker = true;
		
		var urlStart = 0;
		var urlEnd = 0;
		var x = 0;
		var urlString = "";
		var leftPart = "";
		var rightPart = "";
		var urlInString = false;
		
		var incType = xmlDoc.getElementsByTagName("IncType")[i].firstChild.nodeValue;
		var eventMode = xmlDoc.getElementsByTagName("Event_Mode")[i].firstChild.nodeValue.toLowerCase();
		var facility = xmlDoc.getElementsByTagName("Facility")[i].firstChild.nodeValue;
		var incDescLong = xmlDoc.getElementsByTagName("IncDescLong")[i].firstChild.nodeValue;
		var lat = parseFloat(xmlDoc.getElementsByTagName("Event_Lat")[i].firstChild.nodeValue)*.000001;
		var lon = parseFloat(xmlDoc.getElementsByTagName("Event_Lon")[i].firstChild.nodeValue)*.000001;
		var lastActionUpdate = xmlDoc.getElementsByTagName("LastActionUpdate")[i].firstChild.nodeValue;
		var reportOrgName = xmlDoc.getElementsByTagName("Report_Org_Name")[i].firstChild.nodeValue;
		var startDate = xmlDoc.getElementsByTagName("IncVerifiedDateTime")[i].firstChild.nodeValue;
		var endDate = xmlDoc.getElementsByTagName("IncExpDateTime")[i].firstChild.nodeValue;
		var incID = xmlDoc.getElementsByTagName("IncID")[i].firstChild.nodeValue;
		var URL = xmlDoc.getElementsByTagName("URL")[i].firstChild.nodeValue;
		var urlAlias = xmlDoc.getElementsByTagName("urlAlias")[i].firstChild.nodeValue;
		var urlDisplayAs = xmlDoc.getElementsByTagName("urlDisplayAs")[i].firstChild.nodeValue;
		
		var textColor = "";
		var pointType = "";	
		
		if (eventMode == "buses") {
    		pointType = "buses";
    	}
    	else if (incType == "Incident"){
    		pointType = "1";
    	}
    	else if ((incType == "Transit Incident") && (eventMode != "buses")){
    		pointType = "2";
    	}
    	else if (incType == "Active Construction"){
    		pointType = "3";
    	}
    	else if ((incType == "Transit Active Construction") && (eventMode != "buses")){
    		pointType = "4";
    	}
    	else if (incType == "Construction"){
    		pointType = "5";
    	}
    	else if (incType == "Transit Construction"){
    		pointType = "6";
    	}
    	else if (incType == "Special Event"){
    		pointType = "7";
    	}
    	else if (incType == "Active Highway Special Event"){
    		pointType = "14";
    	}
    	else if (incType == "Transit Special Event"){
    		pointType = "16";
    	}
    	else if (incType == "Active Transit Special Event"){
    		pointType = "17";
    	}
    	else{
    		pointType = "17";
    	}
    			
		if (checkExisting) {
			var addToExistingArray = false;
			//we already have data in the array, now check to see if we need to remove markers
			//3-29-07 - need to modify to check all ID's - maintain a separate ID array and loop over it
			//this is because if a marker co-existed, it was not created as new, but the ID should be processed
			//for (var n = 0; n < eventMarkers.length; n++) { old
				//var markerID = eventMarkers[n].getId(); old
			//GLog.write("checkExisting incID: " + incID);
			for (var n = 0; n < idArray.length; n++) {
			    //GLog.write("checkExisting incID: " + incID + " , idArray: " + idArray[n]);
				var markerID = idArray[n];
				if (incID == markerID){
				    appendDesc = false;
				    //GLog.write("found a match, incID is: " + incID);
				    //event already on map - do not display twice
	                
					//now set display flag based on checkbox status --- ugghh
					if ((pointType == "1") || (pointType == "2")) {
						if (incChecked) {
							addToExistingArray = true;
						}
					}
					else if ((pointType == "3") || (pointType == "4") || (pointType == "5") || (pointType == "6")) {
						if (constChecked) {
							addToExistingArray = true;
						}
					}
					else if ((pointType == "7") || (pointType == "14") || (pointType == "16") || (pointType == "17")) {    
						if (specevtChecked) {
							addToExistingArray = true;
						}
					}
					else if (pointType == "buses") {
						if (busChecked) {
							addToExistingArray = true;
						}
					}
	                
					if (addToExistingArray) {
						existingArray[existingArray.length] = markerID;
					}
					addFlag = false;
					break;
				}
				else {
					//marker does not exist - set add flag to true to notify that
					//we have to add it to the map
					addFlag = true;  
				}
			}        
		}
	    
	    //3-29-07 now check lat/lon to find out if we need to append description or create a new marker
	    //if addFlag is true, means we have a new event.
		//find difference between last point passed and current point, lat and long. Since the precision
		//is .001 degrees = about 278ft., check the difference to the nearest thousandth. If the abs. value of the difference of
		//lat and long is less than .002 or roughly 600ft., then combine the incident descriptions, and don't create a new marker. 
		//don't do first iteration
		if (addFlag) {
			var dLat = Math.abs(previousLat - lat)*1000;
			var dLon = Math.abs(previousLon - lon)*1000;
			if ((dLat < 2) && (dLon < 2)) {
				//append to previous desc
				appendDesc = true;
				addFlag = false;
			}	
			else{
				appendDesc = false;
			}
			//end 3-29-07	
		}
		
	    if ((addFlag) && (!appendDesc)) {
	   	   	//create new markers
	    	var point = new GLatLng(lat,lon);	
	    				
    		if ((pointType == "buses")) {
	    		
    			textColor = "#000000";
    			icon = busIcon;
    			busVisible = true;	
	
    			var busMarker = new PdMarker(point, icon);
    			tmpMarker = busMarker;
    			busMarkers.push(busMarker);
	    		
    			if (!document.main.busCheck.checked) {
    				displayMarker = false;
    			}
    		}
	    			
    		else if ((pointType == "1") || (pointType == "2")) {
	    		
    			icon = incIcon;
    			textColor = "#990000";
    			incVisible = true;
	      	
    			var incMarker = new PdMarker(point, icon);
    			tmpMarker = incMarker;
    			incMarkers.push(incMarker);
	    		
	    		
    			if (!document.main.incCheck.checked) {
    				displayMarker = false;
    			}
    		}
	    	
    		else if ((pointType == "3") || (pointType == "4") || (pointType == "5") || (pointType == "6")) {
	    		
    			icon = constIcon; 
    			textColor = "#009900";
    			constVisible = true;
	    		  	
    			var constMarker = new PdMarker(point, icon);
    			tmpMarker = constMarker;
    			constMarkers.push(constMarker);
	    		
    			if (!document.main.constCheck.checked) {
    				displayMarker = false;
    			}
    		}
	    	
    		else if ((pointType == "7") || (pointType == "14") || (pointType == "16") || (pointType == "17")) {
	    		
    			icon = specEvtIcon; 
    			textColor = "#000099";
    			specevtVisible = true;	
	      	
    			var specevtMarker = new PdMarker(point, icon);
    			tmpMarker = specevtMarker;
    			specevtMarkers.push(specevtMarker);
	    		
    			if (!document.main.specevtCheck.checked) {
    				displayMarker = false;
    			}
    		}
	    		
	    	var length = eventMarkers.length;
	    		
	    	//1-24-08 - add ability to search for either http:// or www. in the description. If exists, consider it a URL	
	        if (incDescLong.indexOf('http://') != -1) {
	            urlStart = incDescLong.indexOf('http://'); 
	            urlInString = true;
	        }
	        else if (incDescLong.indexOf('www') != -1) {
	            urlStart = incDescLong.indexOf('www');  
	            urlString = "http://";
	            urlInString = true;
	        }
	        
	        //loop over URL string and make an hyperlink
	        if (urlInString) {
				for (x = urlStart; x < incDescLong.length; x++){
					if (incDescLong.charAt(x) == ' ') {
						//if we've reached the end of the url string, mark the character and exit
						urlEnd = x+1;
						break;
					}
					urlString += incDescLong.charAt(x);        
				}
		    	
	    		leftPart = Left(incDescLong, 0, urlStart);
	    		rightPart = Right(incDescLong, incDescLong.length - urlEnd + 1);
		    	
	    		incDescLong = leftPart + '<a href="' + urlString + '" target="_blank" style="color: #000066;">';
		    	incDescLong += ' More Info' + '</a>' + rightPart;
	    	}
	    		
    		incDescLong = '<b><font style="color: ' + textColor + ';">' + incDescLong + '</font></b><br />';
    		startDate = '<b><font style="color: #000066;">Start Date: ' + startDate + '</font></b><br />';
    		endDate = '<b><font style="color: #000066;">End Date: ' + endDate + '</font></b><br />';
	    									
    		// BUILD HTML MARKUP for info window
    		//3-29-07 slightly modified for look
    		/*
			var infoHtmls = '<div align="left" class="markerinfo" style="width:260px; font-size: 11px;">';
			infoHtmls += '...... from creating ......';
    		infoHtmls += '<b><font style="color: #000066;">Reported By: ' + reportOrgName + '</font></b><br />';	
    		infoHtmls += '<br />';		
    		infoHtmls += incDescLong;
			infoHtmls += '<br />';
	        infoHtmls += startDate;
			infoHtmls += endDate;
			infoHtmls += '</div>';*/
			var infoHtmls = '<div align="left" class="markerinfo" style="font-size: 10px; width: 375px;">';
    		infoHtmls += '<b><font style="color: #000066;">Reported By: ' + reportOrgName + '</font></b>';	
    		infoHtmls += '<br /><br />';		
    		infoHtmls += incDescLong;
            infoHtmls += '<br />';
            
            if (URL != "null") {
                //there is a url to display
                urlAlias = '<a href="' + URL + '" target="_blank" style="color: #000066;">' + urlAlias + '</a>';
                urlDisplayAs = urlDisplayAs.replace("[link]", urlAlias);
                infoHtmls += '<font style="color:' + textColor + '; font-weight: bold;">' + urlDisplayAs + '</font><br />';
            }
            
            //4-18-07 - removed start and end date from description
            //infoHtmls += startDate;
            //infoHtmls += endDate;
            infoHtmls += '</div>';
            
            //now store html and index of last marker created in case we have to append the desc 
	    	//in the next iteration
            htmlDescs[length] = infoHtmls;
            //GLog.write("creating new marker at " + length);
            
            //end 3-29-07
            		
    		tmpMarker.tooltip = '<div class="markerTooltip" style="color:'+textColor+'; font-weight:bold;">'
    		tmpMarker.tooltip = tmpMarker.tooltip + incType +'<br>'+facility+'</div>';
	        
	        //3-29-07 - pass array index of descriptions to create marker, also, pass empty in case we use this
    		//function somewhere else, so as not to break existing
    		//createMarker(point, tmpMarker, infoHtmls);
    		createMarker(point, tmpMarker, '', length);
    		//end 3-29-07
    		
	    	
    		eventMarkers[length] = tmpMarker;
    		eventMarkers[length].setId(incID); // over-ride internal id
			googleMap.addOverlay(eventMarkers[length]);
	    	
			if (displayMarker) {
				//only display the marker if the particular layer checkbox is checked
				eventMarkers[length].display(true);
			}
			else {
				eventMarkers[length].display(false);
			}
			tmpMarker = null;
			
			//3-29-07 store current lat/lon in previous to compare next iteration
			//also store ID in idArray to compare later
			idArray[idArray.length] = incID;	
			previousLat = lat;
			previousLon = lon; 
			latDiff = 0;
			lonDiff = 0;
			appendDesc = false;
			lastIndex = length;
			addCount++; //keep track of how many new markers added
    		//end 3-29-07
    	
	    }//end if addFlag
	    //added 3-27-07 for appending descriptions - here we did not add a marker, rather appended the desc to the existing
   		else if((appendDesc) && (!addFlag)) {
   		    if ((pointType == "buses")) {
	            textColor = "#000000";
	        }
	        else if ((pointType == "1") || (pointType == "2")) {
	            textColor = "#990000";
	        }
	        else if ((pointType == "3") || (pointType == "4") || (pointType == "5") || (pointType == "6")) {
	            textColor = "#009900";
	        }
	        else if ((pointType == "7") || (pointType == "14") || (pointType == "16") || (pointType == "17")) {
	            textColor = "#000099";
	        }
	    
	        //1-24-08 - add ability to search for either http:// or www. in the description. If exists, consider it a URL	
	        if (incDescLong.indexOf('http://') != -1) {
	            urlStart = incDescLong.indexOf('http://'); 
	            urlInString = true;
	        }
	        else if (incDescLong.indexOf('www') != -1) {
	            urlStart = incDescLong.indexOf('www');  
	            urlString = "http://";
	            urlInString = true;
	        }
	        
	        //loop over URL string and make an hyperlink
	        if (urlInString) {
				for (x = urlStart; x < incDescLong.length; x++){
					if (incDescLong.charAt(x) == ' ') {
						//if we've reached the end of the url string, mark the character and exit
						urlEnd = x+1;
						break;
					}
					urlString += incDescLong.charAt(x);        
				}
		    	
	    		leftPart = Left(incDescLong, 0, urlStart);
	    		rightPart = Right(incDescLong, incDescLong.length - urlEnd + 1);
		    	
	    		incDescLong = leftPart + '<a href="' + urlString + '" target="_blank" style="color: #000066;">';
		    	incDescLong += ' More Info' + '</a>' + rightPart;
	    	}
	    	
   		    // BUILD HTML MARKUP for info window
   		    incDescLong = '<b><font style="color: ' + textColor + ';">' + incDescLong + '</font></b>';
    		startDate = '<b><font style="color: #000066;">Start Date: ' + startDate + '</font></b><br />';
    		endDate = '<b><font style="color: #000066;">End Date: ' + endDate + '</font></b>';
    		
    		var newTooltip = '<div class="markerTooltip" style="color:'+textColor+'; font-weight:bold;">'
    		newTooltip += newTooltip + incType +'<br>'+facility+'</div>';
    		
    		//include existing
            var infoHtmls = htmlDescs[lastIndex];
            //append new desc
            infoHtmls += '<hr>';
            infoHtmls += '<div align="left" class="markerinfo" style="font-size: 10px; width: 375px;">';
    		infoHtmls += '<b><font style="color: #000066;">Reported By: ' + reportOrgName + '</font></b>';	
    		infoHtmls += '<br /><br />';		
    		infoHtmls += incDescLong;
            infoHtmls += '<br /><br />';
            //4-18-07 - removed start and end date from description
            //infoHtmls += startDate;
            //infoHtmls += endDate;
            
            if (URL != "null") {
                //there is a url to display
                urlAlias = '<a href="' + URL + '" target="_blank" style="color: #000066;">' + urlAlias + '</a>';
                urlDisplayAs = urlDisplayAs.replace("[link]", urlAlias);
                infoHtmls += '<font style="color:' + textColor + '; font-weight: bold;">' + urlDisplayAs + '</font><br />';
            }
            
            infoHtmls += '</div>';
            
            htmlDescs[lastIndex] = infoHtmls;
            
            //store ID regardless of whether marker was created or not
            idArray[idArray.length] = incID;
            
            //GLog.write("appending to " + lastIndex);
            
            //set tooltip
            var tmpId = eventMarkers[lastIndex].getId();
            var markerToAppend = googleMap.getMarkerById(tmpId);
            var tmpTooltip = markerToAppend.tooltip;
            
            //append new tooltip to existing tooltip
            markerToAppend.tooltip = tmpTooltip + newTooltip
   		}
   		//end 3-27-07 
   		addFlag = true;
	}//end for loop looping through XML elements      
        
	    
	//function to display markers true, make sure something is in the array first
	if (checkExisting) {
	    //3-29-07 Need to modify here - don't want to loop over whole array, 
	    //because whole array contains all marker IDs. Need to only loop over
	    //actual markers that were created, because some may co-exist, just appended desc.
		for (var n = 0; n < existingArray.length; n++) {
		    var markerToDisplay = googleMap.getMarkerById(existingArray[n]);
		//for (var n = 0; n < eventMarkers.length; n++) { 
		    //var markerToDisplay = googleMap.getMarkerById(eventMarkers[n].getId());
		    //added 3-29-07 only going to check markers that exist although we need to pass over
		    //every ID that was created.
		    if (markerToDisplay != null){
		        markerToDisplay.display(true);
		    }
		}
	}
	
	//now that we've gotten data, we need to set a flag to let us know to 
	//check existing next time the user updates the map
	checkExisting = true;

	//append scrolling function to markers
	appendScrollbars(addCount);
	
	//hide please wait screen
	//functions are in javascript/showHidePleaseWaitScreen.js
	hidePleaseWaitScreen();
	
	//reset existing marker array
	existingArray = [];
	
	//3-29-07
	lastIndex = null;
	appendDesc = false;
	previousLat = 0;
	previousLon = 0;
	//end 3-29-07
    
}

//3-29-07  - added to append div style to complete HTML text string that may have been appended to
//for scrolling purposes
function appendScrollbars(addCount) {
    var tmpLength = parseInt(htmlDescs.length);
    var tmpAddCount = parseInt(addCount);
    
    var divString = '<div align="left" style="width:400px; height: 120px; overflow: auto; max-height: 200px;">';
    for (var j = tmpLength-tmpAddCount; j < tmpLength; j++) {
		htmlDescs[j] = divString + htmlDescs[j] +  '</div>';
    } 
}
//end 3-29-07

function initializeEventMarkers(markerValue) {
    //first thing we do is set all markers to display false
    //we pass the marker type so we can use this to display any type of marker
    //false like cctvs, construction, spec events, incidents, etc...
    if (markerValue.length > 0) {
        for (var i = markerValue.length-1; i >=0; i--) { 
		    //we can now set display false because of nice PdMarker extension
		    //sooo much faster!
		        markerValue[i].display(false); 
	    }
    }
    
}

function toggleMarkerCheckBox(checkBox, markerValue, isChecked) {
    //user clicked on words next to checkbox instead of clicking on 
    //checkbox itself. Toggle checkbox on or off and call function to 
    //display or hide events
    
    var checkBoxToToggle = new getObj(checkBox);
    
    if (isChecked) {
        document.main.elements[checkBox].checked = false;
        isChecked = false;
    }
    else {
       document.main.elements[checkBox].checked = true;
       isChecked = true;
    }
    toggleMarkers(markerValue, isChecked)
}

function toggleMarkers(markerValue, isChecked) {
    showPleaseWaitScreen("Updating map. Please wait.");
    
	//either set display true or false depending on state of checkbox
	//if checkbox is checked, turn on, if unchecked, turn off.
	var skipMarkerToggle = false;
	var arrayToToggle = new Array();
	//is there another way to do this,rather than hardcode?
	if (markerValue == "incMarkers") {
	    arrayToToggle = incMarkers;
	}
	else if (markerValue == "constMarkers") {
	    arrayToToggle = constMarkers;
	}
	else if (markerValue == "specevtMarkers") {
	    arrayToToggle = specevtMarkers;
	}
	else if (markerValue == "busMarkers") {
	    arrayToToggle = busMarkers;
	}
	else if (markerValue == "speedMarkers") {
	    skipMarkerToggle = true;
	    var myCanvas = document.getElementById("myCanvas");
	}
	else if (markerValue == "cctvMarkers") {
	    arrayToToggle = cctvMarkers;
	}
	else if (markerValue == "crossingMarkers"){
	    arrayToToggle = crossingMarkers;
	}
	
	if (isChecked) {
		if (skipMarkerToggle) {
		    //this code gets executed if link layer is checked
		    //turn links on
		    //show please wait screen while updating map
		    //function is in javascript/showHidePleaseWaitScreen.js
		    //get current zoom and reset if zoomed out to far
		    var currentZoom = googleMap.getZoom();
		    
		    if (currentZoom < 11) {
		        googleMap.setZoom(11);
		        //drawing links will be handled by map moveend procedure
		        //in traffic main
		    }
		    else {
				//wait for 1/10 of second before calling draw links so 
				//we can properly display please wait box.
				setTimeout("drawLinksAfterWait()",100);
			}
		}
        else {
		    if (markerValue == "cctvMarkers") {
		         //if (!cctvsExist) {
		            //grab data and display
		            createXML('cctvs', 'cctvs', '');
		            var dontToggle = true;
		        //}
		    }
		    else if (markerValue == "crossingMarkers") {
		         //if (!crossingsExist) {
		            //grab data and display
		            createXML('crossings', 'crossings', '');
		            var dontToggle = true;
		        //}
		    }
		    if (!dontToggle) {
		        //not links, toggle markers on - gets executed if link checkbox is not checked
		        //get events
			    //for (var n = 0; n < arrayToToggle.length; n++) {
                    //arrayToToggle[n].display(true);
                //}
                //build event type string - only get if we have layers checked
                var typeString = buildEventTypeString();
			    if (typeString != "") {
			    //checkboxes are checked - now go get events, otherwise, don't get any thing
			        createXML('events', 'marker', typeString);
			    }
		        else {
		            hidePleaseWaitScreen();
			    }
			    typeString = "";
            }
        }
    } //end if (isChecked)
    else {
	    if (skipMarkerToggle) {
		    //turn links off
		    if (browser == "Netscape") {
		        //netscape does not use the custom overlay - remove polylines
		        if (ffPolylineArray.length > 0){
				    for (j=ffPolylineArray.length-1; j>=0; j--) {
					    googleMap.removeOverlay(ffPolylineArray[j]);
				    }
				}
			}
			else {
			    //hide custom overlay
			    myCanvas.style.display = "none";
			}
			hidePleaseWaitScreen();
        }
        else {
	        //turn markers off
	        //function above
	        hidePleaseWaitScreen();
	        initializeEventMarkers(arrayToToggle);
	    }
	}//end else if !isChecked
}

//3-29-07 modified to allow passing of array index in to access the existing description if it needs
//to be appended to in the case of overlapping incidents
//function createMarker(point, marker, html) {
function createMarker(point, marker, html, length) {
  	GEvent.addListener(marker, "click", function() {
  	  if (CCTVPopupDisplayed) {
          closeCCTVPopupWindow();
      }
      if (crossingPopupDisplayed) {
          closeCrossingPopupWindow();
      }
      //3-29-07 - only use if html is empty and length is passed in - modified for appending desc
      if ((length != '') && (html == '') || (parseInt(length) == 0)){
          marker.openInfoWindowHtml(htmlDescs[length]);
      }
      else {
          //this is existing - put back if code breaks
           marker.openInfoWindowHtml(html);
      }
      //end 3-29-07
  	});

    GEvent.addListener(marker,"mouseover", function() {
    	showTooltip(marker);
    });        
    GEvent.addListener(marker,"mouseout", function() {
		markerTooltip.style.visibility="hidden"
    });        
}
//end 3-29-07

function drawLinksAfterWait() {
    //netscape does not use the custom overlay - remove polylines
	if (browser == "Netscape") {
	    if (ffPolylineArray.length > 0) {
		    for (j=ffPolylineArray.length-1; j>=0; j--) {
			   googleMap.removeOverlay(ffPolylineArray[j]);
		    }
		}
	}
	else {
		myCanvas.style.display = "block";
	}
	//now draw the links on the map
	createCustomOverlayAndDrawLinks();
}

function showTooltip(marker) {
  markerTooltip.innerHTML = marker.tooltip;
  var point=googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(googleMap.fromDivPixelToLatLng(new GPoint(0,0),true),googleMap.getZoom());	
  var offset=googleMap.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),googleMap.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=markerTooltip.clientHeight;
  var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(markerTooltip);
	markerTooltip.style.visibility="visible";
	markerTooltip.style.width="150px";
	markerTooltip.style.border="1px solid #000033";
}

function buildEventTypeString() {
    //we need to build a string to pass to SQL to grab only the event data for 
    //the layers that are selected. If each box is checked, the appropriate event type is 
    //added to the string and then exectued in the stored procedure. Return the built string
    var typeString = "";
    if (document.main.incCheck.checked) {
		typeString = "incTypes=\'incident\'";
	}
	if (document.main.constCheck.checked) {
		if (typeString.length == 0){
			typeString = "incTypes=\'active construction\'";
		}
		else {
			typeString += ", \'active construction\'";
		}
	}
	if (document.main.specevtCheck.checked) {
		if (typeString.length == 0){
			typeString = "incTypes=\'active special event\'";
		}
		else {
			typeString += ", \'active special event\'";
		}
	}
	if (document.main.busCheck.checked) {
		if (typeString.length == 0){
			typeString = "busChecked=true";
		}
		else {
			typeString += "&busChecked=true";
		}
	}

    return typeString;
}


//1-25-08 - string manipulation for URL display
function Left(str, startIndex, n){
    //grab left portion of string from starting index to ending index
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(startIndex,n);
}

function Right(str, n){
    //grab right portion of string from end of string to index n
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

