/*VALIDACION BUSCAR*/

function validaBuscar(form){
	
	if (Empty(form.buscar.value) || (form.buscar.value.length < 3))
	{
		alert('Ingresar su criterio de búsqueda (mínimo 3 caracteres).');
		form.buscar.focus();
		return false;
	}
		
	return;
		
}

/*VALIDACION BUSCAR DOCUMENTOS*/

function validaBuscarDocumentos(form, validar){
	
	if(validar)
	{
		if (Empty(form.buscar_documentos.value) || (form.buscar_documentos.value.length < 3))
		{
			alert('Ingresar su criterio de búsqueda (mínimo 3 caracteres).');
			form.buscar_documentos.focus();
			return;
		}
	}
	var tesauroId = 0;
	try
	{
		tesauroId = form.tesauro_id.options[form.tesauro_id.options.selectedIndex].value;
	}
	catch(e){}
	var categoriaId = 0;
	try
	{
		categoriaId = form.categoria_id.options[form.categoria_id.options.selectedIndex].value;
	}
	catch(e){}
	var subcategoriaId = 0;
	try
	{
		subcategoriaId = form.subcategoria_id.options[form.subcategoria_id.options.selectedIndex].value;
	}
	catch(e){}
	document.getElementById('resultados').style.display='';
	getDocumentos(form.buscar_documentos.value,'','','', tesauroId, categoriaId, subcategoriaId);
}

function limpiarBusqueda()
{
	form_busqueda_simple.buscar_documentos1.value='';
	form_busqueda_simple.buscar_documentos.value='';
}

function validaBusquedaAvanzada(form){
	
	fecha_desde  = form.desde_dia.value + '/'+form.desde_mes.value+'/'+form.desde_anio.value;
	fecha_hasta  = form.hasta_dia.value + '/'+form.hasta_mes.value+'/'+form.hasta_anio.value;
	if(form.desde_mes.value!='' && form.desde_mes.value!='mm')
	{
		if(!isDate(fecha_desde))
		{
			alert('La fecha ingresada en mes desde, año desde no es válida. Favor modificar e intentar nuevamente');
			form.buscar_documentos1.focus();
			return;
		}
	}
	if(form.hasta_mes.value!='' && form.hasta_mes.value!='mm')
	{
		if(!isDate(fecha_hasta))
		{
			alert('La fecha ingresada en mes hasta, año hasta no es válida. Favor modificar e intentar nuevamente');
			form.buscar_documentos1.focus();
			return;
		}
	}
	if(Empty(form.buscar_documentos1.value) && !isDate(fecha_desde) && !isDate(fecha_hasta))
	{
		alert('Ingrese a lo menos un parametro de búsqueda');
		form.buscar_documentos1.focus();
		return;
	}
	var tesauroId = 0;
	try
	{
		//tesauroId = form.tesauro_id.options[form.tesauro_id.options.selectedIndex].value;
	}
	catch(e){}
	var categoriaId = 0;
	try
	{
		//categoriaId = form.categoria_id.options[form.categoria_id.options.selectedIndex].value;
	}
	catch(e){}
	var subcategoriaId = 0;
	try
	{
		//subcategoriaId = form.subcategoria_id.options[form.subcategoria_id.options.selectedIndex].value;
	}
	catch(e){}
	document.getElementById('resultados').style.display='';
	fecha_desde  = form.desde_anio.value + '-' + form.desde_mes.value+'-'+form.desde_dia.value;
	fecha_hasta  = form.hasta_anio.value + '-' + form.hasta_mes.value+'-'+form.hasta_dia.value;
	if(form.desde_mes.value=='' || form.desde_mes.value=='mm')
	{
		fecha_desde = "";
	}

	if(form.hasta_mes.value=='' || form.hasta_mes.value=='mm')
	{
		fecha_hasta = "";
	}

	getDocumentos(form.buscar_documentos1.value,fecha_desde,fecha_hasta,form.ordenar.options[form.ordenar.options.selectedIndex].value,tesauroId,categoriaId,subcategoriaId);
	return;

}

