﻿    var xmlhttp;
    var iUrl;
    var jUrl;
//    var token;
    
    var penWidth;
    var map;
 
    var startAddr, endAddr;
    var manuPoints = new Array();
    var drivePoints = new Array();
    var corner1;
    var corner2;
//    var travelTime;
//    var distance;
    var readystate;
    var txtPrint;
    var rtrnPromoteRoute="";

//    var oldPolyline = null;
//    var oldMarkerA = null;
//    var oldMarkerB = null;

    function initXMLDoc()
    {
        xmlhttp = null;
        if( window.XMLHttpRequest )                        // code for IE7, Firefox, Mozilla, etc.
        {   
            xmlhttp=new XMLHttpRequest();
        }
        else if( window.ActiveXObject )                    // code for IE5, IE6
        {
            xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP" );
        }
        
        if( xmlhttp == null )
        {
            alert( "Your browser does not support XMLHTTP." );
            return false;
        }

        return true;
    }


    function loadXMLDoc(url) {

//        alert(url);
        
        // define the callback function  - not working in firefox, so we will not use callback functions
//        xmlhttp.onreadystatechange = function() {
//            //            alert(xmlhttp.readyState);
//            //                alert(xmlhttp.statusText);
//            if (xmlhttp.readyState == 4) {
//                alert(xmlhttp.readyState);
//                // so far so good
//                // alert(xmlhttp.responseXML.getElementsByTagName("ErrMsg").length);
//                //                if ((xmlhttp.status == 200) && (xmlhttp.responseXML != null)) {
//                if (xmlhttp.status == 200) {
//                    // success!
//                    alert('xmlhttp status is ' + xmlhttp.status);
//                    alert('got the xml');
//                    //return true;
//                    readystate = true;
//                    // callback function defined here to deal with the returned content, if desirable
//                    
//                } else if (xmlhttp.responseXML.getElementsByTagName("ErrMsg").length > 0) {
//                    var msg = err.firstChild.data;
//                    alert("'Traffic server fails in Action -- " + err.getAttribute("Action") + " !\n" + msg);
//                    // hide the progress wheel
//                    hideProgressWheel();
//                    // return false;
//                    readystate = false;
//                }
//            } else if (this.readyState == 4 && this.status != 200) {
//                // fetched the wrong page or network error...
//                // return false;
//                var msg = err.firstChild.data;
//                alert("'Traffic server fails in Action -- " + err.getAttribute("Action") + " !\n" + msg);
//                // hide the progress wheel
//                hideProgressWheel();
//                // return false;
//                readystate = false;

//            }

//        };

        xmlhttp.open("GET", url, false);
//        xmlhttp.setRequestHeader("Content-type", "text/xml"); 
        xmlhttp.send(null);

        // below for the case of no callback function defined
        var err = xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0];
       
        if( err != null )
        {
            var msg = err.firstChild.data;
            alert("'Traffic server fails in Action -- " + err.getAttribute("Action") + " !\n" + msg);
            // hide the progress wheel
            document.getElementById("ProgressWheel").style.display = 'none';
            return false;
        }
        return true;

    }
 
    function getTravelTimeXML( _latlngArry ) {

        // this function is described as 'soft-code' - first use findroute method to define routeID and driving path. The data are used to manually create json file during development stage
        // - the use getroute method to retrieve traveltime and distance
        // do 3 things: get traveltime & distance & regionbound, get manuPoints, get drivePoints
        // manuPoints are main points of driving directions which will not be used by the application, 
        // but drivePoints are detailed points along the driving path, which will be used to draw driving path
        if (!initXMLDoc()) return false;
        
        
        // to do: write wrap function getDevZonToken()
        iUrl = "InrixProxy1.ashx?Action=";
        
        // case of no callback function
        if( ! loadXMLDoc( iUrl + "GetSecurityToken" )) return false;

        // case with callback function
//        loadXMLDoc(iUrl + "GetSecurityToken");
//        if ( ! readystate) return false;
        
        // alert(xmlhttp.responseXML.xml);
        x = xmlhttp.responseXML.documentElement.getElementsByTagName("AuthToken")
        // token = x[0].text;
        token = x[0].firstChild.data;
//        alert(token);

        // to do: write wrap function callFindRoute()
        var jUrl = iUrl + "FindRoute&token=" + token;
        // using token retunred from ws.inrix.com will not work on devzone.inrix.com
        //        var jUrl = iUrl + "FindRoute&token=" + document.token;

       // pass in each waypoint as separate query string - not to be used for now
//        for( i = 0; i < _latlngArry.length; i++ )
//        {
//        
//        // alert(_latlngArry[i]);
//            jUrl += "&point" + i + "=" + _latlngArry[i];
//        }

        // pass in all waypoints as one query string
        jUrl += "&points=";
        txtPrint = "";
        for (i = 0; i < _latlngArry.length; i++) {
            // alert(_latlngArry[i]);
            jUrl += _latlngArry[i] + "|";
            // for development use only
            txtPrint += _latlngArry[i] + "|";
        }
        jUrl = jUrl.substring(0, jUrl.length - 2);
        // for development use only
        
        if (window.revDir) {
            txtPrint = "wayPoint: '', wayPointR: '" + txtPrint.substring(0, txtPrint.length - 2) + "', ";
        } else {
            txtPrint = "wayPoint: '" + txtPrint.substring(0, txtPrint.length - 2) + "', wayPointR: '', ";
        };

//        alert(jUrl);
//        alert(txtPrint);
        // case of no callback function defined for httprequest call
        if (!loadXMLDoc(jUrl)) return false;
        
        // for use with callback function defined for httprequest call
//        loadXMLDoc(jUrl);
//        if (! readystate) return false;
        
//        alert(jUrl);
        //        loadXMLDoc(jUrl);


        
        // examine the xml content returned by httprequest call
        //        alert(EIS.BrowserDetect.browser);
        // ********* special debugging tool - show xml content at the footer
        // should be commented out for production

        // should comment out this in production
//        if (EIS.BrowserDetect.browser == 'Explorer') {
//            // work in MSIE only, will break Firefox operation
//            document.getElementById("footer").innerText= xmlhttp.responseXML.xml;
//        } else if (EIS.BrowserDetect.browser == 'Firefox') {
//             // work in Firefox only
//            document.getElementById("footer").textContent = xmlhttp.responseText;
//        };
//        // ********* end of special debugging tool 

        

        // check error for xml returned
//        alert(xmlhttp.responseXML.getElementsByTagName("ErrMsg").length);
        if (xmlhttp.responseXML.getElementsByTagName("ErrMsg").length > 0) {

            alert('Traffic server fails in procedure of ' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].getAttribute("Action") +
            '\n' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].firstChild.nodeValue + 
            '\n Please come back to try your inquiry later !!');
            // hide the progress wheel
            document.getElementById("ProgressWheel").style.display = 'none';

            // abort the function            
            return false;   
        };

        //        alert('got xml returned!');

        // start retrieving data from xml returned by httprequest call
        // all data are placed into json type string
        // get routeID
        var route = xmlhttp.responseXML.documentElement.getElementsByTagName("Route")[0];
