//<!--
	function isset( variabletocheck)
  {
  	// Synonym zu PHP's isset, jede Variable mit Wert hat den Typ gespeichert, zBsp. number, string, etc.
  	// undefined, wenn die Variable keinen Wert hat, den "" ist ja auch ein string-Wert
  	if( typeof variabletocheck == "undefined")
  		return false;
  	else
  		return true;	
  }
  
	function takeOverDate( day, month, year, fieldname, formname)
	{
		date = day + '.' + month + '.' + year;
		eval('window.opener.document.forms.' + formname + '.' + fieldname + '.value="' + date + '";');
		window.close();
	}
  
	function takeOverWeek( week, year, fieldname, formname)
	{
		date = week + '-' + year;
		eval('window.opener.document.forms.' + formname + '.' + fieldname + '.value="' + date + '";');
		window.close();
	}

	function changeTwoFrames( frame1, url1, frame2, url2)
	{
		frame1 = eval('parent.' + frame1);
		frame2 = eval('parent.' + frame2);

		frame1.location.href = url1;
		frame2.location.href = url2;
	}

	function runden( x)
  {
    return Math.round(100*x)/100;
  }

  function openWindow(title, url, width, height, scrollbars)
  {
    if( !isset( height))
    {
	  	if(screen.availHeight>768)  height = 768;
	    else                        height = screen.availHeight;
	    
	    height-=60;
    }
    
    if( !isset( width))
    {
    	if(screen.availWidth>1024)  width = 1024;
    	else                        width = screen.availWidth;
    	
    	width-=30;
    }	

    if( !isset( scrollbars))
    {
    	scrollbars = true;
    }
    
    openWindowCentered( title, url, width, height, scrollbars);
  }

  function openBuchungsWindow(title, url)
  {
    height = 455;
    width = 750;
    openWindowCentered( title, url, width, height, true);
  }

  function openColorTable(title, url)
  {
    height = 150;
    width = 150;
    openWindowCentered( title, url, width, height);
  }

  function openProtokollWindow(title, url)
  {
    height = 430;
    width = 550;
    openWindowCentered( title, url, width, height);
  }

  function openFremdkostenWindow(title, url)
  {
    height = 500;
    width = 500;
    openWindowCentered( title, url, width, height, true);
  }

  function openToDoWindow(title, url)
  {
    height = 650;
    width = 700;
    openWindowCentered( title, url, width, height, true);
  }

  function openCalendarWindow(title, url)
  {
  	height = 650;
    width = 600;
    openWindowCentered( title, url, width, height, true);
  }

  function openRessourcesAllocationWindow(title, url)
  {
    height = 650;
    width = 550;
    openWindowCentered( title, url, width, height, true);
  }

  function openSmalCalendar(title, url)
  {
  	height = 230;
  	width = 178;
    openWindowCentered( title, url, width, height, false);
  }

  function openWindowCentered( title, url, width, height, scrollbars)
  {
  	x = Math.round((screen.availWidth-width)/2);
    y = Math.round((screen.availHeight-height)/2);

    if( scrollbars)
    	s = "yes";
    else
    	s = "no";

    win = window.open(url, title, 'width='+width+', height='+height+', left='+x+', top='+y+', locationbar=no, menubar=no, resizable=yes, scrollbars='+s);
    win.focus();
  }

  function markAllEntries()
  {
    for(var x=0;x<document.edit.elements.length;x++)
    {
      var y=document.edit.elements[x];
      if(y.name=='id[]') y.checked=document.edit.markall.checked;
    }
  }

  function Delete()
  {
    var counter = 0;
    for(var x=0;x<document.edit.elements.length;x++)
    {
      var y=document.edit.elements[x];
      if(y.name=='id[]' && y.checked) counter++;
    }
    if (counter>0)
    {
      if(confirm('Wollen Sie die ausgewählten Einträge wirklich löschen?'))
      {
        document.edit.action.value='MultipleDelete';
        document.edit.submit();
      }
    }
  }
    
  function sort(orderfield, ascdesc)
  {
    document.pagenavigation.orderfield.value = orderfield;
    document.pagenavigation.ascdesc.value = ascdesc;
    document.pagenavigation.orderby.value = orderfield.replace(/,/g, ' ' + ascdesc + ',') + ' ' + ascdesc;
    document.pagenavigation.submit();
  }

  function turnPage(rsindex)
  {
    document.pagenavigation.liststart.value = rsindex;
    document.pagenavigation.submit();
    return true;
  }

  function convertFromCurrency( val)
  {
    if (!val)
      val = '0';

    val = String( val);
    val = val.replace(/-$/,'');
    val = val.replace(/\./,'');
    val = val.replace(/,/,'.');

    return parseFloat(val);
  }

  function convertFromDecimal( val)
  {
    val = String(val);
    if (val == '')
      val = '0';

    val = String( val);
    val = val.replace(/\./,'');
    val = val.replace(/,/,'.');

    return parseFloat(val);
  }

  function convertFromTime( val)
  {
    if (!val)
      val = '00:00';

    val = String( val);

    a_val = val.split(":");

    if(val.slice(0,1) == '-')	{ sign = "-"; a_val[0] = a_val[0] * -1;	}
    else											{ sign = "";	}

    h_val = parseFloat(Math.floor(a_val[0]));
    m_val = parseFloat(Math.floor(a_val[1]));

    m_val = Math.round(100000*m_val/60)/100000;
    val = h_val + m_val;

    return parseFloat(sign + val);
  }

  function convertToCurrency( val)
  {
    val = String( val);
    cur = '';
    tmp = val.split('.');
    vorkomma = tmp[0];

    if(vorkomma.slice(0,1) != '-' && vorkomma.slice(0,1) != '+')
    {
      vorzeichen = '';
    }

    if(vorkomma.slice(0,1) == '-')
    {
      vorzeichen = '-';
      vorkomma = vorkomma.slice(1);
    }

    if(vorkomma.slice(0,1) == '+')
    {
      vorzeichen = '+';
      vorkomma = vorkomma.slice(1);
    }

    if(tmp.length>1)
    {
      if( tmp[1].length == 1)
      	tmp[1]+="0";		// immer 2. Kommastellen anzeigen
      
    	nachkomma = ',' + tmp[1];
    } 
    else							nachkomma = ',00';

    inv = reverse(vorkomma);
    len = inv.length;
    count = Math.ceil(len/3-1);
    for(i=0; i<=count; i++)
    {
      if(cur == '')	cur = inv.slice(3*i, 3*i+3);
      else					cur = cur + '.' + inv.slice(3*i, 3*i+3);
    }
    cur = reverse(cur);

    cur = vorzeichen + cur + nachkomma;

    return String( cur);
  }

  function convertToDecimal( val)
  {
    val = String( val);
    dec = '';
    tmp = val.split('.');
    vorkomma = tmp[0];

    if(vorkomma.slice(0,1) != '-' && vorkomma.slice(0,1) != '+')
    {
      vorzeichen = '';
    }

    if(vorkomma.slice(0,1) == '-')
    {
      vorzeichen = '-';
      vorkomma = vorkomma.slice(1);
    }

    if(vorkomma.slice(0,1) == '+')
    {
      vorzeichen = '+';
      vorkomma = vorkomma.slice(1);
    }

    if(tmp.length>1)
    {
      if( tmp[1].length == 1)
      	tmp[1]+="0";		// immer 2. Kommastellen anzeigen
      
    	nachkomma = ',' + tmp[1];
    } 
    else							nachkomma = ',00';

    inv = reverse(vorkomma);
    len = inv.length;
    count = Math.ceil(len/3-1);
    for(i=0; i<=count; i++)
    {
      if (dec == '')
        dec = inv.slice(3*i, 3*i+3);
      else
        dec = dec + '.' + inv.slice(3*i, 3*i+3);
    }
    dec = reverse(dec);
    dec = vorzeichen + dec + nachkomma;

    return String( dec);
  }

  function convertToTime( val)
  {
    if (!val)
      val = '0';

    val = String( val);

    a_val = val.split(".");

    if(val < 0)	{ sign = "-"; a_val[0] = a_val[0] * -1;	}
    else				{ sign = "";	}

    h_val = String(parseInt(a_val[0]));

    if (a_val.length>1)
      m_val = String(parseInt( Math.round( ('0.'+a_val[1])*60)));
    else
      m_val = '00';

    if(h_val.length<2) {h_val = "0"+h_val;}
    if(m_val.length<2) {m_val = "0"+m_val;}

    val = sign + h_val + ':' + m_val;
    return val;
  }

  function reverse( value)
  {
    value = String(value);
    inv = '';
    len = value.length;

    for(i=0; i<len; i++)
    {
      inv = inv + value.slice(len-i-1, len-i);
    }
    return inv;
  }

  function initNavi()
  /*
  MD 26.02.2003
  ruft für das a-element mit id="init" die funktion naviMark()
  */
  {
    element = document.getElementById("init");
    naviMark( element);
  }

  function naviMark( element)
  /*
  MD 26.02.2003
  setzt für alle a-elemente des dokuments class=""
  setzt für das übergebene element class="marked"
  */
  {
    if( element)
    {
      a_link = document.getElementsByTagName("a");
      for( q=0;q<a_link.length;q++)
      {
        a_link[q].className="";
        a_link[q].parentNode.className = "";
      }
      element.className="marked";
      element.parentNode.className="marked";
      if(element.blur()) element.blur();
    }
  }

  function registerToFront(e_trigger, targetid)
  /*
  MD 26.02.2003
  schaltet alle fieldsets mit id != "" unsichtbar
  schaltet fieldset mit id == targetid sichtbar
  markiert den geklickten reiter
  */
  {
    if( e_trigger != "")
    {
//          if(e_trigger.blur()) e_trigger.blur();
      a_trigger = document.getElementsByTagName("a");
      for(q=0;q<a_trigger.length;q++)
      {
        trigger = a_trigger[q].parentNode;
        if( trigger.className == "active")
        {
          trigger.className = "inactive";
        }
      }
      e_trigger.parentNode.className = "active";
    }

    elements  = document.getElementsByTagName("fieldset");
    for(q=0;q<elements.length;q++)
    {
      e = elements[q];
      if( e.getAttribute("id") != "")
      {
        /*
          nur fieldsets mit id != ""
          werden berücksichtigt
          ==============================
        */
        if(e.getAttribute("id") == targetid)
        {
          /*
            target-element
            sichtbar schalten
            ==============================
          */
          e.style.display = "block";
        } else {
          /*
            andere elemente
            unsichtbar schalten
            ==============================
          */
          e.style.display = "none";
        }
      }
    }
    if(document.edit.currentregister)
      document.edit.currentregister.value = targetid;

    return false;
  }

  function setColor( obj, mode)
  {
    var children  = obj.childNodes;
    switch( mode)
    {
      case "in":
        for( q=0;q<children.length;q++)
        {
          children[q].className += " over";
        }
        break;
      case "out":
        for( q=0;q<children.length;q++)
        {
          children[q].className = children[q].className.replace(/ over$/, "");
        }
        break;
    }
  }

  var active_element;
  function markRow( obj)
  {
    var children  = obj.childNodes;
    var regexp  = /\s+over$/;
    if( active_element != null)
    {
      unMarkRow( active_element);
    }
    for( q=0;q<children.length;q++)
    {
      children[q].className += " over";
      active_element  = obj;
    }
  }
  function unMarkRow( obj)
  {
    var children  = obj.childNodes;
    var regexp  = /\s+over$/;
    for( q=0;q<children.length;q++)
    {
      children[q].className = children[q].className.replace(/ over$/, "");
    }
  }
  function changeFrame( framename, href)
  {
    parent.frames[framename].location.href = href;
  }

  var busy=false;
  function snap(e_anchor, mode)
  {
    if( !mode) mode="month";
    e_img = e_anchor.childNodes[0];
    e_div = e_anchor.parentNode;
    e_tr  = e_anchor.parentNode.parentNode.parentNode;
    visible  = (e_div.className=="open") ? "ja" : "nein";
    e_div.className  = ((visible=="ja") ? "closed" : "open");
    e_img.setAttribute("src", ((visible=="ja") ? "../images/icons/calendar/snap_plus.gif" : "../images/icons/calendar/snap_minus.gif"));
    snap_adjustRow( e_tr);
    snap_forceGeckoRedraw();
    return false;
  }

  function snap_forceGeckoRedraw()
  /*
    md 14.07.2003
    gecko-browser rendern die seite nicht neu, wenn ein snap ausgelöst wurde.
    deshalb wird das rendern durch eine größenänderung des fensters angestoßen.
  */
  {
    if(navigator.userAgent.match(/Gecko/))
    {
      top.resizeTo(window.outerWidth+1, window.outerHeight);
      top.resizeTo(window.outerWidth-1, window.outerHeight);
    }
  }

  function snap_adjustRow( e_tr)
  /*
    md 03.07.2003
    überprüft die divs einer row.
    hat mindestens ein div den className "open", dann werden alle "closed"-divs auf "halfopen" geschaltet.
    ist kein "open"-div vorhanden, dann werden alle divs auf "closed" gesetzt
  */
  {
    a_div = snap_getRowChildren(e_tr, "DIV");
    foundopen = false;
    for(q=0;q<a_div.length;q++)
    {
      if( a_div[q].className == "open")
      {
        foundopen = true;
        break;
      }
    }
    for( q=0;q<a_div.length;q++)
    {
      switch( foundopen)
      {
        case true:
          if( a_div[q].className == "closed")
          {
            a_div[q].className  = "halfopen";   //halfopen
          }
          break;
        case false:
          if( a_div[q].className == "halfopen")   // halfopen
          {
            a_div[q].className  = "closed";
          }
          break;
      }
    }
  }

  function snap_getRowChildren( e_tr, e_elementname)
  /*
    md 03.07.2003
    gibt die div-elemente des übergebenen tr-elements in einem array zurück
  */
  {
    a_re  = new Array();
    for(q=0;q<e_tr.childNodes.length;q++)
    {
      if( (e_tr.childNodes[q].nodeType==1) && (e_tr.childNodes[q].tagName=="TD"))
      {
        e_td = e_tr.childNodes[q];
        for(w=0;w<e_td.childNodes.length;w++)
        {
          if( (e_td.childNodes[w].nodeType==1) && (e_td.childNodes[w].tagName==e_elementname))
          {
            if( (e_td.childNodes[w].className=="open") || (e_td.childNodes[w].className=="closed") || (e_td.childNodes[w].className=="halfopen"))
            a_re[a_re.length] = e_td.childNodes[w];   // [MD 08.07.2003] ie5.0 kann kein push()
          }
        }
      }
    }
    return a_re;
  }

  function switchDisplay(id)
  /*
  MD 24.07.2003
  Ein- und Ausblenden von Elementen.
  Übergeben wird eine Element-ID
  */
  {
    if( e=document.getElementById(id))
    {
      display = e.style.display;
      e.style.display = (display=="none") ? "" : "none";
    }
    return false;
  }

  function setTypeTime( e)
  {
  	val = e.value;
  	if(val.indexOf(':') == -1)
    {
      val = convertFromDecimal(val)
      val = convertToTime(val);
      e.value = val;
    }
  }

  function combo_swap(id_text, id_select)
  /*
  MD 09.06.2004
  Blendet den INPUT-Teil und das dazugehörige IMG einer Combobox aus
  und den SELECT-Teil der Combobox ein (oder umgekehrt)
  Erwartet werden id von inputfeld und selectbox, als id des bildes
  wird id_text + 'img' angenommen.
  */
  {
    switchDisplay(id_text);
    switchDisplay(id_text+'img');
    switchDisplay(id_select);
	//document.getElementById(id_select).focus();
	document.getElementById(id_select).selectedIndex = 0;
  }

  function combo_transfer(id_text, id_select)
  /*
  MD 09.06.2004
  Übernimmt den Wert der SELECT-Box in das INPUT-Feld der Combobox.
  Blendet dann den SELECT-Teil und das dazugehörige IMG einer Combobox aus
  und den INPUT-Teil der Combobox ein
  Erwartet werden id von inputfeld und selectbox, als id des bildes
  wird id_text + 'img' angenommen.
  */
  {
    e_select  = document.getElementById(id_select);
	if( e_select.selectedIndex != 0)
	{
	  e_text    = document.getElementById(id_text);
	  e_text.value  = e_select[e_select.selectedIndex].value;
	  combo_swap(id_text, id_select);
	  e_select.selectedIndex = 0;
	}
  }

  function setTypeDecimal( e)
  {
  	val = e.value;
  	if(val.indexOf(':') != -1)
    {
      val = convertFromTime(val)
      val = convertToDecimal(val);
      e.value = val;
    }
  }

  function makeNewsLetterLink()
  {
    link_document = parent.contentframe.content.location.href;            
    //<-- Nur wenn Detailansicht einer Dokumentenverwaltung
    if( link_document.search(/action=/)!=-1 ) 
    {
      link_document = link_document.replace( /document\.php/, "document_show.php");
    }
    // -->
    link_document = link_document.replace( /&userid=\d*/, "");    
    //prompt( 'Link:', link_document );    
    link = encodeURIComponent( link_document );    
    window.open( '../general/shortlinks.php?link=' + link, 'shortlinks', 'width=600,height=140' );
  }

  	function initAjax() {
      ajax = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
        ajax = new XMLHttpRequest();
        if (ajax.overrideMimeType) {
          ajax.overrideMimeType('text/xml');
        }
      } else if (window.ActiveXObject) { // IE
        try {
          ajax = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
        }
      }
      if (!ajax) {
        alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
        return false;
      }
    }

	function getWindowHeight()
	{
		var y;
		if (self.innerHeight) // all except Explorer
		{
		  y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		  // Explorer 6 Strict Mode
		{
		  y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
		  y = document.body.clientHeight;
		}

		return y;
	}

	function getWindowWidth()
	{
		var x;
		if (self.innerHeight) // all except Explorer
		{
		  x = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		  // Explorer 6 Strict Mode
		{
		  x = document.documentElement.clientWidth;
		}
		else if (document.body) // other Explorers
		{
		  x = document.body.clientWidth;
		}

		return x;
	}
//-->