﻿/*
* JavaScript für die OnControls
* ---
* Benötigt vorher registriertes jQuery
*/
function checkAll(clientID) {
  e = document.getElementById(clientID + 'all');
  for (i = 0; i < document.forms[0].elements.length; i++) {
    element = document.forms[0].elements[i];
    if (element.type) {
      if (element.type == 'checkbox') {
        if (element.name.indexOf(clientID + '_Check_') == 0) {
          element.checked = e.checked;
        }
      }
    }
  }
}

function submitWithValidate(id, action, clientID) {
  try
  {
    prepareForm();
  }
  catch(e)
  {
  }
  e = document.getElementById('noValidate');
  if (!e) {
    e = document.getElementsByName('noValidate')[0];
  }
  e.value = "false";
  e = document.getElementById('action' + clientID);
  if (!e) {
    e = document.getElementsByName('action' + clientID)[0];
  }
  e.value = action;
  if (document.forms[0].action.indexOf('#') > 0) {
    document.forms[0].action = document.forms[0].action.subString(0, document.forms[0].action.indexOf('#'));
  }
  document.forms[0].action = document.forms[0].action + '#anker' + id;
  document.forms[0].submit();
}

function submitWithoutValidate(id, action, clientID) {
  try {
    prepareForm();
  }
  catch (e) {
  }
  e = document.getElementById('noValidate');
  if (!e) {
    e = document.getElementsByName('noValidate')[0];
  }
  e.value = "true";
  e = document.getElementById('action' + clientID);
  if (!e) {
    e = document.getElementsByName('action' + clientID)[0];
  }
  e.value = action;
  if (document.forms[0].action.indexOf('#') > 0) {
    document.forms[0].action = document.forms[0].action.subString(0, document.forms[0].action.indexOf('#'));
  }
  document.forms[0].action = document.forms[0].action + '#anker' + id;
  document.forms[0].submit();
}

function SubmitHtmlSourceTo(printurl, utf8encode) {
  var htmlSource = "<html>";
  htmlSource += document.documentElement.innerHTML;
  htmlSource += "</html>";

  if (utf8encode)
    htmlSource = EncodeBase64(EncodeUTF(htmlSource));
  else
    htmlSource = EncodeBase64(htmlSource);

  if (document.getElementById('printform') == null) {
    var formtag = document.createElement('form');
    document.body.appendChild(formtag);
    var eidie = document.createAttribute('id');
    eidie.nodeValue = "printform";
    formtag.setAttributeNode(eidie);
    var ziel = document.createAttribute('target');
    ziel.nodeValue = "_blank";
    formtag.setAttributeNode(ziel);
    var aktion = document.createAttribute('action');
    aktion.nodeValue = printurl;
    formtag.setAttributeNode(aktion);
    var methode = document.createAttribute('method');
    methode.nodeValue = "post";
    formtag.setAttributeNode(methode);

    var inputtag = document.createElement('input');
    var itypus = document.createAttribute('type');
    itypus.nodeValue = "hidden";
    inputtag.setAttributeNode(itypus);
    formtag.appendChild(inputtag);
    var ieidie = document.createAttribute('id');
    ieidie.nodeValue = "printhtml";
    inputtag.setAttributeNode(ieidie);
    var iname = document.createAttribute('name');
    iname.nodeValue = "printhtml";
    inputtag.setAttributeNode(iname);
    var iwert = document.createAttribute('value');
    iwert.nodeValue = htmlSource;
    inputtag.setAttributeNode(iwert);
  }
  else {
    document.getElementById('printform').getAttributeNode('action').nodeValue = printurl;
    document.getElementById('printhtml').value = htmlSource;
  }


  document.getElementById('printform').submit();
}

function EncodeUTF(string) {
  string = string.replace(/\r\n/g, "\n");
  var utftext = "";
  for (var n = 0; n < string.length; n++) {
    var c = string.charCodeAt(n);
    if (c < 128) {
      utftext += String.fromCharCode(c);
    }
    else if ((c > 127) && (c < 2048)) {
      utftext += String.fromCharCode((c >> 6) | 192);
      utftext += String.fromCharCode((c & 63) | 128);
    }
    else {
      utftext += String.fromCharCode((c >> 12) | 224);
      utftext += String.fromCharCode(((c >> 6) & 63) | 128);
      utftext += String.fromCharCode((c & 63) | 128);
    }
  }
  return utftext;
}

function EncodeBase64(str) {
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  var encoded = [];
  var c = 0;
  while (c < str.length) {
    var b0 = str.charCodeAt(c++);
    var b1 = str.charCodeAt(c++);
    var b2 = str.charCodeAt(c++);
    var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
    var i0 = (buf & (63 << 18)) >> 18;
    var i1 = (buf & (63 << 12)) >> 12;
    var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
    var i3 = isNaN(b2) ? 64 : (buf & 63);
    encoded[encoded.length] = chars.charAt(i0);
    encoded[encoded.length] = chars.charAt(i1);
    encoded[encoded.length] = chars.charAt(i2);
    encoded[encoded.length] = chars.charAt(i3);
  }
  return encoded.join('');
}

