indicemodal=0;

// Ventana modal centrada
function showModal(html,wid){
	var width = wid? wid:600;
	indicemodal++;
	bgTrans();
	ocultarFlash();
	var idventana = '_ajax_modalcontent_'+indicemodal;
	if (!$(idventana)){
		var modalcontent = document.createElement('DIV');
		modalcontent.style.cssText = 'position:absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index:'+((1000*indicemodal)+1)+';';
		modalcontent.id = idventana;
		document.body.appendChild(modalcontent);
	}
	$(idventana).innerHTML = '<table border="0" width="100%" height="100%" align="center">'+
								'<tr><td align="center">'+
									'<div style="padding:20px 20px 5px 20px; width:'+width+'px; background-color:#fff">'+
										html+
										'<div style="width:100%;background-color:#fff"><img style="cursor:pointer" src="imagenes/closemodal.gif" onClick="hideModal();"></div>'+
									'</div>'+
								'</td></tr>'+
							 '</table>';
	$(idventana).style.top = getScrollY()+'px';
}


// Ocultar ventanas modales
this.hideModal = function(){
	mostrarFlash();
	if($('_ajax_modalcontent_'+indicemodal)){
		document.body.removeChild($('_ajax_modalcontent_'+indicemodal));
		document.body.removeChild($('_ajax_trans_'+indicemodal));
		indicemodal--;
	}
	if(indicemodal>0 && $('_ajax_modalcontent_'+indicemodal))
		$('_ajax_modalcontent_'+indicemodal).style.top = getScrollY();
}

function bgTrans(){
	if (!$('_ajax_trans_'+indicemodal)){
		var modal = document.createElement('DIV');
		if(document.all){
			modal.style.filter = 'Alpha(Opacity=80)';
		}else{
			modal.style.MozOpacity='0.8';
		}
		modal.style.backgroundColor = '#74848F';
		modal.style.position = 'absolute';
		modal.style.height = (document.body.scrollHeight?document.body.scrollHeight:document.documentElement.scrollHeight)+'px';
		modal.style.top = '0px';
		modal.style.left = '0px';
		modal.style.zIndex = 1000*indicemodal;
		modal.style.width = '100%';
		modal.className = 'ajax_trans';
		modal.id = '_ajax_trans_'+indicemodal;
		document.body.appendChild(modal);
	}
}


function getScrollY(){
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
		scrollY = window.scrollY;
	}
	return scrollY;
}


// Ocultacion de archivos flash para ventanas modales
function ocultarFlash(){
	var navegador = navigator.appName;
	var elemento = 'embed';
	if (navegador == "Microsoft Internet Explorer"){	//Discriminamos por navegador al usar distintos elementos.
		elemento = 'object';
	}	
	numFlash = document.getElementsByTagName(elemento).length;
	if (numFlash > 0){
		flash = new Array(numFlash);
		for( i=0 ; i<numFlash ; i++){
			var tamanio = new Array(2);	//Primer campo width, segundo height
			tamanio[0] = document.getElementsByTagName(elemento)[i].width;
			tamanio[1] = document.getElementsByTagName(elemento)[i].height;
			flash[i] = tamanio;
			document.getElementsByTagName(elemento)[i].width = '1px';
			document.getElementsByTagName(elemento)[i].height = '1px';
		}	
	}
}

function mostrarFlash(){
	var navegador = navigator.appName;
	var elemento = 'embed';
	if (navegador == "Microsoft Internet Explorer"){	//Discriminamos por navegador al usar distintos elementos.
		elemento = 'object';
	}
	if (numFlash > 0){		
		for( i=0 ; i<numFlash ; i++){				
			document.getElementsByTagName(elemento)[i].width = flash[i][0];
			document.getElementsByTagName(elemento)[i].height = flash[i][1];			
		}	
		flash = new Array(0);
	}
}