//        document.totalTravelTime = route.getAttribute("travelTimeMinutes");
//        document.uncongstTravelTime = route.getAttribute("uncongestedTravelTimeMinutes");
//        document.distance = route.getAttribute("totalDistance");
        window.findRoute_ID = route.getAttribute("id");
        //        alert(window.findRoute_ID);
        if (window.revDir) {
            txtPrint = window.odpairID.substring(0, 4) + ": [{routeID: '', routeIDR: '" + window.findRoute_ID + "', " + txtPrint;
        } else {
            txtPrint = window.odpairID.substring(0, 4) + ": [{routeID: '" + window.findRoute_ID + "', routeIDR: '', " + txtPrint;
        };


        
        var sumry = xmlhttp.responseXML.documentElement.getElementsByTagName("Text")[0];
        document.routeSumry = sumry.firstChild.data;
        
        // get boundingbox of the travel
        var bdbox = xmlhttp.responseXML.documentElement.getElementsByTagName("BoundingBox");

        corner1 = (bdbox[0].getAttribute("Corner1")).split(",");
        corner2 = (bdbox[0].getAttribute("Corner2")).split(",");
        
        
        var maneuver = xmlhttp.responseXML.documentElement.getElementsByTagName("Maneuver");

        // get lat/long of each maneuver point, this is an alternative to plot driving path
        // but not very conforming to curved roads
        manuPoints.length = 0;

        for( i = 0; i < maneuver.length; i ++ )
        {
            manuPoints[i] = new GLatLng(parseFloat(maneuver[i].getAttribute("latitude")), parseFloat(maneuver[i].getAttribute("longitude")));
        }

