function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 return [myWidth, myHeight];
}

function getElement(element_id)
    {
    return document.getElementById(element_id);
    }

function createRequestObject() 
{
	if (window.ActiveXObject && !window.XMLHttpRequest) 
	{
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			return;
		}
	}
	if (!window.ActiveXObject && window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
}

var http = createRequestObject();
var actualDiv = new String();
var startDiv = new String();
var UrlLink = new String();
var mail = new String();
var body = new String();
var orincode = new String();
var confirm_code = 'abcde';


function HandleResponseForm() {
	if(http.readyState == 4) 
	{
		var response = http.responseText;
              if(response == 'OK') 
			{
                  	popup.lastChild.innerHTML = '<center><font style="color:#000000;margin:20px 0px 0px 0px;font-weight:bold;font-size:15px;">Die Nachricht wurde geschickt</font></center>';      
                  	setTimeout("hideTooltip()", "1000");
			}
		else 
		{
			popup.lastChild.innerHTML = form_create2(UrlLink,mail,body,response,orincode)      
		}
		
	}
}

function FormSubmit() 
{
	
	mail = getElement('email_link').value;
	body = getElement('mail_body').value;
	orincode = getElement('orgin_code').value;
	 
	http.open('get', '/js/sendMail/sendMail.php?url='+UrlLink+'&email='+mail+'&body='+body+'&orgin_code='+orincode+'&confirm_code='+confirm_code+'&stat='+(Math.floor(Math.random()*10000)));
	popup.lastChild.innerHTML = sending();
	http.onreadystatechange = HandleResponseForm;
	http.send(null);
	
}

var sw = screen.width;
var sh = screen.height;
var sp=true;
var popup;
var SdeltaWH = 1; 
var deltaWH = 10;
var SOffset = 1;
var ShowSpeed = 10;
var HideSpeed = 5;
var timer = null;
var top = 0;
var wait_for_continue = true;
var waiting = false;
var tooltip_id = "show_mail";




function sending()
{    
var html = '';
html = '<center><font style="color:#000000;margin:20px 0px 0px 0px;font-weight:bold;font-size:15px;">Bitte warten. Die Nachricht wird geschickt.</font></center>';
return html;
}


function getEventPosition(event)
	{
	var pos = new Array();
	
	if(document.all) // ie
	{
	pos['x'] = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
	pos['y'] = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
	}
	else // gecko
	{
	pos['x'] = event.pageX; 		
	pos['y'] = event.pageY;
	}
	return pos;
	}


function ShowBox()
{
var Box = getElement('box_co');
Size = getSize();
getXY = getScrollXY();
Box.style.width = (Size[0]) + 'px';
Box.style.height = (Size[1]-20) + 'px';
Box.style.display = '';
Box.style.top = (getXY[1]) + 'px';
}


var ScrollObj;
function ScrollAction()
{

if(ScrollObj)
{
	Size = getSize();
	getXY = getScrollXY();
	var x = (Size[0]/2)- 200; 
	var y = /*(Size[1]/2)- 200 +*/getXY[1] + 50;
	ScrollObj.style.top = y + 'px';
	ScrollObj.style.left = x + 'px';
	var Box = getElement('box_co');
	Box.style.top = (y - 50) + 'px';

}

}




function CloseAction()
{

if(ScrollObj)
{
var Box = getElement('box_co');
ScrollObj.style.display = 'none';
Box.style.display = 'none';
}

}






function ClickAction()
{ 
ShowBox();
Size = getSize();
getXY = getScrollXY();
var x = (Size[0]/2)- 200; 
var y = /*(Size[1]/2)- 200 +*/getXY[1] + 50;

var Forma = getElement('create_user_popup');

ScrollObj = Forma;
Forma.style.top = y + 'px';
Forma.style.left = x + 'px';

Forma.style.display = '';
}

function ClickActionReminder()
{ 

ShowBox();
Size = getSize();
getXY = getScrollXY();
var x = (Size[0]/2)- 200; 
var y = /*(Size[1]/2)- 200 +*/getXY[1] + 50;

var Forma = getElement('reminder_password');
ScrollObj = Forma;
Forma.style.top = y + 'px';
Forma.style.left = x + 'px';
Forma.style.display = '';
	
}

function ClickActionGenerate()
{ 
ShowBox();
Size = getSize();
getXY = getScrollXY();
var x = (Size[0]/2)- 200; 
var y = /*(Size[1]/2)- 200 +*/getXY[1] + 50;

var Forma = getElement('generate_password');
ScrollObj = Forma;
Forma.style.top = y+'px';
Forma.style.left = x + 'px';
Forma.style.display = '';
	
}




