function showPage(p_curPage) {
  curPage = p_curPage;
  framePaper.location.href = arr_pages[curPage];
}
function switchPage(p_dir) {
  //alert("Page: "+curPage);
  if (p_dir == "next") {
    if (curPage == countPages) {
      curPage = 1;
    } else {
      curPage++;
    }
  } else {
    if (curPage == 1) {
      curPage = countPages;
    } else {
      curPage--;
    }
  }
  //alert("PageNew: "+curPage);
  showPage(curPage);
}


function reloadWebsite(fieldName){
    var url = document.getElementById(fieldName).value;
    if(url != "-"){
        location.href = url;
    }
}

function bannerChange(id, type){
    var url = 'banner.php?id=' + id+'&type='+type;
    location.replace(url);
}

function changeBG(p_str_div, p_color, p_corner) {
    if(p_corner != "") {
        document.getElementById("naviCorner").style.backgroundImage = 'url("images/ws/navigation/'+p_corner+'")';
        document.getElementById(p_str_div).style.backgroundColor = p_color;
//    document.getElementById("naviCorner").src     = "images/ws/navigation/"+p_corner;
//    document.getElementById("naviCorner").style.position = "relative";
//    document.getElementById("naviCorner").style.left   = "-4px";
//    document.getElementById("naviCorner").style.top   = "-4px";
    }
    if(p_corner == "out") {
        document.getElementById("naviCorner").style.backgroundImage = 'url("images/ws/navigation/subNavEcke.gif")';
        document.getElementById(p_str_div).style.backgroundColor = '#DCDCE5';
//    document.getElementById("naviCorner").src = "images/ws/navigation/subNavEcke.gif";
//    document.getElementById("naviCorner").style.position = "relative";
//    document.getElementById("naviCorner").style.left   = "-4px";
//    document.getElementById("naviCorner").style.top   = "-4px";
    }
    if (p_corner == "" && p_str_div != "") {
        document.getElementById(p_str_div).style.backgroundColor = p_color;
    }
}

function changeNewsImage (p_str_picPath, p_str_picName, p_str_picDescr) {
    document.getElementById("newsPic").src       = p_str_picPath;
    document.getElementById("newsPic").title     = p_str_picName;
    document.getElementById("newsPicDescr").value   = p_str_picDescr;
}


function changeImage(p_str_div, p_str_newPic, p_corner) {
    document.getElementById(p_str_div).src = p_str_newPic;
}

function resizeBorder () {
    if (screen.width >= 1024) {
        document.getElementById("borderTopBox").style.width     = "912px";
        document.getElementById("borderTop").style.width       = "901px";

        document.getElementById("borderMiddle").style.width     = "910px";
        document.getElementById("borderMiddleSpace").style.width   = "910px";

        document.getElementById("borderBottomBox").style.width     = "912px";
        document.getElementById("borderBottom").style.width     = "896px";

        document.getElementById("bannerBox").style.display       = "block";

        document.getElementById("footerBox").style.width       = "890px";
    }
}

function openWindow (str_file, params) {
    if (params != "") {
        var win = window.open(str_file, 'Verlagshaus_Jaumann', params);
    } else {
        var win = window.open(str_file, 'Verlagshaus_Jaumann', 'width=735,height=550');
    }
    win.focus();
}

function resizeWin() {
    var imgWidth = document.Bild.width;
    var imgHeight = document.Bild.height;
    var boo_resize = false;
    if (imgWidth > 550) {
        boo_resize = true;
    }
    if (imgHeight > 340) {
        boo_resize = true;
    }
    if (boo_resize) {
        window.resizeTo(imgWidth+40,imgHeight+240);
    } else {
        window.resizeTo(635,500);
    }
}

function nextPic(p_str_title) {
    if (curPic < int_count) {
         curPic++;
     } else {
         curPic = 1;
    }
    document.getElementById('curPic').value = curPic;
    document.getElementById('title').value = p_str_title+' '+curPic;
    document.getElementById('Bild').src = arr_media[curPic][0];
    var resize = window.setInterval("updateWinDim()", 2000);
}
function prevPic(p_str_title) {
    if (curPic > 1) {
        curPic--;
    } else {
        curPic = int_count;
    }
    document.getElementById('curPic').value = curPic;
    document.getElementById('title').value = p_str_title+' '+curPic;
    document.getElementById('Bild').src = arr_media[curPic][0];
    var resize = window.setInterval("updateWinDim()", 2000);
}

function updateWinDim() {
    resizeWin();
    window.clearInterval(resize);
}
function setPayment(p_str_type) {
  if (p_str_type == "invoice") {
    document.getElementById('konto').disabled = "disabled";
    document.getElementById('konto').value    = "";
    document.getElementById('konto').alt      = "";
    document.getElementById('blz').disabled   = "disabled";
    document.getElementById('blz').value      = "";
    document.getElementById('blz').alt        = "";
    document.getElementById('bank').disabled  = "disabled";
    document.getElementById('bank').value     = "";
    document.getElementById('bank').alt       = "";
    document.getElementById('invoiceIntervall').checked = "checked";
  } else {
    document.getElementById('konto').disabled = "";
    document.getElementById('konto').alt      = "numeric";
    document.getElementById('blz').disabled   = "";
    document.getElementById('blz').alt        = "numeric|8";
    document.getElementById('bank').disabled  = "";
    document.getElementById('bank').alt       = "blank";
    document.getElementById('bankIntervall').checked = "checked";
  }
}
var keyStr = "ABCDEFGHIJKLMNOP" +
            "QRSTUVWXYZabcdef" +
            "ghijklmnopqrstuv" +
            "wxyz0123456789+/" +
            "=";

function encode(input) {
   var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;
      do {
        chr1 = input.charCodeAt(i++);
     chr2 = input.charCodeAt(i++);
     chr3 = input.charCodeAt(i++);

     enc1 = chr1 >> 2;
     enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
     enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
     enc4 = chr3 & 63;

     if (isNaN(chr2)) {
        enc3 = enc4 = 64;
     } else if (isNaN(chr3)) {
        enc4 = 64;
     }

     output = output +
        keyStr.charAt(enc1) +
        keyStr.charAt(enc2) +
        keyStr.charAt(enc3) +
        keyStr.charAt(enc4);
     chr1 = chr2 = chr3 = "";
     enc1 = enc2 = enc3 = enc4 = "";
   } while (i < input.length);
   return "?dat=" + output;
}

function decode(input) {
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  var base64test = /[^A-Za-z0-9\+\/\=]/g;
  if (base64test.exec(input)) {
     alert("There were invalid base64 characters in the input text.\n" +
           "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
           "Expect errors in decoding.");
  }
  input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

  do {
     enc1 = keyStr.indexOf(input.charAt(i++));
     enc2 = keyStr.indexOf(input.charAt(i++));
     enc3 = keyStr.indexOf(input.charAt(i++));
     enc4 = keyStr.indexOf(input.charAt(i++));

     chr1 = (enc1 << 2) | (enc2 >> 4);
     chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
     chr3 = ((enc3 & 3) << 6) | enc4;

     output = output + String.fromCharCode(chr1);

     if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
     }
     if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
     }

     chr1 = chr2 = chr3 = "";
     enc1 = enc2 = enc3 = enc4 = "";

  } while (i < input.length);

  return output;
}
