// JavaScript Document
// JavaScript Document
//creo una variable bool para comprobar si se esta usando IE
/*var mensaje_entidad = 'Debe seleccionar una entidad.';
var mensaje_area = 'Debe seleccionar un área de negocio.';
var mensaje_periodo = 'Debe seleccionar un periodo.';*/
/* 2008-06-13 - FS: adaptado a tinyMCE 3.x (en lugar de 2.x) */
function abrirCreditos()
{
	window.open('creditos.php','Creditos','height=600,width=600,scrollbars=1');
}
function abrirContacto()
{
	window.open('contacta.php','Contacto','height=500,width=600,scrollbars=1');
}
function abrirContactoNoSession(idcurso)
{
	window.open('contacta.php?idCursoCli='+idcurso,'Contacto','height=500,width=600,scrollbars=1');
}
function abrirLegal()
{
	window.open('legal.php','Avis','height=600,width=600,scrollbars=1');
}
//
var xmlhttp = false;
//comprobar si se esta usando IE
try
{//si la version de javascript es superior a 5
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{//sino usamos el tradicional objeto activeX
	try
	{//si estamos usando IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(E)
	{//en caso contrario no estamos usando IE
		xmlhttp = false;
	}
}
//si no estamos usando IE creamos la instancia Javascript del objeto
if(!xmlhttp&&typeof XMLHttpRequest != 'undefined')
{
	xmlhttp = new XMLHttpRequest();
}
function cambiarCalendario(mes,anio)
{
	var obj = document.getElementById('zonacalendario');
	var URL ='modulos/generadorCalendario.php?mes='+mes+'&anio='+anio;
	xmlhttp.open("GET",URL);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
function spamSucks(domain,user) 
{ 
	document.location.href = "mailto:" + user + "@" + domain; 
}
function abrirCMS(formulario)
{
	formulario.submit();
}
function visibilidad(i,mostrarCompleto,mostrarResumen)
{
	//var capainfo = document.getElementById("tema_"+i);
	var capainfo = document.getElementById("capatema_"+i);
	var enlace = document.getElementById("enlace_"+i);
	var caparesumen = document.getElementById("caparesumen_"+i);
	var capadetalle = document.getElementById("capadetalle_"+i);
	//alert("enlace:"+enlace.innerHTML + '---'+mostrarResumen);
	if (enlace.innerHTML == mostrarCompleto)
	{
		caparesumen.style.display ="none";
		capadetalle.style.display ="block";
		//capainfo.innerHTML = detalle;
		enlace.innerHTML = mostrarResumen;
		enlace.style.background="url('../img/ico_ocultar.gif') no-repeat right";
	}
	else
	{
		//capainfo.innerHTML = resumen;
		caparesumen.style.display ="block";
		capadetalle.style.display ="none";
		enlace.innerHTML = mostrarCompleto;
		enlace.style.background="url('../img/ico_ampliar.gif') no-repeat right";
	}	
}
function validarComentario(formulario)
{
	//alert("Detalle:"+tinyMCE.activeEditor.getContent("comentarios"));
	detalle_valido =tinyMCE.activeEditor.getContent()!='';
	if (detalle_valido)
	{
		/* 2008-06-13 - FS: forzar el limpiado de los estilos de word mediante el plugin 'PasteWord' */
  	content = tinyMCE.activeEditor.getContent();
  	tinyMCE.activeEditor.setContent("");
  	tinyMCE.activeEditor.execCommand("mcePasteWord", false, content);
  	tinyMCE.activeEditor.getElement().value = tinyMCE.activeEditor.getContent();
	
		formulario.submit();
		return true;
	}
	else
	{
		return false;
	}
}
function validarTema(formulario)
{
	function limpiarCamposError()
	{
		document.getElementById('caparesultadonombre').style.display = 'none';
		formulario.nombre.style.backgroundColor = '#ffffff';	
		document.getElementById('caparesultadoid_areaTema').style.display = 'none';
		formulario.id_areaTema.style.backgroundColor = '#ffffff';
		document.getElementById('caparesultadodetalle').style.display = 'none';
		formulario.detalle.style.backgroundColor = '#ffffff';		
	}
	
	function marcarError(campo,nombre)
	{
		var caparesultado = document.getElementById('caparesultado'+nombre);
		caparesultado.style.display = 'block';
		campo.style.backgroundColor = '#eee';
		//campo.focus();
	}
	formulario.enviar.disabled = true;
	//alert("Detalle:"+tinyMCE.activeEditor.getContent());	
	nombre_valido = formulario.nombre.value !='';
	
	var indice = formulario.id_areaTema.selectedIndex;
	id_area_valido = formulario.id_areaTema.options[indice].value != '-1';
	//resumen_valido =formulario.resumen.value !='';
	detalle_valido =tinyMCE.activeEditor.getContent()!='';
	limpiarCamposError();
	var numErrores = 0;
	if (!nombre_valido)
	{
		numErrores++;
		marcarError(formulario.nombre,'nombre');
	}
	if (!id_area_valido)
	{
		numErrores++;
		marcarError(formulario.id_areaTema,'id_areaTema');
	}
	if (!detalle_valido)
	{
		numErrores++;
		marcarError(formulario.detalle,'detalle');
	}
	if (numErrores == 0)
	{
		/* 2008-06-13 - FS: forzar el limpiado de los estilos de word mediante el plugin 'PasteWord'  */

/*
		content = tinyMCE.activeEditor.getContent();
	  	tinyMCE.activeEditor.setContent('');
	  	tinyMCE.activeEditor.execCommand("mcePasteWord", false, content);
	  	tinyMCE.activeEditor.getElement().value = tinyMCE.activeEditor.getContent();
*/	
		
		formulario.submit();
		return true;
	}
	else
	{
		formulario.enviar.disabled = false;
		return false;
	}
}
function validarMensaje(formulario)
{
		function limpiarCamposError()
		{
			//document.getElementById('caparesultadodestinatario').style.display = 'none';
			formulario.destinatario.style.backgroundColor = '#ffffff';	
			//document.getElementById('caparesultadoasunto').style.display = 'none';
			formulario.asunto.style.backgroundColor = '#ffffff';			
		}
				
		function marcarError(campo,nombre,mensaje)
		{
			//var caparesultado = document.getElementById('caparesultado'+nombre);
			//var resultado = document.getElementById('resultado'+nombre);
			campo.style.backgroundColor = '#eee';
			//resultado.innerHTML = mensaje;
			//caparesultado.style.display = 'block';
			campo.focus();
		}
		var indice = formulario.destinatario.selectedIndex;
		//destinatario_valido = formulario.destinatario.options[indice].value != '-1';
		//alert('indice:'+indice);
		destinatario_valido = indice != -1;
		asunto_valido = formulario.asunto.value!='';
						
		limpiarCamposError();
		var numErrores = 0;
		if (!destinatario_valido)
		{
			//alert("El campo nombre no puede ser vacío");
			numErrores++;
			marcarError(formulario.destinatario,'destinatario',mensaje_seleccion);
		}		
		if (!asunto_valido)
		{					
			//alert("El campo mail no ha es una dirección de correo válida");
			numErrores++;
			marcarError(formulario.asunto,'asunto', mensaje_vacio);		
		}
		if (numErrores == 0)
		{
			/* 2008-10-22 - FS: forzar el limpiado de los estilos de word mediante el plugin 'PasteWord' 	*/
	  	content = tinyMCE.activeEditor.getContent();
	  	tinyMCE.activeEditor.setContent("");
	  	tinyMCE.activeEditor.execCommand("mcePasteWord", false, content);
	  	tinyMCE.activeEditor.getElement().value = tinyMCE.activeEditor.getContent();
	

			formulario.submit();
			return true;
		}
		else
		{
			return false;
		}
}
function modificarNombreDestinatario(formulario)
{
	var indice = formulario.destinatario.selectedIndex;
	formulario.nombreDestinatario.value = formulario.destinatario.options[indice].text;
	//alert("cambiado:"+formulario.nombreDestinatario.value);
}
function visibilidadValoracion(i,mostrarCompleto,mostrarResumen)
{
	var capainfo = document.getElementById("pregunta_"+i);
	var enlace = document.getElementById("enlace_"+i);
	if (capainfo.style.display=="block")
	{
		capainfo.style.display="none";
		//enlace.innerHTML = "mostrar completo";
		enlace.style.background="url('../img/ico_plegar.gif') no-repeat right";		
	}
	else
	{
		capainfo.style.display="block";
		//enlace.innerHTML = "ocultar info";
		enlace.style.background="url('../img/ico_extensor.gif') no-repeat right";	
	}
}
function validarPreguntas(formulario)
{
	var tipos = formulario.tipoPreguntas.value.split('*');
	//alert('tipo:'+tipos);
	var validos = new Array();
	var indice = 0;
	
	for (i=0;i<tipos.length;i++)
	{
		respuesta = 'respuesta_'+i;
		switch(tipos[i])
		{
			case '0': 	for (j=0;j<eval('formulario.'+respuesta+'.length');j++)
						{
							if (eval('formulario.'+respuesta+'['+j+'].checked') == true)
							{
								validos[indice] = 1;
								indice++;
							}							
						}
			break;
			case '1': 	for (j=0;j<eval('formulario.'+respuesta+'.length');j++)
						{
							if (eval('formulario.'+respuesta+'['+j+'].checked') == true)
							{
								validos[indice] = 1;
								indice++;
							}
						}
			break;
			case '2': 	for (j=0;j<eval('formulario.'+respuesta+'.length');j++)
						{
							if (eval('formulario.'+respuesta+'['+j+'].checked') == true)
							{
								validos[indice] = 1;
								indice++;
							}
						}
			break;
			case '3': 	if (eval('formulario.'+respuesta+'.value') != '')
						{
							validos[indice] = 1;
							indice++;
						}
			break;
		}		
	}
	if (tipos.length == validos.length)
	{
		formulario.submit();
	}
	else
	{
		var resultado = document.getElementById('presultado');
		resultado.innerHTML = mensaje_preguntasContestadas;		
		return false;
	}
}

function cambiaFuente(fuente){

	document.getElementById("tipo_letra").value=fuente;
	document.getElementById("cambiar_tipo_letra").submit();

}