function allDone(id,img_w,img_h) {
	var ancho=0;
	var largo=0;
  var image = document.getElementById(id);
  var src2 = image.src;
  image = new Image();
  image.src = src2;
	var width = image.width ;
	var height = image.height;
	
  ancho=width;
  largo=height;
  
  // Si el ancho es mayor que el alto y que el ancho del hueco      
  if(width >= height || width >= img_w ){
  	if(width>img_w){
    	var quitar = width - img_w;                  
		  var porcent = (quitar * 100)/width;
      ancho = width - ((width * porcent)/100);   
		  largo = height - ((height * porcent)/100);
    }else{             
			if (width < height || width < img_w){
		  	if (width<img_w){
	      	var annadir = img_w - width;
		      var porcent = (annadir*100)/img_w;
		      if (porcent <= 5){
          	ancho = width + ((width*porcent)/100);
            largo = height + ((height*porcent)/100);
		      }else{
		        ancho=width;
        	  largo=height;
		      }
		  	}
      }
     }          
  }else{  //Si el alto es mayor que el ancho y que el hueco
  	if(height >= width || height >= img_h){
  		if (height > img_h){
	    	var quitar = height - img_h;                  
			  var porcent = (quitar * 100)/height;
    	  ancho = width - ((width * porcent)/100);   
		  	largo = height - ((height * porcent)/100);
  		}else{
				if (height < width || height < img_h){
			  	if (height<img_h){
	  	    	var annadir = img_h - height;
		  	    var porcent = (annadir*100)/img_h;
		    	  if (porcent <= 5){
          		ancho = width + ((width*porcent)/100);
            	largo = height + ((height*porcent)/100);
		      	}else{
		        	ancho=width;
        	  	largo=height;
						}
  				}
  			}
  		}
  	}
  }
	document.getElementById(id).width = ancho;
	document.getElementById(id).height = largo;
}


function reescHorizonly(id,img_w,img_h) {
	var ancho=0;
	var largo=0;
  var image = document.getElementById(id);
  var src2 = image.src;
  image = new Image();
  image.src = src2;
	var width = image.width ;
	var height = image.height;
	
  ancho=width;
  largo=height;
        
  if(width >= height || width >= img_w ){
	  if(width>img_w){
   		var quitar = width - img_w;                  
		  var porcent = (quitar * 100)/width;
      ancho = width - ((width * porcent)/100);   
		  largo = height - ((height * porcent)/100);

    }else{             
			if (width < height || width < img_w){
		  	if (width<img_w){
	        var annadir = img_w - width;
		      var porcent = (annadir*100)/img_w;
		      if (porcent <= 5){
          	ancho = width + ((width*porcent)/100);
            largo = height + ((height*porcent)/100);
		      }else{
		        ancho=width;
        	  largo=height;
		      }
		  	}
      }
     }          
   }
	document.getElementById(id).width = ancho;
	document.getElementById(id).height = largo;
}