var ventanaBusqueda = null;
var fotoAux1 = new Image();

function delLista (lista)
{
	for (var i = 0; i < lista.length; i++)
	{
		lista[i] = null;
		i--;
	}
}

var isNS4 = (document.layers) ? 1 : 0;
var isIE4 = ((document.all) && !isNS4)? 1 : 0;
var isMoz = ((document.getElementById) && (!isNS4) && (!isIE4)) ? 1 : 0;
var NS = (navigator.appName == "Netscape") ? true : false;

function getWindowHeight() {
	if (isNS4)
		return(window.innerHeight);
	if (isIE4)
		return(document.body.clientHeight);
	return(-1);
}

function getWindowWidth() {
	if (isNS4)
		return(window.innerWidth);
	if (isIE4)
		return(document.body.clientWidth);
	return(-1);
}
function resize ()
{
	var w = getWindowWidth();
	var h = getWindowHeight();
	if (document.getElementById("tablaMain"))
	{
		document.getElementById("tablaMain").width = w;
		document.getElementById("tablaMain").height = h;
	}
}
function agregar_favoritos (titulo)
{
	var url = "http://" + window.location.hostname;
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4))
	{
		window.external.AddFavorite (url, titulo);
	}
	else
	{
		if (navigator.appName == "Netscape")
			window.alert ("Presione Crtl+D para agregar este sitio en sus Bookmarks");
	}
}
function agregar_inicio ()
{
	//incluye esta línea justamente al comienzo del body
	//<IE:HOMEPAGE ID="obj_pagina_inicio" />
	var url = "http://" + window.location.hostname;
	obj_pagina_inicio.style.behavior = 'url(#default#homepage)';
	obj_pagina_inicio.setHomePage (url);
}
function cargar_ventana (url, anchura, altura)
{
	openWindow (url, "", anchura, altura, "no", "no");
}
var ventanaBusqueda;
var fotoAux1 = new Image();

function verFoto(urlFoto) {
/*
	var cont = "<html><head><title>Ver Foto</title></head>\n";
	cont += "<body bgcolor=#F3F3F3 scroll=no><table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
	cont += "<tr><td align=center><img src=\"/js/reloj_arena.gif\" border=0><p><font face=verdana size=1>Cargando imagen...</font></td>\n";
	cont += "</tr></table>\n";
	cont += "</body></html>";
	openWindow ("", "ventanaBusqueda", 250, 300, "no", "no");
	ventanaBusqueda.document.open();
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
	fotoAux1.onload=loadFoto;
	fotoAux1.src = urlFoto;
*/
//	ventanaBusqueda.document.body.onload = fitWindowToPic(ventanaBusqueda);
	imgToLoad = new Image();
	imgToLoad.src = urlFoto;
	imgToLoad.onload = createWindowWithPicture(ventanaBusqueda, imgToLoad);
}

