//Copyright Michael Rettkowitz 2006, Dortmund, Germany
//Nutzung der Skripte ohne meine ausdrückliche Erlaubnis ist untersagt
var xmlhttp=null;
var changeImage;
var urlText;
var zA=false;
var zB=null;
var zoomF;
var dI=false;
var MainImgTop=0;
var MainImgLeft=0;
var LastFieldValue="";
var LastFieldName="";
var aktEbene="Ebene1";
var aktEbeneFixed=false;
var sAntwortInfo = null;

function docComplete()
{
   if (dI)
      docInit();
}


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}

// fuer top
function abstop(i){ return (i.offsetParent) ? i.offsetTop+abstop(i.offsetParent) : i.offsetTop; }

// fuer left
function absleft(i){ return (i.offsetParent) ? i.offsetLeft+absleft(i.offsetParent) : i.offsetLeft; }

function lc()
{
   //alert(document.getElementById("MainImg").style.posTop;
   alert(document.getElementById("MainImg").style.posTop);
}

//Funktionen Kontakformular Anfang ----------------------

var xmlHttpPost

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlHttp=false
}
}
@else
xmlHttp=false
@end @*/

/*if (!xmlHttpPost) 
{
	try 
	{
		xmlHttpPost = new XMLHttpRequest();
	}
	catch (e) 
	{
		xmlHttpPost=false
	}
}*/

// Code f&Uuml;r Mozilla, etc.
if (window.XMLHttpRequest)
{
	xmlHttpPost = new XMLHttpRequest();
	window.status = document.location;
	//xmlHttpPost.onreadystatechange = xmlhttpChange;
	//xmlHttpPost.open("GET",url, true);
	//xmlHttpPost.send(null);
}
	// Code f&uuml;r IE
else if (window.ActiveXObject)
{
	xmlHttpPost=new ActiveXObject("Microsoft.XMLHTTP")
	if (xmlHttpPost)
	{
	    //xmlhttp.onreadystatechange = xmlhttpChange;
		//xmlhttp.open("GET", url, true);
		//xmlhttp.send();
	}
}


var URLto = "http://www.formular-praxis.de/scripts/SendContactMail.asp";

function buildPOST(theFormName) 
{
	theForm = document.forms[theFormName];
	var qs='';
	var tmpValue="";
	for (e=0;e<theForm.elements.length;e++) 
	{
		if (theForm.elements[e].name!='')
		{
			var name = theForm.elements[e].name;	
			if (theForm.elements[e].type=="checkbox") 
			{
				if (theForm.elements[e].checked)
					tmpValue="Ja";
				else	
					tmpValue="Nein";

			}
			else
			{
					tmpValue=encodeURI(escape(theForm.elements[e].value));
			}
			qs+=(qs=='')?'':'&'
			qs+= name+'='+tmpValue;
		}
	}
	qs+="\n";
	return qs
}

function send_post(theFormName) 
{
	//alert(theFormName);
	var xmlMessage=buildPOST(theFormName);
	//alert(xmlMessage);
    //alert(xmlMessage.length);	
	if(theFormName=="FP_Form1")
	{
		URLto = "http://www.formular-praxis.de/scripts/SendContactMail.asp";
	}
	else if (theFormName=="FP_Newsletter1")
	{
		URLto = "http://www.formular-praxis.de/scripts/RegNewsletter.asp";
	}
	xmlHttpPost.open("POST", URLto, false);
	//alert("xmlHttpPostOpen");
	// for ie compatability
	//xmlHttpPost.setRequestHeader('Content-Type','text/html');
	xmlHttpPost.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpPost.setRequestHeader("Content-length", xmlMessage.length);
	xmlHttpPost.setRequestHeader("Connection", "close");
	//alert("xmlHttpPostsetRequestHeader");
	var optionDiv = document.getElementById("antwortInfo");
	optionDiv.style.visibility="visible";
	if (sAntwortInfo==null)
	{
		sAntwortInfo=optionDiv.innerHTML;
	}
	else
	{
		optionDiv.innerHTML=sAntwortInfo;
	}
	//alert("vor absenden");
	xmlHttpPost.send(xmlMessage);
	//alert("nach absenden");
}

