window.onload = function(){
    ajustaScroll();
};
window.onresize = function (){
    ajustaScroll();
}
    
function obtieneMedidas ()
{
    dim = new Array();
    dim['largo'] = 0;
    dim['alto'] = 0;
    if (window.innerWidth)
    {
        dim['largo'] = window.innerWidth - 20;
        dim['alto'] = window.innerHeight;
    }
    else
    {
        if (document.documentElement && document.documentElement.clientWidth)
        {
            dim['largo'] = document.documentElement.clientWidth;
            dim['alto'] = document.documentElement.clientHeight;
        }
        else
        {
            if (document.body && document.body.clientWidth)
            {
                dim['largo'] = document.body.clientWidth;
                dim['alto'] = document.body.clientHeight;
            }
        }

    }
    dim['alto'] = dim['alto'] - 5;
    dim['largo'] = dim['largo'] - 5;
    return dim;
}

function ajustaScroll ()
{
    var medidas = obtieneMedidas();
    var aEncabezado = 0;
    objDiv = document.getElementById("encabezado");
    if (objDiv)
    {
        aEncabezado = objDiv.offsetHeight;
    }
    var aPie = 0;
    objDiv = document.getElementById("pie_p");
    if (objDiv)
    {
        aPie = objDiv.offsetHeight;
    }
    var aTitulo = 0;
    objDiv = document.getElementById("d_titulo");
    if (objDiv)
    {
        aTitulo = objDiv.offsetHeight;
    }

    var marginBody = 2;
    var aDivPrinc = medidas['alto'] - aEncabezado - aPie - aTitulo - marginBody;
    if (aDivPrinc > 300)
    {
        

		div_cot = document.getElementById("div_cot_i");
		if (div_cot)
		{

		overflowDiv("div_cot_i", true);
		ajustaDiv("div_cot_i", 0, aDivPrinc-20);
		overflowDiv("foto_cot", true);
		ajustaDiv("foto_cot", 0, aDivPrinc-20);
		
		}

		overflowDiv("cont_scr", true);
        ajustaDiv("cont_scr", 0, aDivPrinc);
		
    }
    else
    {
        overflowDiv("cont_scr", false);
    }
}

function overflowDiv (idDiv, accDiv)
{
    objDiv = document.getElementById(idDiv);
    if (objDiv)
    {
        if (accDiv)
        {
            objDiv.style.overflow = "auto";
        }
        else
        {
            objDiv.style.overflow = "visible";
        }
    }
}

function ajustaDiv (idDiv, lDiv, aDiv)
{
    objDiv = document.getElementById(idDiv);
    if (objDiv)
    {
        lDiv = entero(lDiv);
        if (lDiv > 0)
        {
            objDiv.style.width = lDiv + "px";
        }
        aDiv = entero(aDiv);
        if (aDiv > 0)
        {
            objDiv.style.height = aDiv + "px";
        }
    }
}

function entero (cant)
{
    catRet = isNaN(parseInt(cant)) ? 0 : parseInt(cant);
    return catRet;
}