$(document).ready(function () {
var radioBtns = "";
var totalStages = 3;
$('table[data-name="Personal Medical History"]').parent().hide();
$('table[data-name="Family Medical History"]').parent().hide();
$('table[data-name="Program Information"]').parent().hide();
$("#InsertButton").hide();
$(".actions").prepend('');
$("#stateDiv").hide();
$(".actions").prepend('');
$(".actions").prepend('');
$("#PreviousButton").hide();
$(".toolbar-row").remove();
$('#mzkdm_sexualpartners option[value="765670001"]').text('Male sexual partners');
$('#mzkdm_sexualpartners option[value="765670002"]').text('Female sexual partners');
$('#mzkdm_sexualpartners option[value="765670003"]').text('Both male and female sexual partners');
$("#mzkdm_visatype_label").hide();
$("#mzkdm_visatype").hide();
$("#mzkdm_timeremaininginus_label").hide();
$("#mzkdm_timeremaininginus").hide();
$('option[label="Select"]').html('');
$('option[label="Select"]').attr('label', '');
$('option[label="Select"]').attr('aria-label', '');
$("select").addClass("form-select");
//Change the text of Submit button to Apply Now
$('#InsertButton').val("Apply Now");
$("#mzkdm_immigrantvisa").change(function () {
var immigrantvisa = $("input[id*='mzkdm_immigrantvisa']:checked").val();
if (immigrantvisa == '1') {
$("#mzkdm_visatype").show();
$("#mzkdm_visatype_label").show();
$("#mzkdm_timeremaininginus_label").show();
$("#mzkdm_timeremaininginus").show();
}
else {
$("#mzkdm_visatype").hide();
$("#mzkdm_timeremaininginus").hide();
$("#mzkdm_visatype_label").hide();
$("#mzkdm_timeremaininginus_label").hide();
}
});
$("#mzkdm_usenicotineregularly_label").hide();
$("#mzkdm_usenicotineregularly").hide();
$("#mzkdm_frequencyofusage_label").hide();
$("#mzkdm_frequencyofusage").hide();
$("#mzkdm_currentlyusenicotinetobacco").change(function () {
var immigrantvisa = $("input[id*='mzkdm_currentlyusenicotinetobacco']:checked").val();
if (immigrantvisa == '1') {
$("#mzkdm_usenicotineregularly_label").show();
$("#mzkdm_usenicotineregularly").show();
$("#mzkdm_frequencyofusage_label").show();
$("#mzkdm_frequencyofusage").show();
}
else {
$("#mzkdm_usenicotineregularly_label").hide();
$("#mzkdm_usenicotineregularly").hide();
$("#mzkdm_frequencyofusage_label").hide();
$("#mzkdm_frequencyofusage").hide();
}
});
$("input[type='radio'][checked='checked']").removeAttr('checked');
$("#btnClosePopup").on("click", function () {
$("#MyPopup").modal("hide");
});
$("#mzkdm_weight").attr("title", "Numeric values only");
$("#address1_postalcode").attr("title", "Numeric values only");
// Optional: You can also use Bootstrap tooltips for a more customized appearance
// Add the following lines if you are using Bootstrap:
$("#mzkdm_weight").tooltip({ title: "Numeric values only", placement: "top" });
$("#address1_postalcode").tooltip({ title: "Numeric values only", placement: "top" });
$("#mobilephone").attr("placeholder", "XXX-XXX-XXXX");
$("#mobilephone").attr("maxlength", "12");
$("#address1_postalcode").attr("oninput", "this.value = this.value.replace(/[^0-9]/g, '')");
$("#mzkdm_weight").attr("oninput", "this.value = this.value.replace(/[^0-9.]/g, '')");
$("#mobilephone").on('input', function (e) {
if (e.target.value) {
const x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
e.target.value = +x[1] + (x[2] ? `-${x[2]}` : '') + (x[3] ? `-${x[3]}` : '');
}
});
// Function to check if any validation errors exist
function validateForm() {
var errorMessages = "";
// Perform custom validation
if ($("#mzkdm_location").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please choose the location you are applying to.";
}
if ($("#mzkdm_hearaboutourprogram").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm how your heard about our program?";
}
if ($('*input[id*=mzkdm_livecloseenough]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm your weekly availability.";
}
if ($('*input[id*=mzkdm_availabletovisitoneofourbranches]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm your availability for the next 9-12 months.";
}
if ($('*input[id*=mzkdm_donateduringregularofficehours]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm whether you will be available for regular office hours.";
}
if ($('*input[id*=mzkdm_receiveautomatedtextalerts]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm if you would like to receive automated text alerts.";
}
if ($('#mzkdm_hearaboutourprogram').val() === '765670009') {
if ($("#mzkdm_hearaboutourprogramreason").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please list the referral source where you heard about California Cryobank.";
}
}
if (errorMessages !== "") {
// Display the error messages in an alert or modal
$(".modal-body").html(errorMessages);
$("#MyPopup").modal("show");
return false;
}
// If no validation errors exist, return true to allow form submission
return true;
}
// Add click event listener to the submit button
$("#InsertButton").on("click", function () {
$("#ValidationSummaryEntityFormControl_7e07f1ca85dcee11904c000d3a346d85_EntityFormView").hide();
// Call the validateForm function to check for validation errors
if (!validateForm()) {
// If validation errors exist, return false to prevent form submission
return false;
}
// If no validation errors exist, allow form submission
// Optionally, you can perform additional actions here before allowing form submission
// SendMessage("Submit");
setLoaderTextAndShow("Submitting application");
return true;
});
$("#NextButton").on("click", function () {
var errorMessages = "";
if ($("#stateDiv").val() == "1") {
if ($("#firstname").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please enter your first name.";
}
if ($("#lastname").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please enter your last name.";
}
var today = new Date();
today.setHours(0, 0, 0, 0); // Set hours, minutes, seconds, and milliseconds to 0 for accurate comparison
// Get the entered date from the input field (assuming you have an input element with id "birthdate")
var enteredDate = new Date($("#birthdate").val());
var birthdateRegex = /^(0?[1-9]|1[0-2])\/(0?[1-9]|[12][0-9]|3[01])\/\d{4}$/;
if (enteredDate.getTime() > today.getTime()) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide a date less than or equal to today's date .";
}
else {
if (!birthdateRegex.test($("#birthdate_datepicker_description").val().trim())) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide your birthdate in the following format mm/dd/yyyy.";
}
}
var phoneRegex = /^\d{3}-\d{3}-\d{4}$/;
if (!phoneRegex.test($("#mobilephone").val().trim())) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide your phone number in the following format XXX-XXX-XXXX.";
}
if ($("#emailaddress1").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please enter your email address.";
}
else {
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test($("#emailaddress1").val().trim())) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide the email in the correct format";
}
}
var numericRegex = /^\d+(\.\d+)?$/;
if (!numericRegex.test($("#address1_postalcode").val().trim())) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please enter your zip code.";
}
var weightVal = $("#mzkdm_weight").val().trim();
var floatregix = /\b\d{2,3}(?:\.\d)?\b/g;
if (!floatregix.test($("#mzkdm_weight").val().trim()) || parseFloat(weightVal) < 0 || parseFloat(weightVal) > 500) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide a valid weight between 0 and 500 lbs.";
}
if ($("#mzkdm_height").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please select one of the available height options.";
}
if ($("#mzk_ethnicity").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please select your ethnicity.";
}
if ($("#mzkdm_educationlevel").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please select one of the education level options.";
}
if ($("#mzkdm_occupation").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please disclose your occupation.";
}
if ($('*input[id*=mzkdm_employmentauthorization]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm if you are authorized to work in U.S.";
}
if ($('*input[id*=mzkdm_immigrantvisa]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm if you are currently in the U.S. on a visa.";
}
else {
var val1 = $('*input[id*=mzkdm_immigrantvisa]:checked').val();
if (val1 === '1') {
if ($("#mzkdm_visatype").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide a response what type of visa you have.";
}
if ($("#mzkdm_timeremaininginus").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please select an option how long do you plan to remain in the US.";
}
}
}
if (errorMessages === "") {
$("#stateDiv").val("2");
$('table[data-name="Personal Information"]').parent().hide();
$('table[data-name="Education & Citizenship"]').parent().hide();
$('table[data-name="Program Information"]').parent().hide();
$('table[data-name="Personal Medical History"]').parent().show();
$('table[data-name="Family Medical History"]').parent().show();
$("#PreviousButton").show();
$("#firstCircle").removeClass('active');
$("#secondCircle").removeClass('active');
$("#thirdCircle").removeClass('active');
$("#firstCircle").removeClass('complete');
$("#secondCircle").removeClass('complete');
$("#thirdCircle").removeClass('complete');
$("#firstCircle").addClass('active');
$("#firstCircle").addClass('complete');
$("#secondCircle").addClass('active');
SendMessage("2");
}
}
else if ($("#stateDiv").val() == "2") {
if ($("#mzkdm_sexualpartners").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm your sexual partner history.";
}
if ($('*input[id*=mzkdm_currentlyusenicotinetobacco]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm if you currently use nicotine/tobacco.";
}
else {
var val4 = $('*input[id*=mzkdm_currentlyusenicotinetobacco]:checked').val();
if (val4 === '1') {
if ($("#mzkdm_usenicotineregularly").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please provide a response how long have you been using nicotine/tobacco regularly.";
}
if ($("#mzkdm_frequencyofusage").val().trim() === "") {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please select an option frequency of usage.";
}
}
}
if ($('*input[id*=mzkdm_familyhistoryavailable]:checked').length === 0) {
if (errorMessages !== "") {
errorMessages += " ";
}
errorMessages += "Please confirm if your are able to provide detailed family medical history.";
}
if (errorMessages === "") {
$("#stateDiv").val("3");
$('table[data-name="Personal Information"]').parent().hide();
$('table[data-name="Education & Citizenship"]').parent().hide();
$('table[data-name="Personal Medical History"]').parent().hide();
$('table[data-name="Family Medical History"]').parent().hide();
$('table[data-name="Program Information"]').parent().show();
$("#PreviousButton").show();
$("#firstCircle").removeClass('active');
$("#secondCircle").removeClass('active');
$("#thirdCircle").removeClass('active');
$("#firstCircle").removeClass('complete');
$("#secondCircle").removeClass('complete');
$("#thirdCircle").removeClass('complete');
$("#firstCircle").addClass('active');
$("#firstCircle").addClass('complete');
$("#secondCircle").addClass('active');
$("#secondCircle").addClass('complete');
$("#thirdCircle").addClass('active');
SendMessage("3");
}
}
if (errorMessages === "" && $("#stateDiv").val() == totalStages) {
$("#NextButton").hide();
$("#InsertButton").show();
}
if (errorMessages !== "") {
$(".modal-body").html(errorMessages);
$("#MyPopup").modal("show");
}
});
$("#PreviousButton").on("click", function () {
if ($("#stateDiv").val() == "2") {
$("#stateDiv").val("1");
$('table[data-name="Personal Information"]').parent().show();
$('table[data-name="Education & Citizenship"]').parent().show();
$('table[data-name="Program Information"]').parent().hide();
$('table[data-name="Personal Medical History"]').parent().hide();
$('table[data-name="Family Medical History"]').parent().hide();
$("#PreviousButton").hide();
$("#NextButton").show();
$("#firstCircle").removeClass('active');
$("#secondCircle").removeClass('active');
$("#thirdCircle").removeClass('active');
$("#firstCircle").removeClass('complete');
$("#secondCircle").removeClass('complete');
$("#thirdCircle").removeClass('complete');
$("#firstCircle").addClass('active');
SendMessage("1");
}
else if ($("#stateDiv").val() == "3") {
$("#stateDiv").val("2");
$('table[data-name="Personal Information"]').parent().hide();
$('table[data-name="Education & Citizenship"]').parent().hide();
$('table[data-name="Program Information"]').parent().hide();
$('table[data-name="Personal Medical History"]').parent().show();
$('table[data-name="Family Medical History"]').parent().show();
$("#PreviousButton").show();
$("#NextButton").show();
$("#firstCircle").removeClass('active');
$("#secondCircle").removeClass('active');
$("#thirdCircle").removeClass('active');
$("#firstCircle").removeClass('complete');
$("#secondCircle").removeClass('complete');
$("#thirdCircle").removeClass('complete');
$("#firstCircle").addClass('active');
$("#firstCircle").addClass('complete');
$("#secondCircle").addClass('active');
SendMessage("2");
}
$("#InsertButton").hide();
});
$("#mzkdm_location > option").each(function () {
if (this.text != '' && this.text.toLowerCase() != 'select') {
radioBtns += ' ' + this.text + ' ';
}
});
$("#mzkdm_location").after(radioBtns);
$("#mzkdm_location").hide();
$('input[type=radio][name=locations]').change(function () {
$("#mzkdm_location").val(this.value);
});
$('#msemr_contacttype').val('935000000');
$('#mzkdm_donortype').val('765670001');
$('#csi_fertility_0').prop('checked', true);
//make required work here for mzkdm_hearaboutourprogram
$("#mzkdm_hearaboutourprogram").change(function () {
var program = $("#mzkdm_hearaboutourprogram").val();
var programreason = "mzkdm_hearaboutourprogramreason";
if (program === "765670009") {
MakeRequired(programreason);
}
else {
MakeNotRequired(programreason);
}
});
$("#mzkdm_immigrantvisa").change(function () {
var certHolder = $("input[id*='mzkdm_immigrantvisa']:checked").val();
var prefferedContactMethod = "mzkdm_timeremaininginus";
var visatype = "mzkdm_visatype";
if (certHolder == '1') {
MakeRequired(prefferedContactMethod);
MakeRequired(visatype);
}
else {
MakeNotRequired(prefferedContactMethod);
MakeNotRequired(visatype);
}
});
$("#mzkdm_currentlyusenicotinetobacco").change(function () {
var tobaccoHolder = $("input[id*='mzkdm_currentlyusenicotinetobacco']:checked").val();
var tobaccoMethod = "mzkdm_usenicotineregularly";
var frequency = "mzkdm_frequencyofusage";
if (tobaccoHolder == '1') {
MakeRequired(tobaccoMethod);
MakeRequired(frequency);
}
else {
MakeNotRequired(tobaccoMethod);
MakeNotRequired(frequency);
}
});
// Function to handle change event of the "Do you currently use nicotine/tobacco?" field
$("#mzkdm_currentlyusenicotinetobacco input[type=radio]").change(onDisplaySectionChange);
$("#mzkdm_familyhistoryavailable input[type=radio]").change(onDisplaySectionChange);
$("#mzkdm_immigrantvisa input[type=radio]").change(onDisplaySectionChange);
$("#mzkdm_hearaboutourprogram").change(onDisplaySectionChange);
let dropdowns = document.querySelectorAll('[aria-label="Blank"]');
dropdowns.forEach(dropdown => {
// Check if the label is empty or only contains whitespace
if (dropdown.innerHTML.trim() === "") {
dropdown.innerHTML = "Select an Option";
}
});
$("#firstname").attr("placeholder", "First Name");
$("#lastname").attr("placeholder", "Last Name");
$("#birthdate_datepicker_description").attr("placeholder", "mm/dd/yyyy");
$("#mobilephone").attr("placeholder", "XXX-XXX-XXXX");
$("#emailaddress1").attr("placeholder", "Email");
$("#mzkdm_weight").attr("placeholder", "Weight");
onDisplaySectionChange(); // Call the function initially to set visibility based on the initial value
});
function SendMessage(pageNumber){
urlArray.forEach(url => {
window.parent.postMessage({page: pageNumber}, url);
});
}
//Make mandatory field
var MakeRequired = function (fieldName) {
try {
if ($("#" + fieldName) != undefined) {
$("#" + fieldName).prop('required', true);
$("#" + fieldName).closest(".control").prev().addClass("required");
// Create new validator
var Requiredvalidator = document.createElement('span');
Requiredvalidator.style.display = "none";
Requiredvalidator.id = fieldName + "Validator";
Requiredvalidator.controltovalidate = fieldName;
Requiredvalidator.errormessage = `` + $(`#` + fieldName + `_label`).html() + ` is a required field.`;
Requiredvalidator.initialvalue = "";
Requiredvalidator.evaluationfunction = function () {
var value = $("#" + fieldName).val();
if (value == null || value == "") {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(Requiredvalidator);
}
}
catch (error) {
errorHandler(error);
}
}
//Make UnMandatory
var MakeNotRequired = function (fieldName) {
try {
if ($("#" + fieldName) != undefined) {
$("#" + fieldName).closest(".control").prev().removeClass("required");
$("#" + fieldName).prop('required', false);
for (i = 0; i < Page_Validators.length; i++) {
if (Page_Validators[i].id == fieldName + "Validator") {
Page_Validators.splice(i);
}
}
}
}
catch (error) {
errorHandler(error);
}
}
function onDisplaySectionChange() {
var program = $("#mzkdm_hearaboutourprogram").val();
// Check if the option set value is equal to 765670009
var isOptionSetEqual = (program === "765670009");
if (isOptionSetEqual) {
$('#mzkdm_hearaboutourprogramreason_label').show();
$('#mzkdm_hearaboutourprogramreason').show();
}
else {
$('#mzkdm_hearaboutourprogramreason_label').hide();
$('#mzkdm_hearaboutourprogramreason').hide();
}
// Get the checked radio input element
var checkedRadio = $("#mzkdm_currentlyusenicotinetobacco input[type=radio]:checked");
var check = $("#mzkdm_familyhistoryavailable input[type=radio]:checked");
var checkedvisa = $("#mzkdm_immigrantvisa input[type=radio]:checked");
if (checkedvisa.length > 0) {
var checkvisa = checkedvisa.val();
var GetVisaValue = (checkvisa === "1") ? "Yes" : "No";
if (GetVisaValue === "Yes") {
$('#mzkdm_visatype').parent().parent().show()
$('#mzkdm_timeremaininginus').parent().parent().show();
} else {
$('#mzkdm_visatype').parent().parent().hide();
$('#mzkdm_timeremaininginus').parent().parent().hide();
}
}
if (check.length > 0) {
// Read the value of the checked radio button
var checkbox = check.val();
// Convert the value to "Yes" or "No" string
var GetValue = (checkbox === "1") ? "Yes" : "No";
// Show or hide the label based on the value
}
if (checkedRadio.length > 0) {
// Read the value of the checked radio button
var checkboxValue = checkedRadio.val();
// Convert the value to "Yes" or "No" string
var varManuf = (checkboxValue === "1") ? "Yes" : "No";
// Show or hide the label based on the value
if (varManuf === "Yes") {
$('#mzkdm_usenicotineregularly').parent().parent().show();
$('#mzkdm_frequencyofusage').parent().parent().show();
} else {
$('#mzkdm_usenicotineregularly').parent().parent().hide();
$('#mzkdm_frequencyofusage').parent().parent().hide();
}
}
}