﻿function LightBoxSizeAdjustment(strPanelId) {
  var LightBoxPanel = document.getElementById(strPanelId);
  if (LightBoxPanel != undefined) {
    LightBoxPanel.style.height = document.body.clientHeight;
    LightBoxPanel.style.width = document.body.clientWidth;
  }
}

function setDisabledStyleForFirefox() {
  for (x = 0; x < document.aspnetForm.elements.length; x++) {
    if (document.aspnetForm.elements[x].disabled) {
      document.aspnetForm.elements[x].className = 'ButtonDefaultDisabled';
    }
  }
}


// checkbox functions used in "CoreData/RoleEditRight.aspx"
function ShowCheckbox(RepeaterGroup) {
  var checkBox;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsView');
  if (checkBox) checkBox.checked = true;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsAdd');
  if (checkBox) checkBox.checked = true;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsChange');
  if (checkBox) checkBox.checked = true;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsDelete');
  if (checkBox) checkBox.checked = true;
}

function HideCheckbox(RepeaterGroup) {
  var checkBox;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsView');
  if (checkBox) checkBox.checked = false;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsAdd');
  if (checkBox) checkBox.checked = false;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsChange');
  if (checkBox) checkBox.checked = false;
  checkBox = document.getElementById(
  RepeaterGroup + '_CbRightsDelete');
  if (checkBox) checkBox.checked = false;
}

function ShowCheckboxOverall(RepeaterID, RepeaterItemCount) {
  for (var i = 0; i < RepeaterItemCount; i++) {
    var z = i;
    if (z < 10)
      z = "0" + z;
    ShowCheckbox(RepeaterID + "_ctl" + z);
  }
}

function HideCheckboxOverall(RepeaterID, RepeaterItemCount) {
  for (var i = 0; i < RepeaterItemCount; i++) {
    var z = i;
    if (z < 10)
      z = "0" + z;
    HideCheckbox(RepeaterID + "_ctl" + z);
  }
}

//-------------------------------------------------------------------
// Popupfenster öffnen
//-------------------------------------------------------------------
function openPopup(url, width, height) {
  var newwindow = '';
  var left = (screen.width / 2) - width / 2;
  var top = (screen.height / 2) - height / 2;

  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
  if (!newwindow.closed && newwindow.location) {
    newwindow.location.href = url;
  }
  else {
    newwindow = window.open(url, "Hip", styleStr);
    if (!newwindow.opener) newwindow.opener = self;
  }

  if (window.focus) { newwindow.focus() }
}

//-------------------------------------------------------------------
// Popupfenster mit Scrollbars öffnen
//-------------------------------------------------------------------
function openPopupWithScrollbars(url, width, height) {
  var newwindow = '';
  var left = (screen.width / 2) - width / 2;
  var top = (screen.height / 2) - height / 2;

  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
  if (!newwindow.closed && newwindow.location) {
    newwindow.location.href = url;
  }
  else {
    newwindow = window.open(url, "Hip", styleStr);
    if (!newwindow.opener) newwindow.opener = self;
  }
  if (window.focus) { newwindow.focus() }
}

//-------------------------------------------------------------------
// Popupfenster mit Scrollbars (Größenverstellbar) öffnen
//-------------------------------------------------------------------
var newwindow = '';
function openPopupWithScrollbarsSize(url, width, height, windowname) {
  var left = (screen.width / 2) - width / 2;
  var top = (screen.height / 2) - height / 2;

  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
  if (!newwindow.closed && newwindow.location) {
    newwindow.close();
  }
  newwindow = window.open(url, windowname, styleStr);
  if (!newwindow.opener) newwindow.opener = self;
}

//-------------------------------------------------------------------
// 
//-------------------------------------------------------------------
function openRealPopup(url, width, height) {
  var newwindow = '';
  var left = (screen.width / 2) - width / 2;
  var top = (screen.height / 2) - height / 2;

  var styleStr = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
  if (!newwindow.closed && newwindow.location) {
    newwindow.location.href = url;
  }
  else {
    newwindow = window.open(url, "Hip", styleStr);
    if (!newwindow.opener) newwindow.opener = self;
  }
  if (window.focus) { newwindow.focus() }
}

function GetCursorCoordinates(e, textBoxXId, textBoxYId, panelMarkerId) {
  // TextBox für X-Koordinate setzen
  var textBoxX = document.getElementById(textBoxXId);
  // TextBox für Y-Koordinate setzen
  var textBoxY = document.getElementById(textBoxYId);
  // Layer für den Marker setzen
  var panelMarker = document.getElementById(panelMarkerId);

  // Variablen der Koordinaten initialisieren
  var coordinateX = 0;
  var coordinateY = 1;

  if (e.offsetX) {
    // Maus-Koordinaten holen (IE)
    coordinateX = e.offsetX;
    coordinateY = e.offsetY;
  } else {
  // Maus-Koordinaten holen (FF)
    coordinateX = e.layerX - 1;
    coordinateY = e.layerY - 1;
  }

  // Debug
  //alert(coordinateX + "/" + coordinateY);

  // Values der Textboxen setzen
  textBoxX.value = coordinateX;
  textBoxY.value = coordinateY;

  // Neue Markerposition setzen (Bildgröße = 14*14
  // Abweichung des Markers innerhalb der Bildmaße: X = 0, Y = +3
  panelMarker.style.left = coordinateX + "px";
  panelMarker.style.top = (coordinateY - 11) + "px";
}
