/*
Usada en editarContacto, visualizarContacto, insertarContacto, busquedaContacto
Funcion para checkear y descheckear las preferencias
Parametros: - id: id de las preferencias (ej: gestion_educativa)
                     - numElem: numero de elementos de las preferencias
La funcion barre los N elementos del id y selecciona o deselecciona todos los elementos dependiendo del estado anterior
Ejemplo de uso: CheckUncheck(gestion_educativa, 4)
*/
function CheckUncheck(id, numElem) {
	if (document.getElementById(id + '_checkuncheck').checked) 
		valor=true;
	else
		valor=false;
	
	for (i=1; i <= numElem; i++) 
		document.getElementById(id + i).checked = valor;
}
/*
Usada en editarContacto, visualizarContacto y busquedaContacto
Funcion para cambiar el color del link de las preferencias
Parametros: - id: id de las preferencias (ej: gestion_educativa)
                     - numElem: numero de elementos de las preferencias
La funcion barre los N elementos del id y cambia el color del link dependiendo de la seleccion actual 
Ejemplo de uso: applyColor(gestion_educativa, 4)
*/
function applyColor (id, numElem) {
	var pelomenosum = false;
	var todos = true;
	for (i=1; i <= numElem; i++) {
		if (document.getElementById(id + i).checked)
			pelomenosum = true;
		else
			todos = false;
	}
	if (todos)
	{
		document.getElementById(id + 'Link').className = 'linkpreferenciasCompleto';
		document.getElementById(id + '_checkuncheck').checked = true;
	}
	else if (pelomenosum)
		document.getElementById(id + 'Link').className = 'linkpreferenciasParcial';
	else
		document.getElementById(id + 'Link').className = 'linkpreferencias';
}
/*
Usada en editarContacto, visualizarContacto y busquedaContacto
Funcion para cambiar el color del link de todas las preferencias
La funcion llama la funcion applyColor para cada tema
Al agregar un nuevo tema, toca agregar una linea mas a esta funcion con el nuevo tema y la cantidad de elementos 
*/
function applyColorAll () {
	applyColor ('gestion_educativa', 4);
	applyColor ('arte', 8);
	applyColor ('ciencias_naturales', 5);
	applyColor ('ciencias_sociales', 10);
	applyColor ('curriculo', 5);
	applyColor ('educacion_diversidad', 8);
	applyColor ('emprendimiento', 2);
	applyColor ('entretenimiento', 6);
	applyColor ('espiritualidad', 3);
	applyColor ('etapas_educacion', 4);
	applyColor ('innovacion_pedagogica', 8);
	applyColor ('lenguaje', 6);
	applyColor ('libros_infantiles', 5);
	applyColor ('filosofia', 9);
	applyColor ('matematicas', 6);
	applyColor ('orientacion', 7);
	applyColor ('pedagogia', 3);
	applyColor ('salud', 7);
	applyColor ('tecnologia', 5);
	applyColor ('publicaciones', 2);
}

/*
Usada en editarContacto, visualizarContacto, insertarContacto y busquedaContacto
Funcion para desaparecer la lista de preferencias
La funcion hace desaparecer el div que contiene la lista de preferencias
*/
function ShowHideAll() {
	if (document.getElementById('cb_todos_temas').checked)
		document.getElementById('todos_temas').style.display = 'none';
	else
		document.getElementById('todos_temas').style.display = 'block';
}

