var ie4=document.all != null;
var ns6=document.getElementById && !document.all;
var _objVentana ;
var MensajeActual = null;
var _liga = "";

function Ocultar(_Resultado)
{
	if(MensajeActual != null)
	{
		if (_Resultado != null)
			MensajeActual.Resultado = _Resultado;
		MensajeActual.Ocultar();
		if (MensajeActual.onCerrar != null)
			MensajeActual.onCerrar(MensajeActual);
	}
}

function MensageDialogo()
{

	this.Width = 400;
	this.Left = 0;
	this.Top = 0;
	this.Opacity = '90';
	this.CSSClassBarraEncabezado = "EncabezadoTabla";
	this.TextoBarraEncabezado = "Texto";
	this.CSSClassMensaje = "Texto";
	this.TextoMensaje = "textoMensaje";
	this.CSSClassBotonMensaje = "EstiloBoton";
	this.ModoBotonMensaje = 3; //0=Ninguno, 1=Aceptar, 2=Cancelar, 3=AceptarCancelar
	this.BloquearContenido = true;
	this.TipoVentana = 1;
	this.UrlVariables = "";
	this.UrlValores = "";	
	this.UrlFrame = "";
	this.AltoFrame = "";
	this.DivGrande;
	this.DivMediano;
	this.TamanoDivGrande="1380px";

	this.CrearHtmlFondoPaginaVentanaMensaje = function()
	{
		var divFondoPaginaVentanaMensaje = document.createElement("div");
				divFondoPaginaVentanaMensaje.id = "FondoPaginaVentanaMensaje";
				divFondoPaginaVentanaMensaje.style.position = "absolute";
				divFondoPaginaVentanaMensaje.style.backgroundColor = "White";
				divFondoPaginaVentanaMensaje.style.width = "100%";
				divFondoPaginaVentanaMensaje.style.height = this.TamanoDivGrande +"px";
				divFondoPaginaVentanaMensaje.style.left = "0px";
				divFondoPaginaVentanaMensaje.style.top = "0px";
				divFondoPaginaVentanaMensaje.style.zIndex = 100;
			
		if (ie4)
				divFondoPaginaVentanaMensaje.style.filter = "alpha(opacity=50)";
			else
				divFondoPaginaVentanaMensaje.style.opacity=0.50
				
			document.body.appendChild(divFondoPaginaVentanaMensaje);
	}
	
	this.CrearHtmlMensaje = function(){		
		var divVentanaMensaje = document.createElement("div");
		var TamVentana = TamanoVentana();
		divVentanaMensaje.id = "VentanaMensaje";
		divVentanaMensaje.style.position = "absolute";
		divVentanaMensaje.style.zIndex = 101;
		divVentanaMensaje.style.width = this.Width + "px";		
		
		if(this.AltoFrame != "")
			divVentanaMensaje.style.height = this.AltoFrame + "px";		
			
		
		divVentanaMensaje.style.left = ((this.Left == 0) ? parseInt(TamVentana[0] / 2 - this.Width / 2) : this.Left) + "px";		
		if(this.TipoVentana == 16)
			divVentanaMensaje.style.top = "480px";
		else
			divVentanaMensaje.style.top = this.Top + "px";
		
		if (ie4)
			divVentanaMensaje.style.filter = "alpha(opacity=" + this.Opacity + ")";
		else
			divVentanaMensaje.style.opacity = this.Opacity / 100;
			
		listen("mouseup", divVentanaMensaje, dragapprovedOff);
		
		var HtmlMensaje = ObtenerHtmMensaje();
			
		divVentanaMensaje.innerHTML = HtmlMensaje;
		document.body.appendChild(divVentanaMensaje);
	}	
	
	this.Ocultar = function(){
		objVentanaMensaje = ns6 ? document.getElementById("VentanaMensaje") : document.all.VentanaMensaje;
		objFondoPaginaVentanaMensaje = ns6 ? document.getElementById("FondoPaginaVentanaMensaje") : document.all.FondoPaginaVentanaMensaje;
		if (objVentanaMensaje != null)
			document.body.removeChild(objVentanaMensaje);
		if (objFondoPaginaVentanaMensaje != null)
			document.body.removeChild(objFondoPaginaVentanaMensaje);
	}
	
	this.Mostrar = function(){
		MensajeActual = this;
		if (this.BloquearContenido)
		{
			var objFondoPaginaVentanaMensaje = ns6 ? document.getElementById("FondoPaginaVentanaMensaje") : document.all.FondoPaginaVentanaMensaje;
			if (objFondoPaginaVentanaMensaje == null)
				this.CrearHtmlFondoPaginaVentanaMensaje();
			else
				objFondoPaginaVentanaMensaje.style.visibility = "";
		}
		var objVentanaMensaje = ns6 ? document.getElementById("VentanaMensaje") : document.all.VentanaMensaje;
		if (objVentanaMensaje == null)
			this.CrearHtmlMensaje();
		else
			objVentanaMensaje.style.visibility = "";
	}
}

