Javascript不工作,但没有错误

Javascript不工作,但没有错误,javascript,html,Javascript,Html,我有一个代码,它看起来完全正常,我看不到任何错误,但它仍然不工作 以下是链接: var映射; var directionsService=new google.maps.directionsService(); var directionsDisplay=new google.maps.DirectionsRenderer(); var map_中心; 变焦; //初始化Google Map API onload $(函数(){ 初始化(); }); //完成页面加载后要进行的调用 $(文档).

我有一个代码,它看起来完全正常,我看不到任何错误,但它仍然不工作

以下是链接:

var映射;
var directionsService=new google.maps.directionsService();
var directionsDisplay=new google.maps.DirectionsRenderer();
var map_中心;
变焦;
//初始化Google Map API onload
$(函数(){
初始化();
});
//完成页面加载后要进行的调用
$(文档).ready(函数(){
$('.typecar')。在('click',function()上{
$('.typecar.selected_car').removeClass('selected_car');
$(this.toggleClass('selected_car');
})
//要求提交表格
$(“#dirform”).submit(函数(){
var type_auto=$('.typecar.selected_car').attr('data-car');
如果(自动输入){
$(“#错误”)。文本(“”);
$(“#加载程序”).html('Loading…');
calcRoute(自动型);
}否则{
$(“#错误”).text('Choose type of transport');
}
返回false;
});
//当从模式框中打开时,正确加载地图
$('#mapmodel')。在('显示',函数()上){
map_center=map.getCenter();
google.maps.event.trigger(map,“resize”);
地图设置中心(地图中心);
map.setZoom(map\u zoom);
});
$('#TransferOrder')。在('submit',函数(e)上{
e、 预防默认值();
var dir=$('#dirform').serialize();
var data=$(this).serialize()+'&carType='+$('.selected_-car').attr('data-car')+'&total='+$('.#summary').text()+'euro&'+dir;
$.ajax({
网址:'http://begosolution.com/EngineTest/proxysender.php',
键入:“POST”,
数据:数据,
成功:功能(数据){
控制台日志(数据);
$('#formdiv').slideUp();
}
})
})
});
//初始化谷歌地图对象
函数初始化(){
变量映射选项={
中心:新google.maps.LatLng(56.909400,24.2055558),
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
应用自动完成($(“#fromAddress”)[0]);
应用自动完成($(“#toAddress”)[0]);
}
//应用自动完成API
函数应用\自动完成(输入){
变量选项={
类型:['geocode']
};
var autocomplete=new google.maps.places.autocomplete(输入,选项);
autocomplete.bindTo('bounds',map);
}
//计算路线和方向
功能计算器(自动类型){
//创建航路点阵列并用用户输入的所有位置填充
var waypts=新数组();
var start_address=$(“#fromAddress”).val();
var end_address=$(“#toAddress”).val();
$('input[name=“toWaypoints[]”)。每个(函数(){
推({
位置:$(this).val(),
中途停留:对
});
});
//为映射创建请求变量
var请求={
来源:起始地址,
目的地:结束地址,
航路点:航路点,
航路点:对,
travelMode:google.maps.Directions travelMode.DRIVING
};
//执行Route方法在地图上生成方向路线
路由(请求、功能(响应、状态){
//var directionsDiv=document.getElementById('directions');
var think=false;
var loc_arr=[];
如果(response.status==='OK'){
var mapData=response.routes[0]。legs;
}否则{
var-reserror=true;
}
//对象列表
var Tallin={in:{
标准:17,
小型货车:18,
小巴:19
},
输出:{
年:35,
标准:0.45,
小型货车:0.55,
小巴:0.65
}
}
var Riga={
机场:{
标准件:25件,
小型货车:32,
小巴:36
},
在:{
标准件:22件,
小型货车:29,
小巴:33
},
输出:{
年:35,
标准:0.45,
小型货车:0.55,
小巴:0.65
}
}
瓦尔赫尔辛基={
机场:{
标准件:39件,
小型货车:49,
小巴:59
},
在:{
标准件:33件,
小型货车:43,
小巴:53
},
输出:{
年:35,
标准:0.8,
小型货车:0.95,
小巴:1.10
}
}
var lat_c=[‘latvijas’、‘П»П°СССёСЏ’、‘拉脱维亚’];
var riga_c=['rö«ga','riga','СЂёёіП'];
var riga_机场=['lv-1053'];
var estЌu c=[‘СЌСЃС’;
var tal_c=['tallinna'、'tallinn'、'С硎硎硎硎硎硎硎;
var fin_c=[“СчёЅззСз”、“芬兰”、“芬兰”];
变量赫尔辛基、赫尔辛福斯、万塔、万达、埃斯波、埃斯波、С…ааааСааёё、СЌСаїѕ、аааааа;
var hel_机场=['01530','01531'];
var rusЏc=[‘俄罗斯’、‘俄罗斯’;
var spbЃu c=[‘СЃЅЅєС-їбССЂбббСб‘’、‘圣彼得堡’、‘圣彼得堡’、‘圣彼得堡’;
var spb_lenobl=[“Сӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗӗ1239;
var-mat=0;
功能检查国家(countryStart、countryEnd){
var c_arr=[lat_c,est_c,fin_c,rus_c];
对于(var p=0;p-1){
垫子++
}
var map;
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map_center;
var map_zoom;

//initialize Google Map API onload
$(function() {
    initialize();
});


//calls to make after finishing complete page load
$(document).ready(function() {
    $('.typecar').on('click', function() {
            $('.typecar.selected_car').removeClass('selected_car');
            $(this).toggleClass('selected_car');
        })
        //call on form submit
    $("#dirform").submit(function() {
        var type_auto = $('.typecar.selected_car').attr('data-car');
        if (type_auto) {
            $('#errors').text('');
            $("#loader").html('&nbsp;<span class="label label-info">Loading...</span>');
            calcRoute(type_auto);
        } else {
            $('#errors').text('Choose type of transport');
        }
        return false;
    });

    // Hack for loading Map properly when opened from Modal box
    $('#mapModal').on('shown', function() {
        map_center = map.getCenter();
        google.maps.event.trigger(map, "resize");

        map.setCenter(map_center);
        map.setZoom(map_zoom);
    });

    $('#TransferOrder').on('submit', function(e) {
        e.preventDefault();
        var dir = $('#dirform').serialize();
        var data = $(this).serialize() +'&carType='+$('.selected_car').attr('data-car') +'&total=' + $('#summary').text() + ' euro&' + dir;
        $.ajax({
            url: 'http://begosolution.com/EngineTest/proxysender.php',
            type: 'POST',
            data: data,
            success: function(data) {
                console.log(data);
                $('#formdiv').slideUp();
            }
        })
    })

});


// Initialize google map object
function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(56.909400, 24.205558),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    apply_autocomplete($("#fromAddress")[0]);
    apply_autocomplete($("#toAddress")[0]);
}

// Apply Autocomplete API
function apply_autocomplete(input) {
    var options = {
        types: ['geocode']
    };
    var autocomplete = new google.maps.places.Autocomplete(input, options);
    autocomplete.bindTo('bounds', map);
}


// Calculate route and directions
function calcRoute(type_auto) {
    //create waypoints array & fill it with all locations entered by user
    var waypts = new Array();

    var start_address = $("#fromAddress").val();
    var end_address = $("#toAddress").val();


    $('input[name="toWaypoints[]"]').each(function() {
        waypts.push({
            location: $(this).val(),
            stopover: true
        });
    });

    // Create a Request variable for Map
    var request = {
        origin: start_address,
        destination: end_address,
        waypoints: waypts,
        optimizeWaypoints: true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };

    // Execute the Route Method to generate Direction Route on Map
    directionsService.route(request, function(response, status) {
        //var directionsDiv = document.getElementById('directions');
        var think = false;
        var loc_arr = [];
        if (response.status === 'OK') {
            var mapData = response.routes[0].legs;
        } else {
            var reserror = true;
        }
        // list of objects
        var Tallin = { in : {
                standart: 17,
                minivan: 18,
                minibus: 19
            },
            out: {
                In: 35,
                standart: 0.45,
                minivan: 0.55,
                minibus: 0.65
            }
        }
        var Riga = {
            airport: {
                standart: 25,
                minivan: 32,
                minibus: 36
            },
            in : {
                standart: 22,
                minivan: 29,
                minibus: 33
            },
            out: {
                In: 35,
                standart: 0.45,
                minivan: 0.55,
                minibus: 0.65
            }
        }
        var Helsinki = {
            airport: {
                standart: 39,
                minivan: 49,
                minibus: 59
            },
            in : {
                standart: 33,
                minivan: 43,
                minibus: 53
            },
            out: {
                In: 35,
                standart: 0.8,
                minivan: 0.95,
                minibus: 1.10
            }
        }

        var lat_c = ['latvijas', 'латвия', 'latvia'];
        var riga_c = ['rД«ga', 'riga', 'СЂРёРіР°'];
        var riga_airport = ['lv-1053'];
        var est_c = ['эстония', 'estonia', 'eesti'];
        var tal_c = ['tallinna', 'tallinn', 'таллин'];
        var fin_c = ['финляндия', 'finland', 'finlandia'];
        var hel_c = ['helsinki', 'helsingfors', 'vantaa', 'vanda', 'espoo', 'esbo', 'хельсинки', 'эспо', 'вантаа'];
        var hel_airport = ['01530', '01531'];
        var rus_c = ['СЂРѕСЃСЃРёСЏ', 'russia', 'rus'];
        var spb_c = ['санкт-петербург', 'st petersburg', 'st.petersburg', 'st.petersburg'];
        var spb_lenobl = ['ленинградская обл.'];


        var mat = 0;

        function checkcountry(countryStart, countryEnd) {
            var c_arr = [lat_c, est_c, fin_c, rus_c];
            for (var p = 0; p < c_arr.length; p++) {
                if (c_arr[p].indexOf(countryStart) > -1) {
                    mat++
                }
                if (c_arr[p].indexOf(countryEnd) > -1) {
                    mat++
                }
            }
        }


        if (!reserror) {
            for (var i = 0; i < mapData.length; i++) {
                loc_arr.push({ 'startLoc': mapData[i].start_address.split(','), 'endLoc': mapData[i].end_address.split(',') });
            }
            for (var i = 0; i < loc_arr.length; i++) {
                checkcountry(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 1].trim().toLowerCase(), loc_arr[i].startLoc[loc_arr[i].startLoc.length - 1].trim().toLowerCase());
                console.log(loc_arr[i]);
                if (loc_arr[i].endLoc[loc_arr[i].endLoc.length - 1] == loc_arr[i].startLoc[loc_arr[i].startLoc.length - 1]) {
                    var country = loc_arr[i].endLoc[loc_arr[i].endLoc.length - 1].trim().toLowerCase();
                    if (lat_c.indexOf(country) > -1) { //Латвия
                        try {
                            var loc_end_city = loc_arr[i].endLoc[2].toLowerCase().trim();
                        } catch (e) {
                            var loc_end_city = loc_arr[i].endLoc[0].toLowerCase().trim();
                        }
                        try {
                            var loc_start_city = loc_arr[i].startLoc[2].toLowerCase().trim();
                        } catch (e) {
                            var loc_start_city = loc_arr[i].startLoc[0].toLowerCase().trim();
                        }
                        if ((riga_c.indexOf(loc_end_city) > -1) || (riga_c.indexOf(loc_start_city) > -1)) { //Р РёРіР°
                            if ((riga_c.indexOf(loc_end_city) > -1) && (riga_c.indexOf(loc_start_city) > -1)) {
                                var COST = Riga.in[type_auto];
                            } else {
                                if ((riga_airport.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].toLowerCase().trim()) > -1) || (riga_airport.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].toLowerCase().trim()) > -1)) {
                                    var COST = Riga.out.In;
                                    var COSTOFLENGTH = Riga.out[type_auto];
                                } else {
                                    var COST = Riga.out.In;
                                    var COSTOFLENGTH = Riga.out[type_auto];
                                }
                            }
                        } else {
                            if ((riga_airport.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].trim()) > -1) || (riga_airport.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].trim()) > -1)) {
                                var COST = Riga.out.In;
                                var COSTOFLENGTH = Riga.out[type_auto];
                            } else {
                                var MSG = 'Price on request';
                                think = true;
                            }
                        }
                    }
                    if (est_c.indexOf(country) > -1) { //Эстония
                        try {
                            var loc_end_city = loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        } catch (e) {
                            var loc_end_city = loc_arr[i].endLoc[0].toLowerCase().trim();
                        }
                        try {
                            var loc_start_city = loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        } catch (e) {
                            var loc_start_city = loc_arr[i].startLoc[0].toLowerCase().trim();
                        }
                        if ((tal_c.indexOf(loc_end_city) > -1) || (tal_c.indexOf(loc_start_city) > -1)) { //Таллин
                            if ((tal_c.indexOf(loc_end_city) > -1) && (tal_c.indexOf(loc_start_city) > -1)) {
                                var COST = Tallin.in[type_auto];
                            } else {
                                var COST = Tallin.out.In;
                                var COSTOFLENGTH = Tallin.out[type_auto];
                            }
                        } else {
                            var MSG = 'Price on request';
                            think = true;
                        }
                    }

                    if (fin_c.indexOf(country) > -1) {
                        try {
                            var loc_end_city = loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        } catch (e) {
                            var loc_end_city = loc_arr[i].endLoc[0].toLowerCase().trim();
                        }
                        try {
                            var loc_start_city = loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        } catch (e) {
                            var loc_start_city = loc_arr[i].startLoc[0].toLowerCase().trim();
                        }
                        if ((hel_c.indexOf(loc_end_city) > -1) || (hel_c.indexOf(loc_start_city) > -1)) {
                            if ((hel_c.indexOf(loc_end_city) > -1) && (hel_c.indexOf(loc_start_city) > -1)) {
                                if ((hel_airport.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\D\s]/gi, '').toLowerCase()) > -1) || (hel_airport.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\D\s]/gi, '').toLowerCase()) > -1)) { ////Хельсинки аэропорт
                                    var COST = Helsinki.airport[type_auto];
                                } else {
                                    var COST = Helsinki.in[type_auto];
                                }
                            } else {
                                if ((hel_airport.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\D\s]/gi, '').toLowerCase()) > -1) || (hel_airport.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\D\s]/gi, '').toLowerCase()) > -1)) { ////Хельсинки аэропорт
                                    var COST = Helsinki.out.In;
                                    var COSTOFLENGTH = Helsinki.out[type_auto];
                                    //Поставить стоимость аэропорта
                                } else {
                                    var COST = Helsinki.out.In;
                                    var COSTOFLENGTH = Helsinki.out[type_auto];
                                }
                            }
                        } else {
                            var MSG = 'Price on request';
                            think = true;
                        }
                    }
                } else {
                    var countryStart = loc_arr[i].startLoc[loc_arr[i].startLoc.length - 1].toLowerCase().trim();
                    var countryEnd = loc_arr[i].endLoc[loc_arr[i].endLoc.length - 1].toLowerCase().trim();
                    if ((rus_c.indexOf(countryStart) > -1) || (rus_c.indexOf(countryEnd) > -1)) {
                        if ((spb_c.indexOf(loc_arr[i].startLoc[Math.ceil(loc_arr[i].startLoc.length / 2 - 1)].toLowerCase().trim()) > -1) || (spb_c.indexOf(loc_arr[i].endLoc[Math.ceil(loc_arr[i].endLoc.length / 2 - 1)].toLowerCase().trim()) > -1) || (spb_lenobl.indexOf(loc_arr[i].startLoc[Math.ceil(loc_arr[i].startLoc.length / 2 - 1)].toLowerCase().trim()) > -1) || (spb_lenobl.indexOf(loc_arr[i].endLoc[Math.ceil(loc_arr[i].endLoc.length / 2 - 1)].toLowerCase().trim()) > -1)) {
                            try {
                                var flag = (riga_c.indexOf(loc_arr[i].endLoc[2].toLowerCase().trim()) > -1) || (riga_c.indexOf(loc_arr[i].startLoc[2].toLowerCase().trim()) > -1);
                                try {
                                    var flagair = (riga_airport.indexOf(loc_arr[i].endLoc[3].toLowerCase().trim()) > -1);
                                } catch (e) {
                                    var flagair = false;
                                }
                                try {
                                    var flagair = (riga_airport.indexOf(loc_arr[i].startLoc[3].toLowerCase().trim()) > -1);
                                } catch (e) {
                                    var flagair = false;
                                }
                            } catch (e) {
                                var flag = (riga_c.indexOf(loc_arr[i].endLoc[0].toLowerCase().trim()) > -1) || (riga_c.indexOf(loc_arr[i].startLoc[0].toLowerCase().trim()) > -1);
                            }
                            if (flag || flagair) { //Р РёРіР°
                                var COST = Riga.out.In;
                                var COSTOFLENGTH = Riga.out[type_auto];
                            }
                            try {
                                var flag = (tal_c.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase()) > -1) || ((tal_c.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase())) > -1);
                            } catch (e) {
                                var flag = (tal_c.indexOf(loc_arr[i].endLoc[0].replace(/[\d\s]/gi, '').toLowerCase()) > -1) || ((tal_c.indexOf(loc_arr[i].startLoc[0].replace(/[\d\s]/gi, '').toLowerCase())) > -1);
                            }
                            if (flag) { //Таллин
                                var COST = Tallin.out.In;
                                var COSTOFLENGTH = Tallin.out[type_auto];
                            }
                            try {
                                var flag = (hel_c.indexOf(loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase()) > -1) || (hel_c.indexOf(loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase()) > -1);
                            } catch (e) {
                                var flag = (hel_c.indexOf(loc_arr[i].endLoc[0].replace(/[\d\s]/gi, '').toLowerCase()) > -1) || (hel_c.indexOf(loc_arr[i].startLoc[0].replace(/[\d\s]/gi, '').toLowerCase()) > -1);
                            }
                            if (flag) { //Хельсинки
                                var COST = Helsinki.out.In;
                                var COSTOFLENGTH = Helsinki.out[type_auto];
                            }
                        }
                    } else if ((fin_c.indexOf(countryEnd) > -1) || (fin_c.indexOf(countryStart) > -1)) {
                        var MSG = 'Unfortunately, this transfer is not possible';
                    } else {
                        var loc_end_city = loc_arr[i].endLoc[loc_arr[i].endLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        var loc_start_city = loc_arr[i].startLoc[loc_arr[i].startLoc.length - 2].replace(/[\d\s]/gi, '').toLowerCase();
                        if ((tal_c.indexOf(loc_start_city) > -1)) {
                            var COST = Tallin.out.In;
                            var COSTOFLENGTH = Tallin.out[type_auto];
                        } else if (riga_c.indexOf(loc_start_city) > -1) {
                            var COST = Riga.out.In;
                            var COSTOFLENGTH = Riga.out[type_auto];
                        } else {
                            var MSG = 'Price on request';
                            think = true;
                        }
                    }
                }
            }
        }

        if (status == google.maps.DirectionsStatus.OK) {
            //directionsDiv.innerHTML = "";
            console.log(typeof(MSG), typeof(COST), think);
            if (mat<2) {
                initialize();
                $('#formdiv').fadeOut();
                $("#loader").html('');
                $("#locations").html('');
                $("#summary").html('');
                return false;
            }
            $('#formdiv').fadeIn();

            directionsDisplay.setMap(map);
            directionsDisplay.setDirections(response);
            //directionsDisplay.setPanel(directionsDiv);
            var route = response.routes[0];

            // calculate total distance and duration
            // generate list of locations to print
            var distance = 0;
            var time = 0;
            var locations_list = '<ol>';
            for (var i = 0; i < route.legs.length; i++) {
                var theLeg = route.legs[i];
                locations_list += '<li>' + theLeg.start_address + '</li>';
                distance += theLeg.distance.value;
                time += theLeg.duration.value;
            }
            locations_list += '<li>' + theLeg.end_address + '</li>';
            locations_list += '</ol>';

            $("#locations").html('<h4>Directions for :</h4>' + locations_list);


            //display summary into summary block
            total_summary = '<div class="alert alert-success">';
            if (COSTOFLENGTH) {
                var summary_cost = (COST + (Math.round(distance / 100) / 10 * COSTOFLENGTH)).toFixed(2);
                total_summary += '  <strong>Total Distance : </strong>' + showDistance(distance) + " ( about " + Math.round(time / 60) + " minutes) " + "<i class='fa fa-eur' aria-hidden='true'></i> " + summary_cost;
            } else if (COST) {
                total_summary += '  <strong>Total Distance : </strong>' + showDistance(distance) + " ( about " + Math.round(time / 60) + " minutes) " + "<i class='fa fa-eur' aria-hidden='true'></i> " + COST;
            } else if (MSG) {
                total_summary += '  <strong>' + MSG + '</strong>';
            }
            total_summary += '</div>';
            $("#summary").html(total_summary);

            map_zoom = map.getZoom();

            $("#loader").html('');
        } else {
            var statusText = getDirectionStatusText(status);
            //directionsDiv.innerHTML = "An error occurred - " + statusText;
        }

    });
}

