var seMostroPublicidad = false;//true si ya cargo una vez la publicidad

window.onload = function(){  
  mostrarSky('contenedor','publicidadSky','publicidad120x600',codigoPublicidadSky);//carga el Sky
  abrirEnNuevaVentana();  
  if(typeof comscore != 'undefined'){document.getElementById("logoPuntofox").innerHTML = comscore;} //Imprime el codigo para el logo de .Fox
}

window.onresize = function(){
  mostrarSky('contenedor','publicidadSky','publicidad120x600',codigoPublicidadSky); //Actualiza la posicion del sky
}

/*
* 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: mostrarSky
* DESCRIPCION: Carga los codigos de la publicidad
* PARAMETROS:
*   string  idDivContenedor
*   string  idDivSky
*   string  idDivPublicidad
*   string  codigoPublicidad
*/
function mostrarSky(idDivContenedor,idDivSky,idDivPublicidad,codigoPublicidad){ 
  var ie=document.all;
  var dom=document.getElementById;
  var ns4=document.layers;
  anchoPantalla = (ie)? document.body.clientWidth : (dom)?window.innerWidth  : window.innerWidth;
  var divSky = document.layers ? document.layers[idDivSky] : document.getElementById ?  document.getElementById(idDivSky) : document.all[idDivSky];
  var divContenedor = document.layers ? document.layers[idDivContenedor] : document.getElementById ?  document.getElementById(idDivContenedor) : document.all[idDivContenedor];
  var anchoContenedor = divContenedor.offsetWidth;
  var anchoSky = 150;
  var separacionSky = 0;
  var anchoAceptable=anchoContenedor+anchoSky+(separacionSky*2);
  
  anchoIdeal = (anchoPantalla>anchoAceptable) ? anchoContenedor+separacionSky+anchoSky:anchoContenedor;
  margen=Math.round(((anchoPantalla-anchoIdeal)/2)-11);
  if(margen<=0){margen = 0;}
  posicionSky = margen+anchoContenedor+separacionSky;
       
  divContenedor.style.marginLeft = margen+'px';
  
  if(anchoPantalla>anchoAceptable){
    divSky.style.display='block';
    divSky.style.position='absolute';
    divSky.style.top='95px';
    divSky.style.left = posicionSky+'px';
    if(seMostroPublicidad==false){//Evita que se recargue la publicidad        
      var divPublicidad = document.layers ? document.layers[idDivPublicidad] : document.getElementById ?  document.getElementById(idDivPublicidad) : document.all[idDivPublicidad];
      divPublicidad.innerHTML = codigoPublicidad;
      seMostroPublicidad = true;
    }
  }else{
    divSky.style.display='none';
  }
}


function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
 alert("Tu direccion de email es incorrecta (revisa las @ y .'s)");
 return false;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) {
 alert("El username no es valido");
 return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
  for (var i=1;i<=4;i++) {
  if (IPArray[i]>255) {
  alert("El IP no es valido");
  return false;
  }
 }
 return true;
}
var domainArray=domain.match(domainPat);
if (domainArray==null) {
 alert("El nombre de dominio no es valido.");
 return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
  alert("La direccion debe terminar con un dominio de cuatro letras o un pais de dos.");
 return false;
}
if (len<2) {
 var errStr="Falta el hostname!";
 alert(errStr);
 return false;
}
var doms= Array("hotmail.com.mx","hotamil.com" ,"hotmai.com","hotmail.com.", "homail.com" ,"hotmil.com" ,"hotmail.com.pe" ,"htomail.com","hotmail.co" ,"hotmial.com" ,"hotmail .com" ,"@." ,"htmail.com","hormail.com" ,"latinamail.com" ,"latinamil.com" ,"hot mail.com","hormail.com" ,"holmail.com" ,"hotmail.com.com" ,".com.com" ,"hotmail.cm",".comm" ,"hotmail." ,"hot");
var splited=emailStr.split('@');
var dom=splited[1];
var test=true;
for (i=0; i<doms.length; i++)
{
  test=(test && !(doms[i]==dom));
}
if (!test) 
{ 
  alert('Por favor revise que su dominio este bien escrito');
  return false;
}
return true;
}

  function recomanda(){
   
    if (document.reco1.email.value.length < 7 || document.reco1.email.value == 'Tu Email'){
   	  document.reco1.email.focus();
	  alert('Ingresa tu email correctamente');
	  return false;
	}
    if (!emailCheck(document.reco1.email.value))
	{
	    document.reco1.email.focus();
		return false;
	}

    if (document.reco1.email2.value.length < 7 || document.reco1.email2.value == 'Email de Tu Amigo 1'){
   	  document.reco1.email2.focus();
	  alert('Ingresa el email de tu amigo correctamente');
	  return false;
	}
    if (!emailCheck(document.reco1.email2.value))
	{
	    document.reco1.email2.focus();
		return false;
	}
	
	if (document.reco1.email3.value.length >= 7 && document.reco1.email3.value != 'Email de Tu Amigo 2'){
      if (!emailCheck(document.reco1.email3.value))
  	  {
	      document.reco1.email3.focus();
		  return false;
	  }
	}	
  }

