var dipwin;

function openThesaurus(action, sessionId) {
   var sessId = sessionId;

   if ((sessId != null) && (sessId.indexOf(".") != -1)) {
      sessId = sessId.substring(0, sessId.indexOf("."));
   }

   var dipwin = window.open("/dip21.web/thesaurus/search.do;jsessionid=" + sessionId + "?initial=true&source=" + action, "Thesaurus" + sessId, "width=1020,height=740,left=20,top=200,resizable=yes,scrollbars=auto");
   dipwin.focus();

   window.setTimeout('submitForm("sessionId", "sessId")', 1000);
}

function openThesaurus(action, sessionId, fieldId) {
   var sessId = sessionId;
   var time = new Date();
   if ((sessId != null) && (sessId.indexOf(".") != -1)) {
      sessId = sessId.substring(0, sessId.indexOf("."));
   }

   var dipwin = window.open("/dip21.web/thesaurus/search.do;jsessionid=" + sessionId + "?initial=true&source=" + action + "&fieldId=" + fieldId, "Thesaurus" + sessId, "width=1020,height=740,left=20,top=200,resizable=yes,scrollbars=auto");
   dipwin.focus();

   window.setTimeout('submitForm("sessionId", "sessId")', 1000);
}

function submitForm(sessionId, sessId) {
   var time = new Date();
   document.forms[0].prompt.value = "yes";
   document.forms[0].submit();
   window.name = "DIP21" + sessionId + time;
   document.forms[0].target = 'Thesaurus' + sessId;
}

function openHelp(helpcall) {
   var dipwin = window.open(helpcall, "Hilfe", "width=640,height=480,left=20,top=200,resizable=yes,scrollbars=yes");
   dipwin.focus();
}

function openProcedureSearch(sessionId) {
   var sessId = sessionId;
   if ((sessionId != null) && (sessionId.indexOf(".") != -1)) {
      sessId = sessionId.substring(0, sessId.indexOf("."));
   }

   dipwin = window.open("/dip21.web/data-acquisition/procedureIndexatSearch.do;jsessionid=" + sessionId, "ISearch" + sessId, "width=850,height=590,left=20,top=200,resizable=yes,scrollbars=auto");
   dipwin.focus();

   document.forms[0].submit();
   document.forms[0].target = 'ISearch' + sessId;
   window.name = "DIP21" + sessionId;
}

function openProcedureLinkSearchOld(sessionId) {
   var sessId = sessionId;
   if ((sessionId != null) && (sessionId.indexOf(".") != -1)) {
      sessId = sessionId.substring(0, sessId.indexOf("."));
   }


   dipwin = window.open("/dip21.web/data-acquisition/procedure_detail_link_search.do;jsessionid=" + sessionId, "ISearch" + sessId, "width=850,height=590,left=20,top=200,resizable=yes,scrollbars=auto");
   dipwin.focus();

   document.forms[0].submit();
   document.forms[0].target = 'ISearch' + sessId;
   window.name = "DIP21" + sessionId;
}

function setTarget(sessionId) {
   setOverrideChanged();

   var sessId = sessionId;
   var time = new Date();
   if ((sessionId != null) && (sessionId.indexOf(".") != -1)) {
      sessId = sessionId.substring(0, sessId.indexOf("."));
   }
   dipwin = window.open("/dip21.web/empty.jsp", "DIP21Auswahl" + sessId, "toolbar=no, titlebar=no, menubar=no," +
      " left=200, top=200, scrollbars=no, resizable=yes, width=500, height=350");
   dipwin.focus();
   document.forms[0].javascriptActive.value = 'yes';
   document.forms[0].target = 'DIP21Auswahl' + sessId;
   window.name = "DIP21" + sessionId + time;
}

