function agregar()
{
	if (document.all)
		window.external.AddFavorite(url,titulo)
}
	
function favoritos()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite ("http://www.cantabriaenredformacion.com","CantabriaEnRedFormacion.com");
	}
	else 
	{
		var msg = "¡Para añadirnos a tus favoritos pulsa Ctrl + D!";
		if(navigator.appName == "Netscape") msg += " (CTRL-D)";
			alert(msg);
	}
}
function ini()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.cantabriaenredformacion.com');
	}
	else
	{
		if(navigator.appName == "Netscape") alert("Su navegador no acepta esta opción automática.");
	}
}
function subWin(loc, titulo, ancho, alto)
{
	options="toolbar=0,Status=0,menubar=0,scrollbars,resizable=0,location=0,directories=0,width=" + ancho + ",height=" + alto;
	window.open(loc,titulo,options);
}
function subWin2(loc, titulo, ancho, alto)
{
	options="toolbar=0,Status=0,menubar=0,scrollbars,resizable=1,location=0,directories=0,width=" + ancho + ",height=" + alto;
	window.open(loc,titulo,options);
}
function clicks(id_banner, url, ventana)
{

	ventana = parseInt(ventana);
	// debemos añadir uno a los clicks en la base de datos, para ellos abrimos ventana
	// con documento 'actualiza_clik.php'
	// queremos obtener en 'direc' la url base de la web 'http://lo.que.sea/'
	var direc = document.location.href;
	var aparicion = 0; //numero de apariciones del caracter '/'
	var posicion = 0; //posicion de la tercera aparición de '/'
	for(i=0;i<direc.length;i++)
	{
		if(direc.charAt(i) == "/")
		{
			aparicion++;
			if(aparicion == 3)
			{
			   posicion = i;
			}
		}
	}
	direc = direc.substring(0,posicion+1);
	//buscamos el documento 'clicks.php' en el directorio raiz
	direc += "clicks.php?id=" + id_banner + "&tipo=0";
	var nueva = window.open(direc, "winActualiza", "width=20,height=20,scrollbars=no,directories=no,status=no,resizable=yes");
	if(ventana == 1)
	{
		// enlace interno, dentro de la web
		document.location.href = "http://" + url;
	}
	else if(ventana == 0)
	{ 
		// enlace externo, fuera de web
		window.open("http://" + url,"","");
	}
}

// pide confirmación para eliminar un usuario -> en el documento 'usuarios' del tutor
function Confirma_borrado(url)
{
	if(confirm("¿Estas seguro de borrar a este usuario del curso?"))
	document.location.href = url;
}
function confirmar(idc)
{
	if(confirm("¿Estas seguro que desea borrar contenido seleccionado?"))
	{
		document.location='./eliminar.php?Id='+idc;
	}
}
function Listado(arg)
{
	estado = document.getElementById(arg).style.display;
	var poner = "";
	if(estado == 'none')
	poner = "block";
	else if(estado == "block")
	poner = "none";
	document.getElementById(arg).style.display = poner;
}
function copiar(idc,nombreInput,nombreInput2)
{
	
	var aux;
	aux=nombreInput+idc;
	
	
	if(document.getElementById(aux).style.display=='block')
	{
		document.getElementById(aux).style.display='none';
	}
	else
	{
		document.getElementById(aux).style.display='block';
		var aux;
		aux=nombreInput2+idc;
		var tempval=document.getElementById(aux);
		tempval.focus();
		tempval.select();
		therange=tempval.createTextRange()
		therange.execCommand("Copy");
		aux2=nombreInput+idc;
		document.getElementById(aux2).innerHTML = "<strong>Url Copiado<\/strong>";
		aux3=nombreInput+idc;
		setTimeout("document.getElementById(aux3).style.display='none';",700);
	}
}
function Date_de_baja(estructura, usuario){
	
	if(confirm("¿Realmente quieres darte de baja de este curso?"))
		document.location.href="/cursos/generico/darse_baja_curso.php?Id_estructura="+estructura+"&Id_usuario=" + usuario;

}
function ver(variar)
{
	if( document.getElementById('curs'+variar).style.display=='block')
	{
		document.getElementById('curs'+variar).style.display='none';
	}
	else
		document.getElementById('curs'+variar).style.display='block'
}
function Date_de_baja(estructura, usuario){
	
	if(confirm("¿Realmente quieres darte de baja de este curso?"))
		document.location.href="/cursos/generico/darse_baja_curso.php?Id_estructura="+estructura+"&Id_usuario=" + usuario;

}
function enviar_form(Id_estructura1,Id_examen1)
{
	 document.examen.Id_estructura.value=Id_estructura1;
	 document.examen.Id_examen.value=Id_examen1;
	 document.examen.submit();
	 
}
function enviar_form1(Id_estructura1,Id_modulo1)
{
	 document.contenido_modulo.Id_estructura.value=Id_estructura1;
	 document.contenido_modulo.Id_modulo.value=Id_modulo1;
	 document.contenido_modulo.submit();
}
function enviar_form2(Id_estructura1,Id_modulo1)
{
	 document.getElementById('form'+Id_modulo1).Id_estructura.value=Id_estructura1;
	 document.getElementById('form'+Id_modulo1).Id_modulo.value=Id_modulo1;
	 document.getElementById('form'+Id_modulo1).submit();
}
function Enviar_papelera(url)
{
	if(confirm("¿Estas seguro de mandar este mensaje a la papelera?"))
		document.location.href = url;
}
function estadisticas_pasadas(Activo1)
{
	document.estadisticas_pasadas.Activo.value=Activo1;
	document.estadisticas_pasadas.submit();
}

