var base = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function Show(s){
    w = 700;
    h = 500;
    x = (screen.width - w)/2;
    y = (screen.height - h)/2;
    if (y < 0) y = 0;
    if (x < 0) x = 0;
    window.open(s, '', 'top=' + y + ', left=' + x + ', scrollbars=yes, width=' + w + ', height=' + h);
}


function ShowVideo(s){
    w = 500;
    h = 430;
    x = (screen.width - w)/2;
    y = (screen.height - h)/2;
    if (y < 0) y = 0;
    if (x < 0) x = 0;
    window.open(s, '', 'top=' + y + ', left=' + x + ', scrollbars=yes, width=' + w + ', height=' + h);
}


function Vacios(formulario){
  counter = 0;
  msg = "";
  s = formulario.a_user.value;
  if(s.length < 4) msg = msg + "Nombre de usuario debe tener al menos 4 caracteres. "; else counter++;
  s = formulario.a_contrasena.value;
  if(s.length < 6) msg = msg + "La contraseña debe tener al menos 6 caracteres. "; else counter++;
  if(counter < 2) alert(msg);
  return counter == 2;
}

function Valida(tag, permiso){
  if(permiso == "no")
    alert("Se terminó el plazo de esta semana para jugar Quiniela.");
  else{
    if(tag == "no")
      alert("Para jugar debes ingresar tu nombre de usuario y contraseña");
    else{
      if(tag == "yes"){
        w = 400;
        h = 550;
        x = (screen.width - w)/2;
        y = (screen.height - h)/2;
        if (y < 0) y = 0;
        if (x < 0) x = 0;
        window.open("mascarilla.php", '', 'top=' + y + ', left=' + x + ', scrollbars=yes, width=' + w + ', height=' + h);
      }
    }
  }
}

function IsInbase(c){
  valor1 = false;
  for(j = 0; j <= base.length - 1; j++)
    if(base.charAt(j) == c){
      valor1 = true;
      break;
  }
  return valor1;
}

function AlphaNumerics(s){
  valor2 = true;
  for(i = 0; i <= s.length - 1; i++)
    if(!IsInbase(s.charAt(i))){
      valor2 = false;
      break;
  }
  return valor2;
}

function ValidaForm(formulario){
    s = formulario.user.value;
    valor = false;
    if(s.length < 4){
        msg = "Nombre de usuario debe tener al menos 4 caracteres.";
        alert(msg);
        valor = false;
    }
    else{
        valor = AlphaNumerics(s);
        if(!valor){
            msg = "El nombre de usuario debe tener entre 4 y 15 caracteres alfanuméricos. (0..9), (a..z), (A..Z)";
            alert(msg);
            valor = false;
        }
        else{
            s = formulario.passw.value;
            if(s.length < 6){
              msg = "La contraseña debe tener al menos 6 caracteres.";
              alert(msg);
              valor = false;
            }
            else{
                u = formulario.confirma.value;
                if(u != s){
                  msg = "La contraseñas son diferentes.";
                  alert(msg);
                  valor = false;
                }
                else{
                    s = formulario.fullName.value;
                    if( s.length <= 2){
                      msg = "El nombre no esta completo.";
                      alert(msg);
                      valor = false;
                    }
                    else{
                        s = formulario.birthDate.value;
                        if(s.length < 4){
                          msg = "El año de nacimiento debe tener 4 digitos. Ejemplo: 1974";
                          alert(msg);
                          valor = false;
                        }
                        else{
                            num = parseInt(s);
                            actual = new Date();
                            year = actual.getFullYear();
                            if((year - num) < 18){
                              msg = "Es menor de 18 años.";
                              alert(msg);
                              valor = false;
                            }
                            else{
                              valor = true;
                            }
                        }
                    }
                }
            }
        }
    }
   return valor;
} // FIN DE LA FUNCION

function esNumero(cadena){
  k = "0123456789";
  res = 0;
  if(cadena.length > 0){
      res = 1;
      for(j = 0; j < cadena.length; j++){
          if(k.indexOf(cadena.charAt(j)) == -1){
              return 0;
          }
      }
  }
  return res;
}

function MarcadoresVacios(formulario){
  for(i = 1; i <= 9; i++){
    num = i.toString();
    objx = formulario["scorex_" + num];
    objy = formulario["scorey_" + num];
    v = esNumero(objx.value) + esNumero(objy.value);
    if(v < 2){
      alert("Número Inválido.");
      return false;
    }
  }
  return true;
}

