
function addAutoResize(frm, onchange)
{

    if(frm._autoresizeHeight)
        return;

    frm._autoresizeHeight = 0;

    frm.scrolling = 'no';

    var isIE = !!(window.attachEvent && !window.opera);

    //var db = document.getElementById('debug');
    //db.innerHTML = 'blah';

    //var count = 0;

    var listener = function()
    {
        var doc = frm.contentWindow.document;

        if(doc.body)
        {
            var height = (isIE)? doc.body.scrollHeight: doc.body.offsetHeight;

            //db.innerHTML = count + ' ' + height;

            //++count;

            if(height != frm._autoresizeHeight)
            {
                frm._autoresizeHeight = height;
                frm.style.height = height + 'px';
                setTimeout(function()
                {
                    var frameScreen = getScreen(frm.contentWindow);

                    if(frameScreen.top > 0)
                    {
                        var scroll = frameScreen.top + getScreen(window).top;
                        frm.contentWindow.scrollTo(0,0);
                        window.scrollTo(0, scroll);
                    }
                }, 10);

                if(onchange)
                    onchange(frm, height);
            }

        }

        setTimeout(arguments.callee, 1000);
    }

    frm.onload = listener;

    listener();

}

function getScreen(w)
{
	var scrOfX = 0, scrOfY = 0;

	if(!w.document || !w.document.documentElement)
	{
		return {left: 0, top: 0, width: 0, height: 0};
	}


	if( typeof( w.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		scrOfY = w.pageYOffset;
		scrOfX = w.pageXOffset;
	} else if( w.document.body && ( w.document.body.scrollLeft || w.document.body.scrollTop ) )
	{
		//DOM compliant
		scrOfY = w.document.body.scrollTop;
		scrOfX = w.document.body.scrollLeft;
	} else if( w.document.documentElement && ( w.document.documentElement.scrollLeft || w.document.documentElement.scrollTop ) )
	{
		//IE6 standards compliant mode
		scrOfY = w.document.documentElement.scrollTop;
		scrOfX = w.document.documentElement.scrollLeft;
	}


	var width = (w.innerWidth)?w.innerWidth: w.document.documentElement.clientWidth;
	var height = (w.innerHeight)?w.innerHeight: w.document.documentElement.clientHeight;

	return {left: scrOfX, top: scrOfY, 'width': width, 'height': height};

}