///////////////////////////////////////////////////////////////////////////// // cookie stuff function save_cookie(name,value,minutes) { if (minutes) { var date = new Date(); date.setTime(date.getTime()+(minutes*60*1000)) var expires = "; expires="+date.toGMTString() } else expires = ""; document.cookie = escape(name)+"="+escape(value)+expires+"; path=/" } function read_cookie(name) { var nameEQ = escape(name) + "=" var ca = document.cookie.split(';') for(var i=0;i 0)?'':'none'; // update qty var input = document.getElementById('basket_input_'+guid); input.value = qty; // update total replace_contents(row.childNodes[2], document.createTextNode(format_price(total))); if (qty>0) isEmpty=false; } var row = document.getElementById('basket_empty_row'); row.style.display = (!isEmpty)?'none':''; var cell = document.getElementById('basket_subtotal'); replace_contents(cell, document.createTextNode(format_price(sub_total))); var row = document.getElementById('basket_update'); row.style.display = (!isEmpty)?'':'none'; var row = document.getElementById('basket_checkout'); row.style.display = (!isEmpty)?'':'none'; } function update_qty(){ if (!g_havebasket) return; for(var i=0; i0){ submitqty += '#'; submititemno += '#'; submitprod += '#'; submitprice += '#'; submitpricetotal += '#'; } submitqty += qty; submititemno += itemno; submitprod += name; submitprice += format_price(price); submitpricetotal += format_price(total); } // show totals row = create_element(elm_tbody, 'TR'); row.id = 'totalrow'; cell = create_element_filled(row, 'TD', iwOrderTotal); cell.setAttribute('colSpan', '5'); cell.setAttribute('align', 'right'); cell = create_element_filled(row, 'TD', format_price(sub_total)+' '+iwOrderCurrency); cell.setAttribute('align', 'right'); cell.id = 'basket_subtotal'; // show vat row = create_element(elm_tbody, 'TR'); cell = create_element_filled(row, 'TD', iwOrderVAT); cell.setAttribute('colSpan', '5'); cell.setAttribute('align', 'right'); var vat = (sub_total - sub_totalnovat) cell = create_element_filled(row, 'TD', format_price(vat)+' '+iwOrderCurrency); cell.setAttribute('align', 'right'); cell.id = 'basket_subtotal'; // show price excl. VAT row = create_element(elm_tbody, 'TR'); cell = create_element_filled(row, 'TD', iwOrderTotalexVAT); cell.setAttribute('colSpan', '5'); cell.setAttribute('align', 'right'); cell = create_element_filled(row, 'TD', format_price(sub_totalnovat)+' '+iwOrderCurrency); cell.setAttribute('align', 'right'); // build input fields if (container_id == 'check_basket') { var input = document.getElementById('orderqty'); input.value = submitqty; var input = document.getElementById('orderitem'); input.value = submititemno; var input = document.getElementById('orderprod'); input.value = submitprod; var input = document.getElementById('orderprice'); input.value = submitprice; var input = document.getElementById('orderpricetotal'); input.value = submitpricetotal; var input = document.getElementById('ordertotal'); input.value = format_price(sub_total); var input = document.getElementById('ordervat'); input.value = format_price(vat); var input = document.getElementById('ordertotalnovat'); input.value = format_price(sub_totalnovat); } } function build_confirmAddressLine(elm_tbody, label_id, value_id) { var cell, row; row = create_element(elm_tbody, 'TR'); cell = create_element_filled(row, 'TD', document.getElementById(label_id).innerHTML); cell.setAttribute('width', '25%') cell = create_element_filled(row, 'TD', document.getElementById(value_id).value); } function build_confirmAddress(container_id) { var elm_parent = document.getElementById(container_id); elm_parent.innerHTML = ''; append_text(elm_parent, document.getElementById('iToptext').innerHTML) var elm_table = create_element(elm_parent, 'TABLE'); elm_table.setAttribute('border', '0'); elm_table.setAttribute('cellPadding', '0'); elm_table.setAttribute('cellSpacing', '0'); // we have to have a tbody for some reason var elm_tbody = create_element(elm_table, 'TBODY'); // add rows build_confirmAddressLine(elm_tbody, 'lname', 'name') build_confirmAddressLine(elm_tbody, 'laddress', 'address') build_confirmAddressLine(elm_tbody, 'lzip', 'zip') build_confirmAddressLine(elm_tbody, 'lcity', 'city') build_confirmAddressLine(elm_tbody, 'lphone', 'phone') build_confirmAddressLine(elm_tbody, 'lprojectdescription', 'projectdescription') build_confirmAddressLine(elm_tbody, 'lreference', 'reference') build_confirmAddressLine(elm_tbody, 'lrequisition', 'requisition') build_confirmAddressLine(elm_tbody, 'leannumber', 'eannumber') build_confirmAddressLine(elm_tbody, 'lemail', 'email') try { if (document.getElementById('deliveryIsDifferent').checked) { append_text(elm_parent, document.getElementById('dToptext').innerHTML) var elm_table = create_element(elm_parent, 'TABLE'); elm_table.setAttribute('border', '0'); elm_table.setAttribute('cellPadding', '0'); elm_table.setAttribute('cellSpacing', '0'); // we have to have a tbody for some reason var elm_tbody = create_element(elm_table, 'TBODY'); build_confirmAddressLine(elm_tbody, 'ldname', 'dname') build_confirmAddressLine(elm_tbody, 'ldaddress', 'daddress') build_confirmAddressLine(elm_tbody, 'ldzip', 'dzip') build_confirmAddressLine(elm_tbody, 'ldcity', 'dcity') // build_confirmAddressLine(elm_tbody, 'ldphone', 'dphone') } } catch(e) {} } ///////////////////////////////////////////////////////////////////////////// // DOM helper stuff function create_element(parent, type){ var elm = document.createElement(type); parent.appendChild(elm); return elm; } function create_element_filled(parent, type, contents){ var elm = document.createElement(type); parent.appendChild(elm); elm.appendChild(document.createTextNode(contents)); return elm; } function replace_contents(node, newnode){ if (node.childNodes.length > 0){ node.replaceChild(newnode, node.childNodes[0]); }else{ node.appendChild(newnode); } } function append_text(node, contents){ node.appendChild(document.createTextNode(contents)); } ///////////////////////////////////////////////////////////////////////////// // format stuff function format_price(price){ var s = new String(Math.round(price*100)); var pence = s.substr(s.length-2); var pounds = s.substr(0, s.length-2); pounds = commaify(pounds); if (pence.length == 0) pence = '00'; if (pence.length == 1) pence = '0'+pence; if (pounds.length == 0) pounds = '0'; return g_currency + pounds + g_decimal + pence; } function commaify(s){ if (s.length <= 3) return s; var out = s.substr(s.length-3); s = s.substr(0, s.length-3); while(s.length > 0){ out = s.substr(s.length-3) + g_thousand + out; if (s.length > 3){ s = s.substr(0, s.length-3); }else{ s = ''; } } return out; }