annotate buy_files/buycode.js @ 90:08f93d043ed2 laserkard

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