﻿
//var mostrarMensajeCerrar = true;
//listen("beforeunload",window,closeIt);
//var Formulario = null;
//function cargarFormulario()
//{
//	Formulario = document.forms['form1'];
//	if (!Formulario) {
//		Formulario = document.form1;
//	}
//	if(Formulario) 
//		listen("submit",Formulario,FormularioSubmit); 
//}
//function closeIt(e){
//	e.returnValue = obtenerMensaje();
//}
//function obtenerMensaje(){
//	if (mostrarMensajeCerrar && document.referrer == ""){
//		mostrarMensajeCerrar = true;
//		return "Quieres que se cierre la ventana";
//	}
//}
//function FormularioSubmit(){
//	mostrarMensajeCerrar = false;
//}
//function ControlBarra_Click(oToolbar, oButton, oEvent){
//	//alert(oButton.Key);
//	switch (oButton.Key)
//	{
//		case "Cerrar": 
//			mostrarMensajeCerrar = true; 
//			break;
//		default:
//			mostrarMensajeCerrar = false;
//			break;
//	}
//}
function listen(evento, elemento, funcion){
	if (elemento.attachEvent){ 
		elemento.attachEvent("on" + evento, funcion);
	}
	else if (elemento.addEventListener){ 
		elemento.addEventListener(evento, funcion, false);
	}
}

///////////Objeto MensageDialogo //////////////

var ie4=document.all != null;
var ns6=document.getElementById && !document.all;

var dragswitch=0;
var nsx;
var nsy;
var nstemp;