function setTargetForPrompt(css, sessionId) {
   var sessId = sessionId;
   if ((sessionId != null) && (sessionId.indexOf(".") != -1)) {
      sessId = sessionId.substring(0, sessId.indexOf("."));
   }
   dipwin = window.open("/dip21.web/yesNo.jsp", "DIP21Auswahl" + sessId, "toolbar=no, titlebar=no, menubar=no, left=200, top=200, scrollbars=no, resizable=yes, width=500, height=200");
   dipwin.focus();
   document.forms[0].javascriptActive.value = 'yes';
   document.forms[0].prompt.value = 'yes';
   document.forms[0].target = 'DIP21Auswahl' + sessId;
   window.name = "DIP21" + sessionId;
}

function openView(action, sessionId, todo) {
   var mainWin = document.forms[0].target;

   if ("Drucken" == todo) {
      dipwin = window.open("/dip21.web/empty.jsp", "Exportansicht", "width=900,height=730,left=20,top=200,resizable=yes,scrollbars=yes");
      document.forms[0].target = "Exportansicht";
   }

   //disableExportButtons();

   document.forms[0].action = "/dip21.web/" + action + sessionId + "?method=" + todo;
   document.forms[0].submit();

   document.forms[0].action = "/dip21.web/" + action + sessionId
   document.forms[0].target = mainWin;

   if (dipwin != null) {
      dipwin.focus();
   }
}

function openQuickView(action, sessionId, todo, vorgangId) {
   var mainWin = document.forms[0].target;

   if ("SchnellDruck" == todo) {
      dipwin = window.open("/dip21.web/empty.jsp", "Exportansicht", "width=900,height=730,left=20,top=200,resizable=yes,scrollbars=yes");
      document.forms[0].target = "Exportansicht";
   }
   var helpaction = document.forms[0].action;
   document.forms[0].action = "/dip21.web/" + action + sessionId + "?method=" + todo + "&selId=" + vorgangId;
   document.forms[0].submit();

   document.forms[0].action = helpaction;
   document.forms[0].target = mainWin;

   if (dipwin != null) {
      dipwin.focus();
   }
}
function closeSubWindows() {
   //var windowName = "DIP21";
   dipwin.close();
}

function executeSearch(e) {
   var key = window.event ? e.keyCode : e.which;
   if (key == 13) {
      element = document.getElementById("btnSuche");
      if (element == null)
         return false;
      element.focus();
      element.click();
      return false;
   }
}


function getSearchValues(action) {
   document.forms[0].action = action;
   document.forms[0].submit();

}

function setJavaScriptActive() {
   if (document.forms[0] != null) {
      if (document.forms[0].javascriptActive != null) {
         document.forms[0].javascriptActive.value = 'yes';
      }
   }
}

function closeValueList() {
   var MW;
   if (window.opener.name != null) {
      MW = window.opener.name;
   }
   else {
      MW = "DIP";
   }
   document.forms[0].target = MW;
   // document.forms[0].submit();
   setTimeout('window.close()', 500);
}

function closeIndexatSearch() {
   var MW;
   if (window.opener.name != null) {
      MW = window.opener.name;
   }
   else {
      MW = "DIP";
   }
   document.forms[0].target = MW;
   // document.forms[0].submit();
   setTimeout('window.close()', 500);
}

function closeProcedureLinkSearch() {
   var MW;
   if (window.opener.name != null) {
      MW = window.opener.name;
   } else {
      MW = "DIP";
   }
   document.forms[0].target = MW;
   // document.forms[0].submit();
   setTimeout('window.close()', 500);
}

function resetTarget() {
   document.DrsAePuSearchForm.target = "_self";
}

function resetParentTarget() {
   window.opener.document.forms[0].target = "_self";
}

function resizeWindow() {
   var width = 250;

   if (document.forms[0] != null) {
      if ((document.forms[0].elements[1] != null) && (document.forms[0].elements[1].offsetWidth > width)) {
         width = document.forms[0].elements[1].offsetWidth;
      }

      if ((document.forms[0].elements[3] != null) && (document.forms[0].elements[3].offsetWidth > width)) {
         width = document.forms[0].elements[3].offsetWidth;
      }

      if ((document.forms[0].elements[5] != null) && (document.forms[0].elements[5].offsetWidth > width)) {
         width = document.forms[0].elements[5].offsetWidth;
      }

      if (width > 820) {
         window.resizeTo(820, 420);
      }

      else {
         window.resizeTo(width + 40, 480);
      }
   }
}


