//--- ACHTUNG! Der Event "document.onLoad" wird im Bereich "menue.js" definiert.


//***********************************************************
//*** JAVACRIPT BEFEHLSERWEITERUNGEN***
//***********************************************************


//-------- AJAX

function createXMLHttpRequest() 
{
 var req = null;

   try 
   {
     req = new ActiveXObject("MSXML2.XMLHTTP");
   }  

   catch (err_MSXML2) {

     try
     {
       req = new ActiveXObject("Microsoft.XMLHTTP");
     }

     catch (err_Microsoft) {

       if (typeof XMLHttpRequest != "undefined")
         req = new XMLHttpRequest;
     }
   }
   return req;
}



//-------------------------------- Ajax Funktionen

function getCategorys(path, id, kat){ //----------- gibt die Einträge des des Categorypfades als Array zurück 
	if(path=="NULL"){
		exit;
	}

	var url="/php-includes/ajax/getCategorys.php";		
	var obj;	
	
	new Ajax.Request(url, {
		method: "POST",
		encoding: "UTF-8",
		parameters: "path="+escape(path),
		onComplete: function(transport){
			var value=transport.responseText;
			var entrys=value.split("#");
			var l= entrys.length;

			formDeletePopUpEntrys(id)
			for(var i=0; i<l; i++){						//---------- entsprechendes PopUp mit Werten füllen
				var entry=entrys[i].split("*");
				formNewPopUpEntry(id, entry[0], entry[1])

				if(kat>""){
					if(id=="Ausfuehrung"){
						var aktKat=entry[1];
					}else{
						var aktKat=entry[1]+"/";;
					}

					if(kat.indexOf(aktKat)>-1){
						var obj=document.getElementById(id);
						var name=obj.name;

						switch (name){
							case "Systeme":
								var nexPopUp="Programme";
								break;
							case "Programme":
								var nexPopUp="Ausfuehrung";
								break;
						}

						obj.selectedIndex=i+1;

						getCategorys(entry[1], nexPopUp, kat);

					}
				}	
			}
		} 
	}); 
}



//--------------------------


function formNewPopUpEntry(id, name, value ) //---- Erzeugt einen neuen Eintrag im PopUp mit der ID "id"
{
	var newEntry = new Option(name, value, false, false);
	var obj=document.getElementById(id);
	var pos=obj.length;
	obj[pos]=newEntry;	
}

function formDeletePopUpEntrys(id){//----------- löscht alle Einträge des PopUp mit der ID 2id" bis auf den Ersten  
	var obj=document.getElementById(id);
	obj.length=1;
	 obj.selectedIndex=0;

	//showOkButton(); //--------- Die Funktion befindet sich direkt in der Seite mit der Auswahl

}

//-------------------

function switchVisibility(obj){
	obj=document.getElementById(obj);
	if(obj.style.display=="none" || obj.style.display==""){
  		obj.style.display="block"
	}else{
 		obj.style.display="none"
	}
}


function switchArrow(id){

  var obj=document.getElementById(id);

//alert(obj.src);

	if(obj.src.indexOf("/close.gif")>0){
  		obj.src="/images/symbols/open.gif";
	}else{
  		obj.src="/images/symbols/close.gif";
	}
}

//-------- Variable testen

//--- Erwartet als Parameter den Namen der Variable in einem String.

isDefined = function(variable){ 
	return this[variable] === undefined ? false : true;
};


//----------- String

function strReplace(strsearch, strreplace, haystack)
{
	// Autor : Thomas B?chler
	// Erstellt : 13.04.2004
	// Beschreibung : Ersetzt alle strsearch innerhalb haystack durch strreplace

	if ((haystack == null) || (strsearch == null))
	{
		return null;
	}
   	
   	if ((haystack.length == 0) || (strsearch.length == 0))
   	{
   		return haystack;
   	}

    if ((strreplace == null) || (strreplace.length == 0))
    { 
    	strreplace = "";
    }

    var len_strsearch = strsearch.length;
    var len_strreplace = strreplace.length;
    var Pos = haystack.indexOf(strsearch, 0);

    while (Pos >= 0)
    {
    	haystack = haystack.substring(0, Pos) + strreplace + haystack.substring(Pos + len_strsearch);
    	Pos = haystack.indexOf(strsearch, Pos + len_strreplace);
    }
    
    return haystack;
}