var MensajeActual = null;

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 Ocultar(_Resultado)
{
	if(MensajeActual != null)
	{
		if (_Resultado != null)
			MensajeActual.Resultado = _Resultado;
		MensajeActual.Ocultar();
		if (MensajeActual.onCerrar != null)
			MensajeActual.onCerrar(MensajeActual);
	}
}
function dragapprovedOff()
{
	dragapproved=false;
}
function MensageDialogo(_TextoMensaje, _TextoBarraEncabezado, _ModoBotonMensaje)
{
	this.Width = 350;
	this.Left = 0;
	this.Top = 0;
	this.Opacity = '90';
	this.CSSClassBarraEncabezado = "FondoCelda";
	this.TextoBarraEncabezado = "TextoEncabezado";
	this.CSSClassMensaje = "MenuIzquierdaItem";
	this.TextoMensaje = "Texto";
	this.CSSClassBotonMensaje = "EstiloBoton";
	this.ModoBotonMensaje = 3; //0=Ninguno, 1=Aceptar, 2=Cancelar, 3=AceptarCancelar
	this.BloquearContenido = true;
	this.Resultado = false;
	this.onCerrar = null;
	this.srcImagenCerrar = "../Images/close.gif";
	
	if (_TextoMensaje != null)
		this.TextoMensaje = _TextoMensaje;
	if (_TextoMensaje != null)
		this.TextoBarraEncabezado = _TextoBarraEncabezado;
	if (_TextoMensaje != null)
		this.ModoBotonMensaje = _ModoBotonMensaje;

this.CrearHtmlFondoPaginaVentanaMensaje = function() {
    //		var HtmlMensaje = "";
    //		HtmlMensaje += "<div id='FondoPaginaVentanaMensaje' style='position:absolute; background-color: White;width: 100%; height: 100%; left: 0px; top: 0px; z-index: 100; filter: alpha(opacity=40);'>";
    //		HtmlMensaje += "</div>";
    var divFondoPaginaVentanaMensaje = document.createElement("div");
    divFondoPaginaVentanaMensaje.id = "FondoPaginaVentanaMensaje";
    divFondoPaginaVentanaMensaje.style.position = "absolute";
    divFondoPaginaVentanaMensaje.style.backgroundColor = "White";
    divFondoPaginaVentanaMensaje.style.width = "100%";
    divFondoPaginaVentanaMensaje.style.height = window.screen.availHeight + window.screen.availHeight;

    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(){

		//HtmlMensaje += "<div id='VentanaMensaje' style='position: absolute; z-index: 100; width: " + this.Width + "px; left: " + this.Left + ";top: " + this.Top + "; filter: alpha(opacity=" + this.Opacity + ");' onmouseup='dragapproved=false'>";
		var divVentanaMensaje = document.createElement("div");
		var TamVentana = TamanoVentana();
		divVentanaMensaje.id = "VentanaMensaje";
		divVentanaMensaje.style.position = "absolute";
		divVentanaMensaje.style.zIndex = 100;
		divVentanaMensaje.style.width = this.Width + "px";
		divVentanaMensaje.style.left = ((this.Left == 0) ? parseInt(TamVentana[0] / 2 - this.Width / 2) : this.Left) + "px";
		divVentanaMensaje.style.top = ((TamVentana[1] - 100) / 2) + "px";
		if (ie4)
			divVentanaMensaje.style.filter = "alpha(opacity=" + this.Opacity + ")";
		else
			divVentanaMensaje.style.opacity = this.Opacity / 100;
		listen("mouseup", divVentanaMensaje, dragapprovedOff);
		
		var HtmlMensaje = "";
		HtmlMensaje += "<table border='0' width='100%' cellspacing='0' cellpadding='2' class='" + this.CSSClassBarraEncabezado + "'>";
		HtmlMensaje += "<tr>";
		HtmlMensaje += "<td>";
		HtmlMensaje += "<table border='0' width='100%' cellspacing='0' cellpadding='0'>";
		HtmlMensaje += "<tr>";
		HtmlMensaje += "<td id='BarraEncabezadoVentanaMensaje' style='cursor: hand' width='100%' onmousedown='initializedrag(event)'>";
		HtmlMensaje += "<div onselectstart='return false' onmouseover='dragswitch=1;' onmouseout='dragswitch=0' class='" + this.CSSClassBarraEncabezado + "'>";
		HtmlMensaje += this.TextoBarraEncabezado + "</div>";
		HtmlMensaje += "</td>";
		HtmlMensaje += "<td style='cursor: hand'>";
		HtmlMensaje += "<img src='" + this.srcImagenCerrar + "' onclick='Ocultar(false);return false' />";
		HtmlMensaje += "</td>";
		HtmlMensaje += "</tr>";
		HtmlMensaje += "<tr>";
		HtmlMensaje += "<td style='padding: 10px;' colspan='2'  class='" + this.CSSClassMensaje + "'>";
		HtmlMensaje += this.TextoMensaje;
		HtmlMensaje += "</tr>";
		HtmlMensaje += "<tr>";
		HtmlMensaje += "<td style='padding: 4px; text-align: center;' colspan='2' bgcolor='white'>";
		if (this.ModoBotonMensaje == 1 || this.ModoBotonMensaje == 3)
			HtmlMensaje += "<input id='ButtonAceptar' type='button' value='Aceptar' onclick='Ocultar(true);return true' hidefocus='hidefocus' class='" + this.CSSClassBotonMensaje + "' />";
		if (this.ModoBotonMensaje == 2 || this.ModoBotonMensaje == 3)
			HtmlMensaje += "<input id='ButtonCancelar' type='button' value='Cancelar' onclick='Ocultar(false);return false' hidefocus='hidefocus' class='" + this.CSSClassBotonMensaje + "' />";
		HtmlMensaje += "</td>";
		HtmlMensaje += "</tr>";
		HtmlMensaje += "</table>";
		HtmlMensaje += "</td>";
		HtmlMensaje += "</tr>";
		HtmlMensaje += "</table>";
		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 TamanoVentana() {
	var Tamano = [0, 0];
	Tamano = [document.documentElement.offsetWidth, document.documentElement.offsetHeight];
	return Tamano;
}