String.prototype.rememberScrollPosition = function () {

   var objElement = document.getElementById(this);
   if (objElement != null && document.forms[0].selectedRow > 0 || objElement != null && window.location.search != "") {
      var intTop = (objElement.id + "-y").getCookie();
      if (intTop) objElement.scrollTop = intTop;
      var intLeft = (objElement.id + "-x").getCookie();
      if (intLeft) objElement.scrollLeft = intLeft;
      objElement.onscroll = function () {
         document.cookie = this.id + "-x=" + objElement.scrollLeft;
         document.cookie = this.id + "-y=" + objElement.scrollTop;
      }
   }
}

String.prototype.getCookie = function () {
   if (document.cookie.length > 0) {
      var intBegin = document.cookie.indexOf(this + "=");
      if (intBegin != -1) {
         intBegin += this.length + 1;
         var intEnd = document.cookie.indexOf(";", intBegin);
         if (intEnd == -1) intEnd = document.cookie.length;
         return unescape(document.cookie.substring(intBegin, intEnd));
      }
   }
   return null;
}

function setChanged() {
   resetOverrideChanged();

   document.forms[0].formChanged.value = 'true';
}

function setPromptUser() {
   if (document.forms[0] == null)
      return;
   if (document.forms[0].promptUser == null)
      return;
   document.forms[0].promptUser.value = 'true';
}

function setOverrideChanged() {
   if (document.forms[0] == null)
      return;
   if (document.forms[0].overrideChanged == null)
      return;
   document.forms[0].overrideChanged.value = 'true';
}
function resetOverrideChanged() {
   if (document.forms[0] == null)
      return;
   if (document.forms[0].overrideChanged == null)
      return;
   document.forms[0].overrideChanged.value = 'false';
}
function setBrowserType() {
   if (document.forms[0] == null)
      return;
   if (document.forms[0].browserType == null)
      return;
   document.forms[0].browserType.value = navigator.appName;
}

function resetChanged() {
   if (document.forms[0].formChanged != null)
      document.forms[0].formChanged.value = 'false';
}


function checkChanged() {
   if (document.forms[0] == null)
      return;
   if (document.forms[0].promptUser == null)
      return;
   if (document.forms[0].promptUser.value == 'true' &&
      document.forms[0].formChanged.value == 'true' &&
      document.forms[0].overrideChanged.value == 'false') {
      var message = "Daten wurden ge\u00e4ndert aber nicht gespeichert. Wenn Sie die Seite jetzt verlassen, gehen die \u00c4nderungen verloren."
      return message;
   }
}

function checkDeactivation() {

   var activeWpIsSelected = false;
   if (document.forms[0].activeWP == null || document.forms[0].activeWP.value == "") {

      document.forms[0].submit();
      return;
   }

   for (var i = 0; i < document.forms[0].gueltZeitraum.length; i++) {
      if (document.forms[0].gueltZeitraum.options[i].selected == true) {
         if (document.forms[0].activeWP.value == document.forms[0].gueltZeitraum.options[i].text) {
            activeWpIsSelected = true;
            break;
         }
      }
   }

   if (!activeWpIsSelected) {
      var agree = confirm("Sie sind dabei einen Haupteintrag zu deaktivieren. \nWollen Sie alle zugeh\u00F6rigen  Nebeneintr\u00e4ge ebenfalls deaktivieren?");
      if (agree) {
         document.forms[0].answer.value = "yes";
      }
      document.forms[0].submit();
   }
}


//Einstellungen fuer Disabled Link
var DisabledLinkHref = 'javascript:void(0)';
var DisabledLinkTarget = '';

