view 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 source
1 function Dollar (val) { // force to valid dollar amount
2 var str,pos,rnd=0;
3 if (val < .995) rnd = 1; // for old Netscape browsers
4 str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
5 pos = str.indexOf (".");
6 if (pos > 0) str = str.substring (rnd, pos + 3);
7 return str;
8 }
10 var amt,des,obj,val,op1a,op1b,op2a,op2b,op3a,op3b,op4a,op4b,op5a,op5b,op6a,op6b,op7a,op7b,op8a,op8b,op9a,op9b,itmn;
12 function ChkTok (obj1) {
13 var j,tok,ary=new Array (); // where we parse
14 ary = val.split (" "); // break apart
15 for (j=0; j<ary.length; j++) { // look at all items
16 // first we do single character tokens...
17 if (ary[j].length < 2) continue;
18 tok = ary[j].substring (0,1); // first character
19 val = ary[j].substring (1); // get data
20 if (tok == "@") amt = val * 1.0;
21 if (tok == "+") amt = amt + val*1.0;
22 if (tok == "%") amt = amt + (amt * val/100.0);
23 if (tok == "-") amt = amt - val*1.0;
24 if (tok == "#") { // record item number
25 if (obj1.item_number) obj1.item_number.value = val;
26 ary[j] = ""; // zap this array element
27 }
28 // Now we do 3-character tokens...
29 if (ary[j].length < 4) continue;
30 tok = ary[j].substring (0,3); // first 3 chars
31 val = ary[j].substring (3); // get data
32 if (tok == "s1=") { // value for shipping
33 if (obj1.shipping) obj1.shipping.value = val;
34 ary[j] = ""; // clear it out
35 }
36 if (tok == "s2=") { // value for shipping2
37 if (obj1.shipping2) obj1.shipping2.value = val;
38 ary[j] = ""; // clear it out
39 }
40 }
41 val = ary.join (" "); // rebuild val with what's left
42 }
44 function StorVal () {
45 var tag;
46 tag = obj.name.substring (obj.name.length-2); // get flag
47 if (tag == "1a") op1a = op1a + " " + val;
48 else if (tag == "1b") op1b = op1b + " " + val;
49 else if (tag == "2a") op2a = op2a + " " + val;
50 else if (tag == "2b") op2b = op2b + " " + val;
51 else if (tag == "3a") op3a = op3a + " " + val;
52 else if (tag == "3b") op3b = op3b + " " + val;
53 else if (tag == "4a") op4a = op4a + " " + val;
54 else if (tag == "4b") op4b = op4b + " " + val;
55 else if (tag == "5a") op5a = op5a + " " + val;
56 else if (tag == "5b") op5b = op5b + " " + val;
57 else if (tag == "6a") op6a = op6a + " " + val;
58 else if (tag == "6b") op6b = op6b + " " + val;
59 else if (tag == "7a") op7a = op7a + " " + val;
60 else if (tag == "7b") op7b = op7b + " " + val;
61 else if (tag == "8a") op8a = op8a + " " + val;
62 else if (tag == "8b") op8b = op8b + " " + val;
63 else if (tag == "9a") op9a = op9a + " " + val;
64 else if (tag == "9b") op9b = op9b + " " + val;
65 else if (tag == "3i") itmn = itmn + " " + val;
66 else if (des.length == 0) des = val;
67 else des = des + ", " + val;
68 }
70 function ReadForm (obj1, tst) { // Read the user form
71 var i,j,pos;
72 amt=0;des="";op1a="";op1b="";op2a="";op2b="";op3a="";op3b="";op4a="";op4b="";op5a="";op5b="";op6a="";op6b="";op7a="";op7b="";op8a="";op8b="";op9a="";op9b="";itmn="";
73 if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount
74 if (obj1.basedes) des = obj1.basedes.value; // base description
75 if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
76 if (obj1.baseos0) op1b = obj1.baseos0.value;
77 if (obj1.baseon1) op2a = obj1.baseon1.value;
78 if (obj1.baseos1) op2b = obj1.baseos1.value;
79 if (obj1.baseon2) op3a = obj1.baseon2.value;
80 if (obj1.baseos2) op3b = obj1.baseos2.value;
81 if (obj1.baseon3) op4a = obj1.baseon3.value;
82 if (obj1.baseos3) op4b = obj1.baseos3.value;
83 if (obj1.baseon4) op5a = obj1.baseon4.value;
84 if (obj1.baseos4) op5b = obj1.baseos4.value;
85 if (obj1.baseon5) op6a = obj1.baseon5.value;
86 if (obj1.baseos5) op6b = obj1.baseos5.value;
87 if (obj1.baseon6) op7a = obj1.baseon6.value;
88 if (obj1.baseos6) op7b = obj1.baseos6.value;
89 if (obj1.baseon7) op8a = obj1.baseon7.value;
90 if (obj1.baseos7) op8b = obj1.baseos7.value;
91 if (obj1.baseon8) op9a = obj1.baseon8.value;
92 if (obj1.baseos8) op9b = obj1.baseos8.value;
93 if (obj1.baseitn) itmn = obj1.baseitn.value;
94 for (i=0; i<obj1.length; i++) { // run entire form
95 obj = obj1.elements[i]; // a form element
101 if (obj.type == "select-one") { // just selects
102 if (obj.name == "quantity" ||
103 obj.name == "amount") continue;
104 pos = obj.selectedIndex; // which option selected
105 val = obj.options[pos].value; // selected value
106 ChkTok (obj1); // check for any specials
108 if (obj.name == "on0" || // let this go where it wants
109 obj.name == "os0" ||
110 obj.name == "on1" ||
111 obj.name == "os1" ||
112 obj.name == "on2" ||
113 obj.name == "os2" ||
114 obj.name == "on3" ||
115 obj.name == "os3" ||
116 obj.name == "on4" ||
117 obj.name == "os4" ||
118 obj.name == "on5" ||
119 obj.name == "os5" ||
120 obj.name == "on6" ||
121 obj.name == "os6" ||
122 obj.name == "on7" ||
123 obj.name == "os7" ||
124 obj.name == "on8" ||
125 obj.name == "os8" ||
126 obj.name == "on9" ||
127 obj.name == "os9") continue;
129 StorVal ();
131 } else
132 if (obj.type == "checkbox" || // just get checkboxex
133 obj.type == "radio") { // and radios
134 if (obj.checked) {
135 val = obj.value; // the value of the selection
136 ChkTok (obj1);
137 StorVal ();
138 }
139 } else
140 if (obj.type == "select-multiple") { //one or more
141 for (j=0; j<obj.options.length; j++) { // run all options
142 if (obj.options[j].selected) {
143 val = obj.options[j].value; // selected value (default)
144 ChkTok (obj1);
145 StorVal ();
146 }
147 }
148 } else
149 if ((obj.type == "text" || // just read text,
150 obj.type == "textarea") &&
151 obj.name != "tot" && // but not from here
152 obj.name != "quantity") {
153 val = obj.value; // get the data
154 //if (val == "" && tst)
155 //{ // force an entry
156 // alert ("Enter data for " + obj.id);
157 // return false;
158 //}
159 StorVal ();
160 }
161 }
162 // Now summarize stuff we just processed, above
163 if (op1a.length > 0) obj1.on0.value = op1a;
164 if (op1b.length > 0) obj1.os0.value = op1b;
165 if (op2a.length > 0) obj1.on1.value = op2a;
166 if (op2b.length > 0) obj1.os1.value = op2b;
167 if (op3a.length > 0) obj1.on2.value = op3a;
168 if (op3b.length > 0) obj1.os2.value = op3b;
169 if (op4a.length > 0) obj1.on3.value = op4a;
170 if (op4b.length > 0) obj1.os3.value = op4b;
171 if (op5a.length > 0) obj1.on4.value = op5a;
172 if (op5b.length > 0) obj1.os4.value = op5b;
173 if (op6a.length > 0) obj1.on5.value = op6a;
174 if (op6b.length > 0) obj1.os5.value = op6b;
175 if (op7a.length > 0) obj1.on6.value = op7a;
176 if (op7b.length > 0) obj1.os6.value = op7b;
177 if (op8a.length > 0) obj1.on7.value = op8a;
178 if (op8b.length > 0) obj1.os7.value = op8b;
179 if (op9a.length > 0) obj1.on8.value = op9a;
180 if (op9b.length > 0) obj1.os8.value = op9b;
181 if (itmn.length > 0) obj1.item_number.value = itmn;
182 obj1.item_name.value = des;
183 obj1.amount.value = Dollar (amt);
184 if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
185 }