openerwindow=window.top.opener;
resizeinit=false;
oldWidth=0;
oldHeight=0;

function resize(first){
	setTimeout('resize(false);',1000);
	try{
		winPosition=getWindowPosition();

		objDims=getDocumentDimensions('documentcontentarea');
		width=objDims[2];
		height=objDims[3];
		scrolling=false;
		if((screen.width - winPosition.x - 100 ) < width){
			width=screen.width-winPosition.x - 100;
			scrolling=true;
		}
		if((screen.height - winPosition.y - 100 ) < height ){
			height=screen.height - winPosition.y - 100;
			scrolling=true;
		}
		if(scrolling)
			extrawidth=40;
		else
			extrawidth=20;		
		
		extraheight=60;
		
		if (parseInt(navigator.appVersion)>3) {
			//a képernyő tetejére rakjuk az ablakot, ha kell
			if(resizeinit==false && width>50 && height>50){  
				objDims=getDocumentDimensions('documentcontentarea');
				width=objDims[2];
				height=objDims[3];

				winl = (screen.width - width - extrawidth) / 2;
				wint = (screen.height - height - extraheight) / 2;

				window.top.moveTo(winl,wint);
				resizeinit=true;
			}			
			//améretezünk, ha kell
			if((width>50 && height>50) && (oldWidth!=width || oldHeight!=height)) {
				window.top.resizeTo(width+extrawidth, height+extraheight);
				oldWidth = width;
				oldHeight = height;
			}
			
		}
	
		if(scrolling){
			window.scrolling = 'yes';
			window.document.body.scroll = 'yes';
			document.body.style.overflowX='hidden';
			//window.top.document.getElementById('dialogframe').style.overflow='auto';
		}
		else{
			window.scrolling = 'no';
			window.document.body.scroll = 'no';
			document.body.style.overflowX='auto';
		}
	}
	catch(e){error=e.description;}
}

function urlreplace(currentlocation,variable,value){
	if(currentlocation.indexOf(variable)==-1){
		if(currentlocation.indexOf('?')==-1)
			separator='?';
		else
			separator='&';		
		currentlocation = currentlocation + separator + variable + '=' + value;
	}
	else{
		splittedlocation = currentlocation.split(variable + '=');
		valuesplit=splittedlocation[1];
		if(valuesplit.indexOf('&')==-1)
			currentlocation=splittedlocation[0] + variable + '=' + value;
		else{
			splittedvalues=splittedlocation[1].split('&');
			currentlocation=splittedlocation[0] + variable + '=' + value; 
			for(i=1;i<splittedvalues.length;i++)
				currentlocation=currentlocation + '&' + splittedvalues[i];	
		}
	}
	return(currentlocation);
}

function refreshopener(getparam){
    var params=refreshopener.arguments;
    getparam = params[0];
	
	uniqueId = String(Math.random()).substr(2);
	currentlocation = openerwindow.location + '';
	window.top.refreshopenerwindowevent=true;
	if(getparam!='' && getparam!=undefined)
		getparam = '&' + getparam;
	else
		getparam = ''
	currentlocation=urlreplace(currentlocation + getparam, 'rfstamp', uniqueId);
	
	if(openerwindow.top.selfpopupwindow!=true)
		openerwindow.location=currentlocation;
	else
		openerwindow.top.dialogframe.location=currentlocation;	
}

function reloadopener(url){
	uniqueId = String(Math.random()).substr(2);
	window.top.refreshopenerwindowevent=true;
	currentlocation=urlreplace(url, 'rfstamp', uniqueId);
	if(openerwindow.top.selfpopupwindow!=true)
		openerwindow.location= currentlocation;
	else
		openerwindow.top.dialogframe.location=currentlocation;	
}

function reloadcontent(url){
	uniqueId = String(Math.random()).substr(2);
	window.location= url+ '&rfstamp=' + uniqueId;
}

function getDocumentDimensions(id){
	objActual=document.getElementById(id);
				
	obj=objActual;
	var objsize= new Array();
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
		obj=objActual;			
		var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
			{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	
	obj=objActual;	
	objsize.push(curleft-1);
	objsize.push(curtop-1);			
	objsize.push(obj.offsetWidth);
	objsize.push(obj.offsetHeight);	

	return(objsize);
}

/* Visszaadja az ablak pozicióját */
function getWindowPosition() {
	var coordinates=new Object();
	x = 0;
	y = 0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=window.screenLeft;
			y=window.screenTop;
			}
		else {
			x=window.screenX+(window.outerWidth-window.innerWidth);
			y=window.screenY+(window.outerHeight-24-window.innerHeight);
			}
		}
	else if (document.all) {
		x=window.screenLeft;
		y=window.screenTop;
		}
	else if (document.layers) {
		x=window.screenX+(window.outerWidth-window.innerWidth);
		y=window.screenY+(window.outerHeight-24-window.innerHeight);
		}

	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}


