var win = 0;
var error = '';
var debug = false;
var processData = processNothing;

function processNothing(result) {
}
function onloadFunc() {
}
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function InZahl (Wert)
    {   // Erstellt von Ralf Pfeifer, www.ArsTechnica.de
        var PosPunkt = Wert.indexOf(".",0);
        var PosKomma = Wert.indexOf(",",0);
        if (PosKomma < 0) PosKomma = Wert.length;

        // Dezimalpunkte zur Tausendergruppierung entfernen
        while ((0 <= PosPunkt) && (PosPunkt < PosKomma))
        {
            Wert = Wert.substring(0, PosPunkt) + Wert.substring(PosPunkt + 1, Wert.length);
            PosPunkt = Wert.indexOf(".",0);
            PosKomma--;
        }

        // Enthaelt die Variable 'Wert' ein Komma ?
        PosKomma = Wert.indexOf(",",0);
        if (PosKomma >= 0)
           { Wert = Wert.substring(0, PosKomma) + "." + Wert.substring(PosKomma + 1, Wert.length); }

        //return parseFloat(Wert);
        return(Wert);
}

function IsNum(n) {
  return isFinite(InZahl(n));
}


	function EMail(s)
  {
  var a = false;
  var res = false;
  if(typeof(RegExp) == 'function')
    {
    var b = new RegExp('abc');
    if(b.test('abc') == true){a = true;}
    }

  if(a == true)
    {
    reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                     '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                     '(\\.)([a-zA-Z]{2,4})$');
    res = (reg.test(s));
    }
  else
    {
    res = (s.search('@') >= 1 &&
           s.lastIndexOf('.') > s.search('@') &&
           s.lastIndexOf('.') >= s.length-5)
    }
  return(res);
  }

function /*out: String*/ number_format( /* in: float   */ number, 
                                        /* in: integer */ laenge, 
                                        /* in: String  */ sep, 
                                        /* in: String  */ th_sep,
                                                          zero_to_space ) {
	number = number.replace(/,/,'.');
	if (! IsNum(number) || number == '') {
		return '';
	}
	else if (zero_to_space && parseFloat(number) == 0) {
		return '';
	}
	else {
		number = parseFloat(number);
    number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
    str_number = number+"";
    arr_int = str_number.split(".");
    if(!arr_int[0]) arr_int[0] = "0";
    if(!arr_int[1]) arr_int[1] = "";
    if(arr_int[1].length < laenge){
      nachkomma = arr_int[1];
      for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
      arr_int[1] = nachkomma;
    }
    if(th_sep != "" && arr_int[0].length > 3){
      Begriff = arr_int[0];
      arr_int[0] = "";
      for(j = 3; j < Begriff.length ; j+=3){
        Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
        arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
      }
      str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
      arr_int[0] = str_first + arr_int[0];
    }
    return arr_int[0]+sep+arr_int[1];
  }
}

  function IsDatum(dat) {
  	var d = dat.value;
  	if (d.length == 6 && parseFloat(d) > 010100) {
  		d = d.substr(0,2)+'.'+d.substr(2,2)+'.'+d.substr(4,2);
  	}
  	var t=0,m=0,j=0,p;
  	d = Trim(d);
  	p = d.lastIndexOf('.');
  	if (p > -1) {
  		j = parseFloat(d.substr(p+1,100));
  		d = d.substr(0,p);
    	p = d.lastIndexOf('.');
    	if (p > -1) {
    		m = parseFloat(d.substr(p+1,100));
  	  	d = d.substr(0,p);
    		t = parseFloat(d);
      }
      else {
    		m = parseFloat(d);
  	  }
  	}  
  	else if (d != '') {
  		j = parseFloat(d);
  	}
  	if (j < 20) {
  		j += 2000;
  	}
  	if (j < 100) {
  		j += 1900;
  	}
    if (t > 0 && t < 32 && m > 0 && m < 13 && j > 0 && j < 10000) {
    	tag = '00'+t;
    	monat = '00'+m;
    	dat.value = tag.substr(tag.length-2,2)+'.'+monat.substr(monat.length-2,2)+'.'+j;
    	return true;
    }
    else {
    	if (dat.value != '') {
    		alert('Datum falsch');
    		dat.value = '';
    	}
    	return false;
    }
  }
  
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function iFrameScrollIntoView() {
  compare = window.location.protocol+'//'+window.location.hostname;
  l = compare.length;
  if (document.referrer.substr(0,l) == compare) {
		document.getElementsByTagName('*')[0].scrollIntoView(true);
	}
}

