// JavaScript Document

function trip_add_stop(stop_to_add){
	new Ajax.Updater('t_destinations', root+'scripts/php/trip_planner.php', { postBody: 'action=add&stop='+stop_to_add+'&root='+root, onComplete: function(){
		Sortable.create("trip_stops", {onUpdate:Send_sortable});
	}});
}

function trip_remove_stop(stop_to_remove){
	new Ajax.Updater('t_destinations', root+'scripts/php/trip_planner.php', { postBody: 'action=remove&stop='+stop_to_remove+'&root='+root, onComplete: function(){
		Sortable.create("trip_stops", {onUpdate:Send_sortable});
	}});
}

function activate_trip_list(){
	Sortable.create("trip_stops", {onUpdate:Send_sortable});
}

function Send_sortable(){
	var post = Sortable.serialize("trip_stops");
	new Ajax.Updater("t_destinations", root+"scripts/php/trip_planner.php", {postBody:'action=reorder&'+post+'&root='+root, onComplete: function(){
		Sortable.create("trip_stops", {onUpdate:Send_sortable});
	}});
}


function test_address(){
	call_ids();
	addresses = window.addresses;
	ids = window.ids;
	window.failed = Array();
	for(i=0; i<addresses.length; i++){
		var action = seek_address(addresses[i]);
	}	
	var TimerID = setTimeout("remove_buttons()", 1000);
}

function seek_address(address){
	geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(address,
			function(point){
				if(!point){
					window.failed.push(address);
				}
			}
		);
	}
}

function remove_buttons(){
	for(i=0; i<window.failed.length; i++){
		for(a=0; a<window.addresses.length; a++){
			if(window.addresses[a] == window.failed[i]){
				var map_button = $('map_it_'+window.ids[a]);
				if(map_button){map_button.remove();}
			}
		}	
	}
}