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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(false);
*/


function chkFormularPrintform()  
{
  if (chkFormFields())
  {
	emptyExampleFields();
	return true;
  } 
  else 
  {
	return false;
  }
}

function chkFormFields()
{
  var index = 0;
  var stillobjects = true;
  var sVar = "", sPflicht="", sCon="";

  while (stillobjects == true)
  {
        if ( document.Formular.elements[index] )
        {
          sVar = trim(document.Formular.elements[index].name);
          sCon = trim(document.Formular.elements[index].value);          
          
          sPflicht = sVar.substr(0,5);
          
          if (isExampleValue(index))
          {
						sCon = "";
					}
                    	
					if ( sPflicht.toUpperCase() == "TXTP_" || sPflicht.toUpperCase() == "TXTE_")
					{
						if ( sCon == "" )
						{         		
							alert ("Bitte füllen Sie das Feld " + getFieldName(index) + " aus.");
							return false;
						}
					}
          	
          if ( sPflicht.toUpperCase() == "TXTE_" || sPflicht.toUpperCase() == "TXTM_")
					{
						if ( sCon.length > 1 )
						{
							if (!chkEmail(sCon))
							{
								alert("Bitte geben Sie beim Feld " + getFieldName(index) + " eine gültige E-Mail an.");
								return false;
				 			}      
						
						}
					}     
          
				  if (sPflicht.toUpperCase() == "CHKP_")
				  {
				 		if (document.Formular.elements[index].checked != true)
						{
								alert(document.Formular.elements[index].alt);
								return false;
						}
				  }
          
          index++;   
         
        }
        else
        {
          stillobjects = false;
        }
  }
 
  return true;
}


function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function getFieldName(uIndex)
{	
	if ( document.Formular.elements[uIndex].title != "" )
	{
		return document.Formular.elements[uIndex].title;
	}
  
  if ( document.Formular.elements[uIndex].type != "select-one" ) {
  	if ( document.Formular.elements[uIndex].alt != "")
  	{
  		return document.Formular.elements[uIndex].alt;		
  	}
  }
	
	return (document.Formular.elements[uIndex].name).substr(5, (document.Formular.elements[uIndex].name).length - 5 );		
}