//------------------------------------- Druckversion -----------------------------------


function showPrintVersion(idName)
{
	// Autor : Thomas BÃ¼chler
	// Erstellt : 01.10.2004
	// GeÃ¤ndert: 11.08.06 - Andreas JÃ¤hrling - Neuer Aufbau der Seite
	// Kommentar : ACHTUNG Version ohne Headline-Filterung
	

	var textzelle = document.getElementById(idName);
	var text = textzelle.innerHTML;
	
	///////////////////// Links filtern		
	while (text.indexOf("href=\"") != -1)
	{
		var part0 = text.substr(text.indexOf("href=\"")+6,text.length);
		var part1 = part0.substr(0,part0.indexOf("\""));	
		
		part1 = "href=\""+part1+"\"";
		var newLnk = "";
		text = strReplace(part1, newLnk, text);
	}
	///////////////////// Links filtern
		
	
	if(xt.length > 0)
	{
		text = strReplace("&lt;&lt; zurück", "", text);
		
		neues_fenster = window.open('', "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=550,screenX=10,screenY=10,top=10,left=10");
		neues_fenster.document.open();
		
		var content ="<div id='button'><a href='javascript:self.print();'>"+notationPrintWindow_+"</a> <a href='javascript:self.close();'>"+notationCloseWindow_+"</a></div>";

			content="<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
			content=content+"<html>";
				content=content+"<head>";
					content=content+"<meta http-equiv='content-type' content=content+'text/html;charset=utf-8'>";
					content=content+"<title>Printversion</title>";
					content=content+"<link href='/css/printversion.css' type='text/css' rel='stylesheet' media='all'>";
				content=content+"</head>";
	
				content=content+"<body bgcolor='#ffffff'>";
					content=content+"<div id='content'>";
					content=content+"<p><img id='logo' src='/images/ebene2/printlogo.gif' alt='' border='0'></p>";
						content=content+"<div id='button'><a href='javascript:self.print();'>"+notationPrintWindow_+"</a> <a href='javascript:self.close();'>"+notationCloseWindow_+"</a></div>";
						content=content+"<div id='dynamicContent'>"+text+"</div>";
						content=content+"<div id='clear'></div>";
						content=content+"<p><b>"+notationCusCompany_+"</b><br>"+ notationCusStreet_+"</p>";
						content=content+"<p>"+ notationCusZip_+" "+notationCusCity_+"</p>";
						content=content+"<div class='phone'>"+notationPhone_+"</div><div class='number'>"+notationCusPhoneNumber_+"</div>";
						content=content+"<div class='phone'>"+notationFax_+"</div><div class='number'>"+notationCusFaxNumber_+"</div>";
					content=content+"</div>";
				content=content+"</body>";
			content=content+"</html>";

		with(neues_fenster.document)
		{
			writeln(content);
		}

		neues_fenster.document.close();
		neues_fenster.focus();
	}
}


//------------------------------------------------ Cookies --------------------------------------

function setCookie(name, wert, domain, expires, path, secure){
	if(path==""){path="/";}
	
   //var cook = name + "=" + unescape(wert);
   var cook = name + "=" + escape(wert);
   cook += (domain) ? "; domain="+ domain : "";
   cook += (expires) ? "; expires="+expires : "";
   cook += (path) ? "; path="+path : "";
   cook += (secure) ? "; secure" : "";
   document.cookie = cook;

}



function eraseCookie(name, domain, path){
	if(path==""){path="/";}
   var cook="name=; expires=Thu, 01-Jan-70 00:00:01 GMT"
   cook += (domain) ? "domain="+domain : ""
   cook += (path) ? "path="+path : ""
   document.cookie = cook
}


function getCookie(name){
   var i=0  //Suchposition im Cookie
   var suche = name+"="
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length)
         ende = (ende>-1) ? ende : document.cookie.length
         var cook = document.cookie.substring(i+suche.length, ende)
         return unescape(cook)
      }
      i++
   }
   return ""
}


function checkCookie(){
   setCookie("CookieTest", "OK")
   if (!getCookie("CookieTest"))
      return false
   else{
      eraseCookie("CookieTest")
      return true
   }
}