function DecodeBase64(str) {
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  var invalid = {
    strlen: (str.length % 4 != 0),
    chars: new RegExp('[^' + chars + ']').test(str),
    equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
  };
  if (invalid.strlen || invalid.chars || invalid.equals)
    throw new Error('Invalid base64 data');
  var decoded = [];
  var c = 0;
  while (c < str.length) {
    var i0 = chars.indexOf(str.charAt(c++));
    var i1 = chars.indexOf(str.charAt(c++));
    var i2 = chars.indexOf(str.charAt(c++));
    var i3 = chars.indexOf(str.charAt(c++));
    var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
    var b0 = (buf & (255 << 16)) >> 16;
    var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
    var b2 = (i3 == 64) ? -1 : (buf & 255);
    decoded[decoded.length] = String.fromCharCode(b0);
    if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
    if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
  }
  return decoded.join('');
}

/*** Liste ***/
function setCommand(target, idfield, action) {
  jQuery('#actionField').val(action);
  jQuery('#idField').val(idfield);
  jQuery('#targetField').val(target);
}

/*** DATEPICKER ***/

/* Standardwerte setzen */
function initDatepickers() {
  jQuery.datepicker.regional['de'] = { clearText: 'l&ouml;schen', clearStatus: 'aktuelles Datum l&ouml;schen',
    closeText: '', closeStatus: 'ohne &Auml;nderungen schlie&szlig;en',
    prevText: '&lt;Zur&uuml;ck', prevStatus: 'letzten Monat zeigen',
    nextText: 'Vor&#x3e;', nextStatus: 'n&auml;chsten Monat zeigen',
    currentText: '', currentStatus: '',
    monthNames: ['Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni',
                'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    monthNamesShort: ['Jan', 'Feb', 'M&auml;r', 'Apr', 'Mai', 'Jun',
                'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
    monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
    weekHeader: 'Wo', weekStatus: 'Woche des Monats',
    dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'W&auml;hle D, M d',
    dateFormat: 'dd.mm.yy', firstDay: 1,
    initStatus: 'bitte Datum ausw&auml;hlen', isRTL: false
  };
  jQuery.datepicker.setDefaults(jQuery.datepicker.regional['de']);
}



/*** CHECKBOXEN ***/

function getSplitPos(e) {
  var bgpos = jQuery(e).parent("label").css("background-position");
  // weil IE "background-position" nicht kennt				
  if (typeof (bgpos) === "undefined") {
    bgpos = jQuery(e).parent("label").css("background-position-x") + " " + jQuery(e).parent("label").css("background-position-y");
  }
  return bgpos.split(" ");
}

/*
* Wandelt input type="checkbox" in eine grafische Checkbox um
* @param e         jQuery Abfrage oder Checkboxobjekt
* @param onclickjs JavaScript das bei onclick ausgeführt wird
*/
function MakeImageCheckbox(e, onclickjs) {
  jQuery(e).addClass("hidecheckbox");

  var bgsplitpos = getSplitPos(e);
  if (jQuery(e).attr("type") == "checkbox") {
    jQuery(e).parent("label").addClass("jqcheckbox");
    if (jQuery(e).attr("disabled")) {
      jQuery(e).parent("label").addClass("disabled");
    }
    jQuery(e).parent("label").click(function() {
      var bgsplitpos = getSplitPos(e);
      if (jQuery(e).attr("disabled")) {
        return false;
      }

      //alert(bgsplitpos);
      if (jQuery(e).attr("checked")) {
        jQuery(e).attr('checked', '');
        // weil IE6 MultiKlassenSelector nicht unterstützt					
        if (jQuery(e).parent("label").hasClass("hidelabel")) {
          jQuery(e).parent("label").css("background-position", bgsplitpos[0] + " 0");
        }
      } else {
        jQuery(e).attr('checked', 'checked');
        // weil IE6 MultiKlassenSelector nicht unterstützt					
        if (jQuery(e).parent("label").hasClass("hidelabel")) {
          jQuery(e).parent("label").css("background-position", bgsplitpos[0] + " -200px");
        }
      }
      jQuery(e).parent("label").toggleClass("checked");
      if (typeof (onclickjs) !== "undefined") {
        eval(onclickjs);
      }
      return false;
    });
  }

  if (jQuery(e).attr("checked")) {
    if (jQuery(e).attr("disabled")) {
      jQuery(e).parent("label").addClass("disabledchecked");
      jQuery(e).parent("label").css("background-position", bgsplitpos[0] + " -500px");
    }
    else {
      jQuery(e).parent("label").addClass("checked");
      jQuery(e).parent("label").css("background-position", bgsplitpos[0] + " -200px");
    }


  }
}

function removeFromQuerystring(url, name) {
  var inttemp;
  var inttemp2;
  var strtemp;
  var strreturn;
  inttemp = url.indexOf(name);
  inttemp2 = url.indexOf("&", inttemp);
  if (inttemp2 != -1) {
    strtemp = url.slice(inttemp + name.length, inttemp2);
  }
  else {
    strtemp = url.slice(inttemp + name.length);
  }
  url = url.replace(name + strtemp, "");
  url = url.replace("?&", "?");
  url = url.replace("&&", "&");
  return url;
}


function navigateToV2(page, anker, ClientID, form, ajaxUrl) {
  if (!ajaxUrl) {
    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    e.value = page;
    e = document.getElementById("noValidate");
    if (!e) {
      e = document.getElementsByName("noValidate")[0];
    }
    e.value = "true";
    if (document.forms[form].action.indexOf("#") > 0) {
      document.forms[form].action = document.forms[form].action.substring(0, document.forms[form].action.indexOf("#"));
    }
    if (anker) {
      document.forms[form].action = document.forms[form].action + "#" + anker;
    }

    document.forms[form].action = removeFromQuerystring(document.forms[form].action, "autoforwardid");

    document.forms[form].submit();
  }
  else {
    e = document.getElementById("size" + ClientID);
    if (!e) {
      e = document.getElementsByName("size" + ClientID)[0];
    }
    size = e.value;

    e = document.getElementById("column" + ClientID);
    if (!e) {
      e = document.getElementsByName("column" + ClientID)[0];
    }
    column = e.value;

    e = document.getElementById("direction" + ClientID);
    if (!e) {
      e = document.getElementsByName("direction" + ClientID)[0];
    }
    direction = e.value;

    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    e.value = page;
    e = document.getElementById("noValidate");
    if (!e) {
      e = document.getElementsByName("noValidate")[0];
    }
    e.value = "true";
    url = getAjaxUrlV2(ajaxUrl) + "page" + ClientID + "=" + page + "&size" + ClientID + "=" + size + "&direction" + ClientID + "=" + direction + "&column" + ClientID + "=" + column + "&rnd=" + Math.random();
    ajaxV2(url, ClientID, onPageModified, MessageOnError, callbackV2, true);
  }
}

function getAjaxUrlV2(ajaxUrl) {
  if (ajaxUrl.indexOf("?") >= 0) {
    ajaxUrl = ajaxUrl + "&";
  }
  else {
    ajaxUrl = ajaxUrl + "?";
  }

  pos = document.location.href.indexOf("?");
  if (pos >= 0) {
    ajaxUrl = ajaxUrl + document.location.href.substring(pos+1, document.location.href.length) + "&";
}

  return ajaxUrl;
}
function setSizeV2(size, anker, ClientID, form, ajaxUrl) {
  if (!ajaxUrl) {
    e = document.getElementById("size" + ClientID, form);
    if (!e) {
      e = document.getElementsByName("size" + ClientID)[0];
    }
    oldSize = e.value;
    e.value = size;

    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    oldPage = e.value;
    page = Math.round(((oldPage - 1) * oldSize) / size) + 1;
    e.value = page;

    e = document.getElementById("noValidate");
    if (!e) {
      e = document.getElementsByName("noValidate")[0];
    }

    e.value = "true";
    if (document.forms[form].action.indexOf("#") > 0) {
      document.forms[form].action = document.forms[form].action.substring(0, document.forms[form].action.indexOf("#"));
    }
    document.forms[form].action = document.forms[form].action + "#" + anker;
    document.forms[form].action = removeFromQuerystring(document.forms[form].action, "autoforwardid");
    document.forms[form].submit();
  }
  else {
    e = document.getElementById("column" + ClientID);
    if (!e) {
      e = document.getElementsByName("column" + ClientID)[0];
    }
    column = e.value;

    e = document.getElementById("direction" + ClientID);
    if (!e) {
      e = document.getElementsByName("direction" + ClientID)[0];
    }
    direction = e.value;

    e = document.getElementById("size" + ClientID);
    if (!e) {
      e = document.getElementsByName("size" + ClientID)[0];
    }
    oldSize = e.value;
    e.value = size;

    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    oldPage = e.value;
    page = Math.round(((oldPage - 1) * oldSize) / size) + 1;
    e.value = page;

    e = document.getElementById("column" + ClientID);
    if (!e) {
      e = document.getElementsByName("column" + ClientID)[0];
    }
    e.value = column;

    e = document.getElementById("direction" + ClientID);
    if (!e) {
      e = document.getElementsByName("direction" + ClientID)[0];
    }
    e.value = direction;
    e = document.getElementById("noValidate");
    if (!e) {
      e = document.getElementsByName("noValidate")[0];
    }
    e.value = "true";

    url = getAjaxUrlV2(ajaxUrl) + "page" + ClientID + "=" + page + "&size" + ClientID + "=" + size + "&direction" + ClientID + "=" + direction + "&column" + ClientID + "=" + column + "&rnd=" + Math.random();
    ajaxV2(url, ClientID, onPageModified, MessageOnError, callbackV2, true);
  }
}

function setSortV2(column, direction, anker, ClientID, form, ajaxUrl) {
  if (!ajaxUrl) {
    e = document.getElementById("size" + ClientID);
    if (!e) {
      e = document.getElementsByName("size" + ClientID)[0];
    }
    size = e.value;

    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    page = e.value;

    e = document.getElementById("column" + ClientID);
    if (!e) {
      e = document.getElementsByName("column" + ClientID)[0];
    }
    //unverändert?
    unchanged = false;
    if (e.value == column) {
      unchanged = true;
    }
    e.value = column;

    e = document.getElementById("direction" + ClientID);
    if (!e) {
      e = document.getElementsByName("direction" + ClientID)[0];
    }
    if (direction != 'toggle') {
      e.value = direction;
    }
    else {
      if (unchanged) {
        if (e.value == 'desc') {
          e.value = 'asc';
          direction = 'asc';
        }
        else {
          e.value = 'desc';
          direction = 'desc';
        }
      }
      else {
        e.value = 'asc';
        direction = 'asc';
      }
    }

    e = document.getElementById("noValidate");
    if (!e) {
      e = document.getElementsByName("noValidate")[0];
    }
    e.value = "true";

    if (document.forms[form].action.indexOf("#") > 0) {
      document.forms[form].action = document.forms[form].action.substring(0, document.forms[form].action.indexOf("#"));
    }
    document.forms[form].action = document.forms[form].action + "#" + anker;
    document.forms[form].action = removeFromQuerystring(document.forms[form].action, "autoforwardid");
    document.forms[form].submit();
  }
  else {
    e = document.getElementById("size" + ClientID);
    if (!e) {
      e = document.getElementsByName("size" + ClientID)[0];
    }
    size = e.value;

    e = document.getElementById("page" + ClientID);
    if (!e) {
      e = document.getElementsByName("page" + ClientID)[0];
    }
    page = e.value;

    e = document.getElementById("column" + ClientID);
    if (!e) {
      e = document.getElementsByName("column" + ClientID)[0];
    }
    //unverändert?
    unchanged = false;
    if (e.value == column) {
      unchanged = true;
    }
    e.value = column;

    e = document.getElementById("direction" + ClientID);
    if (!e) {
      e = document.getElementsByName("direction" + ClientID)[0];
    }
    if (direction != 'toggle') {
      e.value = direction;
    }
    else {
      if (unchanged) {
        if (e.value == 'desc') {
          e.value = 'asc';
          direction = 'asc';
        }
        else {
          e.value = 'desc';
          direction = 'desc';
        }
      }
      else {
        e.value = 'asc';
        direction = 'asc';
      }
    }

    url = getAjaxUrlV2(ajaxUrl) + "page" + ClientID + "=" + page + "&size" + ClientID + "=" + size + "&direction" + ClientID + "=" + direction + "&column" + ClientID + "=" + column + "&rnd=" + Math.random();
    ajaxV2(url, ClientID, onPageModified, MessageOnError, callbackV2, true);
  }
}

function navigateBackV2(ClientID, form, ajaxUrl) {
  navigateToV2(document.getElementsByName('page' + ClientID)[0].value, form, ajaxUrl);
}


function getNaviUrlV2(size, ClientID, form, ajaxUrl) {
  e = document.getElementById("size" + ClientID);
  if (!e) {
    e = document.getElementsByName("size" + ClientID)[0];
  }
  size = e.value;

  e = document.getElementById("page" + ClientID);
  if (!e) {
    e = document.getElementsByName("page" + ClientID)[0];
  }
  page = e.value;

  e = document.getElementById("column" + ClientID);
  if (!e) {
    e = document.getElementsByName("column" + ClientID)[0];
  }
  column = e.value;

  e = document.getElementById("direction" + ClientID);
  if (!e) {
    e = document.getElementsByName("direction" + ClientID)[0];
  }
  direction = e.value;

  url = getAjaxUrlV2(ajaxUrl) + "page" + ClientID + "=" + page + "&size" + ClientID + "=" + size + "&direction" + ClientID + "=" + direction + "&column" + ClientID + "=" + column + "&rnd=" + Math.random();
  return url;
}

function ajaxV2(url, ClientID, onPageModified, MessageOnError, callback, async) {

  var http_request;
  http_request = getXmlObject();
  http_request.onreadystatechange = function() {
    try {
      if (http_request.readyState == 4) {
        if (http_request.status == 200) {
          callback(http_request, ClientID, "myCallback" + ClientID + "()");
          if (onPageModified) {
            try {
              eval(onPageModified);
            }
            catch (e) { }
          }
        }
        else {
          eval(MessageOnError);
        }
      }

      return true;
    }
    catch (e) {
      eval(MessageOnError);
    }
  }
  http_request.open("GET", url, async);
  http_request.send(null);
}


function getXmlObject() {
  var http_request;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
  }
  else
    if (window.ActiveXObject) {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }

  return http_request;
}

