// JavaScript Document

function indforma()
{
	document.getElementById("txtFechaIndforma").value='';
	document.getElementById("txtSectorIndforma").value='';
	document.getElementById("formulario").action="indforma.asp";
	document.getElementById("formulario").submit();
}

function indforma_volver()
{
	document.getElementById("formulario").action="indforma.asp";
	document.getElementById("formulario").submit();
}

function indforma_volver_buscador()
{
	document.getElementById("formulario").action="buscador.asp";
	document.getElementById("formulario").submit();
}

function cargarSector(sector)
{
	document.getElementById("txtSectorIndforma").value=sector;
	document.getElementById("formulario").action="indforma.asp";
	document.getElementById("formulario").submit();
}

function fechaIndforma()
{
	var dd;
	var mm;
	var aa;
	if (document.getElementById("txtDiaInd").value=="")
	{
		alert("Introduzca el día");
		document.getElementById("txtDiaInd").focus();
		return;
	}
	if (document.getElementById("txtMesInd").value=="")
	{
		alert("Introduzca el mes");
		document.getElementById("txtMesInd").focus();
		return;
	}
	if (document.getElementById("txtAnnoInd").value=="")
	{
		alert("Introduzca el año");
		document.getElementById("txtAnnoInd").focus();
		return;
	}
	if (document.getElementById("txtDiaInd").value.length==1)
	{
		dd="0" + document.getElementById("txtDiaInd").value;
	}
	else
	{
		if (parseInt(document.getElementById("txtDiaInd").value)>31)
		{
			alert ("Día incorrecto");
			document.getElementById("txtDiaInd").value="";
			document.getElementById("txtDiaInd").focus();
			return;
		}
		else
		{
			dd=document.getElementById("txtDiaInd").value;
		}
	}
	
	if (document.getElementById("txtMesInd").value.length==1)
	{
		mm="0" + document.getElementById("txtMesInd").value;
	}
	else
	{
		if (parseInt(document.getElementById("txtMesInd").value)>12)
		{
			alert ("Mes incorrecto");
			document.getElementById("txtMesInd").value="";
			document.getElementById("txtMesInd").focus();
			return;
		}
		else
		{
			mm=document.getElementById("txtMesInd").value;
		}
	}
	
	if (document.getElementById("txtAnnoInd").value.length==1)
	{
		aa="200" + document.getElementById("txtAnnoInd").value;
	}
	else
	{
		var fecha=new Date();
		var anno=2000+(fecha.getYear()%100);
		if (parseInt(document.getElementById("txtAnnoInd").value)+2000>anno+1)
		{
			alert ("Año incorrecto");
			document.getElementById("txtAnnoInd").value="";
			document.getElementById("txtAnnoInd").focus();
			return;
		}
		else
		{
			aa="20" + document.getElementById("txtAnnoInd").value;
		}
	}

	document.getElementById("txtFechaIndforma").value=aa+mm+dd;
	document.getElementById("formulario").action="indforma.asp";
	document.getElementById("formulario").submit();
}

function controlRecarga()
{
	if (redir)
	{
		document.getElementById("txtFechaIndforma").value=fecha;
		document.getElementById("formulario").action="indforma.asp";
		document.getElementById("formulario").submit();	
	}
}

function verNoticiaIndforma(codigo)
{
	document.getElementById("txtCodNoticia").value=codigo;
	document.getElementById("formulario").action="noticiaindforma.asp";
	document.getElementById("formulario").submit();	
}

function indforma_print()
{
	var ventimp = window.open(' ', 'popimpr','height=1px;width=1px;z-index=0');
	ventimp.document.write('<link href="includes/estilos_indforma.css" rel="stylesheet" type="text/css">');
	ventimp.document.write('<link href="includes/estilos.css" rel="stylesheet" type="text/css">');
	ventimp.document.write(document.getElementById("desarrollo_noticia").innerHTML);
	ventimp.document.close();
	ventimp.print();
	ventimp.close();	
}

