// Api de funciones para Todo Mac
// Programador: John D. Torres Barreto
// inicio: 10/09/2003 | 11/09/2003
// Funcion publicidad 01/04/2004


num = 8;
function numactual(){
  if (num < 10) {
    donde = 'numeros/num0' + num + '/default.html';
  } else {
    donde = 'numeros/num' + num + '/default.html';
  }
  window.location = donde;
}

// Esta funcion se utilizará para habilitar las publicidades en la página principal
// de cada #. Es importante estandarizar las medidas para que no se desarme la diagramación
// de la página. Los espacios disponibles son 5, con las siguientes medidas:

// 1. Banner superior (nuestro) 468 x 60 		-> id = pub01. Este no se toca
// 2. Banner superior der 162 x 60 			-> id = pub02
// 3. Menú izq 150 x 60	máximo				-> id = pub03
// 4. Menu izq 150 x 80 máximo				-> id = pub04
// 5. Central derecha bajo portada (capa) 150 x 60	-> id = pub05

function publicidad(){
  // Comentar-descomentar variable para habilitar
  // 1. Banner Infor
  //publi01 = '<a href="http://www.megamultimedia.com/suscribeinfo.html"><img src="../../../banners/bannerinfor031007.gif" width="468" height="60" border="0"></a>';
  publi01 = "";
  // 2. Banner Amen
  publi02  = '<a href="http://www.amen.es" target="_blank"><img src="../../images/amenbanner.gif" width="162" height="60" border="0"></a>';
  // 3. Banner Trazos
  //publi03  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="150" height="60">';
  //publi03 += '<param name=movie value="../../images/banner_g51.swf">';
  //publi03 += '<param name=quality value=high>';
  //publi03 += '<param name="menu" value="false">';
  //publi03 += '<embed src="../../images/banner_g51.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="60" menu="false">';
  //publi03 += '</embed></object>';
  publi03 = "";
  // 4. Banner Arsys
  publi04  = '<a href="http://www.arsys.es/" target="_blank"><img src="../../images/arsysbanner.gif" width="120" height="80" border="0"></a>';
  // 5. Banner B-System
  publi05  = '<a href="http://www.betasystem.net/" target="_blank"><img src="../../images/b-system.gif" width="150" height="60" border="0"></a>';
  
  if (document.getElementById) {
    if (window.HTMLElement) {
      spanNode = document.getElementById('pub01');
      while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
      var range = document.createRange();
      range.selectNodeContents(spanNode);
      spanNode.appendChild(range.createContextualFragment(publi01));
      //
      spanNode = document.getElementById('pub02');
      while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
      var range = document.createRange();
      range.selectNodeContents(spanNode);
      spanNode.appendChild(range.createContextualFragment(publi02));
      //
      spanNode = document.getElementById('pub03');
      while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
      var range = document.createRange();
      range.selectNodeContents(spanNode);
      spanNode.appendChild(range.createContextualFragment(publi03));
      //
      spanNode = document.getElementById('pub04');
      while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
      var range = document.createRange();
      range.selectNodeContents(spanNode);
      spanNode.appendChild(range.createContextualFragment(publi04));
      //
      spanNode = document.getElementById('pub05');
      while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
      var range = document.createRange();
      range.selectNodeContents(spanNode);
      spanNode.appendChild(range.createContextualFragment(publi05));
    } else {
      document.getElementById('pub01').insertAdjacentHTML('beforeEnd',publi01);
      document.getElementById('pub02').insertAdjacentHTML('beforeEnd',publi02);
      document.getElementById('pub03').insertAdjacentHTML('beforeEnd',publi03);
      document.getElementById('pub04').insertAdjacentHTML('beforeEnd',publi04);
      document.getElementById('pub05').insertAdjacentHTML('beforeEnd',publi05);
    }
  }
}



