
function valFechaCastellano(v){
	//alert(v);
	if(v != ""){
	//alert('no vacio');
	//alert(v.length);
		if(v.length < 10) {
		//alert('demasiado corto');
		return false;}
			
		
		//dia=parseInt(v.substring(0,2),10);
		//mes=parseInt(v.substring(3,5),10);
		//anio=parseInt(v.substr(6),10);		

		dia=v.substring(0,2);
		//alert(dia);
		mes=v.substring(3,5);
		//alert(mes);
		anio=v.substr(6);		
		//alert(anio);
		if ( !isFinite(anio) || !isFinite(mes) || !isFinite(dia))return false;
		if ( anio > 2100 || anio < 1940 ) return false;	
		if (mes < 1 || mes > 12) return false;
		if (dia < 1)return false;
				
		if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12){
			//meses de 31 dias
			if (dia > 31) return false;	
		}else{
			if (mes == 2 && anio % 4 == 0){
				if (dia > 29) 
					return false;
				else if (anio % 4 != 0)
					if (dia > 28)return false
			}else if(mes == 2 && anio % 4 != 0){
				if (dia > 28) return false
			}else{
				if (dia > 30)return false
			}
		}		
	}	
	return true;
}
function valFechaEuskera(v){
	if(v != ""){
		if(v.length < 10)return false;
		
		//dia=parseInt(v.substring(0,2),10);
		//mes=parseInt(v.substring(3,5),10);
		//anio=parseInt(v.substr(6),10);		

		dia=v.substring(8);
		mes=v.substring(5,7);
		anio=v.substr(0,4);				
		if ( !isFinite(anio) || !isFinite(mes) || !isFinite(dia))return false;
		if ( anio > 2100 || anio < 1940 ) return false;	
		if (mes < 1 || mes > 12) return false;
		if (dia < 1)return false;
				
		if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12){
			//meses de 31 dias
			if (dia > 31) return false;	
		}else{
			if (mes == 2 && anio % 4 == 0){
				if (dia > 29) 
					return false;
				else if (anio % 4 != 0)
					if (dia > 28)return false
			}else if(mes == 2 && anio % 4 != 0){
				if (dia > 28) return false
			}else{
				if (dia > 30)return false
			}
		}		
	}	
	return true;
}

//********* Función que compara dos fechas en castellano ***********************
function CompararFechasCastellano(FechaInicio,FechaFin){
  //fecha_actual = new Date();
  dia_fecha_inicio=FechaInicio.substr(0,2);
  mes_fecha_inicio=FechaInicio.substr(3,2);
  ano_fecha_inicio=FechaInicio.substr(6,4);
  vfecha_inicio=mes_fecha_inicio+"/"+dia_fecha_inicio+"/"+ano_fecha_inicio
  fecha_inicio=new Date(vfecha_inicio);
  
  dia_fecha_fin=FechaFin.substr(0,2);
  mes_fecha_fin=FechaFin.substr(3,2);
  ano_fecha_fin=FechaFin.substr(6,4);
  vfecha_fin=mes_fecha_fin+"/"+dia_fecha_fin+"/"+ano_fecha_fin
  fecha_fin=new Date(vfecha_fin);
  
  var tiempoRestante=fecha_fin.getTime()-fecha_inicio.getTime();
  var dias = Math.floor(tiempoRestante / (1000 * 60 * 60 * 24));
      
  // Los días límite vamos a buscarlos en la BBDD , para marcar el objetivo en funcion del tipo de contrato.
  // Cargo un array con los objetivos de la tabla

  if (dias<-1){
  	return false;
  }
  else {
  	return true;
  }
}

