﻿function AutoSizeImages(maxW, maxH, img)
{
    var currH ;
    var currW ;
    var ratio ;
    if(maxW != undefined && maxW != null)
    {
        currH = img.height;
        currW = img.width;
        ratio = currH / currW;
        if(currW >= maxW)
        {
            currW = maxW;
            currH = currW * ratio;
        } 
        img.height = currH;
        img.width= currW;
    }
    
    if(maxH != undefined && maxH != null)
    {
        currH = img.height;
        currW = img.width;
        ratio = currH / currW;
        if(currH >= maxH)
        {
            currH = maxH;
            currW = currH / ratio;
        }
        img.height = currH;
        img.width= currW;
    }
}


/* PRUEBA 1 --> no funciona en IE
function initAutoSize()
{
    var imgs = document.getElementsByTagName('img');
    for(var i = 0; i < imgs.length; i++)
    {
        var img = imgs[i];
        
        var maxH = img.getAttribute('maxHeight');
        var maxW = img.getAttribute('maxWidth');
        if(maxW != null || maxH != null)
        {
            img.style.display = 'none';
            var maxH2 = img.getAttribute('maxHeight');
            var maxW2 = img.getAttribute('maxWidth');
            AutoSizeImages(maxW2, maxH2, img);
            img.style.display = 'block';
        }
    }
}

var onload = window.onload;

window.onload = function(e) 
{
    alert("hola");
    try{onload(e)}catch(e){}

    initAutoSize();
   
}
*/

/* PRUEBA 2 --> no funciona en IE
function initAutoSize()
{
    var imgs = document.getElementsByTagName('img');
    for(var i = 0; i < imgs.length; i++)
    {
        var img = imgs[i];
        var maxH = img.getAttribute('maxHeight');
        var maxW = img.getAttribute('maxWidth');
        if(maxW != null || maxH != null)
        {
            img.style.display = 'none';
            img.onload = function()
            {
                var maxH2 = this.getAttribute('maxHeight');
                var maxW2 = this.getAttribute('maxWidth');
                AutoSizeImages(maxW2, maxH2, this);
                this.style.display = 'block';
            }
        }
    }
}
*/