function display_response() 
{
	//alert(xmlHttpPost.responseText);
	var optionDiv=document.getElementById("antwortInfo");
	//alert(optionDiv);
	optionDiv.innerHTML=xmlHttpPost.responseText;
	optionDiv.style.visibility="visible";
	optionDiv.style.left=document.body.offsetLeft+(document.body.offsetWidth-optionDiv.offsetWidth)/2;
	optionDiv.style.top=document.body.scrollTop-100;	
}


//Funktionen Kontakformular Ende ----------------------

function loadXMLDoc(url)
{
	// Code fÜr Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
		window.status = document.location;
		xmlhttp.onreadystatechange = xmlhttpChange;
		xmlhttp.open("GET",url, true);
		xmlhttp.send(null);
	}
	// Code für IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
		    xmlhttp.onreadystatechange = xmlhttpChange;
			xmlhttp.open("GET", url, true);
			xmlhttp.send();
		}
	}
	else
    {
		document.getElementById(aktEbene).innerHTML = "Ihr Browser unterstützt das Laden des Textes nicht";	
    }
}

function xmlhttpChange()
{
	if (xmlhttp.readyState==4)
	{
		// wenn geladen
		if (xmlhttp.status == 200)
		{
			//alert(aktEbene);
			document.getElementById(aktEbene).innerHTML=xmlhttp.responseText;
			//document.getElementById("Ebene1").scrollIntoView(false);
		}
		else
		{
			document.getElementById(aktEbene).innerHTML = "Problem beim Laden des Textes!";
		}
		xmlhttp=null;
		if (aktEbeneFixed==false)
		{
			if ((yMousePos-document.body.scrollTop+document.getElementById(aktEbene).offsetHeight) > fensterHoehe())
			{
				//document.getElementById("Ebene1").style.top=Math.max(document.body.scrollTop+fensterHoehe()-document.getElementById("Ebene1").offsetHeight,document.body.scrollTop);
				document.getElementById(aktEbene).style.top=Math.max(document.body.scrollTop+fensterHoehe()-document.getElementById(aktEbene).offsetHeight-4,document.body.scrollTop);
			}
		}
	}
}


// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
	if (zA)
	{
		var x,y,x1,x2,y1,y2,dx=0,dy=0;
		var isOutImg=yMousePos<MainImgTop;
		isOutImg=isOutImg||xMousePos<MainImgLeft;
		isOutImg=isOutImg||yMousePos>MainImgTop+1000;
		isOutImg=isOutImg||xMousePos>MainImgLeft+1000;
		if (isOutImg)
		{
			if (document.getElementById("Zoomer").style.visibility=="visible")
				document.getElementById("Zoomer").style.visibility="hidden";
		}
		else
		{
			fact=2; //Vergrößerung
			opp=100; //halbe Zoomfenstergröße
			x=xMousePos-MainImgLeft;
			y=yMousePos-MainImgTop;
			dx=window.document.body.scrollLeft;
			dy=window.document.body.scrollTop;
		    x1=-opp+(x+dx)*fact-(document.body.scrollLeft*fact); //left
			y1=-opp+(y+dy)*fact-(document.body.scrollTop*fact);	//top
			x2=+opp+(x+dx)*fact-(document.body.scrollLeft*fact); //right
			y2=+opp+(y+dy)*fact-(document.body.scrollTop*fact);	//bottom
			document.getElementById('Zoomer').style.left=(x+dx)*(1-fact)+document.body.scrollLeft+MainImgLeft;
			document.getElementById('Zoomer').style.top=(y+dy)*(1-fact)+document.body.scrollTop+MainImgTop;
			document.getElementById('Zoomer').style.clip="rect(" +y1 +"px," +x2 +"px," +y2 +"px,"+x1 +"px)";
		}
	}
}


function fensterHoehe()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.body && document.body.offsetHeight)
	{
		return document.body.offsetHeight;      
	}
	else
	{
		return(0)
	}
}   

function fensterBreite()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.body && document.body.offsetWidth)
	{
		return document.body.offsetWidth;      
	}
	else
	{
		return(0)
	}
}   

