window.addEvent('domready', function() { 
  popUp('index_inicio.html','850','400',true);
});

function popUp(direccion,ancho,alto,iframe){
	if(iframe){
		try{
			w.$('popUpIframe').dispose();
			w.$('cerrar_popUpIframe').dispose();
		}catch(ex){}
    if(window.parent){
        w=window.parent;
    }else{
        w=window;  
    }
    ocultarPopUp(w);
    var alto_ventana=w.getHeight();
    var scroll_ventana=w.getScrollTop();
    
    var fondo=w.document.createElement('div');
    fondo.id='fondo_popup';
    w.document.getElementsByTagName('body')[0].appendChild(fondo); 
    fondo.style.width=w.Window.getScrollWidth()+'px';   
    fondo.style.height=w.Window.getScrollHeight()+'px';
    
    var pos_y=Math.round((alto_ventana-alto)/2+scroll_ventana)
    var el=w.document.createElement('iframe');
    el.id='popUpIframe';
    el.src=direccion;
    el.scrolling='auto';
    el.frameBorder=0;
    el.style.width=ancho+'px';
    el.style.height=alto+'px';
    el.style.top=pos_y.toString()+'px';
    el.style.marginLeft='-'+Math.round(ancho/2).toString()+'px';
    w.document.getElementsByTagName('body')[0].appendChild(el);   
/*      var cerrar=w.document.createElement('img');
    cerrar.src='/img/popup/cerrar.png';
    $(cerrar).addClass('png');
    cerrar.onclick=function(){
    	try{	
    		w.$('popUpIframe').dispose();
    		w.$('cerrar_popUpIframe').dispose();
            w.$('fondo_popup').dispose();
    	}catch(ex){}
    	mostrarPopUp(w);
    }
    cerrar.id='cerrar_popUpIframe';*/
   // cerrar.style.marginLeft='-'+Math.round(ancho/2+14).toString()+'px';
    var offset_boton = 8;
    cerrar.style.marginRight='-'+(Math.round(ancho/2 - 5)-offset_boton).toString()+'px';
    //cerrar.style.top=(pos_y-12).toString()+'px'; 
    cerrar.style.top=(pos_y + 5 + offset_boton).toString()+'px'; 
    w.document.getElementsByTagName('body')[0].appendChild(cerrar);
    window.onscroll=function(){
			if (el)	el.style.top=Math.round((alto_ventana-alto)/2+window.getScrollTop()).toString()+'px';
			if (cerrar)	cerrar.style.top=Math.round((alto_ventana-alto)/2+window.getScrollTop()+5).toString()+'px';
		}
	}else{
		var cadena='';
		if(ancho || alto) cadena+='toolbar=0';
		if(ancho) cadena+=', width='+ancho;
		if(alto) cadena+=', height='+alto;
		ventana=window.open(direccion,'',cadena);
    ventana.focus();
	}
}

function ocultarPopUp(w){
		if(!w) w=window;
		w.$$('object','embed').each(function(el){
			var wmode=el.getAttribute('wmode');
			if(wmode) wmode=wmode.toLowerCase();		
			if(wmode!='transparent' && wmode!='opaque'){
				el.style.visibility='hidden';
			}
		}); 
}

function mostrarPopUp(w){
		if(!w) w=window;
		w.$$('object','embed').each(function(el){
			el.style.visibility='visible';
		}); 
}
function cerrarPopUp(){
   	    var w=window.parent;
		w.$('popUpIframe').dispose();
   		w.$('cerrar_popUpIframe').dispose();
		w.$('fondo_popup').dispose();
}
function cerrarPopUp2(){
  document.location="index.asp";
  var w=window.parent;
  w.$('popUpIframe').dispose();
  w.$('cerrar_popUpIframe').dispose();
  w.$('fondo_popup').dispose();
}