function createWindowWithPicture(hWindow, img) {
	if (hWindow && (!hWindow.closed)) {
		hWindow.close();
		hWindow = null;
	}
	hWindow = window.open('', 'pic_popup',
			'width=250, height=300, left=0, top=0, resizable=yes, scrollbars=no, status=no');
	hWindow.document.writeln("<html>\n<head>\n<title>Ver imagen</title>");
	hWindow.document.writeln("<script type=\"text/javascript\">");
	hWindow.document.writeln("function imageLoaded(img) {");
	if (window.innerWidth) {
		hWindow.document.writeln("\twindow.resizeBy(img.width - window.innerWidth + 50, img.height - window.innerHeight + 50);");
		hWindow.document.writeln("\twindow.resizeBy(img.width - window.innerWidth, img.height - window.innerHeight);");
	} else if (document.documentElement && document.documentElement.clientWidth) {
		hWindow.document.writeln("\twindow.resizeBy(img.width - document.documentElement.clientWidth, img.height - document.documentElement.clientHeight);");
	} else if (document.body) {
		hWindow.document.writeln("\twindow.resizeBy(img.width - document.body.clientWidth, img.height - document.body.clientHeight);");
	}
	if (navigator.appName == "Microsoft Internet Explorer") {
		hWindow.document.writeln("\twindow.moveTo((screen.availWidth - document.body.offsetWidth) / 2, (screen.availHeight - document.body.offsetHeight) / 2);");
	} else {
		hWindow.document.writeln("\twindow.moveTo((screen.availWidth - window.outerWidth) / 2, (screen.availHeight - window.outerHeight) / 2);");
	}
	hWindow.document.writeln("}\n</script>");
	hWindow.document.writeln("</head>");
	hWindow.document.writeln("<body bgcolor=\"#000000\" scroll=\"no\" leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">");
	hWindow.document.writeln("<img src=\"" + img.src + "\" border=\"0\" onload=\"imageLoaded(this);\">");
	hWindow.document.write("</body>\n</html>\n");
	hWindow.document.close();
	hWindow.focus();
}

function loadPictureInWindow(hWindow, img) {
	hWindow.alert(img.width);
	hWindow.document.images[0].src = img.src;
	fitWindowToPic(hWindow);
}

function fitWindowToPic(hWindow) {
	img = hWindow.document.images[0];
	iWidth = (NS) ? hWindow.innerWidth : hWindow.document.body.clientWidth;
	iHeight = (NS) ? hWindow.innerHeight : hWindow.document.body.clientHeight;
	hWindow.alert(img.width); hWindow.alert(img.height);
	iWidth = img.width - iWidth;
	iHeight = img.height - iHeight;
	hWindow.resizeBy(iWidth, iHeight);
	hWindow.moveTo(
			Math.round((screen.width - hWindow.width) / 2),
			Math.round((screen.height - hWindow.height) / 2));
}

function verFotoImprimir (urlFoto)
{
	var cont = "<html><head><title>Ver Foto</title></head>\n";
	cont += "<body bgcolor=#F3F3F3 scroll=no><table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
	cont += "<tr><td align=center><img src=\"/js/reloj_arena.gif\" border=0><p><font face=verdana size=1>Cargando imagen...</font></td>\n";
	cont += "</tr></table>\n";
	cont += "</body></html>";
	openWindow ("", "ventanaBusqueda", 250, 300, "no", "no");
	ventanaBusqueda.document.open();
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
	fotoAux1.onload=loadFotoImprimir;
	fotoAux1.src = urlFoto;
}
function loadFotoImprimir ()
{
	if (!ventanaBusqueda || ventanaBusqueda.closed)
		return (false);
	var w = fotoAux1.width + 10;
	var h = fotoAux1.height + 79;
	if (w > screen.width - 20)
	{
		var w2 = screen.width - 20;
		h = Math.round (h * w2 / w);
		w = w2;
	}
	if (h > screen.height - 60)
	{
		var h2 = screen.height - 60;
		w = Math.round (w * h2 / h);
		h = h2;
	}
	var cont = "<html><head><title>Ver Foto</title></head>\n";
	cont += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onKeyDown=\"window.close();\" onContextMenu=\"return (false);\">\n";
	cont += "<div id=capafoto style=\"position:absolute; width:" + w + "px; height:" + h + "px; z-index:1; left: 0px; top: 0px; overflow: hidden;\">\n";
	cont += "<img src=\"/js/null.gif\" border=0 width=" + (w - 10) + " heigth=" + (h - 29) + ">\n";
	cont += "</div>\n";
	cont += "<img name=foto src=\"/js/null.gif\" border=0 width=" + (w - 10) + " heigth=" + (h - 29) + ">\n";
	cont += "<div align='center'><input type='button' onClick='print()' value='Imprimir'><div>";
	cont += "</body></html>";
	ventanaBusqueda.resizeTo (w, h);
	var left = Math.round (screen.width / 2) - Math.round (w / 2);
	if (h > screen.height - 100)
		var top = 20;
	else
		var top = Math.round (screen.height / 2) - Math.round (h / 2);
	ventanaBusqueda.moveTo (left, top);
	ventanaBusqueda.document.open();
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
	ventanaBusqueda.document.images["foto"].src = fotoAux1.src;
}
function loadFoto ()
{
	if (!ventanaBusqueda || ventanaBusqueda.closed)
		return (false);
	var w = fotoAux1.width + 10;
	var h = fotoAux1.height + 49;
	if (w > screen.width - 20)
	{
		var w2 = screen.width - 20;
		h = Math.round (h * w2 / w);
		w = w2;
	}
	if (h > screen.height - 60)
	{
		var h2 = screen.height - 60;
		w = Math.round (w * h2 / h);
		h = h2;
	}
	var cont = "<html><head><title>Ver Foto</title></head>\n";
	cont += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onKeyDown=\"window.close();\" onContextMenu=\"return (false);\">\n";
	cont += "<div id=capafoto style=\"position:absolute; width:" + w + "px; height:" + h + "px; z-index:1; left: 0px; top: 0px; overflow: hidden;\">\n";
	cont += "<img src=\"/js/null.gif\" border=0 width=" + (w - 10) + " heigth=" + (h - 29) + ">\n";
	cont += "</div>\n";
	cont += "<img name=foto src=\"/js/null.gif\" border=0 width=" + (w - 10) + " heigth=" + (h - 29) + ">\n";
	ventanaBusqueda.resizeTo (w, h);
	var left = Math.round (screen.width / 2) - Math.round (w / 2);
	if (h > screen.height - 100)
		var top = 20;
	else
		var top = Math.round (screen.height / 2) - Math.round (h / 2);
	ventanaBusqueda.moveTo (left, top);
	ventanaBusqueda.document.open();
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
	ventanaBusqueda.document.images["foto"].src = fotoAux1.src;
}
function abreVentanaModal (win, form, action, target)
{
	win.onLoad = enviaForm (form, action, target);
}
function enviaForm (form, action, target)
{
	form.submit();
	form.action = action;
	form.target = target;
}
function openWindow (url, name, w, h, scrollbars, resizable, otras)
{
	if (ventanaBusqueda && !ventanaBusqueda.closed)
		ventanaBusqueda.close();
	if (w <= 0 || h <= 0)
	{
		if (w <= 0)
			w = screen.width - 10;
		if (h <= 0)
			h = screen.height - 60;
		var left = top = 0;
	}
	else
	{
		var left = Math.round (screen.width / 2) - Math.round (w / 2);
		if (h >= screen.height - 100)
			var top = 10;
		else
			var top = Math.round (screen.height / 2) - Math.round (h / 2);
	}
	var mas = "";
	if (otras != null)
		mas = ", " + otras;
	ventanaBusqueda = window.open (url, name, "top=" + top + ", left=" + left + ", width=" + w + ", height=" + h + ", scrollbars=" + scrollbars + ", resizable=" + resizable + ", status=no" + mas);
}