function in_array(item,arr) {
	for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
	return false;
}

function El(st) {
	return document.getElementById(st);
}

function radioWert(rObj) {
    for (var i=0; i<rObj.length; i++) if (rObj[i].checked) return rObj[i].value;
    return false;
}

function is_array(variable) {
  return typeof(variable) == "object" && (variable instanceof Array);
}

function showWait(id) {
	document.getElementById(id).innerHTML = 'x<img alt="Bitte warten" src="/images/spin_32.gif" />';
}

function doPrint() {
	win = window.open('/drucken.html');
}

function DelCookie(sName) {
  document.cookie = sName + "=''";
  // Expires the cookie in one month
  var date = new Date();
  date.setMonth(date.getMonth()-1);
  document.cookie += ("; expires=" + date.toUTCString() + ";path=/"); 
}

	function openAbschnitt(id) {
		if (! (typeof Effect === 'undefined')) {
			if (El(id+'_head').className == 'abschnitt_head_close') {
				El(id+'_head').className = 'abschnitt_head_open';
				Effect.BlindDown(id+'_container', { duration: 0.5 });
			}
		}
		else {
			El(id+'_container').style.display = 'block';
			El(id+'_head').className = 'abschnitt_head_open';
		}
	}
	function closeAbschnitt(id) {
		El(id+'_container').style.display = 'none';
		El(id+'_head').className = 'abschnitt_head_close';
	}
	function swapAbschnitt(id) {
		if (El(id+'_head').className.indexOf('abschnitt_head_close') > -1 ) {
			El(id+'_head').className = El(id+'_head').className.replace(/abschnitt_head_close/, 'abschnitt_head_open');
		}
		else {
			El(id+'_head').className = El(id+'_head').className.replace(/abschnitt_head_open/, 'abschnitt_head_close');
		}
		if (! (typeof Effect === 'undefined')) {
			Effect.toggle(id+'_container', 'blind', { duration: 0.5 });
		}
		else {
			if (El(id+'_container').style.display == 'block') {
				closeAbschnitt(id);
			}
			else {
				openAbschnitt(id);
			}
		}
	}

	function gohome(myhome){
		if (myhome == null) {
			window.location.href='/';
		}
		else {
			window.location.href=myhome;
		}
	}

function checkCookie() {
	document.cookie="OK";
	alert(document.cookie);
	if(document.cookie!="") {
		alert('Cookies aktiviert');
	}
	else {
		alert('Cookies deaktiviert');
	}
}

            function doRequestX(url1, params, process) {
              	var methode;
              	var Xhttp_request;
         		   	if (params == '') { 
         		   		 methode = 'GET';
         		   		 params = null; 
         		   	}
                else { 
                	methode = 'POST'; 
                }

                Xhttp_request = false;
                

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    Xhttp_request = new XMLHttpRequest();
                    if (Xhttp_request.overrideMimeType) {
                        Xhttp_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        Xhttp_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        Xhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }

                if (! Xhttp_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return false;
                }

                Xhttp_request.onreadystatechange=function()
{
                if (Xhttp_request.readyState == 4) {
                    if (Xhttp_request.status == 200) {
                        process(Xhttp_request.responseText);
                    } else {
                        //alert('There was a problem with the request.');
                    }
                }

}

                Xhttp_request.open(methode, url1, true);
                if (methode == 'POST') {
                	Xhttp_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                }
								//document.body.style.cursor='wait';
                Xhttp_request.send(params);

            }

	function evaluate(result) {
		//alert(result);
		error = '';
		debugtext = '';
  	pairs = result.split('<!&!>');
  	for(i=0; i<pairs.length; i++) {
	  	parts = pairs[i].split('<!=!>');
	  	if (parts.length == 2) {
		  	if (debug) {
		  		alert(parts[0]+':'+parts[1]);
	  		}
	  		if (parts[1].substr(0,1) == "'") {
					eval(parts[0]+'=unescape(' + parts[1] + ')');
				}
				else {
					if (parts[1] != '') {
						eval(parts[0]+'='+parts[1]);
					}
					else {
						eval(parts[0]+'=""');
					}
				}
			}
  	}
  	if (debugtext != '' && document.getElementById('debugdiv')) {
  		//alert('debug');
  		document.getElementById('debugdiv').style.display = 'block';
			document.getElementById('debugdiv').innerHTML = "<a href='javascript:closeDebug()'>close</a><p>"+debugtext;
  	}
	}	


