﻿function BlackAndWhite() {
    if (endsWith(document.body.className, ' bw')) {
      document.body.className = document.body.className.replace(' bw', '');
      document.body.style.backgroundColor = '#FFFFFF';
      document.getElementById('backgroundContainer').className = 'bwborderWhite';
    }
    else {
      document.body.className += ' bw';
      document.body.style.backgroundColor = '';
      document.getElementById('backgroundContainer').className = 'bwborderBlack';
    }
    var e = document.getElementsByTagName('div');
    for (var i = 0; i < e.length; i++) {
        if (e[i].className.indexOf('MainContent') != -1) {
            if (endsWith(e[i].className, ' bwtext')) {
              e[i].className = e[i].className.replace(' bwtext', '');
            }
            else { e[i].className += " bwtext"; }
        }
        if (e[i].className.indexOf('NewsIcons') != -1) {
          if (endsWith(e[i].className, ' bwtext')) {
            e[i].className = e[i].className.replace(' bwtext', '');
            e[i].innerHTML = '<a onclick="BlackAndWhite();" href="#"><img id="colorChangerImage" style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid; border-right: 0px solid;" alt="" src="/images/theme/2011/03/09/weissschwarzicon.jpg"/> Text: Weiss/White</a>';
          }
          else {
            e[i].className += " bwtext";
            e[i].innerHTML = '<a onclick="BlackAndWhite();" href="#"><img id="colorChangerImage" style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid; border-right: 0px solid;" alt="" src="/images/theme/2011/03/09/schwarzweissicon.jpg"/> Text: Schwarz/Black</a>';
           }
        }
    }
}

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
  }