function isExampleValue(uIndex)
{
	var sVar = "", sCon="", sDefault="";
	
	sVar = document.Formular.elements[uIndex].name;
	sCon = document.Formular.elements[uIndex].value;
	sDefault = document.Formular.elements[uIndex].defaultValue;
	
	if (sDefault == sCon)
  {	
		if (sCon.substr(0,5).toUpperCase() == "Z.B. " || sCon.substr(0,3).toUpperCase() == "XXX" || sCon.substr(0,8).toUpperCase() == "TT.MM.JJ")
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	
}



function emptyExampleFields()
{
	// setzt alle nicht pflichtfelder auf leer
	
	var index = 0;
	var stillobjects = true;
	var sVar = "", sCon="", sPflicht="", sDefault="";
	
	while (stillobjects == true)
	{
			if (document.Formular.elements[index])
			{
				sVar = document.Formular.elements[index].name;
				sDefault = document.Formular.elements[index].defaultValue;
        sCon = document.Formular.elements[index].value;
        
        sPflicht = sVar.substr(0,5);
				
				if ( sPflicht.toUpperCase() != "TXTP_" || sPflicht.toUpperCase() != "TXTE_" )
			  {
					if (isExampleValue(index))
					{
						document.Formular.elements[index].value = "";
					}         
		    }
		  	index = index + 1;
		  }
			else
			{
				stillobjects = false;
      }
	}
}



function chkEmail(email)
{
  var goodemail = true;
  var pos1 = 0;
  var part = "";
  var chcode = 0;
  
  // ; und , ersetzten durch " "
  email = email.replace(/;/," ");
  email = email.replace(/,/," ");
  
  // doppelte leerzeichen raus
  while (email.search(/  /) != -1)
  {
    email = email.replace(/  /," ");
  }
  
  // " " durch "," ersetzten
  email = email.replace(/ /,",");
  
  // so jetzt die einzelnen emails in ein array, dann alle auf korrektheit ueberpruefen!
  emailar = email.split(",");
  
  for (var i = 0; i < emailar.length; i++)
  {
    //ein @ zeichen vorhanden? und nicht auch kein einzelnes , also > 0
    pos1 = emailar[i].search(/@/);
    if (pos1 < 1)
    {
      goodemail = false;
      break;
    }
    
    //so jetzt pruefen wir alles vor dem @
    part = emailar[i].substr(0,pos1);
    
    //sind keine komischen sonderzeichen enthalten? wenn ja fehler
    for (var j = 0; j < part.length; j++)
    {
      //ok haben wir hier ein richtiges zeichen??
      chcode = part.charCodeAt(j);
      
      if(!((chcode >= 45 && chcode <= 57) || (chcode >= 64 && chcode <= 90) || (chcode == 95) || (chcode >= 97 && chcode <= 122) || (chcode == 126)))
      {
        goodemail = false;
        break;
      }
    }
    if (!goodemail) break;
    
    //so jetzt alles nach dem @ zeichen pruefen, allerdings ist das hier nen bisschen komplizierter
    part = emailar[i].substr(pos1 + 1);
    //erstes und letztes zeichen duerfen kein "." sein
    if (part.substr(0,1) == "." || part.substr(part.length-1,1) == ".")
    {
      goodemail = false;
      break;
    }
    
    //ist ueberhaupt ein punkt drinne?
    if (part.search(/\./) == -1)
    {
      goodemail= false;
      break;
    }
    
    // so jetzt wie oben auf sonderzeichen pruefen!
    for (var j = 0; j < part.length; j++)
        {
          //ok haben wir hier ein richtiges zeichen??
          chcode = part.charCodeAt(j);
          
          if(!((chcode >= 45 && chcode <= 57) || (chcode >= 64 && chcode <= 90) || (chcode == 95) || (chcode >= 97 && chcode <= 122) || (chcode == 126)))
          {
            goodemail = false;
            break;
          }
        }
    if (!goodemail) break;
    
  }
  return goodemail;
}

function chkFormularPrintformTOnline()  
{
  
  var index = 0;
  var stillobjects = true;
  var sVar = "", sPflicht="";
  
  while (stillobjects == true)
  {
        if (document.Formular.elements[index])
        {
          sVar = document.Formular.elements[index].name;
          sCon = document.Formular.elements[index].value;
          sPflicht = sVar.substr(0,5);

          if ( sPflicht.toUpperCase() == "TXTP_" && sCon.length < 1 )
          {
            alert("Bitte füllen Sie das Feld " + sVar.substr(5, sVar.length - 5) + " aus.");
            return false;
          } 
          else if ( sPflicht.toUpperCase() == "TXTE_")
          {
            //auf email pruefen
            if (!chkEmail(sCon))
            {
              alert("Bitte geben Sie beim Feld " + sVar.substr(5, sVar.length - 5) + " eine gültige E-Mail an.");
              return false;
            }
          }
          else if (sPflicht.toUpperCase() == "TXTP_" ||  sPflicht.toUpperCase() == "TXTE_")
          {
            //jetzt pruefen wir hier auf das z.B.
            if (sCon.substr(0,5).toUpperCase() == "Z.B. ")
            {
              alert("Bitte füllen Sie das Feld " + sVar.substr(5, sVar.length - 5) + " aus.");
              return false;
            }
          }
          else if (sPflicht.toUpperCase() == "CHKP_")
          {
            if (document.Formular.elements[index].checked != true)
						{
								alert(document.Formular.elements[index].alt);
								return false;
						}
          }
          
          index = index + 1;    
        }
        else
        {
          stillobjects = false;
        }
  }
  return true;
}



function ShowHiddenInfo(nr, cnt, root) {

    if (!root) root="";

    if (root.length == 0) root = "self";

    if (eval(root).document.getElementById('hidden' + nr)) {
        if (eval(root).document.getElementById('hidden' + nr).style.display == 'none') {
            eval(root).document.getElementById('hidden' + nr).style.display = '';
        }
        else {
            eval(root).document.getElementById('hidden' + nr).style.display = 'none';
        }
    }

    if (cnt > 0) {
        for (i = 1; i <= cnt; i++) {
            if (i != nr) {
                if (eval(root).document.getElementById('hidden' + i)) eval(root).document.getElementById('hidden' + i).style.display = 'none';
            }
        }
    }

}


function chkform() {
	return chkFormularPrintformTOnline();
}

function confirmURL(pQuestionStr,pURLStr)
{
    if( confirm(pQuestionStr) )
    {
        window.location.href = pURLStr;
        return true;
    }
}


function LimitCharPerLine(sLine, maxLen) {
	/* Anzahl der Zeichen pro Zeile beschränken */

	var nPos = 1;
	var sBreakChars = " .,;:-?!\t";

	var nPos = 0;
	var bFileEnd = false;
	var sChar = ' ';
	var sLineStart = "";
	var sLastLineStart = "";
	var k = 0;
	var bBreakFound = false;
	var j = 0;
	var sRet = "";
	var i = 0;

	while (nPos < sLine.length) {
		i = sLine.substr(nPos).search('\n')
		if (i < 0) {
			i = sLine.substr(nPos).length - 1;
			bFileEnd = true;
		} else {
			bFileEnd = false;
		}
		if (i + 1 > maxLen) {
			
			sLineStart = "";
			k = 0;
			bBreakFound = false;

			/* Zeilenanfang zusammenbauen */
			while (k < 30 && !bBreakFound) {
				sChar = sLine.substr(nPos + k, 1);
				if (sChar == ' ' || sChar == '\t') {
					sLineStart = sLineStart.concat(sChar);
				} else {
					bBreakFound = true;
				}
				++k;
			}

			if (sLastLineStart.length == 0) {
				sLastLineStart = sLineStart;
			} else {
				sLineStart = sLastLineStart + sLineStart;
			}

			/* Umbrechen */
			j = maxLen;
			bBreakFound = false;
			while (j > maxLen - 40 && !bBreakFound) {
				if (sBreakChars.search(sLine.substr(nPos + j, 1)) >= 0) {
					j = j + 1;
					bBreakFound = true;
				} else {
					j = j - 1;
				}
			}
			if (!bBreakFound) {
				j = maxLen;
			}
			
			/* String zusammensetzen */
			sRet = sRet.concat(sLine.substr(nPos, j) + "\n" + sLineStart);
			nPos = nPos + j;
		} else {
			sLastLineStart = "";
			if (bFileEnd) {
				sRet = sRet.concat(sLine.substr(nPos));
			} else {
				sRet = sRet.concat(sLine.substr(nPos, i + 1));
			}
			nPos = nPos + i + 1;
		}
	}
	return sRet;
}

/* von ANG */
function checkFrame() {
      if(top.location != self.location) {
         if(navigator.appName == "Microsoft Internet Explorer") {
            if(document.getElementById('tabzentr')) {
               document.getElementById('tabzentr').style.width = "100%";
               document.getElementById('tabzentr').style.paddingRight = "0px";
            }
            document.getElementById('bdy_id').style.backgroundImage = "none";
            document.getElementById('bdy_id').style.marginLeft = "0px";
         }
         else {
            if(document.getElementById('tabzentr')) {
               document.getElementById('tabzentr').style.maxWidth = "100%";
               document.getElementById('tabzentr').style.paddingRight = "0px";
               document.getElementById('tabzentr').style.width = "100%";
            }
            /**/
            document.getElementById('bdy_id').style.maxWidth = "100%";
            document.getElementById('bdy_id').style.marginLeft = "0px";
            document.getElementById('bdy_id').style.backgroundImage = "none";
            
         }
      }
}


function checkFrame_newStyle() {
   if(top.location != self.location) {
      document.getElementById('bdy_id').style.margin = "0px";
      document.getElementById('bdy_id').style.width = "100%";
      document.getElementById('bdy_id').style.backgroundImage = "none";
      document.getElementById('main_div').style.width = "100%";
      document.getElementById('main_div').style.margin = "0px";
      document.getElementById('header_div').style.width = "100%";
      document.getElementById('header_div').style.marginRight = "0px";
      document.getElementById('content_div').style.width = "99%";
      document.getElementById('content_div').style.marginRight = "0px";
      document.getElementById('content_div').style.marginLeft = "10px";
      if(document.getElementById('left100_div')) {
         document.getElementById('left100_div').style.width = "100%";
      }
      document.getElementById('breadcrumbs_div').style.width = "100%";
      document.getElementById('footer_div').style.width = "100%";
      document.getElementById('footer_div').style.marginRight = "0px";
      document.getElementById('footer_div').style.marginLeft = "0px";
   }
}


function chkDate(dateDat)
{
	//DATE?
	if (!dateDat) return false;
	dateDat = dateDat.toString();
	
	//SPLIT DATE (DD.MM.YYYY or DD.MM.YY) = 3
	dateDat = dateDat.split(".");
	if (dateDat.length != 3) 
		return false;
	
	//DELETE "LEADING ZERO"(01 = 1, 02 = 2, ...); MONTH = MONTH - 1
	dateDat[0] = parseInt(dateDat[0], 10);
	dateDat[1] = parseInt(dateDat[1], 10) - 1;
	
	//CHECK YEAR LENGTH (YY | YYYY)
	if ((dateDat[2].length != 2) && (dateDat[2].length != 4))
		return false;
	
	//IF YEAR-FORMAT = YY --> 20 + YY
	if (dateDat[2].length == 2) 
		dateDat[2] = "20" + dateDat[2];
	
	//CREATE NEW DATE-OBJECT
	var checkDat = new Date(dateDat[2],dateDat[1],dateDat[0]);
	//COMPARE THE TWO DATES
	if (checkDat.getDate() == dateDat[0] && checkDat.getMonth() == dateDat[1] && checkDat.getFullYear() == dateDat[2])
		return true; 
	else 
		return false;
}		

function twitterlink() {
  var link = document.title;
  link = link.replace("GULP - Knowledge Base:","GULP:");
  window.open('http://twitter.com/home?status=' + link + ' ' + document.URL); 
}
