//Creador por: I.S.C. Victor Hugo Zamarripa Gómez
//Fecha: 08/04/2009

var cierra=false;


function lanzar()
{

crea_popup('Contenidos/AvisoEmergente.htm',500,200,'','','0',true,'Atenci&oacuten a usuarios','Atention users');
var alt_final=determina_altura('pop1','0',200);	;mostrar_anuncio('pop1',-150,alt_final,'0');
}



//Función que crea el pop_up recibe:
//	-pagina que mostrará dentro del pop_up
//	-ancho de ventana
//	-alto de ventana
//	-Bandera si es que llevara leyenda de cerrar ventana
//	-Titulo de la ventana
//	-Idioma si es ingles llevara valor i
function crea_popup(pagina_fuente,width,height,Close_wnd,titulo,idioma,npop)
{
    var faux = new Date();
    var FechaLimite = new Date(2009,6, 19,7,0);//(Año,mes,dia,hora,min)
    var fecha = new Date(faux.getYear(), faux.getMonth(), faux.getDate(), faux.getHours(), faux.getMinutes());

    if (fecha < FechaLimite) {
    
        /*
        minimos
        height=0;
        width=170;*/

        var Leyenda_cerrar = '';
        if (idioma == "i")
            Leyenda_cerrar = "Close window";
        else
            Leyenda_cerrar = "Cerrar ventana";





        //	if (parseInt(navigator.appVersion) >= 4 && navigator.javaEnabled()) 
        //	if (navigator.appName!="Netscape" || (navigator.appName=="Netscape" && habilitar_ventana_js_NS=="1"))
        //	{

        if (parseInt(navigator.appVersion) >= 4) {

            var isMac = (navigator.userAgent.indexOf("Mac") != -1);
            var olOp = (navigator.userAgent.toLowerCase().indexOf('opera') > -1 && document.createTextNode);  // Opera 7
            var olNs4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
            var olNs6 = (document.getElementById) ? true : false;
            var olKq = (olNs6 && /konqueror/i.test(navigator.userAgent));
            var olIe4 = (document.all) ? true : false;
            var olIe5 = false;
            var olIe55 = false; // Added additional variable to identify IE5.5+	

            var Alto_browser = 0;
            var Ancho_browser = 0;
            var Scoll = '';
            var Scroll_x = '';
            var Height_vs = 0;

            //Determina la altura de la ventana del browser
            if (document.layers) Alto_browser = window.innerHeight;
            else if (document.all) Alto_browser = document.body.offsetHeight;
            else if (document.getElementById) Alto_browser = window.innerHeight;

            //Determina la anchura de la ventana del browser	
            if (document.layers) Ancho_browser = window.innerWidth;
            else if (document.all) Ancho_browser = document.body.offsetWidth;
            else if (document.getElementById) Ancho_browser = window.innerWidth;
            Alto_browser = Alto_browser + 1;
            Height_vs = height + 90;


            //Si supera la altura del browser el pop_up, lo deja del tamaño de la altura del browser
            if (Height_vs > Alto_browser) {
                height = Alto_browser - 90;
                Height_vs = Alto_browser;
                Scoll = 'scrolling="yes"';
            }

            //Si supera la anchura del browser el pop_up, lo deja del tamaño del ancho del browser
            if ((width + 30) > Ancho_browser) {
                width = Ancho_browser - 30;

                Scroll_x = ';Overflow-x:scroll;';
            }

            var pop_cnt = '';
            //Creación del pop_up
            document.write('<iframe id="pop' + npop + '" src="');
            document.write('" scrolling="no" frameborder="0" style="position:absolute;top:-500px;border:1;display:block;z-index:2000" >');
            document.write('</iframe>');
            pop_cnt = pop_cnt + '<div id="pop1' + npop + '" style="position:absolute;top:-500;z-index:2001;display:block" height="' + height + '" visible=true src="" >';

            pop_cnt = pop_cnt + '<table cellpadding="0" cellspacing="2" bgcolor="#7FA3C7" border="0" height="100%" width="100%">';
            pop_cnt = pop_cnt + '  <tr ><td valign="top" align="center">';
            pop_cnt = pop_cnt + '	<table id="tabla" width="' + width + '" height="' + height + '" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" border="0">';
            pop_cnt = pop_cnt + '	<tr><td align="left"  valign="top" width="4%" background="img/fondoenc1.gif" height="20"><img src="img/fondoenc1.gif" /></td><td align="left"  valign="center" width="92%" background="img/fondoenc1.gif" height="20" style="COLOR: white"  ><b>SNIEG</b></td>';

            pop_cnt = pop_cnt + '	  <td align="right"  valign="top" width="4%" height="20" background="img/fondoenc1.gif"><a href="javascript:void(0)" onclick="esconde_anuncio(';

            pop_cnt = pop_cnt + "'pop" + npop + "','pop1" + npop + "')";
            pop_cnt = pop_cnt + '"><img src="img/Close.bmp" border="0" alt="' + Leyenda_cerrar + '"></a></td>';

            pop_cnt = pop_cnt + '  	</tr>';
            pop_cnt = pop_cnt + '<tr><td colspan=3 align="center" width="100%"><table height="100%"><tr ><td align="center"> <iframe name="bufferFrame" ' + Scoll + ' frameborder="0"  src="' + pagina_fuente + '" width="' + width + '" height="' + height + '"  STYLE="display:block;' + Scroll_x + '"></iframe></td></tr>';
            //		pop_cnt = pop_cnt + '<tr><td colspan=3 align="center" width="100%"><table height="100%"><tr ><td align="center"> </td></tr>';
            if (Close_wnd) {
                pop_cnt = pop_cnt + '<tr ><td align="center" valign="center"><a href="javascript:esconde_anuncio(';
                pop_cnt = pop_cnt + "'pop" + npop + "','pop1" + npop + "')";
                pop_cnt = pop_cnt + '">' + Leyenda_cerrar + '</a></center><br></td></tr>';
            }
            pop_cnt = pop_cnt + '</table></td></tr>	</table>';

            pop_cnt = pop_cnt + '  </td></tr>';
            pop_cnt = pop_cnt + '</table>';
            pop_cnt = pop_cnt + '</div>';


            document.write(pop_cnt);

            var medidas = '';

            if (document.layers) {
                medidas = medidas + 'document.layers.pop1' + npop + '.left= ' + (((window.innerWidth - 30) / 2) - (width / 2)) + ';';
                medidas = medidas + 'document.layers.pop1' + npop + '.width=' + (width + 4) + ';';
                medidas = medidas + 'document.layers.pop1' + npop + '.height=' + (height + 4) + ';';
                medidas = medidas + 'document.layers.pop' + npop + '.left=document.layers.pop1' + npop + '.left;';
                medidas = medidas + 'document.layers.pop' + npop + '.width=document.layers.pop1' + npop + '.width;';
                medidas = medidas + 'document.layers.pop' + npop + '.height=document.layers.pop1' + npop + '.height;';
            }
            else if (document.all) {
                var extra = 0;
                if (width >= 550)
                    extra = 10;
                else
                    extra = ((((550 - width) / 25) * 2) + 1) + 10;
                var extra_height = 0;


                medidas = medidas + 'document.all.pop1' + npop + '.style.left =' + (((document.body.offsetWidth - 30) / 2) - (width / 2)) + ';';

                medidas = medidas + 'document.all.pop1' + npop + '.style.width =' + (width + 4) + ';';
                medidas = medidas + 'document.all.pop1' + npop + '.style.height =' + (height + 4) + ';';
                medidas = medidas + 'document.all.pop' + npop + '.style.left=document.all.pop1' + npop + '.style.left;';
                medidas = medidas + 'document.all.pop' + npop + '.style.width=' + (width + extra) + ';';
                if (Close_wnd) extra_height = 70;
                medidas = medidas + 'document.all.pop' + npop + '.style.height=' + (height + extra_height) + ';';

            }
            else if (document.getElementById) {

                medidas = medidas + 'document.getElementById("pop1' + npop + '").style.left =' + (((window.innerWidth - 30) / 2) - (width / 2)) + ';';
                medidas = medidas + 'document.getElementById("pop1' + npop + '").style.width =' + (width + 4) + ';';
                medidas = medidas + 'document.getElementById("pop1' + npop + '").style.height =' + (height + 4) + ';';
                medidas = medidas + 'document.getElementById("pop' + npop + '").style.left = ' + (((window.innerWidth - 30) / 2) - (width / 2)) + ';';
                medidas = medidas + 'document.getElementById("pop' + npop + '").style.width =' + (width + 4) + ';';
                medidas = medidas + 'document.getElementById("pop' + npop + '").style.height =document.getElementById("pop' + npop + '").style.height;';

            }
            eval(medidas);

        }
        /*	}
        else
        {
        window.open(ventana_NS,'Emergente','left=350,top=300,width=400,height=250,toolbar=0,resizable=0');
        }*/

        var alt_final = determina_altura('pop1' + npop, '0', Height_vs);

        //mostrar_anuncio('pop1',-150,alt_final,'0');
        mostrar_anuncio('pop' + npop, 'pop1' + npop, -150, alt_final, '0');
    }//Termina la condición para considerar la fecha
}


