// Findet die absolute x Position eines Elementes raus
function getAbsoluteX(elm) {
   var x = 0;
   if (elm && typeof elm.offsetParent != "undefined") {
     while (elm && typeof elm.offsetLeft == "number") {
       x += elm.offsetLeft;
       elm = elm.offsetParent;
     }
   }
   return x;
}


// Findet die absolute y Position eines Elementes raus
function getAbsoluteY(elm){
   var y = 0;
   if (elm && typeof elm.offsetParent != "undefined") {
     while (elm && typeof elm.offsetTop == "number") {
       y += elm.offsetTop;
       elm = elm.offsetParent;
     }
   }
   return y;
}

function getPageCoords0(elementId) {		// Auslesen der Position
     var element;
     if (document.all)
       element = document.all[elementId];
     else if (document.getElementById)
       element = document.getElementById(elementId);
     if (element) {
       var coords0 = {x: 0, y: 0};
       do {
		if(element.currentStyle)
		{
			if(element.currentStyle.position!='relative')
			{
				coords0.x += element.offsetLeft;
				coords0.y += element.offsetTop;
			}
		}
		else
		{
			coords0.x += element.offsetLeft;
			coords0.y += element.offsetTop;
		}

         element = element.offsetParent;
       }
       while (element)
       return coords0;
     }
     else
       return null;
    } 

function getPageCoords(elementId) {		// Auslesen der Position
     var element;
     if (document.all)
       element = document.all[elementId];
     else if (document.getElementById)
       element = document.getElementById(elementId);
     if (element) {
       var coords = {x: 0, y: 0};
       do {
		if(element.currentStyle)
		{
			if(element.currentStyle.position!='relative')
			{
				coords.x += element.offsetLeft;
				coords.y += element.offsetTop;
			}
		}
		else
		{
			coords.x += element.offsetLeft;
			coords.y += element.offsetTop;
		}

         element = element.offsetParent;
       }
       while (element)
       return coords;
     }
     else
       return null;
    } 

function posav()  // Auslesen der Div-Position Vorschauelement
{
    var coords0 = getPageCoords0('stemp_div');
    if (coords0)
		{
		posx = coords0.x;
		posy = coords0.y;
		}
}

function alertCoo1(el)	//  Ermittelt die Position der Textzeilen im Bezug zum Vorschauelement
{
	posav();
	var coords = getPageCoords(el);
    if (coords)
		{
		posx1 = coords.x;
		posy1 = coords.y;
		document.getElementById('pleft1').value = (posx1 - posx) / 5;
		document.getElementById('ptop1').value = (posy1 - posy) / 5;
		poleft_1 = document.getElementById('pleft1').value * 5 - parseInt(rahm_abstand); 
		potop_1 = document.getElementById('ptop1').value * 5 - parseInt(rahm_abstand);
		}
}

function alertCoo2(e1)	
{
    posav();
	var coords = getPageCoords(e1);
    if (coords)
		{
		document.getElementById('pleft2').value = (coords.x - posx) / 5;
		document.getElementById('ptop2').value = (coords.y - posy) / 5;
		poleft_2 = document.getElementById('pleft2').value * 5 - parseInt(rahm_abstand);
		potop_2 = document.getElementById('ptop2').value * 5 - parseInt(rahm_abstand);
		}
}

function alertCoo3(e1)
{
    posav();
	var coords = getPageCoords(e1);
    if (coords)
		{
		document.getElementById('pleft3').value = (coords.x - posx) / 5;
		document.getElementById('ptop3').value = (coords.y - posy) / 5;
		poleft_3 = document.getElementById('pleft3').value * 5 - parseInt(rahm_abstand);
		potop_3 = document.getElementById('ptop3').value * 5 - parseInt(rahm_abstand);
		}
}

function alertCoo4(el)	
{
    posav();
	var coords = getPageCoords(el);
    if (coords)
		{
		document.getElementById('pleft4').value = (coords.x - posx) / 5;
		document.getElementById('ptop4').value = (coords.y - posy) / 5;
		poleft_4 = document.getElementById('pleft4').value * 5 - parseInt(rahm_abstand);
		potop_4 = document.getElementById('ptop4').value * 5 - parseInt(rahm_abstand);
		}
}

