
var tema = "alphacube";
var temaDialogo = "alphacube";

Window.keepMultiModalWindow = true;

function Aplicacion()
{
	this.ultimoId = 0;
	this.fxCargador = 0;
	this.margenInferior = 40;

	this.iniciar = function()
	{
		// Cargador
		if( typeof xajax != 'undefined' )
		{
			xajax.loadingFunction =  this.mostrarCargador.bind( this );
			xajax.endLoadingFunction = this.ocultarCargador.bind( this );
			xajax.errorLoadingFunction = this.mostrarError.bind( this );
		}
		if( document.body && window.top.cambiaAltura ) window.top.cambiaAltura( document.body.scrollHeight );
		this.cambiaTamanyo();
	}

	this.nuevoId = function()
	{
		Aplicacion.ultimoId++;
		return "ventana_id_" + Aplicacion.ultimoId;
	};

	this.mostrarCargador = function()
	{
		var cargando = $('cargando');
		if( cargando )
		{
			cargando.style.display = 'block'; //className = 'cargandoVisible';
		}
	};

	this.ocultarCargador = function()
	{
		var cargando = $('cargando');
		if( cargando )
		{
			cargando.style.display = 'none'; //className = 'cargandoOculto';
		}
	};

	this.mostrarError = function( msj, titulo )
	{
		this.ocultarCargador();

		msj = '<br /><div align=\"center\" ><span class=\"txt_msj_err\"><p>'+msj+'</p></span></div>'
		titulo = ( titulo == null ) ? 'Error' : titulo;
		this.abrirVentanaHTML( titulo, msj, 400, 250, true, true, false, false, true );
	};
	
	this.abrirVentanaHTML = function( titulo, contenido, ancho, alto, resizable, closable, modal, minimizable, maximizable )
	{
	 	ventana = new Window( 
	 		Aplicacion.nuevoId(), 
	 		{
	 			className: tema, 
	 			width: ancho, 
	 			height: alto, 
	 			title: titulo,
	 			resizable: resizable,
	 			minimizable: minimizable,
	 			closable: closable,
	 			minimizable: minimizable,
	 			maximizable: maximizable,
	 			showEffect: Effect.Appear,
	 			hideEffect: Effect.BlindUp,
	 			showEffectOptions: { duration: 0.1 },
	 			hideEffectOpcions: { duration: 0.4 }
	 		}
	 	);
	  	ventana.getContent().innerHTML= contenido;
	  	ventana.setDestroyOnClose();
	  	ventana.showCenter(modal);
	};

	this.abrirVentanaURL = function( titulo, dir, ancho, alto, resizable, closable, modal, minimizable, maximizable )
	{
		var id = Aplicacion.nuevoId()
		ventana = new Window(
	 		id,
	 		{
	 			className: tema,
	 			width: ancho,
	 			height: alto,
	 			title: titulo,
	 			resizable: false,
	 			closable: closable,
	 			minimizable: minimizable,
	 			maximizable: maximizable,
				url: dir,
				showEffect: Effect.Appear,
	 			hideEffect: Effect.BlindUp,
	 			showEffectOptions: { duration: 0.1 },
	 			hideEffectOptions: { duration: 0.4 }
			}
		);
	  	ventana.setDestroyOnClose();
	  	ventana.showCenter(modal);
	  	
	  	var sc = window.top.Placom.scrollPantalla();
	  	if( navigator.appVersion.indexOf('MSIE')>0 )
	  	{
	  	 	$(id+'_content').src = dir;
	  	}
	};

	this.abrirAlerta = function( msj, ira )
	{
		if( typeof ira == 'string' && ira != '' )
			Dialog.alert(
				msj,
				{
					windowParameters:
						{
							className: temaDialogo,
							width:350
						},
						buttonClass: "botonDialogo",
						okLabel: "Cerrar",
						ok: function(){ Placom.irA( ira ); return true; }
				});
		else
			Dialog.alert( 
				msj, 
				{ 
					windowParameters: 
					{ 
						className: temaDialogo, 
						width:350,
						showEffectOptions: { duration: 0.2 },
			 			hideEffectOptions: { duration: 0.2 }
					}, 
					buttonClass: "botonDialogo", 
					okLabel: "Cerrar"	
				} 
			);
	};
	
	this.cambiaTamanyo = function()
	{
		var tamanyo = Placom.tamanyoPantalla();
		
		var margenIzdo = ( tamanyo.ancho - 755 ) / 2;
		var cargando = $('cargando');
		if( cargando ) cargando.style.left = ( margenIzdo + 765 )+"px";
	};

	this.abrirFotoGaleria = function( idCat, idFto )
	{
		Placom.abrirPopUp( $('rutabase').href+'index.php/Index/Galeria/Idc/' + idCat + '/Idf/' + idFto, 735, 595 );
	};
	
	this.iniciar();
};

var Aplicacion = new Aplicacion();
Event.observe( window, "load", Aplicacion.iniciar.bind( Aplicacion ) );
Event.observe( window, "resize", Aplicacion.cambiaTamanyo.bind( Aplicacion ) );
