var urlSetIframe = "ifrsize.asp"
var margenReescalado = 20;
//
var actualHeight = 0;
function publishHeight(){
	var frId;
	if($("frameIdHidden")){
		frId = $("frameIdHidden").value;
	}
	else
	{
		var qs = parseQueryString(window.location.href)
		frId = qs["frameId"];
	}
	var newHeight = getBodyHeight();
	if(
		((actualHeight -margenReescalado) > newHeight ) 
		||
		((actualHeight + margenReescalado) < newHeight ) 
	){
		actualHeight = newHeight;
		if(actualHeight != 0) {
			var rndN = Math.floor(Math.random()*10000)
			var urlscript = urlSetIframe + "?op=SET&Id=" + frId + "&size=" + newHeight + "&rnd=" + rndN ;
			new Ajax.Request(urlscript,{})
		}
	}
}

function getBodyHeight()
{
    var height;
    var scrollHeight;
    var offsetHeight;

    if (document.height)
    {
        height = document.height;
    }
    else if (document.body)
    {
        if (document.body.scrollHeight)
        {
            height = scrollHeight = document.body.scrollHeight;
        }
        if (document.body.offsetHeight)
        {
            height = offsetHeight = document.body.offsetHeight;
        }

        if (scrollHeight && offsetHeight)
        {
            height = Math.max(scrollHeight, offsetHeight);
        }
    }

    return height;
}


function parseQueryString(url)
{
    url = new String(url);
    var queryStringValues = new Object();
    var querystring = url.substring((url.indexOf('?') + 1), url.length);
    var querystringSplit = querystring.split('&');

    for (i = 0; i < querystringSplit.length; i++)
    {
        var pair = querystringSplit[i].split('=');
        var name = pair[0];
        var value = pair[1];

        queryStringValues[name] = value;
    }

    return queryStringValues;
}

function startPublishHeight(){
	try{
		var x = window.parent.src;
		if(window.parent.fastResizeIframe)window.parent.fastResizeIframe()
	}catch(ex){
		setTimeout('setInterval("publishHeight()",500)',1000)
	}
}

Event.observe(window,"load",startPublishHeight)