//        alert("maneuver count is " + maneuver.length);

        //route = xmlhttp.responseXML.documentElement.getElementsByTagName( "Route" );        
        //RouteId = route[0].getAttribute("id");
        //loadXMLDoc( iUrl + "GetRoute&token=" + token + "&RouteId=" + RouteId );
        
        xPoints = xmlhttp.responseXML.documentElement.getElementsByTagName( "Point" );
        drivePoints.length = 0;

        // put all points into collection drivePoints[] for plotting the driving path
//        for( i = 0; i < xPoints.length; i ++ )
//        {
        //            drivePoints[i] = new GLatLng( parseFloat( xPoints[i].getAttribute("latitude") ), parseFloat( xPoints[i].getAttribute("longitude") ) );      
//        }

        // put partial points to max 150 points into collection for plotting
        // future work: make max points to plot a configurable parameter
        var maxPtNum = EIS.Map.Config.DrivingPath.totalPoints;
        // alert(maxPtNum);
        if (maxPtNum > xPoints.length) {
            maxPtNum = xPoints.length;
        };
        var iFctr = xPoints.length / maxPtNum;
        var k;
        var len = xPoints.length;
        for( i = 0; i < len; i ++ ) {
            k = parseInt(iFctr * i);
            if (k < len) {
                drivePoints[i] = new GLatLng(parseFloat(xPoints[k].getAttribute("latitude")), parseFloat(xPoints[k].getAttribute("longitude")));
            } else {
            // get the last point
            drivePoints[i] = new GLatLng(parseFloat(xPoints[len - 1].getAttribute("latitude")), parseFloat(xPoints[len - 1].getAttribute("longitude")));
//            alert("plotted point count is " + i + ",  out of full point count of  " + len);
            break;
            }

        }

        // for development use only ********
        // will write the whole json traveltime string into footer area
        //it will be manually copied into json file of eis.tranveltime.config file
        // need to comment out after done

        var sdrivePoint="";
        for (i = 0; i < drivePoints.length; i++) {
            sdrivePoint += fixDecimalLength(drivePoints[i].lat(),6) + "," + fixDecimalLength(drivePoints[i].lng(),6) + "|";
        }

        sdrivePoint = sdrivePoint.substring(0, sdrivePoint.length - 2);
        if (window.revDir) {
            txtPrint = txtPrint + " routeSummary: '', routeSummaryR: '" + sumry.firstChild.data + "', ";
        } else {
            txtPrint = txtPrint + " routeSummary: '" + sumry.firstChild.data + "', routeSummaryR: '', ";
        };

        txtPrint = txtPrint + " drivePath: '" + sdrivePoint + "'}],";
        
        if (EIS.BrowserDetect.browser == 'Explorer') {
            // work in MSIE only, will break Firefox operation
            document.getElementById("footer").innerText = txtPrint;
            } else if (EIS.BrowserDetect.browser == 'Firefox') {
                 // work in Firefox only
            document.getElementById("footer").textContent = txtPrint;
        };

        //******* special section for routeID promotion, after FindRoute run and before GetRoute run
        // routeID need promotion for persistence on INRIX server
        execPromoteRoute(window.findRoute_ID);
        //******* end special section for routeID promotion

        // end of development use region *********

        // to do: write wrap function callGetRoute()
        jUrl = iUrl + "GetRoute&token=" + token;
        jUrl += "&RouteId=" + window.findRoute_ID;
        if (!loadXMLDoc(jUrl)) return false;
        // check error for xml returned
        //        alert(xmlhttp.responseXML.getElementsByTagName("ErrMsg").length);
        if (xmlhttp.responseXML.getElementsByTagName("ErrMsg").length > 0) {

            alert('Traffic server fails in procedure of ' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].getAttribute("Action") +
            '\n' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].firstChild.nodeValue +
            '\n Please come back to try your inquiry later !!');
            // hide the progress wheel
            document.getElementById("ProgressWheel").style.display = 'none';

            // abort the function            
            return false;
        };

        //        alert('got xml returned!');

        // get traveltime, distance etc. and store them in global variable
        totalTravelTime.length = 0;
        uncongstTravelTime.length = 0;
        distance.length = 0;
        avgSpd.length = 0;
        routeSumry.length = 0;
        var route = xmlhttp.responseXML.documentElement.getElementsByTagName("Route")[0];
