
	var req = null;
 	var result=""; 
 	var httpHost = "http://"+window.location.hostname+"/";
 	
 	var httpBase="home/";
 	var httpPath=httpHost+httpBase;
 	var timerAnim="none"
 	var gbl_FCKID="-1";
 	var lurl ="";
 	var picOverName="";
 	
 	function checkTimerAnim()
 	{
 		if (timerAnim!="") 
 		{
			var gear = document.getElementById("gear"); 
		 	if ( gear ) gear.style.display = timerAnim;
		 	timerAnim="";
 			
 		}
	    window.setTimeout("checkTimerAnim()", 300);
 	}
 	
 	function onLoadStart()
 	{
		timerAnim = "block";
 		return true;
 	}
 	
 	function onLoadReady()
 	{
		timerAnim = "none";
 		return true;
 	}
 	
 	
	
	 function checkName(varName,input, response)
	 {
	   if (response != '')
	   {
	     // Response mode
	     message   = document.getElementById('nameCheckFailed');
	     messageOk   = document.getElementById('nameCheckOk');
	     if (response == '1')
	     {
	       message.className = 'error';
	       messageOk.className = 'hidden';
	     }else
	     {
	       message.className = 'hidden';
	       messageOk.className = 'ok';
	     } 
	   }else
	   {
	     // Input mode
	     url  = httpPath+"login?"+varName+"="+input;
	     loadXMLDoc(url,processReqChange);
	   }
	 }
	
	
	function processReqChange() 
	{
	    // only if req shows "complete"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
		      response  = req.responseXML.documentElement;
		      if (response) 
		      {
			      if (response.getElementsByTagName('method')[0]) 
			      {
				      method    = response.getElementsByTagName('method')[0].firstChild.data;
				   	  result    = response.getElementsByTagName('result')[0].firstChild.data;
			    	  eval(method + '(\"\",\"\", result)');
		    	  } else
		    	  {
			    	  alert("There was a problem in the XML data:\n Retrieve Status" + req.statusText + " Text:"+req.responseText);
		    	  }
	    	  } 
	    	  else 
	    	  {
	    	  	alert("Kein Response erhalten!");
	    	  }
	        } 
	        else 
	        {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText + " Text:"+req.responseText);
	        }
	        onLoadReady();
	    }
	    
	    
	    
	}
	
	 
	function loadXMLDoc(url,recallFunction) 
	{
		onLoadStart();
		var t= new Date();
		url = url + "&time"+t.getTime();
		lurl = url;
	    
	    // branch for native XMLHttpRequest object
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = recallFunction;
	        req.open("POST", url, true);
	        req.send(null);
	    // branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = recallFunction;
	            req.open("POST", url, true);
	            req.send();
	        }
	    }
	}	 
	
	function loadXMLDocParams(url,params,recallFunction) 
	{
		onLoadStart();
		var t= new Date();
//		url = url + "?time"+t.getTime();
		lurl = url;
	    
	    // branch for native XMLHttpRequest object
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = recallFunction;
	        req.open("POST", url, true);
	        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	        req.send(params);
	    // branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	        if (req) {
	            req.onreadystatechange = recallFunction;
	            req.open("POST", url, true);
	            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	            req.send(params);
	        }
	    }
	}	 
	
	function ddListClear(ElementList)
	{
		for (var count = ElementList.options.length-1; count >-1; count--)
		{
			ElementList.options[count] = null;
		}
		
		return true;
	}
	
	function processReqChangeSelect() 
	{
	    // only if req shows "complete"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
		      response  = req.responseXML.documentElement;
		      if (response) 
		      {
			      if (response.getElementsByTagName('count')[0]) 
			      {
			      	source = response.getElementsByTagName('source')[0].firstChild.data
			      	dest   = response.getElementsByTagName('dest')[0].firstChild.data
			      	
			 
			      	
			      	// get the Drow Down List Element
			      	destDDList = document.getElementById(dest);
		      	
			      	// Clear Drop Down List
			      	ddListClear(destDDList);
			      	
			      	// get Count of new Items
			      	count = ("0"+response.getElementsByTagName('count')[0].firstChild.data)*1;
			      	
			      	// Add all Items to Drop Down List
					for (i=0;i<count;i++)
					{
						varname = source+i;
						value = response.getElementsByTagName(varname)[0].firstChild.data;
						optionItem = new Option( value, value,  false, false);
						destDDList.options[destDDList.length] = optionItem;
					}
					destDDList.selectedIndex=0;
					destDDList.onchange();
		    	  } else
		    	  {
			    	  alert("1There was a problem in the XML data:\n Retrieve Status" + req.statusText);
		    	  }
	    	  } 
	    	  else 
	    	  {
	    	  	alert("Kein Response erhalten!");
	    	  }
	        } 
	        else 
	        {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText + " Text:"+req.responseText);
	            
	        }
	        onLoadReady();
	    }
	    
	}
	
	function replaceAll(str, strFind, strReplace)
	 {
	  while (str.indexOf(strFind) > -1)
	  {
	   str = str.replace(strFind, strReplace);
	  }
	  return str;
	 }	
 	function FCKInsertHTML(strVal, fldName,id)
    {
    	gbl_FCKID = id;
	    var oEditor = FCKeditorAPI.GetInstance('EditorDefault');
	    if (!oEditor) {
	    	alert("Instance wurde nicht gefunden");
	    }
	    if (oEditor.EditorDocument)
	    {
	    	oEditor.EditorDocument.body.innerHTML = "";
	    } else {
		    oEditor.InsertHtml("");
	    }
	    //strVal = decode(strVal);
	    oEditor.InsertHtml(strVal);
	}
	
	function saveFCK(id,lang)
	{
	    var oEditor = FCKeditorAPI.GetInstance('EditorDefault');
	    var str = oEditor.GetXHTML("UTF-8");
	    var requestUrl;
	    var params;
	    
	    // Build URL and send it to server
	    requestUrl = httpPath+"getTable";
	    params = "aktion=set&value="+encode(str)+"&id="+encodeURIComponent(id)+"&dest=info_EditorDefault&lang="+lang;
	    loadXMLDocParams(requestUrl,params,processReqTable);
	}
	
	var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

	function decode(encStr)
	{
		 var decOut = "";
		 var i = 0;
		 var ch = 0;
		 for(; i<encStr.length; i += 3)
		 {
			 code 	= encStr.substring(i, i+3)*1;
			 ch    	= String.fromCharCode(code*1);
			 decOut += ch;
		 }
		 return(decOut);
	}
	
 	function encode(rohtext) 
 	{
    	rohtext = rohtext.replace(/\r\n/g,"\n");
       	var result = "";
        for(var n=0; n<rohtext.length; n++)
        {
         	var c=""+rohtext.charCodeAt(n);
         	while(c.length<3) {	
         		c = "0"+c;
         	}
         	result = result + c;
        }
        return result;
	}	
	function createLinkData(title,style,dest)
	{
	    var requestUrl;
	    requestUrl = httpPath+"getTable?aktion=createLink&title="+encode_base64(title)+"&stylew="+encodeURIComponent(style)+"&dest="+encodeURIComponent(dest);
	    loadXMLDoc(requestUrl,processReqTable);
	}
	function saveLinkData(id,title,style,dest)
	{
	    var requestUrl;
	    requestUrl = httpPath+"getTable?aktion=saveLink&title="+encode_base64(title)+"&stylew="+encodeURIComponent(style)+"&dest="+encodeURIComponent(dest)+"&ID="+id;
	    loadXMLDoc(requestUrl,processReqTable);
	}
	function createBlobData(title,style,dest)
	{
	    var requestUrl;
	    requestUrl = httpPath+"getTable?aktion=createBlob&title="+encode_base64(title)+"&stylew="+encodeURIComponent(style)+"&dest="+encodeURIComponent(dest);
	    loadXMLDoc(requestUrl,processReqTable);
	}
	function saveBlobData(id,title,style,dest,lang)
	{
	    var requestUrl="";
	    var params="";
	    requestUrl = httpPath+"getTable?aktion=saveBlob";
	    params = "title="+encode_base64(title)+"&stylew="+encodeURIComponent(style)+"&dest="+encodeURIComponent(dest)+"&ID="+id+"&lang="+lang;
	    loadXMLDocParams(requestUrl,params,processReqTable);
	}
	function deleteBlobData(id)
	{
	    var requestUrl;
	    requestUrl = httpPath+"getTable?aktion=deleteBlob&ID="+id;
	    loadXMLDoc(requestUrl,processReqTable);
	}
	function deleteLink(id)
	{
	    var requestUrl;
	    requestUrl = httpPath+"getTable?aktion=deleteLink&ID="+id;
	    loadXMLDoc(requestUrl,processReqTable);
	}
	
	function checkCommand(cmd)
	{
		
		if (cmd=="reload") {
			location.reload();
		}
		return true;
	}
	
	function checkReadyState(state)
	{		
		return;
		if(state == 0)
		{
		 window.status = "Sending Request...";
		}
		if(state == 1)
		{
		 window.status = "Loading Response...";
		}
		if(state == 2)
		{
		 window.status = "Response Loaded...";
		}
		if(state == 3)
		{
		 window.status = "Response Ready...";
		}	
	}
	function processReqTable() 
	{
		if (!document) {
			alert("Dokument nicht gefunden!");
		}
		checkReadyState(req.readyState);
	    // only if req shows "complete"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
		      response  = req.responseXML.documentElement;
			  if (!response && req.responseText) {
			  	req.responseXML.loadXML(req.responseText); 
			  }

		      response  = req.responseXML.documentElement;
			  if (!response && req.responseText) {
		      	req.responseXML.loadXML(req.responseText); 
			  }
		      response  = req.responseXML.documentElement;

		      if (response) 
		      {
			      if (response.getElementsByTagName('dest')[0]) 
			      {
			      	dest="info";
			      	if(response.getElementsByTagName('dest')[0]) {
				      	if(response.getElementsByTagName('dest')[0].firstChild) {
			      			dest   = ""+response.getElementsByTagName('dest')[0].firstChild.data;
			      		}
			      	}
			      	if (!response.getElementsByTagName('dataCount')[0]) {
	    		        alert("There was a problem retrieving the XML dataCount:\n" + req.statusText + " Text:"+req.responseText);
			            alert("url"+lurl);
			      	}
			      	count  = ("0"+response.getElementsByTagName('dataCount')[0].firstChild.data)*1;
			      	html   = "";
			      	for (i=0;i<count;i++) 
			      	{
			      		row  = response.getElementsByTagName('data'+i)[0].firstChild.data;
				      	html = html+row;
					}
					html=decode(html);
					if (dest.lastIndexOf("_")>-1) {
						dest = dest.substring(0,dest.lastIndexOf("_"));
						
						if (dest=="info") {
							dest="EditorDefault";
						}
						id = response.getElementsByTagName('ID')[0].firstChild.data;
								
						FCKInsertHTML(html,dest,id);
					} else {
					
							bodyElement = document.getElementById(dest);
							
							if (bodyElement) {
								bcontainer  = document.getElementById("container");
								if (bcontainer) 
								{
									bcontainer.innerText= "";
                                    i = 0;
									for (i=0;i<count;i++) 
							      	{
							      		row  = ""+response.getElementsByTagName('data'+i)[0].firstChild.data;
										bcontainer.innerText = bcontainer.innerText + decode(row);
									}
									bodyElement.innerHTML = bcontainer.innerText;
								}
							} else {
								if (dest!="null") {
									//alert("Body Element nicht gefunden."+dest);
								}
							}					
					}
			      	cmd   = response.getElementsByTagName('command');
			      	
			      	if ((cmd) && (cmd[0]) && (cmd[0].firstChild.data)) {
			      		checkCommand(cmd[0].firstChild.data);
			      	}
					initLightbox();		    	  
		    	  } else
		    	  {
			    	  alert("(Table)There was a problem in the XML data:\n Retrieve Status" + req.statusText);
		    	  }
	    	  } 
	    	  else 
	    	  {
	    	  	alert("Kein Response erhalten!");
	    	  }
	        } 
	        else 
	        {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText + " Text:"+req.responseText);
	            alert("url"+lurl);
	        }
		    onLoadReady();
	    }
	}
	
	
	function processReqMultiTable() 
	{
		if (!document) {
			alert("Dokument nicht gefunden!");
		}
		checkReadyState(req.readyState);
	    // only if req shows "complete"
	    if (req.readyState == 4) {
	        // only if "OK"
	        if (req.status == 200) {
		      response  = req.responseXML.documentElement;
			  if (!response && req.responseText) {
			  	req.responseXML.loadXML(req.responseText); 
			  }

		      response  = req.responseXML.documentElement;
			  if (!response && req.responseText) {
		      	req.responseXML.loadXML(req.responseText); 
			  }
		      response  = req.responseXML.documentElement;

		      if (response) 
		      {
		      	readParams(response,0,"rightmenu");
		      	readParams(response,1,"info");
				
	    	  } 
	    	  else 
	    	  {
	    	  	alert("Kein Response erhalten!");
	    	  }
	        } 
	        else 
	        {
	            alert("There was a problem retrieving the XML data:\n" + req.statusText + " Text:"+req.responseText);
	        }
		    onLoadReady();
		   	initLightbox();		    	  
	      	
	    }
	}
	
	function readParams(response,type,dest)
	{
	  divElement = document.getElementById("container");
	  	  
      if (dest)  //response.getElementsByTagName('dest')[0]
      {
      	//dest   = ""+response.getElementsByTagName('dest')[0].firstChild.data;
      	count  = ("0"+response.getElementsByTagName('dataCount'+type)[0].firstChild.data)*1;
      	//html   = "";
      	divElement.innerHTML = "";
      	defdest = "";
      	for (i=0;i<count;i++) 
      	{
      		if (response.getElementsByTagName('data'+type+"_"+i+"_dest")[0]) {
      			if (response.getElementsByTagName('data'+type+"_"+i+"_dest")[0].firstChild.data) {
      				dest = response.getElementsByTagName('data'+type+"_"+i+"_dest")[0].firstChild.data;
      				if (i==0) {
      					defdest=dest;
      				} else {
      					if (defdest!=dest) {
	      					processHtml(divElement,response,type,defdest);
							divElement.innerHTML = "";
	      					defdest = dest;
      					}
      				}
      			}
      		}
      		if (response.getElementsByTagName('data'+type+"_"+i)[0].firstChild) {
//      			row  = response.getElementsByTagName('data'+type+"_"+i)[0].firstChild.data;
				divElement.innerHTML = divElement.innerHTML+response.getElementsByTagName('data'+type+"_"+i)[0].firstChild.data;
			}
		}
//		alert(dest+"-"+count+":"+divElement.innerHTML);
		processHtml(divElement,response,type,dest);
	  } else
	  {
    	  alert("(Table)There was a problem in the XML data:\n Retrieve Status" + req.statusText);
	  }
	}	
	
	function processHtml(html,response,type,dest)
	{
		html.innerHTML=decode(html.innerHTML)+ " ";
		if (dest.lastIndexOf("_")>-1) {
			dest = dest.substring(0,dest.lastIndexOf("_"));
			
			if (dest=="info") {
				dest="EditorDefault";
			}
			id = response.getElementsByTagName('ID')[0].firstChild.data;
					
			FCKInsertHTML(html.innerHTML,dest,id);
		} else {
			if (dest=="flyer") {
				var element = document.getElementById("divsun");
				var img = html.innerHTML.substring(html.innerHTML.lastIndexOf("src=\"")+5, html.innerHTML.lastIndexOf("\""));
				while (img.lastIndexOf("\"")>-1) 
				{
					//alert("1");
					img = img.substring(0, img.lastIndexOf("\""));
				}
				if (element) {
                    if (img.indexOf("bild_fert2.jpg")>-1)
                    {
                        img = img.substring(0, img.lastIndexOf("."));
                        img = img + "_"+lang+".jpg";
                    }
                   //alert(img);
					element.style.backgroundImage="url('"+img+"')";
				}
			} else {
				bodyElement = document.getElementById(dest);
				if (bodyElement) {
					//alert(html.innerHTML);
					bodyElement.innerHTML = html.innerHTML;
					//alert(bodyElement.innerHTML);
				} else {
					if (dest!="null") {
						alert("Body Element nicht gefunden."+dest);
					}
				}
			}
		}
      	cmd   = response.getElementsByTagName('command');
      	
      	if ((cmd) && (cmd[0]) && (cmd[0].firstChild.data)) {
      		checkCommand(cmd[0].firstChild.data);
      	}
	}
	
	
	function ListOnChange(ElementSelect,DestElement) 
	{
		if (DestElement=="") return false;
	    // get selected Element
	    var selectedVar = ElementSelect.options[ElementSelect.selectedIndex].value;
	    var requestUrl;
	    // Build URL and send it to server
	    requestUrl = httpPath+"filter?"+ "name="+encodeURIComponent(ElementSelect.name)+ "&value="+encodeURIComponent(ElementSelect.value)+"&dest="+encodeURIComponent(DestElement);
	    loadXMLDoc(requestUrl,processReqChangeSelect);
	}
	
	function init()
	{
		window.setTimeout("checkTimerAnim()", 300);	
	}
	
	function filter(dTable,typ,sb1i,sb2i,sb3i,sb4i) 
	{
		// getDrop Down Elements by ID
		var sb1 = document.getElementById(sb1i); 
		var sb2 = document.getElementById(sb2i); 
		var sb3 = document.getElementById(sb3i); 
		var sb4 = document.getElementById(sb4i); 
		
	    // get selected Elements
	    var sbVar1 = sb1.options[sb1.selectedIndex].value;
	    var sbVar2 = sb1.options[sb2.selectedIndex].value;
	    var sbVar3 = sb1.options[sb3.selectedIndex].value;
	    var sbVar4 = sb1.options[sb4.selectedIndex].value;
	    
	    var requestUrl;
	    // Build URL and send it to server
	    requestUrl = httpPath+"getTable?"+ "dest="+encodeURIComponent(dTable)+ "&typ="+encodeURIComponent(typ)+"&meVar1="+encodeURIComponent(sbVar1)+ "&meVar2="+encodeURIComponent(sbVar2)+ "&meVar3="+encodeURIComponent(sbVar3)+ "&meVar4="+encodeURIComponent(sbVar4);
	    loadXMLDoc(requestUrl,processReqTable);
	}

	function getTableData(table,dest,typ,id,lang) 
	{
	    var requestUrl;
	    // Build URL and send it to server
	    requestUrl = httpPath+"getTable?"+ "table="+table+"&dest="+encodeURIComponent(dest)+ "&typ="+encodeURIComponent(typ)+"&id="+encodeURIComponent(id)+"&lang="+lang;
	    //alert(requestUrl);
	    loadXMLDoc(requestUrl,processReqTable);
	}
	
	function loadMailData(url)
	{
		iframe = document.getElementById("mailFrame");
		if (iframe) {
			iframe.src=url;
			return;
		}
		return;
	}
	function scaleImage(picName,w,h)
	{
		if (picOverName!="") {
    	    document.images[picOverName].width  = 100;
	        document.images[picOverName].height = 75;
		}
        document.images[picName].width = w;
        document.images[picName].height = h;
        
        picOverName = picName;
    }
    
	function getViewportSize() 
	{ 
	 var size = [0, 0]; 
	
	 if (typeof window.innerWidth != 'undefined') 
	 { 
	   size = [ 
	       window.innerWidth, 
	       window.innerHeight 
	   ]; 
	 } 
	 else if (typeof document.documentElement != 'undefined' 
	     && typeof document.documentElement.clientWidth != 
	     'undefined' && document.documentElement.clientWidth != 0) 
	 { 
	   size = [ 
	       document.documentElement.clientWidth, 
	       document.documentElement.clientHeight 
	   ]; 
	 } 
	 else 
	 { 
	   size = [ 
	       document.getElementsByTagName('body')[0].clientWidth, 
	       document.getElementsByTagName('body')[0].clientHeight 
	   ]; 
	 } 
	
	 return size; 
	}    

