//============================================================================
var ifs_vals = [];
var coupon = {};
//============================================================================
function ha_format_dollar_value(dollar_value, option = 'normal') {
if (typeof dollar_value == 'string') dollar_value = parseFloat(dollar_value.replace('$',''));
if (option == 'round_up') dollar_value = Math.ceil(dollar_value);
return Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
.format(dollar_value).replace(".00","");
}
//============================================================================
function get_access_level_string_from_radio() {
if (typeof(pro_only_mode) != 'undefined' && pro_only_mode ) return 'Pro';
if (jQuery('#Access-Bronze').hasClass('Access-Selected')) return 'Bronze';
if (jQuery('#Access-Silver').hasClass('Access-Selected')) return 'Silver';
if (jQuery('#Access-Gold').hasClass('Access-Selected')) return 'Gold';
if (jQuery('#Access-Pro').hasClass('Access-Selected')) return 'Pro';
return 'unknown';
}
//============================================================================
function get_payment_plan_string_from_radio() {
if (jQuery('#Payment-Onepay').hasClass('Payment-Selected')) return 'Onepay';
if (jQuery('#Payment-Annual').hasClass('Payment-Selected')) return 'Annual';
if (jQuery('#Payment-Monthly').hasClass('Payment-Selected')) return 'Monthly';
if (jQuery('#Payment-3year').hasClass('Payment-Selected')) return '3year';
return 'unknown';
}
//============================================================================
function get_market_level_string_from_radio() {
if (jQuery('#Market-City').hasClass('Market-Selected')) return 'City';
if (jQuery('#Market-State').hasClass('Market-Selected')) return 'State';
if (jQuery('#Market-Region').hasClass('Market-Selected')) return 'Region';
if (jQuery('#Market-Nation').hasClass('Market-Selected')) return 'Nation';
return 'unknown';
}
//============================================================================
function set_market_level(market_level) {
jQuery("[id^='Market-']").removeClass('Market-Selected');
jQuery('#Market-' + market_level).addClass('Market-Selected');
clean_csrs();
// update_form_feields_and_prices(); // Called in clean_csrs
}
//============================================================================
function set_access_level(access_level) {
jQuery("[id^='Access-']").removeClass('Access-Selected');
jQuery('#Access-' + access_level).addClass('Access-Selected');
update_form_feields_and_prices();
}
//============================================================================
function set_payment_plan(payment_plan) {
jQuery("[id^='Payment-']").removeClass('Payment-Selected');
jQuery('#Payment-' + payment_plan).addClass('Payment-Selected');
update_form_feields_and_prices();
}
//============================================================================
function update_form_feields_and_prices() {
if ( update_form_feields_and_prices.pause_update ) {
console.log('uffap paused');
return 0;
}
console.log('uffap ok');
var market_type = get_market_level_string_from_radio();
if (market_type == 'unknown') {
console.log('mu');
return 0;
}
var market_count = count_msas();
var access_level = get_access_level_string_from_radio();
var plan = get_payment_plan_string_from_radio();
if (plan == 'unknown') {
console.log("Plan Unknown!");
return 0;
}
if ( plan == '3year' && ( access_level != 'Pro' || market_type != 'Nation' ) ) {
console.log('resetting to Annual.');
set_payment_plan('Annual');
}
document.getElementById('plan_option').value = plan;
document.getElementById('market_type').value = market_type;
document.getElementById('access_level').value = access_level;
if (market_count > 0) {
jQuery("#market_list_summary").html('');
} else {
jQuery("#market_list_summary").html('(Please select at least 1 Market in Step #1 above)');
}
if (market_type == 'Nation') {
document.getElementById('loc1').value = 'msa_id_440';
document.getElementById('loc1name').value = 'USA';
} else {
for (i = 1; i<=market_count; i++) {
document.getElementById('loc' + i).value = document.getElementsByClassName('msa-list-row')[i-1].id;
document.getElementById('loc' + i + 'name').value = document.getElementsByClassName('msa-list-name')[i-1].innerHTML;
jQuery("#market_list_summary").html( jQuery("#market_list_summary").html() + document.getElementsByClassName('msa-list-name')[i-1].innerHTML + '
');
}
}
document.getElementById('market_count').value = market_count;
update_visible_pricing(plan,market_type,market_count,access_level);
jQuery(document.body).addClass('loading-complete');
}
// update_form_feields_and_prices.pause_update = false;
//============================================================================
function pricing_update_wait_start() {
$("#promo-code-apply-btn").hide();
$("#promo-code-apply-wait").css('display', 'inline-block');
jQuery("#top_banner_block").hide();
}
jQuery(function() {
jQuery('#have-gift-cert').click(function(){
jQuery('.gift-cert-row').toggle();
jQuery('.gift-check-row').toggle();
});
});
//============================================================================
function pricing_update_wait_stop() {
$("#promo-code-apply-btn").show();
$("#promo-code-apply-wait").css('display', 'none');
setTimeout(function(){ jQuery("#top_banner_block").show(); }, 1000);
}
//============================================================================
function market_label_countable(market_type, market_count) {
if ( market_type == 'Nation') return "Entire U.S.A.";
if ( market_type == 'City' ) {
if (market_count == 1) {
return "City";
} else {
return "Cities";
}
}
var s_ending = "";
if (market_count > 1) s_ending = "s";
return market_type + s_ending;
}
//============================================================================
function apply_pricing_data(pricing_data,plan,market_type,market_count,access_level) {
// WORKAROUND:
// Sometimes pricing tada is received multiple times in "random" order, And we can set "State" prices, when "USA" is selected.
// To prevent this - make sure current selection matches the params
if (plan != get_payment_plan_string_from_radio()) return 0;
if (market_type != get_market_level_string_from_radio()) return 0;
// if (market_count != count_msas()) return 0; //Fails when non-national level is selected, and no markets are selected yet
if (access_level != get_access_level_string_from_radio()) return 0;
// =======================================================================
var plans = { 1: 'Onepay', 2: 'Annual', 3: 'Monthly'};
var access_levels = { 1: 'Bronze', 2: 'Silver', 3: 'Gold', 4: 'Pro'};
var market_types = { 1: 'City', 2: 'State', 3: 'Region', 4: 'Nation'};
if (pro_only_mode) {
plans = { 2: 'Annual', 3: 'Monthly'};
access_levels = { 4: 'Pro'};
}
ifs_products = pricing_data.ifs_products;
coupon = pricing_data.coupon;
const lowest_level_available = pro_only_mode ? 'Pro' : 'Bronze';
for (var m in market_types) {
if (typeof(ifs_products['Annual'][market_types[m]]) != 'undefined') {
jQuery("#price_from_Annual_" + market_types[m]).html( ifs_products['Annual'][market_types[m]][1][lowest_level_available].price);
jQuery("#price_from_Annual_Month_" + market_types[m]).html( ha_format_dollar_value(ifs_products['Annual'][market_types[m]][1][lowest_level_available].price_month, 'round_up'));
if (ifs_products['Annual'][market_types[m]][1][lowest_level_available].price_month_before_discount != ifs_products['Annual'][market_types[m]][1][lowest_level_available].price_month) {
jQuery("#price_from_Annual_Month_" + market_types[m] + "_before_discount").html( ha_format_dollar_value(ifs_products['Annual'][market_types[m]][1][lowest_level_available].price_month_before_discount, 'round_up'));
jQuery("#price_from_Annual_Month_" + market_types[m] + "_before_discount").show();
} else {
jQuery("#price_from_Annual_Month_" + market_types[m] + "_before_discount").html('^^^');
jQuery("#price_from_Annual_Month_" + market_types[m] + "_before_discount").hide();
}
}
if (typeof(ifs_products['Monthly'][market_types[m]]) != 'undefined') {
jQuery("#price_from_Monthly_" + market_types[m]).html( ha_format_dollar_value(ifs_products['Monthly'][market_types[m]][1][lowest_level_available].price, 'round_up'));
if (ifs_products['Monthly'][market_types[m]][1][lowest_level_available].price != ifs_products['Monthly'][market_types[m]][1][lowest_level_available].price_before_discount) {
jQuery("#price_from_Monthly_" + market_types[m] + "_before_discount").html(ha_format_dollar_value(ifs_products['Monthly'][market_types[m]][1][lowest_level_available].price_before_discount, 'round_up'));
jQuery("#price_from_Monthly_" + market_types[m] + "_before_discount").show();
} else {
jQuery("#price_from_Monthly_" + market_types[m] + "_before_discount").html('^^^');
jQuery("#price_from_Monthly_" + market_types[m] + "_before_discount").hide();
}
}
}
for (var l in access_levels) {
for(var p in plans) {
if ( typeof( ifs_products[plans[p]][market_type][market_count][access_levels[l]] ) != 'undefined' ) {
jQuery("#price_" + access_levels[l] + "_" + plans[p]).html(ifs_products[plans[p]][market_type][market_count][access_levels[l]].price);
if (ifs_products[plans[p]][market_type][market_count][access_levels[l]].price_before_discount != ifs_products[plans[p]][market_type][market_count][access_levels[l]].price) {
jQuery("#price_" + access_levels[l] + "_" + plans[p] + "_before_discount").html(ha_format_dollar_value(ifs_products[plans[p]][market_type][market_count][access_levels[l]].price_before_discount, 'round_up'));
jQuery("#price_" + access_levels[l] + "_" + plans[p] + "_before_discount").show();
} else {
jQuery("#price_" + access_levels[l] + "_" + plans[p] + "_before_discount").html('^^^');
jQuery("#price_" + access_levels[l] + "_" + plans[p] + "_before_discount").hide();
}
if (plans[p].indexOf('Annual') > -1) {
//Calculate Annual Saving
var price_annual = parseFloat(ifs_products[plans[p]][market_type][market_count][access_levels[l]].price.replace('$','').replace(',',''));
var price_annual_month = parseFloat(ifs_products[plans[p]][market_type][market_count][access_levels[l]].price_month.replace('$','').replace(',',''));
var price_month_before_discount = parseFloat(ifs_products[plans[p]][market_type][market_count][access_levels[l]].price_month_before_discount.replace('$','').replace(',',''));
var price_monthly = parseFloat(ifs_products['Monthly'][market_type][market_count][access_levels[l]].price.replace('$','').replace(',',''));
var annual_saving = Math.floor( price_monthly*12 - price_annual);
jQuery("#price_" + access_levels[l] + "_" + plans[p] + "_Save").html('$' + Number(annual_saving).toLocaleString());
}
if (typeof (ifs_products[plans[p]][market_type][market_count][access_level] ) != 'undefined') {
jQuery("#price_" + plans[p]).html(ifs_products[plans[p]][market_type][market_count][access_level].price);
if (ifs_products[plans[p]][market_type][market_count][access_level].price_before_discount != ifs_products[plans[p]][market_type][market_count][access_level].price) {
jQuery("#price_" + plans[p] + "_before_discount").html(ifs_products[plans[p]][market_type][market_count][access_level].price_before_discount);
jQuery("#price_" + plans[p] + "_before_discount").show();
} else {
jQuery("#price_" + plans[p] + "_before_discount").html('^^^');
jQuery("#price_" + plans[p] + "_before_discount").hide();
}
if (plans[p].indexOf('Annual') > -1) {
var price_annual = parseFloat(ifs_products[plans[p]][market_type][market_count][access_level].price.replace('$','').replace(',',''));
var price_annual_month = parseFloat(ifs_products[plans[p]][market_type][market_count][access_level].price_month.replace('$','').replace(',',''));
var price_monthly = parseFloat(ifs_products['Monthly'][market_type][market_count][access_level].price.replace('$','').replace(',',''));
var annual_saving = Math.floor( price_monthly*12 - price_annual);
jQuery("#price_Annual_Save").html('$' + Number(annual_saving).toLocaleString());
jQuery("#price_Annual_Month").html(ha_format_dollar_value(price_annual_month));
if (price_month_before_discount != price_annual_month) {
jQuery("#price_Annual_Month_before_discount").html(ha_format_dollar_value(price_month_before_discount, 'round_up'));
jQuery("#price_Annual_Month_before_discount").show();
} else {
jQuery("#price_Annual_Month_before_discount").html('^^^');
jQuery("#price_Annual_Month_before_discount").hide();
}
}
}
jQuery("#Access-" + access_levels[l]).show();
} else {
jQuery("#Access-" + access_levels[l]).hide();
}
}
}
//3Yr Plan:
if (typeof ( ifs_products['3year'] ) != 'undefined') {
if (typeof ( ifs_products['3year']['Nation'][1]['Pro'] ) != 'undefined') {
var price_monthly = parseFloat(ifs_products['Monthly']['Nation'][1]['Pro'].price.replace('$','').replace(',',''));
var price_monthly_before_discount = parseFloat(ifs_products['Monthly']['Nation'][1]['Pro'].price_before_discount.replace('$','').replace(',',''));
var price_3year = parseFloat(ifs_products['3year']['Nation'][1]['Pro'].price.replace('$','').replace(',',''));
var price_3year_before_discount = parseFloat(ifs_products['3year']['Nation'][1]['Pro'].price_before_discount.replace('$','').replace(',',''));
var rate_3year = parseFloat(ifs_products['3year']['Nation'][1]['Pro'].rate.replace('$','').replace(',',''));
var rate_3year_before_discount = parseFloat(ifs_products['3year']['Nation'][1]['Pro'].rate_before_discount.replace('$','').replace(',',''));
var saving_3year = Math.floor( price_monthly*36 - price_3year);
var saving_3year_before_discount = Math.floor(price_monthly_before_discount * 36 - price_3year_before_discount);
jQuery("#price_3year").html('$' + Number(price_3year).toFixed(2));
jQuery("#price_3year_Save").html('$' + Number(saving_3year).toFixed(2));
jQuery("#price_3year_Rate").html('$' + Number(rate_3year).toFixed(2));
jQuery(".package-paynow-rate").html(ha_format_dollar_value(price_3year));
jQuery(".package-paynow-rate-month").html(ha_format_dollar_value(price_3year/36));
if (price_3year_before_discount != price_3year) {
jQuery(".package-paynow-rate-before-discount").html(ha_format_dollar_value(price_3year_before_discount));
jQuery(".package-paynow-rate-before-discount").show();
jQuery(".package-paynow-rate-month-before-discount").html(ha_format_dollar_value(price_3year_before_discount/36));
jQuery(".package-paynow-rate-month-before-discount").show();
} else {
jQuery(".package-paynow-rate-before-discount").html('^^^');
jQuery(".package-paynow-rate-before-discount").hide();
jQuery(".package-paynow-rate-month-before-discount").html('^^^');
jQuery(".package-paynow-rate-month-before-discount").hide();
}
jQuery(".package-savings-monthly").html(ha_format_dollar_value(saving_3year));
if (saving_3year_before_discount != saving_3year) {
jQuery(".package-savings-monthly-before-discount").html(ha_format_dollar_value(saving_3year_before_discount));
jQuery(".package-savings-monthly-before-discount").show();
} else {
jQuery(".package-savings-monthly-before-discount").html('^^^');
jQuery(".package-savings-monthly-before-discount").hide();
}
jQuery(".package-subscription-rate").html(ha_format_dollar_value(rate_3year));
if (rate_3year_before_discount != rate_3year) {
jQuery(".package-subscription-rate-before-discount").html(ha_format_dollar_value(rate_3year_before_discount));
jQuery(".package-subscription-rate-before-discount").show();
} else {
jQuery(".package-subscription-rate-before-discount").html('^^^');
jQuery(".package-subscription-rate-before-discount").hide();
}
console.log("3Y Price:" + price_3year);
console.log("3Y Save:" + saving_3year);
console.log("3Y Rate:" + rate_3year);
}
}
///////////////////////////
if (typeof ( ifs_products[plan] ) != 'undefined') {
if (typeof ( ifs_products[plan][market_type][market_count][access_level] ) != 'undefined') {
jQuery(".price_current_product").html( ifs_products[plan][market_type][market_count][access_level].price );
// jQuery(".price_recurring_current_product").html( ifs_products[plan][market_type][market_count][access_level].price_recurring );
}
}
jQuery("#promo-code-frame").removeClass('Valid-Code');
jQuery("#promo-code-frame").removeClass('Invalid-Code');
jQuery("#promo-code-apply-btn-wrapper").removeClass('Valid-Code');
jQuery("#promo-code-apply-btn-wrapper").removeClass('Invalid-Code');
if (pricing_data.coupon.value != '') {
if (pricing_data.coupon.valid) {
jQuery("#promo-code-frame").addClass('Valid-Code');
jQuery("#promo-code-apply-btn-wrapper").addClass('Valid-Code');
} else {
jQuery("#promo-code-frame").addClass('Invalid-Code');
jQuery("#promo-code-apply-btn-wrapper").addClass('Invalid-Code');
}
}
//jQuery("#plan_current_product").html( plan );
jQuery("#promo-banner-instructions-span").html(coupon.specialinstructions);
}
//============================================================================
function update_visible_pricing(plan,market_type,market_count,access_level) {
// price_bronze market_count_bronze market_type_bronze price_bronze_onetime price_bronze_annual price_bronze_monthly
if (market_count == 0) market_count = 1;
jQuery("[id^='market_count_']").html(market_count);
jQuery("[id^='market_type_']").html( market_label_countable( market_type, market_count) );
jQuery("[id^='access_level_div_']").show();
pricing_update_wait_start();
const promo_code_field_id = "#promoCode"; // promoCodeToPass"
var promo_code = jQuery(promo_code_field_id).val();
if (!promo_code_applied) promo_code = "";
var form_options = '';
if (typeof(pro_only_mode) != 'undefined' && pro_only_mode ) {
form_options += 'pro_only_mode,';
}
var pricing_code = plan + '-' + access_level + '-' + market_type + '_' + promo_code;
if (typeof(update_visible_pricing.data[pricing_code]) == 'undefined') {
// console.log("REQUESTING PRICING...");
$.getJSON('https://www.housingalerts.com/add-markets/?plan_option=' + plan + '&access_level=' + access_level + '&market_type=' + market_type + '&promoCode=' + promo_code + '&get_pricing=1' + '&form_options=' + form_options, function(data) {
// console.log("PRICING RECEIVED");
apply_pricing_data(data,plan,market_type,market_count,access_level);
update_visible_pricing.data[pricing_code] = data;
pricing_update_wait_stop();
});
} else {
// console.log("PRICING FROM CACHE");
apply_pricing_data(update_visible_pricing.data[pricing_code],plan,market_type,market_count,access_level);
pricing_update_wait_stop();
}
return 0; //Temporary fix
/*
var price_current_product = product_info[plan_option][market_level][1][maps_option].ifs_data.ProductPrice;
var price_maps_upgrade = product_info[plan_option][market_level][1]["with_maps"].ifs_data.ProductPrice - product_info[plan_option][market_level][1]["without_maps"].ifs_data.ProductPrice;
var price_current_annual_subscription = product_info["annual_subscription"][market_level][1]["without_maps"].ifs_data.ProductPrice;
var price_current_one_year = product_info["one_year"][market_level][1]["without_maps"].ifs_data.ProductPrice;
var fake_price = Math.floor( price_current_product * 1.37 );
var message_under_green_button = "";
if ( plan_option == "annual_subscription" ) {
message_under_green_button = "Join today - Only $" + fake_price + "/Year $" + price_current_product + "/Year
(annual subscription, cancel anytime)";
} else {
message_under_green_button = "Join today - Only $" + fake_price + " $" + price_current_product + " (12 months, no subscription)";
}
jQuery("#price_current_product").html( price_current_product );
jQuery("#price_maps_upgrade").html( price_maps_upgrade );
jQuery("#price_current_annual_subscription").html( price_current_annual_subscription );
jQuery("#price_current_one_year").html( price_current_one_year );
jQuery("#message_under_green_button").html( message_under_green_button );
*/
}
update_visible_pricing.data = {};
//============================================================================
jQuery(function() {
jQuery("#orderform-step1").submit(function(){
result = false;
if (get_market_level_string_from_radio() == 'Nation') {
result = true;
} else {
if (count_msas() < 1) {
alert("Please Select at least One Market");
goToAnchor('#Step2');
result = false;
} else {
result = true;
}
}
if (result) {
/* CLOSE FORM ON SUBMISSION */
jQuery("#order-frame").hide();
jQuery("#order-newtab-directions").show();
}
return result;
});
});
//============================================================================
function ha_httpGetRequest(url) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//alert(this.responseText);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
//============================================================================
function applyPromoCode() {
/* Workaroing Apr 2020 - not sure how it worked w/o that... */
// jQuery("#promoCodeToPass").val( jQuery("#promoCode").val() );
/* ---------------------------------------------------------*/
promo_code_applied = true;
update_form_feields_and_prices();
/*
var promoCode = jQuery("#promoCode").val();
if (promoCode == '') {
alert("Promo Code can't be blank");
return 0;
}
jQuery("#order-frame").hide();
jQuery("#apply-promocode-wait").show();
var url = location.protocol + '//' + location.host + location.pathname + "?promoCode=" + promoCode + "&plan_option=" + jQuery("#plan_option").val() + "&access_level=" + jQuery("#access_level").val();
window.location.href = url;
*/
}
//============================================================================
function applyPromoCodeEmail() {
var promoCodeEmail = jQuery("#promoCodeEmail").val();
if (promoCodeEmail == '') {
alert("Email can't be blank");
return 0;
}
jQuery("#order-frame").hide();
jQuery("#apply-promocode-wait").show();
var url = location.protocol + '//' + location.host + location.pathname + "?promoCode=" + jQuery("#promoCode").val() + "&plan_option=" + jQuery("#plan_option").val() + "&access_level=" + jQuery("#access_level").val() + "&email=" + promoCodeEmail;
window.location.href = url;
}
//============================================================================
function jump_to_anchor(h){
var url = location.href; //Save down the URL without hash.
location.href = "#"+h; //Go to the target element.
history.replaceState(null,null,url); //Don't like hashes. Changing it back.
}
//============================================================================
function captureEmail() {
return 0; //Everything should now be captured by 'captureSelection()' Keep this function for compatibility with older forms where it is set as onChange handler
}
//===============================================================================
function captureSelection() {
if ( is_ha_webinar && popinController.lastGoodPlaySecond <= 0) {
return 0;
}
var email = document.getElementById("Email").value;
if (email == "") {
return;
} else {
var form_content = jQuery("#orderform-step1").serialize();
ha_httpGetRequest("https://www.housingalerts.com/o2/wp-content/themes/focusblog-housingalerts/savecontact-lite.php?" + form_content);
}
}
//============================================================================
//============================================================================
//============================================================================
function add_market(id) { //Accepts pure numeric IDs
MSAclick("MSA"+id);
return 0;
}
//============================================================================
function MSAclick(msaid)
{
msaid = msaid.substr(3);
if (msaid == '0') return 0; //USA
//============================
if ( ok_to_add(msaid) ) {
msa_name = globalMsaCaptions[msaid];
// remove "(MSAD)"
msa_name = msa_name.replace(" (MSAD)","");
msa_name = msa_name.replace(" (MSAD)","");
msa_name = msa_name.replace(" (MSAD)","");
var message = "-----";
var current_count = count_msas();
message = "1) You have added \n-----------------\n" + msa_name + "\n-----------------\nto your order!\n \n";
//clean_csrs();
if (true || confirm(message)) {
var max_name_length_mob = 23;
jQuery("#msa_list").append("