/* lista desplegable para elegir una seccion */
function seleccion(id, nombre, capa, control, formulario){
var obj1 = document.getElementById(control);
var obj2 = document.getElementById(capa);
	obj1.innerHTML=nombre;
	obj2.style.visibility="hidden";
	obj1.style.background="#FFCC00";
	document.forms[formulario].secNumero.value=id;	
	document.getElementById('vseccion').innerHTML=nombre;
}
function mostrarElemento(capa,elemento){
var etiqueta="";	
	if(elemento.name=="txt_fuente"){
		etiqueta = "Fuente: ";
	}
	document.getElementById(capa).innerHTML=etiqueta+elemento.value;	
}

/*OCULTA UNA CAPA VISIBLE*/
function ocultar(capa){
	document.getElementById(capa).style.visibility="hidden";
}	

/*CIERRA UNA CAPA */
function cerrar(capa){
var obj = document.getElementById(capa);
	obj.style.display = "none";
}

/*MUESTRA UNA CAPA INVISIBLE*/
function visualizar(capa){
	document.getElementById(capa).style.visibility="visible";
}

/* ABRE UNA CAPA */
function abrir(capa){
var obj = document.getElementById(capa);
	obj.style.display = "block";
}

/*CIERRA LA CAPA DONDE SE VE EL EDITOR Y ABRE DONDE SE VE EL SUBTITULO 
Y MUESTRA EL CONTENIDO EN UN TEXTBOX */
function cerrarEditor(capa, formulario){
	if(capa=='cp_contenido'){ 
		instancia = 'txt_completa';
	}else{
		instancia = 'txt_subtitulo';
	}
	contenido_editor = FCKeditorAPI.__Instances[instancia].GetHTML();

	//muestra el contenido en el div y guarda en el txt_subtitulo o txt_completa
	if(capa=='cp_contenido'){ 
		document.forms[formulario].txt_completa.value = contenido_editor;
		document.getElementById('vcontenido').innerHTML = contenido_editor;
	}else{
		document.forms[formulario].txt_subtitulo.value = contenido_editor;
		document.getElementById('vsubtitulo').innerHTML = contenido_editor;
	}

	if(capa=='cp_contenido'){ 	
		document.getElementById('cont_editor_completa').style.display="none"; //cierra el editor
	}else{
		document.getElementById('cont_editor').style.display="none"; //cierra el editor
	}
	document.getElementById(capa).style.display="block"; //abre la capa indicada
}


function validarExtension(archivo){
extensiones_permitidas = new Array(".gif", ".jpg", ".mp3", ".swf"); 	
	//ver si es una foto, un audio, un video o una dirección de youtbe y tomar sólo una
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	permitida = false;
    for (var i = 0; i < extensiones_permitidas.length; i++) {
         if (extensiones_permitidas[i] == extension) {
         	permitida = true;
         	break;
         }
    } 
	if (!permitida) {
         alert("Comprueba la extensión de los archivos a subir. \nSólo se pueden subir archivos con extensiones: \n\r" + extensiones_permitidas.join());
		 return false;
    }else{
        //submito!
         return true;
    } 
}

function actualizarVistaNota(formulario){
	/*muestra toda la info ingresada como noticia nueva*/
	var f1 = document.forms[formulario];
	var fecha = f1.txt_fecha.value;
	
	var secnumero = f1.secNumero.value;
	if(secnumero > 0){secnumero=document.getElementById('sel_notas').innerHTML;}

	var titulo = f1.txt_titulo.value;
	var subtitulo = f1.txt_subtitulo.value;
	var fuente = f1.txt_fuente.value;
	var contenido = f1.txt_completa.value;

	//multimedia
	var vmultimedia = f1.fotoNota.value;
	var vYoutube = f1.youtube.value;

	var vfotoNota = "<b>Multimedia:</b> No hay archivo multimedia seleccionado.";

//si eligió en ambas, tomar solo vmultimedia
	if( (vmultimedia.length > 0 && vYoutube.length > 0) || vmultimedia.length > 0){
		var nota="";
		if(vmultimedia.length > 0 && vYoutube.length > 0){
			nota = "Se descartará YouTube. <br>";
		}
		if(validarExtension(vmultimedia)){
			//determinar cuál es la extensión
			Arrayextension = new Array(".gif", ".jpg", ".mp3", ".swf"); 
			mi_extension = (vmultimedia.substring(vmultimedia.lastIndexOf("."))).toLowerCase(); 
			switch(mi_extension){
				case ".swf":
					vfotoNota = "<b>Multimedia:</b> Se seleccionó un archivo FLASH.";
					break;
				case ".mp3":
					vfotoNota = "<b>Multimedia:</b> Se seleccionó un archivo de AUDIO.";
					break;
				default:
					vfotoNota = "<b>Multimedia:</b> Se seleccionó una imagen.";
			}
			vfotoNota = nota + vfotoNota;
		}else{
			vfotoNota = "<b>Multimedia:</b> No se seleccionó ningún archivo multimedia";
		}
	}else{
		if(vYoutube.length > 0){
			vfotoNota = "<b>Multimedia:</b> Se seleccionó un video YouTube";
		}
	}		
	
	//fecha
	document.getElementById('vfecha').innerHTML=fecha;
	//seccion
	document.getElementById('vseccion').innerHTML=secnumero;
	//titulo
	document.getElementById('vtitulo').innerHTML=titulo;
	//subtitulo
	document.getElementById('vfuente').innerHTML=fuente;
	
	//imagen-video-youtube
	document.getElementById('vfoto_home').innerHTML=vfotoNota;
	
	//contenido
	document.getElementById('vcontenido').innerHTML=contenido;
}

/* ABRE O CIERRA LA CAPA INDICADA EN EL PARAMETRO*/
function mostrar(capa){
var obj = document.getElementById(capa);
	if(obj.style.display == "block"){
		//cierra
		obj.style.display = "none";
	}else{
		//abre
		obj.style.display = "block"
	}	
}

function permutar(cap){
	if(document.getElementById(cap).style.display == "none"){
		document.getElementById(cap).style.display = "block";
	}else{
		document.getElementById(cap).style.display = "none";
	}
}

/* MUESTRA LAS CAPAS FOTO/VIDEO CERRANDO LA INDICADA EN EL PARAMETRO 2 Y ABRIENDO LA DEL 1*/
function permutarMultimedia(capa1, capa2){
var obj1 = document.getElementById(capa1);
var obj2 = document.getElementById(capa2);
obj1.style.display = "none";
obj2.style.display = "none";
	if(obj1.style.display == "block"){
		//cierra
		obj1.style.display = "none";
	}else{
		//abre
		obj1.style.display = "block"
	}
}

//cierra la capa abierta y abre la cerrada
function switchCapas(c1,c2){
var obj1 = document.getElementById(c1);
var obj2 = document.getElementById(c2);
	if(obj1.style.display == "block"){
		obj1.style.display = "none";
		obj2.style.display = "block";
	}else{
		obj1.style.display = "block"
		obj2.style.display = "none";
	}	
}

//cierra la capa abierta y abre la cerrada
function switchEncuesta(c1,c2){
var obj1 = document.getElementById(c1);
var obj2 = document.getElementById(c2);
	if(obj1.style.display == "block"){
		obj1.style.display = "none";
		obj2.style.display = "block";
		document.getElementById('etiquetaEncuesta').innerHTML="Ver Resultados";
	}else{
		obj1.style.display = "block"
		obj2.style.display = "none";
		document.getElementById('etiquetaEncuesta').innerHTML="Votar";
	}	
}
