function CheckImgByName(ImgName) {
  var prop;
  var img; 
  img = document.getElementsByName(ImgName)[0];
  //alert("imagename = " + img.src);
  if (img.complete == false) {
    //alert("image complete = false. src=" + img.src);
    window.setTimeout("CheckAllImages()", 1000);
    //img.width = 10;
    //img.height = 10;
  }

  if (img.complete == true) {
    ResizeImage(img);
  }
  return true;
}

function CheckAllImages() {
  var img;
  var ImgCnt = document.images.length;
  var i = 0;
  
  //alert ("Check3 reached. Number Images: " + ImgCnt);
  img = document.images[i];
  //alert ("Image0: " + img.src)
  for (i = 0; i < ImgCnt; i++) {
    img = document.images[i];   
    
    if (img.complete == false) {
      //alert("CheckImg3: image complete = false. src=" + img.src);
      window.setTimeout("CheckAllImages()", 2000);
      //img.width = 10;
      //img.height = 10;
    }

    if (img.complete == true) {
      ResizeImage(img);
    }
  }//end for
    
  return true;
}

function ResizeImage (img) {
  var prop;
  //alert("Resize it: " + img.width +"/"+ img.height);
  if (img.width > 400) {
    prop = img.height/img.width;
    img.width = 400;
    img.height = prop*img.width;
  }
  if (img.height > 400) {
    prop = img.width/img.height;
    img.height = 200;
    img.width = prop*img.height;
  }
  //alert("Resized: " + img.width +"/"+ img.height);


}
