﻿function formularioVerificar (formulario, sender) {
	var error = false;
	error = (!error&&typeof(formulariosfin)=='boolean'&&typeof(formulariosgenfin)=='boolean'&&typeof(VerificarFormulario)=='function')?false:error;
	error = (!error)?!VerificarFormulario(formulario, sender):error;
	return !error;
}
/* Funciones para Formularios
-------------------------------------
(Funciones por orden alfabetico)
*/
function cand_cv_con_idioma_cert_0315Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_16_ididiomacertificado');
		var valor = newNumber(campo[campo.selectedIndex].value, 0, 1);
		if ( valor==-1 ) {
			campo = obtenerCampo(formulario, sender, '_02_certificado');
			error = (!error)?!VerificarCajaTexto(campo, 1, 1):error;
		}
	}
	return !error;
}
function cand_cv_estancia_0318Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var fechainicio = obtenerCampo(formulario, sender, '_21_fechainicio');
		var fechafin = obtenerCampo(formulario, sender, '_21_fechafin');
		if ( !diferenciaFechas ( fechainicio.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechainicio, 0 );
			error = true;
		}
		if ( !error &&!diferenciaFechas ( fechafin.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechafin, 0 );
			error = true;
		}
		if ( !error && !diferenciaFechas ( fechainicio.value, fechafin.value, 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechainicio, 1 );
			error = true;
		}
	}
	return !error;
}
function cand_cv_form_comp_0319Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_03_horas');
		if ( newNumber(campo.value, 0, 0)<20 ) {
			error = true;
			AlertaTextoMensaje ( campo, 0 );
		}
	}
	if ( !error ) {
		var fechainicio = obtenerCampo(formulario, sender, '_21_fechainicio');
		var fechafin = obtenerCampo(formulario, sender, '_21_fechafin');
		if ( !diferenciaFechas ( fechainicio.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechainicio, 1 );
			error = true;
		}
		if ( !error &&!diferenciaFechas ( fechafin.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechafin, 1 );
			error = true;
		}
		if ( !error && !diferenciaFechas ( fechainicio.value, fechafin.value, 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( fechainicio, 2 );
			error = true;
		}
	}
	return !error;
}
function cand_cv_tit_est_0311Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	var tipo_error = -1, campo_error = null;
	var mensajes = new Array("Por favor, complete correctamente el campo '=campo='. La opción seleccionada no es válida.", "Por favor, complete correctamente el campo '=campo='. El valor introducido no está dentro del rango permitido (1-4)");
	if ( !error ) {
		var anyoinicio = obtenerCampo(formulario, sender, '_03_fechainicio_anoinicio');
		error = (!error)?!VerificarCajaTextoNumero(anyoinicio, 4, 1):error;
	}
	if ( !error ) {
		var curso_c = obtenerCampo(formulario, sender, '_15_idcursomatriculadouniversidad');
		var curso = newNumber(curso_c[curso_c.selectedIndex].value, 0, 0);
		var curso_total_c = obtenerCampo(formulario, sender, '_15_idcursomatriculadouniversidad_total');
		var curso_total = newNumber(curso_total_c[curso_total_c.selectedIndex].value, 0, 0);
		if ( curso>curso_total || curso>6 ) {
			error = true;
			tipo_error = 0;
			campo_error = curso_c;
		} else if ( curso_total<2 || curso_total>6 ) {
			error = true;
			tipo_error = 0;
			campo_error = curso_total_c;
		}
	}
	if ( !error ) {
		var situacion_c = obtenerCampo(formulario, sender, '_15_idsituacionpfc');
		var situacion = newNumber(situacion_c[situacion_c.selectedIndex].value, 0, 0);
		var descripcion = obtenerCampo(formulario, sender, '_02_tema_pfc');
		if ( situacion>1 && descripcion!=null ) {
			error = (!error)?!VerificarCajaTexto(descripcion, 1, 1):error;
		}
	}
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_03_mediaexpediente');
		if ( campo!=null ) {
			var value = newNumber(campo.value, 1, 0);
			if ( value<1 || value>4 ) {
				error = true;
				tipo_error = 1;
				campo_error = campo;
			}
		}
	}
	if ( error && tipo_error>=0 && campo_error!=null ) {
		AlertaTextoMensaje ( campo_error, tipo_error, null, mensajes[tipo_error] );
	}
	return !error;
}
function cand_cv_tit_tit_0312Situacion (sender) {
	var situacion = newNumber(sender.options[sender.selectedIndex].value, 0, 1);
	var elementos_h = new Array();
	var elementos_v = new Array();
	if ( situacion==-1 ) {
		elementos_v = new Array("ui_universidad_esp", "ui_universidad_extranjera", "ui_titulacion_oficial", "ui_titulacion_no_oficial");
	} else if ( situacion==1 ) {
		elementos_h = new Array("ui_universidad_extranjera", "ui_titulacion_no_oficial");
		elementos_v = new Array("ui_universidad_esp", "ui_titulacion_oficial");
	} else if ( situacion==2 ) {
		elementos_h = new Array("ui_universidad_extranjera", "ui_titulacion_oficial");
		elementos_v = new Array("ui_universidad_esp", "ui_titulacion_no_oficial");
	} else if ( situacion==3 || situacion==4 ) {
		elementos_h = new Array("ui_universidad_esp", "ui_titulacion_oficial");
		elementos_v = new Array("ui_universidad_extranjera", "ui_titulacion_no_oficial");
	}
	for ( var i=0; i<elementos_h.length; i++ ) {
		var elemento = document.getElementById(elementos_h[i]);
		if ( elemento!=null ) {
			elemento.style.display='none';
		}
	}
	for ( var i=0; i<elementos_v.length; i++ ) {
		var elemento = document.getElementById(elementos_v[i]);
		if ( elemento!=null ) {
			elemento.style.display = 'block';
		}
	}
}
function cand_cv_tit_tit_0312Verificar (formulario, sender) {
	var error = false;
	var tipo_error = -1, campo_error = null;
	var mensajes = new Array("Por favor, complete correctamente el campo '=campo='. Un título oficial no puede haber sido cursado fuera de España.", "Por favor, complete correctamente el campo '=campo='. La fecha no puede ser posterior a la actual.", "Por favor, complete correctamente el campo '=campo='. El '=campo=' no puede ser posterior al curso actual.", "Por favor, complete correctamente el campo '=campo='. El '=campo=' y la 'Fecha de finalización de los estudios' tienen que ser coherentes.", "Por favor, complete correctamente el campo '=campo='. La opción seleccionada no es válida.", "Por favor, complete correctamente el campo '=campo='. Revise que el 'Año de inicio', la 'Fecha de finalización de los estudios' y el 'Curso en que finaliza la titulación' sean coherentes.", "Por favor, complete correctamente el campo '=campo='. El valor introducido no está dentro del rango permitido (1-4)");
	var situacion = obtenerCampo(formulario, sender, '_15_idtipotitulouniversitariosituacion');
	var situacion = newNumber(situacion.options[situacion.selectedIndex].value, 0, 1);
	var univ_nac = obtenerCampo(formulario, sender, '_16_iduniversidad');
	var pais = obtenerCampo(formulario, sender, '_16_idpais');
	var univ_text = obtenerCampo(formulario, sender, '_02_universidad');
	var titul_ofic = obtenerCampo(formulario, sender, '_16_idtitulacion');
	var titul_text = obtenerCampo(formulario, sender, '_02_titulacion');
	var titul_text_eq = obtenerCampo(formulario, sender, '_16_idtitulacion_equiv');

	if ( situacion==1 || situacion==2 ) {
		if ( !error ) {
			error = !VerificarSeleccionNumero(univ_nac, -1, 1);
		}
	}
	if ( situacion==1 ) {
		if ( !error ) {
			error = !VerificarSeleccionNumero(titul_ofic, -1, 1);
		}
	} 
	if ( situacion==3 || situacion==4 ) {
		if ( !error ) {
			error = (!VerificarSeleccionNumero(pais, -1, 1)||!VerificarSeleccionNumero(pais, 1, 1));
		}
		if ( !error ) {
			error = !VerificarCajaTexto(univ_text, 1, 1);
		}
	}
	if ( situacion>1 && situacion<5 ) {
		if ( !error ) {
			error = !VerificarCajaTexto(titul_text, 1, 1);
		}
		if ( !error ) {
			error = !VerificarSeleccionNumero(titul_text_eq, -1, 1);
		}
	}
	if ( !error ) {
		error = !formularioVerificar(formulario,sender);
	}
	if ( !error ) {
		var anyoinicio = obtenerCampo(formulario, sender, '_03_fechainicio_anoinicio');
		var fechafin = obtenerCampo(formulario, sender, '_21_fechatitulo');
		var cursos = obtenerCampo(formulario, sender, '_15_idcursomatriculadouniversidad_total');
		if ( fechafin!=null && !diferenciaFechas ( fechafin.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			tipo_error = 1;
			campo_error = fechafin;
			error = true;
		}
		if ( !error && anyoinicio!=null && !diferenciaFechas ( '1/10/' + anyoinicio.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			tipo_error = 2;
			campo_error = anyoinicio;
			error = true;
		}
		if ( !error && anyoinicio!=null && fechafin!=null && !diferenciaFechas ( '1/10/' + anyoinicio.value, fechafin.value, 1, Number.POSITIVE_INFINITY )  ) {
			tipo_error = 3;
			campo_error = anyoinicio;
			error = true;
		}
		if ( !error && cursos!=null && ( newNumber(cursos[cursos.selectedIndex].value,0,0)<2 || newNumber(cursos[cursos.selectedIndex].value,0,0)>6 ) ) {
			tipo_error = 4;
			campo_error = cursos;
			error = true;
		}
		if ( !error && anyoinicio!=null && fechafin!=null && cursos!=null && !diferenciaFechas ( '1/10/' + anyoinicio.value, fechafin.value, (newNumber(cursos.value,0,0)*365)-122, Number.POSITIVE_INFINITY ) ) {
			tipo_error = 5;
			campo_error = fechafin;
			error = true;
		}
	}
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_15_idsino_pfc');
		var campo2 = obtenerCampo(formulario, sender, '_16_idcalificacion_pfc');
		if ( campo!=null && campo2!=null && (campo.type=='select-one') && (campo2.type=='select-one') ) {
			if ( newNumber(campo.options[campo.selectedIndex].value, 0, 0)==1 ) {
				error = !VerificarSeleccionNumero(campo2, -1, 1);
			}
		}
	}
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_03_mediaexpediente');
		if ( campo!=null ) {
			var value = newNumber(campo.value, 1, 0);
			if ( value<1 || value>4 ) {
				error = true;
				tipo_error = 6;
				campo_error = campo;
			}
		}
	}
	if ( error && tipo_error>=0 && campo_error!=null ) {
		AlertaTextoMensaje ( campo_error, tipo_error, null, mensajes[tipo_error] );
	}
	return !error;
}
function cand_pers_0302Verificar (formulario, sender) {
	var error = !reg_reg_cand_0202Verificar(formulario,sender);
	return !error;
}
function emp_oferta_compl_0522Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_03_valoracion');
		var valor = newNumber(campo.value, 1, 0);
		if ( valor<100 ) {
			error = true;
			AlertaTextoMensaje ( campo, 0 );
		}
	}
	return !error;
}
function emp_oferta_gen_0508Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_03_numero_plazas');
		if ( newNumber(campo.value, 0, 0)==0 ) {
			error = true;
			AlertaTextoMensaje ( campo, 0 );
		}
	}
	return !error;
}
function reg_login_0203Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error && challenge.length==20 && typeof(hex_sha256)=='function' ) {
		var username = obtenerCampo(formulario, sender, '_01_username');
		var password = obtenerCampo(formulario, sender, '_01_password');
		var hash_campo = obtenerCampo(formulario, sender, '_02_hash');
		var hash = hex_sha256(username.value + ":" + hex_sha256(password.value) + ":" + challenge);
		if (hash.length==64) {
			hash_campo.value = hash;
			password.value = "SHA256";
		} else {
			error = true;
		}
	} else {
		error = true;
	}
	return !error;
}
function reg_pre_cand_0201Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario, sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_15_idtipodoc');
		var valorCampo = ( campo.type == 'select-one' )?campo.options[campo.selectedIndex].value:campo.value;
		error = !VerificarCajaTextoDNINIE ( obtenerCampo(formulario, sender, '_01_documento'), valorCampo, 1 );
	}
	return !error;
}
function reg_reg_cand_0202Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_15_idtipodoc');
		if ( campo!=null ) {
			var valorCampo = ( campo.type == 'select-one' )?campo.options[campo.selectedIndex].value:campo.value;
			error = !VerificarCajaTextoDNINIE ( obtenerCampo(formulario, sender, '_01_documento'), valorCampo, 1 );
		}
	}
	if ( !error ) {
		var telefono = obtenerCampo(formulario, sender, '_14_telefono');
		var fax = obtenerCampo(formulario, sender, '_14_fax');
		var movil = obtenerCampo(formulario, sender, '_12_movil');
		if ( movil==null || fax==null || telefono==null ) error=true;
		if ( !error && telefono.value.length==0 && fax.value.length==0 && movil.value.length==0 ) {
			error = true;
			AlertaTextoMensaje ( telefono, 0 );
		}
	}
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_21_fecha_nac');
		if ( !diferenciaFechas ( campo.value, new Date(), 1, Number.POSITIVE_INFINITY ) ) {
			AlertaTextoMensaje ( campo, 1 );
			error = true;
		}
	}
	return !error;
}
function reg_pre_emp_0205Verificar (formulario, sender) {
	var error = !formularioVerificar(formulario,sender);
	if ( !error ) {
		var campo = obtenerCampo(formulario, sender, '_01_documento_emp_cif_dni');
		if ( campo!=null && (!compruebaCIF (campo.value) && !compruebaNIF (campo.value) && !compruebaNIE (campo.value) ) ) {
			error = true;
			AlertaTextoMensaje ( campo, 0 );
		}
	}
	return !error;
}
function reg_reg_emp_0206Verificar (formulario, sender) {
	var error = !reg_pre_emp_0205Verificar(formulario,sender);
	return !error;
}
var formulariosfin = true;
