﻿var directions = {
    ShowDirections: false,
    firstLat: null,
    firstLon: null,
    firstDesc: null,
    aSelected: null,
    bSelected: null,
    cSelected: null,
    dSelected: null,
    eSelected: null,
    tempSelected: null,
    tempArrayItem: null,
    tempName: null,
    aArrayItem: null,
    bArrayItem: null,
    cArrayItem: null,
    dArrayItem: null,
    eArrayItem: null,
    dirReady: false,
    stype: null,
    deleting: false,
    clickDirections: false,
    DirArray: new Array(),
    AddDirection: function (lat, lon, desc) {
        try {
            // AddressSearch.jsonAddress = null;
            $("#innerContent").scrollTop(0);
            $("#DidExpander").hide();
            $("#addressResults").hide();
            $("#FastResults").hide();
            $("#DirectionSearch").show();
            $("#DefaultSearchlink").hide();
            $("#PointB").val(desc);
            AddressSearch.RemoveBubble();
            directions.firstDesc = desc;
            directions.firstLat = lat;
            directions.firstLon = lon;
            directions.bSelected = "Selected";
            directions.aSelected = "NotSelected";
            directions.bArrayItem = lat + "|" + lon + "|" + desc;
            $("#_message").html("Get Directions");
        } catch (err) { }
    },
    AddDirectionFrom: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointA").val(desc);
        AddressSearch.RemoveBubble();
        directions.firstDesc = desc;
        directions.firstLat = lat;
        directions.firstLon = lon;
        directions.aSelected = "Selected";
        directions.aArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionTo: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointB").val(desc);
        AddressSearch.RemoveBubble();
        directions.bSelected = "Selected";
        directions.bArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionA: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#Pointa").val(desc);
        AddressSearch.RemoveBubble();
        directions.aSelected = "Selected";
        directions.aArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionB: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointB").val(desc);
        AddressSearch.RemoveBubble();
        directions.bSelected = "Selected";
        directions.bArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionC: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointC").val(desc);
        AddressSearch.RemoveBubble();
        directions.cSelected = "Selected";
        directions.cArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionD: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointD").val(desc);
        AddressSearch.RemoveBubble();
        directions.dSelected = "Selected";
        directions.dArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    AddDirectionE: function (lat, lon, desc) {
        //AddressSearch.jsonAddress = null;
        $("#DidExpander").hide();
        $("#addressResults").hide();
        $("#FastResults").hide();
        $("#DirectionSearch").show();
        $("#DefaultSearchlink").hide();
        $("#PointE").val(desc);
        AddressSearch.RemoveBubble();
        directions.eSelected = "Selected";
        directions.eArrayItem = lat + "|" + lon + "|" + desc;
        $("#_message").html("Get Directions");
    },
    GetDirections: function () {
        directions.ShowDirections = true;
        $('#btnDirections').attr('disabled', 'disabled');
        $("#imgLoadAni").show();
        if ($("#PointA").val() == "") {
            alert("Please complete all fields");
            $("#imgLoadAni").hide();
            $('#btnDirections').removeAttr('disabled');
        }
        else if ($("#PointB").val() == "") {
            alert("Please complete all fields");
            $("#imgLoadAni").hide();
            $('#btnDirections').removeAttr('disabled');
        }
        else if ($("#PointC").val() == "" && directions.cSelected != null) {
            alert("Please complete all fields");
            $("#imgLoadAni").hide();
            $('#btnDirections').removeAttr('disabled');
        }
        else if ($("#PointD").val() == "" && directions.dSelected != null) {
            alert("Please complete all fields");
            $("#imgLoadAni").hide();
            $('#btnDirections').removeAttr('disabled');
        }
        else if ($("#PointE").val() == "" && directions.eSelected != null) {
            alert("Please complete all fields");
            $("#imgLoadAni").hide();
            $('#btnDirections').removeAttr('disabled');
        }
        else {
            g_map.removeGroupOverlay("GreenLine");
            $("ul.paging4").html("");
            //   $(".simplePagerNav").html("");
            var nameA = "";
            var nameB = "";
            var nameC = "";
            var nameD = "";
            var nameE = "";
            if (directions.aSelected == "Selected") {
                itema = directions.aArrayItem.split("|");
                nameA = itema[2];
            }
            if (directions.bSelected == "Selected") {
                itemb = directions.bArrayItem.split("|");
                nameB = itemb[2];
            }
            if (directions.cSelected == "Selected") {
                itemc = directions.cArrayItem.split("|");
                nameC = itemc[2]
            }
            if (directions.dSelected == "Selected") {
                itemd = directions.dArrayItem.split("|");
                nameD = itemd[2]
            }
            if (directions.eSelected == "Selected") {
                iteme = directions.eArrayItem.split("|");
                nameE = iteme[2]
            }
            if (directions.aSelected == "NotSelected" || $("#PointA").val() != nameA) {
                var AddressHTML = "";
                $(".simplePagerNav").html("");
                url = "ashx/pgSearchDir.ashx?SearchString=" + $("#PointA").val();
                $.getJSON(url, function (json) {
                    $('#btnDirections').removeAttr('disabled');
                    try {
                        if (json.Records.length == 0) {
                            alert("No results returned for \"" + $("#PointA").val() + "\" please refine your search");
                            $("#imgLoadAni").hide();
                        }
                        else if (json.Records.length == 1) {
                            directions.aArrayItem = json.Records[0].Latitude + "|" + json.Records[0].Longitude + "|" + json.Records[0].AddressDetails;
                            directions.aSelected = "Selected";
                            $("#PointA").val(json.Records[0].AddressDetails);
                            directions.GetDirections();
                        }
                        else {
                            for (var _counter = 0; _counter < json.Records.length; _counter++) {
                                ArrItem = json.Records[_counter].Latitude + "|" + json.Records[_counter].Longitude + "|" + json.Records[_counter].AddressDetails;
                                AddressHTML += "<li  onclick='directions.SelectA(\"" + ArrItem + "\");'>" + json.Records[_counter].AddressDetails + "</li>"
                            }
                            $("ul.paging4").html(AddressHTML);
                            $("ul.paging4").quickPager({ pagerLocation: "before", pageSize: "5", clickFunction: function (id) { } });
                        }
                    }
                    catch (err) {
                        alert("No results returned for " + $("#PointA").val() + " please refine your search");
                    }
                });
            }
            else if (directions.bSelected == "NotSelected" || $("#PointB").val() != nameB) {
                var AddressHTML = "";
                $(".simplePagerNav").html("");
                url = "ashx/pgSearchDir.ashx?SearchString=" + $("#PointB").val();
                $.getJSON(url, function (json) {
                    try {
                        $('#btnDirections').removeAttr('disabled');
                        if (json.Records.length == 0) {
                            alert("No results returned for \"" + $("#PointB").val() + "\" please refine your search");
                            $("#imgLoadAni").hide();
                        }
                        else if (json.Records.length == 1) {
                            directions.bArrayItem = json.Records[0].Latitude + "|" + json.Records[0].Longitude + "|" + json.Records[0].AddressDetails;
                            directions.bSelected = "Selected";
                            $("#PointB").val(json.Records[0].AddressDetails);
                            directions.GetDirections();
                        }
                        else {
                            for (var _counter = 0; _counter < json.Records.length; _counter++) {
                                ArrItem = json.Records[_counter].Latitude + "|" + json.Records[_counter].Longitude + "|" + json.Records[_counter].AddressDetails;
                                AddressHTML += "<li  onclick='directions.SelectB(\"" + ArrItem + "\");'>" + json.Records[_counter].AddressDetails + "</li>"
                            }
                            $("ul.paging4").html(AddressHTML);
                            $("ul.paging4").quickPager({ pagerLocation: "before", pageSize: "5", clickFunction: function (id) { } });
                        }
                    }
                    catch (err) {
                        alert("No results returned for " + $("#PointB").val() + " please refine your search");
                    }
                });
            }
            else if (directions.cSelected == "NotSelected" || $("#PointC").val() != nameC) {
                var AddressHTML = "";
                $(".simplePagerNav").html("");
                url = "ashx/pgSearchDir.ashx?SearchString=" + $("#PointC").val();
                $.getJSON(url, function (json) {
                    try {
                        $('#btnDirections').removeAttr('disabled');
                        if (json.Records.length == 0) {
                            alert("No results returned for \"" + $("#PointC").val() + "\" please refine your search");
                            $("#imgLoadAni").hide();
                        }
                        else if (json.Records.length == 1) {
                            directions.cArrayItem = json.Records[0].Latitude + "|" + json.Records[0].Longitude + "|" + json.Records[0].AddressDetails;
                            directions.cSelected = "Selected";
                            $("#PointC").val(json.Records[0].AddressDetails);
                            directions.GetDirections();
                        }
                        else {
                            for (var _counter = 0; _counter < json.Records.length; _counter++) {
                                ArrItem = json.Records[_counter].Latitude + "|" + json.Records[_counter].Longitude + "|" + json.Records[_counter].AddressDetails;
                                AddressHTML += "<li  onclick='directions.SelectC(\"" + ArrItem + "\");'>" + json.Records[_counter].AddressDetails + "</li>"
                            }
                            $("ul.paging4").html(AddressHTML);
                            $("ul.paging4").quickPager({ pagerLocation: "before", pageSize: "5", clickFunction: function (id) { } });
                        }
                    }
                    catch (err) {
                        alert("No results returned for " + $("#PointC").val() + " please refine your search");
                    }
                });
            }
            else if (directions.dSelected == "NotSelected" || $("#PointD").val() != nameD) {
                var AddressHTML = "";
                $(".simplePagerNav").html("");
                url = "ashx/pgSearchDir.ashx?SearchString=" + $("#PointD").val();
                $.getJSON(url, function (json) {
                    $('#btnDirections').removeAttr('disabled');
                    try {
                        if (json.Records.length == 0) {
                            alert("No results returned for \"" + $("#PointD").val() + "\" please refine your search");
                            $("#imgLoadAni").hide();
                        }
                        else if (json.Records.length == 1) {
                            directions.dArrayItem = json.Records[0].Latitude + "|" + json.Records[0].Longitude + "|" + json.Records[0].AddressDetails;
                            directions.dSelected = "Selected";
                            $("#PointD").val(json.Records[0].AddressDetails);
                            directions.GetDirections();
                        }
                        else {
                            for (var _counter = 0; _counter < json.Records.length; _counter++) {
                                ArrItem = json.Records[_counter].Latitude + "|" + json.Records[_counter].Longitude + "|" + json.Records[_counter].AddressDetails;
                                AddressHTML += "<li  onclick='directions.SelectD(\"" + ArrItem + "\");'>" + json.Records[_counter].AddressDetails + "</li>"
                            }
                            $("ul.paging4").html(AddressHTML);
                            $("ul.paging4").quickPager({ pagerLocation: "before", pageSize: "5", clickFunction: function (id) { } });
                        }
                    }
                    catch (err) {
                        alert("No results returned for " + $("#PointD").val() + " please refine your search");
                    }
                });
            }
            else if (directions.eSelected == "NotSelected" || $("#PointE").val() != nameE) {
                var AddressHTML = "";
                $(".simplePagerNav").html("");
                url = "ashx/pgSearchDir.ashx?SearchString=" + $("#PointE").val();
                $.getJSON(url, function (json) {
                    $('#btnDirections').removeAttr('disabled');
                    try {
                        if (json.Records.length == 0) {
                            alert("No results returned for \"" + $("#PointE").val() + "\" please refine your search");
                            $("#imgLoadAni").hide();
                        }
                        else if (json.Records.length == 1) {
                            directions.eArrayItem = json.Records[0].Latitude + "|" + json.Records[0].Longitude + "|" + json.Records[0].AddressDetails;
                            directions.eSelected = "Selected";
                            $("#PointE").val(json.Records[0].AddressDetails);
                            directions.GetDirections();
                        }
                        else {
                            for (var _counter = 0; _counter < json.Records.length; _counter++) {
                                ArrItem = json.Records[_counter].Latitude + "|" + json.Records[_counter].Longitude + "|" + json.Records[_counter].AddressDetails;
                                AddressHTML += "<li  onclick='directions.SelectE(\"" + ArrItem + "\");'>" + json.Records[_counter].AddressDetails + "</li>"
                            }
                            $("ul.paging4").html(AddressHTML);
                            $("ul.paging4").quickPager({ pagerLocation: "before", pageSize: "5", clickFunction: function (id) { } });
                        }
                    }
                    catch (err) {
                        alert("No results returned for " + $("#PointE").val() + " please refine your search");
                    }
                });
            }
            else {
                directions.dirReady = true;
                $("ul.paging4").html("");

                directions.CompileDirections();
                $("#imgLoadAni").hide();
            }
            $("#imgLoadAni").hide();
        }
    },
    SelectA: function (arrItem) {
        directions.aArrayItem = arrItem;
        directions.aSelected = "Selected";
        _item = arrItem.split("|");
        $("#PointA").val(_item[2]);
        directions.GetDirections();

    },
    SelectB: function (arrItem) {
        directions.bArrayItem = arrItem;
        //   directions.GetDirections();
        _item = arrItem.split("|");
        $("#PointB").val(_item[2]);
        directions.bSelected = "Selected";

    },
    SelectC: function (arrItem) {
        directions.cArrayItem = arrItem;
        //    directions.GetDirections();
        _item = arrItem.split("|");
        $("#PointC").val(_item[2]);
        directions.cSelected = "Selected";
        directions.GetDirections();
    },
    SelectD: function (arrItem) {
        directions.dArrayItem = arrItem;
        //  directions.GetDirections();
        _item = arrItem.split("|");
        $("#PointD").val(_item[2])
        directions.dSelected = "Selected";
        directions.GetDirections();
    },
    SelectE: function (arrItem) {
        directions.eArrayItem = arrItem;

        _item = arrItem.split("|");
        $("#PointE").val(_item[2]);
        directions.eSelected = "Selected";

        directions.GetDirections();
    },
    CompileDirections: function () {
        oDirection = null;
        directions.stype = $("#cboType").val();
        directions.DirArray = new Array();
        directions.DirArray.push(directions.aArrayItem);
        directions.DirArray.push(directions.bArrayItem);
        if (directions.cSelected == "Selected") {
            directions.DirArray.push(directions.cArrayItem);
        }
        if (directions.dSelected == "Selected") {
            directions.DirArray.push(directions.dArrayItem);
        }
        if (directions.eSelected == "Selected") {
            directions.DirArray.push(directions.eArrayItem);
        }
        var dirOptions = null;
        if (document.getElementById("rbTime").checked == true) {
            dirOptions = new AGDirectionsOptions(AGTravelMethods.DRIVE, AGUnits.KILOMETERS, AGRoutePreferences.FASTEST)
            directions.stype = "TRAVELTIME";
        }
        else {
            dirOptions = new AGDirectionsOptions(AGTravelMethods.DRIVE, AGUnits.KILOMETERS, AGRoutePreferences.SHORTEST)
            directions.stype = "LENGTH";
        }

        var arrCoordWayPoints = new Array();
        g_map.removeGroupOverlay("Flags");
        g_map.removeGroupOverlay("AddressFlags");
        for (_i = 0; _i < directions.DirArray.length; _i++) {
            _item = directions.DirArray[_i].split("|");
            arrCoordWayPoints.push(new AGCoord(parseFloat(_item[0]), parseFloat(_item[1])));

            _image = "images/" + _i + "g.png";
            var _iconAnchor = new AGPoint(-15, -39);
            var myHTMLObj = new Image();
            myHTMLObj.setAttribute("id", "Fast" + _i);
            myHTMLObj.style.zIndex = 1;
            myHTMLObj.setAttribute("src", _image);
            myHTMLObj.setAttribute("title", _i);
            var objectSize = new AGSize(30, 39);
            var opts = new AGHTMLOverlayOptions(_iconAnchor, objectSize);

            var newCoord = new AGCoord(parseFloat(_item[0]), parseFloat(_item[1]));
            var htmlOverlay = new AGHTMLOverlay(myHTMLObj, newCoord, opts);
            g_map.addOverlay(htmlOverlay, "Flags");
        }
        oDirection = new AGDirections(g_map);
        oDirection.loadFromWayPoints(arrCoordWayPoints, dirOptions); //arrCoordWayPoints = origin, via point , distination.

        directions.GetDirectionDescription();
        AGEvent.addListener(oDirection, "onload", directionloadhandler);
    },
    GetDirectionDescription: function () {
        $("#drivingDirections").html("");
        var _type = "TRAVELTIME";
        if (document.getElementById("rbTime").checked == true) {

            _type = "TRAVELTIME";
        }
        else {

            _type = "LENGTH";
        }
        DirectionsDesc = "";
        ItemA = directions.aArrayItem.split("|");
        ItemB = directions.bArrayItem.split("|");
        var _url = "GetDrivingDirections.aspx?start=" + ItemA[0] + "|" + ItemA[1] +
                "&end=" + ItemB[0] + "|" + ItemB[1] +
                "&type=" + _type +
                "&random=" + Math.random();
        $.getJSON(_url, function (json) {
            DirectionsDesc += "<center><div class='leftHeader roundedCorners'>Directions From A To B</div></center><br/>";
            DirectionsDesc += "<div style='width:80%;margin-left:5px;'>" + json.Result + "</div>";
            $("#drivingDirections").html(DirectionsDesc);
            $('#btnDirections').removeAttr('disabled');
            if (directions.cSelected == "Selected") {
                ItemC = directions.cArrayItem.split("|");
                var _url = "GetDrivingDirections.aspx?start=" + ItemB[0] + "|" + ItemB[1] +
                "&end=" + ItemC[0] + "|" + ItemC[1] +
                "&type=" + directions.stype +
                "&random=" + Math.random();
                $.getJSON(_url, function (json) {
                    DirectionsDesc += "<center><div class='leftHeader roundedCorners'>Directions From B To C</div></center><br/>";
                    DirectionsDesc += "<div style='width:80%;margin-left:5px;'>" + json.Result + "</div>";
                    $("#drivingDirections").html(DirectionsDesc);
                    if (directions.dSelected == "Selected") {
                        ItemD = directions.dArrayItem.split("|");
                        var _url = "GetDrivingDirections.aspx?start=" + ItemC[0] + "|" + ItemC[1] +
                "&end=" + ItemD[0] + "|" + ItemD[1] +
                "&type=" + directions.stype +
                "&random=" + Math.random();
                        $.getJSON(_url, function (json) {
                            DirectionsDesc += "<center><div class='leftHeader roundedCorners'>Directions From C To D</div></center><br/>";
                            DirectionsDesc += "<div style='width:80%;margin-left:5px;'>" + json.Result + "</div>";
                            $("#drivingDirections").html(DirectionsDesc);
                            if (directions.eSelected == "Selected") {
                                ItemE = directions.eArrayItem.split("|");
                                var _url = "GetDrivingDirections.aspx?start=" + ItemD[0] + "|" + ItemD[1] +
                        "&end=" + ItemE[0] + "|" + ItemE[1] +
                        "&type=" + directions.stype +
                        "&random=" + Math.random();
                                $.getJSON(_url, function (json) {
                                    DirectionsDesc += "<center><div class='leftHeader roundedCorners'>Directions From D To E</div></center><br/>";
                                    DirectionsDesc += "<div style='width:80%;margin-left:5px;'>" + json.Result + "</div>";
                                    $("#drivingDirections").html(DirectionsDesc);

                                });
                            }
                        });
                    }
                });
            }




        });

    },
    AddDest: function () {
        if (directions.cSelected == null) {
            directions.cSelected = "NotSelected";
            $("#tdC").show();
        }
        else if (directions.dSelected == null) {
            directions.dSelected = "NotSelected";
            $("#tdD").show();
        }
        else if (directions.eSelected == null) {
            directions.eSelected = "NotSelected";
            $("#tdE").show();
            $("#tdAdd").hide();
        }
        $("#remA").show();
        $("#remB").show();
    },
    MoveUpB: function () {
        directions.tempArrayItem = directions.aArrayItem;
        directions.tempSelected = directions.aSelected;
        directions.tempName = $("#PointA").val();
        $("#PointA").val($("#PointB").val());
        directions.aSelected = directions.bSelected;
        directions.aArrayItem = directions.bArrayItem;

        directions.bSelected = directions.tempSelected;
        directions.bArrayItem = directions.tempArrayItem;
        $("#PointB").val(directions.tempName);
        if (!directions.deleting)
            if (directions.aSelected == "Selected" && directions.bSelected == "Selected") {
                directions.GetDirections();
            }
    },
    MoveUpC: function () {
        directions.tempArrayItem = directions.bArrayItem;
        directions.tempSelected = directions.bSelected;
        directions.tempName = $("#PointB").val();
        $("#PointB").val($("#PointC").val());
        directions.bSelected = directions.cSelected;
        directions.bArrayItem = directions.cArrayItem;

        directions.cSelected = directions.tempSelected;
        directions.cArrayItem = directions.tempArrayItem;
        $("#PointC").val(directions.tempName);
        if (!directions.deleting)
            directions.GetDirections();
    },
    MoveUpD: function () {
        directions.tempArrayItem = directions.cArrayItem;
        directions.tempSelected = directions.cSelected;
        directions.tempName = $("#PointC").val();
        $("#PointC").val($("#PointD").val());
        directions.cSelected = directions.dSelected;
        directions.cArrayItem = directions.dArrayItem;

        directions.dSelected = directions.tempSelected;
        directions.dArrayItem = directions.tempArrayItem;
        $("#PointD").val(directions.tempName);
        if (!directions.deleting)
            directions.GetDirections();
    },
    MoveUpE: function () {
        directions.tempArrayItem = directions.dArrayItem;
        directions.tempSelected = directions.dSelected;
        directions.tempName = $("#PointD").val();
        $("#PointD").val($("#PointE").val());
        directions.dSelected = directions.eSelected;
        directions.dArrayItem = directions.eArrayItem;

        directions.eSelected = directions.tempSelected;
        directions.eArrayItem = directions.tempArrayItem;
        $("#PointE").val(directions.tempName);
        if (!directions.deleting)
            directions.GetDirections();
    },
    RemoveA: function () {
        directions.deleting = true;
        if (directions.eSelected != null) {
            directions.MoveUpB();
            directions.MoveUpC();
            directions.MoveUpD();
            directions.MoveUpE();
            directions.eArrayItem = null;
            directions.eSelected = null;
            $("#PointE").val("");
            directions.eArrayItem = null;
            $("#tdE").hide();
        }
        else if (directions.dSelected != null) {
            directions.MoveUpB();
            directions.MoveUpC();
            directions.MoveUpD();
            directions.dArrayItem = null;
            directions.dSelected = null;
            directions.dArrayItem = null;
            $("#PointD").val("");
            $("#tdD").hide();

        }
        else if (directions.cSelected != null) {
            directions.MoveUpB();
            directions.MoveUpC();
            directions.cArrayItem = null;
            directions.cSelected = null;
            $("#PointC").val("");
            $("#tdC").hide();
            $("#remA").hide();
            $("#remB").hide();
            directions.cArrayItem = null;
        }
        directions.deleting = false;
        directions.GetDirections();

    },
    RemoveB: function () {
        directions.deleting = true;
        if (directions.eSelected != null) {
            directions.MoveUpC();
            directions.MoveUpD();
            directions.MoveUpE();
            directions.eArrayItem = null;
            directions.eSelected = null;
            $("#PointE").val("");
            $("#tdE").hide();
            directions.eArrayItem = null;
            $("#tdAdd").show();
        }
        else if (directions.dSelected != null) {
            directions.MoveUpC();
            directions.MoveUpD();
            directions.dArrayItem = null;
            directions.dSelected = null;
            $("#PointD").val("");
            $("#tdD").hide();
            directions.dArrayItem = null;
            $("#tdAdd").show();

        }
        else if (directions.cSelected != null) {
            directions.MoveUpC();
            directions.cArrayItem = null;
            directions.cSelected = null;
            $("#PointC").val("");
            $("#tdC").hide();
            $("#remA").hide();
            $("#remB").hide();
            directions.cArrayItem = null;
            directions.DirArray = null;
            $("#tdAdd").show();
        }
        directions.deleting = false;
        directions.GetDirections();

    },
    RemoveC: function () {
        directions.deleting = true;
        if (directions.eSelected != null) {
            directions.MoveUpD();
            directions.MoveUpE();
            directions.eArrayItem = null;
            directions.eSelected = null;
            $("#PointE").val("");
            $("#tdE").hide();
            directions.eArrayItem = null;
            $("#tdAdd").show();
        }
        else if (directions.dSelected != null) {
            directions.MoveUpD();
            directions.dArrayItem = null;
            directions.dSelected = null;
            $("#PointD").val("");
            $("#tdD").hide();
            directions.dArrayItem = null;

        }
        else if (directions.cSelected != null) {
            directions.cArrayItem = null;
            directions.cSelected = null;
            $("#PointC").val("");
            $("#tdC").hide();
            $("#remA").hide();
            $("#remB").hide();
            directions.cArrayItem = null;

        }
        directions.deleting = false;
        directions.GetDirections();

    },
    RemoveD: function () {
        directions.deleting = true;
        if (directions.eSelected != null) {
            directions.MoveUpE();
            directions.eArrayItem = null;
            directions.eSelected = null;
            $("#PointE").val("");
            $("#tdE").hide();
            directions.eArrayItem = null;
            $("#tdAdd").show();
        }
        else if (directions.dSelected != null) {
            directions.dArrayItem = null;
            directions.dSelected = null;
            $("#PointD").val("");
            $("#tdD").hide();
            directions.dArrayItem = null;

        }

        directions.deleting = false;
        directions.GetDirections();

    },
    RemoveE: function () {
        directions.deleting = true;
        if (directions.eSelected != null) {
            directions.eArrayItem = null;
            directions.eSelected = null;
            $("#PointE").val("");
            $("#tdE").hide();
            directions.eArrayItem = null;
            $("#tdAdd").show();
        }

        directions.deleting = false;
        directions.GetDirections();

    }
};