function indforma_enviar()
{
	document.getElementById("txtHtml").value = document.getElementById("desarrollo_noticia").innerHTML;
	document.getElementById("txtTexto").value = document.getElementById("desarrollo_noticia").innerText;
	document.getElementById("formulario").action="indformaenviar.asp";
	document.getElementById("formulario").submit();
}

function indforma_send()
{
	if (document.getElementById("txtHtml").value=="")
	{
		alert ("Ha sucedido un error procesando la información de la noticia. No se puede enviar.");
		indforma_volver();
		return;
	}
	if (trim(document.getElementById("txtNombreFrom").value)=="")
	{
		alert ("Introduzca su nombre");
		document.getElementById("txtNombreFrom").focus();
		return;
	}
	if (! check_email(document.getElementById("txtEmailFrom").value))
	{
		alert ("Introduzca su email");
		document.getElementById("txtEmailFrom").focus();
		return;
	}
	if (trim(document.getElementById("txtNombreTo").value)=="")
	{
		alert ("Introduzca el nombre del destinatario");
		document.getElementById("txtNombreTo").focus();
		return;
	}
	if (! check_email(document.getElementById("txtEmailTo").value))
	{
		alert ("Introduzca el email del destinatario");
		document.getElementById("txtEmailTo").focus();
		return;
	}
	document.getElementById("txtDatosEnvio").value=trim(document.getElementById("txtNombreFrom").value);
	document.getElementById("txtDatosEnvio").value+="\n"+trim(document.getElementById("txtEmailFrom").value);
	document.getElementById("txtDatosEnvio").value+="\n"+trim(document.getElementById("txtNombreTo").value);
	document.getElementById("txtDatosEnvio").value+="\n"+trim(document.getElementById("txtEmailTo").value);
	document.getElementById("txtDatosEnvio").value+="\n"+trim(document.getElementById("txtComentario").value);
	document.getElementById("txtEnviar").value="1";
	document.getElementById("formulario").action="indformaenviar.asp";
	document.getElementById("formulario").submit();
}

function altaSuscripcion()
{
	document.getElementById("formulario").action="newsletter.asp";
	document.getElementById("formulario").submit();
}

function controlFocoBuscador()
{
	if (document.getElementById("txtBuscadorInd1").value==" Texto a Buscar ")
	{
		document.getElementById("txtBuscadorInd1").value="";
	}
}

function controlSalidaBuscador()
{
	if (trim(document.getElementById("txtBuscadorInd1").value)=="")
	{
		document.getElementById("txtBuscadorInd1").value=" Texto a Buscar ";
	}	
}

function buscarIndforma()
{
	if (trim(document.getElementById("txtBuscadorInd1").value).length<=3)
	{
		alert ("El criterio de búsqueda debe tener más de 3 caracteres");
		return;
	}
	if (trim(document.getElementById("txtBuscadorInd1").value)=="")	
	{
		alert ("Introduzca la/s palabra/s clave para buscar");
		document.getElementById("txtBuscadorInd1").setFocus();
	}
	else
	{
		document.getElementById("txtBuscaIndforma").value=document.getElementById("txtBuscadorInd1").value;
		document.getElementById("formulario").action="indformabuscar.asp";
		document.getElementById("formulario").submit();
	}
}
function buscarAvIndforma()
{
	document.getElementById("formulario").action="indformaavanzada.asp";
	document.getElementById("formulario").submit();
}

function controlComboAmbito()
{
	document.getElementById("txtIAmbito").value="";
	document.getElementById("divCombos").innerHTML="";
	if (document.getElementById("cmbAmbito").value=="Provincial")
	{
		document.getElementById("txtIAmbito").value="2%";
		cargarComboProvincias();
	}
	else
	{
		if (document.getElementById("cmbAmbito").value=="ccaa")
		{
			document.getElementById("txtIAmbito").value="1%";
			cargarComboAutonomias();
		}
		else
		{
			document.getElementById("txtIAmbito").value="0 " + document.getElementById("cmbAmbito").value
		}	
	}
}