function callbackV2(request, ClientID, myCallback) {
  html = request.responseText;
  dummyend = "</div><!--" + ClientID + "-->";
  dummystart = "<div id=\"" + ClientID + "DIV\">";
  if (html.indexOf(dummystart) == -1) {
    dummystart = "<div id=\"" + ClientID + "DIV\" >";
  }
  start = html.indexOf(dummystart) + dummystart.length;
  end = html.indexOf(dummyend);
  html = html.substring(start, end);
  document.getElementById(ClientID + "DIV").innerHTML = html;
  
  extractScripts(html);
  
  try {
    if (myCallback) {
      eval(myCallback);
    }
  }
  catch (e) { }
}


function mySubmitV2(VirtualForm) {
    if (VirtualForm != '') {
        try {
            document.getElementById('virtualForm').value = VirtualForm;
        }
        catch (e) {
            document.getElementsByName('virtualForm')[0].value = VirtualForm;
        }
    }
    return true;
}


function prepareSubmitV2(RealSubmit, BeforeSubmitJS, anker, form) {
  e = document.getElementById("noValidate");
	if (!e)
	{
		e = document.getElementsByName("noValidate")[0];
	}
  e.value = RealSubmit;
	
	eval(BeforeSubmitJS);
	
	if (document.forms[form].action.indexOf("#") > 0)
  {
		document.forms[form].action = document.forms[form].action.substring(0,document.forms[form].action.indexOf("#"));
  }
  document.forms[form].action = document.forms[form].action + "#" + anker;
}

