﻿// Hauptfunktionen Javascript

//-------------------------------------------------------------------------------------------------------------
//Funktion zur Einbindung eines Layers (25.08.2010)
//START--------------------------------------------------------------------------------------------------------
function popupLayer(url,width,height)
{
	document.getElementById('layer').innerHTML='';
ajaxRequest(url,'layer',0,'',showlayer(width,height));
return false;
}

function hidelayer()
{ 
	document.getElementById('layer').style.display='none';
	document.getElementById('layer').style.visibility='hidden';
	
	document.getElementById('overlay').style.display='none';
	document.getElementById('overlay').style.visibility='hidden';
}

function showlayer(width,height)
{
	tmparray = getPageSize();
	pageWidth = tmparray[0];
	pageHeight = tmparray[1];
	windowWidth = tmparray[2];
	windowHeight = tmparray[3];
	xScrolled = tmparray[4];
	yScrolled = tmparray[5];
	
	document.getElementById('layer').style.width=width+'px';
	document.getElementById('layer').style.height=height+'px';
	document.getElementById('layer').style.marginLeft='-'+(width/2)+'px';		
	
	//layer einblenden
	document.getElementById('layer').style.display='block';
	document.getElementById('layer').style.visibility='visible';
	
	//overlay einblenden
	document.getElementById('overlay').style.display='block';
	document.getElementById('overlay').style.visibility='visible';	
} 

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

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

	var xScrolled, yScrolled;
	if (self.pageYOffset) {
		xScrolled = self.pageXOffset;
		yScrolled = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		xScrolled = document.documentElement.scrollLeft;
		yScrolled = document.documentElement.scrollTop;
	} else if (document.body) {
		xScrolled = document.body.scrollLeft;
		yScrolled = document.body.scrollTop;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, xScrolled, yScrolled);
	return arrayPageSize;
}
//ENDE---------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------//Funktion zur Einbindung eines Layers AJAX-Teil (25.08.2010)//START--------------------------------------------------------------------------------------------------------
var http_request = false;
	var daten='';
	var datentoid='';
	var get_url='';
	var ajax_running=0;
	var ajax_state=0;
	var ajax_jsafterdone='';

	function ajaxTimeout(state)
	{
		if (ajax_state==state) ajax_running=0;
	}
	
  function ajaxRequest(url,objid,show,postparam,jsafterrequest)  
  {
      if (ajax_running)
      {

      	if (!show) show=0;
      	window.setTimeout("ajaxRequest('"+url+"','"+objid+"','"+show+"','"+postparam+"','"+jsafterrequest+"')",20);
				
      	if (ajax_running==1) 
      	{
      		ajax_state++;
      		window.setTimeout("ajaxTimeout("+ajax_state+")",5000);
      	}
      	ajax_running=2;
      	return true;
      }
      ajax_running=1;
      ajax_jsafterdone=jsafterrequest;
      get_url=url;
      http_request = false;
      teile=location.href.split('?');
			wobin=teile[0].replace(/default\.aspx/,'');
			if (url==url.replace(/http\:\/\//ig,'') && url==url.replace(/https\:\/\//ig,''))	url=wobin+url;
			datentoid=objid;

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

      if (!http_request) 
      {
          if (document.getElementById(objid)) document.getElementById(objid).innerHTML='Verbindung fehlgeschlagen2';
          return false;
      }
    	else
    	{
    		//http_request.overrideMimeType('text/xml; charset=ISO-8859-1');
    	}
      if (show==1) alert(url);
      
      if (postparam)
    	{
	    	http_request.onreadystatechange = showdata;
	      http_request.open('POST', url, true);
	      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	      http_request.setRequestHeader("Content-length", postparam.length);
	      http_request.setRequestHeader("Connection", "close");
	      http_request.send(postparam);
    	}
			else
			{
	      http_request.onreadystatechange = showdata;
	      http_request.open('GET', url, true);
	      http_request.send(null);
      }
  }

	function ajaxRequestPost(url,objid,show,formobj,jsafterrequest) 
	{
	 var elemente= new Array();
	 elemente['text']=1;
	 elemente['textarea']=1;
	 elemente['checkbox']=2;
	 elemente['select-one']=1;
	 
		mytest='';
		for (var obj in formobj)
		{
			if (formobj[obj])
				if (elemente[formobj[obj].type]>=1)
				{
					myvalue=formobj[obj].value;
					if (mytest!='') mytest+='&';
					if (elemente[formobj[obj].type]==2)
					{
							if (formobj[obj].checked)	myvalue=formobj[obj].value; else myvalue='';
					}
					mytest=mytest+formobj[obj].name+'='+escape(myvalue);
				}
		}

    ajaxRequest(url,objid,show,mytest,jsafterrequest);
   }

  function showdata() 
  {
      objid=datentoid;
      if (http_request.readyState == 4) 
      {
      	if (http_request.status == 200) 
      	{
        	if (obj=document.getElementById(objid)) 
        	{
        		obj.innerHTML=http_request.responseText;
        		if (ajax_jsafterdone) 
        		{
        			eval(ajax_jsafterdone);
        		}
        	}
        } 
        else 
        {
          if (document.getElementById(objid)) document.getElementById(objid).innerHTML=http_request.responseText;
        }
      	ajax_running=0;
      }
  }
//ENDE---------------------------------------------------------------------------------------------------------

