
function feDemark(obj) {
   obj.style.borderColor = '#666666';
   obj.style.backgroundColor = '#FFFFFF';
}

function feRadioValue(domName) {
   var value = null;
   var arr = document.getElementsByName(domName);
   for (i=0;i<arr.length;i++) {
      //      alert(arr[i].value);
      if(arr[i].checked) {
         value = arr[i].value;
      }
   }
   return value;
}


function formSubmit() {
   document.getElementById('anmeldung').style.display = 'none';
   document.getElementById('submitInfo').style.display = 'block';
}



function addTln() {
   document.getElementById('anmeldung_process').value = 'addtln';
   document.getElementById('anmeldung').submit();
}


function delTln(itemnum) {
   document.getElementById('anmeldung_process').value = 'deltln';
   document.getElementById('itemnum').value = itemnum;
   document.getElementById('anmeldung').submit();
}


/**
* fügt einen neuen Textblock in eine TextblockList
*
* @uses prototype.js
*/
function addTextblock(id) {
   var count = parseInt($F(id + "_count"));
   var newId = id + "_" + count;

   html  = '<div id="'+newId+'" class="textblock">';
   html += '<input id="'+newId+'_headline" ';
   html += 'name="'+newId+'_headline" ';
   html += 'value="" ';
   html += 'title="" ';
   html += 'type="text" class="textbox" />';
   html += '<a href="#" ';
   html += "onclick=\"delTextblock('"+newId+"');return false;\" ";
   html += "onmouseover=\"delmarkTextblock('"+newId+"','over');return false;\" ";
   html += "onmouseout=\"delmarkTextblock('"+newId+"','out');return false;\"> ";
   html += '<img src="_images/icn_delete.gif" alt="X" border="0" /></a><br />';
   html += '<textarea id="'+newId+'_text" name="'+newId+'_text" rows="10" style="height:80px;" ></textarea>';
   html += '<br /></div>';

   var insert = new Insertion.Bottom($(id), html);
   var newcount = count + 1;
   $(id + "_count").value = newcount;

   return false;

}


/**
* löscht einen Textblock aus einer TextblockList
*
* @uses prototype.js
* @todo Nachnummerierung der vorhandenen Blocks
*/
function delTextblock(id) {
   blockid = id.substring(0,id.lastIndexOf('_'));
   num = id.substring(id.lastIndexOf('_')+1, id.length);

   $(blockid + "_count").value = parseInt($F(blockid + "_count")) - 1;
   Element.remove($(id));
}


/**
* markiert einen Textblock
*
*/
function delmarkTextblock(eid, event) {
   if(event == 'over') {
      document.getElementById(eid).style.backgroundColor = '#FF8484';
   }
   if(event == 'out') {
      document.getElementById(eid).style.backgroundColor = '#FFFFFF';
   }
}



function anmeldung_paketFamilie() {
   if(document.getElementById('turnhalle').checked == true) {
      changeContent('tlnbetrag', '27,50 &euro; *');
      changeValue('betrag','27.50');
      for(var i=1; i<=tln_anzahl; i++) {
         document.getElementById('tln'+i+'_turnhalle').checked = true;
         document.getElementById('tln'+i+'_turnhalle').readonly = true;
      }
   } else {
      changeContent('tlnbetrag', '20,00 € *');
      changeValue('betrag',20);
   }
}


function anmeldung_paketGruppe() {
   var turnhalle = document.getElementById('turnhalle').checked;
   for(var i=1; i<=tln_anzahl; i++) {
      if(turnhalle) {
         document.getElementById('tln'+i+'_turnhalle').checked = true;
         document.getElementById('tln'+i+'_turnhalle').readonly = true;
      } else {
         document.getElementById('tln'+i+'_turnhalle').checked = false;
         document.getElementById('tln'+i+'_turnhalle').readonly = false;
      }
   }
}


function anmeldung_verantwortlicher() {
   //alert();
   // alert( radiobutton_getvalue('teilnahme_verantwortlicher') );
   toggleDisplay('listeVerantwortlicher');
   if( feRadioValue('teilnahme_verantwortlicher') == 1 ) {
      tln_verantwortlicher = 1;
   } else {
      tln_verantwortlicher = 0;
   }

   anmeldung_jugendPaketGruppe();

}

function anmeldung_jugendPaket() {
   var preis = 0;

   if(document.getElementById('turnhalle').checked == true) {
      // ////////////////////////////////////////////////////
      preis = preis_woe + preis_turnhalle;
      // ////////////////////////////////////////////////////
   } else {
      // ////////////////////////////////////////////////////
      preis = preis_woe;
      // ////////////////////////////////////////////////////
   }

   changeContent('tlnbetrag', format_currency(preis) + ' € *');
   changeValue('betrag', preis);

}



