
	function carregaFoto(src,dst,maxAmple,maxAlt) {
		var fot = new Image(); 
		fot.src = src;

		fot.onload=function() {
			var fotdst=document.getElementById(dst);
		
			if (fot!=null && fotdst!=null) {
				var ample=fot.width;
				var alt=fot.height;
				fotdst.src = fot.src;
		
				if(ample > maxAmple) {
					porcientoAnchura = parseInt(maxAmple/ample*100)
					ample = maxAmple
					alt = porcientoAnchura*alt/100
					}
			
				if (alt > maxAlt) {
					porcientoAltura = parseInt(maxAlt/alt*100)
					alt = maxAlt
					ample = porcientoAltura*ample/100
					}
				
				fotdst.height = alt;
				fotdst.width = ample;
				}
			}
		}
	
	var ventana;

	function afoto(cual){
		if (ventana!=null) { ventana.close(); }
		ventana=window.open('','ventana','resizable=yes,scrollbars=no');
		ventana.document.write('<html><head><title></title></head><body style="text-align: center;" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no"><img src="' + cual + '" onLoad="opener.redimensionar(this.width, this.height)">');
		ventana.document.close();
		}
	
	function redimensionar(ancho, alto){
		if (ancho>screen.width) ancho=screen.width-50;
		if (alto>screen.height) alto=screen.height-50;
		
		ventana.resizeTo(ancho+40,alto+60);
		ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2); 
		}
	
	function foto(id,src,maxAmple,maxAlt) {
		document.write("<img id='"+id+"' width='"+maxAmple+"' height='"+maxAlt+"' ONCLICK=\"afoto('"+src+"');\" />");

		carregaFoto(src,id,maxAmple,maxAlt);
		}
	
			