//Creador por: I.S.C. Victor Hugo Zamarripa Gómez
//Fecha: 08/04/2009
var cierra=false;
//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,animacion){
 /*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){
  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;
   if (Alto_browser <=90)
    Alto_browser = document.documentElement.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;';
  }
  if (document.getElementById('pop' + npop))
   npop++;
  var pop_cnt='';
  //Creación del pop_up
  pop_cnt = pop_cnt + '<iframe id="pop' + npop + '" src="';
  pop_cnt = pop_cnt + '" scrolling="no" frameborder="0" style="position:absolute;top:-500px;border:1;display:block;z-index:2000" >';
  pop_cnt = pop_cnt + '</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' + npop + '" width="' + width + '" height="' + height + '" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" border="0" bordercolor="#000000">';
  pop_cnt = pop_cnt + '	<tr><td align="left"  valign="top" width="4%" background="http://www.inegi.org.mx/img/fondoenc1.gif" height="20"><img src="http://www.inegi.org.mx/img/MiniLogoInegi.bmp"  ></td><td align="left"  valign="center" width="92%" background="http://www.inegi.org.mx/img/fondoenc1.gif" height="20" style="COLOR: white"  ><b>&nbsp;' + titulo + '</b></td>';
  pop_cnt = pop_cnt + '	  <td align="right"  valign="top" width="4%" height="20" background="http://www.inegi.org.mx/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="http://www.inegi.org.mx/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%" width="100%" border="0"><tr ><td align="center" width="100%"> <iframe name="bufferFrame" id="ifrm' + npop + '" ' + Scoll + ' frameborder="0" align="middle" src="' + pagina_fuente + '" width="' + width + '" height="' + height + '" marginwidth="0" STYLE="display:block;' + Scroll_x + '"></iframe></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.getElementById('poptd').innerHTML="";
  if (animacion==1)
   document.getElementById('poptd').innerHTML=pop_cnt;
  else
   document.getElementById('poptd').innerHTML=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;
   var BodyWidth=0;
   if (document.body.offsetWidth>0) BodyWidth=document.body.offsetWidth;
   else BodyWidth=document.documentElement.offsetWidth;
   medidas= medidas + 'document.all.pop1' + npop + '.style.left =' + (((BodyWidth-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);
 }
 var alt_final=determina_altura('pop1' + npop ,'0',Height_vs,Alto_browser);
 mostrar_anuncio('pop' + npop ,'pop1' + npop ,-150,alt_final,'0',animacion);
}
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, animacion){
 if (!cierra){
  if (document.layers) document.layers[divId].visibility = 'visible';
  else if (document.all) document.all[divId].style.visibility = 'visible';
  else if (document.getElementById) document.getElementById(divId).style.visibility = 'visible';
 }
 else
  if (document.getElementById && navigator.appName!="Netscape") document.getElementById(divId).style.visibility = 'hidden';
  if (animacion==1){
   state=typeof topPos;
   if(state=='undefined') topPos=inicio_top;
  }
  else topPos = final_top;
  if((topPos < final_top) && animacion==1){
   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('" + divId + "','" + divId1 + "'," + inicio_top + "," + final_top + "," + habilitar_ventana_js_NS + "," + animacion + "	); "
   setTimeout(recursivo,25);
  }
  else{
   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;
   }
  }
}
function determina_altura(divId,habilitar_ventana_js_NS,alto_pred,Alto_browser){
 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 = ((Alto_browser / 2) - (alto_pop / 2));
 else if (document.all) termino_top = ((Alto_browser / 2) - (alto_pop / 2)) + document.body.scrollTop;
 else if (document.getElementById) termino_top = ((Alto_browser / 2) - (alto_pop / 2))+ document.body.scrollTop;
 return termino_top;
}
function replace(texto,s1,s2){
 return texto.split(s1).join(s2);
}
