/*
 * Script para uso de velo como emergente
 * 
 * AzteComp -- www.aztecomp.com
 * Carlos Alberto Yerena Lanza
 * <cyerena@aztecomp.com>
 * 24/05/2011
 * 
 */

////////////////////////////////////////////////////////////////////////////////////
// MODO DE USO
////////////////////////////////////////////////////////////////////////////////////
/* Incluir el script en el HEADER de la pagina
 * 
 * <script src="[ruta]/velo.js" type="text/javascript"></script>
 * 
 * 
 * Inicializar el script
 * 
 * window.onload = function(){
 * 		velo();
 * }
 * 
 * 
 * Abrir velo usar en el evento deseado
 * 
 * v_abreVentana(ancho,alto,posY,div_a_ocultar);
 * 
 * ejemplo
 * <button onclick="v_abreVentana(ancho,alto,posY);">Abre Ventana</button>
 * 
 * 
 * Cerrar velo en el evento deseado
 * 
 * v_cierraVentana(div_a_ocultar);
 * 
 * 
 * El uso de la ventana se realiza con innerHTML o AJAX al objeto DIV con id
 * 
 * v_ventana
 * 
 * 
 */
////////////////////////////////////////////////////////////////////////////////////
// Funciones para velo
////////////////////////////////////////////////////////////////////////////////////

var v_marco = null;
var v_velo = null;

try {
	window.addEventListener('resize',v_onres,false);
	window.addEventListener('scroll',v_fixed,false);
} catch(e) {
	window.attachEvent('onresize',v_onres);
	window.attachEvent('onscroll',v_fixed);
}
		
function velo(){
	div_velo = document.createElement('div');
	div_velo.setAttribute('style','display:none;position:absolute;top:0px;left:0px;opacity:.50;filter:alpha(opacity=50);background-color:#666666;z-index:1000;');
	div_velo.setAttribute('id','v_velo');
	div_marco = document.createElement('div');
	div_marco.setAttribute('style','overflow:auto;display:none;position:absolute;top:0px;left:0px;z-index:1001;');
	div_marco.setAttribute('id','v_marco');
	div_ventana = document.createElement('div');
	div_ventana.setAttribute('style','display:block;position:relative;border:1px solid #000000;background-color:#ffffff;margin:auto;-moz-border-radius: 10px;border-radius: 10px;padding:5px;');
	div_ventana.setAttribute('id','v_ventana');
	div_marco.appendChild(div_ventana);
	div_mensaje = document.createElement('div');
	div_mensaje.setAttribute('style','display:none;position:relative;border:1px solid #000000;background-color:#ffffff;margin:auto;-moz-border-radius: 10px;border-radius: 10px;padding:5px;');
	div_mensaje.setAttribute('id','v_mensaje');
	div_marco.appendChild(div_mensaje);
	document.body.appendChild(div_velo);
	document.body.appendChild(div_marco);
	try {
		v_marco = document.getElementById('v_marco');
	} catch (e) {}
	try {
		v_velo = document.getElementById('v_velo');
	} catch (e) {}
	try {
		v_mensaje = document.getElementById('v_mensaje');
	} catch (e) {}
	try {
		v_ventana = document.getElementById('v_ventana');
	} catch (e) {}
}

function v_abreMensaje(texto,ancho){
	var v_ventana = document.getElementById('v_ventana');
	var v_mensaje = document.getElementById('v_mensaje');
	ancho = '500';
	alto = '';
	arriba = '60';
	
	if(isNaN(arriba)){
		v_mensaje.style.top = '0px';
	}else{
		v_mensaje.style.top = arriba+'px';
	}
	if(isNaN(ancho)){
		v_mensaje.style.width = '';
	}else{
		v_mensaje.style.width = ancho+'px';
	}
	if(isNaN(alto)){
		v_mensaje.style.height = '';
	}else {
		try {
			v_mensaje.style.height = alto+'px';
		} catch (e) {}
		v_mensaje.style.overflow = 'auto';
	}
	
	v_onres();
	v_ventana.style.display = 'none';
	v_mensaje.style.display = 'block';
	v_mensaje.innerHTML = texto;
	v_mensaje.focus();
}

function v_cierraMensaje(){
	var v_ventana = document.getElementById('v_ventana');
	var v_mensaje = document.getElementById('v_mensaje');
	v_mensaje.style.display = 'none';
	v_ventana.style.display = 'block';
}

function v_abreVentana(ancho,alto,arriba,divDesabilitado){
	var v_ventana = document.getElementById('v_ventana');
	var v_mensaje = document.getElementById('v_mensaje');
	if(divDesabilitado != ''){
		document.getElementById(divDesabilitado).style.display = 'none';
	}
	ancho = parseInt(ancho);
	alto = parseInt(alto);
	arriba = parseInt(arriba);
	
	if(isNaN(arriba)){
		v_ventana.style.marginTop = '0px';
		v_ventana.style.marginBottom = '0px';
	}else{
		v_ventana.style.marginTop = arriba+'px';
		v_ventana.style.marginBottom = arriba+'px';
	}
	if(isNaN(ancho)){
		v_ventana.style.width = '';
	}else{
		v_ventana.style.width = ancho+'px';
	}
	if(isNaN(alto)){
		v_ventana.style.height = '';
	}else {
		v_ventana.style.height = alto+'px';
		v_ventana.style.overflow = 'auto';
	}
	
	document.body.style.overflow = 'hidden';
	v_onres();
	v_velo.style.display = 'block';
	v_marco.style.display = 'block';
	v_mensaje.style.display = 'none';
	v_ventana.style.display = 'block';
	v_ventana.focus();
}
	
function v_cierraVentana(divDesabilitado){
	var v_ventana = document.getElementById('v_ventana');
	var v_mensaje = document.getElementById('v_mensaje');
	
	if(divDesabilitado != ''){
		document.getElementById(divDesabilitado).style.display = 'block';
	}
	document.body.style.overflow = 'auto';
	v_onres();
	v_mensaje.style.display = 'none';
	v_ventana.style.display = 'none';
	v_velo.style.display = 'none';
	v_marco.style.display = 'none';
}
		
function v_onres(){
	try {
		v_velo.style.width = window.innerWidth+"px";
		v_velo.style.height = window.innerHeight+"px";
		v_marco.style.width = window.innerWidth+"px";
		v_marco.style.height = window.innerHeight+"px";
	} catch(e) {
		v_velo.style.width = document.documentElement.clientWidth+"px";
		v_velo.style.height = document.documentElement.clientHeight+"px";
		v_marco.style.width = document.documentElement.clientWidth+"px";
		v_marco.style.height = document.documentElement.clientHeight+"px";
	}
	v_fixed();
}
		
function v_fixed(){
	try {
		v_velo.style.top = window.pageYOffset+"px";
		v_marco.style.top = window.pageYOffset+"px";
	} catch(e) {
		v_velo.style.top = document.documentElement.scrollTop+"px";
		v_marco.style.top = document.documentElement.scrollTop+"px";
	}
}	
////////////////////////////////////////////////////////////////////////////////////

