/* configurable globals */ var start_default = "11:00 am"; if(io_default_start_time != "") start_default = io_default_start_time; var end_default = "3:00 pm"; if(io_default_end_time != "") end_default = io_default_end_time; if(io_user_currency){ var currency = io_user_currency; } else{ var currency = "USD"; } if(io_user_country){ var country = io_user_country; } else{ var country = "US"; } var timeFormat = "g:i a"; if(io_cart_time_format != "") timeFormat = io_cart_time_format; var dateFormat = "m/d/yy"; if(io_cart_date_format != "") dateFormat = io_cart_date_format; var restrictTimes = false; if(io_restrict_times === "on") restrictTimes = true; var restrictTimeStart = start_default; if(io_restrict_time_start != "") restrictTimeStart = io_restrict_time_start; var restrictTimeEnd = end_default; if(io_restrict_time_end != "") restrictTimeEnd = io_restrict_time_end; var multi_day = true; if(io_multidayquote === "off" || io_cartdayselect == "Single Day") multi_day = false; var in_cart_upsell = false; if(io_incartupsell === "on") in_cart_upsell = true; var io_distance_charge = false; if(io_distancecharge === "on") io_distance_charge = true; /* other globals */ var pallet_color1 = ""; /* set in onready */ /* track the date start/end of calendar clicking */ var click_count = 0; /* for configuring upsell carosel in cart */ var cart_carousel_set = false; /* for checking when we remove an item from the cart */ var last_remove = 0; var last_upsell_call = 0; /* for buffering cart qty changes checkAvail calls for qty change only */ var last_checkAvail_call = 0; /*var start_default = "11:00"; var end_default = "15:00"; var currency = "EUR"; var timeFormat = "G:i"; var dateFormat = "d/m/yy";*/ /* For weekday weekend pricing */ var use_weekday_weekend = false; if(io_weekEndPrice == "on") use_weekday_weekend = true; /* Accessory and Upsell Prices */ var show_accessory_price = false; if(io_accessory_price == "on") show_accessory_price = true; var show_upsell_price = false; if(io_upsell_price == "on") show_upsell_price = true; /**/ jQuery(document).ready(function () { pallet_color1 = "var( --e-global-color-accent,green )"; if(pallet_color1=="rgba(0, 0, 0, 0)" || pallet_color1=="rgb(255, 255, 255)") pallet_color1="rgb(25, 147, 35)"; /**/ simpleCart({ currency: currency, cartColumns: [{ view: "image", attr: "image", label: "Image" }, { attr: "name", label: "Name" }, { attr: "encoded", label: false }, { attr: "rentalid", label: false }, { attr: "availability", label: false }, { view: "decrement", label: false, text: "" }, { view: "calculate_area", label: false }, { view:"input", attr:"quantity" }, { attr: "qtyincrement", label: false }, { attr: "inputtype", label: false }, { attr: "qtytype", label: false }, { attr: "vendorid", label: false }, { view: "increment", label: false, text: "" }, { attr: "price", label: "Price", view: 'currency' }, { view: "remove", label: false, text: "" }, { attr: "total", label: "SubTotal", view: 'currency' }, { attr: "timeslots", label: false }, { attr: "timeslots-orig", label: false }, { attr: "href", label: false }, { attr: "linkqty", label: false }, { attr: "acc_dd_parent_limit", label: false } ], checkout: { type: "SendForm", method: "GET", url: io_wp_local_path+"/io_quoteform/", extra_data: { /* name: decodeURIComponent("KidZone Party Rentals".replace(/[+]/gi, " ")), */ clear_rentals: "1", selected_only: "1", wp_checkout: "1", startdate: "", enddate: "", starttime: "", endtime: "", io_custguid: "" } } }); simpleCart.bind('update', cart_onUpdate); simpleCart.bind('beforeSave', cart_hideTimepickerWrapper); simpleCart.bind('beforeRemove', cart_beforeRemove); simpleCart.bind('afterRemove', cart_afterRemove); simpleCart.bind('afterQtyChange', cart_afterQtyChange); simpleCart.bind('beforeCheckout', cart_beforeCheckout); simpleCart.bind('afterAdd', cart_afterAdd); simpleCart.bind('beforeAdd', cart_beforeAdd); /**/ /* showAvail(""); */ let io_star_pic = document.querySelector("#io_star_pic"); if (io_star_pic != null) { let io_star_src = io_star_pic.src; if (io_star_src.indexOf("0star") > -1 || io_star_src.indexOf("1star") > -1 || io_star_src.indexOf("2star") > -1 || io_star_src.indexOf("3star") > -1) { io_star_pic.style.display = "none"; } } /**/ /* build multiple thumb images */ let img_container = document.querySelector(".io_image_thumbbox"); let page_picbox = document.querySelector(".io_product_picbox"); if (typeof images_arr !== "undefined"){ /* Clear noopeners to rebuild */ let no_openers = document.querySelectorAll("[id^='io_img_big']"); for(let n of no_openers){ n.parentElement.removeChild(n); } img_container.innerHTML = ""; for (key in images_arr) { /* build and add the noopener */ img_noopener_ele = document.createElement("a"); img_noopener_ele.rel = "img_group noopener"; img_noopener_ele.href = images_arr[key]["rentalimage_imagelocbig"]; img_noopener_ele.id = "io_img_big"+(parseInt(key, 10)+1); page_picbox.appendChild(img_noopener_ele); /* build and add the thumb image */ img_thumb_ele = document.createElement("img"); img_thumb_ele.className = "io_image_thumb skip-lazy"; img_thumb_ele.title = rental_name_template; img_thumb_ele.src = images_arr[key]["rentalimage_imageloc"]; img_thumb_ele.alt = alt_text_template; img_thumb_ele.id = "io_img_thumb"+(parseInt(key, 10)+1); img_thumb_ele.onclick = function() { updateMainPic(this) }; img_container.appendChild(img_thumb_ele); } } /* Test For Broken Images */ let img_box = document.querySelectorAll(".io_image_thumb"); for (let i of img_box) { let io_img_src = i.src; if(io_img_src!==null) io_img_src = io_img_src.toLowerCase(); let io_img_datasrc = i.getAttribute("data-src"); if(io_img_datasrc===null){ io_img_datasrc = ""; }else{ io_img_datasrc = io_img_datasrc.toLowerCase(); } if ((io_img_src.indexOf("io_noimage.png") >= 0 || io_img_datasrc.indexOf("io_noimage.png") >= 0) || (io_img_src.indexOf(".jpg") == -1 && io_img_src.indexOf(".jpe") == -1 && io_img_src.indexOf(".png") == -1 && io_img_src.indexOf(".gif") == -1 && io_img_src.indexOf(".tif") == -1 && io_img_src.indexOf(".webp") == -1)){ i.style.display = "none"; } } /* hide thumb if only 1 */ let img2 = document.querySelector("#io_img_thumb2"); let img1 = document.querySelector("#io_img_thumb1"); if(img2 == null && img1 != null){ document.querySelector("#io_img_thumb1").style.display = "none"; } /**/ /**/ /* Add Add To Cart Buttons */ let button_add = document.querySelector("#bookNowBtn"); var main_id = 0; if(jQuery(".io_product_container .item_rentalid")){ main_id = jQuery(".io_product_container .item_rentalid").first().text(); } /* if main item is dd but not pkg (linen code) */ if(jQuery(".io_acc_accessorydd").text()==1 && jQuery(".io_acc_ispackage").text()!=1){ /* if order is defined, then reorder here. */ var acc_cls = jQuery('.io_product_accessories') acc_cls.hide(); let pkg = document.querySelector(".io_product_acc_pkg"); if(pkg==undefined){ pkg = document.createElement("div"); pkg.classList.add("io_product_acc_pkg"); pkg.style.textAlign = "center"; acc_cls.after(pkg); } for (let [key, value] of acc_obj_relate) { elem = getAccElem(key,main_id); if(elem){ btn = makeAccBtn(elem,main_id); pkg.append(btn); } } let line = document.createElement("div"); line.innerHTML = "
"; pkg.append(line.cloneNode(true)); for (let [key, value] of acc_obj_relate) { for (key2 in acc_obj_relate.get(key)) { let id = acc_obj_relate.get(key)[key2]; if(typeof id == "object"){ /* 3rd level */ pkg.append(line.cloneNode(true)); for (key3 in acc_obj_relate.get(key)[key2]) { let id = acc_obj_relate.get(key)[key2][key3]; if(typeof id != "object"){ elem = getAccElem(id,key2); if(elem){ btn = makeAccBtn(elem,key2); btn.style.display = "none"; pkg.append(btn); } } } }else{ elem = getAccElem(id,key); if(elem){ btn = makeAccBtn(elem,key); btn.style.display = "none"; pkg.append(btn); } } } } }else { let access_array = document.querySelectorAll(".io_acc_li"); let count = 0; for (let i of access_array) { let path = i.id.replace("io_acc_",""); count++; let newButton = button_add.cloneNode(true); newButton.id = button_add.id + count; newButton.classList.remove("elementor-animation-grow"); newButton.classList.add("elementor-animation-shrink"); let path_arr = path.split("_"); let pid = parseInt(path_arr[0]); let this_id = parseInt(path_arr[1]); if(path_arr.length==1) pid=0; if(jQuery("#io_acc_accessorydd_"+path).first().text()==1){ /* display different to provide choices in dd */ main_id = pid; }else{ /* hide accessories inside a pkg when under an accessory choice item until clicked */ if(jQuery("#io_acc_accessorydd_"+main_id+"_"+pid).first().text()==1){ }else{ /* jpa - not finished/tested yet */ /*jQuery("#io_acc_"+path).hide();*/ } /* Fix broken images for accessories. */ let img_box = document.querySelectorAll(".io_acc_li_img_thumb"); let firstImg = true; let lastAcc = ""; for (let i of img_box) { if(lastAcc=="") lastAcc = i.id; if(lastAcc!=i.id){ lastAcc = i.id; firstImg = true; } let io_img_src = i.src; if(io_img_src!==null) io_img_src = io_img_src.toLowerCase(); let io_img_datasrc = i.getAttribute("data-src"); if(io_img_datasrc===null){ io_img_datasrc = ""; }else{ io_img_datasrc = io_img_datasrc.toLowerCase(); } if ((io_img_src.indexOf("io_noimage.png") >= 0 || io_img_datasrc.indexOf("io_noimage.png") >= 0) || (io_img_src.indexOf(".jpg") == -1 && io_img_src.indexOf(".jpe") == -1 && io_img_src.indexOf(".png") == -1 && io_img_src.indexOf(".gif") == -1 && io_img_src.indexOf(".tif") == -1 && io_img_src.indexOf(".webp") == -1)){ i.style.display = "none"; }else if(!firstImg && jQuery("#io_acc_accessorydd_"+main_id+"_"+pid).first().text()!=1){ i.style.display = "none"; } firstImg = false; } if(jQuery("#io_acc_accessorydd_"+main_id+"_"+pid).first().text()==1){ /* Make the accessory category look more mike a label. */ jQuery("#iothumb_"+main_id+"_"+pid).hide(); jQuery("#io_acc_"+main_id+"_"+pid).css("border", "none"); jQuery("#io_acc_"+main_id+"_"+pid).css("width", "100%"); jQuery("#io_acc_"+main_id+"_"+pid).css("margin-bottom", "5vh"); jQuery("#io_acc_"+main_id+"_"+pid).css("box-shadow", "none"); jQuery("#io_acc_shortname_"+pid).css("font-weight", "bold"); jQuery("#io_acc_shortname_"+pid).css("position", "absolute"); /* Make this auto selected to fix an issue where we can not add to cart if this item is a child of another hidden accessory on screen */ jQuery("#io_acc_"+main_id+"_"+pid).prop("selected", true); accessory_cat_text = jQuery("#io_acc_shortname_"+pid).first().text(); /* This is necessary to make sure there are not multiple colons. */ if(!accessory_cat_text.includes(":")){ jQuery("#io_acc_shortname_"+pid).text(accessory_cat_text+":"); } /* Remove Href so we do not open images on click for dd accessories. */ jQuery("[id^=io_acc_imgbig_"+pid+"_]").removeAttr("href"); /* Get the accessory limit for this set of acessories, then set up click events. */ /* Unbind is used to prevent cascading calls. */ accLmt = parseInt(jQuery("#io_acc_accessorylimit_"+main_id+"_"+pid).prop("textContent")); jQuery("[id^=io_acc_"+pid+"_]").unbind("click").click({pid: pid, accLmt: accLmt}, accDDClicked); jQuery("[id^=io_acc_"+pid+"_]").css("cursor", "pointer"); /* Set up the slected property of all children accessories. Default to false. */ jQuery("[id^=io_acc_"+pid+"_]").prop("selected", false); /* We need to add a hidden button so we can simulate a click on add_item for the cart. */ let newButton = button_add.cloneNode(true); newButton.id = button_add.id + count; newButton.classList.remove("elementor-animation-grow"); newButton.setAttribute("style", "display: none !important"); i.appendChild(newButton); }else{ let button_wrap = document.createElement("div"); button_wrap.classList.add("elementor-widget-button"); button_wrap.classList.add("io_access_button"); button_wrap.appendChild(newButton); let req = false; if(jQuery("#io_acc_required_"+path).first().text()>0) req = true; if(!req){ i.appendChild(button_wrap); }else{ var textnode = document.createTextNode("Included"); i.appendChild(textnode); } } } } } /*
*/ let upsell_array = document.querySelectorAll(".io_upsell_li"); count = 0; for (let i of upsell_array) { count++; let newButton = button_add.cloneNode(true); newButton.id = button_add.id + count; newButton.classList.remove("elementor-animation-grow"); newButton.classList.add("elementor-animation-shrink"); let button_wrap = document.createElement("div"); button_wrap.classList.add("elementor-widget-button"); button_wrap.classList.add("io_upsell_button"); button_wrap.appendChild(newButton); i.appendChild(button_wrap); } if(io_deliverymethod == "on" && jQuery(".calDeliveryMethodLabel").length==0){ let delivery_method_container = jQuery("#ioDeliveryMethodContainer").first(); delivery_method_container.append('Select Delivery Method'); let delivery_method_html = '' time_select_container.append(selected_date_html); time_select_container.append("
") time_select_container.append('Select Timeslot'); let timeslot_html = ''); jQuery("#io_cdl_zip_label").text("Postal code"); if(country == "CA"){ jQuery("#io_cdl_state_label").text("Province"); } else if(country == "AU"){ jQuery("#io_cdl_city_label").text("Suburb"); } } else{ jQuery("#io_cd_zip").attr("type", "number"); } /* Set up on change events to stop end timepickers from allowing users to pick times before start time */ setTimeout(restrictEndTimepickers, 500); /* If we have a custom message in cart, display it. */ if(io_cart_message){ show_cart_message(); } /* code for day select in cart */ if(io_cartdayselect == "dropdown_options" && io_multidayquote === "on"){ saved_whatday = getCookie("io_whatday"); if(saved_whatday) jQuery("#whatday").val(saved_whatday); endDisplay(); setCalBackground(); } else{ jQuery("#div-overnight").hide(); jQuery("#whatday").val(""); } checkRestrictedDeliveries() /* If we are using the information gathering tool, we do not want to show this message. */ if( live_pricing_is_on() && io_info_required == "off" ){ if(!event_time_set() && io_always_display_live_price != "on"){ jQuery("#item_live_price_time_set_message").show(); }else{ jQuery("#item_live_price_time_set_message").hide(); } } /* Check if information gathering header exists. If it does, Remove set even button and add some classes on onclicks */ if(jQuery("#ioInfoHeader").length){ remove_set_event_buttton(); add_classes_and_onClicks(); header_increment_step(); } jQuery(".io_acc_li").each(function() { if(jQuery(this).find(".item_required").first().text() == 1 && jQuery(this).find(".item_accessorydd").first().text() == 1){ jQuery(jQuery(jQuery(this).parent()).prev()).appendTo(".io_product_requiredDD_accessories"); jQuery(jQuery(this).parent()).appendTo(".io_product_requiredDD_accessories"); jQuery(".io_product_requiredDD_accessories").show(); } }); if(jQuery(".io_product_accessories .io_acc_li").length == 0) jQuery(".io_product_accessories").hide(); /* Hide the cart add button for items with required accessories on category page */ jQuery(".item_hasRequiredAcc").each(function() { if (this.innerText == '1') { let rental_id_element = jQuery(this).parent().find(".item_rentalid")[0]; let addCartButton = jQuery(".io_item2_list_inner .add_cart_" + rental_id_element.innerText).find('.io_button'); addCartButton.removeClass("item_add"); addCartButton.html(''); let itemHref = jQuery(this).parent().find(".item_href").text(); addCartButton.attr('href', itemHref); } }); /* If they have same day selection allowed, need to update checkout page datepicker on delay to make sure it works */ if(io_cartAllowSameDay == "on"){ setTimeout(allow_same_day_select_on_checkout, 500); } if(io_info_required_data && io_info_required == "on"){ let io_required_data = io_info_required_data; jQuery("#ioAdditonalInformationContainer").show(); for (const [data, value] of Object.entries(io_required_data)) { if(value == 1){ jQuery("#io_info_modal_"+data).css("display", "inline-flex") jQuery("#io_im_"+data).val(getCookie(data)); } } show_or_hide_required_info_message() } if(jQuery(".bootstrap-timepicker").length == 0) { if (!/Mobi|Android/i.test(navigator.userAgent)) { jQuery("#cartPopover").scroll(function () { jQuery("[name=timeStart]").timepicker("hide"); jQuery("[name=timeEnd]").timepicker("hide"); }); jQuery(window).scroll(function () { jQuery("#cartPopover [name=timeStart]").timepicker("hide"); jQuery("#cartPopover [name=timeEnd]").timepicker("hide"); }); } } if(jQuery(".io_product_infobox .item_inputtype").text() == "Map"){ simpleCart.items().forEach(function (item, index){ if(item.get("rentalid") === jQuery(".io_product_infobox .item_rentalid").text()){ if(item.get("quantity") > 1){ let units; if(jQuery(".io_product_infobox .item_qtytype").text() == "Area"){ units = "sq meters" if(country === "US") units = "sq feet" }else if(jQuery(".io_product_infobox .item_qtytype").text() == "Perimeter"){ units = "meters" if(country === "US") units = "feet" } set_price_on_item_page(units, item.get("quantity")); } } }); } /* IO-21808 */ jQuery(".io_product_price_box").each(function() { let classes = jQuery(this).attr("class"); jQuery(this).attr("class", classes.replace(":", "_")); }); /* Set time instructions (IO-21496) */ set_cart_time_instructions(); if(io_accessory_select === "on"){ if(jQuery(".io_product_acc_pkg").children().length > 0){ let main_rental_id = jQuery(".item_rentalid").text(); let sel_div = jQuery("
"); let sel = jQuery(""); sel2.append("") jQuery("[id^=io_acc_shortname_"+option_rental_id+"_]").each(function(){ sel2.append("") }); sel_div.append(sel2); } }); sel_div.prepend(sel); jQuery(".io_product_acc_pkg").replaceWith(sel_div); } } if(io_cart_party_planner_email === "on" && io_cart_party_planner_destination){ jQuery("#cartPartyBuilderEmailContainer").show() if(getCookie("email")){ jQuery("#cartPartyBuilderEmailInput").val(getCookie("email")); } } if(io_brand == "PW"){ jQuery(".io_product_price_box").attr("style", "display: none !important;"); jQuery(".io_product_price_sqfoot").attr("style", "display: grid !important;"); } setTimeout(simpleCart.init, 100); if(io_hide_zero == 1){ jQuery(".io_product_price_top_left").each(function (){ if(Number(this.innerText.replace(/[^0-9.-]+/g,"")) == 0){ jQuery(this).parent().attr('style','display:none !important'); } }); jQuery(".io_product_price_left").each(function (){ if(Number(this.innerText.replace(/[^0-9.-]+/g,"")) == 0){ jQuery(this).parent().attr('style','display:none !important'); } }); } }); /*end of on-ready*/ /*
*/ /**/ function io_party_planner_email_submit(){ let valid_regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; let email = jQuery("#cartPartyBuilderEmailInput").val(); if(email){ if(email.match(valid_regex)){ setCookie("email", email, 14); window.open(io_cart_party_planner_destination, '_blank').focus(); }else{ jQuery("#cartPartyBuilderEmailWarning").show(); } }else{ jQuery("#cartPartyBuilderEmailWarning").show(); } } function rid_in_batch(rid, batch_ids){ let result = batch_ids.filter(function(batch){ if(batch.includes(this)) return true; }, rid); return result } function set_cart_time_instructions(){ /* Making it clearer that customers need to set the time in order to see pricing and availability. */ let instructions_container = jQuery("

"); let instructions = ""; if(multi_day){ instructions += "Select the event date or date range using the calendar"; }else{ instructions += "Select the event date using the calendar"; } instructions += "."; instructions_container.text(instructions); jQuery("#cartCalendar").append(instructions_container); } function live_pricing_is_on(){ /* Checks to see if live pricing is on. Assumes it is on unless one of the following conditions: The setting Hide Live Price is off. The setting Show Weekend/Weekday Pricing is off. Delivery method pricing is enabled by default. We are on an item page that uses delivery method pricing. */ if(io_hide_live_prices != 1 || io_weekEndPrice != "on" || io_delivery_prices["default"].length != 0 || jQuery(".io_product_infobox .item_rentalid").innerText in io_delivery_prices["override"] || io_custom_prices["default"].length != 0 || jQuery(".io_product_infobox .item_rentalid").innerText in io_delivery_prices["override"]){ return false; } return true; } function allow_same_day_select_on_checkout(){ jQuery(".jquery-datepicker").datepicker("option", "minDate", 0); } function show_or_hide_required_info_message(){ if(io_info_required == "on"){ if(!all_info_provided()){ jQuery("#io_all_prices").hide(); jQuery("#item_additonal_info_open_message").show(); }else{ jQuery("#io_all_prices").show(); jQuery("#item_additonal_info_open_message").hide(); } } } function all_info_provided(){ /* This is used for when the "Hide all pricing on page until information is provided" setting is on price settings. */ let all_data_provided = true; let io_required_data = io_info_required_data; for (const [data, value] of Object.entries(io_required_data)) { if(value == 1){ if(!getCookie(data)){ all_data_provided = false } } } if(live_pricing_is_on() && !event_time_set()) { all_data_provided = false; } return all_data_provided; } function event_time_set(){ if(getCookie("timeStart") && getCookie("timeEnd") && getCookie("dateStart") && getCookie("dateEnd")){ return true; } else{ return false } } function show_cart_message(){ message_container = jQuery("#cartCustomMessage"); message_container.html(io_cart_message); message_container.show(); } function deliveryMethodSelected(){ setCookie("io_delivery_method", jQuery(".ioDeliveryMethods option:selected").text(), 14); checkRestrictedDeliveries(); } function adjustPicBoxForHeader(){ /* For some reason its hard to get css with querySelector so we use jQuery to get the picbox. */ pic_box = jQuery(".io_product_picbox"); io_header = document.querySelector(".io_header"); if(pic_box != null && pic_box.css("position") == "sticky"){ if(io_header != null){ header_height = io_header.offsetHeight; pic_box.css("top", (10+header_height).toString()+"px"); } else{ possible_headers = document.querySelectorAll("header,section") possible_headers.forEach((ele) =>{ if(ele.style.top == "0px" && (ele.style.position == "fixed" || ele.style.position == "sticky")){ header = ele; header_height = header.offsetHeight; pic_box.css("top", (10+header_height).toString()+"px"); } }); } } } function cart_times_all_set(){ if(jQuery("#ioCartTimeSelectContainer [name=dateStart]").val() == ""){ return false; } if(io_hidetimes === "off" || io_hidetimes === ""){ if(jQuery("#ioCartTimeSelectContainer [name=timeStart]").val() == ""){ return false; } if(jQuery("#ioCartTimeSelectContainer [name=timeEnd]").val() == ""){ return false; } } return true; } function checkRestrictedDeliveries(){ let items = simpleCart.items() let restrictions_found = false; for(i in items){ let rid = items[i].get("rentalid"); if(typeof jQuery(".ioDeliveryMethods").val() != "undefined"){ if(io_delivery_methods[jQuery(".ioDeliveryMethods").val()]["restricted"].includes(rid)){ jQuery("#deliveryMethodWarning").show(); restrictions_found = true; } } } if(!restrictions_found){ jQuery("#deliveryMethodWarning").hide(); } } function display_cart_warning(item){ let cart_warning_container = jQuery("#cartWarning"); // Check if an event date if not we should tell them to set it. event_times = getAvailTimes(); if(!event_times[0] || !event_times[1]){ cart_warning_container.text("Please set the date and time for your event above."); cart_warning_container.show() return false; } let item_name = item.get("name"); let item_timeslots = item.get("timeslots"); let timeslot_name = getTimeslotName(item_timeslots); let stop_loop = false; if(item_timeslots){ if(jQuery(item_timeslots).nodeName == "SELECT"){ /* NOTE: It should not be possible for timeslots to be empty. But in the event they somehow are, we should have this here. */ /* timeslots */ var timeslot_sel_range = jQuery(".item-timeslots [name=\""+timeslot_name+"\"] option:selected").val(); if(typeof timeslot_sel_range != "undefined"){ var [start_time, end_time] = break_timeslot_sel_range(timeslot_sel_range); } }else{ /* timepickers */ let [start_timepicker, end_timepicker] = get_cart_timepickers(timeslot_name); var start_time = start_timepicker.value; var end_time = end_timepicker.value; } if(!start_time || !end_time){ cart_warning_container.text("Please select a time range for the following item: " + item_name); cart_warning_container.show() stop_loop = true; } } else{ cart_warning_container.text("Some items are not available on this date."); cart_warning_container.show() } return stop_loop } function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/"; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(";"); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") c = c.substring(1); if (c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } function break_timeslot_sel_range(timeslot_sel_range){ /* Takes a time range given by selected timeslot and gets the start and end time removing meridiem.*/ timeslot_sel_arr = timeslot_sel_range.split(" - "); var start_time = timeslot_sel_arr[0].replace("am"," am").replace("pm"," pm").replace(" "," "); var end_time = timeslot_sel_arr[1].replace("am"," am").replace("pm"," pm").replace(" "," "); return Array(start_time, end_time); } function getAvailTimes(){ /* Commonly used helper function. Accomplishes two things: Returns an array containing start_date, start_time, and event duration. Sets cookies for start and end date, and start and end time. Uses the inputs available in the cart if they are filled out, so dateStart, dateEnd, timeStart, and timeEnd. If timeslots are being used in cart it chooses the selected timeslot and breaks it on - and gets the start ane end time from that. */ let start_date = jQuery("input[name=dateStart]").val(); let end_date = jQuery("input[name=dateEnd]").val(); if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day"){ let cart_company_timeslot_selected = jQuery(".ioCartCompanyTimeslots option:selected").first().val(); if(cart_company_timeslot_selected){ setCookie("company_timeslot_selected", cart_company_timeslot_selected, 14); cart_company_timeslot_selected = cart_company_timeslot_selected.split("-"); var start_time = cart_company_timeslot_selected[0].trim(); var end_time = cart_company_timeslot_selected[1].trim(); } } else { var start_time = jQuery("input[name=timeStart]").val(); var end_time = jQuery("input[name=timeEnd]").val(); } if (start_date.length == 0) { start_date = getCookie("dateStart"); end_date = getCookie("dateEnd"); start_time = getCookie("timeStart"); end_time = getCookie("timeEnd"); } if(start_time.length == 0){ start_time = start_default; } if(end_time.length == 0){ end_time = end_default; } /* no past dates */ if(start_date.length != 0 && convertDateStringtoDateObject(start_date, start_time) < new Date()){ start_date=""; end_date=""; } /* setCookie("checkDate", start_date, 14); */ setCookie("dateStart", start_date, 14); setCookie("dateEnd", end_date, 14); setCookie("timeStart", start_time, 14); setCookie("timeEnd", end_time, 14); /* If we are using the information gathering tool, we do not want to show this message.*/ if( live_pricing_is_on() && io_info_required == "off" ){ if(!event_time_set() && io_always_display_live_price != "on"){ jQuery("#item_live_price_time_set_message").show(); }else{ jQuery("#item_live_price_time_set_message").hide(); } } var newDate1 = convertDateStringtoDateObject(start_date, start_time); var newDate2 = convertDateStringtoDateObject(end_date, end_time); let time_duration = ((newDate2 - newDate1) / 3600) / 1000; return [start_date,start_time,time_duration]; } function getAllRentalIDsFromCart(){ let rental_ids = ""; jQuery("[id^='cartItem_']").each(function(){ children = this.children for(let i = 0; i < children.length; ++i){ if(children[i].className == "item-rentalid") { rental_ids += children[i].innerText + "|"; break; } } }); return rental_ids } /*
*/ /**/ function init_date_timepicker_for_info_header(){ jQuery(".ioInfoDatepicker").datepicker({ changeMonth: true, changeYear: true, dateFormat: dateFormat, rangeSelect: true, numberOfMonths: 1, stepMonths: 1, speed: "fast", showOn: "both", onChangeMonthYear: cal_onChangeMonthYear, buttonText: "Calendar", minDate: 1, firstDay: 0 }); jQuery("#ioHeaderDateStart").datepicker("option", { onSelect: function() { set_info_header_end_date(); saveInfoHeader(); // Add more functions if needed } }); if(restrictTimes){ jQuery(".ioInfoTimepicker").timepicker({ startTime: new Date(0, 0, 10, 0, 0, 0), endTime: new Date(0, 0, 0, 20, 0, 0, 0), minTime:restrictTimeStart, maxTime:restrictTimeEnd, /*show24Hours: $show24Hours,*/ timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } else{ jQuery(".ioInfoTimepicker").timepicker({ startTime: new Date(0, 0, 10, 0, 0, 0), endTime: new Date(0, 0, 0, 20, 0, 0, 0), /*show24Hours: $show24Hours,*/ timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } setTimeout(setUpTimeRestrictions_infoHeaderTimepickers, 500); } function saveInfoHeader(){ let info_header_start_date = jQuery("[id$=ioHeaderDateStart]"); let info_header_end_date = jQuery("[id$=ioHeaderDateEnd]"); let info_header_start_time = jQuery("[id$=ioHeaderTimeStart]"); let info_header_end_time = jQuery("[id$=ioHeaderTimeEnd]"); let info_header_address = jQuery("[id$=ioHeaderAddress]"); let info_header_city = jQuery("[id$=ioHeaderCity]"); let info_header_state = jQuery("[id$=ioHeaderState]"); let info_header_zip = jQuery("[id$=ioHeaderZipCode]"); let info_header_phone = jQuery("[id$=ioHeaderPhone]"); let info_header_email = jQuery("[id$=ioHeaderEmail]"); if(info_header_start_time.val()) setCookie("timeStart", info_header_start_time.val(), 14); if(info_header_end_time.val()) setCookie("timeEnd", info_header_end_time.val(), 14); if(info_header_start_date.val()) setCookie("dateStart", info_header_start_date.val(), 14); if(info_header_end_date.val()) setCookie("dateEnd", info_header_end_date.val(), 14); if(info_header_address.val()) setCookie("address", info_header_address.val(), 14); if(info_header_city.val()) setCookie("city", info_header_city.val(), 14); if(info_header_state.val()) setCookie("state", info_header_state.val(), 14); if(info_header_zip.val()) setCookie("zip", info_header_zip.val(), 14); if(info_header_phone.val()) setCookie("phone", info_header_phone.val(), 14); if(info_header_email.val()) setCookie("email", info_header_email.val(), 14); /* Set information in the cart. */ calCancel(); header_increment_step(); /* Stop form from doing anything else for elementor */ // jpa - still allow, turn off actions in form if wanted. to turn off io lead submission use the plugin settings //event.preventDefault(); //event.stopPropagation(); return true; } function set_info_header_values(){ let info_header_start_date = jQuery("[id$=ioHeaderDateStart]"); let info_header_end_date = jQuery("[id$=ioHeaderDateEnd]"); let info_header_start_time = jQuery("[id$=ioHeaderTimeStart]"); let info_header_end_time = jQuery("[id$=ioHeaderTimeEnd]"); let info_header_street = jQuery("[id$=ioHeaderAddress]"); let info_header_city = jQuery("[id$=ioHeaderCity]"); let info_header_state = jQuery("[id$=ioHeaderState]"); let info_header_zip = jQuery("[id$=ioHeaderZipCode]"); let info_header_phone = jQuery("[id$=ioHeaderPhone]"); let info_header_email = jQuery("[id$=ioHeaderEmail]"); if(getCookie("timeStart")) info_header_start_time.val(getCookie("timeStart")); if(getCookie("timeEnd")) info_header_end_time.val(getCookie("timeEnd")); if(getCookie("dateStart")) info_header_start_date.val(getCookie("dateStart")); if(getCookie("dateEnd")) info_header_end_date.val(getCookie("dateEnd")); if(getCookie("address")) info_header_street.val(getCookie("address")); if(getCookie("city")) info_header_city.val(getCookie("city")); if(getCookie("state")) info_header_state.val(getCookie("state")); if(getCookie("zip")) info_header_zip.val(getCookie("zip")); if(getCookie("phone")) info_header_phone.val(getCookie("phone")); if(getCookie("email")) info_header_email.val(getCookie("email")); } function add_classes_and_onClicks(){ /* First set up for dates */ let info_header_start_date = jQuery("#ioHeaderDateStart"); let info_header_end_date = jQuery("#ioHeaderDateEnd"); info_header_start_date.addClass("ioInfoDatepicker"); info_header_end_date.addClass("ioInfoDatepicker"); /* Now Timepickers */ let info_header_start_time = jQuery("#ioHeaderTimeStart"); let info_header_end_time = jQuery("#ioHeaderTimeEnd"); info_header_start_time.addClass("ioInfoTimepicker"); info_header_end_time.addClass("ioInfoTimepicker"); /* Add the onClick to the button */ let button = jQuery("#ioInfoHeaderSubmit"); button.click(saveInfoHeader); button.css("cursor", "pointer"); /* Init datepicker and timepickers */ init_date_timepicker_for_info_header(); /* Lastly set the values if they are set already */ set_info_header_values(); } function remove_set_event_buttton(){ let set_event_button = jQuery(".pageDateRangeWrapper"); if(set_event_button.length > 0) set_event_button.hide(); } function set_info_header_end_date(){ if(!jQuery("#ioHeaderDateEnd").val()){ jQuery("#ioHeaderDateEnd").val(jQuery("#ioHeaderDateStart").val()) } jQuery("#ioHeaderDateEnd").datepicker("option", { minDate: new Date(jQuery("#ioHeaderDateStart").val()) }); } function header_increment_step(){ let active = jQuery(".io-step-active"); switch(active.attr("id")){ case "io-step-1": if (/Mobi|Android/i.test(navigator.userAgent)) { jQuery("#io-step-2,#io-step-3,#io-step-4").hide(); } if(check_header_step_one(active)){ active.removeClass("io-step-active"); active.addClass("io-step-done") jQuery("#io-step-2").addClass("io-step-active") header_increment_step(); } break; case "io-step-2": if (/Mobi|Android/i.test(navigator.userAgent)) { jQuery("#io-step-2,#io-step-3,#io-step-4").show(); } if(simpleCart.items().length > 0){ active.removeClass("io-step-active"); active.addClass("io-step-done") jQuery("#io-step-3").addClass("io-step-active") header_increment_step(); } break; case "io-step-3": if (/Mobi|Android/i.test(navigator.userAgent)) { jQuery("#io-step-2,#io-step-3,#io-step-4").show(); } if(document.location.href.indexOf("io_quoteconfirm") >= 0){ active.removeClass("io-step-active"); active.addClass("io-step-done") jQuery("#io-step-4").addClass("io-step-active") header_increment_step(); } break; case "io-step-4": if (/Mobi|Android/i.test(navigator.userAgent)) { jQuery("#io-step-2,#io-step-3,#io-step-4").show(); } break; } } function check_header_step_one(active) { var allInputs = active.find('input'); for (var i = 0; i < allInputs.length; i++) { if (jQuery(allInputs[i]).val() === "") { return false; // Return false if any input is empty } } return true; // Return true if all inputs have a value } /**/ /**/ function accDDClicked(event){ this_element = jQuery(this) if(!this_element.prop("selected")){ pid = event.data.pid accLmt = event.data.accLmt all_elements = jQuery("[id^=io_acc_"+pid+"_]") let count = 0; /* Tried using .filter and .length to get the count of selected items but could not make it work. */ for(i = 0; i < all_elements.length; ++i){ if(all_elements[i].selected){ ++count; } } if(accLmt == 0){ this_element.css("border", "5px solid #bbb"); this_element.prop("selected", true); } else if(count >= accLmt){ let selected_value = jQuery("[id^=io_acc_"+pid+"_]").filter(function() { return this["selected"]; }); /* be sure to unselect other slected values if our acc limit has been reached. */ selected_value.prop("selected", false); selected_value.css("border", "1px solid #bbb"); } this_element.css("border", "5px solid #bbb"); this_element.prop("selected", true); } else{ this_element.prop("selected", false); this_element.css("border", "1px solid #bbb"); } } /* when accessory choice is clicked */ function accOnClick(acc_select=null){ /* set name/img back to original main in case they are just clicking on a 1st level size option */ jQuery(".io_product_title.item_name").html(main_name_orig); jQuery(".io_product_container .item_image").first().attr("src",main_img_src); jQuery(".io_product_container .item_image").first().attr("data-src",main_img_src); jQuery(".io_product_container .item_encoded").first().html(main_encoded); jQuery(".io_product_container .io_image_big").first().attr("src",main_img_src); jQuery(".io_product_container .io_image_big").first().attr("data-src",main_img_src); let main_id = jQuery(".io_product_container .item_rentalid").first().text(); let main_id_arr = main_id.split(":") jQuery(".io_product_container .item_rentalid").html(main_id_arr[0]); let clk_id; if(jQuery(acc_select).find(":selected").val()){ clk_id = jQuery(acc_select).find(":selected").val().replace("io_acc_shortname_",""); }else{ clk_id = this.id.replace("io_acc_shortname_",""); } clk_id = clk_id.replace("iothumb_",""); let click_id_arr = clk_id.split("_"); /* let pid = main_id; */ /* if(main_id.split("_").length>1) pid = parseInt(click_id_arr[0]); */ for (let [key, value] of acc_obj_relate) { let id = key; if(acc_obj_relate.get(key)[0]!=undefined){ for (key2 in acc_obj_relate.get(key)) { let id = acc_obj_relate.get(key)[key2]; if(typeof id == "object"){ /* 3rd level */ for (key3 in acc_obj_relate.get(key)[key2]) { let id = acc_obj_relate.get(key)[key2][key3]; if(typeof id != "object"){ displayPackageChoices(clk_id,key2,id,acc_obj_relate.get(key)[key2]); } } }else{ displayPackageChoices(clk_id,key,id,acc_obj_relate.get(key)); } } }else{ displayPackageChoices(clk_id,0,id,acc_obj_relate); } } } /* show/hide accessory levels as needed */ /* clk_id: one they clicked on, pid: parentid, id: iterator, arr: relationship array */ function displayPackageChoices(clk_id,pid,id,arr){ let main_id = jQuery(".io_product_container .item_rentalid").first().text(); let main_arr = main_id.split("_"); if(main_arr.length>1) main_id = parseInt(main_arr[0]); let click_id_arr = clk_id.split("_"); elem = getAccElem(id,pid); if(click_id_arr[0]==pid || click_id_arr[1]==pid || pid==0){ elem.style.display="inline-block"; }else{ elem.style.display="none"; } if(click_id_arr[1]==id && (click_id_arr[0]==pid || (pid==0 && click_id_arr[0]==main_id) ) || (click_id_arr.length==1 && click_id_arr[0]==id)){ updateMainItem(id,pid); } } /* update it with accessory data for choices */ var main_img_src = jQuery("#single_image").first().attr("href"); var main_name_orig = jQuery(".io_product_title.item_name").html(); var main_encoded = jQuery(".io_product_container .item_encoded").html(); var main_desc = jQuery(".io_product_detailbox .io_product_desc").html(); function updateMainItem(id,pid){ /* update add to cart btn, name, img, desc */ let name = ""; let name_enc = ""; let main_id = jQuery(".io_product_container .item_rentalid").first().text(); let main_arr = main_id.split(":"); if(main_arr.length>1) main_id = main_arr[0]; if(pid!=0){ name += jQuery("#io_acc_itemname_"+pid).html()+":"; name_enc += jQuery("#io_acc_itemname_"+pid).html()+":"; name += jQuery("#io_acc_shortname_"+id).html(); name_enc += jQuery("#io_acc_itemname_"+id).html(); }else{ pid = main_id; name += jQuery("#io_acc_itemname_"+id).html(); name_enc += jQuery("#io_acc_itemname_"+id).html(); } jQuery(".io_product_container .item_encoded").html(encodeURIComponent(name_enc.replace(/[\u2032\u2019]+/ig,"'"))); jQuery(".io_product_container .item_rentalid").html(main_id+":"+pid+"_"+id); jQuery(".io_product_title.item_name").html(name); if(jQuery("#io_acc_desc_"+pid+"_"+id).first().length>0){ jQuery(".io_product_container .io_product_desc").first().html(jQuery("#io_acc_desc_"+pid+"_"+id).first()[0].innerHTML); } /* swap accessory image with main image pic for drop-down type items (linens) */ let img = jQuery("#io_acc_imgbig_"+pid+"_"+id).first().attr("href"); if(img==null) img = jQuery("#iothumb_"+pid+"_"+id).first().attr("src") if(img==null){ }else{ if(img.length==0 && pid==main_id){ /* for 1 level dd items that have no img, use the main img */ img = main_img_src; } jQuery(".io_product_container .io_image_big").first().attr("src",img); jQuery(".io_product_container .io_image_big").first().attr("data-src",img); jQuery(".io_product_container .item_image").first().attr("src",jQuery("#iothumb_"+pid+"_"+id).first().attr("src")); jQuery(".io_product_container .item_image").first().attr("data-src",jQuery("#iothumb_"+pid+"_"+id).first().attr("src")); jQuery("#single_image").first().attr("href",img).show(); } checkAvailFilter(); } /* get either img or text for accessory choices */ function getAccElem(id,pid){ let path =pid+"_"+id; if(pid==0){ path=id; } let elem = null; try{ elem = document.querySelector("#ioAccButtonWrapper_"+path); }catch(e){} if(elem == null){ try{ elem = document.querySelector("#iothumb_"+path); }catch(e){} } if(elem==null){ try{ elem = document.querySelector("#io_product_acc_pkg_sel_"+pid); }catch(e){} if(elem!=null) return elem; }else{ return elem; } if(elem == null){ try{ elem = document.querySelector("#io_acc_shortname_"+path); }catch(e){} }else if(elem.src=="" | elem.getAttribute("data-src")==""){ try{ elem = document.querySelector("#io_acc_shortname_"+path); }catch(e){} }else if(elem.src.substr(-1)=="/"){ try{ elem = document.querySelector("#io_acc_shortname_"+path); }catch(e){} } if(elem==null){ try{ elem = document.querySelector("#io_acc_shortname_"+id); }catch(e){} } return elem; } /* create the accessory choice btn (img/text) */ function makeAccBtn(button_add,pid){ let newButton; if(button_add.nodeName=="IMG"){ newButton = button_add; let id = newButton.id.replace("iothumb_"+pid,""); var wrapper = document.createElement("div"); wrapper.setAttribute("id", "ioAccButtonWrapper_"+pid+id); wrapper.style.display = "inline-block"; wrapper.appendChild(newButton); let acc_name = document.createElement("span"); acc_name.style.overflow = "hidden"; acc_name.style.textOverflow = "ellipsis"; acc_name.style.maxWidth = "80px"; acc_name.style.display = "block"; acc_name.style.whiteSpace = "nowrap"; acc_name.textContent = jQuery("#io_acc_shortname"+id).text(); acc_name.classList.add("accTextName"); acc_name.setAttribute("id", "io_acc_shortname_"+pid+id); wrapper.appendChild(document.createElement("br")); wrapper.appendChild(acc_name); }else{ newButton = button_add.cloneNode(true); let id = newButton.id.replace("io_acc_shortname_",""); newButton.id = "io_acc_shortname_" + pid + "_" + id; } newButton.classList.add("elementor-animation-grow"); newButton.classList.remove("item_image"); newButton.style="cursor:pointer;border: solid 1px grey"; newButton.classList.add("io_access_button"); newButton.style.display = "inline-block"; newButton.style.verticalAlign = "top"; newButton.onclick=accOnClick; if(newButton.nodeName=="IMG"){ newButton.style.minWidth = "80px"; newButton.style.width = "80px"; newButton.style.margin = "2px"; newButton.style.height = "80px"; }else{ newButton.style.margin = "0px 2px 0px 2px"; } if(button_add.nodeName=="IMG"){ return wrapper } return newButton; } /* when clicking the thumb swatches under main image (2nd image for an item) */ function updateMainPic(img) { /* calling image */ let thumb_id = img.id; let big_id = thumb_id.replace('thumb', 'big'); /* main image we are updating */ let main_img = document.querySelector(".io_image_big"); let img_big = document.querySelector("#" + big_id); main_img.src = img_big.href; /* document.querySelector("#single_image").href =img_big.href; */ } /**/ /**/ function calApply() { /* reset timeslots if filtering is on */ filterTimeslotsByDay_itemTimeslots(); simpleCart.update(); if(cart_times_all_set()){ setCookie("dateApplied", "true", 1) checkAvailAll(); calCancel(); } let io_required_data = io_info_required_data; for (const [data, value] of Object.entries(io_required_data)) { if(value == 1){ setCookie(data, jQuery("#io_im_"+data).val(), 14); } } /* Check if information gathering header exists. If it does, update the times on there. */ if(jQuery("#ioInfoHeader").length){ jQuery("#ioHeaderTimeStart").val(jQuery("[name=timeStart]").val()); jQuery("#ioHeaderTimeEnd").val(jQuery("[name=timeEnd]").val()); jQuery("#ioHeaderDateStart").val(jQuery("[name=dateStart]").val()); jQuery("#ioHeaderDateEnd").val(jQuery("[name=dateEnd]").val()); header_increment_step(); } show_or_hide_required_info_message() /* if(!cartStayOpen) cartHide(); */ } function calCancel() { click_count = 0; jQuery("input[name=dateStart]").val(getCookie("dateStart")); jQuery("input[name=dateEnd]").val(getCookie("dateEnd")); if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day" && getCookie("company_timeslot_selected")){ jQuery(".ioCartCompanyTimeslots").val(getCookie("company_timeslot_selected")); } else{ jQuery("input[name=timeStart]").val(getCookie("timeStart")); jQuery("input[name=timeEnd]").val(getCookie("timeEnd")); } setCalBackground(); jQuery(".ioDateRange").html(smartFormatDateRange()) jQuery("#cartCalendar, #cartTimePicker").hide(); jQuery(".ioDateRange").show(); jQuery(".changeDateLinkWrapper").show(); } /* var cartStayOpen = false; */ function calSetDateRange(stayOpen) { /* if(stayOpen==1){ cartStayOpen = true; }else{ cartStayOpen = false; } */ jQuery(".changeDateLinkWrapper").hide(); jQuery("#cartCalendar, #cartTimePicker").show(); jQuery("#cartDateRange").hide(); } function smartFormatDateRange() { let start_date = jQuery("input[name=dateStart]").val(); let end_date = jQuery("input[name=dateEnd]").val(); if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day"){ let cart_company_timeslot_selected = jQuery(".ioCartCompanyTimeslots option:selected").first().val(); if(cart_company_timeslot_selected){ setCookie("company_timeslot_selected", cart_company_timeslot_selected, 14); cart_company_timeslot_selected = cart_company_timeslot_selected.split("-"); var start_time = cart_company_timeslot_selected[0].trim(); var end_time = cart_company_timeslot_selected[1].trim(); } } else { var start_time = jQuery("input[name=timeStart]").val(); var end_time = jQuery("input[name=timeEnd]").val(); } let text = ""; text = start_date; if(io_hidetimes!="on") text += " " + start_time; if (start_date == end_date) { if(io_hidetimes!="on"){ text += " "; text += end_time; } } else { text += " "; text += end_date; if(io_hidetimes!="on") text += " " + end_time; } /* text += " "; */ return text; } function resetCalButtons() { jQuery("#cartCalendar .ui-datepicker-prev").addClass("fas fa-arrow-left").css("color", pallet_color1); jQuery("#cartCalendar .ui-datepicker-next").addClass("fas fa-arrow-right").css("color", pallet_color1); } function cal_onChangeMonthYear(year, month, obj) { setTimeout(resetCalButtons, 10); setTimeout(setCalBackground, 10); } function cal_onSelect(dateText, obj) { setTimeout(resetCalButtons, 10); let whatday_choice = ""; if(io_cartdayselect === "dropdown_options" && io_multidayquote === "on"){ let choice_obj = jQuery("#whatday"); if(choice_obj){ whatday_choice = choice_obj.val(); } } click_count++; end_timepicker = jQuery("input[name=timeEnd]"); let timeStart = jQuery("input[name=timeStart]").val(); if (timeStart == "") { jQuery("input[name=timeStart]").val(start_default); jQuery("input[name=timeEnd]").val(end_default); } if (click_count == 1 || !multi_day || whatday_choice==="Same Day" || whatday_choice==="Overnight") { jQuery("input[name=dateStart]").val(dateText); jQuery("input[name=dateEnd]").val(dateText) end_timepicker.timepicker("option",{"minTime": jQuery("input[name=timeStart]").val()}); if(EndTimeLessThanStartTime( jQuery("input[name=timeStart]").val(), end_timepicker.val(), jQuery("[name='dateStart']").val(), jQuery("[name='dateEnd']").val() ) ) { end_timepicker.val(""); } if(io_cartAllowSameDay == "on"){ restrictStartTimepickerOnSameDaySelect(dateText, jQuery("input[name=timeStart]"), end_timepicker); } } else if (click_count == 2) { jQuery("input[name=dateEnd]").val(dateText); let start_date_str = jQuery("input[name=dateStart]").val(); let start_date_obj = convertDateStringtoDateObject(start_date_str); let end_date_obj = convertDateStringtoDateObject(dateText); if(end_date_obj < start_date_obj){ jQuery("input[name=dateStart]").val(dateText); if(io_cartAllowSameDay == "on"){ restrictStartTimepickerOnSameDaySelect(dateText, jQuery("input[name=timeStart]"), end_timepicker); } } else{ end_timepicker.timepicker("option",{"minTime": io_restrict_time_start}); } click_count = 0; } else { click_count = 0; } //custom code for suncoast_event if(io_cartdayselect === "dropdown_options" && io_multidayquote === "on"){ endDisplay(); //daysSelect(); } filterTimeslotsByDay_companyTimeslots(); setTimeout(setCalBackground, 10); } function endDisplay(){ //todo: need to figure out if these work and set triggers // trigger enddisplay after date is selected or possibly when dateEnd changes? let choice = jQuery("#whatday").val(); setCookie("io_whatday", choice, 14); let dateStart = jQuery("[name=dateStart]"); let timeStart = jQuery("[name=timeStart]"); let dateEnd = jQuery("[name=dateEnd]"); let timeEnd = jQuery("[name=timeEnd]"); if(choice==='Overnight'){ let startdate = dateStart.val(); let starttime = io_overnightPickupTime; let endcalc_date_obj = new Date(buildDateobjectstring(startdate,dateFormat,starttime)); let duration_hrs = 24; let end_date_obj = new Date(endcalc_date_obj.getTime()+duration_hrs*60*60*1000); if(!isNaN(end_date_obj)){ dateEnd.val(getFormatteddate(end_date_obj)); timeEnd.val(getFormattedtime(end_date_obj)); timeEnd.attr('readonly','readonly'); } }else if(choice==='Multi-Day'){ timeEnd.removeAttr('readonly'); }else{ timeEnd.removeAttr('readonly'); } setTimeout(setCalBackground, 10); } function setCalBackground() { let dateStart_string = jQuery("input[name=dateStart]").val(); let dateEnd_string = jQuery("input[name=dateEnd]").val(); if (dateFormat == "d/m/yy") { let dateStartArray = dateStart_string.split("/"); let dateEndArray = dateEnd_string.split("/"); var dateStart = new Date(dateStartArray[2], Number(dateStartArray[1])-1, dateStartArray[0]); var dateEnd = new Date(dateEndArray[2], Number(dateEndArray[1])-1, dateEndArray[0]); } else { var dateStart = new Date(dateStart_string); var dateEnd = new Date(dateEnd_string); } let sday = dateStart.getDate(); let smonth = dateStart.getMonth(); let syear = dateStart.getFullYear(); let eday = dateEnd.getDate(); let emonth = dateEnd.getMonth(); let eyear = dateEnd.getFullYear(); /* clear any (in case of cancel) */ jQuery(".ui-datepicker-calendar [data-handler=selectDay]").css("background-color","initial"); /* set the selected ones */ jQuery("#cartCalendar [data-month=" + smonth + "][data-year=" + syear + "], #cartCalendar [data-month=" + emonth + "][data-year=" + eyear + "]").each(function (i) { let cday = jQuery(this).find("a").first().text(); let cmonth = jQuery(this).attr("data-month"); let cyear = jQuery(this).attr("data-year"); /* let dateCurrent = new Date(Date.UTC(cyear,cmonth,cday,12)); */ let dateCurrent = new Date(cyear, cmonth, cday); if (click_count == 1 && dateEnd_string.length == 0) dateEnd = dateStart; if (dateCurrent.getTime() == dateStart.getTime() && dateCurrent.getTime() == dateEnd.getTime()) { jQuery(this).css("border-radius", "6px 6px 6px 6px"); } else if (dateCurrent.getTime() == dateStart.getTime()) { jQuery(this).css("border-radius", "6px 0 0 6px"); } else if (dateCurrent.getTime() == dateEnd.getTime()) { jQuery(this).css("border-radius", "0 6px 6px 0"); } if (dateCurrent >= dateStart && dateCurrent <= dateEnd) { jQuery(this).css("background-color", pallet_color1); } }); } /**/ /**/ /* called from simplecart */ function timeslotChange(){ checkAvailCartTimeslots(); } function filterTimeslotsByDay_companyTimeslots(){ var weekday = new Array(); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; weekday[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; let times = getAvailTimes(); let start_date = times[0]; let day = weekday[new Date(start_date).getDay()]; let selected_option_label = jQuery(".ioCartCompanyTimeslots option:selected").first().text().toLowerCase(); if(optionHasDay(weekday, selected_option_label)){ if(selected_option_label.indexOf(day.toLowerCase()) === -1){ jQuery(".ioCartCompanyTimeslots").val(""); } } if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day"){ jQuery(".ioCartCompanyTimeslots > option").each(function() { if(optionHasDay(weekday, this.text.toLowerCase())){ for(i=0; i 0){ var timeslot_name = getTimeslotName(timeslots_html); if(typeof item.get("timeslots-orig") == "undefined"){ var timeslots_obj = jQuery.parseHTML(timeslots_html); } else{ var timeslots_obj = jQuery.parseHTML(item.get('timeslots-orig')); } jQuery(timeslots_obj).find("option").each(function(){ if(optionHasDay(weekday, this.text.toLowerCase())){ for(i=0; i'+jQuery(timeslots_obj).html()+''); } } }); } function optionHasDay(weekdays, option_label){ for(i=0; i0){ item.set("timeslots",jQuery(".item-timeslots [name=\""+timeslot_name+"\"]")[0].outerHTML); } /* set on quote page */ jQuery(".controls [name=\""+timeslot_name+"\"] option").not(":selected").removeAttr("selected"); jQuery(".controls [name=\""+timeslot_name+"\"] option[value='"+jQuery(".item-timeslots [name=\""+timeslot_name+"\"] option:selected").val()+"']").attr("selected","selected"); } function setTimePicker(item, timepicker_name){ let [start_timepicker, end_timepicker] = get_cart_timepickers(timepicker_name); let start_time = start_timepicker.value; let end_time = end_timepicker.value; if(!start_time){ start_timepicker.style.borderColor = "red"; } else{ start_timepicker.style.borderColor = ""; } if(!end_time){ end_timepicker.style.borderColor = "red"; } else{ end_timepicker.style.borderColor = ""; } let start_timepicker_html = start_timepicker.outerHTML; let end_timepicker_html = end_timepicker.outerHTML; if(document.querySelectorAll(".item-timeslots [name=\""+timepicker_name+"\"]").length>0){ start_timepicker_html = addOrReplaceValueInTimepicker(start_timepicker_html, start_time); end_timepicker_html = addOrReplaceValueInTimepicker(end_timepicker_html, end_time); item.set("timeslots", '
Start: '+start_timepicker_html+' End: '+end_timepicker_html+'
'); } /* set on quote page */ /* For linen type items with timepickers */ let rental_id = item.get("rentalid"); let split_on_colon = rental_id.split(":"); if(split_on_colon.length > 1){ fix_time_name_for_linen_rid(timepicker_name, split_on_colon, start_time, end_time, rental_id) }else{ let quote_page_start_timepicker = document.querySelectorAll(".controls [name=\""+timepicker_name.replace("io_timepicker_", "starttime_")+"\"]")[0]; let quote_page_end_timepicker = document.querySelectorAll(".controls [name=\""+timepicker_name.replace("io_timepicker_", "endtime_")+"\"]")[0]; if(quote_page_start_timepicker != null && quote_page_end_timepicker != null){ quote_page_start_timepicker.value = start_time; quote_page_end_timepicker.value = end_time; } } } function fix_time_name_for_linen_rid(time_name, split_rid, start_time, end_time, rental_id){ for(let x = 0; x < split_rid.length; x++){ temp_timepicker_name = time_name.replace(rental_id, split_rid[x]); let quote_page_start_timepicker = document.querySelectorAll(".controls [name=\""+temp_timepicker_name.replace("io_timepicker_", "starttime_")+"\"]")[0]; let quote_page_end_timepicker = document.querySelectorAll(".controls [name=\""+temp_timepicker_name.replace("io_timepicker_", "endtime_")+"\"]")[0]; if(quote_page_start_timepicker != null && quote_page_end_timepicker != null){ quote_page_start_timepicker.value = start_time; quote_page_end_timepicker.value = end_time; } } } function addOrReplaceValueInTimepicker(timepicker_html, time_value){ if(timepicker_html.includes("value=")){ timepicker_html = [timepicker_html.slice(0, timepicker_html.indexOf("value=")), 'value="'+time_value+'"', timepicker_html.slice(timepicker_html.length-1)].join(""); }else{ /* No value defined. Add it at the end of the outer html. */ let position = timepicker_html.lastIndexOf(">"); timepicker_html = [timepicker_html.slice(0, position), ' value="'+time_value+'"', timepicker_html.slice(position)].join(""); } return timepicker_html } function restrictEndTimepickers(){ setUpTimeRestrictions_cartTimepickers() setUpTimeRestrictions_timeBasedItems() } function setUpTimeRestrictions_timeBasedItems(){ jQuery("input[name^=start_timeslot_]").change(function() { end_timepicker = jQuery("input[name='"+this.name.replace("start", "end")+"']"); end_timepicker = jQuery(end_timepicker[end_timepicker.length - 1]); end_timepicker.timepicker("option",{"minTime": jQuery(this).val()}); if( EndTimeLessThanStartTime( jQuery(this).val(), end_timepicker.val(), "0/0/0", "0/0/0" ) ){ end_timepicker.val(""); } }); } function setUpTimeRestrictions_cartTimepickers(){ jQuery("input[name=timeStart]").change(function() { end_timepicker = jQuery("[name='"+this.name.replace("Start", "End")+"']"); if(jQuery("[name='dateStart']").val() === jQuery("input[name='dateEnd']").val()){ end_timepicker.timepicker("option",{"minTime": jQuery(this).val()}); if(EndTimeLessThanStartTime( jQuery(this).val(), end_timepicker.val(), jQuery("[name='dateStart']").val(), jQuery("[name='dateEnd']").val() ) ) { end_timepicker.val(""); } } }); } function setUpTimeRestrictions_infoHeaderTimepickers(){ jQuery("#ioHeaderTimeStart").change(function() { end_timepicker = jQuery("#ioHeaderTimeEnd"); if(jQuery("#ioHeaderDateStart").val() === jQuery("#ioHeaderDateEnd").val()){ end_timepicker.timepicker("option",{"minTime": jQuery(this).val()}); if(EndTimeLessThanStartTime( jQuery(this).val(), end_timepicker.val(), jQuery("#ioHeaderDateStart").val(), jQuery("#ioHeaderDateEnd").val() ) ) { end_timepicker.val(""); } } }); } /* helper function to see if the value from a start timepicker is less than the string value of an end timepicker. param start_time: string representation of the start time picker. 12hr or 24hr. param end_time: string representation of the end time picker. 12hr or 24hr. param start_date: string representation of the start date, seperated by "/". Can be wither d/m/y or m/d/y. Pass "0/0/0" if dates do not matter. param end_date: string representation of the end date, seperated by "/". Can be wither d/m/y or m/d/y. Pass "0/0/0" if dates do not matter. */ function EndTimeLessThanStartTime(start_time, end_time, start_date, end_date){ if(!start_time || !end_time) return false; start_time = convert12HourTo24Hour(start_time); end_time = convert12HourTo24Hour(end_time); var split_start_date = start_date.split("/"); var split_end_date = end_date.split("/"); var startDate = buildDateObj(split_start_date, start_time); var endDate = buildDateObj(split_end_date, end_time); if(endDate < startDate){ return true; } else { return false; } } function get_cart_timepickers(timepicker_name){ let start_timepicker = document.getElementsByName(timepicker_name.replace("io_timepicker_", "start_timeslot_")); let end_timepicker = document.getElementsByName(timepicker_name.replace("io_timepicker_", "end_timeslot_")); start_timepicker = start_timepicker[start_timepicker.length-1]; end_timepicker = end_timepicker[end_timepicker.length-1]; return Array(start_timepicker, end_timepicker); } function restrictStartTimepickerOnSameDaySelect(start_date_str, start_timepicker, end_timepicker){ let selected_date_obj = convertDateStringtoDateObject(start_date_str); let current_date_obj = new Date(); if(current_date_obj.getDate() == selected_date_obj.getDate() && current_date_obj.getMonth() == selected_date_obj.getMonth() && current_date_obj.getYear() == selected_date_obj.getYear()){ let next_hour_time_stamp = current_date_obj.setMinutes(60); let next_hour_str = getFormattedtime(new Date(next_hour_time_stamp)) start_timepicker.timepicker("option",{"minTime": next_hour_str}); /* If the time in the input box is less than the time we just restricted too, then clear time inputs */ restricted_time_obj = convertDateStringtoDateObject(start_date_str, next_hour_str); currently_selected_time_obj = convertDateStringtoDateObject(start_date_str, start_timepicker.val()); if(currently_selected_time_obj < restricted_time_obj){ start_timepicker.val(next_hour_str); end_timepicker.val(""); end_timepicker.timepicker("option",{"minTime": next_hour_str}); } }else{ start_timepicker.timepicker("option",{"minTime": restrictTimeStart}); } } /*
*/ /**/ function cart_onUpdate() { /* need slight delay so simplecart updates before this runs */ setTimeout(cart_onUpdate2, 500); try{ for(var i=0;i Number(avail) || avail == "not") { /* item.set("availability",""+item.get("availability")+""); */ setTimeout(function () { jQuery("#cartItem_" + item_id + " .item-availability").css("color", "red") }, 10); //jQuery("#cartWarning").show(); stop_loop = display_cart_warning(item); hasUnavail = true; } else { jQuery("#cartItem_" + item_id + " .item-availability").css("color", "inherit"); } }else{ event_times = getAvailTimes(); if(!event_times[0] || !event_times[1]){ jQuery("#cartWarning").text("Please set the date and time for your event above."); jQuery("#cartWarning").show() } } var timeslots_html = item.get("timeslots"); if(typeof timeslots_html != "undefined"){ if(timeslots_html.length > 0){ var timeslot_name = getTimeslotName(timeslots_html); if(timeslots_html.indexOf("= 0){ setTimeslotSelected(item, timeslot_name); }else{ setTimePicker(item, timeslot_name); } } } if(stop_loop){ return false; } }); if(gift_cards_only){ jQuery("#cartCalendarTimePickerContainer").hide(); }else{ jQuery("#cartCalendarTimePickerContainer").show(); } if(hasUnavail && io_checkavail!="off"){ jQuery(".simpleCart_checkout").removeClass("simpleCart_checkout").addClass("simpleCart_checkout_off").trigger("classChange").click(cartShow); }else if(io_checkavail!="off"){ jQuery(".simpleCart_checkout_off").removeClass("simpleCart_checkout_off").addClass("simpleCart_checkout").trigger("classChange"); } add_cart_buttons = document.querySelectorAll("[class*=add_cart_]"); if(add_cart_buttons){ for(let i = 0; i < add_cart_buttons.length; ++i){ add_cart_buttons[i].innerHTML = add_cart_buttons[i].innerHTML.replace("fa-cart-arrow-down", "fa-shopping-cart"); add_cart_buttons[i].innerHTML = add_cart_buttons[i].innerHTML.replace("Added to Cart", "Add to Cart"); add_cart_buttons[i].style.filter = "brightness(100%)"; simpleCart.each(function (item, x) { if( add_cart_buttons[i].className.includes( item.get("rentalid") ) ){ add_cart_buttons[i].innerHTML = add_cart_buttons[i].innerHTML.replace("fa-shopping-cart", "fa-cart-arrow-down"); add_cart_buttons[i].innerHTML = add_cart_buttons[i].innerHTML.replace("Add to Cart", "Added to Cart"); add_cart_buttons[i].style.filter = "brightness(90%)"; } }); } } /* init time-based items */ if(document.location.href.indexOf("io_quoteform") == -1){ let today = new Date(); let io_dd = today.getDate(); let io_mm = today.getMonth() + 1; let io_yyyy = today.getFullYear(); if(restrictTimes){ jQuery(".item-timeslots .timepicker").each( function() { if(this.name.includes("end")){ start_timepicker = jQuery("input[name='"+this.name.replace("end", "start")+"']"); start_timepicker = jQuery(start_timepicker[start_timepicker.length - 1]); if(start_timepicker.val() != ""){ jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), minTime:start_timepicker.val(), maxTime:restrictTimeEnd, timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } else { jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), minTime:restrictTimeStart, maxTime:restrictTimeEnd, timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } } else { jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), minTime:restrictTimeStart, maxTime:restrictTimeEnd, timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } }); } else{ jQuery(".item-timeslots .timepicker").each( function() { if(this.name.includes("end") != -1){ start_timepicker = jQuery("input[name='"+this.name.replace("end", "start")+"']"); start_timepicker = jQuery(start_timepicker[start_timepicker.length - 1]); if(start_timepicker.val() != ""){ jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), minTime:start_timepicker.val(), timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } else { jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } } else{ jQuery(this).timepicker({ startTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + start_default), endTime: new Date(io_mm+"/"+io_dd+"/"+io_yyyy + " " + end_default), timeFormat: timeFormat, separator: ":", className: "elementor-widget-text-editor", step: 15, disableTouchKeyboard: true }); } }); } setUpTimeRestrictions_timeBasedItems(); if(!event_time_set()){ jQuery(".itemRow .item-total").hide(); }else{ jQuery(".itemRow .item-total").show(); } } } function cart_beforeCheckout(data) { data.startdate = jQuery("input[name=dateStart]").val(); data.enddate = jQuery("input[name=dateEnd]").val(); data.io_custguid = getCookie("guid"); if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day"){ let cart_company_timeslot_selected = jQuery(".ioCartCompanyTimeslots option:selected").first().val(); if(cart_company_timeslot_selected){ setCookie("company_timeslot_selected", cart_company_timeslot_selected, 14); cart_company_timeslot_selected = cart_company_timeslot_selected.split("-"); data.starttime = cart_company_timeslot_selected[0]; data.endtime = cart_company_timeslot_selected[1]; } } else { data.starttime = jQuery("input[name=timeStart]").val(); data.endtime = jQuery("input[name=timeEnd]").val(); } } function cart_beforeAdd(item) { var main_id = jQuery(".io_product_container .item_rentalid").first().text(); var item_id = item.get("rentalid"); timeslots = item.get("timeslots"); if(timeslots){ if(timeslots.indexOf(" 0 && dropdown == 1) }); var required_selected = true; required_dropdown_values.each(function() { required_value_id = jQuery(this).find(".item_rentalid")[0].outerText; required_value_id = required_value_id.split("_"); required_value_id = required_value_id[required_value_id.length-1]; let selected = jQuery("[id^='io_acc_"+required_value_id+"']").filter(function() { return this["selected"]; }); //IO-22431 - This wasnt catching if [0] was undefined if(jQuery(this).find(".io_acc_li_name")[0] != undefined){ required_value_name = jQuery(this).find(".io_acc_li_name")[0].outerText ? jQuery(this).find(".io_acc_li_name")[0].outerText : ""; } if(selected.length < jQuery(this).find(".item_required")[0].outerText){ if(item_id == main_id){ alert(required_value_name+" is a required field."); } required_selected = false; } if(!required_selected){ return false; } return true; }); if(!required_selected){ return false; } /* IO-14857 */ if(jQuery(".io_product_measurement_price").length > 0){ let units; if(jQuery(".io_product_infobox .item_qtytype").text() == "Area"){ units = "sq meters" if(country === "US") units = "sq feet" }else if(jQuery(".io_product_infobox .item_qtytype").text() == "Perimeter"){ units = "meters" if(country === "US") units = "feet" } item.set("units", units); item.set("quantity", jQuery(".io_measure_price_raw_measurement").text()); } } function cart_afterAdd(item) { /* Add required Accessories */ let required_accs = jQuery("[id^=io_acc_required_]").filter(function() { return parseInt(this["outerText"]) > 0 && this.parentElement.style['display'] != 'none'; }); required_accs.each(function(index) { simpleCart.parse_html_and_add(this, true); }); /* required_accs.each(function(index) { let parent_element = this.parentElement; let info = {}; if(jQuery(parent_element).find(".io_acc_li_name").length > 0){ info["name"] = jQuery(parent_element).find(".io_acc_li_name")[0].outerText } if(jQuery(parent_element).find(".item_qtyincrement").length > 0){ info["qtyincrement"] = jQuery(parent_element).find(".item_qtyincrement")[0].outerText } if(jQuery(parent_element).find(".item_inputtype").length > 0){ info["inputtype"] = jQuery(parent_element).find(".item_inputtype")[0].outerText } if(jQuery(parent_element).find(".item_vendorid").length > 0){ info["vendorid"] = jQuery(parent_element).find(".item_vendorid")[0].outerText } if(jQuery(parent_element).find(".item_required").length > 0){ info["quantity"] = jQuery(parent_element).find(".item_required")[0].outerText } if(jQuery(parent_element).find(".item_rentalid").length > 0){ info["rentalid"] = jQuery(parent_element).find(".item_rentalid")[0].outerText } if(jQuery(parent_element).find(".io_acc_li_img_thumb")[0]){ info["image"] = jQuery(parent_element).find(".io_acc_li_img_thumb")[0].src } if(jQuery(parent_element).find(".item_accessorydd")[0].outerText != 1){ let rentalid = info["rentalid"]; let split_rid = rentalid.split("_"); if(split_rid.length > 2){ let parent_rid = split_rid[0]+"_"+split_rid[1]; if(jQuery("#io_acc_accessorydd_"+parent_rid)[0].outerText != 1){ simpleCart.add(info, true); } }else{ simpleCart.add(info, true); } } }); */ let selected_values = jQuery("[id^=io_acc_]").filter(function() { return this["selected"]; }); selected_values.each(function() { let info = {}; let rid = jQuery(this).find(".item_rentalid")[0].outerText; let split_rid = rid.split("_"); if(split_rid.length == 3){ let parent_rid = split_rid[1]; let main_item_rid = split_rid[0]; info["acc_dd_parent_limit"] = jQuery("#io_acc_accessorylimit_"+main_item_rid+"_"+parent_rid)[0].outerText; } info["name"] = jQuery(this).find(".io_acc_li_name")[0].outerText info["qtyincrement"] = jQuery(this).find(".item_qtyincrement")[0].outerText info["quantity"] = jQuery(this).find(".item_required")[0].outerText > 0 ? jQuery(this).find(".item_required")[0].outerText : 1; info["rentalid"] = jQuery(this).find(".item_rentalid")[0].outerText if(jQuery(this).find(".io_acc_li_img_thumb")[0]){ info["image"] = jQuery(this).find(".io_acc_li_img_thumb")[0].src } if(jQuery(this).find(".item_accessorydd")[0].outerText != 1){ simpleCart.add(info, true); } }); checkAvailCartOnly(true); let last_upsell_call_time = Date.now() - last_upsell_call; if(in_cart_upsell && last_upsell_call_time > 2000){ let rental_ids = ""; /* Get the last element in the cart. This is the last item added. */ last_added = jQuery("[id^='cartItem_']").last(); if(last_added.length){ last_added_children = last_added.children(); for(let i = 0; i < last_added_children.length; ++i){ if(last_added_children[i].className == "item-rentalid") { rental_ids += last_added_children[i].innerText + "|"; } } } if(rental_ids.length>0 && jQuery("#cartPopover").attr("class") == "cartIn"){ var times = getAvailTimes(); last_upsell_call = Date.now(); getUpsellsCall(times[0],times[1],times[2],rental_ids,updateCartUpsell); } else{ jQuery("#cart-carousel-container").hide(); } } if(io_company_timeslots.length != 0 && io_cartdayselect == "single_day"){ filterTimeslotsByDay_itemTimeslots(); simpleCart.update(); } if (jQuery(".cartInfo.open,.ioCart.open, .ioCart_link.open").length == 0) { setTimeout(function () { cartShow(); }, 100); } if(simpleCart.items().length==0){ jQuery(".simpleCart_checkout").hide() }else{ jQuery(".simpleCart_checkout").show(); } if(simpleCart.items().length > 0){ let headerBookButton = jQuery("a[href$='io_quoteform/']"); headerBookButton.addClass("ioCart_link"); headerBookButton.attr("href", "javascript:;"); } checkRestrictedDeliveries() if(jQuery("#ioInfoHeader").length){ header_increment_step(); } } function cart_afterQtyChange(){ let last_checkAvail_call_time = Date.now() - last_checkAvail_call; if(last_checkAvail_call_time > 2000){ last_checkAvail_call = Date.now(); checkAvailCart(); checkAvailCartTimeslots(); } } function cart_hideTimepickerWrapper(){ jQuery(".ui-timepicker-wrapper").hide(); } function cart_beforeRemove() { last_remove = Date.now(); } function cart_afterRemove(removed_item){ checkAvailCart(); last_upsell_call_time = Date.now() - last_upsell_call; if(in_cart_upsell && last_upsell_call_time > 2000){ rental_ids = getAllRentalIDsFromCart(); if(rental_ids.length>0 && jQuery("#cartPopover").attr("class") == "cartIn"){ var times = getAvailTimes(); last_upsell_call = Date.now(); getUpsellsCall(times[0],times[1],times[2],rental_ids,updateCartUpsell); } else{ jQuery("#cart-carousel-container").hide(); } } /* IO-24060 */ simpleCart.items().forEach(function (item, index) { let expression = '^' + removed_item.get('rentalid') + '(?:[_:]\\d+)*'; if(item.get("rentalid").match(expression)){ item.remove(); } }); checkAvailCartTimeslots(); checkRestrictedDeliveries(); if(simpleCart.items().length==0){ jQuery(".simpleCart_checkout").hide() }else{ jQuery(".simpleCart_checkout").show(); } if(jQuery("#ioInfoHeader").length && simpleCart.items().length == 0){ jQuery("#io-step-3").removeClass("io-step-active"); jQuery("#io-step-2").addClass("io-step-active"); jQuery("#io-step-2").removeClass("io-step-done") } } /**/ /**/ function getFormatteddate(date_obj){ if(dateFormat.substring(0,1)=='d'){ let month = date_obj.getMonth() + 1; formatteddate = date_obj.getDate()+'/'+month+'/'+date_obj.getFullYear(); }else{ let month = date_obj.getMonth() + 1; formatteddate = month+'/'+date_obj.getDate()+'/'+date_obj.getFullYear(); } return formatteddate; } function getFormattedtime(date_obj){ var hour24 = false; var ampm = 'am'; var starttime = jQuery('[name=timeStart]').val(); if(starttime.length>0 && starttime.indexOf('m')==-1) hour24 = true; if(hour24){ //24 hour return return date_obj.getHours()+':'+pad(date_obj.getMinutes(),2); }else{ //12 hour return var hour = date_obj.getHours(); if(hour==12) ampm='pm'; if(hour==0) hour=12; if(hour>12){ hour-=12; ampm='pm'; } return hour+':'+pad(date_obj.getMinutes(),2)+' '+ampm; } } function buildDateobjectstring(date,dateformat,time){ var ampm = 'am'; var hour24 = false; if(typeof date == "undefined") return; if(typeof dateformat == "undefined") return; var start_arr = date.split('/'); if(dateformat.substring(0,1)=='d'){ date = start_arr[2]+'/'+pad(start_arr[1],2)+'/'+pad(start_arr[0],2); }else{ date = start_arr[2]+'/'+pad(start_arr[0],2)+'/'+pad(start_arr[1],2); } if(time.length>0 && time.indexOf('m')==-1) hour24 = true; if(hour24){ try{ var time_arr = time.split(':'); var hour = parseInt(time_arr[0]); var min = pad(time_arr[1], 2); time = hour + ':' + min + ':00'; }catch(err){ time = ""; } }else { try { time = time.replace('am', "").replace(' ', ""); if (time.indexOf('pm') != -1) ampm = 'pm'; time = time.replace('pm', "").replace(' ', ""); var time_arr = time.split(':'); var hour = parseInt(time_arr[0]); var min = pad(time_arr[1], 2); if (ampm == 'pm') { if (hour < 12) hour += 12; } else if (ampm == 'am' && hour == 12) { hour -= 12; } hour = pad(hour, 2); time = hour + ':' + min + ':00'; } catch (err) { time = ""; } } return date+' '+time; } function pad(num, size) { var s = num+""; while (s.length < size) s = "0" + s; return s; } function convertDateStringtoDateObject(date_str, time_str=null){ if(date_str){ split_date_str = date_str.split("/"); /* Parse start and end time. */ if(time_str){ /* Check and see if we are in 12 hour format, if so convert it to 24 hour format. */ split_time_str = convert12HourTo24Hour(time_str); }else{ /* If we do not have a time, then default to zeros */ split_time_str = [0, 0]; } /* Create date object based off our set date format. */ date_obj = buildDateObj(split_date_str, split_time_str); return date_obj; }else{ return new Date(); } } function buildDateObj(split_date_str, split_time_str){ if (dateFormat == "d/m/yy"){ return new Date(split_date_str[2], (+split_date_str[1] - 1).toString(), split_date_str[0], split_time_str[0], split_time_str[1]); }else{ return new Date(split_date_str[2], (+split_date_str[0] - 1).toString(), split_date_str[1], split_time_str[0], split_time_str[1]); } } function convert12HourTo24Hour(time_str){ /* This function returns an array containing hours and minutes of provided string in 24 hour format. */ /* This is primarily used for creating JS Date objects */ split_time = time_str.split(":"); /* We are in 12 hour format if there is an "m" attached to minutes portion. */ if(split_time[1].toLowerCase().search("m") != -1) { let separated_minutes = split_time[1].split(" "); if(separated_minutes.length==1){ split_time[1] = split_time[1].replace("am"," am"); split_time[1] = split_time[1].replace("pm"," pm"); separated_minutes = split_time[1].split(" "); } let minutes = separated_minutes[0]; let modifier = separated_minutes[1]; split_time[1] = minutes; /* First assume that if the hours are 12, then its midnight. */ if(split_time[0] == "12"){ split_time[0] = "00"; } /* Second if there is a "p" in the modifier, then add twelve to the hours. */ if(typeof modifier != "undefined"){ if(modifier.toLowerCase().search("p") != -1){ split_time[0] = (parseInt(split_time[0], 10) + 12); } } } return split_time; } /**/ /**/ function cartShow() { jQuery("#cartPopover").show(); jQuery("#cartPopover").removeClass("cartOut"); jQuery("#cartPopover").addClass("cartIn"); jQuery(".cartInfo,.ioCart,.ioCart_link").addClass("open"); if (/Mobi|Android/i.test(navigator.userAgent)) { document.body.style.overflow = "hidden"; } /* jQuery(this).one("click", cartHide); */ jQuery(".cartInfo").unbind("click").one("click", function(event){ event.stopPropagation(); event.stopImmediatePropagation(); cartHide(); }); jQuery(".ioCart, .ioCart_link").unbind("click").one("click", function(event){ event.stopPropagation(); event.stopImmediatePropagation(); cartHide(); }); jQuery(".cartIcon").removeClass("fa-shopping-cart").addClass("fa-close"); if(simpleCart.items().length==0){ jQuery(".simpleCart_checkout").hide() }else{ jQuery(".simpleCart_checkout").show(); } checkAvailCartOnly(); last_upsell_call_time = Date.now() - last_upsell_call; if(in_cart_upsell && last_upsell_call_time > 2000){ rental_ids = getAllRentalIDsFromCart(); if(rental_ids.length>0 && jQuery("#cartPopover").attr("class") == "cartIn"){ var times = getAvailTimes(); last_upsell_call = Date.now(); getUpsellsCall(times[0],times[1],times[2],rental_ids,updateCartUpsell); } else{ jQuery("#cart-carousel-container").hide(); } } } function cartHide() { jQuery("#cartPopover").removeClass("cartIn"); jQuery("#cartPopover").addClass("cartOut"); if (/Mobi|Android/i.test(navigator.userAgent)) { document.body.style.overflow = "auto"; } /* jQuery("#cartPopover").hide(); */ jQuery(".cartInfo,.ioCart, .ioCart_link").removeClass("open"); /* jQuery(this).one("click", cartShow); */ jQuery(".cartInfo").unbind("click").one("click", function(event){ event.stopPropagation(); event.stopImmediatePropagation(); cartShow(); }); jQuery(".ioCart, .ioCart_link").unbind("click").one("click", function(event){ event.stopPropagation(); event.stopImmediatePropagation(); cartShow(); }); jQuery(".cartIcon").removeClass("fa-close").addClass("fa-shopping-cart"); } /* function set_date_cookie(){ if(this.id.indexOf("start_") !== -1){ setCookie("dateStart", this.value, 14); } else if(this.id.indexOf("end_") !== -1){ setCookie("dateEnd", this.value, 14); } } */ jQuery(document).ready(function () {setTimeout(simpleCart.init, 3);}); /**/ /**/ function checkAvailAll(){ checkAvailCart(); checkAvailCartTimeslots(); checkAvailFilter(); if(addressCookiesSet() && io_distance_charge){ runDeliveryCall(true); } } /**/ /**/ /* for items on page not in cart */ function checkAvailFilter() { let rental_names = ""; let rental_ids = ""; let batch_ids = []; let cart_rental_names = ""; let cart_rental_ids = ""; let item_id = ""; let main_id = ""; jQuery(".item_encoded").each(function(){ rental_names += this.innerText + "|"; }); jQuery(".io_product_infobox .item_rentalid").each(function(){ rental_ids += this.innerText + "|"; item_id = this.innerText; main_id = this.innerText; }); let batch_count = 0; let batch_index = 0; jQuery(".io_item2_list_inner .item_rentalid").each(function(){ /* if(rental_ids.indexOf(this.innerText+"|") == -1){ rental_ids += this.innerText + "|"; } */ if(batch_count < 9){ if(!batch_ids.length) batch_ids.push("") if(!rid_in_batch(this.innerText + "|", batch_ids).length){ batch_ids[batch_index] += this.innerText + "|"; batch_count++; } }else{ if(!rid_in_batch(this.innerText + "|", batch_ids).length){ batch_ids[batch_index] += this.innerText + "|"; batch_index++; batch_count = 0; batch_ids.push(""); } } }); simpleCart.each(function (item, x) { var cart_name = item.get("encoded"); if(cart_name==null){ cart_name = encodeURIComponent(item.get("name")); cart_name = encodeURIComponent(decodeURIComponent(cart_name).replace(/[\u2032\u2019]+/ig,"'")); } let quantity = item.get("quantity"); if(item.get("inputtype") == "Map"){ quantity = 1 } cart_rental_names += cart_name + "-" + quantity + "|"; var cart_id = item.get("rentalid"); cart_rental_ids += cart_id + "-" + quantity + "|"; }); /* #14494 IO-13779 */ let delivery_methods_arr = []; if(io_delivery_prices){ if(Object.keys(io_delivery_prices["override"]).includes(item_id)){ var delivery_prices = io_delivery_prices["override"][item_id] }else{ var delivery_prices = io_delivery_prices["default"] } for(item in io_delivery_methods){ if(delivery_prices.includes(io_delivery_methods[item]["id"])){ delivery_methods_arr.push(item); } } } let custom_prices_arr = []; if(io_custom_prices){ if(Object.keys(io_custom_prices["override"]).includes(item_id)){ custom_prices_arr = io_custom_prices["override"][item_id] }else{ custom_prices_arr = io_custom_prices["default"] } } /* IO-13548 */ if(io_accessory_price == "on"){ let times = getAvailTimes(); let acc_rental_id_str = getAccIDforPrice(); let return_id = 0; if(acc_rental_id_str != ""){ checkAvailCall(times[0],times[1],times[2],rental_names,acc_rental_id_str,displayAccessoryPrices,0,[],[],return_id,0,null,1,"",1); } } let times = getAvailTimes(); if(rental_names.length>0){ if(use_weekday_weekend){ let return_id = 0; let week_weekend = ""; if(rental_ids != ""){ return_id = 1; week_weekend = get_week_weekend_times(times, main_id); checkAvailCall(week_weekend["weekday"][0],week_weekend["weekday"][1],week_weekend["weekday"][2],rental_names,rental_ids,updatePageAvail_weekday,0,cart_rental_ids,cart_rental_names,return_id,1); checkAvailCall(week_weekend["weekend"][0],week_weekend["weekend"][1],week_weekend["weekend"][2],rental_names,rental_ids,updatePageAvail_weekend,0,cart_rental_ids,cart_rental_names,return_id,1); } } let return_id = 0; if(rental_ids != "" || batch_ids.length){ return_id = 1; } if(delivery_methods_arr && (rental_ids != "" || batch_ids.length)){ delivery_methods_arr.forEach(function(delivery_method){ checkAvailCall(times[0],times[1],times[2],rental_names,rental_ids,updatePageAvail_delivery_method,0,cart_rental_ids,cart_rental_names,return_id,1,delivery_method); }); } if(custom_prices_arr && (rental_ids != "" || batch_ids.length)){ custom_prices_arr.forEach(function(custom_price){ let start_date = times[0]; let start_time = times[1]; if(!start_date){ start_date = getFormatteddate(new Date()); } if(!start_time){ start_time = io_default_start_time; } checkAvailCall(start_date,start_time,custom_price['duration'],rental_names,rental_ids,updatePageAvail_custom_price,0,cart_rental_ids,cart_rental_names,return_id,1,"",1,custom_price['name']); }); } if(batch_ids.length){ batch_ids.forEach(function(rids){ return checkAvailCall(times[0],times[1],times[2],"",rids,updatePageAvail,0,cart_rental_ids,cart_rental_names,return_id,1,null,1,"",1); }); }else{ return checkAvailCall(times[0],times[1],times[2],rental_names,rental_ids,updatePageAvail,0,cart_rental_ids,cart_rental_names,return_id,1,null,1); } } } function get_week_weekend_times(times, rid){ /* Create a copy instead of reference.*/ let temp_times = JSON.parse(JSON.stringify(times)); let start_date = temp_times[0]; if(!start_date){ start_date = getFormatteddate(new Date()); temp_times[0] = start_date; } temp_times[1] = io_default_start_time var newDate1 = convertDateStringtoDateObject(start_date, io_default_start_time); var newDate2 = convertDateStringtoDateObject(start_date, io_default_end_time); let time_duration = ((newDate2 - newDate1) / 3600) / 1000; temp_times[2] = time_duration; let day = new Date(start_date).getDay(); let weekday_weekend = {}; weekday_weekend["rid"] = rid; if(io_weekendDefine == "friday-sunday"){ if(day == 5 || day == 6 || day == 0){ weekday_weekend["weekend"] = JSON.parse(JSON.stringify(temp_times)); temp_times[0] = getNextMonday(temp_times[0]); weekday_weekend["weekday"] = JSON.parse(JSON.stringify(temp_times)); }else if(day == 1 || day == 2 || day == 3 || day == 4){ weekday_weekend["weekday"] = JSON.parse(JSON.stringify(temp_times)); temp_times[0] = getNextSaturday(temp_times[0]); weekday_weekend["weekend"] = JSON.parse(JSON.stringify(temp_times)); } }else if(io_weekendDefine == "saturday-sunday"){ if(day == 6 || day == 0){ weekday_weekend["weekend"] = JSON.parse(JSON.stringify(temp_times)); temp_times[0] = getNextMonday(temp_times[0]); weekday_weekend["weekday"] = JSON.parse(JSON.stringify(temp_times)); }else if(day == 1 || day == 2 || day == 3 || day == 4 || day == 5){ weekday_weekend["weekday"] = JSON.parse(JSON.stringify(temp_times)); temp_times[0] = getNextSaturday(temp_times[0]); weekday_weekend["weekend"] = JSON.parse(JSON.stringify(temp_times)); } } return weekday_weekend; } /* helper function found here: https://bobbyhadz.com/blog/javascript-get-date-of-next-monday#:~:text=To%20get%20the%20next%20Monday%2C%20we%3A&text=If%20the%20remainder%20is%20equal,month%20for%20the%20next%20Monday. */ function getNextMonday(date_str) { const date_obj = new Date(date_str); const nextMonday = new Date( date_obj.setDate( date_obj.getDate() + ((7 - date_obj.getDay() + 1) % 7 || 7), ), ); return getFormatteddate(nextMonday); } /* modified from function above */ function getNextSaturday(date_str) { const date_obj = new Date(date_str); const next_friday = new Date( date_obj.setDate( date_obj.getDate() + ((7 - date_obj.getDay() + 6) % 7 || 7), ), ); return getFormatteddate(next_friday); } function updatePageAvail(data){ let use_id = data["return_id"] delete data["return_id"]; if(use_id == 1){ updatePageAvail_itemIDs(data) }else{ updatePageAvail_itemNames(data); } } function updatePageAvail_weekday(data){ jQuery.each(data, function (rental_id, qty){ if (rental_id == "price") { var prices = qty; jQuery.each(prices, function (price_id, amt) { let cust_price = document.querySelector(".io_product_cust_price_weekday"); if(cust_price==undefined){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price_weekday"); cust_price.style.display = "none"; first_price.before(cust_price); } } main_item_id = jQuery(".io_product_infobox .item_rentalid").first().text(); if(main_item_id == price_id && cust_price!=undefined){ if(typeof amt == "string") amt = Number(amt.replace(",","")); cust_price.querySelector("p:nth-child(1)").innerHTML=simpleCart.toCurrency(amt); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = io_weekDayText; if(amt>0){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } }); } function updatePageAvail_delivery_method(data){ var delivery_method = data["delivery_method"] jQuery.each(data, function (rental_id, qty){ if (rental_id == "price") { var prices = qty; jQuery.each(prices, function (price_id, amt) { let cust_price = document.querySelector(".io_product_cust_price_delivery_method"+io_delivery_methods[delivery_method]["id"]); let rid = jQuery(".io_product_container .item_rentalid").first().text(); if(cust_price==undefined && !io_delivery_methods[delivery_method]["restricted"].includes(rid)){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price_delivery_method"+io_delivery_methods[delivery_method]["id"]); cust_price.style.display = "none"; first_price.before(cust_price); } } main_item_id = jQuery(".io_product_infobox .item_rentalid").first().text(); if(main_item_id == price_id && cust_price!=undefined){ if(typeof amt == "string") amt = Number(amt.replace(",","")); cust_price.querySelector("p:nth-child(1)").innerHTML=simpleCart.toCurrency(amt); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = make_live_price_editable_time(times, delivery_method); if(amt>0 && event_time_set()){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } }); } function updatePageAvail_custom_price(data, custom_price_name){ let custom_price_class_name = custom_price_name.replace(/[\s:./]/g, '_'); jQuery.each(data, function (rental_id, qty){ if (rental_id == "price") { var prices = qty; jQuery.each(prices, function (price_id, amt) { let cust_price = document.querySelector(".io_product_cust_price_"+custom_price_class_name); let rid = jQuery(".io_product_container .item_rentalid").first().text(); if(cust_price==undefined){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price_"+custom_price_class_name); cust_price.style.display = "none"; first_price.before(cust_price); } } main_item_id = jQuery(".io_product_infobox .item_rentalid").first().text(); if(main_item_id == price_id && cust_price!=undefined){ if(typeof amt == "string") amt = Number(amt.replace(",","")); cust_price.querySelector("p:nth-child(1)").innerHTML=simpleCart.toCurrency(amt); cust_price.querySelector("p:nth-child(2)").innerHTML = "for " + custom_price_name; if(amt>0){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } }); } function updatePageAvail_weekend(data){ jQuery.each(data, function (rental_id, qty){ if (rental_id == "price") { var prices = qty; jQuery.each(prices, function (price_id, amt) { let cust_price = document.querySelector(".io_product_cust_price_weekend"); if(cust_price==undefined){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price_weekend"); cust_price.style.display = "none"; first_price.before(cust_price); } } main_item_id = jQuery(".io_product_infobox .item_rentalid").first().text(); if(main_item_id == price_id && cust_price!=undefined){ if(typeof amt == "string") amt = Number(amt.replace(",","")); cust_price.querySelector("p:nth-child(1)").innerHTML=simpleCart.toCurrency(amt); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = io_weekEndText; if(amt>0){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } }); } function updatePageAvail_itemIDs(data){ jQuery.each(data, function (rental_id, qty){ if (rental_id == "price" && jQuery(".io_product_infobox .item_inputtype").text() != "Map") { var prices = qty; jQuery.each(prices, function (price_id, amt) { let cust_price = document.querySelector(".io_product_cust_price"); if(cust_price==undefined){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price"); cust_price.style.display = "none"; first_price.before(cust_price); } } main_item_id = jQuery(".io_product_infobox .item_rentalid").first().text(); if(main_item_id == price_id && cust_price!=undefined){ if(typeof amt == "string") amt = Number(amt.replace(",","")); cust_price.querySelector("p:nth-child(1)").innerHTML=simpleCart.toCurrency(amt); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = make_live_price_editable_time(times); if(amt>0 && (event_time_set() || io_always_display_live_price == "on")){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } if(qty<=0 && rental_id != "delivery_method"){ /* cat,all-item,widget */ if(io_checkavail=="warn"){ jQuery(".add_cart_"+rental_id.replace(":", "\\\:")+" .item_add").removeClass("item_add").addClass("item_add_off").trigger("classChange"); jQuery(".unavailable_message_"+rental_id.replace(":", "\\\:")).show(); } if(io_checkavail=="hide") jQuery(".add_cart_"+rental_id).parent().parent().hide(); /* product page */ if(jQuery(".io_product_container").length && io_checkavail!="off" && jQuery(".io_product_container .item_rentalid").first().text() === rental_id){ jQuery(".add_cart_"+rental_id.replace(":", "\\\:")+" .item_add").first().removeClass("item_add").addClass("item_add_off").trigger("classChange"); jQuery(".io_product_container .unavailable_message").show(); } }else if(qty>0){ if(io_checkavail=="warn"){ jQuery(".add_cart_"+rental_id.replace(":", "\\\:")+" .item_add_off").removeClass("item_add_off").addClass("item_add").trigger("classChange"); jQuery(".unavailable_message_"+rental_id.replace(":", "\\\:")).hide(); } if(io_checkavail=="hide") jQuery(".add_cart_"+rental_id).parent().parent().show(); /* product page */ if(jQuery(".io_product_container").length && io_checkavail!="off" && jQuery(".io_product_container .item_rentalid").first().text() === rental_id){ jQuery(".add_cart_"+rental_id.replace(":", "\\\:")+" .item_add_off").removeClass("item_add_off").addClass("item_add").trigger("classChange"); jQuery(".io_product_container .unavailable_message").hide(); } } }); } function updatePageAvail_itemNames(data){ jQuery.each(data, function (rental_name, qty) { rental_name = rental_name.replace(/[\u2032\u2019]+/ig,"'"); var main_name_temp = ""; if(typeof main_name_orig != "undefined"){ main_name_temp = main_name_orig.replace(/[\u2032\u2019]+/ig,"'"); } rental_name_esc = rental_name.replace(/'/g, "\\\\'"); if (rental_name == "price") { var prices = qty; jQuery.each(prices, function (price_name, amt) { /* var prices = document.querySelector(".io_product_price_box:not(.io_product_cust_price)"); */ /* if(prices != null) prices.remove(); */ let cust_price = document.querySelector(".io_product_cust_price"); if(cust_price==undefined){ var first_price = document.querySelector(".io_product_price_box"); if(first_price != null){ cust_price = first_price.cloneNode(true); /* clear all classes */ cust_price.className = ""; cust_price.classList.add("io_product_price_box"); cust_price.classList.add("io_product_cust_price"); cust_price.style.display = "none"; first_price.before(cust_price); } } try{ var main_name = decodeURIComponent(jQuery(".io_product_container .item_encoded").first().html().replace(/[+]/gi, "%20")); }catch(e){main_name=""} var i = main_name.lastIndexOf(":"); let acc_name = ""; let rental_name = ""; var i = main_name.lastIndexOf(":"); if(i>0){ rental_name = main_name.substring(0, i); acc_name = main_name.substring(i+1); } if (acc_name.toUpperCase() == price_name.toUpperCase() && cust_price!=undefined){ var rental_id = document.querySelector(".item_rentalid").innerText; if(rental_id != null){ rid_arr = rental_id.split(":"); /* ignore the main id for this */ rental_id = rid_arr[rid_arr.length-1]; if(jQuery("#io_acc_overrideprice_"+rental_id).first().text()>0){ amt = prices[acc_name]; }else{ let item_price = Number(prices[rental_name].replace(",","")); amt = Number(amt.replace(",","")) + item_price; amt = simpleCart.toCurrency(amt, {symbol:""}) } } cust_price.querySelector("p:nth-child(1)").innerText="$"+amt; if(typeof amt == "string") amt = Number(amt.replace(",","")); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = make_live_price_editable_time(times); if(amt>0 && (event_time_set() || io_always_display_live_price == "on")){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } }else if(!rental_name && !acc_name && cust_price!=undefined){ amt = prices[main_name]; cust_price.querySelector("p:nth-child(1)").innerText="$"+amt; if(typeof amt == "string") amt = Number(amt.replace(",","")); let times = getAvailTimes(); cust_price.querySelector("p:nth-child(2)").innerHTML = make_live_price_editable_time(times); if(amt>0 && (event_time_set() || io_always_display_live_price == "on")){ cust_price.style.display = "grid"; }else{ cust_price.style.display = "none"; } } }); } if(qty<=0){ /* cat,all-item,widget */ if(io_checkavail=="warn"){ jQuery("div[name='maindiv_"+rental_name_esc+"'] .item_add").removeClass("item_add").addClass("item_add_off").trigger("classChange"); jQuery("div[name='maindiv_"+rental_name_esc+"'] .unavailable_message").show(); } if(io_checkavail=="hide") jQuery("div[name='maindiv_"+rental_name_esc+"']").hide(); /* product page */ if(jQuery(".io_product_container").length && io_checkavail!="off"){ if(main_name_temp==rental_name){ jQuery(".io_product_container .item_add").first().removeClass("item_add").addClass("item_add_off").trigger("classChange"); jQuery(".io_product_container .unavailable_message").show(); } } }else if(qty>0){ /* console.log("good"); */ if(io_checkavail=="warn"){ jQuery("div[name='maindiv_"+rental_name_esc+"'] .item_add_off").removeClass("item_add_off").addClass("item_add").trigger("classChange"); jQuery("div[name='maindiv_"+rental_name_esc+"'] .unavailable_message").hide(); } if(io_checkavail=="hide") jQuery("div[name='maindiv_"+rental_name_esc+"']").show(); /* product page */ if(jQuery(".io_product_container").length && io_checkavail!="off"){ if(main_name_temp==rental_name){ jQuery(".io_product_container .item_add_off").removeClass("item_add_off").addClass("item_add").trigger("classChange"); jQuery(".io_product_container .unavailable_message").hide(); } } } }); } function displayAccessoryPrices(data){ if(data.price){ let acc_prices = data.price; for (const [key, value] of Object.entries(acc_prices)) { let new_key = key; if((key.match(/_/g)||[]).length > 1){ let split_key = key.split("_"); let second_to_last = split_key[split_key.length-2]; let last = split_key[split_key.length-1]; new_key = second_to_last+"_"+last; } if(io_hide_zero == 1 && value > 0){ let id_string = "#io_acc_desc_" + new_key; let formatted_price = simpleCart.toCurrency(value); if(jQuery("#io_acc_"+new_key+" .io_acc_price").length > 0){ jQuery("#io_acc_"+new_key+" .io_acc_price").html(formatted_price); }else{ let price_display =' '+formatted_price+' '; jQuery(id_string).after(price_display); } }else if(io_hide_zero == 0){ let id_string = "#io_acc_desc_" + new_key; let formatted_price = simpleCart.toCurrency(value); if(jQuery(".io_acc_price").length > 0){ jQuery(".io_acc_price").html(formatted_price); }else{ let price_display =' '+formatted_price+' '; jQuery(id_string).after(price_display); } } } } } function make_live_price_editable_time(times, delivery_method=null) { if(!delivery_method) delivery_method = getCookie("io_delivery_method"); let ele_text = ""; if(times[0]) ele_text = "on " + times[0] + " "; if(times[2] === 0) times[2] = 1; if(io_hidetimes!="on" && !isNaN(times[2])) ele_text += "for "+times[2]+" hours "; if(delivery_method) ele_text += "for " + delivery_method + ". "; ele_text += 'edit'; return ele_text; } function checkAvailDateClick(){ cartShow(); /* expand the date picker */ setTimeout(calSetDateRange,100); } function checkAvailPageOnly(){ checkAvailFilter(); if(addressCookiesSet() && io_distance_charge){ runDeliveryCall(true); } } function getAccIDforPrice(){ let accessory_arr = jQuery(".io_acc_li").toArray(); let acc_rental_id_str = ""; for(let current_accessory = 0; current_accessory < accessory_arr.length; current_accessory++){ let required_tag = jQuery(accessory_arr[current_accessory]).find(".item_required"); if(required_tag.length > 0){ if(required_tag[0].innerText == 0){ acc_rental_id_str += jQuery(accessory_arr[current_accessory]).find(".item_rentalid")[0].innerText +"|"; } } } return acc_rental_id_str; } function getUpsellIDforPrice(){ let upsell_arr = jQuery(".page-carousel-rid").toArray(); let upsell_rental_id_str = ""; for(let current_upsell = 0; current_upsell < upsell_arr.length; current_upsell++){ upsell_rental_id_str +=upsell_arr[current_upsell].innerText+"|"; } return upsell_rental_id_str; } function displayUpsellPrices(data){ if(data.price){ let upsell_prices = data.price; for (const [key, value] of Object.entries(upsell_prices)) { if(io_hide_zero == 1 && value > 0){ let id_string = "#rid"+ key; let formatted_price = simpleCart.toCurrency(value); let price_display =' '+formatted_price+' '; jQuery(id_string).after(price_display); }else if(io_hide_zero == 0){ let id_string = "#rid"+ key; let formatted_price = simpleCart.toCurrency(value); let price_display =' '+formatted_price+' '; jQuery(id_string).after(price_display); } } pageFlickityRefresh(); } } /**/ /**/ function checkAvailCartOnly(skip_timer=false){ checkAvailCart(); checkAvailCartTimeslots(); if(addressCookiesSet() && io_distance_charge){ runDeliveryCall(true); } } function checkAvailCartTimeslots(){ let rental_names = ""; let rental_ids = ""; let cart_rental_names = ""; let cart_rental_ids = ""; let times = getAvailTimes(); let start_date = times[0]; let event_duration = times[2]; let end_date = start_date; var event_start_time = getCookie("timeStart"); simpleCart.each(function (item, x) { var timeslots_html = item.get('timeslots'); if(typeof timeslots_html == "undefined") return; if(timeslots_html.length == 0) return; var cart_name = item.get("encoded"); if(cart_name==null) { cart_name = encodeURIComponent(item.get("name")); cart_name = encodeURIComponent(decodeURIComponent(cart_name).replace(/[\u2032\u2019]+/ig,"'")); } rental_id = item.get("rentalid"); var timeslot_name = getTimeslotName(timeslots_html); var timeslot_sel_range = jQuery(".item-timeslots [name=\""+timeslot_name+"\"] option:selected").val(); if(typeof timeslot_sel_range != "undefined"){ /* timeslots */ setTimeslotSelected(item, timeslot_name); }else{ /* timepickers */ setTimePicker(item, timeslot_name); let start_timepicker = document.getElementsByName(timeslot_name.replace("io_timepicker_", "start_timeslot_")); let end_timepicker = document.getElementsByName(timeslot_name.replace("io_timepicker_", "end_timeslot_")); timeslot_sel_range = start_timepicker[start_timepicker.length-1].value; timeslot_sel_range += " - " + end_timepicker[end_timepicker.length-1].value; } var timeslot_sel_arr = ""; if(typeof timeslot_sel_range != "undefined"){ var [start_time, end_time] = break_timeslot_sel_range(timeslot_sel_range); if(start_time && end_time){ let newDate1 = convertDateStringtoDateObject(start_date, start_time); let newDate2 = convertDateStringtoDateObject(end_date, end_time); let time_duration = ((newDate2 - newDate1) / 3600) / 1000; let quantity = item.get("quantity"); if(item.get("inputtype") == "Map"){ quantity = 1 } rental_names += cart_name + "-" + quantity+"|"; rental_ids += rental_id+"-"+quantity+"-"+start_time+"-"+time_duration+"|"; cart_rental_names = rental_names; cart_rental_ids = rental_ids; } } }); if(rental_ids || rental_names){ checkAvailCall(start_date,event_start_time,event_duration,rental_names,rental_ids,updateCartAvail,1,cart_rental_ids,cart_rental_names,1); } return true; } function checkAvailCart(){ let rental_names = ""; let rental_ids = ""; let cart_rental_names = ""; let cart_rental_ids = ""; simpleCart.each(function (item, x) { if(typeof item.get('timeslots') != "undefined"){ if(item.get('timeslots').length > 0){ return; } } var cart_name = item.get("encoded"); if(cart_name==null){ cart_name = encodeURIComponent(item.get("name")); cart_name = encodeURIComponent(decodeURIComponent(cart_name).replace(/[\u2032\u2019]+/ig,"'")); } let quantity = item.get("quantity"); if(item.get("inputtype") == "Map"){ quantity = 1 } rental_names += cart_name + "-" + quantity + "|"; cart_rental_names += cart_name + "-" + quantity + "|"; var cart_id = item.get("rentalid"); rental_ids += cart_id + "-" + quantity + "|"; cart_rental_ids += cart_id + "-" + quantity + "|"; }); var times = getAvailTimes(); let return_id = 0; if(rental_ids != ""){ return_id = 1; } return checkAvailCall(times[0],times[1],times[2],rental_names,rental_ids,updateCartAvail,1,cart_rental_ids,cart_rental_names,return_id); } function updateCartAvail(data){ let use_id = data["return_id"] delete data["return_id"]; if(use_id == 1){ updateCartAvail_itemIDs(data) }else{ updateCartAvail_itemNames(data); } console.log("cart update"); /* simpleCart.trigger("update"); */ simpleCart.update(); /* jQuery("#avail").html(output); */ } function updateCartAvail_itemIDs(data){ jQuery.each(data, function (rental_id, qty){ simpleCart.each(function (item, x) { if(rental_id == item.get("rentalid")){ if(io_hideQuantityAvail == "off"){ if(qty>=9999 || item.get("inputtype") == "Map" || (item.get("giftcardvalue") && item.get("giftcardvalue").trim())){ item.set("availability", "available"); }else{ item.set("availability", qty + " available"); } }else if(io_hideQuantityAvail == "on"){ if(qty<=0){ item.set("availability", "not available"); }else{ item.set("availability", "available"); } } var vendorid = item.get("vendorid"); if(vendorid && vendorid.trim()){ item.set("availability", "availability must be verified"); } } if (rental_id == "price") { var prices = qty; jQuery.each(prices, function (price_name, amt) { if(price_name == item.get("rentalid")){ if (typeof amt == "string" || amt instanceof String){ if(amt != "TBD"){ if(typeof amt == "string") amt = Number(amt.replace(",","")); } } item.set("price", amt); } }); } }); }); } function updateCartAvail_itemNames(data){ jQuery.each(data, function (rental_name, qty) { rental_name = rental_name.replace(/[\u2032\u2019]+/ig,"'"); simpleCart.each(function (item, x) { try{ var cart_name = decodeURIComponent(item.get("encoded").replace(/[+]/gi, "%20")); }catch(e){cart_name=null} if(cart_name==null) cart_name = item.get("name") cart_name = cart_name.replace(/[\u2032\u2019]+/ig,"'"); var i = cart_name.lastIndexOf(":"); if(i>0 && cart_name.toUpperCase() != rental_name.toUpperCase() && rental_name!="price"){cart_name = cart_name.substring(i+1)} if (cart_name.toUpperCase() == rental_name.toUpperCase()) { if(qty>9999){ item.set("availability", "available"); }else{ item.set("availability", qty + " available"); } } if (rental_name == "price") { var prices = qty; jQuery.each(prices, function (price_name, amt) { price_name = price_name.replace(/[\u2032\u2019]+/ig,"'"); let acc_name = ""; let rental_name = ""; var i = cart_name.lastIndexOf(":"); if(i>0){ rental_name = cart_name.substring(0, i); acc_name = cart_name.substring(i+1); } if (acc_name === price_name) { var rental_id = item.get("rentalid"); if(rental_id != null){ rid_arr = rental_id.split(":"); /* ignore the main id for this */ rental_id = rid_arr[rid_arr.length-1]; if(jQuery("#io_acc_overrideprice_"+rental_id).first().text()>0){ amt = prices[acc_name]; }else{ let item_price = Number(prices[rental_name].replace(",","")); amt = Number(amt.replace(",","")) + item_price; item.set("price", amt); return; } } if(amt==null){ amt = "0"; } /* returned price is per unit */ if(typeof amt == "string") amt = Number(amt.replace(",","")); item.set("price", amt); }else if(!rental_name && !acc_name){ amt = Number(prices[cart_name].replace(",","")); item.set("price", amt); } }); } }); }); } /**/ /**/ function updateCartUpsell(data){ let cart_carousel = jQuery(".cart-carousel"); viewport = jQuery(".cart-carousel .flickity-viewport"); if(viewport.length > 0){ cart_carousel.flickity("destroy"); } cart_carousel.empty(); data.forEach(function(upsell){ cell = createCartCarouselCell(upsell["image"], upsell["name"], upsell["page"]); cart_carousel.append(cell); }); makeCarousel(cart_carousel); jQuery("#cart-carousel-container").show(); setTimeout(cartFlickityRefresh, 500); } function cartFlickityRefresh(){ jQuery(".cart-carousel").flickity("resize"); } function makeCarousel(cart_carousel){ cart_carousel.flickity({ wrapAround: true, draggable: false, cellAlign: 'left', //autoPlay: 3000, groupCells: true, resize: true }); cart_carousel_set = true; } function createCartCarouselCell(image, name, page){ cell = ''; return cell; } /**/ /**/ function checkAvailCall(start_date,start_time,time_duration,rental_names,rental_ids,returnFunc,singleCart,cart_rental_ids,cart_rental_names,return_id,temp=0,delivery_method=null,price_only=0,custom_price_name="", skip_hidden_lead = 0) { /* IO-21459 If we have no duration set (event not set in cart), and we are doing the call for the page live price, and we have the setting on where we want to display this price even if the event date is not set: We set the time_duration to 1 hour. This defaults the start date to January 1, 1970 with duration of 1 hour in the lead meaning it will be available and we have the one hour price. */ if((isNaN(time_duration) || time_duration===0) && price_only==1 && io_always_display_live_price == "on"){ time_duration = 1; }else if((isNaN(time_duration) || time_duration===0) && price_only==0 && io_hidetimes === "on"){ /* IO-22689 if they have times hidden, and happen to have the same default start and end time, we still want to do the call. */ time_duration = 1; }else if(isNaN(time_duration) || time_duration===0){ return; } url = "https://rental.software/quotes/check_availability_v2.php?callback=?"; if(window.location.href.indexOf("localhost") > -1){ //url = "http://localhost/bugs/quotes/check_availability_v2.php?callback=?"; url = "http://localhost/io/bugs/quotes/check_availability_v2.php?callback=?"; //url = "http://localhost/jbug/trunk/quotes/check_availability_v2.php?callback=?"; } if(!delivery_method) delivery_method = getCookie("io_delivery_method"); let address_data = { "address": getCookie("address"), "state": getCookie("state"), "city": getCookie("city"), "zip": getCookie("zip") }; url += "&name=" + encodeURIComponent("KidZone Party Rentals") + "&startdate=" + start_date + "&starttime=" + start_time + "&duration=" + time_duration + "&street=" + encodeURIComponent(address_data["address"]) + "&city=" + encodeURIComponent(address_data["city"]) + "&state=" + encodeURIComponent(address_data["state"]) + "&zip=" + encodeURIComponent(address_data["zip"]) + "&single_cart=" + singleCart + "&usecushion=1" + "&include_price=1" + "&showlocations=0" + "&rental_names=" + rental_names + "&rental_ids=" + rental_ids + "&cart_rental_names=" + cart_rental_names + "&cart_rental_ids=" + cart_rental_ids + "&return_id=" + return_id + "&delivery_method=" + delivery_method + "&temp=" + temp + "&skip_hidden_lead="+ skip_hidden_lead; if(custom_price_name){ jQuery.getJSON(url, function(data) { returnFunc(data, custom_price_name); }); }else{ jQuery.getJSON(url, returnFunc); } } function getUpsellsCall(start_date,start_time,time_duration,rental_ids,returnFunc) { if(rental_ids.replace(/[|]/g,"").length==0){return;} url = "https://rental.software/quotes/in_cart_upsell.php?callback=?"; if(window.location.href.indexOf("localhost") > -1){ //url = "http://localhost/bugs/quotes/in_cart_upsell.php?callback=?" url = "http://localhost/io/bugs/quotes/in_cart_upsell.php?callback=?" } url += "&name=" + encodeURIComponent("KidZone Party Rentals") + "&startdate=" + start_date + "&starttime=" + start_time + "&duration=" + time_duration + "&usecushion=1" + "&include_price=1" + "&showlocations=0" + "&rental_ids=" + rental_ids; //IO-25557 if(window.location.href.indexOf("dev.rental.software") > -1)//if it is a dev site, we need to send { let pattern = /(https:\/\/dev\.rental\.software\/[^\/]+\/)/; let matches = window.location.href.match(pattern); matches && matches.length > 0 ? url += "&site=" + matches[0]:0; } else { url += "&site=" + window.location.host; } jQuery.getJSON(url, returnFunc); } /**/