function ver_datos_estadisticas(Id_estructura1,Activo1,identform)
{
	document.getElementById(identform).Activo.value=Activo1;
	document.getElementById(identform).Id_estructura.value=Id_estructura1;
	document.getElementById(identform).submit();
}
function estadisticas_pasadas(Activo1)
{
	 document.estadisticas_pasadas.Activo.value=Activo1;
	 document.estadisticas_pasadas.submit();
}
function enviar_form(Id_padre1,Id_estructura1,Id_examen1)
{
	document.examen.Id_estructura.value=Id_estructura1;
	document.examen.Id_estructura_curso.value=Id_padre1;
	document.examen.Id_examen.value=Id_examen1;
	document.examen.submit();
}
function activar()
{
	document.getElementById('blob').style.display='block';
}
function muestraPasa(check)
{
	var valor = document.getElementById(check).value;
	if(valor == 0)
	{
		// mostramos
		document.getElementById('Dni').disabled = true;
		document.getElementById(check).value = 1;
		document.getElementById('celdaPasaporte').style.display = 'inline';
	}
	else if(valor == 1)
	{ // mostramos
		document.getElementById('Dni').disabled = false;
		document.getElementById(check).value = 0;
		document.getElementById('celdaPasaporte').style.display = 'none';
	}
}
//realizar examenes
function recogeHtml(arg){
	document.getElementById('hidHtml').value = document.getElementById(arg).innerHTML;
	document.VolverAtras.submit()
	return false;
}
function marcaEstado(campo, contenedor){
	navegador = navigator.appName;
	if(navegador.indexOf("Explorer") == -1)
		esIE = false;
	else
		esIE = true;

	if(!esIE){
		estado = document.getElementById(campo).checked;
		celda = document.getElementById(contenedor).innerHTML;
		if(estado == true){
			pon = " checked>";
			celda = celda.substring(0,celda.length-1);
			celda += pon;
			
		}
		else if(estado == false){
			pon = true;
			celdaDespues = celda.substring(celda.indexOf("checked")+17);
			celdaAntes = celda.substring(0,celda.indexOf("checked"));
			celda = celdaAntes + " " + celdaDespues;
		}
		document.getElementById(contenedor).innerHTML = celda;
	}
	
}
function marcaEstado2(campo, conten,tope){ //para botones de radio
	tope = parseInt(tope);
	navegador = navigator.appName;
	if(navegador.indexOf("Explorer") == -1)
		esIE = false;
	else
		esIE = true;

	if(!esIE){	
		//al nombre del campo le quitamos el indice
		indice = campo.substring(campo.lastIndexOf("_")+1);
		indice = parseInt(indice);
		nombreCampo = campo.substring(0,campo.lastIndexOf("_")+1);
		nombreConten = conten.substring(0,conten.lastIndexOf("_")+1);
		//el limite del FOR es el mismo que el Contador que esté mostrando las respuestas
		for(i=0;i<tope;i++){
			nombreCampo1 = nombreCampo + i;
			nombreConten1 = nombreConten + i;
			valor2 = document.getElementById(nombreCampo1).checked;
			textoInput = document.getElementById(nombreConten1).innerHTML;
			//controlamos si hay que marcarlo o desmarcarlo
			celda = document.getElementById(nombreConten1).innerHTML;
			
			if( parseInt(i) == parseInt(indice)){ 
				pon = " checked'>";
				celda = celda.substring(0,celda.length-1);
				celda += pon;	
			}
			else{	//desactivamos		
				if(celda.indexOf("checked") != -1){
					celdaDespues = celda.substring(celda.indexOf("checked")+17);
					celdaAntes = celda.substring(0,celda.indexOf("checked"));
					celda = celdaAntes + " " + celdaDespues;
				}
			}
			document.getElementById(nombreConten1).innerHTML = celda;		
		}
	}
	
}
//FOROS
function Operacion(cual1,cual2,cual3)
{
	document.EliminarReg.foro.value=cual1;
	document.EliminarReg.tema.value=cual2;
	document.EliminarReg.niv.value=cual3;
	document.EliminarReg.action="tutor_activa_foro.php";
	document.EliminarReg.submit();
}