function alertCoo5(el)	
{
    posav();
	var coords = getPageCoords(el);
    if (coords)
		{
		document.getElementById('pleft5').value = (coords.x - posx) / 5;
		document.getElementById('ptop5').value = (coords.y - posy) / 5;
		poleft_5 = document.getElementById('pleft5').value * 5 - parseInt(rahm_abstand);
		potop_5 = document.getElementById('ptop5').value * 5 - parseInt(rahm_abstand);
		}
}

function alertCoo6(el)	
{
    posav();
	var coords = getPageCoords(el);
    if (coords)
		{
		document.getElementById('pleft6').value = (coords.x - posx) / 5;
		document.getElementById('ptop6').value = (coords.y - posy) / 5;
		poleft_6 = document.getElementById('pleft6').value * 5 - parseInt(rahm_abstand);
		potop_6 = document.getElementById('ptop6').value * 5 - parseInt(rahm_abstand);
		}
}

function posavgraf()  // Auslesen der Div-Position Vorschauelement
{
    var coords0 = getPageCoords0('stemp_stemp');
    if (coords0)
		{
		posx = coords0.x;
		posy = coords0.y;
		}
}

function alertCoograf(el)	
{
    posavgraf();
	var coords = getPageCoords(el);
    if (coords)
		{
		document.getElementById('pleftgraf').value = (coords.x - posx - 25) /5;
		document.getElementById('ptopgraf').value = (coords.y - posy - 25) /5;
		poleft_graf = document.getElementById('pleftgraf').value * 5; 
		potop_graf = document.getElementById('ptopgraf').value * 5;
		} 
}

	function alertCoo_all()	
	{
	   stemp_zeil_anz = document.getElementById("stemp_zeil").value;
	   for(i = 0 ; i < stemp_zeil_anz ; i ++)
	   {
		t_nr = 1 + i;
		if(t_nr == 1)
		{alertCoo1('stemp_zeile_1');}
		if(t_nr == 2)
		{alertCoo2('stemp_zeile_2');}
		if(t_nr == 3)
		{alertCoo3('stemp_zeile_3');}
		if(t_nr == 4)
		{alertCoo4('stemp_zeile_4');}
		if(t_nr == 5)
		{alertCoo5('stemp_zeile_5');}
		if(t_nr == 6)
		{alertCoo6('stemp_zeile_6');}
	   }
	   
	}

function posCoo_schreib()	//  Ermittelt die Position der Textzeilen im Bezug zum Vorschauelement
{
		rahm_abstand = document.getElementById("r_dick").value;
	   stemp_zeil_anz = document.getElementById("stemp_zeil").value;
	   for(i = 0 ; i < stemp_zeil_anz ; i ++)
	   {
		t_nr = 1 + i;
		if(t_nr == 1)
		{document.getElementById('pleft1').value = (poleft_1 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop1').value = (potop_1 / 5) + parseInt(rahm_abstand);}
		if(t_nr == 2)
		{document.getElementById('pleft2').value = (poleft_2 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop2').value = (potop_2 / 5) + parseInt(rahm_abstand);}
		if(t_nr == 3)
		{document.getElementById('pleft3').value = (poleft_3 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop3').value = (potop_3 / 5) + parseInt(rahm_abstand);}
		if(t_nr == 4)
		{document.getElementById('pleft4').value = (poleft_4 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop4').value = (potop_4 / 5) + parseInt(rahm_abstand);}
		if(t_nr == 5)
		{document.getElementById('pleft5').value = (poleft_5 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop5').value = (potop_5 / 5) + parseInt(rahm_abstand);}
		if(t_nr == 6)
		{document.getElementById('pleft6').value = (poleft_6 / 5) + parseInt(rahm_abstand);
		document.getElementById('ptop6').value = (potop_6 / 5) + parseInt(rahm_abstand);}
	   }
	//document.getElementById('pleft1').value = poleft_1; 
	//document.getElementById('ptop1').value = potop_1;
}