if (!Array.prototype.push) {
  Array.prototype.push = function(elem) {
    this[this.length] = elem;
  }
}

var EventManager =
{
  _registry: null,
  Initialise: function() {
    if (this._registry == null) {
      this._registry = [];
      EventManager.Add(window, "unload", this.CleanUp);
    }
  },

  Add: function(obj, type, fn, useCapture) {
    this.Initialise();
    if (typeof obj == "string")
      obj = document.getElementById(obj);
    if (obj == null) {
      try {
        obj = document.getElementsByName(obj)[0];
      }
      catch (e) { }
    }
    if (obj == null || fn == null)
      return false;
    if (obj.addEventListener) {
      obj.addEventListener(type, fn, useCapture);
      this._registry.push({ obj: obj, type: type, fn: fn, useCapture: useCapture });
      return true;
    }
    if (obj.attachEvent && obj.attachEvent("on" + type, fn)) {
      this._registry.push({ obj: obj, type: type, fn: fn, useCapture: false });
      return true;
    }
    return false;
  },
  CleanUp: function() {
    if (EventManager._registry) {
      for (var i = 0; i < EventManager._registry.length; i++) {
        with (EventManager._registry[i]) {
          if (obj.removeEventListener)
            obj.removeEventListener(type, fn, useCapture);
          else if (obj.detachEvent)
            obj.detachEvent("on" + type, fn);
        }
      }
      EventManager._registry = null;
    }
  }
}

