");
jQuery(document).ready(function(){
/* load in original library to avoid conflicts */
// $jQueryAEM = jQuery.noConflict();
// jQuery.getScript("https://code.jquery.com/jquery-1.12.4.js")
// .done(function( script, textStatus ) {
// $jQueryUI = jQuery.noConflict();
// jQuery.getScript("https://code.jquery.com/ui/1.12.1/jquery-ui.js")
// .done(function( script, textStatus) {
// $ = $jQueryAEM; jQuery = $jQueryAEM;
/* begin widget for pre-populated list search */
jQuery( function() {
// var itemList = JSON.parse(jQuery("#custom-search-data").text());
var request = new XMLHttpRequest();
request.open("GET","https://www.redcrossblood.org/content/dam/redcrossblood/rcb/hosting-a-blood-drive/resource/HighSchoolAccountNames011121.csv", false);
request.send(null);
var itemList = JSON.parse(request.responseText);
var locationList = [];
jQuery.each(itemList, function(index, item) {
itemList[index].label = item.key;
locationList[item.key] = item.location;
});
itemList[itemList.length] = {
label: "Other School Not Listed | Write in your own"
}
jQuery("#custom-search-school").data("location", locationList);
jQuery("#custom-search-school").autocomplete({
autoFocus: true,
minLength: 3,
source: function(request, response) {
var results = jQuery.ui.autocomplete.filter(itemList, request.term);
response(results.slice(0, 10));
}
});
} );
/* end widget for pre-populated list */
// });
// });
/* end library load */
var customPanel = '
';
jQuery(customPanel).first().insertAfter(".content-card-with-zip .card-info");
if (window.self !== window.top) {
return false;
}
/* move around items to avoid default dynamic behaviors */
var $link = jQuery("a[data-att-button='custom-button']");
var $button = $link.find("button");
var $form = jQuery("a[data-att-button='custom-button']").closest("form");
var $input = $form.find("input[name='zipSponsor']");
$link.parent().append($button);
$link.hide();
$input.parent().prepend('
');
$input.hide();
/* end moving around default elements */
jQuery("#fallback").parent().hide(); /* since script is working */
jQuery(".breadcrumb-main .crumb-hidden-container").hide();
jQuery("div[id*=wufoo-]")
.closest(".generic-cta-panel").hide(); /* until we collect some info */
customAttachHandler();
});
function customAttachHandler() {
jQuery("a[data-att-button='custom-button']")
.closest("form").submit(function(event){
event.preventDefault();
var $postal = jQuery("#custom-zip-code");
if (/^\d{5}$/.test($postal.val()) === false) {
alert("Please provide a valid five-digit ZIP Code.");
return false;
}
if (/write in/i.test(jQuery("#custom-search-school").val()) === true) {
if (confirm("Are you sure you want to continue without selecting a suggested school?") === false) {
return false;
} else {
var customInputName = prompt("Please write in your own High School Name to proceed.");
if (customInputName.length < 1) { return false; }
customInputName = customInputName + " [writein]";
/* append for lookup to be checked as valid */
var locationList = jQuery("#custom-search-school")
.data("location");
locationList[customInputName] = customInputName;
jQuery("#custom-search-school").val(customInputName)
.data("location", locationList);
}
}
if (typeof jQuery("#custom-search-school")
.data("location")[jQuery("#custom-search-school").val()] === "undefined") {
alert("Please select a high school from the suggestions.");
return false;
}
customToggleFormStatus();
jQuery.ajax({
async: true,
type: 'GET',
url: "/bin/region-search.zip=" + $postal.val() + ".json",
success: function(data){
if(typeof data.region.regionCode === "undefined") {
customToggleFormStatus();
alert("The ZIP Code provided does not match available locations. Please enter a different ZIP Code and try again.");
return false;
}
// lookup tables to match Wufoo values
var customUnits = {
"041": "Alabama and Central Gulf Coast",
"035": "Appalachian",
"007": "Arizona",
"032": "Badger-Hawkeye",
"012": "Carolinas",
"016": "Central Ohio",
"002": "Central Plains",
"033": "Connecticut",
"018": "Great Lakes",
"027": "Greater Alleghenies",
"053": "Greater Chesapeake and Potomac",
"055": "Greater Ozarks-Arkansas",
"040": "Heart of America",
"038": "Indiana-Ohio",
"020": "Lewis and Clark",
"004": "Massachusetts",
"029": "Mid-Atlantic",
"009": "Midwest",
"011": "Missouri-Illinois",
"001": "New York-Penn",
"017": "North Central",
"030": "Northeastern Pennsylvania",
"084": "Northern California",
"034": "Northern New England",
"042": "Northern Ohio",
"021": "Pacific Northwest",
"022": "Penn-Jersey",
"054": "Puerto Rico",
"024": "River Valley",
"036": "South Carolina",
"013": "Southeastern Michigan",
"003": "Southern",
"006": "Southern California",
"049": "Southwest",
"019": "Tennessee Valley",
"050": "Western Lake Erie"
}
jQuery("#custom-unit-name")
.val(customUnits[data.region.regionCode]);
customToggleFormStatus();
customEmbedForm();
}
}); // end ajax
return false;
}); // end listener
} // end customAttachHandler
function customToggleFormStatus() {
if (this.state === undefined) {
this.state = false;
}
if (!this.state) {
jQuery("html, body").css("cursor", "wait");
jQuery("#custom-form-start input").attr("disabled", "disabled");
this.state = true;
return this.state;
} else {
jQuery("html, body").css("cursor", "auto");
jQuery("#custom-form-start input").removeAttr("disabled");
this.state = false;
return this.state;
}
}
function customEmbedForm() {
jQuery("a[data-att-button='custom-button']")
.closest(".content-card-with-zip").hide();
jQuery("div[id*=wufoo-]").closest(".generic-cta-panel").show();
var options = {
'userName':'americanredcross',
'formHash':'zhrajom0iykure',
'autoResize':true,
'defaultValues':'field68=' + jQuery("#custom-unit-name").val()
+ '&field14=' + jQuery("#custom-search-school").val()
+ '&field3=' + jQuery("#custom-search-school")
.data("location")[jQuery("#custom-search-school").val()],
'height':'1015',
'async':true,
'host':'wufoo.com',
'header':'show',
'ssl':true}
zhrajom0iykure = new WufooForm(); zhrajom0iykure.initialize(options); zhrajom0iykure.display();
} // end customEmbedForm