function getElement(element_id)
    {
    return (document.all)?document.all[element_id]: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();

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 form_create(url)
{    
document.getElementById('pop_title').innerHTML = '<table><tr><td style="color:#FFFFFF; font-weight:bold;">Benachrichtigen Sie einen Bekannten &uuml;ber das interessante Angebot auf unserem Service</td><td width="10" style="cursor:pointer;" onclick="hideTooltip();" title="exit"><img src="http://jobs.wtc.pl/pics/exit.jpg" alt=""/></td></tr></table>';
document.getElementById('pop_title').style.backgroundColor='#10417B';
var html = '';
html += '<form>';
html += '<font style="color:#000000; font-weight:bold;">Email : </font><input type="text" id="email_link" style="width:100%;"/><br />';
html += '<font style="color:#000000; font-weight:bold;">Text :</font><br /><textarea rows="2" style="width:100%;" id="mail_body" name="mail_body" ></textarea><br />';
html += '<img src="/confirm/'+confirm_code+'/" style="float:left; margin:5px 5px 0px 0px;"><font style="color:#000000; font-weight:bold; float:left; margin:10px 0px 5px 0px;">Code eintragen :</font>';
html += '</font><input type="text" id="orgin_code" style="width:180px;"/><br />';
html += '<br /><center><img src="http://www.jobslocal.de/pics/send.gif" onClick="FormSubmit();" title="Send"></center></form>';
return html;
}


function form_create2(url,mail,body,response,orincode)
{    
//alert("url = "+url+" mail = "+mail+" body = "+body+" response ="+response);


getElement('pop_title').innerHTML = '<table style="width:100%; border:1px solid #FF0000;"><tr><td style="color:#FF0000; font-weight:bold; font-size:15px;">'+response+'</td><td width="10" style="cursor:pointer;" onclick="hideTooltip();" title="exit"><img src="http://jobs.wtc.pl/pics/exit2.jpg" alt=""/></td></tr></table>';
getElement('pop_title').style.backgroundColor='#FFFFFF';


var html = '';
html += '<form>';
if (mail)
html += '<font style="color:#000000; font-weight:bold;">Email : </font><input type="text" value="'+mail+'" id="email_link" style="width:100%;"/><br />';
else
html += '<font style="color:#000000; font-weight:bold;">Email : </font><input type="text" value="'+mail+'" id="email_link" style="width:100%; background-color:#FFE990;"/><br />';
html += '<font style="color:#000000; font-weight:bold;">Text :</font><br /><textarea rows="2" style="width:100%;" id="mail_body" name="mail_body" >'+body+'</textarea><br />';
html += '<img src="/confirm/'+confirm_code+'/" style="float:left; margin:5px 5px 0px 0px;"><font style="color:#000000; font-weight:bold; float:left; margin:10px 0px 5px 0px;">Code eintragen :</font>';
if (response =='Eingegebener Code fehlerhaft')
html += '</font><input type="text" id="orgin_code" value="'+orincode+'" style="background-color:#FFE990;width:180px;"/><br />';
else
html += '</font><input type="text" id="orgin_code" value="'+orincode+'" style="width:180px;"/><br />';
html += '<br /><center><img src="http://www.jobslocal.de/pics/send.gif" onClick="FormSubmit();" title="Send"></center></form>';
return html;
}



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 ClickAction(object,event, url_ogl)
{ 
form_create(UrlLink);
UrlLink = url_ogl;	

var ep = getEventPosition(event);

	var x = ep['x'];
	var y = ep['y'];
	var tooltip = getElement(tooltip_id);
		
	tooltip.style.left = x;
	tooltip.style.top = y;		

	showTooltip(tooltip_id,x+20,y-20);

}




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("");


//displayDebug(popup);
//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;
}