function setWaitCursor(form) {
    if (form == undefined)
        document.forms[0].style.cursor = 'wait';
    else
        document.forms[form].style.cursor = 'wait';
}

function resetCursor(form) {
    if (form == undefined)
        document.forms[0].style.cursor = 'default';
    else
        document.forms[form].style.cursor = 'default';
}

function filterhtml(myhtml, dummystart, dummyend) {
  html = myhtml;
  if (dummystart.length > 0 && dummyend.length > 0) {
    start = html.indexOf(dummystart) + dummystart.length;
    end = html.indexOf(dummyend);
    html = html.substring(start, end);
  }
  return html;
}

var timeoutId = null;


/*AJAX*/
function loadXMLDocV2(url, callback, sc, params, ClientID, CancelOnNewRequest, UseEncodeURI, AddRandomParam, AjaxRedirUrl, AjaxConnectionTimeout, Form, scriptcallback, HideAlert, AlertText, ErrorScript, UsePost, VirtualFormElement, CloseConnection, myviewstatefield) {
  if (CancelOnNewRequest) {
    if (window["xmlhttp" + ClientID]) {
      try {
        window["xmlhttp" + ClientID].abort();
      }
      catch (e) { }
    }
  }
  var doSetCursor;
  doSetCursor = sc;

  p = "";
  if (params) {
    var pa = params.split("|");
    for (i = 0; i < pa.length; i++) {
      if (UseEncodeURI) {
        p = p + "&param" + i + "=" + encodeURI(pa[i]);
      }
      else {
        p = p + "&param" + i + "=" + escape(pa[i]);
      }
    }
  }

  if (AddRandomParam) {
    p = p + "&rnd=" + Math.random();
  }

  if (window.XMLHttpRequest) {
    window["xmlhttp" + ClientID] = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    window["xmlhttp" + ClientID] = new ActiveXObject("Microsoft.XMLHTTP");
  }

  if (AjaxRedirUrl.Length > 0) {
    timeoutId = window.setTimeout(function() {
      window["xmlhttp" + ClientID].abort();
      loadXMLDocV2("autologout.aspx", null);
      window.location.href = AjaxRedirUrl;
    }, AjaxConnectionTimeout);
  }
  if (window.XMLHttpRequest) {
    window["xmlhttp" + ClientID].onreadystatechange = function() {
      if (window["xmlhttp" + ClientID].readyState == 4) {
        if (AjaxRedirUrl.length > 0) {
          window.clearTimeout(timeoutId);
        }
        if (doSetCursor) {
          resetCursor(Form);
        }
        if (window["xmlhttp" + ClientID].status == 200) {
          eval(scriptcallback);
        }
        else {
          if (window["xmlhttp" + ClientID].status != 0) //abort
          {
            if (!HideAlert) {
              if (!AlertText || AlertText.length == 0) {
                alert("Fehler beim Laden der Daten:" + window["xmlhttp" + ClientID].statusText + " (" + window["xmlhttp" + ClientID].status + ")");
              }
              else {
                alert(AlertText);
              }
            }
            if (ErrorScript && ErrorScript.length > 0) {
              eval(ErrorScript);
            }
          }
        }
        if (CancelOnNewRequest) {
          window["xmlhttp" + ClientID] = null;
        }
      }
    }
    if (UsePost) {
      window["xmlhttp" + ClientID].open("POST", url + p, true);
      window["xmlhttp" + ClientID].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
    else {
      window["xmlhttp" + ClientID].open("GET", url + p, true);
    }
    if (doSetCursor) {
      setWaitCursor(Form);
    }
//    myviewstatefield = "__VIEWSTATE";

//    if (GetQueryString("viewstatefield") && GetQueryString("viewstatefield").length > 0) {
//      myviewstatefield = GetQueryString("viewstatefield");
//    }

    if (UsePost) {
      if (VirtualFormElement && VirtualFormElement.length > 0) {
        target = document.getElementById(VirtualFormElement);
        params = "";
        if (target) {
          for (i = 0; i < document.forms[Form].elements.length; i++) {
            element = document.forms[Form].elements[i];
            if (isChild(element, target) || (element.value != null && (element.name.indexOf("CacheStore") > -1 || element.name.indexOf("actionField") > -1 || element.name.indexOf("idField") > -1 || element.name.indexOf("targetField") > -1 || element.name.indexOf("virtualForm") > -1 || element.name.indexOf("size#") > -1 || element.name.indexOf(myviewstatefield) > -1))) {
              if (element.type == 'checkbox' || element.type == 'radio') {
                if (element.checked == true) {
                  if (i > 0) { params = params + "&"; }
                  params = params + element.name + "=" + element.value;
                }
              }
              else if (element.value != null) {
                var fieldname = element.name;
                var takeme = true;

                if (fieldname.indexOf("__VIEWSTATE") > -1) {
                  if (fieldname == myviewstatefield) {
                    fieldname = "__VIEWSTATE";
                  }
                  else {
                    takeme = false;
                  }
                }
                if (takeme) {
                  if (i > 0) {
                    params = params + "&";
                  }
                  if (UseEncodeURI) {
                    params = params + fieldname + "=" + encodeURI(element.value).replace(/\+/g, "%2b");
                  }
                  else {
                    params = params + fieldname + "=" + escape(element.value).replace(/\+/g, "%2b");
                  }
                }
              }
            }
          }
        }
        window["xmlhttp" + ClientID].setRequestHeader("Content-length", params.length);
        if (CloseConnection) {
          window["xmlhttp" + ClientID].setRequestHeader("Connection", "close");
        }
        if (window["xmlhttp" + ClientID].sendAsBinary) {
          window["xmlhttp" + ClientID].sendAsBinary(params);
        }
        else {
          window["xmlhttp" + ClientID].send(params);
        }
      }
      else //get
      {
        window["xmlhttp" + ClientID].send(null);
      }
    }
    else {
      window["xmlhttp" + ClientID].send(null);
    }
  }
  else if (window.ActiveXObject) {
    if (window["xmlhttp" + ClientID]) {
      window["xmlhttp" + ClientID].onreadystatechange = function() {
        if (window["xmlhttp" + ClientID].readyState == 4) {
          if (AjaxRedirUrl.length > 0) {
            window.clearTimeout(timeoutId);
          }
          if (doSetCursor) {
            resetCursor(Form);
          }
          if (window["xmlhttp" + ClientID].status == 200) {
            eval(scriptcallback);
          }
          else {
            if (window["xmlhttp" + ClientID].status != 0) //abort
            {
              if (!HideAlert) {
                if (AlertText == null || AlertText.Length == 0) {
                  alert("Fehler beim Laden der Daten:" + window["xmlhttp" + ClientID].statusText + " (" + window["xmlhttp" + ClientID].status + ")");
                }
                else {
                  alert(AlertText);
                }
              }
              if (ErrorScript && ErrorScript.length > 0) {
                eval(ErrorScript);
              }
            }
          }
        }
      }
      if (UsePost) {
        window["xmlhttp" + ClientID].open("POST", url + p, true);
        window["xmlhttp" + ClientID].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      }
      else {
        window["xmlhttp" + ClientID].open("GET", url + p, true);
      }
      if (doSetCursor) {
        setWaitCursor(Form);
      }
      if (UsePost) {
        target = document.getElementById(VirtualFormElement);
        params = "";
        if (target) {
          for (i = 0; i < document.forms[Form].elements.length; i++) {
            element = document.forms[Form].elements[i];
            if (isChild(element, target) || (element.value != null && (element.name.indexOf("CacheStore") > -1 || element.name.indexOf("actionField") > -1 || element.name.indexOf("idField") > -1 || element.name.indexOf("targetField") > -1 || element.name.indexOf("virtualForm") > -1 || element.name.indexOf(myviewstatefield) > -1))) {
              if (element.type == 'checkbox' || element.type == 'radio') {
                if (element.checked == true) {
                  if (i > 0) { params = params + "&"; }
                  params = params + element.name + "=" + element.value;
                }
              }
              else if (element.value != null) {
                var fieldname = element.name;
                var takeme = true;
                if (fieldname.indexOf("__VIEWSTATE") > -1) {
                  if (fieldname == myviewstatefield) {
                    fieldname = "__VIEWSTATE";
                  }
                  else {
                    takeme = false;
                  }
                }
                if (takeme) {
                  if (i > 0) {
                    params = params + "&";
                  }
                  if (UseEncodeURI) {
                    params = params + fieldname + "=" + encodeURI(element.value).replace(/\+/g, "%2b");
                  }
                  else {
                    params = params + fieldname + "=" + escape(element.value).replace(/\+/g, "%2b");
                  }
                }
              }
            }
          }
        }
        window["xmlhttp" + ClientID].setRequestHeader("Content-length", params.length);
        if (CloseConnection) {
          window["xmlhttp" + ClientID].setRequestHeader("Connection", "close");
        }
        if (window["xmlhttp" + ClientID].sendAsBinary) {
          window["xmlhttp" + ClientID].sendAsBinary(params);
        }
        else {
          window["xmlhttp" + ClientID].send(params);
        }
      }
      else {
        window["xmlhttp" + ClientID].send();
      }
    }
  }
}

function GetQueryString(param) {
  if (!window.location.search) {
    return null;
  }
  else {
    start = window.location.search.indexOf("?" + param);
    if (start < 0) {
      start = window.location.search.indexOf("&" + param);
    }
    if (start < 0) {
      return null;
    }
    start = start.param.length;
    end = window.location.search.length;
    if (window.location.search.indexOf("&", start) > 0) {
      end = window.location.search.indexOf("&", start);
    }

    return window.location.search.substring(start, end);
  }
}

function isChild(element, target) {
  if (element.parentNode == target) {
    return true;
  }
  else {
    if (element.parentNode) {
      return isChild(element.parentNode, target);
    }
  }

  return false;
}

function callbackAjaxV2(result, ClientID, Target, ExecuteJScript, JSPostProcessing) {
  targets = Target.split('|');
  for (i = 0; i < targets.length; i++) {
      try
      {
        eval (targets[i]  + '= result');
      }
      catch(e){}
    try {
        eval("myCallback" + ClientID + "(" + targets[i] + ")");
    }
    catch (e) { }
  }

  if (ExecuteJScript) {
    extractScripts(result);
  }

  eval(JSPostProcessing);
}


function extractScripts(htmltext) {
  var FunctionFragment = "function([\\S\\s]*?)\\)";
  var ScriptFragment = '<script[^>]*>([\\S\\s]*?)<\/script>';
  var matchAll = new RegExp(ScriptFragment, 'img');
  var matchOne = new RegExp(ScriptFragment, 'im');

  var tempmatch = '';

  var matches = htmltext.match(matchAll) || [];

  if (matches) {
    for (var i = matches.length - 1; i >= 0; i--) {
      tempmatch = matches[i];
      tempmatch = tempmatch.match(matchOne)[1];

      var head = document.getElementsByTagName("head")[0] || document.documentElement,
              script = document.createElement("script");

      script.type = "text/javascript";
      script.text = tempmatch;
      head.appendChild(script);
      head.removeChild(script);
    }
  }
}

function ajaxCallAjaxV2(params, AutoRefresh, WaitImageUrl, Target, meineUrl, CallbackJS, SetCursor, ClientID, CancelOnNewRequest, UseEncodeURI, AddRandomParam, AjaxRedirUrl, AjaxConnectionTimeout, Form, scriptcallback, HideAlert, AlertText, ErrorScript, UsePost, VirtualFormElement, CloseConnection, myviewstatefield) {
  if (WaitImageUrl && WaitImageUrl.length > 0 && Target && Target.length > 0) {
    eval(Target + " = \"<div style='width: 100%; text-align: center;'><img src='" + WaitImageUrl + "' alt='' /></div>\"");
  }

  loadXMLDocV2(meineUrl, CallbackJS, SetCursor, params, ClientID, CancelOnNewRequest, UseEncodeURI, AddRandomParam, AjaxRedirUrl, AjaxConnectionTimeout, Form, scriptcallback, HideAlert, AlertText, ErrorScript, UsePost, VirtualFormElement, CloseConnection, myviewstatefield);
  if (AutoRefresh != 0) {
    window.setTimeout(ajaxCallAjaxV2(params, AutoRefresh, WaitImageUrl, Target, meineUrl, CallbackJS, SetCursor, ClientID, CancelOnNewRequest, UseEncodeURI, AddRandomParam, AjaxRedirUrl, AjaxConnectionTimeout, Form, scriptcallback, HideAlert, AlertText, ErrorScript, UsePost, VirtualFormElement, CloseConnection, myviewstatefield), AutoRefresh);
  }
}

/* contentreader*/

function getContentV2(ClientID, url, AlertText, AdditionalHtmlFilter, parseStart, parseEnd, RemoveFormTag, RemoveLeadingSlashInLinks, ExcludeFromRemoveSlash, ReplaceSlashWith, Callback, ExecuteJScript)
{
  
    var xmlHttp = null;
	  if (window.XMLHttpRequest)
	  {
      if (typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
      }
    }
    
    if (!xmlHttp) {
      try {
        xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
      } catch(e) {
        try {
          xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
          xmlHttp = null;
        }
      }
    }
    
    if (xmlHttp) 
    {
      xmlHttp.open('GET', url, true);
      xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) 
      {
        if (xmlHttp.status==200)
        {
          processContentV2(xmlHttp.responseText, ClientID, AdditionalHtmlFilter, parseStart, parseEnd, RemoveFormTag, RemoveLeadingSlashInLinks, ExcludeFromRemoveSlash, ReplaceSlashWith, Callback, ExecuteJScript)
        }
        else
        {
          if (xmlHttp.status!=0) //abort
          {
            if (!AlertText || AlertText.length == 0)
            {
            }
            else
            {
              alert(AlertText);
            }
          }
        }
      }
    }
    xmlHttp.send(null);
  }
}