var LinkArray = new Array();
var TargetArray = new Array();
function DisableLinks() {
   for (i = 0; i < document.links.length; i++) {
      a = document.links[i].href;
      b = document.links[i].target;
      LinkArray[i] = a;
      TargetArray[i] = b;
      document.links[i].href = DisabledLinkHref;
      document.links[i].target = DisabledLinkTarget;
   }
}

function EnableLinks() {
   for (i = 0; i < LinkArray.length; i++) {
      document.links[i].href = LinkArray[i];
      document.links[i].target = TargetArray[i];
   }
}

var allselected = "";

function checkAllEntries(name) {
   if (allselected == "") {
      allselected = "true";
   }
   else {
      allselected = "";
   }

   for (i = 0; i < document.getElementsByName(name).length; i++) {
      document.getElementsByName(name)[i].checked = allselected;
   }
}

function disableExportButtons() {
   var exportButton = document.getElementById("btnExport");
   if (exportButton != null) {
      exportButton.disabled = true;
      exportButton.className = 'button-medium-disabled';
   }
   var exportAllButton = document.getElementById("btnExportAll");
   if (exportAllButton != null) {
      exportAllButton.disabled = true;
      exportAllButton.className = 'button-medium-disabled';
   }
   var printButton = document.getElementById("btnPrint");
   if (printButton != null) {
      printButton.disabled = true;
      printButton.className = 'button-medium-disabled';
   }
   var exportTrefferButton = document.getElementById("btnExportTreffer");

}

function enableExportButtons() {
   var exportButton = document.getElementById("btnExport");
   if (exportButton != null) {
      exportButton.disabled = false;
      exportButton.className = 'button-medium';
   }
   var exportAllButton = document.getElementById("btnExportAll");
   if (exportAllButton != null) {
      exportAllButton.disabled = false;
      exportAllButton.className = 'button-medium';
   }
   var printButton = document.getElementById("btnPrint");
   if (printButton != null) {
      printButton.disabled = false;
      printButton.className = 'button-medium';
   }
}

function setFocus() {
   var elem = document.getElementById("langtitel");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("ku");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("ressort");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("beschlusstenor");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("ausschuss");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("nachname");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("statistikmerkmal");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("sachgebiet");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("zustBeduerftigkeit");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
}

function setSearchFocus() {
   var elem = document.getElementById("suchBegriff");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
   elem = document.getElementById("vorgangsindexSuchwort");
   if ((elem != null) && (elem.type != "hidden")) {
      elem.focus();
   }
}

var sAmount = "";
var sSession = "";
var sUrl = "";
function openProgress(amount, session) {
   sAmount = amount;
   sSession = session;
   window.setTimeout('openPBar()', 1000);
   sUrl = "/dip21.web/pleaseWaitForExport.jsp" + sSession + "?amount=" + sAmount;
}

function openPBar() {

   var dipwin = window.open(sUrl, "Exportfortschritt", "width=550,height=115,left=200,top=200,resizable=yes,scrollbars=yes");

   if (dipwin != null) {
      dipwin.focus();
   }

}

function refreshPBar(intervall, amount, session) {
   sAmount = amount;
   sSession = session;
   sUrl = "window.location.replace('/dip21.web/pleaseWaitForExport.jsp" + sSession + "?amount=" + sAmount + "')";
   window.setTimeout(sUrl, intervall);
}

function addtofavorites(obj, url, title) {
   var url = url;
   var title = title;

   // Mozilla Firefox Bookmark
   if (window.sidebar) {
      window.sidebar.addPanel(title, url, "");
      return false;
   }

   // IE Favorite
   else if (window.external) {
      window.external.AddFavorite(url, title);
      return false;
   }

   // Opera Hotlist
   else if (window.opera && window.print) {
      obj.setAttribute('href', url);
      obj.setAttribute('title', title);
      obj.setAttribute('rel', 'sidebar');
      obj.click();
      return true;
   }

   else {
      alert("Leider unterst&uuml;tzt Ihr Webbrowser diese Funktion nicht.");
      return true;
   }
}

