console.info("--- STORE -----------------------------------------------");
console.info($ == undefined);
console.info($);
store = {
debug: (window.location.origin == "http://bs" || window.location.origin == "https://staging.scan2scan.com" || window.location.origin == "https://staging.bridescan.com"),
debugEventKey: (window.location.origin == "http://bs"),
ok: function () {
this._conf._eventKey = this.debugEventKey ? "development" : this._conf._eventKey;
var _ok = $("#store-" + this._conf._eventKey).length !== 0;
console.warn("##########################################################################################################");
console.warn("### EMBED STORE #store-" + this._conf._eventKey + " :: INIT-OK :: " + (_ok ? "OK" : "NOT OK "));
console.warn("##########################################################################################################");
return _ok;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
init: function () {
console.warn("##########################################################################################################");
console.warn("### EMBED STORE :: INIT :: IN ############################################################################");
console.info("#store-" + this._conf._eventKey + " :: " + $("#store-" + this._conf._eventKey).length);
console.info(this._conf);
console.info(this._eventInfo);
this.initialize();
console.warn("### EMBED STORE :: INIT :: OUT ###########################################################################");
console.warn("##########################################################################################################");
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
initialize: function () {
console.info("--- initialize :: -------------------------------------------------------");
$.each(this, function (k, v) {
if (k.indexOf("_") == 0) {
v["_root"] = "$store";
v["_eventKey"] = $store._conf._eventKey;
}
});
this._form._css_prefix_ = "str-";
this.css();
this._store.init(this._eventInfo);
this._comm._initialize();
this.renderStore();
this.next(true);
//------------------------------------------------------------
//--- DEBUG
//------------------------------------------------------------
if (this.debug) {
//this.renderCode();
var div = "
";
var html = "";
html += JSON.stringify(this._eventInfo, null, 2);
$("#atbta-debug-atbta").html(html);
}
//------------------------------------------------------------
//--- DEBUG
//------------------------------------------------------------
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
canNext: function (visible) {
switch (visible) {
case "tickets":
$store._store.update();
var ret = $store._store.hasQuantity();
if (!ret) {
this.renderError("Choose a quantity to purchase");
}
return ret;
case "info":
$store._store.update();
}
return true;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
next: function (initial) {
console.info("--- next" + (initial ? " :: " + initial : ""));
this.renderError();
var visible = $(".str-section:visible");
if (this.canNext(visible.data("store-section"))) {
var show = null;
var title = "";
console.info("--- next :: -" + visible.data("store-section") + "- :: " + (visible.data("store-section") == "completed"));
if ((visible.data("store-section") + "") == "completed" && initial != true) {
return;
}
switch (visible.data("store-section")) {
case "tickets":
if ($store._store.infos() == null) {
show = "cart";
title = "Checkout";
this.renderCart();
}
else {
show = "info";
title = "Provide Needed Info(s)";
this.renderInfo();
}
break;
case "info":
console.info("infos");
let _valid = this._form.validateUnique();
console.info(_valid);
if (_valid != "uniqueCheck") {
if (_valid == 1) {
show = "cart";
title = "Checkout";
this.renderCart();
}
else {
show = "info";
title = "Provide Needed Info(s)";
console.info(typeof _valid);
this.renderError(typeof _valid == "string" ? _valid : "Provide all required information before continuing.");
}
}
else {
return;
}
break;
case "cart":
title = "Thank You";
show = "completed";
this.renderCompleted();
break;
default:
show = "tickets";
title = $store._eventInfo.eventStoreButton;
break;
}
$("#str-navigation-title").html(title);
if ($(".str-section:visible").data("storeSection") != show) {
$(".str-section:visible").hide();
$("[data-store-section='" + show + "']").show();
if (initial !== true) {
this.scrollUp();
}
}
}
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
nextTo: function (show, title) {
$("#str-navigation-title").html(title);
if ($(".str-section:visible").data("storeSection") != show) {
$(".str-section:visible").hide();
$("[data-store-section='" + show + "']").show();
this.scrollUp();
}
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
back: function (from) {
console.info("back" + (from ? " :: " + from : ""));
this.renderError();
var visible = $(".str-section:visible");
var show = null;
var back = false;
var title = "";
var current = visible.data("store-section");
switch (from ? from : current) {
case "info":
case "code":
$store._store.update();
title = $store._eventInfo.eventStoreButton;
show = "tickets";
break;
case "codeCheckout":
$store._store.update();
if ($store._store.infos() == null) {
show = "cart";
title = "Checkout";
this.renderCart();
}
else {
show = "info";
title = "Provide Needed Info(s)";
this.renderInfo();
}
break;
case "cart":
if ($store._store.infos() == null) {
title = $store._eventInfo.eventStoreButton;
show = "tickets";
}
else {
show = "info";
title = "Provide Needed Info(s)";
back = true;
}
break;
case "payment":
show = "cart";
title = "Cart";
back = true;
break;
case "completed":
show = "payment";
title = "Payment";
back = true;
break;
default:
break;
}
if (show == "tickets") {
$store.renderTickets();
}
$("#str-navigation-title").html(title);
console.info(current + " :: " + show);
$(".str-section:visible").hide();
$("[data-store-section='" + show + "']").show();
this.scrollUp();
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStore: function () {
console.info("--- renderStore -------------------------------------------------------");
var html = "";
html += this.renderEvent();
html += this.renderNav();
html += this.renderTickets();
html += this.renderCode();
html += this.renderInfo();
html += this.renderCart();
html += this.renderCompleted();
this.content(html);
this.renderTickets();
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderEvent: function () {
return "
" + this._eventInfo.event.name + " Store
" + this._eventInfo.event.startDate + "
";
},
renderNav: function () {
var html = "
";
html += "
";
html += "
";
html += "
";
html += "
";
html += "";
return html;
},
renderError: function (msg) {
$("#str-error").hide();
if (msg) {
console.info(msg);
$("#str-error").html(msg);
$("#str-error").show();
this.scrollUp();
}
},
scrollUp: function () {
$([document.documentElement, document.body]).animate({scrollTop: $(".str-navigation").offset().top - 75}, 500);
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderTickets: function () {
if ($("[data-store-section='tickets']").length == 0) {
return "";
}
var isLocalhost = window.location.hostname == "localhost";
var innerHtml = "";
var innerHtmlGroup = "";
innerHtml += $store.renderStoreCodes();
var _groups = {}
var _groupNames = [];
$.each(this._eventInfo.products, function (i, ticket) {
if (ticket.hasOwnProperty("groupingName") && ticket.groupingName != null && ticket.groupingName.trim().length != 0) {
if (!_groups.hasOwnProperty(ticket.groupingName)) {
_groups[ticket.groupingName] = [];
_groupNames.push(ticket.groupingName);
}
_groups[ticket.groupingName].push(ticket);
}
else {
innerHtml += $store.renderStoreTicket(ticket, (isLocalhost ? 2 : 0));
}
});
if(_groupNames.length != 0) {
innerHtmlGroup += "
click groups below to show additional items
";
$.each(_groupNames.sort(), function (i, groupName) {
innerHtmlGroup += $store.renderStoreGroup(i, groupName, _groups[groupName]);
});
}
html = "
";
html += ($store._eventInfo.hasOwnProperty("codes") && $store._eventInfo.codes.length != 0 ? "
Have Promo Code? Click HERE first.
" : "");
html += "
choose quantity for each item and press continue
";
html += "
" + innerHtml + "
";
html += innerHtmlGroup;
html += ($store._eventInfo.hasOwnProperty("codes") && $store._eventInfo.codes.length != 0 ? "
Have Promo Code? Click HERE first.
" : "");
html += "";
html += $store.renderFbPixel("PageView", undefined, window.location.href);
html += "
";
$("[data-store-section='tickets']").html(html);
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStoreGroup: function (groupId, groupName, tickets) {
var cartQuantities = $store._storage.store("cart-quantities");
var innerHtml = "
" + groupName + "
";
var count = 0;
$.each(tickets, function (i, ticket) {
var id = ticket.eventProductId;
if (cartQuantities.hasOwnProperty(id)) {
count += cartQuantities[id];
}
innerHtml += $store.renderStoreTicket(ticket, 0);
});
innerHtml ="
" + innerHtml + "
";
return "
" + groupName + "
" +innerHtml;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStoreGroupShowHide: function (groupId, show) {
if (show) {
$("#grpc" + groupId).show();
$("#grp" + groupId).hide();
}
else {
$("#grpc" + groupId).hide();
$("#grp" + groupId).show();
}
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStoreTicket: function (ticket, index) {
console.info("--- renderStoreTicket :: " + ticket.name + " -------------------------------------------------------");
var html = "";
var symbol = $store._eventInfo.currency.symbol;
var max = ticket.maxPurchaseQuantity;
var oprice = ticket.price;
var price = ticket.price;
var discountCodes = $store._store.codes();
var discount = null;
var isAmount = true;
var upto = "";
$.each(discountCodes, function (key, discountCode) {
console.info(discountCode);
if (discount == null && discountCode.skipQuantities && (discountCode.haveProducts || (discountCode.exclusive == "EXCLUSIVE" && discountCode.discountCodeAmountType == "PERCENTAGE"))) {
if (discountCode.groups.length == 0) {
discount = discountCode.price;
isAmount = discountCode.discountCodeAmountType == "AMOUNT";
}
$.each(discountCode.groups, function (g, group) {
$.each(group.products, function (p, product) {
if (ticket.eventProductId == product.eventProductId) {
console.info(discountCode);
discount = discountCode.price;
isAmount = discountCode.discountCodeAmountType == "AMOUNT";
upto = (product.hasOwnProperty("maxQuantity") ? "(up to " + product.maxQuantity + " count)" : "");
}
});
});
}
});
if (price == undefined) {
var different = false;
$.each(ticket.variations, function (v, variation) {
if (price != undefined) {
different |= price != variation.price;
}
oprice = price = (price == undefined || parseFloat(price) > parseFloat(variation.price) ? variation.price : price);
if (variation.hasOwnProperty("maxPurchaseQuantity")) {
if (max == undefined || max > variation.maxPurchaseQuantity) {
max = variation.maxPurchaseQuantity;
}
}
});
var discountAmount = (discount != null ? (isAmount ? discount : price * discount / 100) : 0);
oprice = (different ? "from " : "") + symbol + oprice;
price = (different ? "from " : "") + symbol + parseFloat(price - discountAmount).toFixed(2);
}
else {
var discountAmount = (discount != null ? (isAmount ? discount : price * discount / 100) : 0);
oprice = symbol + oprice;
price = symbol + parseFloat(price - discountAmount).toFixed(2);
}
var quantityHtml = this._store.inputs.quantity(ticket.eventProductId, index + "", "str-item-quantity str-override", max);
html += "
";
html += "
";
html += "
" + ticket.name + "
";
html += "
" + (oprice != price ? upto + price + "
" + oprice + "
" : price) + quantityHtml + "
";
html += "
";
html += "
" + ticket.description + "
";
html += "
";
return html;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStoreCodes: function () {
var html = "";
var discountCodes = $store._store.codes();
$.each(discountCodes, function (key, discountCode) {
var code = undefined;
$.each($store._eventInfo.codes, function (i, c) {
if (c.code.toUpperCase() == key.toUpperCase()) {
code = c;
}
});
if (code) {
html += $store.renderStoreCode(discountCode);
}
else {
delete discountCodes[key];
}
});
$store._store.codes(discountCodes);
return html;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderStoreCode: function (code) {
console.clear();
console.info("--- renderStoreCode ----------------------------------------");
console.info(code);
var symbol = $store._eventInfo.currency.symbol;
var html = "";
var price = 0.00;
var discount = 0.00;
var isAmount = code.discountCodeAmountType == "AMOUNT";
var isPercentage = code.discountCodeAmountType == "PERCENTAGE";
var isExclusive = code.exclusive == "EXCLUSIVE";
var isEach = code.applyTo == "EACH";
var isCollection = code.applyTo == "COLLECTION";
var isDefault = code.applyToType == "DEFAULT";
var isGroups = code.applyToType == "GROUPS";
var haveProducts = code.haveProducts;
$.each(code.groups, function (g, group) {
if (group.hasOwnProperty("count") && group.count > 0) {
if (group.hasOwnProperty("priceEach")) {
price += group.count * group.priceEach;
discount += group.count * group.discountAmountEach;
}
else {
$.each(group.products, function (p, product) {
if (product.hasOwnProperty("count")) {
price += group.count * product.count * product.priceEach;
discount += group.count * product.count * product.discountAmountEach;
}
});
}
}
});
var discountedPrice = "";
if (!haveProducts || code.skipQuantities) {
discountedPrice = (isAmount ? symbol : "") + code.price + (!isAmount ? "%" : "") + "
off" + (code.haveProducts ? " each" : "") + "
";
}
else {
discountedPrice = symbol + parseFloat(price - discount).toFixed(2);
}
html += "
";
if (isCollection || (isEach && isGroups)) {
var allStyle = "vertical-align: middle;font-size: 110%;";
var connectorStyle = allStyle + "font-size: 105%;padding: 0 5px;";
if (group.hasOwnProperty("discountPriceEach")) {
html += "
@
";
html += "
";
html += symbol + parseFloat(group.discountPriceEach).toFixed(2);
html += "
" + symbol + parseFloat(group.priceEach).toFixed(2) + "
";
html += "
";
}
html += "
x
";
html += "
" + group.count + "
";
}
html += "
";
skipQuantities |= code.skipQuantities;
}
});
html += "
IMPORTANT:" + (skipQuantities ? " Select quantities for the products listed below to add to the cart." : " Items listed above will be added to the cart IN ADDITION to those selected below.
");
html += "
";
}
html += "
";
html += "
";
html += "
";
html += this.renderCodeDebug(code);
return html;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderCode: function (code) {
var codeInput = (this.debug && false ? "P01" : "");
if ($("[data-store-section='code']").length == 0) {
return "";
}
var html = "";
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
if (code) {
console.clear();
console.info("--- renderCode ----------------------------------------");
console.info(code);
var haveCodes = false;
var haveExclusiveCode = false;
$.each($store._store.codes(), function (c, _code) {
haveCodes = true;
haveExclusiveCode |= _code.exclusive == "EXCLUSIVE";
});
code.price = parseFloat(code.price);
code["skipQuantities"] = false;
code["haveProducts"] = false;
$.each(code.groups, function (g, group) {
code.haveProducts |= group.products.length != 0;
});
var symbol = $store._eventInfo.currency.symbol;
var isAmount = code.discountCodeAmountType == "AMOUNT";
var isPercentage = code.discountCodeAmountType == "PERCENTAGE";
var isExclusive = code.exclusive == "EXCLUSIVE";
var isEach = code.applyTo == "EACH";
var isCollection = code.applyTo == "COLLECTION";
var isDefault = code.applyToType == "DEFAULT";
var isGroups = code.applyToType == "GROUPS";
var haveProducts = code.haveProducts;
var canAddDiscountCode = !haveCodes || (isExclusive && !haveCodes) || (!haveExclusiveCode && !isExclusive);
var discount = parseFloat(code.price);
if (canAddDiscountCode && (!haveProducts || (isEach && isDefault))) {
code.skipQuantities = (isExclusive && (haveProducts || (!haveProducts && isAmount)) ? false : true);
$store.processCode(code.code);
return;
}
html += "
";
html += (!canAddDiscountCode ? "
Promo code \"" + code.code + "\" cannot be used with other promo codes in the cart.
" : "");
html += "
";
html += "
";
html += "
" + code.code.toUpperCase() + (isExclusive ? "EXCLUSIVE, cannot be used with any other offer" : "") + "
";
// ##############################################################################################################################
// ##############################################################################################################################
if (code.haveProducts) {
html += "
";
$.each(code.groups, function (g, group) {
html += (g != 0 && isCollection ? "
- OR -
" : "");
html += "
";
var totalGroupPrice = 0.0;
$.each(group.products, function (p, product) {
$.each($store._eventInfo.products, function (j, eventProduct) {
if (eventProduct.eventProductId == product.eventProductId) {
totalGroupPrice += $store.productPrice(eventProduct) * product.quantity;
}
});
});
// ##########################################################################################################################
// ##########################################################################################################################
if (isGroups || isCollection) {
var discountAmount = (isPercentage ? totalGroupPrice * code.price / 100 : code.price);
var discountPrice = totalGroupPrice - discountAmount;
group["priceEach"] = totalGroupPrice;
group["discountPriceEach"] = discountPrice;
group["discountAmountEach"] = discountAmount;
html += "
";
$.each(group.products, function (p, product) {
$.each($store._eventInfo.products, function (j, eventProduct) {
if (eventProduct.eventProductId == product.eventProductId) {
html += "
";
});
}
// ##############################################################################################################################
// ##############################################################################################################################
html += "
";
html += "
";
html += "
";
html += "
";
html += "";
html += ((isExclusive && isGroups) || !canAddDiscountCode ? "" : "");
html += "
";
//------------------------------------------------------------
//--- DEBUG
//------------------------------------------------------------
html += this.renderCodeDebug(code);
if (this.debugEventKey) {
html += "
HAVE CODES: " + haveCodes + " :: HAVE EXCLUSIVE CODES: " + haveExclusiveCode + " :: IS EXCLUSIVE: " + isExclusive + " :: CAN ADD DISCOUNT: " + canAddDiscountCode + "
";
html += "
" + JSON.stringify(code, null, 2) + "
";
}
//------------------------------------------------------------
//--- DEBUG
//------------------------------------------------------------
$("#str-navigation-title").html("Promo Code - " + code.code.toUpperCase());
$("[data-store-section='code']").html(html);
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
else {
if (this.debug) {
var btns = {};
var abtns = [];
$.each($store._eventInfo.codes, function (i, __code) {
btns[__code.code] = "";
abtns.push(__code.code);
});
abtns.sort();
html += "";
html += "";
html += "";
}
else {
html += "
enter your promo code below and press continue
";
html += "";
html += "";
}
$("#str-navigation-title").html("Promo Code");
$("[data-store-section='code']").html(html);
$(".str-section:visible").hide();
$("[data-store-section='code']").show();
$("#str-code").focus();
if (codeInput.length > 0) {
$store.processCode();
}
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
},
renderCodeDebug: function (code) {
var html = "";
if (this.debugEventKey) {
html = "
";
html += " " + (code.haveProducts ? "PRODUCTS" : "NO PRODUCTS") + " :: ";
html += " " + (code.skipQuantities ? "SKIP" : "NO SKIP") + " :: ";
html += " " + code.exclusive + " :: ";
html += " " + code.discountCodeAmountType + " :: ";
html += " " + code.applyTo + " :: ";
html += " " + code.applyToType + "";
html += "
";
}
return html;
},
clickCode: function (_code) {
$("#str-code").val(_code);
$store.processCode();
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
productPrice: function (product) {
var different = false;
var symbol = $store._eventInfo.currency.symbol;
var price = product.price;
if (price == undefined) {
$.each(product.variations, function (v, variation) {
if (price != undefined) {
different |= price != variation.price;
}
price = (price == undefined || parseFloat(price) > parseFloat(variation.price) ? variation.price : price);
});
}
return price;
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
processCode: function (_code, _groupid) {
this.renderError();
// ##########################################################################################################################
// ##########################################################################################################################
if (_code) {
var haveGroupCount = false;
var haveProductCounts = false;
var haveProducts = false;
var skipQuantityCheck = false;
console.clear();
console.info("--- processCode :: CODE ----------------------------------------");
console.info(_code);
console.info(_groupid);
$.each($store._eventInfo.codes, function (i, __code) {
if (__code.code == _code) {
var code = JSON.parse(JSON.stringify(__code));
var discountCodes = $store._store.codes();
console.info(discountCodes);
console.info(code);
var isAmount = code.discountCodeAmountType == "AMOUNT";
var isPercentage = code.discountCodeAmountType == "PERCENTAGE";
var isExclusive = code.exclusive == "EXCLUSIVE";
var isEach = code.applyTo == "EACH";
var isCollection = code.applyTo == "COLLECTION";
var isDefault = code.applyToType == "DEFAULT";
var isGroups = code.applyToType == "GROUPS";
haveProducts = code.haveProducts == 1;
console.info(code.haveProducts);
discountCodes[_code] = code;
if (!haveProducts || (isEach && isDefault)) {
console.info("--- SKIP QUANTITY CHECK ---");
skipQuantityCheck = true;
}
else {
if (isExclusive) {
$.each(code.groups, function (g, group) {
if (_groupid == undefined || _groupid == group.eventDiscountCodeGroupId) {
group["count"] = 1;
haveGroupCount = true;
$.each(group.products, function (p, product) {
product["count"] = product.quantity;
haveProductCounts = true;
});
}
else {
delete group["count"];
}
});
}
else {
$.each(code.groups, function (g, group) {
console.info("\t--- GROUP " + g + " -----------------------");
console.info(group);
var groupCount = $("[data-form-item-id='g-" + group.eventDiscountCodeGroupId + "']").html();
if (!isNaN(groupCount)) {
groupCount = parseInt(groupCount);
group["count"] = parseInt(groupCount);
haveGroupCount |= group.count > 0;
}
$.each(group.products, function (p, product) {
console.info("\t\t--- PRODUCT " + product.eventProductId + "-----------------------");
if (haveGroupCount) {
product["count"] = product.quantity;
haveProductCounts = true;
}
else {
var productCount = $("[data-form-item-id='p-" + product.eventProductId + "']").html();
if (!isNaN(productCount)) {
productCount = parseInt(productCount);
if (productCount > 0) {
product["count"] = (product.hasOwnProperty("maxQuantity") && product.maxQuantity < productCount ? product.maxQuantity : productCount);
haveProductCounts = true;
}
}
}
if (product.hasOwnProperty("count") && !group.hasOwnProperty("count")) {
group["count"] = 1;
}
});
});
}
}
$store._store.codes(discountCodes);
}
});
console.info("HAVE GROUPS: " + haveGroupCount + " HAVE PRODUCTS: " + haveProducts + " :: HAVE PRODUCT COUNT: " + haveProductCounts);
if (!haveProducts || (haveProductCounts && haveGroupCount) || skipQuantityCheck) {
$("[data-store-section='code']").html("");
$store.back(haveProducts ? "code" : "code");
}
else {
this.renderError("Make the necessary quantity choices prior to proceeding.");
}
}
// ##########################################################################################################################
// ##########################################################################################################################
else {
console.info("--- processCode :: INPUT ----------------------------------------");
var val = $("#str-code").val().toUpperCase();
var code = null;
$.each($store._eventInfo.codes, function (i, c) {
if (c.code.toUpperCase() == val) {
code = c;
}
});
if (code != null) {
$store.renderCode(code);
return;
}
this.renderError("The promo code you entered is not valid.");
}
// ##########################################################################################################################
// ##########################################################################################################################
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
clearCode: function (code) {
var codes = $store._store.codes();
delete codes[code];
$store._store.codes(codes);
$("[data-store-section='code']").html("");
$store.back("code");
},
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
renderInfo: function () {
if ($("[data-store-section='info']").length == 0) {
return "";
}
console.info("--- renderInfo ----------------------------------------");
var symbol = $store._eventInfo.currency.symbol;
var accountInfos = this._storage.store("accountInfos");
var infos = this._store.infos();
var html = "
specify information for each ticket below
";
html += "
" + this._form.required() + "
";
$.each(infos, function (ii, info) {
html += "
";
for (var i = 0; i < info.quantity; i++) {
var price = info.price;
var different = false;
var accountInfo = accountInfos[info.eventProductId];
accountInfo = (accountInfo && accountInfo.length > i ? accountInfo = accountInfo[i] : null);
if (info.variations) {
$.each(info.variations, function (v, variation) {
if (variation.price) {
if (price != undefined) {
different |= price != variation.price;
}
else {
price = variation.price;
}
}
});
$.each(info.variations, function (v, variation) {
price = (price == undefined || price > variation.price ? variation.price : price);
});
}
price = (different ? "from " : "") + symbol + price;
html += "
";
if (info.variations) {
var options = null;
var value = (accountInfo && accountInfo["variation"] ? accountInfo["variation"] : "");
$.each(info.variations, function (v, variation) {
options += "";
});
html += "
You should receive a purchase receipt email within the next 5 minutes. If you do not, please check your Spam folder! Mark the email as safe if it landed there so your purchase details are easily accessible in your inbox for the event.
";
/*html += "
If you do not receive an email from us, please email info@bridescan.com for assistance.
Purchase guest admission tickets here! For engaged couples and their guests please use the tickets labeled \"Engaged Bride/Groom Ticket\".<\/em><\/strong><\/p>
Your emailed receipt is your ticket into the show.<\/strong><\/p>", "feeType": { "percentageAmountOther": "0.00", "percentageAmountType": "default", "dollarAmount": "1.50", "dollarAmountOther": "0.00", "name": "Default Ticket", "percentageAmount": "0.000", "percentageAmountOtherType": "default" }, "variations": [], "price": "0.00", "formName": "storeGuestInfo", "options": [], "eventProductId": 14297, "name": "General Admission Tickets", "productType": "Ticket" } ] },
_conf: { _uri:"https://www.bridescan.com", _authKey:"jmi", _eventKey:"chatt" },
_store: { init: function (storeInfo) { if (!this.initialized) { console.info("### STORE :: init :: --------------------------------------------------------------------------------------------------------------"); console.info(storeInfo); if (storeInfo.hasOwnProperty("paymentService")) { this["paymentService"] = (storeInfo.paymentService.name == "Stripe" ? this.stripe : this.paytheory); $("head").append(""); } $.each(storeInfo.products, function (i, p) { if (p.hasOwnProperty("variations") && p.variations.length == 0) { delete p.variations; } }); $store._storage.store("store-info", storeInfo); $store._storage.store("store", {}); if (!$store._storage.store("cart-quantities")) { $store._storage.store("cart-quantities", {}); } this["initialized"] = true; if (this.hasOwnProperty("paymentService")) { setTimeout(this.paymentService.init, 2000); } } }, update: function () { console.clear(); console.warn("---------------------------------------------------------------------"); console.info("### STORE :: update :: " + this._eventKey); var store = $store._storage.store("store"); var codes = $store._store.codes(); $("[data-store='" + this._eventKey + "']").each(function () { var id = $(this).data("formItemId"); var index = $(this).data("formItemIndex"); var name = $(this).data("formItemName"); var type = $(this).data("formItemType"); var val = $(this).val(); if (name == "quantity") val = $(this).html(); console.info(id + " :: " + index + " :: " + name + " :: " + type + " :: " + val); if (val != null && val != 0 && val.length == 0) val = null; if (!store.hasOwnProperty(id)) { store[id] = {id: id}; } if (index) { if (!store[id].hasOwnProperty("infos")) { store[id]["infos"] = {}; } if (!store[id].infos.hasOwnProperty(index)) { store[id].infos[index] = {}; } if (val) store[id].infos[index][name] = val; else delete store[id].infos[index][name]; } else { if (val) store[id][name] = (type == "number" ? parseInt(val) : val); else delete store[id][name]; } }); $.each(store, function (pid, storeProduct) { delete storeProduct["discountCode"]; delete storeProduct["discountCount"]; delete storeProduct["discountAmount"]; delete storeProduct["discountAmountType"]; }); $.each(codes, function (c, code) { console.info("-----------------------------"); console.info(code); if (code.groups.length == 0) { if (code.exclusive != "EXCLUSIVE" || code.discountCodeAmountType == "PERCENTAGE") { $.each(store, function (pid, storeProduct) { if (!storeProduct.hasOwnProperty("discountCount")) { storeProduct["discountCode"] = code.code; storeProduct["discountCount"] = storeProduct.quantity; storeProduct["discountAmount"] = code.price; storeProduct["discountAmountType"] = code.discountCodeAmountType; } }); } } else { $.each(code.groups, function (c, group) { if ((group.hasOwnProperty("count") && group.count > 0) || code.skipQuantities) { $.each(group.products, function (c, product) { if ((product.hasOwnProperty("count") && product.count > 0) || code.skipQuantities) { if (code.skipQuantities) { if (store.hasOwnProperty(product.eventProductId)) { if (store[product.eventProductId].quantity > 0) { store[product.eventProductId]["discountCode"] = code.code; store[product.eventProductId]["discountCount"] = (product.hasOwnProperty("maxQuantity") && product.maxQuantity < store[product.eventProductId].quantity ? product.maxQuantity : store[product.eventProductId].quantity); store[product.eventProductId]["discountAmount"] = code.price; store[product.eventProductId]["discountAmountType"] = code.discountCodeAmountType; group["count"] = 1; product["count"] = store[product.eventProductId]["discountCount"]; } } } else { store[product.eventProductId].quantity += product.count * group.count; } } }); } }); } }); console.info("--- STORE -------------------------------"); console.info(store); console.info(codes); console.info("--- STORE -------------------------------"); $store._storage.store("store", store); $store._store.codes(codes); accountInfos = {}; $.each(store, function (i, item) { if (item.hasOwnProperty("infos")) { $.each(item.infos, function (i, info) { var accountInfo = JSON.parse(JSON.stringify(info)); if (!accountInfos.hasOwnProperty(item.id)) { accountInfos[item.id] = []; } accountInfos[item.id].push(accountInfo); }); } }); if (Object.keys(accountInfos).length > 0) { console.info("--- ACCOUNT INFOS -------------------------------"); console.info(accountInfos); console.info("--- ACCOUNT INFOS -------------------------------"); $store._storage.store("accountInfos", accountInfos); } console.warn("---------------------------------------------------------------------"); }, infos: function () { var products = []; var storeInfo = $store._storage.store("store-info"); var store = $store._storage.store("store"); $.each(store, function (id, item) { if (item.quantity > 0) { var product = null; $.each(storeInfo.products, function (ip, p) { if (p.eventProductId == id) product = p; }); if (product && (product.hasOwnProperty("form") || product.hasOwnProperty("variations"))) { console.info(product); var p = {eventProductId: product.eventProductId, variationLabel: product.variationLabel, name: product.name, price: product.price, quantity: item.quantity, form: product.form}; if (product.hasOwnProperty("variations")) { p["variations"] = product.variations; } if (product.hasOwnProperty("options")) { p["options"] = product.options; } if (product.hasOwnProperty("uniqueAccount")) { p["uniqueAccount"] = product.uniqueAccount; } products.push(p); } } }); return (products.length != 0 ? products : null) }, codes: function (codes) { if (codes) $store._storage.store("store-codes", codes); return $store._storage.store("store-codes"); }, cart: function () { console.warn("---------------------------------------------------------------------------------------------------------"); console.warn("---------------------------------------------------------------------------------------------------------"); console.info("### STORE :: cart"); var cart = []; var storeInfo = $store._storage.store("store-info"); var store = $store._storage.store("store"); $.each(store, function (id, item) { var product = null; $.each(storeInfo.products, function (ip, p) { if (p.eventProductId == id) product = p; }); if (product) { console.warn("- - - - - -"); console.info(item); console.info(product); var usedDiscount = 0; var availableDiscount = (item.hasOwnProperty("discountCount") ? item.discountCount : 0); var discountAmount = (item.hasOwnProperty("discountAmount") ? item.discountAmount : null); var isDiscountAmount = item.discountAmountType == "AMOUNT"; var discountCode = (item.hasOwnProperty("discountCode") ? "" + item.discountCode + "" : ""); for (var i = 0; i < item.quantity; i++) { var variation = null; var info = null; var optionsTotal = 0.0; var productOptionsInfos = []; if (item.hasOwnProperty("infos") && item.infos.hasOwnProperty(i + 1)) { info = item.infos[i + 1]; if (product.variations) { $.each(product.variations, function (iv, v) { if (v.eventProductVariationId == info.variation) { variation = v; } }); } if (product.options) { var auxs = []; $.each(product.options, function (io, o) { if (info.hasOwnProperty(o.eventProductId)) { if (o.variations) { $.each(o.variations, function (iv, v) { if (v.eventProductVariationId == info[o.eventProductId] && v.hasOwnProperty("price")) { optionsTotal += parseFloat(v.price); productOptionsInfos.push({label: v.name, price: v.price}); auxs.push({"id": o.eventProductId, "value": info[o.eventProductId], "ordering": io}); } }); } else { productOptionsInfos.push({label: info[o.eventProductId]}); auxs.push({"id": o.eventProductId, "value": info[o.eventProductId], "ordering": io}); } } }); info["infos"] = [{auxs: auxs}]; } } var productTotal = parseFloat(variation ? variation.price : product.price) + optionsTotal; var discount = (discountAmount != null && usedDiscount < availableDiscount ? (isDiscountAmount ? discountAmount : productTotal * discountAmount / 100) : 0.00); var code = (discountAmount != null && usedDiscount < availableDiscount ? discountCode : ""); var price = productTotal - discount; var dollarAmount = parseFloat(product.feeType.dollarAmount); var cartItem = {id: "p" + id + "-" + i, eventProductId: id, name: code + product.name + (variation ? " - " + variation.name : ""), price: price, priceOriginal: productTotal, symbol: storeInfo.currency.symbol, quantity: 1, fee: (dollarAmount + ((price + (product.feeType.percentageAmountType == "onFeeAmount" ? dollarAmount : 0.00)) * parseFloat(product.feeType.percentageAmount))), productOptionsInfos: productOptionsInfos}; if (info) { var accountFields = ",name,companyName,contactName,emailAddress,phoneNumber,mobilePhoneNumber,streetAddress1,streetAddress2,city,state,country,zip,"; var attributes = {}; $.each(info, function (field, value) { if (accountFields.indexOf("," + field + ",") == -1 && field != "infos") { attributes[field] = value; } }); if (Object.keys(attributes).length != 0) { info["attributes"] = attributes; } cartItem["accountInfo"] = info; if (info.hasOwnProperty("variation")) { cartItem["eventProductVariationId"] = info.variation; var variationDollarAmount = parseFloat(variation.feeType ? variation.feeType.dollarAmount : product.feeType.dollarAmount); cartItem.fee = (variationDollarAmount + ((price + (product.feeType.percentageAmountType == "onFeeAmount" ? variationDollarAmount : 0.00)) * parseFloat(variation.feeType ? variation.feeType.percentageAmount : product.feeType.percentageAmount))); delete info.variation; } } cart.push(cartItem); usedDiscount++; } } }); console.warn("-------------------------------------------------------"); console.info(cart); console.warn("---------------------------------------------------------------------------------------------------------"); console.warn("---------------------------------------------------------------------------------------------------------"); return cart; }, processPurchase: function (token) { console.clear(); console.warn("---------------------------------------------------------------------"); console.warn("--- processPurchase"); console.info("### STORE :: processPurchase :: " + token); var subtotal = 0.0; var fee = 0.0; var cart = $store._store.cart(); var json = {eventId: $store._eventInfo.event.eventId, name: $("[data-form-item-id='paymentInfo-name']").val(), emailAddress: $("[data-form-item-id='paymentInfo-emailAddress']").val(), phoneNumber: $("[data-form-item-id='paymentInfo-phoneNumber']").val(), paymentType: 1, products: [], eventDiscountCodes: []}; if (token) { json["paymentServiceToken"] = token; } $.each(cart, function (index, item) { var product = JSON.parse(JSON.stringify(item)); delete product.fee; delete product.id; delete product.name; delete product.price; delete product.symbol; json.products.push(product); subtotal += item.price; fee += item.fee; }); $.each($store._store.codes(), function (c, code) { var _code = {eventDiscountCodeId: code.eventDiscountCodeId, groups: []}; $.each(code.groups, function (g, group) { if (group.hasOwnProperty("count") && group.count > 0) { var _group = {eventDiscountCodeGroupId: 0, count: group.count, products: []}; if (group.hasOwnProperty("eventDiscountCodeGroupId")) { _group["eventDiscountCodeGroupId"] = group.eventDiscountCodeGroupId; } $.each(group.products, function (p, product) { if (product.hasOwnProperty("count") && product.count > 0) { _group.products.push({eventProductId: product.eventProductId, count: product.count}); } }); _code.groups.push(_group); } }); json.eventDiscountCodes.push(_code); }); json["total"] = parseFloat($store._storage.store("store-totals").total).toFixed(2); console.info(json); if (token != "-bob-") { $store._comm._post("/api/embedPurchase", json); } console.warn("--- processPurchase"); console.warn("---------------------------------------------------------------------"); }, quantity: function (id, val, inc, max) { var products = $store._eventInfo.products; var product = null; $.each(products, function (i, p) { if (p.eventProductId == id) { product = p; } }); var cartQuantities = $store._storage.store("cart-quantities"); if (!cartQuantities.hasOwnProperty(id)) { cartQuantities[id] = val; } var o = cartQuantities[id]; cartQuantities[id] += inc; cartQuantities[id] = max !== undefined && max > 0 && cartQuantities[id] > max ? max : cartQuantities[id]; cartQuantities[id] = cartQuantities[id] < 0 ? 0 : cartQuantities[id]; var n = cartQuantities[id]; if (o < n) $store._store.activity.record("AddToCart", product.name); if (o > n) $store._store.activity.record("RemoveFromCart", product.name); $store._storage.store("cart-quantities", cartQuantities); $("[data-form-item-id='" + id + "']").html(cartQuantities[id]); }, hasQuantity: function () { var store = $store._storage.store("store"); var ret = false; $.each(store, function (key, item) { ret |= item.quantity > 0; }); var codes = $store._store.codes(); $.each(codes, function (c, code) { $.each(code.groups, function (g, group) { ret |= group.hasOwnProperty("count") && group.count > 0; }); }); return ret; }, inputs: { number: function (id, val, cls, max) { return ""; }, quantity: function (id, val, cls, max, ro) { var cartQuantities = $store._storage.store("cart-quantities"); if (cartQuantities.hasOwnProperty(id)) { val = cartQuantities[id]; } var txt = "
"; if (ro !== true) txt += "
" + $store._svg.minus + "
"; txt += "
" + val + "
"; if (ro !== true) txt += "
" + $store._svg.plus + "
"; txt += "
"; return txt; }, choice: function (id, index, options, cls, key) { return ""; } }, activity: { record: function (auxLogTypeAction, comment, record) { var json = {eventId: $store._eventInfo.event.eventId, auxLogTypeAction: auxLogTypeAction, comment: comment, uniqueId: $store._store.activity.getUniqueId()}; var params = new URLSearchParams(window.location.search); if (params.get("fbclid") != null) { json["fbclid"] = params.get("fbclid"); } if (record != undefined) { json["record"] = record; } $store._comm._postAction("/api/embedStoreActivity", json); }, getUniqueId: function () { var uniqueIdJson = $store._storage.store("_app_aux_log_id"); if (uniqueIdJson == null || uniqueIdJson == undefined || uniqueIdJson.uniqueId == null || uniqueIdJson.uniqueId == undefined) { uniqueId = ""; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for (var i = 0; i < 10; i++) { uniqueId += characters.charAt(Math.floor(Math.random() * charactersLength)); } $store._storage.store("_app_aux_log_id", {"uniqueId":"EM_" + uniqueId + "-" + new Date().getTime()}); } return $store._storage.store("_app_aux_log_id").uniqueId; }, clearUniqueId: function () { $store._storage.store("_app_aux_log_id", null); } }, paytheory: { init: function () { console.warn("### STORE :: PAYTHEORY :: INIT"); $store["paytheory"] = window.paytheory }, render: function () { console.info("### STORE :: PAYTHEORY :: RENDER"); var html = "
"; html += " "; html += " "; html += " "; html += " "; html += "
"; return html; }, populate: function () { console.warn("### STORE :: PAYTHEORY :: POPULATE"); $store.paytheory.payTheoryFields({apiKey: $store._storage.store("store-info").paymentService.apiKey}); }, token: async function () { console.warn("### STORE :: PAYTHEORY :: TOKEN"); var name = $("[data-form-item-id='paymentInfo-name']").val(); var emailAddress = $("[data-form-item-id='paymentInfo-emailAddress']").val(); var phoneNumber = $("[data-form-item-id='paymentInfo-phoneNumber']").val(); console.info(name + " :: " + emailAddress + " :: " + phoneNumber); var firstName = name; var lastName = name; if (name.split(" ").length > 1) { firstName = name.split(' ').slice(0, -1).join(' '); lastName = name.split(' ').slice(-1).join(' '); } const TOKENIZE_PAYMENT_METHOD_PARAMETERS = { payorInfo: { "first_name": firstName, "last_name": lastName, "email": emailAddress, "phone": phoneNumber } }; let result = await $store.paytheory.tokenizePaymentMethod(TOKENIZE_PAYMENT_METHOD_PARAMETERS); console.info(result); if (result.type === "TOKENIZED") { $store._store.processPurchase(result.body.payment_method_id); } else if (result.type === "ERROR") { $("#str-message-payment").hide(); $("#str-buttons-payment").show(); $store.renderError("Processing of your payment did not succeed. Please verify your payment information and try again."); } } }, stripe: { init: function () { console.warn("### STORE :: STRIPE :: INIT"); var paymentService = $store._storage.store("store-info").paymentService; try { if (paymentService.hasOwnProperty("uid")) { $store["stripe"] = Stripe(paymentService.publicKey, {"stripeAccount": paymentService.uid}); } else { $store["stripe"] = Stripe(paymentService.publicKey); } } catch (e) { /*setTimeout(this.initStripe, 1000);*/ } }, render: function () { console.warn("### STORE :: STRIPE :: RENDER"); return ""; }, populate: function () { console.warn("### STORE :: STRIPE :: POPULATE"); if ($store.stripe) { if ($store.stripe.elements()) { var style = {base: {color: '#32325d', fontFamily: '"Helvetica Neue", Helvetica, sans-serif', fontSmoothing: 'antialiased', fontSize: '14px', '::placeholder': {color: '#aab7c4'}}, invalid: {color: '#fa755a', iconColor: '#fa755a'}}; var elements = $store.stripe.elements(); $store["card"] = elements.create('card', {style: style}); $store.card.mount('#card-element'); $store.card.addEventListener('change', function (event) { if (event.error) { $store.renderError(event.error.message); } }); } } }, token: function () { console.warn("### STORE :: STRIPE :: TOKEN"); var name = $("[data-form-item-id='paymentInfo-name']").val(); var emailAddress = $("[data-form-item-id='paymentInfo-emailAddress']").val(); var phoneNumber = $("[data-form-item-id='paymentInfo-phoneNumber']").val(); $store.stripe.createPaymentMethod({type: "card", card: $store.card, billing_details: {name: name, email: emailAddress, phone: phoneNumber}}).then(function (result) { if (result.error) { $("#str-message-payment").hide(); $("#str-buttons-payment").show(); $store.renderError(result.error.message); } else { $store._store.processPurchase(result.paymentMethod.id); } }); } } },
_form: { _css_prefix_: "", render: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return this[field.formPartType](id, index, field, value, datas,onblur); }, text: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return ""; }, email: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return ""; }, phone: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return ""; }, hidden: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return ""; }, date: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; return ""; }, choice: function (id, index, field, value, datas, onblur) { onblur = onblur !== undefined ? onblur : ""; var choices = ""; $.each(field.choices, function (i, c) { choices += ""; }); return ""; }, required: function () { return "required "; }, datas: function (id, index, field, datas) { var additionalDatas = ""; if (datas) { $.each(datas, function (k, v) { additionalDatas += "data-" + k + "='" + v + "' "; }) } return additionalDatas + "data-store='" + this._eventKey + "' " + "data-form-item-id='" + id + "' " + "data-form-item-lbl-id='" + id + "-" + (index ? index + "-" : "") + field.key + "' " + (index ? "data-form-item-index='" + index + "' " : "") + "data-form-item-name='" + field.key + (field.product ? "' data-form-item-product='" + field.product : "") + (field.name ? "' data-form-item-lbl='" + field.name : "") + "' data-form-item-type='" + field.formPartType + "' " + "data-form-item-required='" + field.required + "' " + "data-form-item-required-css='" + this._css_prefix_ + "form-item-required' " + (field.parentKey ? "data-form-item-parent='" + field.parentKey + "' " : "") + (field.parentChoiceKey ? "data-form-item-parent-value='" + field.parentChoiceKey + "' " : "") + "onkeyup=\"" + this._root + "._form.validate('" + id + "')\" " + "onchange=\"" + this._root + "._form.validate('" + id + "')\""; }, lbldatas: function (id, index, field) { return " data-form-lbl-id='" + id + "-" + (index ? index + "-" : "") + field.key + "' "; }, validate: function (iid) { var _valid = true; $("[data-store='" + $store._form._eventKey + "']").each(function () { var parentKey = $(this).data("formItemParent"); var parentValue = $(this).data("formItemParentValue") + ""; var index = $(this).data("formItemIndex"); if (parentKey != null) { var parent = $("[data-store='" + $store._form._eventKey + "'][data-form-item-name='" + parentKey + "']" + (index ? "[data-form-item-index='" + index + "']" : "") + ":visible"); var value = parent.val() + ""; if (parent.length == 0 || value != parentValue) { $(this).hide(); $("[data-form-lbl-id='" + $(this).data("formItemLblId") + "']").hide(); } else { $(this).show(); $("[data-form-lbl-id='" + $(this).data("formItemLblId") + "']").show(); } } }); $("[data-store='" + $store._form._eventKey + "']:visible").each(function () { var id = $(this).data("formItemId"); var val = $(this).val(); var name = $(this).data("formItemName"); var type = $(this).data("formItemType"); var required = $(this).data("formItemRequired"); var requiredCss = $(this).data("formItemRequiredCss"); if (iid == undefined || (iid != undefined && (iid == id))) { $(this).removeClass(requiredCss); valid = true; if (id && required && !val) { valid = false; } if (val) { switch (type) { case "email": valid = $store._form.validateEmailAddress(val); break; case "phone": valid = $store._form.validatePhone(val); break; } switch (name) { case "state": valid = $store._form.validateState(val); break; case "zip": valid = $store._form.validateZip(val); break; } } _valid &= valid; if (!valid) $(this).addClass(requiredCss); } }); return _valid; }, validateUnique: function (iid) { var _valid = this.validate(); if (_valid) { var uniques = {}; var duplicates = false; $("[data-unique]").each(function () { console.info($(this).data()); if (!uniques.hasOwnProperty($(this).val())) { uniques[$(this).val()] = $(this).data("formItemId"); } else { duplicates = true; _valid = "Only one " + $(this).data("formItemProduct") + " per " + $(this).data("formItemLbl") + " can be purchased."; } }); if (!duplicates) { var emailsProducts = []; $.each(uniques, function (email, eventProductId) { emailsProducts.push({emailAddress: email, eventProductId: eventProductId}); }); if (emailsProducts.length != 0) { $store._comm._post("/api/purchasedProductCheck", emailsProducts); return "uniqueCheck"; } } } return _valid; }, validateEmailAddress: function (value) { return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value); }, validatePhone: function (value) { return /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im.test(value); }, validateState: function (value) { return /^(A[BLKSZRAEP]|BC|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ABDEHINOPST]|N[BCDEHJLMVSY]|O[NHKR]|P[AERW]|QC|RI|S[CDK]|T[NX]|UT|V[AIT]|W[AIVY])$/.test(value); }, validateZip: function (value) { return /^[0-9A-Z -]{1,10}$/.test(value); } },
_storage: { store: function (key, value) { if (window.localStorage) { if (key !== undefined) { if (value !== undefined) { if (value != null) { value = JSON.stringify(value); window.localStorage[this._eventKey + "-" + key] = value; if (window.localStorage[this._eventKey + "-" + key] != value) alert("SYSTEM ERROR: Unable to store local data!!!"); return window.localStorage[this._eventKey + "-" + key] == value; } else { delete window.localStorage[this._eventKey + "-" + key]; } } else { if (window.localStorage[this._eventKey + "-" + key]) { return JSON.parse(window.localStorage[this._eventKey + "-" + key]); } return {}; } } } } },
_comm: { _uri: "https://www.bridescan.com", _initialize: function () { $("body") .append("") .append("") .append("") .append("") .append(""); for (var i = 0; i < 20; i++) { $("body").append(""); } }, _get: function (url) { url = this._uri + (url.indexOf("/") == 0 ? "" : "/") + url; $("#comm-" + this._eventKey.toLowerCase() + "-form-get").attr("action", url); $("#comm-" + this._eventKey.toLowerCase() + "-form-get").submit(); }, _post: function (url, json) { console.info("------ _post :: " + url); url = this._uri + (url.indexOf("/") == 0 ? "" : "/") + url; var ljson = JSON.stringify(json); $("#comm-" + this._eventKey.toLowerCase() + "-form-post").attr("action", url); $("#comm-" + this._eventKey.toLowerCase() + "-form-post-json").val(ljson); $("#comm-" + this._eventKey.toLowerCase() + "-form-post").submit(); }, _postAction: function (url, json) { console.info("------ _postAction :: " + url); if (!$store.hasOwnProperty("_postActionIndex")) { $store["_postActionIndex"] = 0; } var index = $store["_postActionIndex"] % 20; url = this._uri + (url.indexOf("/") == 0 ? "" : "/") + url; var ljson = JSON.stringify(json); var eventKey = this._eventKey.toLowerCase(); $("#comm-" + eventKey + "-form-post-action-" + index).attr("action", url); $("#comm-" + eventKey + "-form-post-action-json-" + index).val(ljson); var f = function () { console.info("_postAction :: " + index + " :: " + url + " :: SUBMIT"); $("#comm-" + eventKey + "-form-post-action-" + index).submit(); }; setTimeout(f, index * 750); $store["_postActionIndex"]++; } },
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
// @formatter:on
_xyz: {}
};
if ($ == undefined) {
$ = jQuery.noConflict();
}
$(function () {
if (store.ok()) {
eval("window.$store = store").init();
}
});
window.addEventListener("message", function (event) {
if (typeof event.data === "string") {
var parts = event.data.replace(/(<([^>]+)>)/ig, "").split("::");
if (parts.length == 2) {
var type = parts[0];
var data = JSON.parse(parts[1]);
$store.data(type, data);
}
}
});
console.info("--- STORE -----------------------------------------------");