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