function cerrar(){
    this.close();
	
}





//funcion esconde
function esconde_anuncio(divId,divId1) 	
{
if (document.layers) 
  {
	document.layers[divId].visibility = 'hide';
	document.layers[divId1].visibility = 'hide';
  }
else if (document.all) 
{
	document.all[divId].style.visibility = 'hidden';
	document.all[divId1].style.visibility = 'hidden';
}
else if (document.getElementById) 
{
	document.getElementById(divId).style.visibility = 'hidden';
	document.getElementById(divId1).style.visibility = 'hidden';
}
cierra=true;
}
//funcion muestra
function mostrar_anuncio(divId,divId1,inicio_top,final_top,habilitar_ventana_js_NS) 
{
  //if (navigator.appName!="Netscape" || (navigator.appName=="Netscape" && habilitar_ventana_js_NS=="1"))
  //{ 
	if (!cierra)
	{
	  if (document.layers) 
	  {
		//document.layers[divId1].visibility = 'visible';
		document.layers[divId].visibility = 'visible';
	  }
	  else if (document.all) 
	  {
		//document.all[divId1].style.visibility = 'visible';
		document.all[divId].style.visibility = 'visible';
	  }
	  else if (document.getElementById) 
	  {
		//document.getElementById(divId1).style.visibility = 'visible';
		document.getElementById(divId).style.visibility = 'visible';
	  }
	}
	else
	{
	  if (document.getElementById && navigator.appName!="Netscape") 
	  {
		//document.getElementById(divId1).style.visibility = 'hidden';
		document.getElementById(divId).style.visibility = 'hidden';
	  }
	}


	 state=typeof topPos;


	if(state=='undefined') topPos=inicio_top;

	if(topPos < final_top)
	{ 	

	topPos+=3;
	if (document.layers) 
	{
	document.layers[divId].top = topPos;
	document.layers[divId1].top = topPos;

	}
	else if (document.all) 
	{
	document.all[divId].style.top = topPos;
	document.all[divId1].style.top = topPos;

	}
	else if (document.getElementById) 
	{
	document.getElementById(divId).style.top = topPos; 
	document.getElementById(divId1).style.top = topPos; 


	}

//	var recursivo="mostrar_anuncio('" + divId1 + "'," + inicio_top + "," + final_top + "," + habilitar_ventana_js_NS + "); "
	var recursivo="mostrar_anuncio('" + divId + "','" + divId1 + "'," + inicio_top + "," + final_top + "," + habilitar_ventana_js_NS + "); "
	setTimeout(recursivo,25);


	}
 // }

}

function determina_altura(divId,habilitar_ventana_js_NS,alto_pred)
{


	//if (navigator.appName!="Netscape" || (navigator.appName=="Netscape" && habilitar_ventana_js_NS=="1"))
	//{
	var alto_pop=0;
	var termino_top=0;

	if (document.layers) alto_pop=document.layers[divId].clientHeight ;
	else if (document.all) alto_pop=document.all[divId].clientHeight ;
	else if (document.getElementById) alto_pop=document.getElementById(divId).offsetHeight ;
	if (alto_pop<=0) alto_pop=alto_pred;



	if (document.layers) termino_top = ((window.innerHeight / 2) - (alto_pop / 2)); 
	else if (document.all) termino_top = ((document.body.offsetHeight / 2) - (alto_pop / 2));
	else if (document.getElementById) termino_top = ((window.innerHeight / 2) - (alto_pop / 2));

	return termino_top;
//	}
}
function replace(texto,s1,s2)
{

	return texto.split(s1).join(s2);
}