function Ir(valor, adonde)
{
	// compone una url a partir los argumentos: url/adonde + valor
	// es para el caso en que a la función paginar
	// recoge el valor del campo oculto con todos los ids seleccionados y redirige
	// a la dirección indicada por 'adonde'

	//alert(valor);

	valores = valor;
	//alert("valores: " + valores + " adonde: " + adonde);
	url = document.location.href;
	arg = "/";
	pos = url.lastIndexOf(arg);
	if(parseInt(pos) != -1)
	{
		//eliminamos el argumento de la cadena
		url2 = url.substring(0,parseInt(pos)+1);
		resto = url.substring(parseInt(pos+arg.length+1),url.length);
	}
	url2=url2+"temas.php"+adonde;
	//miramos si la variable 'adonde' ya contiene '&ids'
	document.location.href= url2;
}
//mensajeria
function Operacion_mesaj(cual1,cual2,cual3)
{
	if( cual1=='3' )
	{
		if( confirm("¿Desea realmente eliminar el contenido seleccionado?") )
		{
			document.EliminarReg.Usuario.value=cual2;
			document.EliminarReg.Contenido.value=cual3;
			document.EliminarReg.action="eliminar.php?Id_carpeta=3";
			document.EliminarReg.submit();
		}
	}
	else if( cual1=='10')
	{
		document.EliminarReg.Id.value=cual2;
		document.EliminarReg.action="ampliar.php";
		document.EliminarReg.submit();
	}
	else if( cual1=='11')
	{
		document.EliminarReg.Id.value=cual2;
		document.EliminarReg.IdAlumno.value=cual3;
		document.EliminarReg.action="ampliar.php";
		document.EliminarReg.submit();
	}
	else if( cual1=='1')
	{
		if(confirm("¿Estas seguro de mandar el contenido seleccionado a la papelera?"))
		{
			document.EliminarReg.Usuario.value=cual2;
			document.EliminarReg.Contenido.value=cual3;
			document.EliminarReg.action="index.php?Id_alumno=<?=$Id1?>&Id_carpeta=<?=$Carpeta?>";
			document.EliminarReg.submit();
		}
	}
}


//mostrar / ocultar comentarios
function mostrarcomentario(id){
	var elhtml = document.getElementById('coment'+id);
	if (elhtml.style.display == 'block'){
		elhtml.style.display = 'none';
	}else{
		elhtml.style.display = 'block';
	}
}
function invertir(content)
{
	dummy = document.getElementById(content);
	dummy = dummy.getElementsByTagName("input");
	Size = dummy.length;
	for(q = 0; q < Size; q++)
	{
		if( dummy[q].checked == true ) dummy[q].checked = false;
		else dummy[q].checked = true;
	}
}