home *** CD-ROM | disk | FTP | other *** search
/ 11 Top Anwendungen / CD_ROM_MAGAZIN.iso / MoneyMethod-Demo / Beispiel / source / scripts / shop.js < prev    next >
Encoding:
JavaScript  |  2000-05-29  |  31.6 KB  |  1,018 lines

  1. //
  2. // Client side shopping system - based on remote JavaScript
  3. //
  4. //
  5. // public functions
  6. // ================
  7. // start(source_location,email,             -> initialisation
  8. //       max_products,
  9. //       max_items_per_product,
  10. //       currency,mwst_excl_incl)
  11. // restart()                                -> reinitialisation (empty orderlist)
  12. // addOrderElem(num,name,bestnum,preisStr
  13. //                      [,optStr])          -> selecting product
  14. // incrOrderElem(i)                         -> increment product counter of product (i)
  15. // decrOrderElem(i)                         -> decrement product counter of product (i)
  16. // deleteOrderElem(i)                       -> deselecting product (i)
  17. // isOrder()                                -> true/false (onSubmit)
  18. // printOrder(target,borderWidth,asform)    -> print order list form in window 'target' as form or as label
  19. // printUserData(target,borderWidth,asform) -> print user data form in window 'target' as form or as label
  20. // checkUserData(target)                    -> true/false (onSubmit)
  21. // printSendButton(target,caption,
  22. //                  redirect_fax,redirect,
  23. //                              infotext)   -> print hidden send message in window 'target' and send button 'caption'
  24. //                                          ie 3.x redirect to side 'redirect_fax'
  25. //                                          do redirect to location 'redirect' after email send in same window
  26. //                                          attention: button click implicits restart()
  27. // define(image_or_str,variable,value)      -> define "image": "+", "-", "x", "ok"
  28. //                         define "string": "NO_ORDER", "MAX_ORDER", "MAX_ITEM", "ORDER_NUM",
  29. //                                          "ORDER_OPTIONAL", "SEARCH_NORESULT", "MAIL_SUBJECT"
  30. //                         define "boolean": "ORDER_VARIABLE", "ORDER_DOUBLE" -> "0/1"
  31. //                         define "payment": "NACHNAHME", "RECHNUNG", "BANK", "KREDIT" -> "float" for additional fee
  32. // search(pdname,pdnum,pdprice)             -> define search query
  33. // printHitList(target,dbname,dbname_i,     -> print hitlist for defined search query
  34. //              dbnum,dbnum_i,dbprice,dbprice_i,dbref)
  35. // test()                                   -> return messagebox of orderList
  36. // copyright(mode)                          -> check and alert version info
  37.  
  38. // globals
  39. // =======
  40. var isScriptLoaded = false;         // true, if script is completely loaded
  41. var MAX;                    // maximum numbers of orders
  42. var MAXITEM;                    // maximum numbers of items per order
  43. var orderList;                  // list of orders
  44. var orderNum;                   // actual number of orders
  45. var userData;                   // user data
  46. var recAction;                  // receiver (email or cgi) -> protocol (mailto/http) neccessary!!
  47. var definePayments = false;         // true, if any payment method is manual defined; initialize payments first
  48.  
  49. // configurable images
  50. var image_delete = "x";         // x image      (delete)
  51. var image_incr = "+";           // + image      (increment)
  52. var image_decr = "-";           // - image      (delete)
  53. var image_upd = "ok";           // update image     (update)
  54.  
  55. // input form modes
  56. var addVariable = false;        // in-/decrement productNum in textbox
  57. var addDouble = false;          // in-/decrement productNum as double
  58.  
  59. // payment modes
  60. var NACHNAHME = 1;              // payment definition
  61. var strNACHNAHME = "Nachnahme";
  62. var feeNACHNAHME = 0;
  63. var RECHNUNG = 2;               // payment definition
  64. var strRECHNUNG = "Rechnung";
  65. var feeRECHNUNG = 0;
  66. var BANKEINZUG = 4;             // payment definition
  67. var strBANKEINZUG = "Bankeinzug";
  68. var feeBANKEINZUG = 0;
  69. var KREDITKARTE = 8;            // payment definition
  70. var strKREDITKARTE = "Kreditkarte";
  71. var feeKREDITKARTE = 0;
  72.  
  73. var ALLPAYMENT = (NACHNAHME | RECHNUNG | BANKEINZUG);
  74. var payment = NACHNAHME;        // default payment
  75. var sendprice;
  76.  
  77. // MwSt
  78. var mwst;
  79.  
  80. // resource strings     (static)
  81. // ================
  82. var strProduct = "Produkt";
  83. var strId = "ISBN";
  84. var strPrice = "Einzelpreis";
  85. var strProductTotal = "Gesamt";
  86. var strOrderTotal = "Bestellsumme";
  87. var strOrderCost = "zzgl. Versandkosten";
  88. var strTotal = "Gesamtsumme";
  89.  
  90. var strCheckFailure = "Es fehlt die Eingabe des Feldes";
  91.  
  92. var strPrename = "Vorname";
  93. var strName = "Name";
  94. var strStreet = "Stra▀e";
  95. var strZip = "Plz";
  96. var strCity = "Stadt";
  97. var strCountry = "Land";
  98. var strTelephone = "Telefon";
  99. var strFax = "Fax";
  100. var strEmail = "E-Mail";
  101.  
  102. var strPayment = "Zahlungsart";
  103. var strBankname = "Name der Bank";
  104. var strKtnr = "Kontonummer";
  105. var strBlz = "Blz";
  106. var strPlus = "zzgl.";
  107. var strKreditinstitut = "Kreditinstitut";
  108. var strKreditnr = "Kartennummer";
  109. var strKreditdatum = "Gⁿltig bis";
  110. var Kreditdb = new Array("Visa","Eurocard/Mastercard","American Express","Diners Club");
  111.  
  112. var strMaxOrder1 = "Die maximale Gesamtbestellmenge von";
  113. var strMaxOrder2 = "Produkten ist erreicht.";
  114. var strMaxItem1 = "Die maximale Bestellmenge dieses Produktes von";
  115. var strMaxItem2 = "ist erreicht.";
  116.  
  117. var strCountIncr = "Anzahl erh÷hen";
  118. var strCountDecr = "Anzahl verringern";
  119. var strCountUpd = "Anzahl aktualisieren";
  120. var strCountDel = "Produkt entfernen";
  121.  
  122. var strVersionWarning = "Sie ben÷tigen eine aktuellere Version Ihres Browsers, um das Shopping System zu nutzen!";
  123.  
  124. var strMwst = "MwSt.";
  125. var strMwstIncl = "inklusive";
  126. var strMwstExcl = "zzgl.";
  127.  
  128.  
  129. var strEuroCur="EUR";
  130. var strEuroPrice="Euro";
  131. var ECost;
  132.  
  133. // resource strings     (dynamic)
  134. // ================
  135. var slocation;
  136. var strMaxOrder;
  137. var strMaxItem;
  138. var strCurrency;
  139. var strNoOrder = "<CENTER>Es liegt derzeit keine Bestellung vor</CENTER><BR>";
  140. var strOrderNum = "Anzahl";
  141. var strOrderOptional = "";
  142. var strSearchNoResult = "Es wurden keine Treffer zu den angegebenen Suchbegriffen gefunden.";
  143. var strMailSubject = "Bestellung von ½▒¢1/2⌡∙Ñτµ";
  144.  
  145. //*******************************************************************************************
  146.  
  147. // return text for horizontal line
  148.  
  149. function hline ()
  150. {
  151.   s = "<table height='1' width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='";
  152.   s += linecolor;
  153.   s += "'><tr><td><img src='Images/pixel.gif'></td></tr></table>"
  154.   return s;
  155. }
  156.  
  157. // copyright check function
  158. function copyright(msgbox)
  159. {
  160.  var now = new Date();
  161.  var till = new Date(Date.UTC(99,12-1,31));
  162.  
  163.  if(msgbox)
  164.     alert("Shopping System Version " + VERSION + " (" +
  165.                                     till.getDate() + "/" +
  166.                                     (till.getMonth() + 1) + "/" +
  167.                                     till.getYear() + ")" +
  168.                                     ".");
  169.  return(now.getTime() <= till.getTime());
  170. }
  171.  
  172. // check browser version mimimum
  173. function check_browser(netscape_version, ie_version)
  174. {
  175.  var name = navigator.appName;
  176.  var version = parseInt("" + navigator.appVersion.substring(0,1));
  177.  
  178.  //alert("*" + name + "#" + version + "*");
  179.  if(((name.indexOf("Netscape") > -1) && (version >= netscape_version)) ||
  180.     ((name.indexOf("Microsoft") > -1) && (version >= ie_version)))
  181.     return(true);
  182.  else
  183.     return(false);
  184. }
  185.  
  186. // init function
  187. function start(source_location,action,
  188.         max_products,max_items_per_product,
  189.         currency, rate, mwst_excl_incl, delcost, lcolor)
  190. {
  191.  // check client version
  192.  
  193.  if(!check_browser(3,2))
  194.     alert(strVersionWarning);
  195.  
  196.  // set location of this source
  197.  slocation = source_location;
  198.  if(slocation.length > 0 &&
  199.     slocation.charAt(slocation.length - 1) != ".")
  200.     slocation += ".";
  201.  
  202.  // set globals from args
  203.  MAX = max_products;
  204.  strMaxOrder = strMaxOrder1 + " " + MAX + " " + strMaxOrder2;
  205.  MAXITEM = max_items_per_product;
  206.  strMaxItem = strMaxItem1 + " " + MAXITEM + " " + strMaxItem2;
  207.  strCurrency = currency;
  208.  recAction = action;
  209.  mwst = mwst_excl_incl;
  210.  if(mwst > 0)
  211.     strMwstExcl += " " + mwst + "% "  + strMwst;            // exclusive (positive MwSt.)
  212.  else if(mwst < 0)
  213.     strMwstIncl += " " + Math.abs(mwst) + "% " + strMwst;   // inclusive (negative MwSt.)
  214.  else
  215.     strMwstExcl = strMwstIncl = "";
  216.  
  217.  // init new user
  218.  userData = new getUser();
  219.  
  220.  // init new orderList
  221.  restart();
  222.  
  223.  
  224.  sendprice=delcost;
  225.  linecolor=lcolor;
  226.  ECost=rate;
  227.  
  228.  return(copyright(0));
  229. }
  230.  
  231. // restart function (empty orderList)
  232. function restart()
  233. {
  234.  initGlobals();
  235. }
  236.  
  237. // test function for debugging internals
  238. function test()
  239. {
  240.  var s = "";
  241.  
  242.  for(var i = 1; i <= orderNum; i++)
  243.     s += orderList[i].anzahl + " x " + orderList[i].name + " " + orderList[i].name + "\n";
  244.  
  245.  alert("DataBase Input:\n" + s);
  246. }
  247.  
  248. // create a list of 'num' elements
  249. function getList(num)
  250. {
  251.  this.length = num;
  252.  for(var i = 1; i <= num; i++)
  253.     this[i] = 0;
  254.  
  255.  return(this);
  256. }
  257.  
  258. // create a user
  259. function getUser()
  260. {
  261.  this.prename = "";
  262.  this.name = "";
  263.  this.street = "";
  264.  this.zip = "";
  265.  this.city = "";
  266.  this.country = "";
  267.  this.tel = "";
  268.  this.fax = "";
  269.  this.email = "";
  270.  
  271.  this.payment = "";
  272.  this.bankname = "";
  273.  this.ktnr = "";
  274.  this.blz = "";
  275.  
  276.  this.kreditcompany = "";
  277.  this.kreditnr = "";
  278.  this.validation = "";
  279.  
  280.  this.fee = 0;
  281.  
  282.  return(this);
  283. }
  284.  
  285. // init all globals
  286. function initGlobals()
  287. {
  288.  orderList = new getList(MAX);
  289.  orderNum = 0;
  290. }
  291.  
  292. // lookup in orderList and return index
  293. function lookUp(index)
  294. {
  295.  for(var i = 1; i <= orderNum; i++)
  296.     if(orderList[i].index == index)
  297.         return(i);
  298.  
  299.  return(0);
  300. }
  301.  
  302. // create new order element
  303. function orderElem(num,name,bestnum,preis,hrf,maxitem,index)
  304. {
  305.  this.anzahl = num;
  306.  this.name = name;
  307.  this.bestnum = bestnum;
  308.  this.preis = preis;
  309.  this.hrf = hrf;
  310.  this.maxitem = maxitem;
  311.  this.index = index;
  312. }
  313.  
  314. // change a comma through dot
  315. function comma2dot(str)
  316. {
  317.  var i;
  318.  var tmp = str;
  319.  var len = str.length;
  320.  
  321.  i = -1;
  322.  while((i = str.indexOf(",",i+1)) >= 0) {
  323.     tmp = tmp.substring(0,i) + "." + tmp.substring(i+1,str.length);
  324.  }
  325.  
  326.  str = tmp;
  327.  i = -1;
  328.  while((i = str.indexOf(".",i+1)) >= 0) {
  329.     if(len - (i+1) <= 2) {
  330.         break;
  331.     }
  332.     tmp = tmp.substring(0,i) + tmp.substring(i+1,str.length);
  333.  }
  334.  
  335.  return(tmp);
  336. }
  337.  
  338. // add a new order in orderList
  339. function addOrderElem(numStr,name,bestnum,preisStr, link, max, index)
  340. {
  341.  var i = lookUp(index);
  342.  var preis;
  343.  var num;
  344.  var tmp;
  345.  
  346.  // get price
  347.  preis = parseFloat(comma2dot(preisStr));
  348.  
  349.  // get number
  350.  num = 0 + (addDouble ? parseFloat(comma2dot(numStr)) : parseInt(numStr));
  351.  
  352.  // determine max
  353.  if(num > MAXITEM) {
  354.     // max items reached
  355.     alert(strMaxItem);
  356.     return false;
  357.  } else if((i <= 0) && (orderNum >= MAX) && (num > 0)) {
  358.     // max orders reached
  359.     alert(strMaxOrder);
  360.     return false;
  361.  }
  362.  
  363.  // control optStr
  364. // if(addOrderElem.arguments.length < 5)
  365. //    optStr = "";
  366.  
  367.  // insert/update/delete order
  368.  if(num <= 0) {
  369.     if(i > 0)
  370.         // delete
  371.         deleteOrderElem(i);
  372.  } else {
  373.     if(i > 0)
  374.         // update
  375.         orderList[i].anzahl = num;
  376.     else
  377.         // insert
  378.         orderList[++orderNum] = new orderElem(num,name,bestnum,preis,link, max, index);
  379.  }
  380.   return true;
  381. }
  382.  
  383.  
  384. // increment number of orders for orderListElem 'i'
  385. function incrOrderElem(i)
  386. {
  387.  if(i <= orderNum && i > 0) {
  388.     if(orderList[i].anzahl < MAXITEM)
  389.         orderList[i].anzahl++;
  390.     else
  391.         alert(strMaxItem);
  392.  }
  393. }
  394.  
  395. // decrement number of orders for orderListElem 'i'.
  396. // if neccessary delete orderListElem 'i' and rearrange
  397. // orderList.
  398. function decrOrderElem(i)
  399. {
  400.  if(i <= orderNum && i > 0) {
  401.     orderList[i].anzahl--;
  402.     if(orderList[i].anzahl <= 0)
  403.         deleteOrderElem(i);
  404.  }
  405. }
  406.  
  407. // delete orderListElem 'i'
  408. function deleteOrderElem(i)
  409. {
  410.  if(i <= orderNum && i > 0) {
  411.     for(var j = i; j < orderNum; j++)
  412.         orderList[j] = orderList[j + 1];
  413.     orderNum--;
  414.  }
  415. }
  416.  
  417. // convert float to string
  418. function f2s(f)
  419. {
  420.  var num = "" + Math.round(f * 100);
  421.  var s;
  422.  
  423.  if(num.length == 0)
  424.     s = "0,00";
  425.  else if(num.length == 1)
  426.     s = "0,0" + num;
  427.  else if(num.length == 2)
  428.     s = "0," + num;
  429.  else {
  430.     if(num.length > 5)
  431.         s = num.substring(0,num.length - 5) + "." + num.substring(num.length - 5,num.length - 2) + ",";
  432.     else
  433.         s = num.substring(0,num.length - 2) + "," ;
  434.     s += num.substring(num.length - 2, num.length);
  435.  }
  436.  
  437.  return(s);
  438. }
  439.  
  440. // retrieve file from local (\) or remote (/) URL target
  441. function getFile(url)
  442. {
  443.  var delim = (url.indexOf("\\") > -1 ? "\\" : "/");
  444.  
  445.  return(url.substring(url.lastIndexOf(delim) + 1,url.length));
  446. }
  447.  
  448. // function to reload target window
  449. function reload(target)
  450. {
  451.  if(navigator.appName.indexOf("Netscape") > -1)
  452.     target.location.reload(true);
  453.  else
  454.     // target.location = target.location.href does not work (cache!!!)
  455.     target.location = getFile(target.location.href);
  456. }
  457.  
  458. // check if there is a orderList
  459. function isOrder()
  460. {
  461.  return(orderNum > 0);
  462. }
  463.  
  464. // print complete orderList
  465. function printOrder(target,borderWidth,asform)
  466. {
  467.  var sum;
  468.  var total = 0;
  469.  var tax = 0;
  470.  var colspan;
  471.  
  472.  if(!isOrder()) {
  473.     target.document.write(strNoOrder);
  474.     return;
  475.  }
  476.  var s = "<FORM NAME=\"sel\"><TABLE align='center' BORDER=" + borderWidth + " WIDTH=\"725\" align='center'><TR>";
  477.  if(asform) {
  478. //    s += "<TH>" + strChoice + "</TH>";
  479.     colspan = 6;
  480.  }
  481.  else {
  482.     colspan = 6;
  483.  }
  484.  if(strOrderOptional > "")
  485.     colspan++;
  486.  
  487.  s += "<TH ALIGN=CENTER>" + strId + "</TH>";
  488.  s += "<TH ALIGN=LEFT>"   + strProduct + "</TH>";
  489.  s += "<TH ALIGN=CENTER>" + strOrderNum + "</TH>";
  490.  if(strOrderOptional > "")
  491.     s += "<TH ALIGN=CENTER>" + strOrderOptional + "</TH>";
  492.  s += "<TH ALIGN=RIGHT>" + strPrice + "</TH>";
  493.  s += "<TH ALIGN=RIGHT>" + strProductTotal + "</TH>";
  494.  s += "<TH ALIGN=RIGHT>" + strEuroPrice + "</TH>";
  495. // if(asform)
  496. //    s += "<TH></TH>";
  497.  
  498.  s += "</TR>";
  499.  target.document.write(s);
  500.  
  501.  for(var i = 1; i <= orderNum; i++) {
  502.     sum = orderList[i].anzahl * orderList[i].preis;
  503.     total += sum;
  504.     s = "<TR>";
  505.     // éδó«ñ CheckBox
  506. /*
  507.     if(asform) {
  508.             s += "<td align=\"center\">"; // width=\"5%\"
  509.             s += "<input type=\"checkbox\" name=\"ch" + i + "\" checked onClick=\"javascript:ChCheckBox(this, sel);\">";
  510.             s += "</TD>";
  511.     }
  512. */
  513.     // éδó«ñ ISBN
  514.     s += "<td>"; // width=\"10%\"
  515.     s += "<p align=\"center\">" + orderList[i].bestnum;
  516.     s += "<input type=\"hidden\" name=\"isbn" + i + "\"value=\"" + orderList[i].bestnum + "\"></p>";
  517. //    s += (addDouble ? f2s(orderList[i].anzahl) : orderList[i].anzahl);
  518.     s += "</TD>";
  519.     // éδó«ñ Produkt
  520.     s += "<TD><a href=\"" + orderList[i].hrf + "\">" + orderList[i].name + "</a>";
  521.     s += "<input type=\"hidden\" name=\"title" + i + "\" value=\"" + orderList[i].name + "\">";
  522.     s += "<input type=\"hidden\" name=\"link" + i + "\" value=\"" + orderList[i].hrf + "\"></TD>";
  523. //    if(strOrderOptional > "")
  524. //        s += "<TD ALIGN=LEFT>" + orderList[i].optstr + "</TD>";
  525.     // éδó«ñ Anzahl
  526.     if (asform) {
  527.         s += "<TD><input type=\"text\" name=\"quantity" + i + "\" value=\"" + orderList[i].anzahl + "\" onBlur=\"ChangeTxt(this, sel);\" size=\"5\">";
  528.         }
  529.     else {
  530.         s += "<TD ALIGN=RIGHT>" + orderList[i].anzahl;
  531.         }
  532.     s += "<input type=\"hidden\" name=\"num" + i + "\" value=\"" + orderList[i].maxitem + "\">";
  533.     s += "<input type=\"hidden\" name=\"price" + i + "\" value=\"" + orderList[i].preis + "\">";
  534.     s += "<input type=\"hidden\" name=\"index" + i + "\" value=\"" + orderList[i].index + "\">";
  535.     s += "<input type=\"hidden\" name=\"prsh" + i + "\" value=\"" + orderList[i].preiship + "\"></TD>";
  536.  
  537.  
  538.     s += "<TD ALIGN=RIGHT>" + f2s(orderList[i].preis) + " " + strCurrency + "</TD>";
  539.     s += "<TD ALIGN=RIGHT>" + f2s(sum) + " " + strCurrency + "</TD>";
  540.     s += "<TD ALIGN=RIGHT>" + f2s(sum*ECost) + " " + strEuroCur + "</TD>";
  541. //    if(asform) {
  542. //        s += "<TD ALIGN=CENTER>";
  543. //        s += "<A HREF=\"javascript:" + slocation + "deleteOrderElem(" + i + ");" + slocation + "reload(self);\">" + image_delete + "</A>";
  544. //        s += "</TD>";
  545. //    }
  546.     s += "</TR>";
  547.     target.document.write(s);
  548.  }
  549.  
  550. // Hier: Achtung !! éδó«ñ ú«α¿º«¡Γá½∞¡«⌐ τÑαΓδ
  551.  s = "<TR>";
  552.  s += "<TD COLSPAN=" + colspan + ">" + hline() +"</TD></TR><TR>";
  553.  s += "<TD COLSPAN=" + (colspan - 2) + " ALIGN=RIGHT><B>" + strOrderTotal + "</B></TD>";
  554.  s += "<TD ALIGN=RIGHT><B>" + f2s(total) + " " + strCurrency + "</B></TD>";
  555.  s += "<TD ALIGN=RIGHT><b>" + f2s(total*ECost) + " " + strEuroCur + "</b></TD>";
  556.  s += "</TR>";
  557.  
  558. s += "<TR>";
  559. s += "<TD COLSPAN=" + (colspan - 2) + " ALIGN=RIGHT>Versandkosten</TD>";
  560. s += "<TD ALIGN=RIGHT>" + f2s(sendprice) + " " + strCurrency + "</TD>";
  561. s += "<TD ALIGN=RIGHT>" + f2s(sendprice*ECost) + " " + strEuroCur + "</TD>";
  562. s += "</TR>";
  563. total += sendprice;
  564.  
  565.  
  566.  s += "<TR>";
  567.  s += "<TD COLSPAN=" + colspan + ">" + hline() + "</TD></TR><TR>";
  568. // s += "<TD COLSPAN=" + colspan + "><HR></TD></TR><TR>";
  569.  s += "<TD COLSPAN=" + (colspan - 2) + " ALIGN=RIGHT><B>" + strTotal + "</B></TD>";
  570.  s += "<TD ALIGN=RIGHT><B><U>" + f2s(total) + " " + strCurrency + "</U></B></TD>";
  571.  s += "<TD ALIGN=RIGHT><b><u>" + f2s(total*ECost) + " " + strEuroCur + "</u></b></TD>";
  572.  s += "</TR>";
  573.  
  574.  s += "<TD COLSPAN=" + colspan + ">" + hline() + "</TD></TR><TR>";
  575.  if (asform) {
  576.     s += "<tr>";
  577.     s += "<td colspan=" + (colspan - 1) + "><div align=\"right\">";
  578.     s += "<input type=\"button\" name=\"Count\" value=\" Neuberechnen \" onClick=\"self.location.reload();\">";
  579.     s += "</div></td>";
  580.     s += "<td><div align=\"right\">";
  581.     s += "<input type=\"button\" name=\"Button\" value=\" Bestellen \" onClick=\"self.location='mailform.htm';\">";
  582.     s += "</div></td></tr>";
  583.  }
  584.  s += "</TABLE></FORM>";
  585.  
  586.  target.document.write(s);
  587. }
  588.  
  589. // print text or label
  590. function printInput(variable,len,value,valuename,astext)
  591. {
  592.  if(astext)
  593.     return("<INPUT TYPE=TEXT NAME=" + variable + " MAXLENGTH=" + len + " SIZE=" + len + " VALUE=\"" + value + "\" onChange=\"" + slocation + valuename + "=this.value;\">");
  594.  else
  595.     return(value);
  596. }
  597.  
  598. // print user data form
  599. function printUserData(target,borderwidth,asform)
  600. {
  601.  var s = "<FORM NAME=\"userform\"><TABLE align='center' BORDER=" + borderwidth + ">";
  602.  var blanks = "";
  603.  var i;
  604.  
  605.  for(i = 0; i < 5; i++)
  606.     blanks += " ";
  607.  
  608.  s += "<TR><TD ALIGN=LEFT><B>" + strPrename + ":" + blanks + "</B></TD>";
  609.  s += "<TD COLSPAN=3 ALIGN=LEFT>" + printInput("prename",10,userData.prename,"userData.prename",asform) + "</TD></TR>";
  610.  
  611.  s += "<TR><TD ALIGN=LEFT><B>" + strName + ":</B></TD>";
  612.  s += "<TD COLSPAN=3 ALIGN=LEFT>" + printInput("name",40,userData.name,"userData.name",asform) + "</TD></TR>";
  613.  
  614.  s += "<TR><TD ALIGN=LEFT><B>" + strStreet + ":</B></TD>";
  615.  s += "<TD COLSPAN=3 ALIGN=LEFT>" + printInput("street",40,userData.street,"userData.street",asform) + "</TD></TR>";
  616.  
  617.  s += "<TR><TD ALIGN=LEFT><B>" + strZip + ":</B></TD>";
  618.  s += "<TD ALIGN=LEFT>" + printInput("zip",10,userData.zip,"userData.zip",asform) + blanks + "</TD>";
  619.  s += "<TD ALIGN=LEFT><B>" + strCity + ":</B></TD>";
  620.  s += "<TD ALIGN=LEFT>" + printInput("city",15,userData.city,"userData.city",asform) + "</TD></TR>";
  621.  
  622.  s += "<TR><TD ALIGN=LEFT><B>" + strCountry + ":</B></TD>";
  623.  s += "<TD COLSPAN=3 ALIGN=LEFT>" + printInput("country",40,userData.country,"userData.country",asform) + "</TD></TR>";
  624.  
  625.  s += "<TR><TD ALIGN=LEFT><B>" + strTelephone + ":</B></TD>";
  626.  s += "<TD ALIGN=LEFT>" + printInput("tel",15,userData.tel,"userData.tel",asform) + blanks + "</TD>";
  627.  s += "<TD ALIGN=LEFT><B>" + strFax + ":</B></TD>";
  628.  s += "<TD ALIGN=LEFT>" + printInput("fax",15,userData.fax,"userData.fax",asform) + "</TD></TR>";
  629.  
  630.  s += "<TR><TD ALIGN=LEFT><B>" + strEmail + ":</B></TD>";
  631.  s += "<TD COLSPAN=3 ALIGN=LEFT>" + printInput("email",40,userData.email,"userData.email",asform) + "</TD></TR>";
  632.  
  633.  s += "</TABLE>";
  634.  if (asform) {
  635.     s += "<table align='center'><tr><td><INPUT type=button value=\"Bestellung absenden\" onClick=\"if(parent.shop.checkUserData(self)) self.location='confirm.htm';\"></td></tr></table>";
  636.  }
  637.  s += "</FORM>";
  638.  target.document.write(s);
  639. }
  640.  
  641. // ckeck a user data
  642. function check(field, str, elem)
  643. {
  644.  if(str == "") {
  645.     alert(strCheckFailure + " >" + field + "<");
  646.     elem.focus();
  647.     return(false);
  648.  }
  649.  
  650.  return(true);
  651. }
  652.  
  653. // check completeness of user data
  654. function checkUserData(target)
  655. {
  656.  var ret;
  657.  
  658.  if((ret = check(strName,userData.name,target.document.userform.name)) == false)
  659.     return(ret);
  660.  if((ret = check(strStreet,userData.street,target.document.userform.street)) == false)
  661.     return(ret);
  662.  if((ret = check(strZip,userData.zip,target.document.userform.zip)) == false)
  663.     return(ret);
  664.  if((ret = check(strCity,userData.city,target.document.userform.city)) == false)
  665.     return(ret);
  666.  if((ret = check(strCountry,userData.country,target.document.userform.country)) == false)
  667.     return(ret);
  668.  
  669.  if(userData.payment == strBANKEINZUG) {
  670.     if((ret = check(strBankname,userData.bankname,target.document.userform.bank)) == false)
  671.         return(ret);
  672.     if((ret = check(strKtnr,userData.ktnr,target.document.userform.ktnr)) == false)
  673.         return(ret);
  674.     if((ret = check(strBlz,userData.blz,target.document.userform.blz)) == false)
  675.         return(ret);
  676.  }
  677.  
  678.  if(userData.payment == strKREDITKARTE) {
  679.     if((ret = check(strKreditnr,userData.kreditnr,target.document.userform.kreditnr)) == false)
  680.         return(ret);
  681.     if((ret = check(strKreditdatum,userData.validation,target.document.userform.kreditvalidation)) == false)
  682.         return(ret);
  683.  }
  684.  
  685.  return(true);
  686. }
  687.  
  688. function do_submit(target, redirect, infotext)
  689. {
  690.  
  691. // parent.parent.content.order.submit();
  692.  target.document.order.submit();
  693.  
  694.  if (sendmethod=="1")
  695.   {
  696.     setTimeout("parent.parent." + target.name + ".location='" + redirect + "'", 10000);
  697.     // initialize order
  698.   }
  699.  restart();
  700.  return(true);
  701. }
  702.  
  703.  
  704. // print email form or redirect to a faxable side
  705. function printSendButton(target,caption,redirect_fax,redirect,infotext)
  706. {
  707.  if(!isOrder())
  708.     return;
  709.  
  710.     if(!check_browser(0,4))
  711.     {
  712.         // ie does not support correctly mailto protocol, netscape does it
  713.         target.location = redirect_fax;
  714.         return;
  715.     }
  716.  
  717.  var s = "<center><form name='order' ";
  718.  if (sendmethod=='1') s+= "enctype='text/plain'"; 
  719.  s+= "encoding='iso-8859-1'";
  720.  s+= " method='post' action=\"" + recAction;
  721.  
  722. // if(mailMode)
  723. //    s += "?subject=" + strMailSubject + "\" enctype=\"text/plain" + NAME=\"mailform\" ;
  724.  
  725.  s += "\" onClick=\"" + slocation + "restart()\">";
  726.  
  727.  s += "<INPUT TYPE=HIDDEN NAME=\"To\" VALUE=\"" + storemail + "\">";
  728.  s += "<INPUT TYPE=HIDDEN NAME=\"From\" VALUE=\"" + userData.email + "\">";
  729.  s += "<INPUT TYPE=HIDDEN NAME=\"Order\" VALUE=\"\n";
  730.  s += "\n------------------------------\n";
  731.  var date=new Date();
  732.  s += "Datum: " + date.toLocaleString() + "\n" +
  733.       "Vorname: " + userData.prename + "\n" +
  734.       "Name:    " + userData.name + "\n" +
  735.       "Strasse: " + userData.street + "\n" +
  736.       "Plz:     " + userData.zip + "\n" +
  737.       "Stadt:   " + userData.city + "\n" +
  738.       "Land:    " + userData.country + "\n" +
  739.       "Tel:     " + userData.tel + "\n" +
  740.       "Fax:     " + userData.fax + "\n" +
  741.       "Email:   " + userData.email + "\n\n";
  742.  sum = 0;
  743.  for(var i = 1; i <= orderNum; i++) {
  744. //    sum = orderList[i].anzahl * orderList[i].preis;
  745. //    s += "orderNum: " + orderNum + ":"+ i + "; "; // DEBUG MODE
  746.     s += "----- Produkt " + i + "-----\n";
  747.     s += "ISBN: " + orderList[i].bestnum + "; \n";
  748.     s += "Anzahl: " + orderList[i].anzahl + "; \n";
  749.     s += "Titel: " + orderList[i].name + "; \n";   // always send something
  750.     s += "Preis: " + strCurrency + " " + f2s(orderList[i].preis) + "; \n";
  751.     s += "\n";
  752.  }
  753.  // s += "Total Preis: " + sum + " ;";   // DEBUG
  754.     s += "Versandkosten: " + f2s(sendprice) + strCurrency; //f2s(userData.fee)
  755.     s += "\n---------------------------";
  756.     s += "\">";
  757.  if (sendmethod!="1")
  758.  {
  759.    s+= "<input type=\"hidden\" name=\"Location\" value=\""
  760.    s+= serverloc;
  761.    if (serverloc.charAt (serverloc.length-1) != '/');
  762.     s+= "/";
  763.    s += "tcat11.htm\">"; 
  764.  }
  765.  s += "<INPUT TYPE=button VALUE=\"" + caption + "\"";
  766.  s += " onClick=\" disabled='true';" + slocation + "do_submit( self, '" + redirect + "','" + infotext + "')\">";
  767.  s += "</form></center>";
  768.  target.document.write(s);
  769. }
  770.  
  771. // define some defaults
  772. function define(image_or_str,variable,value)
  773. {
  774.  if(value.length <= 0)
  775.     return;
  776.  
  777.  if(image_or_str == "image") {
  778.     var s = "<IMG SRC=\"" + value + "\" BORDER=0 ALT=\"";
  779.     if(variable == "+")
  780.         image_incr = s + strCountIncr + "\">";
  781.     else if(variable == "-")
  782.         image_decr = s + strCountDecr + "\">";
  783.     else if(variable == "x")
  784.         image_delete = s + strCountDel + "\">";
  785.     else if(variable == "ok")
  786.         image_upd = s + strCountUpd + "\">";
  787.  } else if(image_or_str == "string") {
  788.     if(variable == "NO_ORDER")
  789.         strNoOrder = value;
  790.     else if(variable == "MAX_ORDER")
  791.         strMaxOrder = value;
  792.     else if(variable == "MAX_ITEM")
  793.         strMaxItem = value;
  794.     else if(variable == "ORDER_NUM")
  795.         strOrderNum = value;
  796.     else if(variable == "ORDER_OPTIONAL")
  797.         strOrderOptional = value;
  798.     else if(variable == "SEARCH_NORESULT")
  799.         strSearchNoResult = value;
  800.     else if(variable == "MAIL_SUBJECT")
  801.         strMailSubject = value;
  802.  } else if(image_or_str == "boolean") {
  803.     if(variable == "ORDER_VARIABLE")
  804.         addVariable = (parseInt(value) == 1 ? true : false);
  805.     else if(variable == "ORDER_DOUBLE")
  806.         addDouble = (parseInt(value) == 1 ? true : false);
  807.  } else if(image_or_str == "payment") {
  808.     if(definePayments == false) {
  809.         // init payments, if first call
  810.         payment &= 0;
  811.         definePayments = true;
  812.     }
  813.     if(variable == "NACHNAHME") {
  814.         feeNACHNAHME = parseFloat(comma2dot(value));
  815.         payment |= NACHNAHME;
  816.     } else if(variable == "RECHNUNG") {
  817.         feeRECHNUNG = parseFloat(comma2dot(value));
  818.         payment |= RECHNUNG;
  819.     } else if(variable == "BANK") {
  820.         feeBANKEINZUG = parseFloat(comma2dot(value));
  821.         payment |= BANKEINZUG;
  822.     } else if(variable == "KREDIT") {
  823.         feeKREDITKARTE = parseFloat(comma2dot(value));
  824.         payment |= KREDITKARTE;
  825.     }
  826.  }
  827. }
  828.  
  829. // *****************************************************
  830. // ****************** search engine ********************
  831. // *****************************************************
  832.  
  833. var pdname;
  834. var pdnum;
  835. var pdprice;
  836.  
  837. // print one hitlist line (mode dependent)
  838. function printHitLine(target,pdname,pdnum,pdprice,pdref,mode)
  839. {
  840.  var s;
  841.  
  842.  if(mode == 0) {
  843.     s = "<TABLE BORDER=1>";
  844.     s += "<TH ALIGN=LEFT>" + strProduct + "</TH>";
  845.     s += "<TH ALIGN=LEFT>" + strId + "</TH>";
  846.     s += "<TH ALIGN=RIGHT>" + strPrice + "</TH>";
  847.  } else if(mode == 1) {
  848.     s = "<TR>";
  849.     s += "<TD ALIGN=LEFT>";
  850.     if(pdref.length > 0) {
  851.         s += "<A HREF=\"" + pdref + "\">" + pdname + "</A>";
  852.     } else {
  853.         s += pdname;
  854.     }
  855.     s += "</TD>";
  856.     s += "<TD ALIGN=CENTER>" + pdnum + "</TD>";
  857.     s += "<TD ALIGN=RIGHT>" + f2s(pdprice) + " " + strCurrency + "</TD>";
  858.     s += "</TR>";
  859.  } else if(mode == 2) {
  860.     s = "</TABLE>";
  861.  } else {
  862.     s = strSearchNoResult;
  863.  }
  864.  target.document.write(s);
  865. }
  866.  
  867. // bisearch
  868. function bisearch(db,dblen,word)
  869. {
  870.  var l = 0;
  871.  var r = dblen - 1;
  872.  var i;
  873.  
  874.  while(r >= l) {
  875.     i = parseInt((l + r) / 2);
  876.     //alert(i + ":" + l + ":" + r);
  877.     //alert(db[i].toUpperCase().substring(0,word.length));
  878.     if(word < db[i].toUpperCase().substring(0,word.length))
  879.         r = i - 1;
  880.     else if(word > db[i].toUpperCase().substring(0,word.length))
  881.         l = i + 1;
  882.     else {          // word == db[i].substring(0,word.length)
  883.         i--;
  884.         while((i >= 0) && (word == db[i].toUpperCase().substring(0,word.length)))
  885.             i--;
  886.         i++;
  887.         return(i);
  888.     }
  889.  }
  890.  
  891.  return(-1);
  892. }
  893.  
  894. // search for products
  895. function search(name,num,price)
  896. {
  897.  pdname = name.toUpperCase();
  898.  pdnum = num.toUpperCase();
  899.  pdprice = comma2dot(price);
  900.  
  901.  //alert(pdname + ":" + pdnum + ":" + pdprice);
  902. }
  903.  
  904. // search for products
  905. function printHitList(target,dbname,dbname_i,
  906.                      dbnum,dbnum_i,
  907.                      dbprice,dbprice_i,
  908.                  dbref)
  909. {
  910.  var i;
  911.  var num = 0;
  912.  var searchmode;
  913.  var printmode = 0;
  914.  var price = parseFloat(pdprice) + 0;
  915.  var dbMax = dbname.length;
  916.  
  917.  // check for valid args
  918.  if((pdname.length == 0) &&
  919.     (pdnum.length == 0) &&
  920.     (pdprice.length == 0)) {
  921.     // print all products
  922.     for(i = 0;i < dbMax;i++) {
  923.         // table header
  924.         if(printmode == 0)
  925.             printHitLine(target,"","","","",printmode++);
  926.         // table row
  927.         printHitLine(target,dbname[i],
  928.                 dbnum[dbname_i[i]],
  929.                 dbprice[dbnum_i[dbname_i[i]]],
  930.                 dbref[i],printmode);
  931.         num++;
  932.     }
  933.     printHitLine(target,"","","","",++printmode);
  934.     return(num);
  935.  }
  936.  
  937.  // check for algorithm
  938.  if((pdname.length >= 3 && pdnum.length <= 2) ||
  939.     (pdname.length > 0 && pdnum.length == 0))
  940.     searchmode = 1;     // search for pdname
  941.  else if(pdnum.length > 0)
  942.     searchmode = 2;     // search for pdnum
  943.  else
  944.     searchmode = 3;     // search for price
  945.  
  946.  // search
  947.  if((searchmode == 1) &&    // **** search for pdname ***
  948.     ((i = bisearch(dbname,dbMax,pdname)) >= 0)) {
  949.     //alert("Search for Name:" + dbname[i]);
  950.     while((i < dbMax) &&
  951.           (dbname[i].toUpperCase().substring(0,pdname.length) == pdname)) {
  952.             if(((pdnum.length == 0) ||
  953.                 (dbnum[dbname_i[i]].toUpperCase().substring(0,pdnum.length) == pdnum)) &&
  954.                 ((pdprice.length == 0) || (dbprice[dbnum_i[dbname_i[i]]] <= price))) {
  955.             // table header
  956.             if(printmode == 0)
  957.                 printHitLine(target,"","","","",printmode++);
  958.             // table row
  959.             printHitLine(target,dbname[i],
  960.                     dbnum[dbname_i[i]],
  961.                     dbprice[dbnum_i[dbname_i[i]]],
  962.                     dbref[i],printmode);
  963.             num++;
  964.         }
  965.         i++;
  966.     }
  967.  } else if((searchmode == 2) && // *** search for pdnum ***
  968.     ((i = bisearch(dbnum,dbMax,pdnum)) >= 0)) {
  969.     //alert("Search for Num:" + dbnum[i]);
  970.     while((i < dbMax) &&
  971.           (dbnum[i].toUpperCase().substring(0,pdnum.length) == pdnum)) {
  972.             if(((pdname.length == 0) ||
  973.                 (dbname[dbprice_i[dbnum_i[i]]].toUpperCase().substring(0,pdname.length) == pdname)) &&
  974.                 ((pdprice.length == 0) || (dbprice[dbnum_i[i]] <= price))) {
  975.             // table header
  976.             if(printmode == 0)
  977.                 printHitLine(target,"","","","",printmode++);
  978.             // table row
  979.             printHitLine(target,dbname[dbprice_i[dbnum_i[i]]],
  980.                     dbnum[i],
  981.                     dbprice[dbnum_i[i]],
  982.                     dbref[dbprice_i[dbnum_i[i]]],printmode);
  983.             num++;
  984.         }
  985.         i++;
  986.     }
  987.  } else {           // *** search for price ***
  988.     i = 0;
  989.     while((dbprice[i] <= price) && (i < dbMax)) {
  990.         // table header
  991.         if(printmode == 0)
  992.             printHitLine(target,"","","","",printmode++);
  993.         // table row
  994.         printHitLine(target,dbname[dbprice_i[i]],
  995.                 dbnum[dbname_i[dbprice_i[i]]],
  996.                 dbprice[i],
  997.                 dbref[dbprice_i[i]],printmode);
  998.         num++;
  999.         i++;
  1000.     }
  1001.  }
  1002.  
  1003.  if(num > 0) {
  1004.     // table trailer
  1005.     printHitLine(target,"","","","",++printmode);
  1006.  } else {
  1007.     // no result
  1008.     printHitLine(target,"","","","",-1);
  1009.  }
  1010.  
  1011.  return(num);
  1012. }
  1013.  
  1014. // *****************************************************
  1015. // the following codeline must be the last one !!!
  1016. // *****************************************************
  1017. isScriptLoaded = true;
  1018.