annotate awesome_js/buycode.js @ 106:5b0753c6f34d laserkard tip

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