function traceroute(ip) {
    $.ajax({
	url : traceroute_url,
	data : {
	    a : Math.random(),
	    d : ip
	},
	dataType: 'json',
	beforeSend : function() {
	    // show throbber
	    document.getElementById('thr').style.display = 'block';
	    document.getElementById('start_button').style.display = 'none';
	    document.getElementById('custom_trace').style.display = 'none';
	    document.getElementById('tracepath_data').innerHTML = '';
	    if(ip) {
		document.getElementById('target').innerHTML = ip;
	    }
	    if(map) {
		map.clearOverlays();
	    }
	},
	success : function(data, status) {
	    // hide throbber
	    document.getElementById('thr').style.display = 'none';
	    // show results on map and table
    	    var micon = new GIcon(G_DEFAULT_ICON);
	    micon.image = "/images/map/point.gif";
	    micon.shadow = "";
            micon.iconSize = new GSize(6, 6);
            micon.iconAnchor = new GPoint(3, 3);
	    var sicon = new GIcon(G_DEFAULT_ICON);
	    sicon.image = '/images/map/start_marker.png';
	    var ficon = new GIcon(G_DEFAULT_ICON);
	    ficon.image = '/images/map/finish_marker.png';
	    var prev_ll = null;
	    var html = '';
	    var b = null;
            var ccode;
            var cname;
            var city;
	    if(data.length > 2) {
		b = new GLatLngBounds(
		    new GLatLng(data[0].location.latitude + 1, data[0].location.longitude - 1),
		    new GLatLng(data[0].location.latitude - 1, data[0].location.longitude + 1)
		);
	    }
	    for(var i=0;i < data.length; i++) {
		if(map && data[i].location) {
		    var ll = new GLatLng(data[i].location.latitude, data[i].location.longitude);
		    if(b && i > 0) {
			b.extend(ll);
		    }
		    if(prev_ll) {
    			var polyline = new GPolyline([prev_ll, ll], '#000000', 3);
			map.addOverlay(polyline);
		    }
		    var markerOptions = {icon:micon};
		    if(i == 0) {
			markerOptions.icon = sicon;
		    }
		    if(i == data.length - 1) {
			markerOptions.icon = ficon;
    		    }
    	    	    map.addOverlay(new GMarker(ll, markerOptions));
		    prev_ll = ll;
		}
                if(data[i].location) {
                    ccode = data[i].location.country_code.toLowerCase();
                    cname = data[i].location.country_name;
                    city = data[i].location.city;
                } else {
                    ccode = 'unknown';
                    cname = '?';
                    city = '';
                }
                var country_name = data[i].location
		html += '<tr class="'+(i % 2 ? 'even' : 'odd')+'"><td>' + (i + 1) + '</td><td width="130">' + data[i].ip + '</td><td>' +
		    '<img src="/images/icons/countries/'+ccode +
		    '.gif" align="bottom" alt=""> ' + cname +
		    (city ? ', ' + city : '') +
		    '</td><td width="80">' + data[i].time + '</td></tr>';
	    }
	    if(html != '') {
		html = '<table class="tbl" border="0" width="100%" cellpadding="4" cellspacing="1">' + html + '</table>';
	    }
	    if(map && b) {
		var zoom = map.getBoundsZoomLevel(b);
		map.setCenter(b.getCenter(), zoom);
	    }
	    document.getElementById('tracepath_data').innerHTML = html;
	    document.getElementById('custom_trace').style.display = 'block';
	}
    });
}