function pop_motion(mode)
{

//popup_width = popup.scrollHeight;
//popup_height = popup.scrollWidth;

popup_width = popup.scrollWidth;
popup_height = popup.scrollHeight;


//setOut(popup_width+","+popup_height);

	if(mode == 'show')
		{
		var new_val;
		
if(parseInt(popup.style.width) < (popup_width-1))
			{
			//	popup.style.width = parseInt(popup.style.width) + deltaWH;
			
				popup.style.left = (parseInt(popup.style.left) - deltaWH)+"px";
				popup.style.width = (parseInt(popup.style.width) + deltaWH)+"px";			
			if(parseInt(popup.style.height) < 40)
			{
			popup.style.height = parseInt(popup.style.height) + deltaWH;			
			
			
			var delta = parseInt(popup.style.top) - deltaWH; 
			
			if(delta <= (document.documentElement.scrollTop || document.body.scrollTop)+5)
				{
				delta = (document.documentElement.scrollTop || document.body.scrollTop)+5;
				}
			
			popup.style.top = delta+"px";
			}
			}
		else	
		if(parseInt(popup.style.height) < popup_height)
			{
			popup.style.width = popup_width;
			//if(wait_for_continue) { clearTimeout(timer); timer=null; waiting=true; return 0; }
			
			var delta_h = ((parseInt(popup.style.height)+SOffset < popup_height && parseInt(popup.style.height) > SOffset)?deltaWH:SdeltaWH)
			popup.style.height = parseInt(popup.style.height) + delta_h;
			
			var delta = parseInt(popup.style.top) - delta_h; 
			
			if(delta <= (document.documentElement.scrollTop || document.body.scrollTop)+5)
				{
				delta = (document.documentElement.scrollTop || document.body.scrollTop)+5;
				}
			
			popup.style.top = delta+"px";
			
			
			}

		if(parseInt(popup.style.width) >= popup_width && parseInt(popup.style.height) >= popup_height)	
				{
				popup.scrollTop=0;
				popup.scrollLeft=0;
				clearTimeout(timer);
				timer = null;			
				}		
				else timer = setTimeout('pop_motion("'+mode+'")',ShowSpeed);
		}
	else
	if(mode == 'hide')
		{

		if(parseInt(popup.style.height) > 40)
			{
			new_val = parseInt(popup.style.height) - ((parseInt(popup.style.height) > SOffset)?deltaWH:SdeltaWH);
			if(new_val < 1) new_val = 1;
			popup.style.height = new_val;
			}
			else 
			{
		if(parseInt(popup.style.width) > 1)
			{
			if(parseInt(popup.style.width) > 1)
				{
				new_val = parseInt(popup.style.width) - deltaWH;
				if(new_val < 1) new_val = 1;
				
				popup.style.width = new_val;
				}
			if(parseInt(popup.style.height) > 1)
				{
				new_val = parseInt(popup.style.height) - deltaWH;
				if(new_val < 1) new_val = 1;
				
				popup.style.height = new_val;
				}
				
			}
			else 
			{ 
			popup.style.width = 1;
			popup.style.height = 1; 
			}
			
			}
			
		if((parseInt(popup.style.width) == 1) && (parseInt(popup.style.height) == 1))	
				{
				popup.scrollTop=0;
				popup.scrollLeft=0;
				popup.style.visibility = 'hidden';
				clearTimeout(timer);
				timer = null;
				}		
				else timer = setTimeout('pop_motion("'+mode+'")',HideSpeed);
		}	



}
function showTooltip(tip_id,x,y)
{
popup = getElement(tip_id);

if(!popup.id) return 0;

popup.lastChild.innerHTML = form_create("");


alert(popup.innerHTML);
return 0;

popup.style.visibility = 'visible';
popup.scrollTop=0;
popup.scrollLeft=0;

top = y;
//popup.style.top = (((sh/2) - (parseInt(popup.style.height)/2))+top)-100;

sp = true;

if(timer != null)
	{
	clearTimeout(timer);
	timer = null;
	}

//if(popup.onclick==null)
//	popup.onclick = function(event) { hideTooltip() };

pop_motion('show');


}

function hideTooltip()
{
sp = true;
if(timer != null)
	{
	clearTimeout(timer);
	timer = null;
	}
	
pop_motion('hide');
wait_for_continue = true;
if(window['onscroll'] != undefined)
window['onscroll'] = undefined;
}