/*VALIDACION INGRESO INTRANET*/

function validaIngresoIntranet(form){
	if (form.form_action.value != '0'){
	
		if (Empty(form.username.value) || (form.username.value.length < 3))
		{
			alert('Ingresar su nombre de usuario por favor.');
			form.username.focus();
			return false;
		}
			
		if (Empty(form.password.value) || (form.password.value.length < 4))
		{
			alert('Ingrese su password por favor.');
			form.password.focus();
			return false;
		}
		
	} else {
		alert('Debe seleccionar una Intranet');
		return false;
	}
	return true;
		
}


/*VALIDACION FORMULARIO CONTACTO*/

function validaContacto(form){
	
	if (Empty(form.nombre.value) || (form.nombre.value.length < 3))
	{
		alert('Ingresar su nombre por favor.');
		form.nombre.focus();
		return false;
	}
		
	if (Empty(form.apellido.value) || (form.apellido.value.length < 3))
	{
		alert('Ingrese su apellido por favor.');
		form.apellido.focus();
		return false;
	}

	if (!isMail(form.email.value))
	{
		alert('Ingrese su email por favor.');
		form.email.focus();
		return false;
	}


	if (!isInteger(form.telefono.value) || (form.telefono.value.length < 4))
	{
		alert('Ingrese su nº de telefono por favor (sólo números.');
		form.telefono.focus();
		return false;
	}
	
	if(Empty(form.mensaje.value) || (form.mensaje.value.length >= 250))
	{
		alert('Ingreso su comentario o mensaje por favor. (Máximo permitido de caracteres: 250), ahora existen '+ form.mensaje.value.length);
		form.mensaje.focus();
		return false;
	}
	var suscrip="";
	for(i=0;form.elements['motivos['+i+']'];i++)
	{
		if(form.elements['motivos['+i+']'].checked==true)
		{
			suscrip+= "<li>" + form.elements['motivos_text['+i+']'].value + "</li>";
		}
	}
	form.suscripciones.value=suscrip;
	return;
		
}


/*VALIDACION FORMULARIO CONTACTO POSTULACION JSCH*/

function validaContacto_postulacion(form){
	
	if (Empty(form.nombre.value) || (form.nombre.value.length < 3))
	{
		alert('Ingresar su nombre por favor.');
		form.nombre.focus();
		return false;
	}
		
	if (Empty(form.apellido.value) || (form.apellido.value.length < 3))
	{
		alert('Ingrese su apellido por favor.');
		form.apellido.focus();
		return false;
	}
	
	if (Empty(form.edad.value) || (form.edad.value.length < 2))
	{
		alert('Ingrese su Edad por favor.');
		form.edad.focus();
		return false;
	}

	if (!isMail(form.email.value))
	{
		alert('Ingrese su email por favor.');
		form.email.focus();
		return false;
	}
	
	if (!isInteger(form.telefono.value) || (form.telefono.value.length < 4))
	{
		alert('Ingrese su nº de telefono por favor (sólo números.');
		form.telefono.focus();
		return false;
	}
	
	if (Empty(form.carrera.value) || (form.carrera.value.length < 3))
	{
		alert('Ingrese su Carrera por favor.');
		form.carrera.focus();
		return false;
	}
	
	if (Empty(form.universidad.value) || (form.universidad.value.length < 3))
	{
		alert('Ingrese su Universidad por favor.');
		form.universidad.focus();
		return false;
	}
	
	if(Empty(form.mensaje.value) || (form.mensaje.value.length >= 250))
	{
		alert('Ingreso su comentario o mensaje por favor. (Máximo permitido de caracteres: 250), ahora existen '+ form.mensaje.value.length);
		form.mensaje.focus();
		return false;
	}

	return;
		
}