/*	---------------------------------------------------	*/
/*			FUNCIONES AZVI			*/
/*	---------------------------------------------------	*/

var NS4,NS6,IE4,IE5,vis,invis,pantallas,idioma,donde,ruta,menus,cargapagina,puedo_enviar

  NS4 = (document.layers) ? true : false;
  IE4 = (document.all && !document.getElementById) ? true : false;
  IE5 = (document.all && document.getElementById) ? true : false;
  NS6 = (!document.all && document.getElementById) ? true : false;

var mensajes
mensajes=[
"Día no válido (1-31).",
"Mes no válido (1-12).",
"Año no válido (1900-actual).",
"Formato no válido.",
"E-mail erróneo.",
"El caracter ~ no es válido.",
"El caracter § no es válido.",
"El NIF no parece ser correcto.",
"El email parece incorrecto, comprueba @ y .XXX (.es, .com, .net, etc).",
"El nombre de usuario no es válido.",
"IP de destino inválida.",
"El dominio parece no ser válido.",
"La dirección debe tener 3 letras si es .com o 2 si es de algún pais.",
"La dirección es errónea.",
"Debes rellenar todos los datos de la fecha.",
"Debes rellenar los campos marcados con asterisco (*)."
];

if(NS4){vis="shown";invis="hide";}else{vis="visible";invis="hidden";}

document.onmousedown=click;
if (NS6){document.addEventListener("mouseup",alerta,false);}

function alerta(e){
if (e.which == 3) {alert("AZVI");return false;}
}

function click(e) {
  NS4 = (document.layers) ? true : false;
  if (NS4) {if (e.which == 3) {alert("AZVI");return false;}} else {if(NS6){}else{if (event.button == 2) {alert("AZVI");return false;}}}
}

ruta="";
cargapagina=true;
inicio=0;
//qid=1;
/*	---------------------------------------------------	*/
/*	---------------------------------------------------	*/


function imprime(){
  window.print();
}

function especial(obj){
  str=obj.value;
  n=str.lastIndexOf("~");
  if(n!=-1){
    alert(mensajes[5]);
    obj.focus();
  }else{
    n=str.lastIndexOf("§");
    if(n!=-1){
    alert(mensajes[6]);
      obj.focus();
    }
  }
}

function numero(obj,minimo,maximo,error){
  if(maximo==-1){
    actual=new Date();
    maximo=actual.getYear();
  }
  valor=obj.value;
  if(valor!=""){
    num=parseInt(valor);
    if(!(num>=minimo&&num<=maximo)){
	alert(mensajes[error]);
	obj.value="";
	obj.focus();
    }else{
	if(num<10&&valor.length<2){
	  obj.value="0"+valor;
	}
    }
  }
}

function nif(obj){
  valor=obj.value;
  if(valor!=""){
	rg=/^\d+[a-zA-Z]$/;
    e=valor.match(rg);
	rg2=/^[a-zA-Z]\d+$/;
    e2=valor.match(rg2);
    if(e==null){
      if(e2==null){
	alert(mensajes[7]);
	obj.value="";
      obj.focus();
      }
    }
  }
}

function correo(obj) {
  puede=true;
  emailStr=obj.value;
if(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(mensajes[8]);
    puede=false;
  }
  if(puede){
  var user=matchArray[1];
  var domain=matchArray[2];

  if (user.match(userPat)==null) {
    alert(mensajes[9]);
    puede= false;
  }
  if(puede){
  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) {
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
        alert(mensajes[10]);
        puede= false;
      }
    }
  }
  if(puede){
  var domainArray=domain.match(domainPat);
  if (domainArray==null) {
    alert(mensajes[11]);
    puede= false;
  }
  if(puede){
  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) { 
    alert(mensajes[12]);
    puede= false;
  }
  if(puede){
  if (len<2) {
    alert(mensajes[13]);
    puede= false;
  }
}}}}}}
  if(!puede){obj.focus();}
}

function enviar(){
 //if(puedo_enviar){

  if(comprueba_fechas()==true){
	
    if(comprueba_obl()==true){
	alert("enviar2");
	//puedo_enviar=false;

	document.getElementById("fenvio").submit();
    }
  }
 //}
}

function comprueba_fechas(){

  fechas=["alta","desde","hasta","desde2","hasta2","d"];

  for(var i=0;i<fechas.length;i++){
	
    dia=document.getElementById("Dia"+fechas[i]);
    if(dia.value!=""){alert("funciona");
        mes=document.getElementById("Mes"+fechas[i]);
            if(mes.value!=""){
				any=document.getElementById("Ano"+fechas[i]);
	           if(any.value ==""){
                    alert(mensajes[14]);
	               any.focus();
	               return false;
	           }
            }else{
                alert(mensajes[14]);
	           mes.focus();
	           return false;
            }
    }
  }

  return true;
}


function comprueba_obl(){
  obligatorios=["Nombre","Apellido1","Apellido2","Sexo","Estado","Lugarn","Direccion","Localidad","Telefono"]
  for(var i=0;i<obligatorios.length;i++){
    obj=document.getElementById(obligatorios[i]);
    str=obj.value;
    if(str==""||((i>2&&i<6)&&str=="0")){
      retro(obj);
alert(obligatorios[i]);
      return false;
    }
  }
  return true;
}

function retro(obj){
  alert(mensajes[15]);
  obj.focus();
}
