var items = new Array(); var VARIATION_TYPE_NAME = ""; var VARIATION_TYPE_VALUE = ""; function SetItems(name, value, ite)
{
VARIATION_TYPE_NAME = name; VARIATION_TYPE_VALUE = value; items = ite; }
function updatePackagesPerDay(obj)
{
var tbody = $("auto-generate-auto-delivery"); var input = $("auto-generate-auto-delivery-textbox"); var head = $("variation_type_autodelivery"); head.innerHTML = VARIATION_TYPE_NAME; var value = 0; if (input.value == "")
{
$("auto-delivery-table-header-tbody").hide(); tbody.update(""); return; }
else
{
if (input.value != null && !isNaN(parseInt(input.value, 10)))
{
value = parseInt(input.value, 10); if (value < 1)
{
alert("Please enter a positive number of diapers used per day."); return; }
}
else
{
alert("Please enter a valid number of the number of diapers used per day. Thank You!"); return; }
}
$("auto-delivery-table-header-tbody").show(); tbody.update(""); for (var i = 0; i < items.length; i++)
{
var className = "auto_delivery_popup_info_" + (i % 2); var row = tbody.insertRow(-1); row.className = className; var cell1 = row.insertCell(-1); cell1.appendChild(document.createTextNode(items[i].size)); var cell2 = row.insertCell(-1); cell2.appendChild(document.createTextNode(items[i].perpkg)); var cell4 = row.insertCell(-1); var cell3 = row.insertCell(-1); cell3.appendChild(document.createTextNode("$" + (items[i].price / (parseFloat(items[i].perpkg) + 0.00)).toFixed(2))); cell4.className = "ez-green-cell"; var result = ""; var weeks = (1.0 / (value / items[i].perpkg)) / 7.0; cell4.setAttribute("variant", items[i].variation_name); cell4.sku = items[i].sku; cell4.variation_name = items[i].size; if (weeks < 2.5)
{
weeks = (1.0 / (value / items[i].perpkg)) / 7.0; result = "Order " + Math.ceil(3.0 / weeks) + " every 3 weeks"; cell4.setAttribute("total", Math.ceil(3.0 / weeks)); cell4.onclick = function(e)
{
SelectRepl("3-1", this.getAttribute("total"), this.getAttribute("variant"), this.sku, this.variation_name); }; }
else if (weeks < 3.5)
{
result = "Order 1 every 3 weeks"; cell4.onclick = function(e)
{
SelectRepl("3-1", 1, this.getAttribute("variant"), this.sku, this.variation_name); }; }
else if (weeks < 7.5)
{
result = "Order 1 every " + Math.floor(weeks) + " weeks"; cell4.setAttribute("total", weeks); cell4.onclick = function(e)
{
SelectRepl(this.getAttribute("total") + "-1", 1, this.getAttribute("variant"), this.sku, this.variation_name); }; }
else if (weeks < 8.5)
{
result = "Order 1 every 2 months"; cell4.onclick = function(e)
{
SelectRepl("2-2", 1, this.getAttribute("variant"), this.sku, this.variation_name); }; }
else
{
result = "Order 1 every 3 months"; cell4.onclick = function(e)
{
SelectRepl("3-2", 1, this.getAttribute("variant"), this.sku, this.variation_name); }; }
cell4.style.cursor = 'pointer'; var img = document.createElement("img"); img.src = "/icons/ba/ezdelivery/small_cart_button.png"; img.title = "Add this selection to your shopping cart"; img.alt = "Add To Cart"; img.style.cssFloat = 'right'; img.style.marginRight = '4px'; img.onclick = function(e)
{
cell4.onclick(); $('ez-delivery-popup-button').up("form").down('input[name="btnSubscribe"]').click(); return false; }; cell4.appendChild(img); cell4.appendChild(document.createTextNode(result)); row.appendChild(cell1); row.appendChild(cell2); row.appendChild(cell4); row.appendChild(cell3); tbody.appendChild(row); }
}
function ShowAutoDeliveryPopup(obj, productname)
{
var popup = $("ez-delivery-wrap"); updatePackagesPerDay(obj); popup.show(); $("auto-generate-auto-delivery-textbox").focus(); popup.clonePosition(obj, { setWidth: false, setHeight: false, offsetLeft: -20, offsetTop: -20 }); return; }
function HideAutoDeliveryPopup(obj)
{
var popup = document.getElementById("ez-delivery-wrap"); popup.hide(); return true; }
function SelectRepl(option_value, quantity, variation, sku, name)
{
var select = document.getElementsByName("rdoReplenishmentFrequency")[0]; for (var i = 0; i < select.options.length; i++)
{
if (select.options[i].value == option_value)
{
select.options[i].selected = true; }
else
{
select.options[i].selected = false; }
}
var textbox = document.getElementsByName("txtProductQuantity")[0]; textbox.value = quantity; var obj = $$('.variation-body a[title="' + name + '"]')[0]; if (sku.v && sku.v[0]) {
bjx_sel_var(obj, name, 'img_prod_main', sku.v[0].t.id, sku.v[0].id); }
HideAutoDeliveryPopup(null); }
