/*
* Documento con funciones para manipular im?genes.
*/
function scale(imagen,cx,cy){
	
	img1 = new Image();
	img1.src = imagen.src;
	var ix = img1.width;
	var iy = img1.height;
	var recorteX = 0;
	var recorteY = 0;
	var rat = 0;
		
	//Si la imagen cabe en el contenedor
	if(ix <= cx && iy <= cy){
		img1.width = ix;
		img1.height = iy;
		imagen.width = img1.width;
		imagen.height = img1.height;
		imagen.style.display = 'inline';
		return;
	}
		
	
	//Si el ancho de la imagen cabe en el contenedor
	if(ix <= cx){
		recorteY = iy - cy;
		rat = 1 - (recorteY/iy);		
		img1.width = Math.floor(ix*rat);
		img1.height = Math.floor(iy*rat);
		imagen.width = img1.width;
		imagen.height = img1.height;
		imagen.style.display = 'inline';
		return;
	}
	
	//Si el alto de la imagen cabe en el contenedor
	if(iy <= cy){
		recorteX = ix - cx;
		rat = 1 - (recorteX/ix);		
		img1.width = Math.floor(ix*rat);
		img1.height = Math.floor(iy*rat);
		imagen.width = img1.width;
		imagen.height = img1.height;
		imagen.style.display = 'inline';
		return;
	}
	
	//Ya que la imagen no cabe en ninguna dimension, entonces intentemos ajustar en ancho
	recorteX = ix - cx;
	rat = 1 - (recorteX/ix);
	if((iy*rat) < cy){
		img1.width = Math.floor(ix*rat);
		img1.height = Math.floor(iy*rat);
		imagen.width = img1.width;
		imagen.height = img1.height;
		imagen.style.display = 'inline';
		return;
	}
	
	//No fue posible ajustar en ancho, entonces es necesario hacerlo en alto
	recorteY = iy - cy;
	rat = 1 - (recorteY/iy);
	img1.width = Math.floor(ix*rat);
	img1.height = Math.floor(iy*rat);
	
	
	imagen.width = img1.width;
	imagen.height = img1.height;
	imagen.style.display = 'inline';	
	return;
}
function esHorizontal(url){
	img = new Image();
	img.src = url;
		
	if(img.width > img.height)
		return true;
	else
		return false;	 
}
function imagenPopup(img){
	imag1 = new Image();
	imag1.src = img.src;
	window.open(imag1.src,'_blank','scrollbars=NO,resizable=NO,directories=NO,location=NO,status=YES,toolbar=NO,titlebar=NO,menubar=NO,width='+(imag1.width+20)+',height='+(imag1.height+20)+',top=0,left=0');
}

function abrirBajasta(url){
	ventanaPopup = window.open(url,"popupAdmonCanal","scrollbars=YES,resizable=YES,directories=NO,location=NO,status=NO,toolbar=NO,titlebar=YES,menubar=NO,width=100%,height=100%,top=0,left=0");
}

