var aqty = new Array (); // amount qty breakpoint var aamt = new Array (); // amount to charge var an = 0; // number of discount brkpts var hqty = new Array (); // handling qty breakpoints var hamt = new Array (); // amount charged var hn = 0; // number of handling brkpts var qqty = new Array (); // quantity discount breakpoints var qamt = new Array (); // amount of discount var qd = 0; // number of qty breakpoints var sqty = new Array (); // shipping qty breakpoints var samt = new Array (); // amount charged var sn = 0; // number of shipping brkpts var stxt = ""; // shipping type text var taxp = 0; // tax percent for this order var coup = -1; // discount coupon not active var cdis = 0; // amount of coupon discount (%) var coupons = new Array (); // array of valid coupon names coupons[0] = "coup1"; // list as many as you want... coupons[1] = "coup2"; var on = 1; var off = 0; var root = new Object (); root.xx_ship = off; // default is no shipping function ChkCoup (val, amt) { // check for a discount coupon var i; coup = -1; // assume the worst cdis = 0; if (amt == "" || isNaN (amt)) { alert ("\n\n\n Coup arg not valid percent (01) \n\n\n"); return; } for (i=0; i= 0) amt = temp.substring (pos + 1)*1.0; pos = temp.indexOf ("+"); // is there a price adjustment? if (pos >= 0) amt = amt + temp.substring (pos + 1)*1.0; pos = temp.indexOf ("%"); // is there a percent adjustment? if (pos >= 0) amt = amt * (1.0 + temp.substring (pos + 1)/100.0); return amt; } function ClearAll () { sn = 0; // reset shipping indicator } function Dollar (val) { // force to valid dollar amount var str,pos,rnd=0; if (val < 1) rnd = 1; str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape pos = str.indexOf ("."); if (pos > 0) str = str.substring (rnd, pos + 3); return str; } function Process (obj1) { // process the form, but no submit var i,j,obj,bqty,bamt,btxt,tdis,thnd,tshp,ttax,val,pos; if (root.xx_ship == on) { // is shipping on? if (sn == 0) { alert("Select shipping method!"); return false; } } if (!obj1.quantity) { alert ("HTML must have quantity field!"); return false; } if (!obj1.basedes) { alert ("HTML must have basedes field!"); return false; } if (!obj1.baseamt) { alert ("HTML must have baseamt field!"); return false; } btxt = obj1.basedes.value; // reload desc bamt = obj1.baseamt.value*1.0; // and amount bqty = obj1.quantity.value; // selected quantity if (isNaN(bqty) || bqty == "" || bqty < 1) { alert ("Quantity not valid - forcing to 1!"); bqty = 1; obj1.quantity.value = "1"; } bqty = bqty*1.0; // float that sucker for (i=0; i 0) { val = obj.value; // the value of it btxt = btxt + ", " + val; } } } for (i=an-1; i>=0; i--) { // qty amount? if (bqty >= aqty[i]) { // qty brkpt bamt = aamt[i]*1.0; // set amount from qty btxt = btxt + ", AMT=" + Dollar (bamt); break; // get out, now } } tdis = 0; // qty discounts for (i=qd-1; i>=0; i--) { // run backwards if (bqty >= qqty[i]) { // qty brkpt tdis = qamt[i]*1.0; bamt = bamt - tdis; // Deduct from item price btxt = btxt + ", QDIS=$" + Dollar (tdis); break; // get out, now } } if (coup > 0 && // coupon discount percent? cdis > 0) { bamt = bamt * (1.0 - cdis/100.0); btxt = btxt + ", COUP=" + cdis + "%"; } thnd = 0; // handling charges for (i=hn-1; i>=0; i--) { // run backwards if (bqty >= hqty[i]) { // qty brkpt thnd = hamt[i]; // set hand amount obj1.handling.value = Dollar (thnd); break; // get out, now } } tshp = 0; // shipping charges for (i=sn-1; i>=0; i--) { // run backwards if (bqty >= sqty[i]) { // qty brkpt tshp = samt[i]*1.0; // set shipping amount btxt = btxt + ", SHP:" + stxt; break; // get out, now } } /* At this point everything has been calculated except tax. We need to figure out what we need to calculate tax on. Handling is most often put into the tax calculation, but shipping is a toss-up. In the following statement you may need to modify the Dollar amount to include shipping - I have already included handling (thnd) - just add tshp to include shipping in the tax calculation... */ ttax = 0; if (taxp > 0 && // have a percent recorded? obj1.tax) { // check for override ttax = taxp/100.0; // yep - calculate it. obj1.tax.value = Dollar (ttax * bqty * (bamt + thnd)); } obj1.shipping.value = Dollar (tshp); obj1.amount.value = Dollar (bamt); // plug amount obj1.item_name.value = btxt; // and descriptiuon } function SetHN (q1, h1) { // set qty handling breakpoints var i; hn = 0; // count of breakpoints for (i=0; i