<!--  
// Código JavaScript para Validación de los campos
// del formulario de solicitud electrónico.
//
//

//Variables globales.
//
var anterior;
var nombre;

//
// Recepción de parametros desde selector.html
//

var x = document.location.search;
var parametros = new Array();
var campos = new Array();
var y=0;
campos = x.split('&');
for (var i=0; i < campos.length; i++) {
   valores = campos[i].split('=');
   for (var j=0; j < valores.length; j++) {
       y = y+1;
       parametros[y]=valores[j];}
 }


var cur = new Date();
var min_year = 2002; // define el año más pequeño del menú
var max_year = getFullYear(cur); // define el mayor año del menú

//months = new arr("Ene.","Feb.","Marzo","Abril","Mayo",
 //"Junio","Julio","Ago.","Sep.","Oct.","Nov.","Dic.");
months = new arr("01","02","03","04","05",
 "06","07","08","09","10","11","12");

if (min_year <= 400)
 alert("Para que este algoritmo funcione el año debe ser mayor que 400");



/////////////////////////////////////////////////////////
//                                                     //
// Funciones para realizar distintas Comprobaciones    //
//                                                     //
/////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
//
// Funcion para Incrementar el año en 1000 si este es menor 
// de dicho número.
//

function y2k(ano) { 
  return (ano < 1000) ? ano + 1900 : ano; 
}

//////////////////////////////////////////////////////////
//
// Funcion para validar si es una fecha válida 
// y en formato AAAA,MM,DD. 
//

function esFecha (dia,mes,ano) {
     var hoy = new Date();
     ano = ((!ano) ? y2k(hoy.getYear()):ano);
     mes = ((!mes) ? hoy.getMonth():mes-1);
     if (!dia) return false
     var test = new Date(ano,mes,dia);
     if ( (y2k(test.getYear()) == ano) &&
          (mes == test.getMonth()) &&
          (dia == test.getDate()) )
         return true;
     else
         return false
}

////////////////////////////////////////////////////////////////////////
//
// Validamos el NIF frente a la forma juridica
// par1 tiene la Forma Juridica elegida y par2 el Nif que introducimos. 
// Si par1 es '' no tenemos q casarlo con otra variable.
//

function ValidaNIF(par1,par2) {
    return true;
}
//    var resultado;
//    var nif=/[A-HNPQS][0-9]{5,8}[A-Z]?/;
//    var caracpar1=par1.charAt(0).toLowerCase();
//    var caracpar2=par2.charAt(0).toLowerCase();
//    var longitud=par2.length;

//    if (par1=='') return true;	    
//    if (caracpar1 == 'z') return true;
//    resultado=par2.match(nif);
//    if (resultado == null) return false;
//    if (caracpar1 != caracpar2) return false;
//    return true;
//}
////////////////////////////////////////////////
//
// Validación de nombres de máquinas totalmente
// calificadas (FQDN)

function ValidaFQDN(campo) {
      
dominio=/^([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])(\.[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])*\.[a-zA-Z]{2,3}$/;
       resultado=campo.match(dominio);
       if (resultado == null) {
         return false;}
       return true;	 
}

////////////////////////////////////////////////////////////////////////////////////////////
//
// Validamos que la dirección tenga el formato correcto, que no sean
// para direccionamiento privado y que estén en los rangos permitidos.
//

function ValidaIP(ClaseA,ClaseB,ClaseC,ClaseD){
 	if (ClaseA > -1 && ClaseA.length > 0 && ClaseB > -1 && ClaseB.length > 0 &&
		ClaseC > -1 && ClaseC.length > 0 && ClaseD > -1 && ClaseD.length > 0){
		ClaseA = parseInt(ClaseA);
		ClaseB = parseInt(ClaseB);
		ClaseC = parseInt(ClaseC);
		ClaseD = parseInt(ClaseD);
		if (ClaseA == 10 || ClaseA == 172 && ClaseB == 16 || 
		    ClaseA == 192 && ClaseB == 168){ 		 
			alert('IP Reservadas para Direccionamiento Privado');
			return false;
		}
	}
	else{return false}
	for(i=0;i<ValidaIP.arguments.length;i++){
		if (ValidaIP.arguments[i] < 0 || ValidaIP.arguments[i] > 255) return false;
	}
	return true;
}


///////////////////////
//
// QuitaBlancos 
// (Iniciales y finales)
//
//////////////////////

