Mercurial > laserkard
diff buycode.js @ 0:599d0315537d laserkard
[svn r1] initial import
author | rlm |
---|---|
date | Wed, 30 Dec 2009 02:01:25 -0500 |
parents | |
children | c96cb4e773e5 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/buycode.js Wed Dec 30 02:01:25 2009 -0500 1.3 @@ -0,0 +1,185 @@ 1.4 +function Dollar (val) { // force to valid dollar amount 1.5 +var str,pos,rnd=0; 1.6 + if (val < .995) rnd = 1; // for old Netscape browsers 1.7 + str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape 1.8 + pos = str.indexOf ("."); 1.9 + if (pos > 0) str = str.substring (rnd, pos + 3); 1.10 + return str; 1.11 +} 1.12 + 1.13 +var amt,des,obj,val,op1a,op1b,op2a,op2b,op3a,op3b,op4a,op4b,op5a,op5b,op6a,op6b,op7a,op7b,op8a,op8b,op9a,op9b,itmn; 1.14 + 1.15 +function ChkTok (obj1) { 1.16 +var j,tok,ary=new Array (); // where we parse 1.17 + ary = val.split (" "); // break apart 1.18 + for (j=0; j<ary.length; j++) { // look at all items 1.19 +// first we do single character tokens... 1.20 + if (ary[j].length < 2) continue; 1.21 + tok = ary[j].substring (0,1); // first character 1.22 + val = ary[j].substring (1); // get data 1.23 + if (tok == "@") amt = val * 1.0; 1.24 + if (tok == "+") amt = amt + val*1.0; 1.25 + if (tok == "%") amt = amt + (amt * val/100.0); 1.26 + if (tok == "-") amt = amt - val*1.0; 1.27 + if (tok == "#") { // record item number 1.28 + if (obj1.item_number) obj1.item_number.value = val; 1.29 + ary[j] = ""; // zap this array element 1.30 + } 1.31 +// Now we do 3-character tokens... 1.32 + if (ary[j].length < 4) continue; 1.33 + tok = ary[j].substring (0,3); // first 3 chars 1.34 + val = ary[j].substring (3); // get data 1.35 + if (tok == "s1=") { // value for shipping 1.36 + if (obj1.shipping) obj1.shipping.value = val; 1.37 + ary[j] = ""; // clear it out 1.38 + } 1.39 + if (tok == "s2=") { // value for shipping2 1.40 + if (obj1.shipping2) obj1.shipping2.value = val; 1.41 + ary[j] = ""; // clear it out 1.42 + } 1.43 + } 1.44 + val = ary.join (" "); // rebuild val with what's left 1.45 +} 1.46 + 1.47 +function StorVal () { 1.48 +var tag; 1.49 + tag = obj.name.substring (obj.name.length-2); // get flag 1.50 + if (tag == "1a") op1a = op1a + " " + val; 1.51 + else if (tag == "1b") op1b = op1b + " " + val; 1.52 + else if (tag == "2a") op2a = op2a + " " + val; 1.53 + else if (tag == "2b") op2b = op2b + " " + val; 1.54 + else if (tag == "3a") op3a = op3a + " " + val; 1.55 + else if (tag == "3b") op3b = op3b + " " + val; 1.56 + else if (tag == "4a") op4a = op4a + " " + val; 1.57 + else if (tag == "4b") op4b = op4b + " " + val; 1.58 + else if (tag == "5a") op5a = op5a + " " + val; 1.59 + else if (tag == "5b") op5b = op5b + " " + val; 1.60 + else if (tag == "6a") op6a = op6a + " " + val; 1.61 + else if (tag == "6b") op6b = op6b + " " + val; 1.62 + else if (tag == "7a") op7a = op7a + " " + val; 1.63 + else if (tag == "7b") op7b = op7b + " " + val; 1.64 + else if (tag == "8a") op8a = op8a + " " + val; 1.65 + else if (tag == "8b") op8b = op8b + " " + val; 1.66 + else if (tag == "9a") op9a = op9a + " " + val; 1.67 + else if (tag == "9b") op9b = op9b + " " + val; 1.68 + else if (tag == "3i") itmn = itmn + " " + val; 1.69 + else if (des.length == 0) des = val; 1.70 + else des = des + ", " + val; 1.71 +} 1.72 + 1.73 +function ReadForm (obj1, tst) { // Read the user form 1.74 +var i,j,pos; 1.75 + amt=0;des="";op1a="";op1b="";op2a="";op2b="";op3a="";op3b="";op4a="";op4b="";op5a="";op5b="";op6a="";op6b="";op7a="";op7b="";op8a="";op8b="";op9a="";op9b="";itmn=""; 1.76 + if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount 1.77 + if (obj1.basedes) des = obj1.basedes.value; // base description 1.78 + if (obj1.baseon0) op1a = obj1.baseon0.value; // base options 1.79 + if (obj1.baseos0) op1b = obj1.baseos0.value; 1.80 + if (obj1.baseon1) op2a = obj1.baseon1.value; 1.81 + if (obj1.baseos1) op2b = obj1.baseos1.value; 1.82 + if (obj1.baseon2) op3a = obj1.baseon2.value; 1.83 + if (obj1.baseos2) op3b = obj1.baseos2.value; 1.84 + if (obj1.baseon3) op4a = obj1.baseon3.value; 1.85 + if (obj1.baseos3) op4b = obj1.baseos3.value; 1.86 + if (obj1.baseon4) op5a = obj1.baseon4.value; 1.87 + if (obj1.baseos4) op5b = obj1.baseos4.value; 1.88 + if (obj1.baseon5) op6a = obj1.baseon5.value; 1.89 + if (obj1.baseos5) op6b = obj1.baseos5.value; 1.90 + if (obj1.baseon6) op7a = obj1.baseon6.value; 1.91 + if (obj1.baseos6) op7b = obj1.baseos6.value; 1.92 + if (obj1.baseon7) op8a = obj1.baseon7.value; 1.93 + if (obj1.baseos7) op8b = obj1.baseos7.value; 1.94 + if (obj1.baseon8) op9a = obj1.baseon8.value; 1.95 + if (obj1.baseos8) op9b = obj1.baseos8.value; 1.96 + if (obj1.baseitn) itmn = obj1.baseitn.value; 1.97 + for (i=0; i<obj1.length; i++) { // run entire form 1.98 + obj = obj1.elements[i]; // a form element 1.99 + 1.100 + 1.101 + 1.102 + 1.103 + 1.104 + if (obj.type == "select-one") { // just selects 1.105 + if (obj.name == "quantity" || 1.106 + obj.name == "amount") continue; 1.107 + pos = obj.selectedIndex; // which option selected 1.108 + val = obj.options[pos].value; // selected value 1.109 + ChkTok (obj1); // check for any specials 1.110 + 1.111 + if (obj.name == "on0" || // let this go where it wants 1.112 + obj.name == "os0" || 1.113 + obj.name == "on1" || 1.114 + obj.name == "os1" || 1.115 + obj.name == "on2" || 1.116 + obj.name == "os2" || 1.117 + obj.name == "on3" || 1.118 + obj.name == "os3" || 1.119 + obj.name == "on4" || 1.120 + obj.name == "os4" || 1.121 + obj.name == "on5" || 1.122 + obj.name == "os5" || 1.123 + obj.name == "on6" || 1.124 + obj.name == "os6" || 1.125 + obj.name == "on7" || 1.126 + obj.name == "os7" || 1.127 + obj.name == "on8" || 1.128 + obj.name == "os8" || 1.129 + obj.name == "on9" || 1.130 + obj.name == "os9") continue; 1.131 + 1.132 + StorVal (); 1.133 + 1.134 + } else 1.135 + if (obj.type == "checkbox" || // just get checkboxex 1.136 + obj.type == "radio") { // and radios 1.137 + if (obj.checked) { 1.138 + val = obj.value; // the value of the selection 1.139 + ChkTok (obj1); 1.140 + StorVal (); 1.141 + } 1.142 + } else 1.143 + if (obj.type == "select-multiple") { //one or more 1.144 + for (j=0; j<obj.options.length; j++) { // run all options 1.145 + if (obj.options[j].selected) { 1.146 + val = obj.options[j].value; // selected value (default) 1.147 + ChkTok (obj1); 1.148 + StorVal (); 1.149 + } 1.150 + } 1.151 + } else 1.152 + if ((obj.type == "text" || // just read text, 1.153 + obj.type == "textarea") && 1.154 + obj.name != "tot" && // but not from here 1.155 + obj.name != "quantity") { 1.156 + val = obj.value; // get the data 1.157 + //if (val == "" && tst) 1.158 + //{ // force an entry 1.159 + // alert ("Enter data for " + obj.id); 1.160 + // return false; 1.161 + //} 1.162 + StorVal (); 1.163 + } 1.164 + } 1.165 +// Now summarize stuff we just processed, above 1.166 + if (op1a.length > 0) obj1.on0.value = op1a; 1.167 + if (op1b.length > 0) obj1.os0.value = op1b; 1.168 + if (op2a.length > 0) obj1.on1.value = op2a; 1.169 + if (op2b.length > 0) obj1.os1.value = op2b; 1.170 + if (op3a.length > 0) obj1.on2.value = op3a; 1.171 + if (op3b.length > 0) obj1.os2.value = op3b; 1.172 + if (op4a.length > 0) obj1.on3.value = op4a; 1.173 + if (op4b.length > 0) obj1.os3.value = op4b; 1.174 + if (op5a.length > 0) obj1.on4.value = op5a; 1.175 + if (op5b.length > 0) obj1.os4.value = op5b; 1.176 + if (op6a.length > 0) obj1.on5.value = op6a; 1.177 + if (op6b.length > 0) obj1.os5.value = op6b; 1.178 + if (op7a.length > 0) obj1.on6.value = op7a; 1.179 + if (op7b.length > 0) obj1.os6.value = op7b; 1.180 + if (op8a.length > 0) obj1.on7.value = op8a; 1.181 + if (op8b.length > 0) obj1.os7.value = op8b; 1.182 + if (op9a.length > 0) obj1.on8.value = op9a; 1.183 + if (op9b.length > 0) obj1.os8.value = op9b; 1.184 + if (itmn.length > 0) obj1.item_number.value = itmn; 1.185 + obj1.item_name.value = des; 1.186 + obj1.amount.value = Dollar (amt); 1.187 + if (obj1.tot) obj1.tot.value = "$" + Dollar (amt); 1.188 +}