function anmeldung_jugendPaketGruppe() {
   var preis = 0;
   var summe = 0;

   if(document.getElementById('turnhalle').checked == true) {
      // ////////////////////////////////////////////////////
      preis = preis_woe + preis_turnhalle;
      summe = (tln_anzahl + tln_verantwortlicher) * preis;
      // ////////////////////////////////////////////////////
   } else {
      // ////////////////////////////////////////////////////
      preis = preis_woe;
      summe = (tln_anzahl + tln_verantwortlicher) * preis;
      // ////////////////////////////////////////////////////
   }

   changeContent('tlnbetrag', (tln_anzahl + tln_verantwortlicher) + ' x '+ format_currency(preis) +' € *');
   changeContent('tlnsumme', format_currency(summe) + ' € *');
   changeValue('betrag') = summe;

}


function anmeldung_berechneSummeFamilie() {
   var elem1;
   var elem2;
   var anzahlErw = 0;
   var anzahlKinder = 0;
   var anzahlKinderFrei = 0;
   var anzahlPakete = 0;
   var anzahlPaketeFrei = 0;
   var summe = 0;
   var turnhalle = document.getElementById('turnhalle').checked == true;


   elem1 = document.getElementById('vorname');
   elem2 = document.getElementById('nachname');

   if(elem1.value != '' && elem2.value != '') {
      anzahlErw++;
      if(turnhalle) {
         anzahlPakete++;
      }
   }

   elem1 = document.getElementById('elt1_vorname');
   elem2 = document.getElementById('elt1_nachname');

   if(elem1.value != '' && elem2.value != '') {
      anzahlErw++;
      if(turnhalle) {
         anzahlPakete++;
      }
   }

   for(var i=1; i<=tln_anzahl; i++) {
      elem1 = document.getElementById('tln'+i+'_vorname');
      elem2 = document.getElementById('tln'+i+'_turnhalle');

      if(elem1.value != '') {

         var day = getValue('tln'+i+'_geburtsdatum_day');
         var month = getValue('tln'+i+'_geburtsdatum_month');
         var year = getValue('tln'+i+'_geburtsdatum_year');
         var alter = Number(calculateAge(year,month,day,2008,7,3));

         //         alert(alter);
         if(alter >= 12) {


            if(anzahlKinder < 4) {
               anzahlKinder++;
               if(elem2.checked) {
                  anzahlPakete++;
               }
            } else {
               anzahlKinderFrei++;
               if(elem2.checked) {
                  anzahlPaketeFrei++;
               }
            }

         } else {

            anzahlKinderFrei++;
            if(elem2.checked) {
               anzahlPaketeFrei++;
            }

         }
      }

   }


   summe = (anzahlErw * preis_woe) + (anzahlKinder * preis_woekind) + (anzahlPakete * preis_turnhalle);

   changeContent('tlnbetrag', anzahlErw + ' x '+ format_currency(preis_woe) +' &euro; *')
   changeContent('tlnbetragKinder', anzahlKinder + ' x '+ format_currency(preis_woekind) +' € *');
   changeContent('tlnbetragKinderFrei', anzahlKinderFrei + ' x frei');
   changeContent('tlnpakete', anzahlPakete + ' x '+ format_currency(preis_turnhalle) +' € *');
   changeContent('tlnpaketeFrei', anzahlPaketeFrei + ' x frei');
   changeContent('tlnsumme', format_currency(summe) + ' € *');
   changeValue('betrag', summe);

}



function anmeldung_berechneSummeGruppe() {
   var elem1;
   var elem2;
   var anzahlTln = 0;
   var anzahlPakete = 0;
   var summe = 0;
   var turnhalle = document.getElementById('turnhalle').checked == true;


   elem1 = document.getElementById('vorname');
   elem2 = document.getElementById('nachname');

   if(elem1.value != '' && elem2.value != '') {
      anzahl++;
      if(turnhalle) {
         anzahlPakete++;
      }
   }


   for(var i=1; i<=tln_anzahl; i++) {
      elem1 = document.getElementById('tln'+i+'_vorname');
      elem2 = document.getElementById('tln'+i+'_turnhalle');

      if(elem1.value != '') {
         var day = getValue('tln'+i+'_geburtsdatum_day');
         var month = getValue('tln'+i+'_geburtsdatum_month');
         var year = getValue('tln'+i+'_geburtsdatum_year');
         var alter = Number(calculateAge(year,month,day,2008,7,3));

         if(alter < 14) {

            //
            // :todo: alert('Zu jung!');
            //

         } else {

            anzahlTln++;
            if(elem2.checked) {
               anzahlPakete++;
            }

         }
      }
   }

   summe = (anzahlTln * preis_woe) + (anzahlKinder * preis_woekind) + (anzahlPakete * preis_turnhalle);

   changeContent('tlnbetrag', anzahlTln + ' x '+ format_currency(preis_woe) +' &euro; *')
   changeContent('tlnpakete', anzahlPakete + ' x '+ format_currency(preis_turnhalle) +' &euro; *');
   changeContent('tlnsumme', format_currency(summe) + ' &euro; *');
   changeValue('betrag', summe);

}
