var FotoPreis = 0.50;
var BriefPorto = 2.20;
var FotoAussehen = "hochglanz";

  function pAuswahl()
  {
    var t = "";
    if (document.Bestellung.p00.checked) t = t + "p00";
    if (document.Bestellung.p01.checked) t = t + "p01";
    if (document.Bestellung.p02.checked) t = t + "p02";
    if (document.Bestellung.p03.checked) t = t + "p03";
    if (document.Bestellung.p04.checked) t = t + "p04";
    if (document.Bestellung.p05.checked) t = t + "p05";
    if (document.Bestellung.p06.checked) t = t + "p06";
    if (document.Bestellung.p07.checked) t = t + "p07";
    if (document.Bestellung.p08.checked) t = t + "p08";
    if (document.Bestellung.p09.checked) t = t + "p09";
    if (document.Bestellung.p10.checked) t = t + "p10";
    if (document.Bestellung.p11.checked) t = t + "p11";
    if (document.Bestellung.p12.checked) t = t + "p12";
    if (document.Bestellung.p13.checked) t = t + "p13";
    if (document.Bestellung.p14.checked) t = t + "p14";
    if (document.Bestellung.p15.checked) t = t + "p15";
    if (document.Bestellung.p16.checked) t = t + "p16";
    if (document.Bestellung.p17.checked) t = t + "p17";
    if (document.Bestellung.p18.checked) t = t + "p18";
    if (document.Bestellung.p19.checked) t = t + "p19";
    if (document.Bestellung.p20.checked) t = t + "p20";
    if (document.Bestellung.p21.checked) t = t + "p21";
    if (document.Bestellung.p22.checked) t = t + "p22";
    if (document.Bestellung.p23.checked) t = t + "p23";
    if (document.Bestellung.p24.checked) t = t + "p24";
    if (document.Bestellung.p25.checked) t = t + "p25";
    if (document.Bestellung.p26.checked) t = t + "p26";
    if (document.Bestellung.p27.checked) t = t + "p27";
    if (document.Bestellung.p28.checked) t = t + "p28";
    if (document.Bestellung.p29.checked) t = t + "p29";
    if (document.Bestellung.p30.checked) t = t + "p30";
    if (document.Bestellung.p31.checked) t = t + "p31";
    if (document.Bestellung.p32.checked) t = t + "p32";
    if (document.Bestellung.p34.checked) t = t + "p34";
    if (document.Bestellung.p35.checked) t = t + "p35";
    if (document.Bestellung.p36.checked) t = t + "p36";
    if (document.Bestellung.p37.checked) t = t + "p37";

    return t;
  }

  function qAuswahl()
  {
    var t = "";
    if (document.Bestellung.q02.checked) t = t + "q02";
    if (document.Bestellung.q03.checked) t = t + "q03";
    if (document.Bestellung.q04.checked) t = t + "q04";
    if (document.Bestellung.q05.checked) t = t + "q05";
    if (document.Bestellung.q06.checked) t = t + "q06";
    if (document.Bestellung.q07.checked) t = t + "q07";
    if (document.Bestellung.q08.checked) t = t + "q08";
    if (document.Bestellung.q09.checked) t = t + "q09";
    if (document.Bestellung.q10.checked) t = t + "q10";
    if (document.Bestellung.q11.checked) t = t + "q11";
    if (document.Bestellung.q12.checked) t = t + "q12";
    if (document.Bestellung.q13.checked) t = t + "q13";
    if (document.Bestellung.q14.checked) t = t + "q14";
    if (document.Bestellung.q15.checked) t = t + "q15";
    if (document.Bestellung.q16.checked) t = t + "q16";
    if (document.Bestellung.q17.checked) t = t + "q17";
    if (document.Bestellung.q18.checked) t = t + "q18";
    if (document.Bestellung.q19.checked) t = t + "q19";
    if (document.Bestellung.q20.checked) t = t + "q20";
    if (document.Bestellung.q21.checked) t = t + "q21";
    if (document.Bestellung.q22.checked) t = t + "q22";
    if (document.Bestellung.q23.checked) t = t + "q23";
    if (document.Bestellung.q24.checked) t = t + "q24";
    if (document.Bestellung.q25.checked) t = t + "q25";
    if (document.Bestellung.q26.checked) t = t + "q26";
    if (document.Bestellung.q27.checked) t = t + "q27";
    if (document.Bestellung.q28.checked) t = t + "q28";
    if (document.Bestellung.q29.checked) t = t + "q29";
    if (document.Bestellung.q30.checked) t = t + "q30";
    if (document.Bestellung.q31.checked) t = t + "q31";
    if (document.Bestellung.q32.checked) t = t + "q32";
    if (document.Bestellung.q33.checked) t = t + "q33";
    if (document.Bestellung.q34.checked) t = t + "q34";
    if (document.Bestellung.q35.checked) t = t + "q35";
    if (document.Bestellung.q36.checked) t = t + "q36";
    if (document.Bestellung.q37.checked) t = t + "q37";

    return t;
  }

  function rAuswahl()
  {
    var t = "";
    if (document.Bestellung.r00.checked) t = t + "r00";
    if (document.Bestellung.r01.checked) t = t + "r01";
    if (document.Bestellung.r02.checked) t = t + "r02";
    if (document.Bestellung.r03.checked) t = t + "r03";
    if (document.Bestellung.r04.checked) t = t + "r04";
    if (document.Bestellung.r05.checked) t = t + "r05";
    if (document.Bestellung.r06.checked) t = t + "r06";
    if (document.Bestellung.r07.checked) t = t + "r07";
    if (document.Bestellung.r08.checked) t = t + "r08";
    if (document.Bestellung.r09.checked) t = t + "r09";
    if (document.Bestellung.r10.checked) t = t + "r10";
    if (document.Bestellung.r11.checked) t = t + "r11";
    if (document.Bestellung.r12.checked) t = t + "r12";
    if (document.Bestellung.r13.checked) t = t + "r13";
    if (document.Bestellung.r15.checked) t = t + "r15";
    if (document.Bestellung.r16.checked) t = t + "r16";
    if (document.Bestellung.r17.checked) t = t + "r17";
    if (document.Bestellung.r18.checked) t = t + "r18";
    if (document.Bestellung.r19.checked) t = t + "r19";
    if (document.Bestellung.r21.checked) t = t + "r21";
    if (document.Bestellung.r22.checked) t = t + "r22";
    if (document.Bestellung.r23.checked) t = t + "r23";
    if (document.Bestellung.r24.checked) t = t + "r24";
    if (document.Bestellung.r25.checked) t = t + "r25";
    if (document.Bestellung.r26.checked) t = t + "r26";
    if (document.Bestellung.r27.checked) t = t + "r27";
    if (document.Bestellung.r29.checked) t = t + "r29";

    return t;
  }

  function DatenSpeichern()
  {
    var jetzt = new Date();
    var Auszeit = new Date(jetzt.getTime() + 1000*60*60*24*365);
    var t="photos="
    t=t+pAuswahl()+qAuswahl()+rAuswahl();

    t = t + "#v|" + document.Bestellung.vname.value;
    t = t + "#n|" + document.Bestellung.nname.value;
    t = t + "#s|" + document.Bestellung.strasse_nr.value;
    t = t + "#o|" + document.Bestellung.plz_ort.value;
    t = t + "##|";

    t = t + "; expires="+Auszeit.toGMTString();
    document.cookie = t;
  }

  function DatenLaden()
  {
    var t = document.cookie;
    //p
    document.Bestellung.p00.checked = (t.indexOf("p00") != -1);
    document.Bestellung.p01.checked = (t.indexOf("p01") != -1);
    document.Bestellung.p02.checked = (t.indexOf("p02") != -1);
    document.Bestellung.p03.checked = (t.indexOf("p03") != -1);
    document.Bestellung.p04.checked = (t.indexOf("p04") != -1);
    document.Bestellung.p05.checked = (t.indexOf("p05") != -1);
    document.Bestellung.p06.checked = (t.indexOf("p06") != -1);
    document.Bestellung.p07.checked = (t.indexOf("p07") != -1);
    document.Bestellung.p08.checked = (t.indexOf("p08") != -1);
    document.Bestellung.p09.checked = (t.indexOf("p09") != -1);
    document.Bestellung.p10.checked = (t.indexOf("p10") != -1);
    document.Bestellung.p11.checked = (t.indexOf("p11") != -1);
    document.Bestellung.p12.checked = (t.indexOf("p12") != -1);
    document.Bestellung.p13.checked = (t.indexOf("p13") != -1);
    document.Bestellung.p14.checked = (t.indexOf("p14") != -1);
    document.Bestellung.p15.checked = (t.indexOf("p15") != -1);
    document.Bestellung.p16.checked = (t.indexOf("p16") != -1);
    document.Bestellung.p17.checked = (t.indexOf("p17") != -1);
    document.Bestellung.p18.checked = (t.indexOf("p18") != -1);
    document.Bestellung.p19.checked = (t.indexOf("p19") != -1);
    document.Bestellung.p20.checked = (t.indexOf("p20") != -1);
    document.Bestellung.p21.checked = (t.indexOf("p21") != -1);
    document.Bestellung.p22.checked = (t.indexOf("p22") != -1);
    document.Bestellung.p23.checked = (t.indexOf("p23") != -1);
    document.Bestellung.p24.checked = (t.indexOf("p24") != -1);
    document.Bestellung.p25.checked = (t.indexOf("p25") != -1);
    document.Bestellung.p26.checked = (t.indexOf("p26") != -1);
    document.Bestellung.p27.checked = (t.indexOf("p27") != -1);
    document.Bestellung.p28.checked = (t.indexOf("p28") != -1);
    document.Bestellung.p29.checked = (t.indexOf("p29") != -1);
    document.Bestellung.p30.checked = (t.indexOf("p30") != -1);
    document.Bestellung.p31.checked = (t.indexOf("p31") != -1);
    document.Bestellung.p32.checked = (t.indexOf("p32") != -1);
    document.Bestellung.p34.checked = (t.indexOf("p34") != -1);
    document.Bestellung.p35.checked = (t.indexOf("p35") != -1);
    document.Bestellung.p36.checked = (t.indexOf("p36") != -1);
    document.Bestellung.p37.checked = (t.indexOf("p37") != -1);
    //q
    document.Bestellung.q02.checked = (t.indexOf("q02") != -1);
    document.Bestellung.q03.checked = (t.indexOf("q03") != -1);
    document.Bestellung.q04.checked = (t.indexOf("q04") != -1);
    document.Bestellung.q05.checked = (t.indexOf("q05") != -1);
    document.Bestellung.q06.checked = (t.indexOf("q06") != -1);
    document.Bestellung.q07.checked = (t.indexOf("q07") != -1);
    document.Bestellung.q08.checked = (t.indexOf("q08") != -1);
    document.Bestellung.q09.checked = (t.indexOf("q09") != -1);
    document.Bestellung.q10.checked = (t.indexOf("q10") != -1);
    document.Bestellung.q11.checked = (t.indexOf("q11") != -1);
    document.Bestellung.q12.checked = (t.indexOf("q12") != -1);
    document.Bestellung.q13.checked = (t.indexOf("q13") != -1);
    document.Bestellung.q14.checked = (t.indexOf("q14") != -1);
    document.Bestellung.q15.checked = (t.indexOf("q15") != -1);
    document.Bestellung.q16.checked = (t.indexOf("q16") != -1);
    document.Bestellung.q17.checked = (t.indexOf("q17") != -1);
    document.Bestellung.q18.checked = (t.indexOf("q18") != -1);
    document.Bestellung.q19.checked = (t.indexOf("q19") != -1);
    document.Bestellung.q20.checked = (t.indexOf("q20") != -1);
    document.Bestellung.q21.checked = (t.indexOf("q21") != -1);
    document.Bestellung.q22.checked = (t.indexOf("q22") != -1);
    document.Bestellung.q23.checked = (t.indexOf("q23") != -1);
    document.Bestellung.q24.checked = (t.indexOf("q24") != -1);
    document.Bestellung.q25.checked = (t.indexOf("q25") != -1);
    document.Bestellung.q26.checked = (t.indexOf("q26") != -1);
    document.Bestellung.q27.checked = (t.indexOf("q27") != -1);
    document.Bestellung.q28.checked = (t.indexOf("q28") != -1);
    document.Bestellung.q29.checked = (t.indexOf("q29") != -1);
    document.Bestellung.q30.checked = (t.indexOf("q30") != -1);
    document.Bestellung.q31.checked = (t.indexOf("q31") != -1);
    document.Bestellung.q32.checked = (t.indexOf("q32") != -1);
    document.Bestellung.q33.checked = (t.indexOf("q33") != -1);
    document.Bestellung.q34.checked = (t.indexOf("q34") != -1);
    document.Bestellung.q35.checked = (t.indexOf("q35") != -1);
    document.Bestellung.q36.checked = (t.indexOf("q36") != -1);
    document.Bestellung.q37.checked = (t.indexOf("q37") != -1);
    //r
    document.Bestellung.r00.checked = (t.indexOf("r00") != -1);
    document.Bestellung.r01.checked = (t.indexOf("r01") != -1);
    document.Bestellung.r02.checked = (t.indexOf("r02") != -1);
    document.Bestellung.r03.checked = (t.indexOf("r03") != -1);
    document.Bestellung.r04.checked = (t.indexOf("r04") != -1);
    document.Bestellung.r05.checked = (t.indexOf("r05") != -1);
    document.Bestellung.r06.checked = (t.indexOf("r06") != -1);
    document.Bestellung.r07.checked = (t.indexOf("r07") != -1);
    document.Bestellung.r08.checked = (t.indexOf("r08") != -1);
    document.Bestellung.r09.checked = (t.indexOf("r09") != -1);
    document.Bestellung.r10.checked = (t.indexOf("r10") != -1);
    document.Bestellung.r11.checked = (t.indexOf("r11") != -1);
    document.Bestellung.r12.checked = (t.indexOf("r12") != -1);
    document.Bestellung.r13.checked = (t.indexOf("r13") != -1);
    document.Bestellung.r15.checked = (t.indexOf("r15") != -1);
    document.Bestellung.r16.checked = (t.indexOf("r16") != -1);
    document.Bestellung.r17.checked = (t.indexOf("r17") != -1);
    document.Bestellung.r18.checked = (t.indexOf("r18") != -1);
    document.Bestellung.r19.checked = (t.indexOf("r19") != -1);
    document.Bestellung.r21.checked = (t.indexOf("r21") != -1);
    document.Bestellung.r22.checked = (t.indexOf("r22") != -1);
    document.Bestellung.r23.checked = (t.indexOf("r23") != -1);
    document.Bestellung.r24.checked = (t.indexOf("r24") != -1);
    document.Bestellung.r25.checked = (t.indexOf("r25") != -1);
    document.Bestellung.r26.checked = (t.indexOf("r26") != -1);
    document.Bestellung.r27.checked = (t.indexOf("r27") != -1);
    document.Bestellung.r29.checked = (t.indexOf("r29") != -1);

    var i1,i2 = 0;
    //vname
    i1 = t.indexOf("#v|");
    i2 = t.indexOf("#n|");
    document.Bestellung.vname.value = t.substring(i1+3,i2);

    //nname
    i1 = t.indexOf("#n|");
    i2 = t.indexOf("#s|");
    document.Bestellung.nname.value = t.substring(i1+3,i2);

    //strasse_nr
    i1 = t.indexOf("#s|");
    i2 = t.indexOf("#o|");
    document.Bestellung.strasse_nr.value = t.substring(i1+3,i2);

    //plz_ort
    i1 = t.indexOf("#o|");
    i2 = t.indexOf("##|");
    document.Bestellung.plz_ort.value = t.substring(i1+3,i2);
  }

  function Format(i)
  {
    if (i==9) FotoPreis = 0.40;
    if (i==10) FotoPreis = 0.50;
    Preis();
  }

  function DM(i)
  {
      var s = String(i);
      if (s.indexOf(".") != -1) s = s + "00";
      while (s.length-s.indexOf(".") > 3) s = s.substring(0,s.length-1);
      if (s.indexOf(".") == -1) s = s + ".00";
      s = s.substring(0,s.indexOf(".")) + "," + s.substring(s.indexOf(".")+1,s.length);
      return s + " DM";
  }

  function Preis()
  {
    with (document.Bestellung)
    {
      DatenSpeichern();
      var x = pAuswahl() + qAuswahl() + rAuswahl();
      var anz = x.length / 3;

      anzahl.value = anz + " Stück";
      BriefPorto = 4.00;
      porto.value = DM(BriefPorto);
      preis.value = DM(anz * FotoPreis);
      summe.value = DM(anz * FotoPreis + BriefPorto);
    }

  }

  function Aussehen(i)
  {
    FotoAussehen = (i == 1) ? "matt" : "hochglanz";
  }

  function Anfang()
  {
    DatenLaden();
    Preis();
  }

  function Ende()
  {
    DatenSpeichern();
  }

  function Laden()
  {
    DatenLaden();
    Preis();
  }

  function Speichern()
  {
    DatenSpeichern();
    alert("Daten gespeichert");
  }

  function Drucken()
  {
    var x = pAuswahl() + qAuswahl() + rAuswahl();
    with (document.Bestellung)
    {
      var vn = vname.value;
      if (vn == "") {alert("Kein Vorname eingegeben!"); vname.focus(); return }
      var nn = nname.value;
      if (nn == "") {alert("Kein Nachname eingegeben!"); nname.focus(); return }
      var str = strasse_nr.value;
      if (str == "") {alert("Keine Straße eingegeben!"); strasse_nr.focus(); return }
      var ort = plz_ort.value;
      if (ort == "") {alert("Kein Ort eingegeben!"); plz_ort.focus(); return }
      var anz = anzahl.value;
      var pr = preis.value;
      var sum = summe.value;
      var fp = FotoPreis;
      var fa = FotoAussehen;
      var bp = BriefPorto;
    }
    document.close();
    document.open("text/html");
    with (document)
    {
      writeln("<HTML><HEAD><TITLE>Bestellung</TITLE></HEAD><BODY><FONT FACE=\"Verdana, Arial, Helvetica, sans-serif\">");
      writeln("<H2>[=][::][||] [arnep photo] Bestellung</H2></FONT>");
      writeln("<TT><I>Senden an:</I><BR>Arne Pottharst<BR>");
      writeln("Im Sandacker 10<BR>");
      writeln("64342 Seeheim-Jugenheim<BR>");
      writeln("<BR><BR>");
      writeln("<I>Besteller:</I><BR>"+vn+" "+nn+"<BR>");
      writeln(str+"<BR>");
      writeln(ort+"<BR>");
      writeln("<BR><BR>");
      write("<I>Format:</I><BR>");
      write((fp == 0.4) ? "9x13" : "10x15");
      writeln("<BR>"+fa+"<BR><BR>");

      writeln("<B>Film arnep/38:</B>");
      var n = 0;
      var l = 0;
      for (var i=0; i<40; i++)
      {
         if (n % 7 == 0 && l==0) { writeln("<BR>"); l = 1; }
         if (x.indexOf("p" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i))) != -1)
         {
           writeln("&nbsp;&nbsp;X&nbsp;1038" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i)));
           n++;
           l = 0;
         }
      }
      writeln("<BR>(" + String(n) + " Stück)");

      writeln("<BR><B>Film arnep/39:</B>");
      n = 0;
      l = 0;
      for (var i=0; i<40; i++)
      {
         if (n % 7 == 0 && l==0) { writeln("<BR>"); l = 1; }
         if (x.indexOf("q" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i))) != -1)
         {
           writeln("&nbsp;&nbsp;X&nbsp;1039" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i)));
           n++;
         }
      }
      writeln("<BR>(" + String(n) + " Stück)");

      writeln("<BR><B>Film arnep/40:</B>");
      n = 0;
      l = 0;
      for (var i=0; i<40; i++)
      {
         if (n % 7 == 0 && l==0) { writeln("<BR>"); l = 1; }
         if (x.indexOf("r" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i))) != -1)
         {
           writeln("&nbsp;&nbsp;X&nbsp;1040" + ((String(i).length == 1) ? "0" + String(i) : "" + String(i)));
           n++;
           l = 0;
         }
      }
      writeln("<BR>(" + String(n) + " Stück)<BR><BR>");

      writeln("&nbsp;Anzahl: " + anz + "<BR>");
        var s = String(fp);
        if (s.indexOf(".") != -1) s = s + "00";
        while (s.length-s.indexOf(".") > 3) s = s.substring(0,s.length-1);
        if (s.indexOf(".") == -1) s = s + ".00";
        s = s.substring(0,s.indexOf(".")) + "," + s.substring(s.indexOf(".")+1,s.length);
        s = s + " DM";
      writeln("x&nbsp;Preis: " + s + "<BR>");
      writeln("<U>=&nbsp;Summe: " + pr + "</U><BR>");
        s = String(bp);
        if (s.indexOf(".") != -1) s = s + "00";
        while (s.length-s.indexOf(".") > 3) s = s.substring(0,s.length-1);
        if (s.indexOf(".") == -1) s = s + ".00";
        s = s.substring(0,s.indexOf(".")) + "," + s.substring(s.indexOf(".")+1,s.length);
        s = s + " DM";
      writeln("+ Porto: " + s + "</U><BR>");
      writeln("<B><U>=&nbsp;Summe: " + sum + "</U></B><BR>");

      writeln("<H2>Bezahlung:</H2></TT>");
      writeln("<TABLE BORDER=0><TR><TD><TT>(&nbsp;)</TT></TD><TD><TT>Ich bezahle die " + sum + " in bar, das Geld liegt in Scheinen bzw. Briefmarken bei (<I>keine</I> Münzen).</TT></TD></TR>");
      writeln("<TR><TD><TT>(&nbsp;)</TT> </TD><TD><TT>Ich bezahle per Überweisung auf das folgende Konto:  Überweisung: Sparkasse Darmstadt, BLZ 508 501 50, Konto-Nr. 125 026 923, Verwendungszweck: KSJ-2000-Fotobestellung, Name nicht vergessen! </TT></TD></TR></TABLE>");
      writeln("<TT>Lieferzeit ca. 1-2 Wochen<BR><BR><BR>Hiermit erkläre ich, daß alle vorstehenden Angaben richtig sind.<BR><BR><BR><BR>");
      writeln("&nbsp; &nbsp; &nbsp; _________________________________<BR>");
      writeln("&nbsp; &nbsp; &nbsp; Ort, Datum, Unterschrift");
      writeln("</TT></BODY></HTML>");
    }
    document.close();
    alert("H I N W E I S:\n\nAus dem Menu \"Datei\" den Befehl \"Drucken\"\nwählen um die Bestellung auszudrucken!");

  }