function resol(profun){
  if (profun == 0){
    cab800_1 = '../../images/cabecera_01.gif';
    cab800_2 = '../../images/cabecera_02.gif';
  
    cab1024_1 = '../../images/cab1024_01.gif';
    cab1024_2 = '../../images/cab1024_02.gif';
  
    lateral1 = "../../images/para1024_01.gif";
    lateral2 = "../../images/para1024_02.gif";
    lateral3 = "../../images/para1024_03.gif";
  } else if (profun == 1){
    cab800_1 = '../images/cabecera_01.gif';
    cab800_2 = '../images/cabecera_02.gif';
  
    cab1024_1 = '../images/cab1024_01.gif';
    cab1024_2 = '../images/cab1024_02.gif';
  
    lateral1 = "../images/para1024_01.gif";
    lateral2 = "../images/para1024_02.gif";
    lateral3 = "../images/para1024_03.gif";
  } else if (profun == 2){
    cab800_1 = 'images/cabecera_01.gif';
    cab800_2 = 'images/cabecera_02.gif';
  
    cab1024_1 = 'images/cab1024_01.gif';
    cab1024_2 = 'images/cab1024_02.gif';
  
    lateral1 = "images/para1024_01.gif";
    lateral2 = "images/para1024_02.gif";
    lateral3 = "images/para1024_03.gif";
  }
 
  numeo = '# ' + num;
  if (document.getElementById) {
    if (window.HTMLElement) {   //ESTE ES EL QUE FUNCIONA PARA NETSCAPE 6.X
      if (isNS6 && (screen.width >= 1024)){
        //cabeceras
        cabe1 = document.getElementById('cab01');
        cabe2 = document.getElementById('cab02');
        // Laterales
        late01 = document.getElementById('lat1024_1');
        late02 = document.getElementById('lat1024_2');
        late03 = document.getElementById('lat1024_3');
        if (profun == 0){
          cabe1.setAttribute("style", "background-image: url(../../images/cab1024_01.gif); background-repeat: no-repeat;");
          cabe2.setAttribute("style", "background-image: url(../../images/cab1024_02.gif); background-repeat: no-repeat;");
          late01.setAttribute("style", "background-image: url(../../images/para1024_01.gif); background-repeat: no-repeat;");
          late02.setAttribute("style", "background-image: url(../../images/para1024_02.gif); background-repeat: no-repeat;");
          late03.setAttribute("style", "background-image: url(../../images/para1024_03.gif); background-repeat: no-repeat;");
        }
        if (profun == 1){
          cabe2.setAttribute("style", "background-image: url(../images/cab1024_02.gif); background-repeat: no-repeat;");
          cabe1.setAttribute("style", "background-image: url(../images/cab1024_01.gif); background-repeat: no-repeat;");
          late01.setAttribute("style", "background-image: url(../images/para1024_01.gif); background-repeat: no-repeat;");
          late02.setAttribute("style", "background-image: url(../images/para1024_02.gif); background-repeat: no-repeat;");
          late03.setAttribute("style", "background-image: url(../images/para1024_03.gif); background-repeat: no-repeat;");
        }
        if (profun == 2){
          cabe2.setAttribute("style", "background-image: url(images/cab1024_02.gif); background-repeat: no-repeat;");
          cabe1.setAttribute("style", "background-image: url(images/cab1024_01.gif); background-repeat: no-repeat;");
          late01.setAttribute("style", "background-image: url(images/para1024_01.gif); background-repeat: no-repeat;");
          late02.setAttribute("style", "background-image: url(images/para1024_02.gif); background-repeat: no-repeat;");
          late03.setAttribute("style", "background-image: url(images/para1024_03.gif); background-repeat: no-repeat;");
        }
      }
      if (isNS6 && (screen.width <= 800)){
        if (profun == 0){
          cabe1 = document.getElementById('cab01');
          cabe1.setAttribute("style", "background-image: url(../../images/cabecera_01.gif); background-repeat: no-repeat;");
          //
          cabe2 = document.getElementById('cab02');
          cabe2.setAttribute("style", "background-image: url(../../images/cabecera_02.gif); background-repeat: no-repeat;");
        }
        if (profun == 1){
          cabe1 = document.getElementById('cab01');
          cabe1.setAttribute("style", "background-image: url(../images/cabecera_01.gif); background-repeat: no-repeat;");
          //
          cabe2 = document.getElementById('cab02');
          cabe2.setAttribute("style", "background-image: url(../images/cabecera_02.gif); background-repeat: no-repeat;");
        }
        if (profun == 2){
          cabe1 = document.getElementById('cab01');
          cabe1.setAttribute("style", "background-image: url(images/cabecera_01.gif); background-repeat: no-repeat;");
          //
          cabe2 = document.getElementById('cab02');
          cabe2.setAttribute("style", "background-image: url(images/cabecera_02.gif); background-repeat: no-repeat;");
        }
      }
    }
    else {
      if (isIE && (screen.width >= 1024 || screen.height >= 768)){
        cab01.background = cab1024_1;
        cab02.background  = cab1024_2;
        lat1024_1.background = lateral1;
        lat1024_2.background = lateral2;
        lat1024_3.background = lateral3;
      }
      else if (isIE && (screen.width >= 800 || screen.height >= 600)){
        cab01.background  = cab800_1;
        cab02.background  = cab800_2;
      }
    }
  }
}