function ObtenerHtmMensaje()
{
	var stringHtml = "<table style='BACKGROUND-COLOR: #ffcc66' Width='100%' cellSpacing='0' cellPadding='0' border='0' ><tr><td class='bodyGrandeBold'>ACCESO</td><td align=right ><img src='images/cerrar.jpg' style='cursor : pointer;'  onclick='Ocultar(false);return false;'></td> </tr>";
	stringHtml +="<tr><td colspan='2' Width='100%' ><iframe src='FuncionesGenerales/LoginNido.aspx' Width='100%' frameborder='0' Style='BACKGROUND-COLOR: #66ccff' />"; 
	stringHtml +="</td></tr> </table>";
	return stringHtml;
}
function TamanoVentana() 
{
	var Tamano = [0, 0];
	Tamano = [document.documentElement.offsetWidth, document.documentElement.offsetHeight];
	return Tamano;
}
function dragapprovedOff()
{
	dragapproved=false;
}
function drag_drop(e){
	if(ie4 && dragapproved){
		objVentanaMensaje.style.left=tempx+event.clientX-offsetx;
		objVentanaMensaje.style.top=tempy+event.clientY-offsety;
		return false;
	}
	else if (ns6 && dragapproved){
		objVentanaMensaje.style.left=tempx + e.clientX-offsetx + "px";
		objVentanaMensaje.style.top=tempy + e.clientY-offsety + "px";
		return false;
	}
}
function initializedrag(e){
	objVentanaMensaje = ns6 ? document.getElementById("VentanaMensaje") : document.all.VentanaMensaje;
	var firedobj = ns6 ? e.target : event.srcElement;
	var topelement = ns6 ? "html" : (document.compatMode != "BackCompat" ? "documentElement" : "body");
	while (firedobj.tagName != topelement.toUpperCase() && firedobj.id != "BarraEncabezadoVentanaMensaje")
		firedobj = ns6 ? firedobj.parentNode : firedobj.parentElement;

	if (firedobj.id=="BarraEncabezadoVentanaMensaje"){
		offsetx = ie4 ? event.clientX : e.clientX;
		offsety = ie4 ? event.clientY : e.clientY;

		tempx = parseInt(objVentanaMensaje.style.left);
		tempy = parseInt(objVentanaMensaje.style.top);

		dragapproved = true;
		document.onmousemove = drag_drop;
	}
}
function listen(evento, elemento, funcion){
	if (elemento.attachEvent){ 
		elemento.attachEvent("on" + evento, funcion);
	}
			else if (elemento.addEventListener){ 
				elemento.addEventListener(evento, funcion, false);
	}
}	


function MostrarVentana()
{	
	_objVentana =  new MensageDialogo();
	_objVentana.AltoFrame = "300";
	_objVentana.Width = 300;
	_objVentana.Mostrar();	
}

function MostrarVentana(liga,altoDivGrande,topMensaje,leftMensaje)
{	
	//alert(liga);
	//alert("entro");
	_liga = liga;
	_objVentana =  new MensageDialogo();
	_objVentana.AltoFrame = "300";
	_objVentana.Width = 300;
	_objVentana.TamanoDivGrande=altoDivGrande;
	_objVentana.Top=topMensaje;
	_objVentana.Mostrar();	
}




function CerrarVentana(siAutoPostBack)
{
	Ocultar(true);
	//alert(_liga);
	if(_liga != "")
	{
		window.parent.location.href = "../" + _liga;
	}		
	else if(siAutoPostBack)
	{
		document.parent.forms[0].submit();
	}
	
}
