﻿function abrir_ventana(_window_id, _url, _width, _height, _scroll_bars)
{
	if (_scroll_bars)
	{
		_scroll_bars = "yes";
	}
	else
	{
		_scroll_bars = "no";
	}

	var top = 0;
	var left = 0;	
	var ancho_maximo = screen.availWidth;
	var alto_maximo = screen.availHeight;
	var fullscreen = "no";

	if (_width == undefined || !_width || _width <= 0 || _width > ancho_maximo)
	{
		_width = ancho_maximo;
		fullscreen = "yes";	
	}
	else
	{
		left = Math.round((ancho_maximo - _width) / 2);
	}
	
	if (_height == undefined || !_height || _height <= 0 || _height > alto_maximo)
	{
		_height = alto_maximo;
		fullscreen = "yes";	
	}
	else
	{
		top = Math.round((alto_maximo - _height) / 2);
	}
	
	// Abrir la ventana
	var myWindow = window.open(_url, _window_id,
						  "copyhistory=yes," + 
					      "status=no," + 
				          "toolbar=no," + 
			              "menubar=no," +
		                  "directories=no," + 
							"resizable=yes," +
							"scrollbars=" + _scroll_bars + "," +
							"top=" + top + "," +
							"left=" + left + "," + 
							"screenY=" + top + "," +
							"screenX=" + left + "," + 
							"width=" + _width + "," + 
							"height=" + _height + "," +
							"channelmode=" + fullscreen);
	
	/*
	if (!myWindow)
	{
		alert("Por favor, haz CTRL + Click para poder abrir la ventana emergente");
		return false;
	}*/
	
	// Traer la ventana al frente
	myWindow.focus();
	//return myWindow;
};