function cargarComboProvincias()
{
	txt='<SELECT id="cmbProv" name="cmbProv" class="formindforma3" onClick="javascript:ponProv()">'
	txt+='<option value="">Cualquiera</option>';
	txt+='<option value="Álava">&Aacute;lava</option>';
	txt+='<option value="Albacete">Albacete</option>';
	txt+='<option value="Alicante">Alicante</option>';
	txt+='<option value="Almería">Almer&iacute;a</option>';
	txt+='<option value="Asturias">Asturias</option>';
	txt+='<option value="Ávila">&Aacute;vila</option>';
	txt+='<option value="Badajoz">Badajoz</option>';
	txt+='<option value="Barcelona">Barcelona</option>';
	txt+='<option value="Burgos">Burgos</option>';
	txt+='<option value="Cáceres">C&aacute;ceres</option>';
	txt+='<option value="Cádiz">C&aacute;diz</option>';
	txt+='<option value="Cantabria">Cantabria</option>';
	txt+='<option value="Castellón">Castell&oacute;n</option>';
	txt+='<option value="Ceuta">Ceuta</option>';
	txt+='<option value="Ciudad Real">Ciudad Real</option>';
	txt+='<option value="Córdoba">C&oacute;rdoba</option>';
	txt+='<option value="Cuenca">Cuenca</option>';
	txt+='<option value="Gerona">Gerona</option>';
	txt+='<option value="Granada">Granada</option>';
	txt+='<option value="Guadalajara">Guadalajara</option>';
	txt+='<option value="Guipúzcoa">Guip&uacute;zcoa</option>';
	txt+='<option value="Huelva">Huelva</option>';
	txt+='<option value="Huesca">Huesca</option>';
	txt+='<option value="Baleares">Islas Baleares</option>';
	txt+='<option value="Jaén">Ja&eacute;n</option>';
	txt+='<option value="La Coruña">La Coru&ntilde;a</option>';
	txt+='<option value="La Rioja">La Rioja</option>';
	txt+='<option value="Las Palmas">Las Palmas</option>';
	txt+='<option value="León">Le&oacute;n</option>';
	txt+='<option value="Lérida">L&eacute;rida</option>';
	txt+='<option value="Lugo">Lugo</option>';
	txt+='<option value="Madrid">Madrid</option>';
	txt+='<option value="Málaga">M&aacute;laga</option>';
	txt+='<option value="Melilla">Melilla</option>';
	txt+='<option value="Murica">Murcia</option>';
	txt+='<option value="Navarra">Navarra</option>';
	txt+='<option value="Orense">Orense</option>';
	txt+='<option value="Palencia">Palencia</option>';
	txt+='<option value="Pontevedra">Pontevedra</option>';
	txt+='<option value="Salamanca">Salamanca</option>';
	txt+='<option value="Segovia">Segovia</option>';
	txt+='<option value="Sevilla">Sevilla</option>';
	txt+='<option value="Soria">Soria</option>';
	txt+='<option value="Tarragona">Tarragona</option>';
	txt+='<option value="Tenerife">Tenerife</option>';
	txt+='<option value="Teruel">Teruel</option>';
	txt+='<option value="Toledo">Toledo</option>';
	txt+='<option value="Valencia">Valencia</option>';
	txt+='<option value="Valladolid">Valladolid</option>';
	txt+='<option value="Vizcaya">Vizcaya</option>';
	txt+='<option value="Zamora">Zamora</option>';
	txt+='<option value="Zaragoza">Zaragoza</option>';
	txt+='</SELECT>';
	document.getElementById("divCombos").innerHTML=txt;
}

