//global 2 dimensional javascript shopping cart array var toPurchase = new Array(); var frmAction = ""; var order_total = 0; function isVisible(obj) { if (obj == document) return true if (!obj) return false if (!obj.parentNode) return false if (obj.style) { if (obj.style.display == 'none') return false if (obj.style.visibility == 'hidden') return false } //Try the computed style in a standard way if (window.getComputedStyle) { var style = window.getComputedStyle(obj, "") if (style.display == 'none') return false if (style.visibility == 'hidden') return false } //Or get the computed style using IE's silly proprietary way var style = obj.currentStyle if (style) { if (style['display'] == 'none') return false if (style['visibility'] == 'hidden') return false } return isVisible(obj.parentNode) } // this function is only called as a UI ajax request function render_product_list(ajax_resp) { // parse the ajax_resp into innerhtml and the target div id var data = ajax_resp.split("|||"); // No Products - just return if (data[0] == "") return; // insert the exam window DOM (HTML) into the div document.getElementById(data[1]).innerHTML = data[0]; var z=0; // number of checkboxes (products) in the exam window var cb = new Array(); // stores an array of info about the checkboxes in the exam window var dom_arr = new Array(); // store the actual checkbox DOM objects for the exam window // parse the exam window DOM to get all the checkboxes (products in the window) var inps = document.getElementById(data[1]).getElementsByTagName('input'); for (var i = 0; i < inps.length; i++) { if (inps[i].type == "checkbox") { dom_arr[z] = inps[i]; // get each checkbox DOM object cb[z++] = inps[i].id.split("_"); // parse product info from the checkbox objects id } } var course = cb[0][2]; // contains the course no like 500 for CPCU 500 var checked = 0; // product counter for the course/window var set = false; // nothing done var processed = new Array(); // a dup product filter to prevent reprocessing dup aliases update_product_counter(0, document.getElementById(course+'_count')) // check the checkboxes for all selected products in this window // and/or map the products to the new window when it changes for (var idx=toPurchase.length-1; idx >= 0; idx--) { if (toPurchase[idx][2] == course) // find selected products listed in this course/window { set = false; for (i = 0; i < cb.length; i++) { // window has not changed so just check the right boxes if (cb[i][3] == toPurchase[idx][3]) { if (toPurchase[idx][1] == cb[i][1]) { set = true; // product selected break; } } // window has changed so remap selections to new window if possible else if (cb[i][0] == toPurchase[idx][0]) { if (processed.indexOf(cb[i][1]) == -1) // filter out duplicate products { // update cart/product values to new win/product values var oprice = parseFloat(toPurchase[idx][4]); var nprice = parseFloat(cb[i][4]); toPurchase[idx][1] = processed[processed.length] = cb[i][1]; // new win/product item_seq toPurchase[idx][3] = cb[i][3]; // new win/product win order_total = (order_total - oprice) + nprice; // recalc total when window changes toPurchase[idx][4] = nprice; // new win/product item price set = true; // product selected break; } } } if (set) { dom_arr[i].checked = true; // check the checkbox update_product_counter(1, document.getElementById(course+'_count')) } else { order_total -= parseFloat(toPurchase[idx][4]); toPurchase.splice(idx, 1); // no matching product in new window so delete it from JS cart array } update_order_total(); } } } /** * This function is used to get products. It uses its arguments array as a flattened associative * style to simulate passing named parameters. This style has the key as the element preceeding the * value. The function is used to get products when an exam window is changed. If the exam window * value is "" then the window is cleared and any seleted items in the window are removed from the * cart array. **/ function get_products() { var qs = p_store = p_lang = p_prodfam = p_filter_type = p_filter1 = p_filter2 = ""; for (var i = 0; i < arguments.length; i+=2) { qs += "&"+arguments[i]+"="+arguments[i+1]; switch (arguments[i]) { case "p_store" : p_store = arguments[i+1]; break; case "p_lang" : p_lang = arguments[i+1]; break; case "p_prodfam" : p_prodfam = arguments[i+1]; break; case "p_filter_type" : p_filter_type = arguments[i+1]; break; case "p_filter1" : p_filter1 = arguments[i+1]; break; case "p_filter2" : p_filter2 = arguments[i+1]; break; } } if (p_filter_type == "EXAM_SERIES" && p_filter2 == "") clearSelections(p_filter1); else callAfter("/product_picker/product_picker_controller.php?ajax=get_product_list" + qs, "POST", render_product_list); } function render_course_list(ajax_resp) { var data = ajax_resp.split("|||"); if (data[0] == "") return; document.getElementById(data[1]).innerHTML = data[0]; } function clearSelections() { if (arguments.length > 0) { course = arguments[0]; for (var i=toPurchase.length -1; i >= 0; i--) { if (toPurchase[i][2] == course) { order_total -= parseFloat(toPurchase[i][4]); toPurchase.splice(i, 1); } } update_order_total(); if (document.getElementById(course+"_products_div")) { document.getElementById(course+"_products_div").innerHTML = ""; update_product_counter(0, document.getElementById(course+'_count')) } } else { toPurchase.length = 0; var divs = document.body.getElementsByTagName('div'); for (var i = 0; i < divs.length; i++) { if (divs[i].id.indexOf("_products_div") > -1) { var course = divs[i].id.split("_"); if (document.getElementById(course[0])) document.getElementById(course[0]).value = ""; update_product_counter(0, document.getElementById(course[0]+'_count')) divs[i].innerHTML = ""; } else if (divs[i].id.indexOf("main_products_list") > -1) { var inps = divs[i].getElementsByTagName('input'); for (var j = 0; j < inps.length; j++) { if (inps[j].type == "checkbox") inps[j].checked = false; } } } update_order_total(order_total*-1) } } function add_toPurchase(chkbox_obj) { var cb = chkbox_obj.id.split("_"); // checked so add to cart if (chkbox_obj.checked == true) // CB is checked so add product to JS cart { toPurchase[toPurchase.length] = cb; update_product_counter(1, document.getElementById(cb[2]+'_count')) update_order_total(parseFloat(cb[4])); } else // CB is unchecked so delete product from JS cart { for (var idx = toPurchase.length-1; idx >= 0; idx--) { if (toPurchase[idx][0] == cb[0] && toPurchase[idx][1] == cb[1]) { toPurchase.splice(idx, 1); update_product_counter(-1, document.getElementById(cb[2]+'_count')) update_order_total(parseFloat(cb[4])*-1); break; } } } } function update_product_counter(counter, tdObj) { if (tdObj) { var div_count = counter != 0 ? parseInt(tdObj.innerHTML,10) + counter : 0; tdObj.style.color = div_count > 0 ? "#000000" : "#808080"; tdObj.style.fontWeight = div_count > 0 ? "bold" : "normal"; tdObj.innerHTML = div_count; } } function update_order_total() { total = document.getElementById('order_total'); if ( isVisible(total)) { if (arguments.length > 0) order_total+=arguments[0]; document.getElementById('order_total').innerHTML = order_total.toFixed(2); } } function add_to_cart() { if (toPurchase.length == 0) return; // nothing in the javascript cart so return if (arguments.length == 0 || arguments[0] == "") { var sa = location.href.split("/"); var form_action = "https://"+sa[2]+"/www2/webops.SaveMat"; } else var form_action = arguments[0] var toPurchaseForm = document.createElement("FORM"); toPurchaseForm.id = "aicpcu_cart"; toPurchaseForm.action = form_action; toPurchaseForm.method = "POST"; toPurchaseForm.target = "_self"; var newElement = document.createElement("input"); newElement.setAttribute("name", "P_PARAMS"); newElement.setAttribute("type", "hidden"); newElement.setAttribute("value", 0); toPurchaseForm.appendChild(newElement); for (var idx=0; idx < toPurchase.length; idx++) { val = (toPurchase[idx][1]+" ").substring(0,8); val += (toPurchase[idx][4]+" ").substring(0,8); val += toPurchase[idx][3]; var newElement = document.createElement("input"); newElement.setAttribute("name", "P_PARAMS"); newElement.setAttribute("type", "hidden"); newElement.setAttribute("value", val); toPurchaseForm.appendChild(newElement); } //WEBPUBLISH-567, removing the cart form, if there exists one already. existing_cart = document.getElementById("aicpcu_cart"); if(existing_cart){ existing_cart.parentNode.removeChild(existing_cart); } document.body.appendChild(toPurchaseForm); document.getElementById("aicpcu_cart").submit(); } if(typeof jQuery === "undefined"){ (function() { var script = document.createElement('script'); script.type = 'text/javascript'; script.async = false; script.src = '/jquery/jquery-1.6.2.min.js'; document.getElementsByTagName('head')[0].appendChild(script); })(); } window.onload = function (){ if(typeof $ !== "undefined"){ jQuery.noConflict(); } jQuery.getCSS = function( url, media ) { if (document.createStyleSheet) { document.createStyleSheet(url); } else { jQuery( document.createElement('link') ).attr({ href: url, media: media || 'all', type: 'text/css', rel: 'stylesheet' }).appendTo('head'); } return false; }; jQuery.getCSS('/product_picker/css/picker.css'); if(jQuery.browser.msie && jQuery.browser.version >= 7){ jQuery.getCSS('/product_picker/css/ie-picker.css'); } jQuery('table.picker_buttons').attr('width','100%'); }