function replaceAll( str, from, to ) { 
    var idx = str.indexOf( from );  
 
    while ( idx > -1 ) { 
        str = str.replace( from, to ); 
        idx = str.indexOf( from ); 
    } 
 
    return str; 
}

function daFormatoDecodificado(cad){
	cad = replaceAll(cad, "%20%20", "&nbsp;&nbsp;");
	cad = replaceAll(cad, "%0D%0A", "<br/>");
	cad = unescape(cad);
	return cad;
}

function abrirNoticia(id,titulo,cuerpo,firma,fecha ){
	document.getElementById("nTitulo").innerHTML = daFormatoDecodificado(titulo);
	document.getElementById("nCuerpo").innerHTML = daFormatoDecodificado(cuerpo);
	document.getElementById("nFirmaFecha").innerHTML = daFormatoDecodificado(firma) + " - " + daFormatoDecodificado(fecha);
	document.getElementById("capaVisualizacionNoticia").style.display = 'inline';
	capaSemitransparenteON('../imagenes/capaSemiTrans.gif');
	window.scroll(0,0);
}

function cerrarNoticia(){
	document.getElementById("nTitulo").innerHTML = "";
	document.getElementById("nCuerpo").innerHTML = "";
	document.getElementById("nFirmaFecha").innerHTML = "";
	document.getElementById("capaVisualizacionNoticia").style.display = 'none';
	capaSemitransparenteOFF();
}

function irPagina(pag){
	document.getElementById("paginacion").pagina.value = pag;
	document.getElementById("paginacion").method = "POST";
	document.getElementById("paginacion").action = "noticias.php";
	document.getElementById("paginacion").submit();
}

function publicarNoticias() {
	window.open('publicar.php', 'publiNotic', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=460');
}

function muestraForm(){
	document.getElementById("capaInformacion").style.display="none";
	document.getElementById("capaFormularioNoticia").style.display="inline";
}

function enviarNoticia(){
	if (document.getElementById("form").titular.value != ""){
		if (document.getElementById("form").cuerpo.value != ""){
			if (document.getElementById("form").autor.value != ""){
				if (document.getElementById("form").usuarioEmail.value != "" && document.getElementById("form").dominioEmail.value != "" && document.getElementById("form").extensionEmail.value != "") {			
					
					var titular = document.getElementById("form").titular.value;
					var cuerpo = document.getElementById("form").cuerpo.value;
					var autor = document.getElementById("form").autor.value;
					var email = document.getElementById("form").usuarioEmail.value + "@" + document.getElementById("form").dominioEmail.value + "." + document.getElementById("form").extensionEmail.value;
					
					var url = "/cgi-bin/formmail/formmail.cgi";
					url = url + "?recipient=webmaster@hermandadperdon.es";
					url = url + "&subject=NOTICIA PARA PUBLICAR";
					url = url + "&redirect=http://www.hermandadperdon.es/noticias/publicar.php&#63;exito&#61;si";
					url = url + "&titular=" + titular;
					url = url + "&email=" + email;
					url = url + "&cuerpo=" + cuerpo;
					url = url + "&autor=" + autor;
					
					animacionEsperaON("Se está enviando la noticia,<br />espere unos instantes...", "20%", "0px", "0px", "27%", true);
					
					setTimeout("document.location ='" + url + "';",1000);
				
				} else {
					alert("Debe completar el correo electrónico de la persona que firma.");
					document.getElementById("form").usuarioEmail.focus();
				}		
			} else {
				alert("Debe completar el autor de la noticia.");
				document.getElementById("form").autor.focus();
			}	
		} else {
			alert("Debe completar el cuerpo de la noticia.");
			document.getElementById("form").cuerpo.focus();
		}
	} else {
		alert("Debe completar el titular de la noticia.");
		document.getElementById("form").titular.focus();
	}
}

function imprimirNoticia(){
	var cad = "<div id=\"nTitulo\">" + document.getElementById('nTitulo').innerHTML + "</div>";
	cad = cad + "<br />&nbsp;";
	cad = cad + "<div id=\"nCuerpo\">" + document.getElementById('nCuerpo').innerHTML + "</div>";
	cad = cad + "<br />&nbsp;";
	cad = cad + "<div id=\"nFirmaFecha\">" + document.getElementById('nFirmaFecha').innerHTML + "</div>";
	imprimir(cad, '../paginaImpresion.php');
}