function ventanaAbrir(destino,titulo,ancho,alto,scrolleo){
	sw=screen.width; 
	sh=screen.height;
	window.open(destino, titulo,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+scrolleo+', resizable=no, width='+ancho+', height='+alto+', top='+(sh-alto)/2+',left='+(sw-ancho)/2+'');
}
function ventanaAbrir2(destino){
	sw=screen.width; 
	sh=screen.height;
	window.open(destino, 'ficha' ,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=YES, resizable=no, width=620, height=550, top='+(sh-550)/2+',left='+(sw-620)/2+'');
}
function ventanaImprimir(){
	window.print();
}
function abrirImprimir(destino,titulo,ancho,alto,scrolleo){
	sw=screen.width; 
	sh=screen.height;
	ventana=window.open(destino, titulo,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+scrolleo+', resizable=no, width='+ancho+', height='+alto+', top='+(sh-alto)/2+',left='+(sw-ancho)/2+'');
	ventana.print();
	ventana.close();
}

function opw_trek(imageName,imageWidth,imageHeight,wTopTitle,posLeft,posTop,wWidth,wHeight) {
	newWindow = window.open("","newWindow","location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,width="+wWidth+",height="+wHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+wTopTitle+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" >'); 
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+wTopTitle+'>'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}
function validarEmail(campo) {
	e = trim(campo.value);
	if (isEmail(e))
		return true;
	alert('La dirección de Email no es correcta');
	campo.focus();
	return false;
}

//Comprueba que el email es correcto
function ComprobarEmail(email,requerido) { 
	if ((requerido != true) && (Trim(email)==""))
	return true
	var PosArroba=email.indexOf("@");
	var PosPunto=email.indexOf(".");
	if (email == "" ) {
		alert('Debe introducir su dirección de correo electrónico');
		return false;
	}
	else if ((PosArroba < 1)||(PosPunto<0)) {
			alert('La dirección de correo electrónico no es correcta');
			return false;
	}
	else
		return true;
}

//función que indica si la dirección de email tiene la sintaxis correcta
function isEmail(argvalue) {
  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  // arrayString = argvalue.split("@"); (works only in netscape3 and above.)
  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }
  return true;
}


//--------------------------------------------------------------------
//NIF
//--------------------------------------------------------------------
function comprobarNIF(campo) {
	if (ValidarNIF(campo.Value)){
		return true;
	}
	else {
		campo.focus();
		alert('La letra del NIF introducido no es correcta. Por favor, introduzcala de nuevo.');
		return false;
	}
}
function ValidarNIF(NIF) {
	var prim;
	if (NIF.length < 6){
		return false;
	}
	NIF = NIF.toUpperCase();
	prim = NIF.substr(0,1);
	if (isNaN(prim)) {
		resto = NIF.substring(1, NIF.length);
		if (prim == LetraNIFFisicas(resto))
			return true;
		else
			return false;
	}
	else {
		fin = NIF.substr(NIF.length -1,1);
		resto = NIF.substr(0, NIF.length -1);
		if (fin == LetraNIFFisicas(resto))
			return true;
		else
			return false;
	}
}
function LetraNIFFisicas(Caracter) {
  var Cadena;
  var i;
  var resp;
  if (isNaN(Caracter)) return 'AB';
  Cadena = "TRWAGMYFPDXBNJZSQVHLCKE";
  i = parseInt(Caracter / 23);
  i = Caracter - i * 23 + 1;
  resp = Cadena.substr(i-1, 1);
  return resp;
}
//no se donde se usa
function comprobarDNI(campo) {	
	if (ValidarCif(campo.value))
		return true;
	else {
		campo.focus();
		alert('Introduzca sólo números para el DNI.');
		return false;
	}
}
function ValidarCif(cif) {
	var prim;
	var r1,r2,p1,p3,p5,p7;
	var cociente, resto, dc;
	
	cadena = "ABCDEFGHSPQ"
	EQUIV = "ABCDEFGHIJ"
	
	if (cif.length != 9) {
		return false;
  	}
  	
  	cif = cif.toUpperCase();
	prim = cif.substr(0,1);
  	if (cadena.search(prim) == -1) {
  		return false;
  	}
  
	if (isNaN(cif.substr(1,7))) {
		return false;
	}
  	  
  	r1 = parseInt(cif.charAt(2)) + parseInt(cif.charAt(4)) + parseInt(cif.charAt(6));
  	p1 = 2 * parseInt(cif.charAt(1));
  	cociente = parseInt(p1/10);
  	resto = (p1%10);
	p1 = cociente + resto;
	p3 = 2 * parseInt(cif.charAt(3));
	cociente = parseInt(p3/10);
	resto = (p3%10);
	p3 = cociente + resto
	p5 = 2 * parseInt(cif.charAt(5));
	cociente = parseInt(p5/10);
	resto = (p5%10);
	p5 = cociente + resto;
	p7 = 2 * parseInt(cif.charAt(7));
	cociente = parseInt(p7/10);
	resto = (p7%10);
	p7 = cociente + resto;
	r2 = p1 + p3 + p5 + p7;
	r = r1 + r2;
	resto = (r%10);
	resto = 10 - resto;
	dc = cif.substr(cif.length -1,1);
	
	cadena = cadena.substr(0,8);
	if ((cadena.search(prim) != -1) && !(isNaN(dc))) {
		if (resto == 10) {
			resto = 0;
		}
		if (resto != parseInt(dc)) {
			return false;
		}
	} else {
		dig = EQUIV.substr(resto-1,1);
		if (dc != dig) {
			return false;
		}
	}
	return true;  	
}
//--------------------------------------------------------------------
//NIF
//--------------------------------------------------------------------
