/* Ascent JavaScript Functions */ /* Harold Asbridge */ /* Blue Lantern, Inc. */ // Image rollover function btnSwap(element, filename) { var temp = new Image(); temp.src = "images/buttons/" + filename + ".jpg"; element.src = temp.src; } function navSwap(element, filename) { var temp = new Image(); temp.src = "images/nav/" + filename + ".jpg"; element.src = temp.src; } // Populate shipping information function checkoutSameAsAbove(isSame) { if (isSame) { getElement("s_address").value = getElement("b_address").value; getElement("s_city").value = getElement("b_city").value; getElement("s_state").selectedIndex = getElement("b_state").selectedIndex; getElement("s_zip").value = getElement("b_zip").value } else { getElement("s_address").value = ""; getElement("s_city").value = ""; getElement("s_state").selectedIndex = 0; getElement("s_zip").value = ""; } } //Update SubTotal function updateSubTotal(productID,qty) { if (qty > 0) { var bottlePrice = 0; var subTotal = 0; var shipping = 0; if (productID == 4) bottlePrice = 5.00; if (productID == 4) shipping = 0.00; if (productID == 2) bottlePrice = 120.00; if (productID == 2 && qty <= 99999) shipping = 10.00; if (productID == 1) bottlePrice = 8.99; if (productID == 1 && qty <= 2) shipping = 3.99; if (productID == 3) bottlePrice = 15.00; if (productID == 3) shipping = 0.00; if (productID == 5) bottlePrice = 9.99; if (productID == 5 && qty <= 2) shipping = 4.50; shipping = shipping * qty; var subTotal = bottlePrice * parseInt(qty); subTotal = subTotal + shipping; getElement("subtotal").innerHTML = formatCurrency(subTotal); } if (qty > 1){ getElement("shippingtext").innerHTML = "Free!"; } else { getElement("shippingtext").innerHTML = "0.00"; } } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } // Get Element function getElement(elementId) { return document.getElementById(elementId); } function updatePriceTable() { var productID = getElement("productID").value; var bottlePrice = 0; var bottleShipping = 0; var subTotal = 0; var shipping = 0; var qty = getElement("qty").value; var shipping = 0; var freeShippingMin = 0; if (productID == 4) { bottlePrice = '5.00'; bottleShipping = '0.00'; freeShippingMin = '0'; } if (productID == 2) { bottlePrice = '120.00'; bottleShipping = '10.00'; freeShippingMin = '99999'; } if (productID == 1) { bottlePrice = '8.99'; bottleShipping = '3.99'; freeShippingMin = '2'; } if (productID == 3) { bottlePrice = '15.00'; bottleShipping = '0.00'; freeShippingMin = '0'; } if (productID == 5) { bottlePrice = '9.99'; bottleShipping = '4.50'; freeShippingMin = '2'; } if (qty >= freeShippingMin && freeShippingMin != 0){ shipping = 0; } else { shipping = bottleShipping; } var subTotal = (parseFloat(bottlePrice) + parseFloat(shipping)) * parseInt(qty); if (shipping == 0) { getElement("shippingtext").innerHTML = "FREE"; } else { getElement("shippingtext").innerHTML = formatCurrency(shipping); } getElement("productPrice").innerHTML = formatCurrency(bottlePrice); getElement("subTotal").innerHTML = formatCurrency(subTotal); } function shippingSameAsBilling(isSame) { getElement("shippingInformation").style.display = (isSame) ? "none" : "block"; } function cardSameAsBilling(isSame) { if (isSame) { if (getElement("chkCardSameAsShipping")) getElement("chkCardSameAsShipping").checked = false; getElement("cardHolderInformation").style.display = "none"; } else { if (getElement("chkCardSameAsShipping")) { if (!getElement("chkCardSameAsShipping").checked) { getElement("cardHolderInformation").style.display = "block"; } } else { getElement("cardHolderInformation").style.display = "block"; } } } function cardSameAsShipping(isSame) { if (isSame) { if (getElement("chkCardSameAsBilling")) getElement("chkCardSameAsBilling").checked = false; getElement("cardHolderInformation").style.display = "none"; } else { if (getElement("chkCardSameAsBilling")) { if (!getElement("chkCardSameAsBilling").checked) { getElement("cardHolderInformation").style.display = "block"; } } else { getElement("cardHolderInformation").style.display = "block"; } } } function useOtherPaymentMethod(useOther) { if (useOther) { getElement("creditCardForm").style.display = "none"; } else { getElement("creditCardForm").style.display = "block"; } }