var loadingDivInnerHTMLSwap; var domainsInCart = new Array(); var doNotRestLoadingDiv = 0; var testCount = 0; function handleProductTypeLevelOverride(checked, productType, name) { if(checked) { getURL('/products-pricing/services/productCart.php?action=removetype&type='+productType+"&name="+name, handleProductTypeLevelOverrideHandler); } else { getURL('/products-pricing/services/productCart.php?action=getaddonextendedinfo&type='+productType+"&name="+name, handleProductTypeLevelOverrideHandler); } } function handleProductTypeLevelOverrideHandler(status, content, contentType) { if(status != 200 && status != 0) { return; } var results = eval('('+content+')'); if(!results["status"]) { return; } if(!results["addonExtendedInfo"]) return; var levelOverride = results["addonExtendedInfo"]["levelOverride"]; var name = results["name"]; for(var i = 0; i < levelOverride.length; i++) { var elementId = levelOverride[i]+"_"+name; if(document.getElementById(elementId)) { document.getElementById(elementId).checked = false; document.getElementById(elementId).disabled = (document.getElementById(elementId).disabled) ? false : true ; } } } function isMouseLeaveOrEnter(e, handler) { if(e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); } function createCustomPopupDiv(event, id, parentId, className, content) { var newDiv = document.createElement("div"); var parent = document.getElementById(parentId); if(className) newDiv.setAttribute("class", className); newDiv.setAttribute("id", id); if(event) { var cursorPosition = getCursorPosition(event); newDiv.style.left = cursorPosition.x; newDiv.style.top = cursorPosition.y; } newDiv.innerHTML = unescape(content); parent.appendChild(newDiv); newDiv.style.display = "block"; } function destroyCustomPopupDiv(id, parentId) { if(document.getElementById(id) && document.getElementById(parentId)) { parentObj = document.getElementById(parentId); childObj = document.getElementById(id); parentObj.removeChild(childObj); } } function getCursorPosition(e) { e = e || window.event; var cursor = {x:0, y:0}; if (e.pageX || e.pageY) { cursor.x = e.pageX; cursor.y = e.pageY; } else { var de = document.documentElement; var b = document.body; cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0); cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0); } return cursor; } function insertCartRow(referenceNode, name, type, duration, privateWhois, googleApps, price, cartRowId, tag, displayType) { if(!referenceNode) return; if(document.getElementById("tr_"+type+"_"+name)) { deleteTableRow("tr_"+type+"_"+name, "cartTable"); return; } var parent = referenceNode.parentNode.parentNode.getElementsByTagName("TBODY")[0]; var originalName = name; var newRow = document.createElement("TR"); newRow.setAttribute("id", "tr_"+type+"_"+name); newRow.setAttribute("class", "even"); newRow.style.height = "25px"; var td1 = document.createElement("TD"); var td2 = document.createElement("TD"); var td3 = document.createElement("TD"); var td4 = document.createElement("TD"); var td5 = document.createElement("TD"); var td6 = document.createElement("TD"); var td7 = document.createElement("TD"); newRow.appendChild(td1); newRow.appendChild(td2); newRow.appendChild(td3); newRow.appendChild(td4); newRow.appendChild(td5); newRow.appendChild(td6); newRow.appendChild(td7); var privateWHoisHtml = ""; var googleAppsHtml = ""; var priceHtml = ""+price+""+price+""; var removeHtml = "remove"; var durationControlsHtml = " year(s) [ - / + ] "; if(privateWhois) privateWhoisHtml = ""; else privateWhoisHtml = "n/a"; if(googleApps) googleAppsHtml = ""; else googleAppsHtml = "n/a"; if(!displayType) displayType = type; if(type == "google_apps_support_level_1") { durationControlsHtml = " domain(s)"; } else if(type == "google_apps") { durationControlsHtml = " domain(s)"; } td1.innerHTML = name; td2.innerHTML = removeHtml; td3.style.whiteSpace = "nowrap"; td3.innerHTML = displayType; td4.innerHTML = ""+duration+""+durationControlsHtml; td5.innerHTML = privateWhoisHtml; td6.innerHTML = googleAppsHtml; td7.innerHTML = priceHtml; td5.style.textAlign = "center"; td6.style.textAlign = "center"; td7.style.textAlign = "right"; parent.insertBefore(newRow, referenceNode.nextSibling); } String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } function processPromoCode(event) { if(event && event.keyCode != "13") return; if(!document.getElementById("promo_code")) return; var promoCode = document.getElementById("promo_code").value.trim(); document.getElementById("span_promo_code").style.display = "none"; document.getElementById("span_processing_promo").style.display = ""; document.getElementById("span_checkoutSavings").style.color = "#000000"; document.getElementById("tr_checkoutSavings").style.display = "none"; getURL('/products-pricing/services/productCart.php?action=processpromocode&promoCode='+promoCode, processPromoCodeHandler); } function processPromoCodeHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); document.getElementById("span_promo_code").style.display = ""; document.getElementById("span_processing_promo").style.display = "none"; return; } if(!content) return; var results = eval('('+content+')'); var promoCodeApplicationArray = results["promoCodeApplicationArray"]; var promoCodeApplicationArrayLength = promoCodeApplicationArray.length; for(var i = 0; i < promoCodeApplicationArrayLength; i++) { if(document.getElementById("span_checkoutProductPrice_"+promoCodeApplicationArray[i]["domain"])) { document.getElementById("span_checkoutProductPrice_"+promoCodeApplicationArray[i]["domain"]).innerHTML = formatCurrency((document.getElementById("span_checkoutProductPriceHidden_"+promoCodeApplicationArray[i]["domain"]).innerHTML - promoCodeApplicationArray[i]["savings"]), true); if(promoCodeApplicationArray[i]["savings"]) document.getElementById("span_checkoutProductPrice_"+promoCodeApplicationArray[i]["domain"]).style.color = 'red' else document.getElementById("span_checkoutProductPrice_"+promoCodeApplicationArray[i]["domain"]).style.color = '#000000' } if(document.getElementById("span_checkoutProductPriceHiddenAlternative_"+promoCodeApplicationArray[i]["domain"])) { document.getElementById("span_checkoutProductPriceAlternative_"+promoCodeApplicationArray[i]["domain"]).innerHTML = formatCurrency((document.getElementById("span_checkoutProductPriceHiddenAlternative_"+promoCodeApplicationArray[i]["domain"]).innerHTML - promoCodeApplicationArray[i]["savings"]), true); if(promoCodeApplicationArray[i]["savings"]) document.getElementById("span_checkoutProductPriceAlternative_"+promoCodeApplicationArray[i]["domain"]).style.color = 'red' else document.getElementById("span_checkoutProductPriceAlternative_"+promoCodeApplicationArray[i]["domain"]).style.color = '#000000' } } if(!results["productTotalPrice"]) results["productTotalPrice"] = 0; if(!results["status"]) { if(document.getElementById("span_checkoutSavings")) document.getElementById("span_checkoutSavings").innerHTML = formatCurrency(0, true); if(document.getElementById("span_checkoutTotalCost")) document.getElementById("span_checkoutTotalCost").innerHTML = formatCurrency(results["productTotalPrice"], true); if(results["message"]) alert(results["message"]); document.getElementById("span_promo_code").style.display = ""; document.getElementById("span_processing_promo").style.display = "none"; return; } var savings = results["savings"]; if(document.getElementById("span_checkoutSavings")) { document.getElementById("span_checkoutSavings").innerHTML = formatCurrency(savings, true); if(savings) { document.getElementById("span_checkoutSavings").style.color = "red"; document.getElementById("tr_checkoutSavings").style.display = ""; } } if(document.getElementById("span_checkoutTotalCost")) document.getElementById("span_checkoutTotalCost").innerHTML = formatCurrency(results["productTotalPrice"], true); currentPromoCode = results["promoCode"]; document.getElementById("span_promo_code").style.display = ""; document.getElementById("span_processing_promo").style.display = "none"; } function adjustCartDuration(operator, cartId) { document.getElementById("span_durationControls_"+cartId).style.display = "none"; document.getElementById("span_durationLoading_"+cartId).style.display = ""; getURL('/products-pricing/services/productCart.php?action=adjustcartduration&operator='+operator+'&cartId='+cartId, adjustCartDurationHandler); } function adjustCartDurationHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); return; } var results = eval('('+content+')'); var id = results["cartItemId"]; if(!results["status"]) { document.getElementById("span_durationControls_"+id).style.display = ""; document.getElementById("span_durationLoading_"+id).style.display = "none"; alert(results["message"]); return; } var name = results["name"]; var price = results["newPrice"]; var duration = results["newDuration"]; if(document.getElementById("span_checkoutProductPrice_"+name)) { document.getElementById("span_checkoutProductPrice_"+name).innerHTML = formatCurrency(price, true); document.getElementById("span_checkoutProductPriceHidden_"+name).innerHTML = formatCurrency(price, true); } if(document.getElementById("span_checkoutProductPriceAlternative_"+name)) { document.getElementById("span_checkoutProductPriceAlternative_"+name).innerHTML = formatCurrency(price, true); document.getElementById("span_checkoutProductPriceHiddenAlternative_"+name).innerHTML = formatCurrency(price, true); } setShoppingCartInfo(results["productTotalPrice"], results["productCount"]); if(document.getElementById("span_qty_"+name)) document.getElementById("span_qty_"+name).innerHTML = duration; document.getElementById("span_durationControls_"+id).style.display = ""; document.getElementById("span_durationLoading_"+id).style.display = "none"; processPromoCode(); } function processFastBuyAmazon(domain) { document.getElementById("LoadingDiv").style.display = 'block'; getURL('/products-pricing/services/productCart.php?action=processfastbuyamazon&name='+domain, processFastBuyAmazonHandler); } function processFastBuyAmazonHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } var results = eval('('+content+')'); if(!results["status"]) { if(results["redir"]) { var confirmation = confirm(results["message"]); if(!confirmation) { resetLoadingDiv(); document.getElementById("check_"+results["name"]).checked = false; return; } productCartSwap(0, results["name"], 1, "registration", "fast-buy", results["tld"], "", 1); window.location = results["redir"]; return; } else { alert(results["message"]); } if(!results["accountId"]) location.reload(); document.getElementById("check_"+results["name"]).checked = false; productCartSwap(0, results["name"], 1, "registration", "fast-buy", results["tld"], "", 1); resetLoadingDiv(); return; } document.getElementById("check_"+results["name"]).checked = false; document.getElementById("check_"+results["name"]).disabled = true; document.getElementById("div_"+results["name"]).innerHTML = "Taken"; document.getElementById("div_"+results["name"]).style.color = "red"; resetLoadingDiv(); } function resetLoadingDiv() { if(doNotRestLoadingDiv) return; if(document.getElementById("LoadingDiv")) { document.getElementById("LoadingDiv").style.display = 'none'; if(loadingDivInnerHTMLSwap) { document.getElementById("span_loading_content").innerHTML = loadingDivInnerHTMLSwap; loadingDivInnerHTMLSwap = ""; } document.getElementById("LoadingDiv_inner").style.height = 200; document.getElementById("LoadingDiv_inner").style.width = 200; document.getElementById("LoadingDiv_inner").style.textAlign = "center"; document.getElementById("LoadingDiv").style.background = ""; document.getElementById("LoadingDiv").style.paddingTop = "100px"; } } function deleteTableRow(rowId, tableId) { if(document.getElementById(tableId) && document.getElementById(rowId)) { var rowIndex = document.getElementById(rowId).rowIndex; document.getElementById(tableId).deleteRow(rowIndex); } } function emptyCart() { var confirmation = confirm("Empty all the contents of your shopping cart?"); if(!confirmation) return; document.getElementById("LoadingDiv").style.display='block'; getURL('/products-pricing/services/productCart.php?action=empty', emptyCartHandler); } function emptyCartHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } var results = eval('('+content+')'); if(!results["status"]) { alert(results["message"]); resetLoadingDiv(); return; } var removedItems = results["removedItems"]; var removedItemsLength = removedItems.length; for(var i = 0; i < removedItemsLength; i++) { if(document.getElementById("check_"+removedItems[i])) { document.getElementById("check_"+removedItems[i]).checked = false; } if(document.getElementById("div_"+removedItems[i])) { document.getElementById("div_"+removedItems[i]).innerHTML = "Available"; document.getElementById("div_"+removedItems[i]).style.color = "#00CC00"; if(document.getElementById('div_fast_'+removedItems[i])) document.getElementById('div_fast_'+removedItems[i]).style.display = ''; } if(document.getElementById("new_check_"+removedItems[i])) { document.getElementById("new_check_"+removedItems[i]).click(); } } domainsInCart = new Array(); setShoppingCartInfo(results["productTotalPrice"], results["productCount"]); if(document.getElementById("cartTable")) location.reload(); resetLoadingDiv(); } function productCartSwapAddOnDomain(add, name, duration, type, tag, tld, handler, notasync) { var action = ""; if(!tag) tag = ""; if(!tld) tld = ""; if(!handler) handler = productCartSwapHandler; if(!notasync) notasync = 0; if(add) action = "add"; else action = "remove"; getURL('/products-pricing/services/productCart.php?action='+action+'&name='+name+'&duration='+duration+'&type='+type+'&tld='+tld+'&tag='+tag, handler, notasync); } function productCartSwapAddOnDomainHandler(status, content, contentType) { productCartSwapHandler(status, content, contentType, 1); } function productCartSwap(add, name, duration, type, tag, tld, handler, notasync) { var action = ""; if(!tag) tag = ""; if(!tld) tld = ""; if(!handler) handler = productCartSwapHandler; if(!notasync) notasync = 0; if(tag == "addon_product") handler = productCartSwapAddOnHandler; if(add) action = "add"; else action = "remove"; if(notasync) document.getElementById("LoadingDiv").style.display='block'; getURL('/products-pricing/services/productCart.php?action='+action+'&name='+name+'&duration='+duration+'&type='+type+'&tld='+tld+'&tag='+tag, handler, notasync); } function productCartSwapAddOn(add, name, duration, type, tag, tld, handler, notasync) { var action = ""; if(!tag) tag = ""; if(!tld) tld = ""; if(!handler) handler = productCartSwapHandler; if(!notasync) notasync = 0; if(add) action = "addaddon"; else action = "removeaddon"; getURL('/products-pricing/services/productCart.php?action='+action+'&name='+name+'&duration='+duration+'&type='+type+'&tld='+tld+'&tag='+tag, handler, notasync); } function productCartSwapAddOnHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } if(!content) return; var results = eval('('+content+')'); var action = results["action"]; if(!results["status"]) { alert(results["message"]); if(document.getElementById("check_addon_"+results["name"])) document.getElementById("check_addon_"+results["name"]).checked = false; resetLoadingDiv(); return; } if(action == "remove") if(document.getElementById("check_addon_"+results["name"])) document.getElementById("check_addon_"+results["name"]).checked = false; else if(action == "add") if(document.getElementById("check_addon_"+results["name"])) document.getElementById("check_addon_"+results["name"]).checked = true; productCartSwapHandler(status, content, contentType); } function productCartSwapAddOnInlineHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } if(!content) return; var results = eval('('+content+')'); if(!results["status"]) { alert(results["message"]); if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; resetLoadingDiv(); return; } productCartSwapHandler(status, content, contentType, 0); } function productCartSwapHandler(status, content, contentType, minimal) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } if(!content) return; var results = eval('('+content+')'); var action = results["action"]; if(!results["status"]) { alert(results["message"]); resetLoadingDiv(); if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; return; } if(action == "remove") { if(document.getElementById("check_addon_"+results["name"])) document.getElementById("check_addon_"+results["name"]).checked = false; if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; } else if(action == "add") { if(document.getElementById("check_addon_"+results["name"])) document.getElementById("check_addon_"+results["name"]).checked = true; if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = true; } if(document.getElementById("whois_"+results["name"]) && document.getElementById("check_"+results["name"])) { if(document.getElementById("whois_"+results["name"]).disabled) document.getElementById("whois_"+results["name"]).disabled = false; else document.getElementById("whois_"+results["name"]).disabled = true; if(!document.getElementById("check_"+results["name"]).checked) document.getElementById("whois_"+results["name"]).checked = false; } if(document.getElementById("google_apps_"+results["name"]) && document.getElementById("check_"+results["name"])) { /* if(document.getElementById("google_apps_"+results["name"]).disabled) document.getElementById("google_apps_"+results["name"]).disabled = false; else document.getElementById("google_apps_"+results["name"]).disabled = true; if(!document.getElementById("check_"+results["name"]).checked) document.getElementById("google_apps_"+results["name"]).checked = false; */ } if(document.getElementById("div_"+results["name"])) { document.getElementById("check_"+results["name"]).checked = (results["action"] == "add") ? true : false; document.getElementById("div_"+results["name"]).innerHTML = (results["action"] == "add") ? "Added to Cart" : "Available"; document.getElementById("div_"+results["name"]).style.color = (results["action"] == "add") ? "#245FA5" : "#00CC00"; if(document.getElementById('div_fast_'+results["name"])) document.getElementById('div_fast_'+results["name"]).style.display = (results["action"] == "add") ? 'none' : ''; } setShoppingCartInfo(results["productTotalPrice"], results["productCount"]); deleteTableRow("tr_"+results["type"]+"_"+results["name"], "cartTable"); deleteTableRow("tr_show_names_"+results["name"], "cartTable"); var removedItems = results["removedItems"]; if(removedItems) { var removedItemsLength = removedItems.length; if(removedItemsLength > 0) { for(var i = 0; i < removedItemsLength; i++) { if(document.getElementById("tr_"+removedItems[i]["type"]+"_"+removedItems[i]["name"])) { deleteTableRow("tr_"+removedItems[i]["type"]+"_"+removedItems[i]["name"], "cartTable"); } } } } if(!minimal) { prepareCheckoutLoggedIn(); } if(results["action"] == "add") { domainsInCart.push(results["name"]); } else if(results["action"] == "remove") { if(Array.indexOf) delete(domainsInCart[domainsInCart.indexOf(results["name"])]); if(document.getElementById("span_checkoutProductPrice_"+results["name"])) { document.getElementById("span_checkoutProductPrice_"+results["name"]).innerHTML = formatCurrency(document.getElementById("span_checkoutProductPriceHidden_"+results["name"]).innerHTML, true); document.getElementById("span_checkoutProductPrice_"+results["name"]).style.color = '#000000' } if(document.getElementById("span_checkoutProductPriceAlternative_"+results["name"])) { document.getElementById("span_checkoutProductPriceAlternative_"+results["name"]).innerHTML = formatCurrency(document.getElementById("span_checkoutProductPriceHiddenAlternative_"+results["name"]).innerHTML, true); document.getElementById("span_checkoutProductPriceAlternative_"+results["name"]).style.color = '#000000' } } if(results["tag"] != "addon_product" && document.getElementById("div_addonDomainsInCart")) if(document.getElementById("div_addonDomainsInCart").style.display != "none") showAddonDomainList("cart" , globalCurrentAddOnProductName, globalCurrentAddOnProductType); if(results["action"] == "add" || results["action"] == "addaddon") { handleProductTypeLevelOverride(true, results["type"], results["name"]); insertCartRow(document.getElementById("tr_cartTable"), results["name"], results["type"], results["duration"], results["privateWhois"], results["googleApps"], results["price"], results["cartRowId"], results["tag"], results["displayType"]); } else { handleProductTypeLevelOverride(false, results["type"], results["name"]); if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; } if(document.getElementById("tr_addOnProducts")) { processAddOnServices(processAddOnServicesInlineHandler); } processPromoCode(); if(!minimal) resetLoadingDiv(); } function productCartSwapSimpleHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); resetLoadingDiv(); return; } if(!content) return; var results = eval('('+content+')'); var action = results["action"]; if(!results["status"]) { alert(results["message"]); resetLoadingDiv(); if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; return; } if(action == "remove") { if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = false; } else if(action == "add") { if(document.getElementById("check_"+results["name"])) document.getElementById("check_"+results["name"]).checked = true; } if(document.getElementById("div_"+results["name"])) { document.getElementById("div_"+results["name"]).innerHTML = (results["action"] == "add") ? "Added to Cart" : "Available"; document.getElementById("div_"+results["name"]).style.color = (results["action"] == "add") ? "#245FA5" : "#00CC00"; if(document.getElementById('div_fast_'+results["name"])) document.getElementById('div_fast_'+results["name"]).style.display = (results["action"] == "add") ? 'none' : ''; } setShoppingCartInfo(results["productTotalPrice"], results["productCount"]); resetLoadingDiv(); } function getSetShoppingCartInfo() { getURL('/products-pricing/services/productCart.php?action=getTotals', getSetShoppingCartInfoHandler); } function getSetShoppingCartInfoHandler(status, content, contentType) { if(status != 200 && status != 0) { alert("Something went wrong. Please refresh the page and try again. ("+status+")"); return; } if(!content) return; var results = eval('('+content+')'); if(!results["status"]) { alert(results["message"]); return; } var cartItems = results["cartItems"]; var cartItemsLength = cartItems.length; for(var i = 0; i < cartItemsLength; i++) { if(document.getElementById("check_"+cartItems[i])) { document.getElementById("check_"+cartItems[i]).checked = true; } if(document.getElementById("div_"+cartItems[i])) { document.getElementById("div_"+cartItems[i]).innerHTML = "Added to Cart"; document.getElementById("div_"+cartItems[i]).style.color = "#245FA5"; if(document.getElementById('div_fast_'+cartItems[i])) document.getElementById('div_fast_'+cartItems[i]).style.display = 'none'; } domainsInCart.push(cartItems[i]); } setShoppingCartInfo(results["productTotalPrice"], results["productCount"]); } function setShoppingCartInfo(productTotalPrice, productCount) { if(document.getElementById("shopping_cart_info")) { document.getElementById("shopping_cart_info").innerHTML = " Your Cart: "+productCount+" item(s) Total: "+formatCurrency(productTotalPrice, true); if(productCount > 0) document.getElementById("shopping_cart_info").innerHTML += " | empty cart"; } } function formatCurrency(num, nosign) { 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)?'':'-') + ((nosign) ? '' : '$') + num + '.' + cents); }