// usage: format_zahl( number [, number]  [, bool]  )
function format_currency(num) {
   return num.toFixed(2).replace(".", ",");
}

function changeContent(id, content) {
   document.getElementById(id).firstChild.nodeValue = content;
}

function changeValue(id, value) {
   document.getElementById(id).value = value;
}

function getValue(id) {
   return document.getElementById(id).value;
}

function getContent(id) {
   return document.getElementById(id).firstChild.nodeValue;
}

function changeBgColor(id, newColor) {
   document.getElementById(id).style.backgroundColor = newColor;
}

function changeBgImage(id,image) {
   if(document.getElementById(id)) {
      document.getElementById(id).style.backgroundImage = "url('"+image+"')";
   }
}

function changeBorderColor(id, newColor) {
   document.getElementById(id).style.borderColor = newColor;
}

function changeUri(uri) {
   window.location.href = uri;
}



function toggleDisplay(id) {
   var display = document.getElementById(id).style.display;
   if(display == 'none' || display == '') {
      document.getElementById(id).style.display = 'block';
   }
   if(display == 'block') {
      document.getElementById(id).style.display = 'none';
   }
}


function toggleButton(id) {

   src = document.getElementById(id).src;

   basename = src.substring(0,src.lastIndexOf('_'));
   appendix = src.substring(src.lastIndexOf('_'), src.lastIndexOf('.'));
   extension = src.substring(src.lastIndexOf('.'));

   //   alert(appendix);

   if(appendix == '_closed') {
      document.getElementById(id).src = basename + '_open' + extension;
   }

   if(appendix == '_open') {
      document.getElementById(id).src = basename + '_closed' + extension;
   }

}


function highlightButton(id, event) {
   src = document.getElementById(id).src;
   basename = src.substring(0,src.lastIndexOf('_'));
   appendix = src.substring(src.lastIndexOf('_'), src.lastIndexOf('.'));
   extension = src.substring(src.lastIndexOf('.'));

   if(event == 'over') {
      document.getElementById(id).src = basename + '_hi' + extension;
   }

   if(event == 'out') {
      document.getElementById(id).src = basename + '_norm' + extension;
   }
}



function calculateAge(year1, month1, day1, year2, month2, day2) {
   var age = null;

   //   alert( year1+'-'+month1+'-'+day1 + ' ' + year2+'-'+month2+'-'+day2 );

   // Wenn eine Angabe fehlt wird "" zurückgegeben
   if (year1 != 0 && month1 != 0 && day1 != 0 && year2 != 0 && month2 != 0 && day2 != 0) {
      //   return "";

      var date1 = new Date(year1, month1 - 1, day1);
      var date2 = new Date(year2, month2, day2);

      age = date2.getFullYear() - date1.getFullYear();

      // Wenn der Monat noch nicht erreicht ist => 1 Jahr abziehen
      if (date2.getMonth() < date1.getMonth()) {
         age = age - 1;
      } else    {
         // Richtiger Monat aber der Tag ist noch nicht erreicht
         // => 1 Jahr abziehen
         if (date2.getMonth() == date1.getMonth() &&
         date2.getDate() < date1.getDate())
         age = age - 1;
      }

   }

   // Alter zurückgeben
   return age;

}
