var POPDIV={
/////////////////
obj_PDid:"POPDIV",
obj_PDCid:"POPDIVCONTENTDIV",
need_animation: true, //true=igen; false=nem;
rate:15,
delay:20,
/////////////////
temp_top:0,
selboxes:[],
flashes:[],

obj_PD:"undefined",
obj_PDC:"undefined",

timerId:0,
imageTimerID:0,

isDOM:false,
isIE:false,
isIEWin:false,
ieVers:0,
tip:"",

init:function()
{
	if(document.getElementById)
	{
		this.isDOM=true;
		if(document.all && !window.opera)
		{
			this.isIE=true;
			this.isIEWin=this.isIE && /win/.test(navigator.userAgent.toLowerCase());
			this.ieVers=parseFloat(navigator.appVersion.split("MSIE")[1]);
		}
		
		return true;
	}
	else
	{
		alert('Az Ön böngészője nagyon elavult.\nHasználjon modernebb böngészőt!\npl. Internet Explorer 8+, Firefox 3+, Opera 10+\n\nYour browser is too old.\nUse modern browser!\nLike:Explorer 8+, Firefox 3+, Opera 10+...');
		return false;
	}
},

pop_div_mutat: function (f,kw,kh,tip,tit)
{
	this.tip=tip;
	
	var kep;
	if(tip=='img')
	{
		kep=f+'?'+ new Date().getTime();
	}
	
	this.init();

	if(!this.isDOM)
	{
		return;
	}	

	this.createPD();
	this.createPDC();

	kw=parseInt(kw,10);
	kh=parseInt(kh,10);
	
	var scrS=this.screenSize();

/*	
	var w=scrS['w'];
	var h=scrS['h'];
	var t=scrS['t'];
*/
	var w=scrS.w;
	var h=scrS.h;
	var t=scrS.t;

	//save top position:
	this.temp_top=t;
	
	//scroll to top, left
	self.scrollTo(0, 0);

	this.hideFlash();
	this.hideSelectbox();

	var cnt="<table id='POPDIV_cntTable' cellspacing='0' cellpadding='0' border='0' style='background-color:#fff;color:#000;'>\n<tr>\n<td align='right' class='a10' style='padding:3px 10px 3px 0'><a href='javascript:void(0)' onclick='POPDIV.pop_div_rejt();return false' style='color:#00f'><span style='font-family:Arial;font-size:10px'>Bezár - Close</span><img src='img/popdivclose.png' width='20' height='20' border='0' style='margin-left:5px' align='middle' alt='bezár - close' title='bezár - close' /></a></td></tr>";
	
	if(!tit)
	{
		tit='';
	}
	
	tit=tit.replace(/\'/g,"&#039;");
	var alt_tit=tit.replace(/<br \/>/g," &bull; ");
	alt_tit=alt_tit.replace(/\[:sortores:\]/g," ");
	alt_tit=this.strip_tags(alt_tit);
	tit=tit.replace(/\[:sortores:\]/g,"<br />");		
	
	if(this.isIE)
	{
		alt_tit=alt_tit.replace(/<br \/>/g,"\n").replace(/<br>/g,"\n");
	}
	else
	{
		alt_tit=alt_tit.replace(/<br \/>/g," ").replace(/<br>/g," ");
	}
	
	switch(tip)
	{
		case 'iframe':
			cnt+="<tr><td><div style='border-right:10px solid #fff;border-bottom:10px solid #fff;border-left:10px solid #fff'><iframe id='popdivElement' src='"+f+"' width='"+kw+"' height='"+kh+"'  marginwidth='0' marginheight='0' frameborder='0' align='middle' scrolling=no style='padding:0'></iframe></div></td></tr></table>";
			break;

		case 'img':
			cnt+="<tr><td style='padding:0px 10px 0px 10px;text-align:center' align='center'><a href='javascript:void(0)' onclick='POPDIV.pop_div_rejt();return false'><img id='popdivElement' src='"+kep+"' width='"+kw+"' height='"+kh+"' border='0' alt='"+alt_tit+"' title='"+alt_tit+"' /></a></td></tr>";

			if(tit!="")
			{
				cnt+="<tr><td class='a12' align='center' style='width:"+(kw+20)+"px; padding:5px 0px 10px 0px'>"+tit+"</td></tr>";
			}
			else
			{
				cnt+="<tr><td style='width:"+(kw+20)+"px;line-height:10px'>&nbsp;</td></tr>";
			}
			cnt+="</table>\n";
			break;
	}
	
	POPDIV.obj_PDC.innerHTML=cnt;
	
	var bh=parseInt(this.getBodySize().h,10);
	if(bh>0)
	{
		this.obj_PD.style.height=bh+'px';
	}	
	
	var full_kw=this.o('POPDIV_cntTable').scrollWidth;
	var full_kh=this.o('POPDIV_cntTable').scrollHeight;

	this.obj_PDC.style.width=parseInt(full_kw,10)+'px';
	this.obj_PDC.style.height=parseInt(full_kh,10)+'px';
	
	var kleft=( w/2 - (full_kw/2) )+'px';
	var ktop=( h/2 - (full_kh/2) );
	ktop = ktop>=10 ? (ktop+'px') : "10px";

	//pozicionálás, méretezés:
	this.obj_PDC.style.left=kleft;
	this.obj_PDC.style.top=ktop;
		
	//ha nagyobb a kép,mint a div:
	if(parseInt(this.obj_PD.style.height,10)<=full_kh)
	{
		this.obj_PD.style.height=(full_kh+100)+"px";
	}
	if(parseInt(this.obj_PD.style.width,10)<=full_kw)
	{
		this.obj_PD.style.width=(full_kw+100)+"px";
	}
	
	//opera hibajavítás:
	if(window.opera)
	{
		this.obj_PD.scrollIntoView(true);
	}

	if(this.tip=='img')
	{
		POPDIV.imageTimerID=0;
		POPDIV.imageTimerID = window.setInterval(function()
		{
			POPDIV.checkLoadedImg(kw,kh);
		},200);
	}
	else if(this.tip=='iframe')
	{
		this.dispCont(kw,kh);
		this.obj_PDC.style.visibility="visible";
	}
},

checkLoadedImg: function(kw,kh)
{
	if(this.o('popdivElement').complete)
	{
		window.clearInterval(POPDIV.imageTimerID);
		POPDIV.imageTimerID=0;
		POPDIV.dispCont(kw,kh);
		return;
	}

},
	
dispCont: function(kw,kh)
{
	if(this.need_animation && this.tip=="img")
	{
		if(this.isIEWin)
		{
			this.o('POPDIV_cntTable').style.filter="revealTrans(duration=0.8, transition=8)";
			this.o('POPDIV_cntTable').filters.revealTrans.Transition=Math.floor(Math.random()*23);
			this.o('POPDIV_cntTable').filters.revealTrans.stop();
			this.o('POPDIV_cntTable').filters.revealTrans.apply();
			this.obj_PDC.style.visibility="visible";
			this.o('POPDIV_cntTable').filters.revealTrans.play();
			this.obj_PDC.style.visibility="visible";
		}
		else
		{
			this.o('popdivElement').style.width=0;
			this.o('popdivElement').style.height=0;
			this.obj_PDC.style.visibility="visible";
			this.ani(kw,kh);
		}
	}
},

ani: function(kw,kh){

	var rW,rH,d;
	window.clearInterval(POPDIV.timerId);
	POPDIV.timerId=0;
	window.clearInterval(POPDIV.imageTimerID);
	POPDIV.imageTimerID=0;
	rW=Math.round(kw/this.rate);
	rH=Math.round(kh/this.rate);
	d=this.o("popdivElement").style;
	POPDIV.timerId=window.setInterval(function(){POPDIV.ani2(d,kw,kh,rW,rH);},this.delay);
 },

ani2: function(d,kw,kh,rW,rH)
{
	var maxW,maxH;
	if(parseInt(d.width,10)<kw )
	{
		if(parseInt(d.width,10)+rW>kw)
		{
			d.width=kw + "px";
		}
		else
		{
			d.width=(parseInt(d.width,10)+rW)+"px";
		}
		maxW=false;
	}
	else
	{
		maxW=true;
	}
	if(parseInt(d.height,10)<kh )
	{
		if(parseInt(d.height,10)+rH>kh)
		{
			d.height=kh + "px";
		}
		else
		{
			d.height=(parseInt(d.height,10)+rH)+"px";
		}
		maxH=false;
	}
	else
	{
		maxH=true;
	}

	if(maxW && maxH)
	{
		window.clearInterval(POPDIV.timerId);
		POPDIV.timerId=0;
	}
},


pop_div_rejt:function() {

	window.clearInterval(POPDIV.timerId);
	POPDIV.timerId=0;
	
	window.clearInterval(POPDIV.imageTimerID);
	POPDIV.imageTimerID=0;

	//kiürítés
	this.obj_PD.parentNode.removeChild(this.obj_PD);
	this.obj_PDC.parentNode.removeChild(this.obj_PDC);

	//Show hided flash divs
	this.showFlash();
	this.flashes.length=0;

	//Show hided selectboxes in IE6/IE5/IE4:
	this.showSelectbox();
	this.selboxes.length = 0;

	//scroll to temp_top
	self.scrollTo(0,this.temp_top);
	
	if (this.isIEWin)
	{
		window.attachEvent("onunload", POPDIV.cleanupIELeaks);
	}
},

getScrollerWidth: function ()
{
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    scr.style.overflow = 'hidden';
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';
    scr.appendChild(inn);
    document.body.appendChild(scr);
    wNoScroll = inn.offsetWidth;
    scr.style.overflow = 'auto';
    wScroll = inn.offsetWidth;
    document.body.removeChild(document.body.lastChild);
    return (wNoScroll - wScroll);
},

getBodySize: function()
{
	var bh=0;
	var bw=0;
	
	//Opera:
	if(window.opera)
	{
		bh=document.documentElement.scrollHeight;
		bw=document.documentElement.scrollWidth;
	}

	// Firefox:
	else if( window.innerWidth && window.scrollMaxX && window.innerHeight && window.scrollMaxY) 
	{
		bh = window.innerHeight + window.scrollMaxY;
		bw = window.innerWidth + window.scrollMaxX;
	}

	//all but Explorer Mac
	else if( document.body.scrollHeight > document.body.offsetHeight ) 
	{
		bh = document.body.scrollHeight;
		bw = document.body.scrollWidth;
	}
	
	//Explorer 6 Strict, Mozilla (not FF) and Safari
	else
	{
		bh = document.body.offsetHeight + document.body.offsetTop;
		bw = document.body.offsetWidth + document.body.offsetLeft;
	}
	
	if(document.all)
	{
		bw=Math.round(bw*0.999);
	}
	return {w : bw, h : bh};
},

createPD: function()
{
	var bod,ujDiv,firstEl;
        if(document.getElementsByTagName("body"))
        {
		bod=document.getElementsByTagName("body")[0];
        }
        else if(window.content.document.getElementsByTagName("body"))
        {
		bod=window.content.document.getElementsByTagName("body")[0];
        }
        else if(document.childNodes[1])
        {
		bod=document.childNodes[1];
        }
       
	ujDiv = document.createElement("div");
	ujDiv.setAttribute("title", "Bezár");
	ujDiv.id=this.obj_PDid;
	ujDiv.onclick=function(){POPDIV.pop_div_rejt();};
	ujDiv.style.backgroundColor='#000';
	if(this.isIE)
	{
		ujDiv.style.filter='alpha(opacity=70)';
		ujDiv.style.cursor='hand';	
	}
	else
	{
		ujDiv.style.opacity=0.7;
		ujDiv.style.cursor='pointer';
	}
	ujDiv.style.position='absolute';	
	ujDiv.style.width=this.getBodySize().w+"px";
	ujDiv.style.top=0;
	ujDiv.style.left=0;
	ujDiv.style.display='block';
	ujDiv.style.zIndex='999998';
	firstEl=bod.childNodes[0];
	bod.insertBefore(ujDiv,firstEl);
	this.obj_PD=this.o(this.obj_PDid);
},

createPDC: function()
{
	var ujContDiv;
	ujContDiv=document.createElement('div');
	ujContDiv.id=this.obj_PDCid;
	ujContDiv.style.textAlign='center';
	ujContDiv.style.backgroundColor='#fff'; 
	ujContDiv.style.position='absolute';
	ujContDiv.style.width=0;
	ujContDiv.style.height=0;
	ujContDiv.style.top=0;
	ujContDiv.style.left=0;
	ujContDiv.style.display='block';
	ujContDiv.style.visibility='hidden';
	ujContDiv.style.zIndex ='999999'; 
	this.o(this.obj_PDid).parentNode.insertBefore( ujContDiv, this.o(this.obj_PDid).nextSibling );
	this.obj_PDC=this.o(this.obj_PDCid);
},

strip_tags: function (str, allowed_tags)
{
    var key='', allowed=false;
    var matches=[];
    var allowed_array=[];
    var allowed_tag='';
    var i=0;
    var k='';
    var html='';
 
    var replacer=function(search, replace, str)
    {
        return str.split(search).join(replace);
    };
 
    if(allowed_tags)
    {
        allowed_array=allowed_tags.match(/([a-zA-Z]+)/gi);
    }

    str+= '';
 
    matches=str.match(/(<\/?[\S][^>]*>)/gi);
 
    for(key in matches)
    {
        if(isNaN(key))
        {
            // IE7 Hack
            continue;
        }
        html = matches[key].toString();
        allowed = false;
        for (k in allowed_array)
        {
            allowed_tag=allowed_array[k];
            i=-1;
            if(i !== 0){i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if(i !== 0){i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if(i !== 0){i = html.toLowerCase().indexOf('</'+allowed_tag);}
            if(i === 0)
            {
                allowed=true;
                break;
            }
        }
        if (!allowed)
        {
            str=replacer(html,"",str); // Custom replace. No regexing
        }
    }
    return str;
},

o: function(id)
{
	return document.getElementById(id);
},

hideFlash: function()
{
	//###### önálló EMBED OBJECT nélkül:
	var et= document.getElementsByTagName("embed");
	var etl=et.length;
	for (var e=0; e<etl; e++)
	{
		if(et[e].parentNode.style.display!='none'&&et[e].parentNode.tagName.toLowerCase()!="object")
		{
			if(this.getFlashExt(this.gal(et[e],'src')) )
			{
				et[e].style.display='none';
				this.flashes.push(et[e]);
			}
			else if(this.gal(et[e],'type')=="application/x-shockwave-flash")
			{
				et[e].style.display='none';
				this.flashes.push(et[e]);
			}
		}
	}
	
	//###### OBJECT param-el és embeddel vagy anélkül:	
	var ft=document.getElementsByTagName("object");
	var ftl=ft.length;
	for (var i=0; i<ftl; i++)
	{
		if (ft[i].style.display!='none' )
		{
			if(this.gal(ft[i],'classid')=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000')
			{
				ft[i].style.display='none';
				this.flashes.push(ft[i]);
			}
			else if( this.getFlashExt(this.gal(ft[i],'src')) )
			{
				ft[i].style.display='none';
				this.flashes.push(ft[i]);
			}
			else if( this.getFlashExt(this.gal(ft[i],'data')) )
			{
				ft[i].style.display='none';
				this.flashes.push(ft[i]);
			}			
			else if(this.gal(ft[i],'type')=="application/x-shockwave-flash")
			{
				ft[i].style.display='none';
				this.flashes.push(ft[i]);
			}
			else
			{
				var pt=ft[i].getElementsByTagName("param");
				var ptl=pt.length;
				for(var p=0; p<ptl; p++)
				{
					if( this.gal(pt[p],'name')=="movie" && this.getFlashExt(this.gal(pt[p],'value')) )
					{
						ft[i].style.display='none'; 
						this.flashes.push(ft[i]);
					}
					else if( this.gal(pt[p],'name')=="src" && this.getFlashExt(this.gal(pt[p],'value')) )
					{
						ft[i].style.display='none'; 
						this.flashes.push(ft[i]);
					}				
					else if( this.gal(pt[p],'name')=="data" && this.getFlashExt(this.gal(pt[p],'value')) )
					{
						ft[i].style.display='none'; 
						this.flashes.push(ft[i]);
					}
				}
			}
		}	
	}
},


gal: function (elem,attr)
{
	try
	{
		if(elem.getAttribute(attr)!==null||elem.getAttribute(attr)!="undefined")
		{
			return elem.getAttribute(attr).toLowerCase();
		}
		else
		{
			return eval("elem."+attr).toLowerCase();
		}
	}
	catch (e)
	{
		return null;
	}
},

getFlashExt: function(f)
{	
	if(!f)
	{
		return false;
	}
	var fe ="";
	var d = f.replace(/^\s|\s$/g, "");
	if (d.match(/\.(swf|SWF)/) )
	{
		fe = RegExp.$1;
	}
	return fe;
},

showFlash: function()
{
	var l=this.flashes.length;
	for(var i=0; i<l;i++)
	{
		this.flashes[i].style.display="";
	}
},

hideSelectbox: function()
{
	//IE6/IE5/IE4:
	if(this.isIE && this.ieVers<7)
	{
		selects = document.getElementsByTagName('select');
		var i;
		var sl=selects.length;
		for(i=0;i<sl;i++)
		{
			if(selects[i].style.display!="none")
			{
				selects[i].style.display="none";
				this.selboxes.push(selects[i]);
			}
		}		
	}
},

showSelectbox: function()
{
	if(this.isIE && this.ieVers<7)
	{
		var i;
		var sl=this.selboxes.length;
		for(i=0;i<sl;i++)
		{
			this.selboxes[i].style.display="block";
		}		
	}
},

screenSize: function()
{
	var hi,he,sw,sh,st,scrw;	
	hi = typeof(window.innerWidth) == 'number';
	he = document.documentElement && document.documentElement.clientWidth;
	
	if(hi)
	{
		sw = window.innerWidth;
		sh = window.innerHeight;
		st = pageYOffset;
	}
	else if(he)
	{
		sw = document.documentElement.clientWidth;
		sh = document.documentElement.clientHeight;
		st = document.documentElement.scrollTop;
	}
	else
	{
		sw = document.body.clientWidth;
		sh = document.body.clientHeight;
		st = document.body.scrollTop;
	}
	scrw= this.getScrollerWidth();
	if(scrw>0)
	{
		sw=(sw-scrw );
		sh=(sh-scrw );
	}	
	return {w:sw, h:sh, t:st};
},

cleanupIELeaks: function()
{
	var _o = document.getElementsByTagName("object");
	var _l = _o.length;
	for (var i = 0; i < _l; i++) {
		_o[i].style.display = "none";
		for (var x in _o[i])
		{
			if (typeof _o[i][x] == "function")
			{
				_o[i][x] = null;
			}
		}
	}
}

};//end class

function pop_div_mutat(f,kw,kh,tip,tit)
{
	POPDIV.pop_div_mutat(f,kw,kh,tip,tit);
}
