
$(function() {
$(document).on("click", "#save_account", function () {
if ($(this).prop("checked")) {
$("#_account_label_row").removeClass("hidden");
} else {
$("#_account_label_row").addClass("hidden");
}
});
$("#account_id").data("swipe_string", "");
$("#payment_method_id").data("swipe_string", "");
$("#account_id,#payment_method_id").keypress(function (event) {
var thisChar = String.fromCharCode(event.which);
if ($(this).data("swipe_string") != "") {
if (event.which == 13) {
processMagneticData($(this).data("swipe_string"));
$(this).data("swipe_string", "");
} else {
$(this).data("swipe_string", $(this).data("swipe_string") + thisChar);
}
return false;
} else {
if (thisChar == "%") {
$(this).data("swipe_string", "%");
setTimeout(function () {
if ($(this).data('swipe_string') == "%") {
$(this).data('swipe_string', "");
}
}, 3000);
return false;
} else {
return true;
}
}
});
$("#payment_method_id").change(function (event) {
$(".payment-method-logo").removeClass("selected");
$("#payment_method_logo_" + $(this).val()).addClass("selected");
calculateAdminFee();
return false;
});
$(document).on("click", "#add_admin_fee", function () {
calculateAdminFee();
});
$(".preset-amount").click(function () {
var amount = $(this).data("amount");
if (!empty(amount)) {
$("#amount").val(amount).trigger("change");
} else {
$("#amount").val("").focus();
}
return false;
});
$("#amount").change(function () {
$(this).data("entered_amount", $(this).val());
calculateAdminFee();
});
$("#same_address").click(function () {
if ($(this).prop("checked")) {
$("#_billing_address").hide();
$("#_billing_address").find("input,select").val("");
} else {
$("#_billing_address").show();
}
});
$("#create_user").click(function () {
if ($("#create_user").prop("checked")) {
$(".create-user").show();
} else {
$(".create-user").hide();
}
});
$("input[name=recurring_donation_type_id]").click(function () {
showRecurringStartDate();
});
$("select#recurring_donation_type_id").change(function () {
showRecurringStartDate();
});
$("#country_id").change(function () {
if ($(this).val() == "1000") {
$("#_state_row").hide();
$("#_state_select_row").show();
} else {
$("#_state_row").show();
$("#_state_select_row").hide();
}
}).trigger("change");
$("#billing_country_id").change(function () {
if ($(this).val() == "1000") {
$("#_billing_state_row").hide();
$("#_billing_state_select_row").show();
} else {
$("#_billing_state_row").show();
$("#_billing_state_select_row").hide();
}
}).trigger("change");
$("#state_select").change(function () {
$("#state").val($(this).val());
})
$("#billing_state_select").change(function () {
$("#billing_state").val($(this).val());
});
$("#payment_method_id").change(function () {
$(".payment-method-fields").hide();
if (!empty($(this).val())) {
var paymentMethodTypeCode = $(this).find("option:selected").data("payment_method_type_code");
$("#payment_method_" + paymentMethodTypeCode.toLowerCase()).show();
}
});
$("#user_name").change(function () {
if (!empty($(this).val())) {
$("#create_user").prop("checked", true);
$(".create-user").show();
loadAjaxRequest("/checkusername.php?ajax=true&user_name=" + $(this).val(), function (returnArray) {
$("#_user_name_message").removeClass("info-message").removeClass("error-message");
if ("info_user_name_message" in returnArray) {
$("#_user_name_message").html(returnArray['info_user_name_message']).addClass("info-message");
}
if ("error_user_name_message" in returnArray) {
$("#_user_name_message").html(returnArray['error_user_name_message']).addClass("error-message");
$("#user_name").val("");
$("#user_name").focus();
setTimeout(function () {
$("#_edit_form").validationEngine("hideAll");
}, 10);
}
});
} else {
$("#_user_name_message").val("");
}
});
$(document).on("tap click", "#copy_address", function () {
$("#_donor_info_section").find("input,select").each(function () {
if ($("#billing_" + $(this).attr("id")).length > 0) {
$("#billing_" + $(this).attr("id")).val($(this).val());
}
});
$("#billing_country_id").trigger("change");
return false;
});
$("#account_id").change(function () {
if (!empty($(this).val())) {
$("#_new_account").hide();
} else {
$("#_new_account").show();
}
});
$("#designation_code").keyup(function (event) {
if (event.which == 13 || event.which == 3) {
$(this).trigger("blur");
}
return false;
});
$(document).on("blur", "#designation_code", function () {
$("#designation_code_error").html("");
if ($("#designation_code").val() != "") {
loadAjaxRequest("/support?ajax=true&url_action=check_designation&designation_code=" + encodeURIComponent($(this).val()), function (returnArray) {
if ("error_message" in returnArray) {
$("#designation_code_error").html(returnArray['error_message']);
}
if ("designation" in returnArray) {
if ($("#designation_id").find("option[value=" + returnArray['designation']['designation_id'] + "]").length == 0) {
$("#designation_id").append($("<option></option>").attr("value", returnArray['designation']['designation_id']).text(returnArray['designation']['description']).data("merchant_account_id", returnArray['designation']['merchant_account_id']));
}
$("#designation_id").val(returnArray['designation']['designation_id']).trigger("change");
if ("tax_deductible_message" in returnArray['designation']) {
$("#tax_deductible_message").html(returnArray['designation']['tax_deductible_message']).removeClass("hidden");
} else {
$("#tax_deductible_message").addClass("hidden");
}
$("#designation_code").val("");
}
});
}
});
$(document).on("change", "#designation_id", function () {
if (accountIds == null) {
accountIds = new Array();
if ($("select#account_id").length > 0) {
$("select#account_id").find("option").each(function () {
if (!empty($(this).val())) {
var thisAccount = new Object();
thisAccount.account_id = $(this).val();
thisAccount.merchant_account_id = $(this).data("merchant_account_id");
thisAccount.text = $(this).text();
accountIds.push(thisAccount);
}
});
}
}
var designationId = $("#designation_id").val();
var merchantAccountId = "";
if ($("#designation_id").is("select")) {
merchantAccountId = $("#designation_id").find("option:selected").data("merchant_account_id");
} else {
merchantAccountId = $("#designation_id").data("merchant_account_id");
}
if (empty(merchantAccountId)) {
merchantAccountId = defaultMerchantAccountId;
}
$("#merchant_account_id").val(merchantAccountId);
if ($("select#account_id").length > 0) {
var saveAccountId = $("select#account_id").val();
$("select#account_id").find("option[value!='']").remove();
var foundAccountId = false;
for (var i in accountIds) {
if (merchantAccountId == accountIds[i].merchant_account_id) {
if (!empty(saveAccountId) && saveAccountId == accountIds[i].account_id) {
foundAccountId = true;
}
var thisOption = $("<option></option>").attr("value", accountIds[i].account_id).text(accountIds[i].text);
$("select#account_id").append(thisOption);
}
}
if (foundAccountId) {
$("#select#account_id").val(saveAccountId);
}
if ($("select#account_id").val() != "") {
$("#_new_account").hide();
} else {
$("#_new_account").show();
}
}
if (designationId == "") {
$("#_designation_code_row").show();
$("#_detailed_description_row").hide();
$("#_project_name_row").hide();
$("#_notes_row").hide();
return;
}
$("#_designation_code_row").hide();
$("#_detailed_description_row").hide();
loadAjaxRequest("/support?ajax=true&url_action=get_projects&designation_id=" + $(this).val(), function (returnArray) {
if ("tax_deductible_message" in returnArray) {
$("#tax_deductible_message").html(returnArray['tax_deductible_message']).removeClass("hidden");
} else {
$("#tax_deductible_message").addClass("hidden");
}
if ("detailed_description" in returnArray && returnArray['detailed_description'] != "") {
$("#_detailed_description_row").html(returnArray['detailed_description']).show();
}
var urlProject = getURLParameter("project");
var selectedProject = "";
if ("projects" in returnArray) {
$("#project_name").find("option[value!='']").remove();
for (var i in returnArray['projects']) {
if (!empty(urlProject) && urlProject == returnArray['projects'][i]) {
selectedProject = returnArray['projects'][i];
}
$("#project_name").append($("<option></option>").attr("value", returnArray['projects'][i]).text(returnArray['projects'][i]).data("inactive", "1"));
}
} else {
$("#_project_name_row").hide();
}
$("#project_name").val(selectedProject);
if ("project_label" in returnArray) {
$("#project_label").html(returnArray['project_label']);
} else {
$("#project_label").html("Project");
}
if ("project_required" in returnArray && returnArray['project_required'] && $("#project_name").find("option[value!='']").length > 0) {
$("#project_name").addClass("validate[required]");
$("#project_label").append("<span class='required-tag'>*</span>");
$("#no_project").html("[Select]");
} else {
$("#project_name").removeClass("validate[required]");
$("#no_project").html("[None]");
}
if ("memo_label" in returnArray) {
$("#notes_label").html(returnArray['memo_label']).attr("placeholder", returnArray['memo_label']);
}
if ("memo_required" in returnArray && returnArray['memo_required']) {
$("#notes").addClass("validate[required]");
$("#notes_label").append("<span class='required-tag'>*</span>");
} else {
$("#notes").removeClass("validate[required]");
}
checkProject();
calculateAdminFee();
});
});
$(document).on("tap click", "#_submit_form", function () {
if (empty(grecaptcha) || empty(grecaptcha.getResponse())) {
displayErrorMessage("Captcha invalid, please check \"I'm not a robot checkbox\".");
orderInProcess = false;
return false;
}
if ($("#_edit_form").validationEngine("validate")) {
$("#_submit_form").hide();
$("#_processing_paragraph").show();
loadAjaxRequest("/support?url_action=make_donation&ajax=true", $("#_edit_form").serialize(), function (returnArray) {
if ("error_message" in returnArray) {
$("#_submit_form").show();
return;
}
if ("response" in returnArray) {
$("#_donation_form").html(returnArray['response']);
$(".user-logged-in").remove();
$(".user-not-logged-in").remove();
$(".admin-logged-in").remove();
$(".admin-not-logged-in").remove();
scrollInView($("#_donation_form"));
if (typeof afterSubmitForm == "function") {
afterSubmitForm(returnArray);
}
} else {
$("#_submit_form").show();
}
}, function (returnArray) {
$("#_processing_paragraph").hide();
$("#_submit_form").show();
});
}
return false;
});
$("#designation_id").trigger("change");
$("#amount").trigger("change");
showRecurringStartDate();
$('.user-logged-in').remove();
$('.admin-logged-in').remove();
$('.super-logged-in').remove();
$('.development-server').remove();
$('.user-type-administrator,.user-type-cms,.user-type-donor services,.user-type-staff,.user-group-not-donor-services,.user-group-not-emails,.user-group-not-personnel,.user-group-not-site-developers,.user-group-not-training,.user-group-not-user-admin').remove();
if ("commaSeparatedProductCategoryCodes" in window) {
const productCategoryCodes = commaSeparatedProductCategoryCodes.toLowerCase().split(",");
$(".product-category").each(function() {
const productCategoryCode = $(this).data("product_category_code");
if (!empty(productCategoryCode) && !isInArray(productCategoryCode, productCategoryCodes)) {
$(this).remove();
}
});
}
if ("commaSeparatedProductDepartmentCodes" in window) {
const productDepartmentCodes = commaSeparatedProductDepartmentCodes.toLowerCase().split(",");
$(".product-department").each(function() {
const productDepartmentCode = $(this).data("product_department_code");
if (!empty(productDepartmentCode) && !isInArray(productDepartmentCode, productDepartmentCodes)) {
$(this).remove();
}
});
}
if ("commaSeparatedProductCategoryGroupCodes" in window) {
const productCategoryGroupCodes = commaSeparatedProductCategoryGroupCodes.toLowerCase().split(",");
$(".product-category-group").each(function() {
const productCategoryGroupCode = $(this).data("product_category_group_code");
if (!empty(productCategoryGroupCode) && !isInArray(productCategoryGroupCode, productCategoryGroupCodes)) {
$(this).remove();
}
});
}
});

