/*INICIO DE PROCESOS*/
var seMostroSky = false;//true si ya cargo una vez la publicidad

window.onload = function(){ 
  if (strPais != 'GT'){
	  mostrarSky('contenedor',codigoPublicidadSky,anchoPublicidadSky,altoPublicidadSky);//carga el Sky
  }
  abrirEnNuevaVentana();
  if(comscore){document.getElementById("logoPuntofox").innerHTML = comscore;} //Imprime el codigo para el logo de .Fox
  limpiarTxt('txtBusqueda','Haz tu búsqueda aquí');//Agrega texto al input de Nickname
}
window.onresize = function(){
  mostrarSky('contenedor',codigoPublicidadSky,anchoPublicidadSky,altoPublicidadSky);//actualiza el Sky
}

/*FUNCIONES PARA MOSTRAR PUBLICIDAD*/
/*
* FUNCION: mostrarPublicidad
* DESCRIPCION: Carga los codigos de la publicidad
* PARAMETROS:
*   string  ID del area del publicidad
*   string  Codigo HTML de la publicidad
*/
function mostrarPublicidad(idDivPublicidad, codigoPublicidad){
  var divPublicidad = document.layers ? document.layers[idDivPublicidad] : document.getElementById ?  document.getElementById(idDivPublicidad) : document.all[idDivPublicidad];
  if(divPublicidad){
    divPublicidad.innerHTML = codigoPublicidad;
    return true;
  }
  return false;  
}
/*
* FUNCION: mostrarSky
* DESCRIPCION: Muestra la publicidad del Sky si la ventana tiene el ancho adecuado
* PARAMETROS:
*   string  ID del div Contenedor (del contenido)
*   string  ID del area del publicidad
*   string  Codigo HTML de la publicidad
*/
function mostrarSky(idDivContenedor, codigoPublicidad, anchoSky, altoSky){ 
  var ie=document.all;
  var dom=document.getElementById;
  var ns4=document.layers;
  anchoPantalla = (ie)? document.body.clientWidth : (dom)?window.innerWidth  : window.innerWidth;
  
  var divSkyPublicidad = document.layers ? document.layers['publicidadSky'] : document.getElementById ?  document.getElementById('publicidadSky') : document.all['publicidadSky'];
  var divContenedor = document.layers ? document.layers[idDivContenedor] : document.getElementById ?  document.getElementById(idDivContenedor) : document.all[idDivContenedor];
  var anchoContenedor = divContenedor.offsetWidth;
  var separacionSky = 5;
  var anchoAceptable=anchoContenedor+anchoSky+(separacionSky*2);
  
  anchoIdeal = (anchoPantalla>anchoAceptable) ? anchoContenedor+separacionSky+anchoSky:anchoContenedor;
  posicionSky = anchoContenedor+separacionSky;

  if(anchoPantalla>anchoAceptable){
    if(!divSkyPublicidad){
      var domDivSky = document.createElement('div');
      domDivSky.id = 'publicidadSky';
      domDivSky.style.display = 'block';
      domDivSky.style.overflow = 'hidden';
      domDivSky.style.width = anchoSky+'px';
      domDivSky.style.height = altoSky+'px';
      domDivSky.style.position = 'absolute';
      domDivSky.style.top = "0";
      domDivSky.style.left = posicionSky+'px';  
      document.body.appendChild(domDivSky);
    }
    
    if(seMostroSky==false){//Evita que se recargue la publicidad  
      seMostroSky = mostrarPublicidad('publicidadSky', codigoPublicidad);
    }else{
      if(divSkyPublicidad){
        divSkyPublicidad.style.display='block';
      }
    }
  }else{
    if(divSkyPublicidad){
      divSkyPublicidad.style.display='none';
    }
  }
}
/*
 *
 * FUNCIONES ADICIONALES
 *
 */ 
/*
* FUNCION: abrirEnNuevaVentana
* DESCRIPCION: Modifica todos los enlaces de clase 'NoFollow' y 'Extenal' para que abran en una nueva pagina
* PARAMETROS: Ninguno
*/
function abrirEnNuevaVentana(){
  var As = document.getElementsByTagName('a');
  for (var i = 0; i < As.length; i++){
    var el = As[i];
    if (el.getAttribute('rel') == 'external'||el.getAttribute('rel') == 'nofollow'){
      el.onclick = function(){
        window.open(this.href);
        return false;
      };
    }
  }
}
/*
* FUNCION: limpiarTxt
* DESCRIPCION: Agrega un texto predeterminado a un input y lo elimina al obtener el foco
* PARAMETROS:
*   string  ID del input a modificar
*   string  Texto por defecto
*/
function limpiarTxt(idTxt,textoPredeterminado){
  var txt = document.layers ? document.layers[idTxt] : document.getElementById ?  document.getElementById(idTxt) : document.all[idTxt];
  if(txt){
    txt.value = textoPredeterminado;
    txt.onfocus = function(){
      if(txt.value==textoPredeterminado){
        txt.value="";
      }
    }
  }
}
