function saveThisPage() {
  url = this.location.href;
  document.execCommand("saveAs", true,"sekretaria");
  this.location.href = url;
}

/* Preload und Austausch der Produkt-Bilder */
var prdImages = new Array();
var prdImagesCarousel = new Array();
var currentProdImg = 1;

function preloadPrdImg(url,title) {
  var img = new Image();
  img.src = url;
  img.name = title;
  prdImages[prdImages.length] = img;
}

function preloadPrdImgCarousel(url, title) {
  var img = new Image();
  img.src = url;
  img.name = title;
  prdImagesCarousel[prdImagesCarousel.length] = img;
}

function showPrdImg(index) {
  var img = document.getElementById("prdbig");
  img.width = prdImages[index].width;
  img.height = prdImages[index].height;
  img.src = prdImages[index].src;
  var imgtitle = document.getElementById("prdbigtitle");
  imgtitle.innerHTML = prdImages[index].name;
  currentProdImg = index + 1;
}

function showPrdImgCarousel(index) {
  var img = document.getElementById("prdbig_carousel");
  img.width = prdImagesCarousel[index].width;
  img.height = prdImagesCarousel[index].height;
  img.src = prdImagesCarousel[index].src;
  var imgtitle = document.getElementById("prdbigtitle_carousel");
  imgtitle.innerHTML = prdImagesCarousel[index].name;
  currentProdImg = index + 1;
}

function openPopup(url, width, height) {
  var options = 'location=no,menubar=yes,scrollbars=yes';
  if (parseInt(width) && parseInt(height)) {
    options += ',width=' + width + ',height=' + height;
  }
  var p = '?';
  if (url.split('?').length != 1) {
    p = '&';
  }
  url += p + 'imgcol=' + currentProdImg;

  return window.open(url, "prdpopup", options);
}

function openPopup2(url, width, height) {
  var options = 'location=no,menubar=yes,scrollbars=yes';
  if (parseInt(width) && parseInt(height)) {
    options += ',width=' + width + ',height=' + height;
  }
  var p = '?';
  if (url.split('?').length != 1) {
    p = '&';
  }
  url += p;

  return window.open(url, "prdpopup", options);
}

function setSize() {
  var img = document.getElementById('prdbig_carousel');
  width = img.width + 80;
  height = img.height + 180;
  if (window.outerWidth) {
    window.outerWidth = width;
    window.outerHeight = height;
  }
  else
    if (window.resizeTo) {
      window.resizeTo(width,height);
    }
}

function openPrdCompare(pcode, width, height) {
  var options = 'location=no,menubar=no';
  if (parseInt(width) && parseInt(height)) {
    options += ',width=' + width + ',height=' + height;
  }
  var url = 'ecms.php?page=prd_compare&pv[p]=' + pcode;
  return window.open(url, 'prdCompare', options);
}

function show_notice_and_disable(formname) {
  popup = document.getElementById("payment_save_notice");

  if (formname== 'OrderPayment') {
    if (popup.style.visibility != 'visible') {
      popup.style.visibility = "visible";
      popup.style.display = "block";

      document.getElementById("doSave").disabled = true;

      document.OrderPayment.submit();

    } else {
      popup.style.visibility = "hidden";
      popup.style.display = "none";

      document.getElementById("doSave").disabled = false;
    }
  }
  if (formname== 'OrderDone') {
    if (popup.style.visibility != 'visible') {
      popup.style.visibility = "visible";
      popup.style.display = "block";

      document.getElementById("doSave").disabled = true;

      document.OrderDone.submit();

    } else {
      popup.style.visibility = "hidden";
      popup.style.display = "none";

      document.getElementById("doSave").disabled = false;
    }
  }
}

// File-Upload Progressbar
// Get the Current Upload-Status (AJAX) and set the Progressbar to match
function getProgress(idx, sid, redirect){
  var myRequest = new Ajax.Request('ecms.php?page=ecms_pageCfgUploadProgress&id=' + idx, {
  onSuccess: function(transport) {
    var splitted = transport.responseText.split("/");
    prozent = splitted[0] / splitted[1] * 100;
    document.getElementById('cfg_progress_done').style.width = (prozent ) + "%";
    document.getElementById('cfg_progress_missing').style.width = (100 - prozent ) + "%";
    if (splitted[1] > 1048576) {
      document.getElementById('cfg_progress_current').innerHTML = Math.round((splitted[0]/1048576)*100)/100+' von '+Math.round((splitted[1]/1048576)*100)/100+' MB ('+Math.round(prozent)+' %)';
    } else {
      document.getElementById('cfg_progress_current').innerHTML = Math.round((splitted[0]/1024)*100)/100+' von '+Math.round((splitted[1]/1024)*100)/100+' kB ('+Math.round(prozent)+' %)';
    }
    // call again until upload is finished
    if (prozent != 100) {
      setTimeout("getProgress('" + idx + "', '" + sid + "', '" + redirect + "')", 500);
    } else {
      document.location.href = redirect;
    }
  }
  });
}

// Start the refreshing of the progressbar
function startProgress(filename, idx, sid, redirect) {
  // do we have a file?
  if (filename) {
      // show the progressbar
      document.getElementById("cfg_progressbar").style.display="block";
      document.getElementById("cfg_progress").style.display="block";
    // get the upload-status
      setTimeout("getProgress('" + idx + "', '" + sid + "', '" + redirect + "')", 500);
  }
}