// Show distance in different measurements
function showDistance(distance) {
    return Math.round(distance / 100) / 10 + " km (" + Math.round((distance * 0.621371192) / 100) / 10 + " miles)";
}

// Get the Map direction status message
function getDirectionStatusText(status) {
    switch (status) {
        case google.maps.DirectionsStatus.INVALID_REQUEST:
            return "Invalid request";
        case google.maps.DirectionsStatus.MAX_WAYPOINTS_EXCEEDED:
            return "Maximum waypoints exceeded";
        case google.maps.DirectionsStatus.NOT_FOUND:
            return "Not found";
        case google.maps.DirectionsStatus.OVER_QUERY_LIMIT:
            return "Over query limit";
        case google.maps.DirectionsStatus.REQUEST_DENIED:
            return "Request denied";
        case google.maps.DirectionsStatus.UNKNOWN_ERROR:
            return "Unknown error";
        case google.maps.DirectionsStatus.ZERO_RESULTS:
            return "Zero results";
        default:
            return status;
    }
}


// Add More waypoints
function add_waypoint() {
    waypoint_container = '<div class="control-group ">';
    waypoint_container += '  <label class="control-label" for="inputEmail">Journey Start From :</label>';
    waypoint_container += '  <div class="controls">';
    waypoint_container += '      <input type="text" id="toWaypoints" name="toWaypoints[]" class="input-xlarge" value="">';
    waypoint_container += '      &nbsp;<a href="#" onclick="return add_waypoint();">Add Waypoints</a>';
    waypoint_container += '      &nbsp;<a href="#" onclick="return remove_waypoint(this);">Remove</a>';
    waypoint_container += '  </div>';
    waypoint_container += '</div>';

    $('.destination-container').before(waypoint_container);

    $('[name=toWaypoints\\[\\]]').each(function() {
        apply_autocomplete($(this)[0]);
    });

    return false;
}

// Remove waypoint
function remove_waypoint(obj) {
    $(obj).parent().parent().remove();
    return false;
}