/* * CUSF Landing Prediction Version 2 * Jon Sowman 2010 * jon@hexoc.com * http://www.hexoc.com * * http://github.com/jonsowman/cusf-standalone-predictor * * This file contains all the cookie-related functions for the landing * predictor * */ function saveLocationToCookie() { // Get the variables from the form var req_lat = $("#req_lat").val(); var req_lon = $("#req_lon").val(); var req_alt = $("#req_alt").val(); var req_name = $("#req_name").val(); var cookie_name = "cusf_predictor"; var locations_limit = 5; var name_limit = 20; // Check the length of the name if ( req_name.length > name_limit ) { req_name = req_name.substr(0, name_limit); } // Now let's init the cookie $.Jookie.Initialise(cookie_name, 99999999); if ( !$.Jookie.Get(cookie_name, "idx") ) { $.Jookie.Set(cookie_name, "idx", 0); var idx = 0; } else { var idx = $.Jookie.Get(cookie_name, "idx"); } if ( $.Jookie.Get(cookie_name, "idx") >= locations_limit ) { $("#location_save").fadeOut(); throwError("You may only save " + locations_limit + " locations - please delete some."); } else { // Find the next free index we can use var i=1; while ( $.Jookie.Get(cookie_name, i+"_name") && i<=locations_limit ) { i++; } // We will use this idx for the next location $.Jookie.Set(cookie_name, i+"_lat", req_lat); $.Jookie.Set(cookie_name, i+"_lon", req_lon); $.Jookie.Set(cookie_name, i+"_alt", req_alt); $.Jookie.Set(cookie_name, i+"_name", req_name); // Increase the index idx++; $.Jookie.Set(cookie_name, "idx", idx); // Close dialog and let the user know it worked $("#location_save").hide(); appendDebug("Successfully saved the location to cookie " + cookie_name); } } // For when the user clicks the "Custom" link for Launch Site // Construct and display a table of their custom saved locations stored // in a cookie, and display it function constructCookieLocationsTable(cookie_name) { var t = ""; t += "
Name | Use | Delete | "+$.Jookie.Get(cookie_name, i+"_name")+" | "; t += "Use"; t += " | "; t += "Delete"; t += " | "; t += ""; j++; } i++; } t += "