function QuitaBlancos(campo) {
var espaciof=/ +$/;
var espacioi=/^ +/;
var salida='';

salida=campo.replace(espacioi,"");
salida=salida.replace(espaciof,"");
return salida;
}

//////////////////
//
// QuitaTildes
//
/////////////////

function QuitaTildes(campo){
	
	var i;	
	var tmpcad = '';
	var acentuadas = 'áéíóúÁÉÍÓÚüÜ';
	var sinacentuar = 'aeiouAEIOUuU';
	var letra;
	
   for(i=0;i<campo.length;i++) {  
   	letra = campo.charAt(i);
        posicion=acentuadas.indexOf(letra);
   	if (posicion >= 0) 
   	    tmpcad = tmpcad + sinacentuar.charAt(posicion);
    	else 
    	   tmpcad = tmpcad + letra;
	}
	return tmpcad;
}

//////////////////
//
// QuitaPuntos
//
/////////////////

function QuitaPuntos(campo) 
{
  var i;
  var caracter;
  var salida = '';

  for (i=0; i<campo.length;i++) {
    caracter=campo.charAt(i);
    if (caracter != '.') {
      salida = salida + caracter;
    }
  }
  return salida;
}

      
/////////////////
//
// Capitaliza
//
////////////////

function Capitaliza(campo) {
	
	var i;
	var tmpcad = '';
	var Mayuscula = true;
	var letra;	
	
   for(i=0;i<campo.length;i++){  
   	letra = campo.charAt(i);
   	if (Mayuscula && letra != ' ') { 
   		tmpcad = tmpcad + letra.toUpperCase();
   		Mayuscula = false;   		
    	}
    	else {
    		if (letra == ' ') {
    			Mayuscula = true;
    			tmpcad = tmpcad + letra;
    		}
    		else {
    		   tmpcad = tmpcad + letra.toLowerCase();
    		}    		   
    	}
	}
	return tmpcad;	
}

////////////////////////////////////////////////
//                                            //
// Gestión de fechas con listas desplegables  //
//                                            //
////////////////////////////////////////////////

/////////////////////////////
// 
// generaFecha, 
// como cadena tipo yyyymmdd
//
/////////////////////////////

function generaFecha(pdia,pmes,panho,psiglo) {
var dia,mes;
var nodef;
var tiponodef = typeof nodef;
var tipopsiglo = typeof psiglo;

dia=pdia.selectedIndex+1;
mes=pmes.selectedIndex+1;
if (mes < 10) mes='0'+mes;
if (dia < 10) dia='0'+dia;
if (tiponodef != tipopsiglo) 
  fecha=psiglo.options[psiglo.selectedIndex].text+panho.options[panho.selectedIndex].text+mes+dia;
else 
  fecha=panho.options[panho.selectedIndex].text+mes+dia;
return fecha;
}


function cambiaDias(numb,pday,pmonth,pyear,pcent) {
 var nodef;
 var tiponodef = typeof nodef;
 var tipopcent = typeof pcent;

 mth = pmonth.selectedIndex;
 if (tiponodef != tipopcent) {
   sel = pcent.selectedIndex;
   cent = pcent.options[sel].value;
   yr = cent*100+pyear.selectedIndex;}
 else {
   sel= pyear.selectedIndex;
   yr = pyear.options[sel].text;
  }
 if (numb != 1) {
  numDays = numDaysIn(mth,yr);
  pday.options.length = numDays;
  for (i=27;i<numDays;i++) {
   pday.options[i].text = i+1;
  }
 }
 day = pday.selectedIndex+1;
}

function numDaysIn(mth,yr) {
 if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
 else if ((mth==1) && leapYear(yr)) return 29;
 else if (mth==1) return 28;
 else return 31;
}

function leapYear(yr) {
 if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0)
  return true;
 else
  return false;
}

function arr() {
 this.length=arr.arguments.length;
 for (n=0;n<arr.arguments.length;n++) {
  this[n] = arr.arguments[n];
 }
}

function firstDayOfYear(yr) {
 diff = yr - 401;
 return parseInt((1 + diff + (diff / 4) - (diff / 100) + (diff / 400)) % 7);
}

// fixes a Netscape 2 and 3 bug
function getFullYear(d) { // d is a date object
 yr = d.getYear();
 if (yr < 1000)
  yr+=1900;
 return yr;
}

//-->