function yaestas(){
  mensaje = 'Ya estás en la página';
  window.alert(mensaje);
}

//
//// Links todavia no desarrollados
//
function nodisp(){
  mensaje = 'Vínculo no disponible';
  window.alert(mensaje);
}

////Navegación
function abri(cual){
  window.location = cual;
}

//Funciones para el manejo de suscripciones comunes

function validar_datos(){
  if (document.suscrispain.nombre.value == ""){
    alert ("Olvidaste completar el campo Nombre");
    document.suscrispain.nombre.focus();
    return false; 
  } 
  if (document.suscrispain.apellido.value == ""){
    alert ("Olvidaste completar el campo Apellidos");
    document.suscrispain.apellido.focus();
    return false; 
  } 
  if (document.suscrispain.direccion.value == ""){
    alert ("Olvidaste completar el campo Dirección");
    document.suscrispain.direccion.focus();
    return false; 
  } 
  if (document.suscrispain.cpostal.value == ""){
    alert ("Olvidaste completar el campo Código Postal");
    document.suscrispain.cpostal.focus();
    return false; 
  } 
  if (document.suscrispain.ciudad.value == ""){
    alert ("Olvidaste completar el campo Ciudad");
    document.suscrispain.ciudad.focus();
    return false; 
  } 
  if (document.suscrispain.provincia.value == ""){
    alert ("Olvidaste completar el campo Provincia");
    document.suscrispain.provincia.focus();
    return false; 
  } 
  if (document.suscrispain.correo.value == ""){
    alert ("Olvidaste completar el campo Correo Electrónico");
    document.suscrispain.correo.focus();
    return false; 
  } else {
    if (!emailcheck(document.suscrispain.correo.value)) {
      document.suscrispain.correo.focus();
      return false;
    }
  }
  
  no = false;
  for (i=0; i<=3; i++){
    no = no || document.suscrispain.fpago[i].checked;
  }
  if(no){
    document.suscrispain.submit();
    return no;
  }
  else{
    alert("Debes indicar una forma de pago");
    document.suscrispain.fpago[0].focus();
    return no;
  }
}

//////
// Funciones de validación finales
// ======================= EMAIL CHECK ==============================

function emailcheck (emailStr) {
/* Verificar si el email tiene el formato user@dominio. */
var emailPat=/^(.+)@(.+)$/ 

/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 
	
/* Verifica los caracteres que son válidos en una dirección de email */
var validChars="\[^\\s" + specialChars + "\]" 

var quotedUser="(\"[^\"]*\")" 

/* Verifica si la dirección de email está representada con una dirección IP Válida */ 

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

/* Verificar caracteres inválidos */ 

var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* dominio, como opuesto a ipDomainPat, se muestra abajo. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  window.alert("La dirección de email parece incorrecta (compruebe @ y .'dom')");
  return false;

}
var user=matchArray[1]
var domain=matchArray[2]

// Si el user "user" es valido 
if (user.match(userPat)==null) {
// Si no
  window.alert("El nombre de usuario de email no es válido.");
  return false;
}

/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
  for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
      window.alert("IP de destino de email inválida");
      return false;
    }
  }
  return true;
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
  window.alert("El dominio del email parece no ser válido.");
  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>3) { 
  window.alert("La dirección de email debe tener 3 letras si es .com o 2 si es de algún país.");
  return false;
}

if (len<2) {
  var errStr="El email es erróneo";
  window.alert(errStr);
  return false;
}

// La dirección de email ingresada es Válida
  return true;
}

// ============= FIN EMAIL CHECK ======================== 