function showSiteinfo()
{
   document.getElementById("Siteinfo").style.top=yMousePos + 4;
   document.getElementById("Siteinfo").style.left=xMousePos + 4;
   startZoomElement("Siteinfo", 30, 5)
}

window.onscroll=function()
{
	document.getElementById("Posviewer").style.top=document.body.scrollTop;
	document.getElementById("Posviewer").style.left=(document.body.scrollLeft + fensterBreite()/2);
}
function showEbene1(Ebene,imgSrc,textSrc,isFixed)
{
	//changeImage = imgSrc;
	aktEbene=Ebene;
	aktEbeneFixed=isFixed;
	urlText = "http://www.formular-praxis.de/"+textSrc;
	//alert(urlText);
	to1 = window.setTimeout("showEbene2()", 500);
}

function showEbene2()
{
	//document.getElementById("imgBig").src = changeImage;
	e1=document.getElementById(aktEbene);
	if (aktEbeneFixed==false)
	{
		document.getElementById(aktEbene).style.top=yMousePos+2;
		document.getElementById(aktEbene).style.left=xMousePos+2;
		if ((document.getElementById(aktEbene).offsetWidth+xMousePos)>fensterBreite())
			document.getElementById(aktEbene).style.left=Math.max(fensterBreite()-document.getElementById(aktEbene).offsetWidth,document.body.scrollLeft);
		//alert(document.getElementById("Ebene1").offsetTop  + yMousePos  + document.getElementById("Ebene1").offsetHeight);
	}
	document.getElementById(aktEbene).innerHTML = "Lade Daten...";
	loadXMLDoc(urlText);
	e1.style.visibility = "visible";
}

function hideEbene(Ebene)
{
	if (typeof to1!="undefined")
		window.clearTimeout(to1);
	document.getElementById(Ebene).style.visibility = "hidden";
	//imgBig.src = "img-site/BildLaden.jpg";
}

function clearInputfield(fld)
{
	if (fld.value=="your@email.address")
		fld.value="";
}

function restoreInputfield(fld)
{
	if (fld.value=="")
		fld.value="your@email.address";
}

function sZ()
{
	if (zA==false)
	{
		document.getElementById("Posviewer").style.visibility="hidden";
		document.getElementById("Zoomer").style.visibility="hidden";		
		if (!zB)
		{
			zB=document.createElement("img");
			zB.setAttribute("src", document.getElementById("MainImg").src);
			zB.width=document.getElementById("MainImg").width*2;
			zB.height=document.getElementById("MainImg").height*2;
		}
		zA=true;
		document.getElementById("Zoomer").innerHTML='<img src="' + zB.src + '" + width="' + zB.width  + '" + height="' + zB.height + '">';
		document.getElementById("Zoomer").style.visibility = "visible";
	}
	else
	{
		document.getElementById("Zoomer").style.visibility="hidden";
		document.getElementById("Zoomer").innerHTML="";
		zA=false;
	}
}


function mZ()
{
   document.getElementById("yp").innerHTML="<font size='1pt'>"+Math.floor((yMousePos-MainImgTop)/10+1)+"</font>";
   document.getElementById("xp").innerHTML="<font size='1pt'>"+Math.floor((xMousePos-MainImgLeft)/10+1)+"</font>";   
}

function showHidePosviewer()
{
if (document.getElementById("Posviewer").style.visibility=="hidden")
   {
   document.getElementById("Zoomer").style.visibility = "hidden";
   startZoomElement("Posviewer", 30, 5)
   zA=false;   
   }
else
   {
   document.getElementById("Posviewer").style.visibility="hidden";
   }

}

function startZoomElement(element, zoomInit, interval)
{
   if (typeof aktiv!="undefined")
   {
      window.clearInterval(aktiv);
   }
   document.getElementById(element).style.zoom=zoomInit+"%";
   document.getElementById(element).style.visibility="visible";
   zoomF=zoomInit;
   el=element;
   aktiv=window.setInterval("zoomElement(el)", interval);
}

function zoomElement(element, iix)
{
  zoomF=zoomF+5;
  document.getElementById(element).style.zoom=zoomF+"%";
  if (zoomF>=100)
  {
     window.clearInterval(aktiv);
     el=null;
  }   
}


