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