var xDiff = new Number(100);
var yDiff = new Number(100);
var tiempo = new Number(150);

function getRefToDivMod( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	return document[divID];
}
/**
 *	Redimensiona la ventana del navegador al tamaño de un objeto -- generalmente
 *	un DIV que engloba toda la página
 */
function resizeWinTo( idOfDiv ) {
	var oH = getRefToDivMod( idOfDiv ); if( !oH ) { return false; }
	var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
	var x = window; x.resizeTo( oW + 200, oH + 200 );
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
        var height;
	if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
        height = (oH + ( (oH + 200 ) - myH ));
        if (height > screen.height)
                height = screen.height * 0.90;
	
	if( x.focus ) { x.focus(); }
	
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	
	if (x.resizeTo && !is_chrome) {
		x.resizeTo( oW + ( ( oW + 200 ) - myW ), height );
	} else if (x.resizeBy) {
		//para google chrome hay que hacer una triquiÃ±uela porque no calcula bien las dimensiones
		//obtiene las dimensiones de la pantalla
		var scW = screen.availWidth ? screen.availWidth : screen.width;
		var scH = screen.availHeight ? screen.availHeight : screen.height;

		//en chrome se tiene que usar el resizeby porque el resizeto no funciona
		var myWidth = 0, myHeight = 0;
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		
		//escala la ventana hasta el maximo disponible
		x.resizeBy(scW-myWidth, scH - myHeight);
		
		//a partir de ahi comienza a reducir
		xDiff = 100;
		yDiff = 100;
		setTimeout("reduce()", tiempo);
	}
}

function reduce() {
	if (xDiff>1) {
		//reduce en el ancho
		setTimeout("reduce()", tiempo);
		
		window.scrollTo(1,0);
		
		if (getScrollX() == 0) {
			window.resizeBy(-xDiff,0);
		} else {
			window.resizeBy(xDiff, 0);
			xDiff = Math.round(xDiff*0.5);
		}
	} else if (yDiff>1) {
		//reduce en el alto
		setTimeout("reduce()", tiempo);
		
		window.scrollTo(0,1);
		
		if (getScrollY() == 0) {
			window.resizeBy(0, -yDiff);
		} else {
			window.resizeBy(0, yDiff);
			yDiff = Math.round(yDiff*0.5);
		}
	} else {
		window.resizeBy(1, 1);
		//el tiempo se reduce desde el momento de la carga, dado que la primera
		//vez el chrome parece fallar en el calculo de las medidas
		tiempo = 40;
	}
}

function getScrollX() {
	var scrOfX = 0;
	scrOfX = document.body.scrollLeft;
	
	return scrOfX;
}

function getScrollY() {
	var scrOfY = 0;
	scrOfY = document.body.scrollTop;
	
	return scrOfY;
}
function popup(pagina, altura) {
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=750, height="+altura+", top=250, left=440";
	window.open(pagina,"",opciones);
}