//        document.totalTravelTime = route.getAttribute("travelTimeMinutes");
//        document.uncongstTravelTime = route.getAttribute("uncongestedTravelTimeMinutes");
//        document.distance = route.getAttribute("totalDistance");

        totalTravelTime.push(route.getAttribute("travelTimeMinutes"));
        uncongstTravelTime.push(route.getAttribute("uncongestedTravelTimeMinutes"));
        distance.push(route.getAttribute("totalDistance"));
        avgSpd.push(route.getAttribute("averageSpeed"));

        var sumry = xmlhttp.responseXML.documentElement.getElementsByTagName("Text")[0];
        if (sumry) {
            routeSumry.push(sumry.firstChild.data);
        } else {
            routeSumry.push("");
        };


//        alert("GetRoute");

        return true;

    }

    function drawDrivePath(_map, _objOverlay) 
    {
 
            // drivePath data are sourced from document global variable
            // to do: put wrapper function plotDrivingPath(_map)
//            var map = _map.getValue();
           // do we still need drivePoints to decide boundbox ?????
//            var mpx = (drivePoints[0].x + drivePoints[drivePoints.length - 1].x) / 2
//            var mpy = (drivePoints[0].y + drivePoints[drivePoints.length - 1].y) / 2
                    
            var x1 = parseFloat( corner1[0] ), y1 = parseFloat( corner1[1] );
            var x2 = parseFloat( corner2[0] ), y2 = parseFloat( corner2[1] );
            var mpx = ( x1 + x2 ) / 2, mpy = ( y1 + y2 ) / 2;
            var swCornr = new GLatLng( x1, y1 ), neCornr = new GLatLng( x2, y2 );
            var bdbox = new GLatLngBounds(swCornr, neCornr);
            var zoom = _map.getBoundsZoomLevel( bdbox );
            var color = EIS.Map.Config.DrivingPath.colorCode;
            var opa = EIS.Map.Config.DrivingPath.opacity;
            var weight = EIS.Map.Config.DrivingPath.weight;
//            alert(color);
//            alert(weight);

            var mpCtr = new GLatLng(mpx, mpy);

//            removeTravelTimeOverlay(_map, arryTravelTimeOverlay);

            _map.setCenter(mpCtr, zoom);
            
            // plot driving path from points
            var polyline = new GPolyline(drivePoints, color, weight, opa);

            // plot driving path from maneuvers
            // manuPoints will not give an accurate plot of driving path
//            var polyline = new GPolyline(manuPoints, color, weight, opa);
             	    

//    	    oldPolyline = polyline;
            //    	    arryTravelTimeOverlay.push(polyline);
            var arryOvery = _objOverlay.getValue()
            arryOvery.push(polyline);
            _objOverlay.setValue(arryOvery);
            
    	    _map.addOverlay(polyline);
   	    
    	    
    	    // #CC700, "#0011EE", "#44HHFF", or "#117788", #ff0000
    	    // Put infowindow and Marker on start and end point
    	    // to do: write wrapper function drawMarkerWithTabWindow(_imgURL,_travelInfo)
//    	    var start = drivePoints[0], end = drivePoints[drivePoints.length - 1];
        
//        var baseIcon = new GIcon(G_DEFAULT_ICON);
//        baseIcon.shadow = "Image/shadow50.png";
//        baseIcon.iconSize = new GSize(24, 38);
//        baseIcon.shadowSize = new GSize(37, 34);
//        baseIcon.iconAnchor = new GPoint(9, 34);
//        baseIcon.infoWindowAnchor = new GPoint(9, 2);
//        var letteredIconA = new GIcon(baseIcon);
//        letteredIconA.image = "Image/icon_greenA.png";

//        var letteredIconA = new GIcon(G_DEFAULT_ICON);
//        letteredIconA.image = "Image/icon_rt_start.png";
//        markerAOptions = { icon:letteredIconA };
//        var markerA = new GMarker( start, markerAOptions );
//        GEvent.addListener( markerA, "click", function() {markerA.openInfoWindowHtml("Start");});
//        
//        //        oldMarkerA = markerA;
//        arryTravelTimeOverlay.push(markerA);
//        _map.addOverlay(markerA);
        
      
//        var letteredIconB = new GIcon( baseIcon );
    	    //        letteredIconB.image = "Image/icon_greenB.png";

//        var letteredIconB = new GIcon(G_DEFAULT_ICON);
//        letteredIconB.image = "Image/icon_rt_end.png";
//        markerBOptions = { icon: letteredIconB };
//        
//        var markerB = new GMarker( end, markerBOptions );
//        //  var travelInfo = "<div style=\"background-color:#0000ff\";>Travel Time in Minute: " + travelTime +
//        //      "<p>Total Distance in Miles: " + distance + "</div>";
//        //  var travelInfo = "<table bgcolor=\"#0011EE\"><tr><td>Travel Time in Minute: " + travelTime +
//        //      "<p>Total Distance in Miles: " + distance + "</td></tr></table>";
//        var d = new Date();
//        var travelInfo = "<div> Travel Time: " + document.travelTime + " min" +
//                            "<br/>Total Distance: " + document.distance + " mi" +
//                            "<br/>Time Stamp: " + d.toLocaleTimeString() + "</div>";


//        GEvent.addListener( markerB, "click", function() { markerB.openInfoWindowHtml( travelInfo ); } );
//          // oldMarkerB = markerB ;
//        arryTravelTimeOverlay.push(markerB);
//        _map.addOverlay(markerB);
//        markerB.openInfoWindowHtml(travelInfo);
        
        return true;
    }

    
    function getTravelTimeXML_HC() {
        // function is described as hard-code because it uses pre-generated routeID, drivepoints etc. stored in EIS.TravelTime.Config file
        // only getroute method is used to get traveltime from INRIX
        // do these things: get waypoints from config file, get traveltime & distance & regionbound from retunred xml
        
        if (!initXMLDoc()) return false;

        // to do: write wrap function getDevZonToken()
        tUrl = "InrixProxy1.ashx?Action=";

        // case of no callback function
        if (!loadXMLDoc(tUrl + "GetSecurityToken")) return false;

        // case with callback function
        //        loadXMLDoc(iUrl + "GetSecurityToken");
        //        if ( ! readystate) return false;

//        alert(xmlhttp.responseXML.xml);
        x = xmlhttp.responseXML.documentElement.getElementsByTagName("AuthToken")
        // token = x[0].text;
        token = x[0].firstChild.data;
        //        alert(token);

        
        // use GetRoute method to retrieve travel time

        // to do: write wrap function callGetRoute()
        tUrl += "GetRoute&token=" + token;
        var _odpairID = window.odpairID;
        //        alert(_odpairID);
        _odpairID = _odpairID.substring(0, 4);

        totalTravelTime.length = 0;
        uncongstTravelTime.length = 0;
        distance.length = 0;
        avgSpd.length = 0;
        routeSumry.length = 0;

        
        // looping through multiple routing loops on each OD pair, for now, we have only 1 routing loop

        if (window.revDir) {
            var rtKey = 'routeIDR';
        } else {
            var rtKey = 'routeID';
        };
//        var jsnTst = eval('EIS.TravelTime.Config');
        
        for (i = 0; i < window.routingLoop; i++) {

            if (operMode == 'traveltimecoding') {      // get routeID from TravelTime.Config file
                var jsnTst = eval('EIS.TravelTime.Config');
                if (jsnTst.ODPair[_odpairID][0][rtKey].length == 0) {
                    alert('this routing has not yet been coded!!');
                    hideProgressWheel();
                    return false;
                } else {
                //                    var tUrl2 = tUrl + "&RouteId=" + jsnTst.ODPair[_odpairID][0][rtKey];
                    var tUrl2 = tUrl + "&RouteId=" + jsnTst.ODPair[_odpairID][0][rtKey];
                };

            } else {   // get routeid from saved data
                if (!(ajxRouteID)) {
                    alert('this routing has not yet been coded!!');
                    hideProgressWheel();
                    return false;
                } else {
                    var tUrl2 = tUrl + "&RouteId=" + window.ajxRouteID;
//                    alert(tUrl2);
                };
            };



            //        alert(tUrl2);
            // retrieve traveltime data from INROX using httprequest call
            if (!loadXMLDoc(tUrl2)) return false;
            // check error for xml returned
            //        alert(xmlhttp.responseXML.getElementsByTagName("ErrMsg").length);

            // check error for xml returned
            //        alert(xmlhttp.responseXML.getElementsByTagName("ErrMsg").length);
            if (xmlhttp.responseXML.getElementsByTagName("ErrMsg").length > 0) {

                alert('Traffic server fails in procedure of ' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].getAttribute("Action") +
            '\n' + xmlhttp.responseXML.getElementsByTagName("ErrMsg")[0].firstChild.nodeValue +
            '\n Please come back to try your inquiry later !!');
                // hide the progress wheel
                hideProgressWheel();

                // abort the function            
                return false;
            };

            //        alert('got xml returned!');

            // get traveltime, distance
            var route = xmlhttp.responseXML.documentElement.getElementsByTagName("Route")[0];
            //        document.totalTravelTime = route.getAttribute("travelTimeMinutes");
            //        document.uncongstTravelTime = route.getAttribute("uncongestedTravelTimeMinutes");
            //        document.distance = route.getAttribute("totalDistance");
            //        document.avgSpd = route.getAttribute("averageSpeed");
            totalTravelTime.push(route.getAttribute("travelTimeMinutes"));
            uncongstTravelTime.push(route.getAttribute("uncongestedTravelTimeMinutes"));
            distance.push(route.getAttribute("totalDistance"));
            avgSpd.push(route.getAttribute("averageSpeed"));

            var sumry = xmlhttp.responseXML.documentElement.getElementsByTagName("Text")[0];
            if (sumry) {
                routeSumry.push(sumry.firstChild.data);
            } else {
                routeSumry.push("");
            };
            //        alert(routeSumry[0]);

            // get boundingbox of the travel, only need from first routing loop
            if (i == 0) {
                
                var bdbox = xmlhttp.responseXML.documentElement.getElementsByTagName("BoundingBox");

                corner1 = (bdbox[0].getAttribute("Corner1")).split(",");
                corner2 = (bdbox[0].getAttribute("Corner2")).split(",");
            };

        };  // end of all routingloops

        return true;

    }         
    
    // function for hard code drivePath plotting
    function drawDrivePath_HC(_map, _objOverlay) {


         var x1 = parseFloat(corner1[0]), y1 = parseFloat(corner1[1]);
         var x2 = parseFloat(corner2[0]), y2 = parseFloat(corner2[1]);
         var mpx = (x1 + x2) / 2, mpy = (y1 + y2) / 2;
         var swCornr = new GLatLng(x1, y1), neCornr = new GLatLng(x2, y2);
         var bdbox = new GLatLngBounds(swCornr, neCornr);
         var zoom = _map.getBoundsZoomLevel(bdbox);
         var color = EIS.Map.Config.DrivingPath.colorCode;
         var opa = EIS.Map.Config.DrivingPath.opacity;
         var weight = EIS.Map.Config.DrivingPath.weight;
         var _odpairID = window.odpairID;
         _odpairID = _odpairID.substring(0, 4);
//         alert(_odpairID);
        // looping through multiple routing loops on each OD pair

         for (i = 0; i < window.routingLoop; i++) {
             if (operMode == 'traveltimecoding') {      // get drivepath from TravelTime.Config file
                 var jsnTst = eval('EIS.TravelTime.Config');
                 var sDrivePath = jsnTst.ODPair[_odpairID][0].drivePath;
             } else {   // get drivepath from saved data
                 var sDrivePath = window.ajxDrivePath;
             };
             

            //         alert(sDrivePath.length);
             if (sDrivePath.length == 0) {
                 alert('the drive path source data have not been coded!!');
                 hideProgressWheel();
                 return false;
             };
             //         alert(sDrivePath);
             var arryDrivePath = sDrivePath.split('|');
             var tempArry;

             drivePoints.length = 0;
             for (idx in arryDrivePath) {

                 tempArry = arryDrivePath[idx].split(',');
                 drivePoints[idx] = new GLatLng(parseFloat(tempArry[0]), parseFloat(tempArry[1]));
                 // debug testing
                 //             if (idx==0) alert(drivePoints[idx].lat());
                 //             if (idx == 0) alert(drivePoints[idx].lng());
             };
             var polyline = new GPolyline(drivePoints, color, weight, opa);

             //         arryTravelTimeOverlay.push(polyline);
             var arryOvery = _objOverlay.getValue()
             arryOvery.push(polyline);
             _objOverlay.setValue(arryOvery);

             // plot driving path from points
             _map.addOverlay(polyline);

             // to do: add midMarker and EWindow for each route if multiple routings
             if (window.routingLoop > 1) {
                // add EWindow for each routing with travel time info
            
             };

             if (i == 0) {
                 var mpCtr = new GLatLng(mpx, mpy);
             };

         };
      
         _map.setCenter(mpCtr, zoom);

         return true;
     }
     
     
     // Arguments: numFloat to round, decLength to keep number of decimal digit
     function fixDecimalLength(numFloat, decLength) {
         var newFloat = Math.round(numFloat * Math.pow(10, decLength)) / Math.pow(10, decLength);
         return newFloat; 
     }


     function execPromoteRoute(_iRouteID) {
         if (!initXMLDoc()) return false;
         var _map = new EIS.Map();
         var txt;
         _map.getToken();
         if (!(_map.checkTokenFetchSuccess())) return false;
         
         var tURL = "InrixProxy1.ashx?Action=PromoteRoute" + "&routeID=" + _iRouteID;
         tURL += '&token=' + token;
         if (loadXMLDoc(tURL)) {
//         alert(xmlhttp.responseXML.xml);
             var irxTag = xmlhttp.responseXML.documentElement;
             var status = irxTag.getAttribute("statusId");
             var rtID = irxTag.getElementsByTagName("InputParameter")[3].getAttribute("value");
             txt = rtID + ' promotion status = ' + status + '||';
             rtrnPromoteRoute += txt;
             // observe to be sure the RouteID has been promoted, can be commented out once the code is veriried
//             alert(txt);
        } else { // RouteID not found case, need hard code to show error
            txt = _iRouteID + ' promotion status = Gone' + '||';
            rtrnPromoteRoute += txt;

        }

    }




