var actualText, actualImg, actualURL,timer; 


function addCss(cssCode) {
var styleElement = document.createElement("style");
  styleElement.type = "text/css";
  if (styleElement.styleSheet) {
    styleElement.styleSheet.cssText = cssCode;
  } else {
    styleElement.appendChild(document.createTextNode(cssCode));
  }
  document.getElementsByTagName("head")[0].appendChild(styleElement);
}


addCss('.popup_cnt{position: absolute;top: 20px;z-order:1101;filter:alpha(opacity=100);-moz-opacity:1;opacity:1;text-align: center; width: 100%;}');
addCss('.popup_frame{z-order: 1000;position: absolute;top: 0px; left: 0px; width: 100%;height: 0px;background: #000000;text-align: center; filter:alpha(opacity=80);-moz-opacity:.80;opacity:.80;}');

function copyDataToClip(){
	if (document.all)//IE
		window.clipboardData.setData('test');
}

function getYScroll(){
	if (document.all)
		return document.documentElement.scrollTop;
	else
		return window.pageYOffset;
}

function popdown(e){
   if (!e) var e = window.event;
  
   var targ2 = e.srcElement || e.target;
  
   if (targ2.tagName == "INPUT"){
	targ2.select();
	return;
   }
  

   var popdiv = document.getElementById('popup_frame');
   document.body.removeChild( popdiv );
   //popdiv.style.visibility = "hidden";	
   popdiv = document.getElementById('popup_contents');
   //popdiv.style.visibility = "hidden";
   document.body.removeChild( popdiv );
   clearTimeout(timer);	
}

function getTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function sizeChange(){
	var htmlheight = document.body.parentNode.scrollHeight;  
	var htmlwidth  = document.body.parentNode.scrollWidth;  


	var windowheight, windowwidth; 
	if (window.innerHeight) windowheight=window.innerHeight;
	else if(document.documentElement.clientHeight) windowheight=document.documentElement.clientHeight;

	if (window.innerWidth) windowwidth=window.innerWidth;
	else if(document.documentElement.clientWidth) windowwidth=document.documentElement.clientWidth;

	var popdiv = document.getElementById('popup_frame');
	if (htmlheight > windowheight)
	{
		popdiv.style.height = htmlheight + 'px';
	}
	else
	{
		popdiv.style.height = windowheight + 'px';
	}

	if (htmlwidth > windowwidth)
		popdiv.style.width = htmlwidth + 'px';
}	

function pageLoaded(req){
   if (req.readyState == 4 && 
        (req.status==200 || window.location.href.indexOf("http")==-1)){

	var popdiv = document.getElementById('popup_contents');
 	popdiv.style.visibility = "visible";      
	popdiv.innerHTML = '<table width="10" style="background:#000000;word-wrap:break-word;" cellspacing="5" border="0" align="center"><tr><td>'+req.responseText+'<br/><input type="text" style="width: 90%;" id="address" /><br /><br /><font color="#ffffff">Kliknij aby zamkn±æ to okno.</font></td></tr></table>';
	//if (document.all) {
		popdiv.style.top =  getYScroll() + 10 + 'px';
		popdiv.style.position = 'absolute';
	//}
	document.getElementById('address').value = 'http://www.terrarium.com.pl'+actualURL;
	timer = setTimeout(sizeChange, 500);
   }
}

function popup(url){
   actualURL = url;
   var popdiv = document.getElementById('popup_frame');
   var popdiv2 = document.getElementById('popup_contents');
   if (popdiv == null){
	popdiv = document.createElement('div');
	popdiv.id = "popup_frame";
	popdiv.style.visibility = "hidden";	
	popdiv.style.width="100%";
	popdiv.className = "popup_frame";
            popdiv.innerHTML = '<div style="position:relative;top:'+(getYScroll()+20) +'px;color:#ffffff;">Trwa wczytywanie..</div>';
	popdiv.onclick = popdown;
	document.body.appendChild( popdiv );

	popdiv2 = document.createElement('div');
	popdiv2.id = "popup_contents";
	popdiv2.className = "popup_cnt";
	popdiv2.onclick = popdown;
	document.body.appendChild( popdiv2 );
   }

   sizeChange()
   popdiv.style.visibility = "visible";	

//AJAX------------------------------
   var page_request = false
   if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest();
   else if (window.ActiveXObject){ // if IE
	   try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP");
	   } 
	   catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){}
	   }
   }
   else
	return false

   page_request.onreadystatechange=function(){
	pageLoaded(page_request)
   }
   page_request.open('GET', url, true)
   page_request.send(null)
}