function cargarComboAutonomias()
{
	txt='<SELECT id="cmbCCAA" name="cmbCCAA" class="formindforma3" onChange="javascript:ponCCAA()">';
	txt+='<option value="">Cualquiera</option>';
	txt+='<option value="Andalucía">Andaluc&iacute;a</option>';
	txt+='<option value="Aragón">Arag&oacute;n</option>';
	txt+='<option value="Asturias">Asturias</option>';
	txt+='<option value="Canarias">Canarias</option>';
	txt+='<option value="Cantabria">Cantabria</option>';
	txt+='<option value="Castilla y León">Castilla y Le&oacute;n</option>';
	txt+='<option value="Castilla - La Mancha">Castilla - La Mancha</option>';
	txt+='<option value="Cataluña">Catalu&ntilde;a</option>';
	txt+='<option value="Ceuta">Ciudad de Ceuta</option>';
	txt+='<option value="Melilla">Ciudad de Melilla</option>';
	txt+='<option value="Madrid">Comunidad de Madrid</option>';
	txt+='<option value="Valencia">Comunidad Valenciana</option>';
	txt+='<option value="Extremadura">Extremadura</option>';
	txt+='<option value="Galicia">Galicia</option>';
	txt+='<option value="Baleares">Islas Baleares</option>';
	txt+='<option value="La Rioja">La Rioja</option>';
	txt+='<option value="Navarra">Navarra</option>';
	txt+='<option value="Pais Vasco">Pa&iacute;s Vasco</option>';
	txt+='<option value="Murcia">Regi&oacute;n de Murcia</option>';
	txt+='</SELECT>';
	document.getElementById("divCombos").innerHTML=txt;
}

function ponCCAA()
{
	document.getElementById("txtIAmbito").value="1 " + document.getElementById("cmbCCAA").value;
}

function ponProv()
{
	document.getElementById("txtIAmbito").value="2 " + document.getElementById("cmbProv").value;
}

function verCalendario(caja)
{
	var obj=document.forms["formulario"];
	var destino=obj.elements[caja];
	window.open("./includes/calendario.asp?caja="+caja,"","titlebar=no,toolbar=no,scrollbars=no,status=no,width=180,height=160,resizable=yes");
}

function lanzarAvanzada()
{
	document.getElementById("txtBuscaIndformaAv").value=document.getElementById("txtICadena").value + "\n";
	document.getElementById("txtBuscaIndformaAv").value+=document.getElementById("cmbTemas").value + "\n";
	document.getElementById("txtBuscaIndformaAv").value+=document.getElementById("txtIAmbito").value + "\n";
	if (document.getElementById("txtFechaD").value!="dd/mm/aaaa")
	{
		document.getElementById("txtBuscaIndformaAv").value+=document.getElementById("txtFechaD").value + "\n";
	}
	else
	{
		document.getElementById("txtBuscaIndformaAv").value+="\n";
	}
	if (document.getElementById("txtFechaH").value!="dd/mm/aaaa")
	{
		document.getElementById("txtBuscaIndformaAv").value+=document.getElementById("txtFechaH").value + "\n";
	}
	else
	{
		document.getElementById("txtBuscaIndformaAv").value+="\n";
	}
	document.getElementById("formulario").action="indformabuscar.asp?tipo=avanzada";
	document.getElementById("formulario").submit();
}

function controlTecla(e) 
{ 
	/* Ejemplo de patrones para el control:
	
		patron = /\d/; // Solo acepta números
		patron = /\w/; // Acepta números y letras
		patron = /\D/; // No acepta números
		patron =/[A-Za-z\s]/; // Solo acepta letras
		patron =/[A-Za-zñÑ\s]/; // igual que el anterior, pero acepta también las letras ñ y Ñ
		patron = /[ajt69]/; // Solo los caracteres indicados
	*/
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function cambioFoco(origen, destino)
{
	txt=document.getElementById(origen).value;
	if (txt.length==2)
	{
		document.getElementById(destino).focus();	
	}
}

function ponerFecha(valor)
{
	document.getElementById("capaFecha").innerHTML=valor;
}

function quitaValorFecha(caja)
{
	if (document.getElementById(caja).value=="dd/mm/aaaa")
	{
		document.getElementById(caja).value="";
	}
}

function ponValorFecha(caja)
{
	if (document.getElementById(caja).value=="")
	{
		document.getElementById(caja).value="dd/mm/aaaa";
	}
}
