jQuery(document).ready(function () {
is_race_history = "1";
jQuery("#heat-selector-container").css('display','none');
if (jQuery('#locations-selector').length) {
jQuery('#locations-selector').on('change', function (e) {
jQuery('#heat-selector-container').empty(); jQuery('#heat-selector-container').css("display", "none"); jQuery("#stat-box").attr("data-populated", 0); var option_selected = jQuery(this).val(); //var api_url = ".clubspeedtiming.com/sp_center/SignIn.aspx"; setCookie("STYXKEYracerdatalocation", option_selected, 30); if (is_race_history === "1") { jQuery("#cs-login").css('display', 'block');
} else { //this is not racer personal data var action = "get_tracks"; var data = {}; var location = option_selected;
data = { "json": true };
args = { "location": location, "data": data, "action": action }; getClubSpeedRaceData(args, showTracks); } }); }
//heat selector for personal race into jQuery('#heat-selector-container').on('change', '#heat-selector', function() { var option_selected = jQuery(this).val();
var location_txt = "Mokena"; var location = 'aismokena'; if (!location) { jQuery("#racer-information").html("
Please select a Location
"); return; } jQuery("#racer-information").html("
Getting info..." + location_txt + "
"); var action = "get_heatinfo"; var data = {}; var heat = option_selected; var racer_id = jQuery(this).find(':selected').attr('data-racerid');
data = { "json": true, };
args = { "location": location, "heat": heat, "racer_id": racer_id, "data": data, "action": action }; getClubSpeedRaceData(args, showTable); });
//season selector jQuery('#season-selector-container').on('change', '#season-selector', function () { //alert('test'); });
if (jQuery('#stat-type-selector').length) {
jQuery('#stat-type-selector').on('change', function (e) { var option_selected = jQuery(this).val(); var api_url = ".clubspeedtiming.com/sp_center/SignIn.aspx"; setCookie("STYXKEYracerstattype", option_selected, 30);
if (option_selected === "stat-type-3" || option_selected === "stat-type-7") { jQuery("#stat-type-month-selector-container").css('display', 'block'); } else { jQuery("#stat-type-month-selector-container").css('display', 'none'); } }); }
//make it so if personal email changes, the heat selector is hidden if (jQuery('#email').length) { jQuery('#email').on('input', function (e) { jQuery('#heat-selector-container').empty(); jQuery('#heat-selector-container').css("display", "none"); jQuery("#stat-box").attr("data-populated",0); }); }
if (jQuery('#birthday').length) { jQuery('#birthday').on('input', function (e) { jQuery('#heat-selector-container').empty(); jQuery('#heat-selector-container').css("display", "none"); jQuery("#stat-box").attr("data-populated",0); }); }
//proskill button if (jQuery('#btn-get-proskill').length) {
jQuery('#btn-get-proskill').on('click', function (e) { var location_txt = jQuery('#locations-selector option:selected').text(); jQuery("#racer-information").html("
Getting info..." + location_txt + "
");
var data = {}; var location = jQuery('#locations-selector').val(); var season = jQuery('#season-selector').val();
var action = ""; if (Number(season) >= 2) { action = "get_proskill_spreadsheet"; } else { action = "get_proskill"; }
data = { "json": true };
args = { "location": location, "data": data, "action": action, "season": Number(season), }; if (location) { getClubSpeedRaceData(args,showTable); }else { jQuery("#racer-information").html("
Please select a Location
"); } }); }
//request proskill scores if (jQuery('#btn-request-proskill').length) {
jQuery('#btn-request-proskill').on('click', function (e) {
var action = "request_proskill_info"; var args = {}; var data = {}; var params = {}; var email = trim(jQuery('#proskill-email').val()); jQuery("#racer-information").html("
Getting info for..." + email + "
");
if (!validateEmail(email)) { jQuery("#racer-information").html("
Please enter a valid email address
"); return; } email = encodeURIComponent(email); setCookie("STYXKEYracerdataemail", email, 30);
var consent = jQuery('#accept-email').is(":checked");
data = { "json": true };
args = { "consent": consent, "email": email, "data": data, "action": action }; getClubSpeedRaceData(args, insertProskillRequestConfirmation); }); }
//request proskill scores checkbox jQuery("#accept-email").prop('checked', false); // Unchecks box jQuery('.consent-container').on('change', '#accept-email', function () { if (this.checked) { // checkbox is checked jQuery('#btn-request-proskill').trigger('click'); } });
//personal stats if (jQuery('#btn-get-rankings').length) {
jQuery('#btn-get-rankings').on('click', function (e) { var location_txt = "Mokena"; var location = 'aismokena'; jQuery("#racer-information").html("
Getting info..." + location_txt + "
"); var action = "get_personal_race_info"; var args = {}; var data = {}; var params = {}; var email = trim(jQuery('#email').val()); var birthdate = jQuery('#birthday').val(); //2020-08-04
if (!validateEmail(email)) { jQuery("#racer-information").html("
Please enter a valid email address
"); return; }
if (birthdate.length === 0) { jQuery("#racer-information").html("
Please enter a valid birthday
"); return; }
email = encodeURIComponent(email); setCookie("STYXKEYracerdataemail", email, 30); var url = "/racers/search";
var noncevalue = 'noserioussecurityneeded'; let encryption = new Encryption(); let pdata_str = `${email}:||:${birthdate}`; let pdata = encryption.encrypt(pdata_str, noncevalue);
data = { "json": true };
args = { "location": location, "url": url, "data": data, "action": action, "pdata": pdata };
getClubSpeedRaceData(args, insertHeatSelector);
//look into getting personal stats if (jQuery("#stat-box").attr("data-populated") == 0) { var action = "get_personal_stats";
data = { "json": true };
args = { "location": location, "url": url, "data": data, "action": action, "pdata": pdata }; getClubSpeedRaceData(args, showPersonalStats); } }); }
if (jQuery('#btn-get-stats').length) {
//this is not racer personal data var action = "get_tracks"; var data = {};
data = { "json": true };
args = { "location": location, "data": data, "action": action }; getClubSpeedRaceData(args, showTracks);
jQuery('#stat-type-month-selector-container').css('display', 'none');
jQuery('#btn-get-stats').on('click', function (e) { var location_txt = "Mokena"; jQuery("#racer-information").html("
Getting info..." + location_txt + "
"); var action = "get_stats"; var data = {}; var stat_type = jQuery('#stat-type-selector').val(); var location = 'aismokena'; var track= jQuery('#track-selector').val();
if(!track){
jQuery("#racer-information").html("
Please select a track
"); return; }
var month = ''; if (stat_type === "stat-type-3" || stat_type === "stat-type-7") { month = jQuery('#stat-type-month-selector').val(); }
data = { "json": true };
args = { "stat_type": stat_type, "location": location, "track": track, "month": month, "data": data, "action": action }; if (stat_type && location) { getClubSpeedRaceData(args,showTable); }else if (!stat_type) { jQuery("#racer-information").html("
Please select a Stat Type
"); }else if (!location) { jQuery("#racer-information").html("
Please select a Location
"); } }); }
var cookie_location = getCookie("STYXKEYracerdatalocation"); var cookie_stattype = getCookie("STYXKEYracerstattype"); var cookie_email = getCookie("STYXKEYracerdataemail");
if (cookie_email) { if (jQuery('#btn-get-rankings').length) { var em = decodeURIComponent(cookie_email); jQuery('#email').val(em); } }
//get params from URL string. This is for Race Results emails that link to this page. //autobahnspeed.kurt/scores-rankings/?email=kdommermuth@exit10.com&loc=baltimore&rid=1392904&hid=209569 //var url_string = window.location.href //var url = getUrlVars(url_string); // var e = url.searchParams.get("email"); //var loc = url.searchParams.get("loc"); //var rid = url.searchParams.get("rid"); //var hid = url.searchParams.get("hid");
var e = getQueryString("email"); var loc = getQueryString("loc"); var rid = getQueryString("rid"); var hid = getQueryString("hid"); var bday = getQueryString("birthdate"); let pdata_str = getQueryString("pdata");
if ((e && bday) || (pdata_str) && loc && jQuery('#btn-get-rankings').length) {
var location_txt = "Mokena"; var location = 'aismokena';
if (pdata_str) {
let noncevalue = 'noserioussecurityneeded'; let encryption = new Encryption(); let pdata_str_dec = encryption.decrypt(pdata_str, noncevalue); let pdata_ar = pdata_str_dec.split(":||:"); //jQuery('#email').val(decodeURIComponent(pdata_ar[0])); //jQuery('#birthday').val(pdata_ar[1]);
} else { jQuery('#email').val(e); jQuery('#birthday').val(bday); }
jQuery('#heat-selector').val(hid);
jQuery('#btn-get-rankings').trigger('click');
jQuery("#racer-information").html("
Getting info..." + location_txt + "
"); var action = "get_heatinfo"; var data = {}; var heat = hid; var racer_id = rid;
data = { "json": true, };
args = { "location": location, "heat": heat, "racer_id": racer_id, "data": data, "action": action }; getClubSpeedRaceData(args, showTable); //jQuery('#heat-selector').val(hid); }
});
//simple email validation function validateEmail(email) { var re = /\S+@\S+\.\S+/; return re.test(email); }
function insertProskillRequestConfirmation(data) { jQuery("#racer-information").html(""); if (data.success === 1) { jQuery("#racer-information").html(data.html); } else if (data.success === 2) { //we can't email them jQuery("#proskill-request-form").removeClass('hide'); jQuery("#accept-email").prop('checked', false); // Unchecks box jQuery("#racer-information").html("
" + data.html + "
"); }else { jQuery("#racer-information").html("
" + data.html + "
"); } }
function insertHeatSelector(data){ if (jQuery("#racer-information").find('.fa').length !== 0) { jQuery("#racer-information").html(""); } if (data.success === 1) { jQuery("#heat-selector-container").css('display','flex'); jQuery("#heat-selector-container").html(data.html); } else { jQuery("#racer-information").html("
" + data.html + "
"); } } rd_scroll = 1111110; function showTable(data) {
if (data.success === 1) {
jQuery("#racer-information").html(data.html);
var win_width = jQuery(window).width(); var table_width = jQuery(".racer-data").width();
if (win_width >= table_width) { rd_scroll = jQuery(".race-data").offset().top; var header_height = jQuery(".header").outerHeight(); var race_data_height = jQuery(".race-data").outerHeight(); var floatThead_top = header_height; jQuery(".racer-data").floatThead({ top: floatThead_top, position:'fixed', zIndex:100 }); }
jQuery('html, body').animate({ scrollTop: jQuery(".flag-logo").offset().top }, 2000);
} else {
jQuery("#racer-information").html("
" + data.html + "
"); }
}
function showPersonalStats(data) { if (data.success === 1) { jQuery("#stat-box").html(data.html); jQuery("#stat-box").removeClass('hide'); jQuery("#stat-box").attr('data-populated', 1); } else { jQuery("#stat-box").attr('data-populated', 0); jQuery("#stat-box").html("
" + data.html + "
"); } }
function showTracks(data) { if (data.success === 1) { if(!data.html.includes('hidden')){ jQuery("#track-selector-container").css('display','flex');
}else{ jQuery("#track-selector-container").css('display','none'); } jQuery("#track-selector-container").html(data.html); } else { jQuery("#track-selector-container").css('display','none'); jQuery("#racer-information").html("
" + data.html + "
"); } }
function getClubSpeedRaceData(data,callback) { jQuery.ajax({ url: "/wp-content/themes/autobahn/scores-rankings-api/api.php", type: "POST", data: JSON.stringify(data), dataType: 'text', success: function (data_returned) { r = JSON.parse(data_returned); callback(r); console.log("success-scores-rankings-api");
}, error: function () { console.log("error-loc"); } }); }
function trim(value) { return value.replace(/^\s+|\s+$/g,""); }
function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; }
function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; }