comparison awesome_js/buycode.js @ 78:4ebd94bfecda laserkard

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