   // Functions for cookie detail serialization and evaluation.
    var cookie_name = 'routeplanner_history';
	var routeHistory = new Array();
	var months = ['Jan','Feb','Mar','Apr','May','Jun ','Jul','Aug','Sep','Oct','Nov','Dec']
	
	function getCurrentHistory() {
		var cookie = $.cookie(cookie_name);
		if (cookie != null) {
			routeHistory = eval( cookie );
		}
	}
	
	function addRoute(url, from, to, via ) {
		getCurrentHistory();
		var addNewRoute = true;
		var newURL = url.toString();
		var newFrom = from.toString();
		var newTo = to.toString();
		if( via ) {
			var newVia = via.toString();
		} else {
			var newVia = '';
		}
		var date = new Date();
		
		var newDate = date.getDate() + ' ';
		newDate += months[date.getMonth()] + ' ';
		newDate += date.getFullYear();
		
		if(newFrom.length > 25) {
			newFrom = newFrom.substr(0,25) + '...';
		} 
		if(newTo.length > 25) {
			newTo = newTo.substr(0,25) + '...';
		}
		if(newVia.length > 25) {
			newVia = newVia.substr(0,25) + '...';
		}
		
		for (i=0; i<routeHistory.length; i++){
			oldURL = routeHistory[i][0].toString();
			if(oldURL == newURL) {
				addNewRoute = false;
			}
		}
		
		if(addNewRoute == true) {
			if (routeHistory.length >= 5) {
				routeHistory.shift();
			}
			routeHistory.push([newURL,newFrom,newTo,newVia,newDate]);
			updateCookie();
		}
	}
	
	function removeRoutes(indexArray) {
		var newRouteHistory = new Array();
		
		for(i=0; i < routeHistory.length; i++ ){
			removeThis = false;
			for(j=0; j< indexArray.length; j++) {
				if( indexArray[j] == i ) {
					removeThis = true;
				}
			}
			
			if (removeThis == false) {
				newRouteHistory.push(routeHistory[i].slice());
			}
		}
		
		routeHistory = newRouteHistory.slice();
		updateCookie();
	}
	
	function updateCookie() {
		var date = new Date();
        date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
		var str = '[';
		for(i=0; i < routeHistory.length; i++ ){
			str += serialize(routeHistory[i]);
			if(i<(routeHistory.length-1)){
				str += ',';
			}
		}
		str += ']';
		$.cookie(cookie_name, str, { path: '/', expires: date });
	}
	
	function serialize( array )
	{
		var str = '[';
		var i;
		for( i=0; i<array.length; ++i ) {
			str += '"' + array[i] + '"';
			if(i<array.length-1){
				str += ',';
			}
		}
		str += ']';
		return str;
	}