﻿function getWidthAndHeight() {

    var imgW = document.getElementsByName("PictureWidth")[0];
    var imgH = document.getElementsByName("PictureHeight")[0];
            
    if (this.width != imgW.value || this.height != imgH.value)
    {
        if (this.height * imgW.value / this.width <= imgH.value)
        {
            this.image.style.width = imgW.value
            this.image.style.height = this.height * imgW.value / this.width;
        }
        else 
        { 
            this.image.style.width = (this.width * imgH.value / this.height);
            this.image.style.height = imgH.value;
        }         
    }
   
    this.image.style.display = "";
    return true;
}
function loadFailure() {
    
    return true;
}

 function LoadImages() {

   var images = document.getElementsByTagName("img");
    for (var i = 0; i < images.length; i++) {
        var imagesname = document.getElementsByName("PICR")[i];
        if (imagesname) {
            imagesname.style.display = "none";
        }
    }

    for (var i = 0; i < images.length; i++) {
        var image = images[i];
        var toResize = false;
        if (image.attributes && image.attributes.getNamedItem("resize") && image.attributes.getNamedItem("resize").value == "true") {
            toResize = true;
        }
        if (toResize) {

            var myImage = new Image();

            myImage.image = image;
            myImage.onload = getWidthAndHeight;
           
            myImage.onerror = loadFailure;
           
            myImage.src = image.src;
        }
    }
}
window.onload = function() { LoadImages(); }

/**/