/*********************************************************************************************\ * COPYRIGHT © 2010 ENVISION INFORMATION TECHNOLOGIES, LLC. ALL RIGHTS RESERVED * * DISTRIBUTION, UNAUTHORIZED USE AND MODIFICATION IS STRICTLY PROHIBITED * * ENVISION IT, MADISON, WI http://www.envisionitllc.com info@envisionitllc.com * \*********************************************************************************************/ function setEComProductImage(imageID) { document.getElementById('eComProductImageLargeImage').src = '/ecommerce/images/product/image' + imageID + '-med.jpg'; document.getElementById('eComProductImageFullLink').href = '/ecommerce/images/product/image' + imageID + '-full.jpg'; }; function eComAddToCart(id) { var qty = document.getElementById('eComProductQty').value; if (qty == '') { alert('You must enter a quantity first'); return false; }; var qty = parseInt(qty); if (isNaN(qty) || qty < 0) { alert('You must enter a valid, positive number for the quantity'); return false; }; if (eComHasOptions == true) { var options = document.getElementById('eComProductOptionSelect'); if (options.selectedIndex < 1) { alert('You must select a valid product option from the drop down before adding this item to your cart.'); return; }; var optionid = options.options[options.selectedIndex].value; } else optionid = ''; xmlHttp = createHTTPRequest(); xmlHttp.onreadystatechange = function() { // xmlHttp.readyState // 0 The request is not initialized ,1 The request has been set up, 2 The request has been sent, 3 The request is in process, 4 The request is complete if (xmlHttp.readyState == 4) { var text = xmlHttp.responseText; // Display ADJ|| // -or- // QTY // Item added successfully, update the cart total if (text.length > 3 && text.substr(0,3) == "QTY") { var totalqty = parseInt(text.substr(3)); if (totalqty == "" || isNaN(totalqty) == true || totalqty < 0) totalqty = 0; var cartcount = document.getElementById('itemsInCartCount'); cartcount.innerHTML = totalqty; // if the add to cart link is set to #, do nothing. If it is set to something other than #, load that page if (document.getElementById('eComProductATCBlockLink').href == "#") alert('Item added successfully!'); else document.location.href = document.getElementById('eComProductATCBlockLink').href; } else if (text.length > 3 && text.substr(0,3) == "ADJ") { var info = text.substr(3); var values = info.split("|"); var adjustedQty = values[0]; var totalqty = values[1]; var reason = values[2]; var cartcount = document.getElementById('itemsInCartCount'); cartcount.innerHTML = totalqty; alert(reason); } else { alert('An error occurred while adding the item to your cart. Please try again.'); }; }; }; var params = "id=" + escape(id) + "&qty=" + escape(qty) + "&optionid=" + escape(optionid); xmlHttp.open("POST","/ecommerce/ecommerce_addtocart.php",true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); }; var eComRelatedNextTimer = null; var eComRelatedNextCount = 0; function moveRelatedNext() { clearInterval(eComRelatedNextTimer); clearInterval(eComRelatedPreviousTimer); eComRelatedNextTimer = setInterval('moveRelatedNextStart();', 15); }; function moveRelatedNextEnd() { clearInterval(eComRelatedNextTimer); clearInterval(eComRelatedPreviousTimer); eComRelatedNextCount = 0; }; function moveRelatedNextStart() { var related = document.getElementById('eComRelatedProductsScroll'); var parent = document.getElementById('eComRelatedProductsList'); var left = parseInt(related.style.left); var width = parseInt(related.offsetWidth); var parentWidth = parseInt(parent.offsetWidth); if (isNaN(left)) left = 0; eComRelatedNextCount++; if (eComRelatedNextCount < 20) adjust = 2; else if (eComRelatedNextCount < 40) adjust = 4; else if (eComRelatedNextCount < 80) adjust = 6; else if (eComRelatedNextCount < 120) adjust = 10; else if (eComRelatedNextCount < 160) adjust = 14; else if (eComRelatedNextCount < 200) adjust = 18; else adjust = 20; if (left > (parentWidth-width)) related.style.left = (left-adjust) + "px"; }; var eComRelatedPreviousTimer = null; var eComRelatedPreviousCount = 0; function moveRelatedPrevious() { clearInterval(eComRelatedPreviousTimer); clearInterval(eComRelatedNextTimer); eComRelatedPreviousTimer = setInterval('moveRelatedPreviousStart();', 15); }; function moveRelatedPreviousEnd() { clearInterval(eComRelatedPreviousTimer); clearInterval(eComRelatedNextTimer); eComRelatedPreviousCount = 0; }; function moveRelatedPreviousStart() { var related = document.getElementById('eComRelatedProductsScroll'); var parent = document.getElementById('eComRelatedProductsList'); var left = parseInt(related.style.left); var width = parseInt(related.offsetWidth); var parentWidth = parseInt(parent.offsetWidth); if (isNaN(left)) left = 0; eComRelatedPreviousCount++; if (eComRelatedPreviousCount < 20) adjust = 2; else if (eComRelatedPreviousCount < 40) adjust = 4; else if (eComRelatedPreviousCount < 80) adjust = 6; else if (eComRelatedPreviousCount < 120) adjust = 10; else if (eComRelatedPreviousCount < 160) adjust = 14; else if (eComRelatedPreviousCount < 200) adjust = 18; else adjust = 20; if (left < 0) related.style.left = (left+adjust) + "px"; }; function updateCart() { var products = document.getElementById('eComViewCartTable'); var updateForm = document.getElementById('viewcartform'); var totalUpdates = 0; for (var a=1; a < products.rows.length; a++) { if (products.rows[a].cells[0].childNodes.length < 2) continue; var productid = products.rows[a].cells[0].childNodes[1].value; var optionid = products.rows[a].cells[0].childNodes[2].value; // blank if none var oldQty = products.rows[a].cells[0].childNodes[3].value; var remove = products.rows[a].cells[0].childNodes[0].checked; var qty = products.rows[a].cells[2].childNodes[0].value; if (remove) qty = "0"; // verify the qty qty = parseInt(qty); if (isNaN(qty) || qty < 0 || qty > 999) { alert('You have an invalid quantity for row number ' + a + '. Please enter a quantity between 0 and 999.'); return; }; if (oldQty != qty) { var updateField = document.createElement("input"); updateField.type = 'hidden'; updateField.name = "qty_id_" + productid + "_" + optionid; updateField.value = qty; updateForm.appendChild(updateField); totalUpdates++; }; }; if (totalUpdates > 0) updateForm.submit(); else alert('If you want to make a change to your cart, please make the change, then click "Update Cart."'); }; function trackFeaturedProduct(productId, boxId, pageViewId) { var xmlHttp = createHTTPRequest(); //productid, boxid, pageviewid var params = "productid=" + escape(productId) + "&boxid=" + escape(boxId) + "&pageviewid=" + escape(pageViewId); xmlHttp.open("POST","/ecommerce/ecommerce_featuredproductclick.php",true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); return true; };