/*
Usada en editarContacto, visualizarContacto, insertarContacto y busquedaContacto
Funcion para desaparecer los campos que estan relacionados a Persona Natural o Juridica
La funcion, dependiendo del tipo de contacto, hace aparecer o desaparecer algunos campos
*/
function ShowHideDoc() {
	var browser=navigator.appName;
	var displayStyle = 'table-row';
	
	if (browser=="Microsoft Internet Explorer")
		displayStyle = 'block';
	else
		displayStyle = 'table-row';
	
	if (document.getElementById('tipo_contacto1').checked) {
		document.getElementById('tipo_doc_id').style.display = displayStyle;
		document.getElementById('sexo_id').style.display = displayStyle;
		document.getElementById('nombre_contacto_id').style.display = 'none';
		document.getElementById('nombre_contacto').value = '';
		document.getElementById('repre_legal_id').style.display = 'none';
		document.getElementById('repre_legal').value= '';
		document.getElementById('apellidos_id').style.display = displayStyle;
		document.getElementById('fecha_nacimiento_id').style.display = displayStyle;
		document.getElementById('inst_nombre_id').style.display = displayStyle;
	}
	
	if (document.getElementById('tipo_contacto2').checked) {
		document.getElementById('tipo_doc_id').style.display = 'none';
		document.getElementById('tipo_documento1').checked = false;
		document.getElementById('tipo_documento2').checked = false;
		document.getElementById('tipo_documento3').checked = false;
		document.getElementById('sexo_id').style.display = 'none';
		document.getElementById('sexo1').checked = false;
		document.getElementById('sexo2').checked = false;
		document.getElementById('nombre_contacto_id').style.display = displayStyle;
		document.getElementById('repre_legal_id').style.display = displayStyle;
		document.getElementById('apellidos_id').style.display = 'none';
		document.getElementById('apellidos').value = '';
		document.getElementById('fecha_nacimiento_id').style.display = 'none';
		document.getElementById('fecha_nacimiento').value = '';
		document.getElementById('inst_nombre_id').style.display = 'none';
		document.getElementById('inst_nombre').value = '';
	}
	
	return;
}

/*
Usada en editarContacto, visualizarContacto, insertarContacto y busquedaContacto
Funcion para visualizar la lista de contactos
La funcion, dependiendo dsi el usuario elige Si o No, hace aparecer o desaparecer los campos eventos
*/
function ShowHidePartEvento() {
	var browser=navigator.appName;
	var displayStyle = 'table-row';
	
	if (browser=="Microsoft Internet Explorer")
		displayStyle = 'block';
	else
		displayStyle = 'table-row';

	if (document.getElementById('participacion_evento1').checked)
		document.getElementById('nombre_evento_id').style.display = displayStyle;
	
	if (document.getElementById('participacion_evento2').checked)
		document.getElementById('nombre_evento_id').style.display = 'none';
	
	return;
}

/*
Usada en editarContacto, visualizarContacto, insertarContacto y busquedaContacto
Funcion para visualizar los campos Nivel y Clase, dependiendo del tipo de institucion (Colegio, Escuela o Instituto)
*/
function ShowHideClaseNivel() {
	var browser=navigator.appName;
	var displayStyle = 'table-row';
	
	if (browser=="Microsoft Internet Explorer")
		displayStyle = 'block';
	else
		displayStyle = 'table-row';

	if ((document.getElementById('inst_tipo').value == 'Colegio') || (document.getElementById('inst_tipo').value == 'Escuela') || (document.getElementById('inst_tipo').value == 'Instituto')) {
		document.getElementById('nivel_ensen_id').style.display = displayStyle;
		document.getElementById('inst_clase_id').style.display = displayStyle;
		document.getElementById('jornada_id').style.display = displayStyle;
	}
	else {
		document.getElementById('nivel_ensen_id').style.display = 'none';
		document.getElementById('inst_clase_id').style.display = 'none';
		document.getElementById('jornada_id').style.display = 'none';
	}
	
	return;
}

/*
Usada en editarContacto, visualizarContacto, insertarContacto y busquedaContacto
Funcion para agregar un campo evento
*/
function addInput() {
	var textInput = document.createElement('input');
	var newline = document.createElement('br');
	textInput.type = 'text';
	textInput.name = 'nombre_evento[]';
	textInput.size = '30';
	textInput.maxlength = '30';
	document.getElementById('eventosExtras').appendChild( textInput);
	document.getElementById('eventosExtras').appendChild( newline);
}