function processContentV2(html, ClientID, AdditionalHtmlFilter, parseStart, parseEnd, RemoveFormTag, RemoveLeadingSlashInLinks, ExcludeFromRemoveSlash, ReplaceSlashWith, Callback, ExecuteJScript)
{
  if (AdditionalHtmlFilter && AdditionalHtmlFilter.length > 0)
  {
    html = eval(AdditionalHtmlFilter + "(html)");
  }
  foundparsestart = html.indexOf(parseStart);
  if(foundparsestart > 0)
  {
    start = html.indexOf(parseStart) + parseStart.length;
    end = html.indexOf(parseEnd);
    html = html.substring(start, end);
    if (RemoveFormTag)
    {
      html = html.replace(/(<f[o]rm([^>]+)>)/i, '');
      html = html.replace(/name="__VIEWSTATE"/g, 'name="' + ClientID + '__VIEWSTATE"');
      html = html.replace(/id="__VIEWSTATE"/g, 'id="' + ClientID + '__VIEWSTATE"');
      html = html.replace('<' + '/' + 'for' + 'm>', '');
    }
    if (RemoveLeadingSlashInLinks)
    {
      var excludesStr = ExcludeFromRemoveSlash;
      var excludes = excludesStr.split(""|"");
      var doExclude = false;

      for(i=0; i < excludes.length; i++)
      {
        if (html.indexOf(excludes[i]) != -1)
        {
          doExclude = true;
        }
      }

      if (!doExclude)
      {
        html = html.replace(/(href=""\/)/g, 'href=""' + ReplaceSlashWith);
      }
    }
  }
  else
  {
    html = '';
  }
  
  if (document.getElementById(ClientID) != null)
  {
    document.getElementById(ClientID).innerHTML = html;
  }
  if (ExecuteJScript)
  {
    extractScripts(html);
  }

  if (Callback && Callback.length > 0)
  {
    eval (Callback + "(html)");
  }
  try
  {
    eval ("myCallback" + ClientID + "()");
  }
  catch(e){}
}

function showCustomFooter(gridId)
{
  if (isdefined(gridId))
  {
    var grid = window[gridId]; 

    var Page = "Seite";
    var of = "von";
    var items = "Zeilen";

    var pagerSpan = 5; // should be at least 2
    var First = "Erste";
    var Last = "Letzte";
    var cssClass = "GridFooterText";

    var footer = buildPagerNavi(grid);
    document.getElementById(gridId + "pager").innerHTML = "<div style='white-space:nowrap;display:inline;' class=' + cssClass + '>" + footer + "</div>";
  }
  else
  {
    setTimeout("showCustomFooter(gridId);", timeoutDelay);
  }
}

function setValueOnElement(id, value)
{
  document.getElementById(id).value = value;
}