var developmentServer = false;
var languageCode = "ENG";
var scriptFilename = "/support";
var userLoggedIn = false;
var adminLoggedIn = false;
var gWebUserId = "";
var gUserUid = "";
var gUserKey = "";
var thisIsAPublicWebsite = true;
gDefaultAjaxTimeout = "60000";
$(function() {
$(".logo").click(function() {
document.location = "https://www.ywamcos.org";
});
$('html').flowtype({
minimum   : 800,
maximum   : 1600,
minFont   : 14,
fontRatio : 90
});
$(window).resize(function() {
$("#_mobile_navbar_wrapper").removeClass("shown");
});
$(document).on("click","#_mobile_icon",function() {
$("#_mobile_navbar_wrapper").addClass("shown");
});
$(document).on("click","#_close_mobile_icon",function() {
$("#_mobile_navbar_wrapper").removeClass("shown");
});
});
$(window).on("load",function() {
$("#_body_wrapper").show();
});

var userIsLoggedIn = false;
var adminIsLoggedIn = false;
var loggedInUserTypeCode = '';
var loggedInUserGroupCodes = '';
var loggedInUserId = '';
var defaultMerchantAccountId = 1;
var accountIds = null;
function calculateAdminFee() {
const enteredAmount = $("#amount").data("entered_amount");
const designationId = $("#designation_id").val();
const paymentMethodId = $("#payment_method_id").val();
const accountId = $("#account_id").val();
if (!empty(enteredAmount)) {
let postData = { amount: enteredAmount, designation_id: designationId, payment_method_id: paymentMethodId, account_id: accountId };
$("body").addClass("no-waiting-for-ajax");
loadAjaxRequest("/support?ajax=true&url_action=get_admin_fee", postData, function (returnArray) {
let feeAmount = parseFloat(returnArray['fee_amount']);
if (empty(feeAmount) || isNaN(feeAmount) || feeAmount < 0) {
feeAmount = 0;
}
let feeMessage = ("fee_message" in returnArray ? returnArray['fee_message'] : "The admin fee on this donation is $" + RoundFixed(feeAmount, 2) + ".");
if (feeAmount > 0) {
$("#_add_admin_fee_row").removeClass("hidden");
$("#fee_message").add(".fee-message").html(feeMessage);
$("#fee_amount").add(".fee-amount").html(RoundFixed(feeAmount,2));
} else {
$("#_add_admin_fee_row").addClass("hidden");
$("#fee_message").html("");
$("#fee_amount").html("");
returnArray['fee_amount'] = 0;
}
if ($("#add_admin_fee").prop("checked")) {
$("#amount").val(RoundFixed(parseFloat(enteredAmount) + feeAmount, 2));
} else if (!empty(enteredAmount) && parseFloat(enteredAmount) != parseFloat($("#amount").val())) {
$("#amount").val(RoundFixed(enteredAmount, 2, true));
}
});
}
}
function showRecurringStartDate() {
if ($("select#recurring_donation_type_id").length > 0 && $("select#recurring_donation_type_id").val() == "") {
$("#_start_date_row").hide();
} else if ($("select#recurring_donation_type_id").length == 0 && $("input[name=recurring_donation_type_id]:checked").val() == "") {
$("#_start_date_row").hide();
} else {
$("#_start_date_row").show();
}
}
function checkProject() {
if ($("#project_name option").length > 1) {
$("#_project_name_row").show();
} else {
$("#_project_name_row").hide();
}
if ($("#notes_label").html() == "") {
$("#_notes_row").hide();
} else {
$("#_notes_row").show();
}
}
$(function() {
$("#_designation_code_row").remove().insertBefore("#_designation_id_row");
})
