var factual = 10;
var fsmallest = 10;
var flargest = 20;
function aumentarFontSize(l){
	factual = (factual >= flargest) ? flargest : factual + 1;
	var lay = window.document.getElementById(l);
	lay.style.fontSize = factual+"px";
	lay.style.lineHeight = (factual + 3) + "px";
}

function reducirFontSize(l){
	factual = (factual <= fsmallest) ? fsmallest : factual - 1;
	var lay = window.document.getElementById(l);
	lay.style.fontSize = factual+"px";
	lay.style.lineHeight = (factual + 3) + "px";
}
// ajax
// Documento JavaScript
// Esta función cargará las paginas
function check_form_cont(){
	if(document.getElementById('nombre').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su NOMBRE !!!";
	} else if(document.getElementById('apellido').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su APELLIDO !!!";
	} else if(document.getElementById('localidad').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su LOCALIDAD !!!";
	} else if(document.getElementById('provincia').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PROVINCIA !!!";
	} else if(document.getElementById('pais').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PAIS !!!";
	} else if(document.getElementById('email').value.length < 8 || document.getElementById('email').value.indexOf('@')< 2 || document.getElementById('email').value.indexOf('.')< 1){
		document.getElementById("resultados").innerHTML="Escriba correctamente su E-MAIL !!!";
	} else if(document.getElementById('asunto').value == ""){
		document.getElementById("resultados").innerHTML="Escriba el ASUNTO de su mensaje !!!";
	} else if(document.getElementById('comentarios').value == ""){
		document.getElementById("resultados").innerHTML="No olvide redactar su MENSAJE !!!";
	} else {
		llamarasincrono('envia_datos.php', 'formulario');
	}
}
function check_form_aviso(){
	if(document.getElementById('nombre').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su NOMBRE !!!";
	} else if(document.getElementById('apellido').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su APELLIDO !!!";
	} else if(document.getElementById('localidad').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su LOCALIDAD !!!";
	} else if(document.getElementById('provincia').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PROVINCIA !!!";
	} else if(document.getElementById('pais').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PAIS !!!";
	} else if(document.getElementById('email').value.length < 8 || document.getElementById('email').value.indexOf('@')< 2 || document.getElementById('email').value.indexOf('.')< 1){
		document.getElementById("resultados").innerHTML="Escriba correctamente su E-MAIL !!!";
	} else if(document.getElementById('asunto').value == ""){
		document.getElementById("resultados").innerHTML="Escriba el ASUNTO de su mensaje !!!";
	} else if(document.getElementById('comentarios').value == ""){
		document.getElementById("resultados").innerHTML="No olvide redactar su MENSAJE !!!";
	} else if(document.getElementById('hacer').value == "" || document.getElementById('hacer').value == undefined || document.getElementById('hacer').value == "Seleccionar"){
		document.getElementById("resultados").innerHTML="SELECCIONE que hacer con su aviso !!!";
	} else if(document.getElementById('categoria').value == "" || document.getElementById('categoria').value == undefined || document.getElementById('categoria').value == "Seleccionar"){
		document.getElementById("resultados").innerHTML="SELECCIONE la Categoría de su aviso !!!";
	} else {
		llamarasincrono('envia_aviso.php', 'form_clas');
	}
}
function check_form_resp(){
	if(document.getElementById('nombre').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su NOMBRE !!!";
	} else if(document.getElementById('apellido').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su APELLIDO !!!";
	} else if(document.getElementById('localidad').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su LOCALIDAD !!!";
	} else if(document.getElementById('provincia').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PROVINCIA !!!";
	} else if(document.getElementById('pais').value == ""){
		document.getElementById("resultados").innerHTML="Escriba correctamente su PAIS !!!";
	} else if(document.getElementById('email').value.length < 8 || document.getElementById('email').value.indexOf('@')< 2 || document.getElementById('email').value.indexOf('.')< 1){
		document.getElementById("resultados").innerHTML="Escriba correctamente su E-MAIL !!!";
	} else if(document.getElementById('asunto').value == ""){
		document.getElementById("resultados").innerHTML="Escriba el ASUNTO de su mensaje !!!";
	} else if(document.getElementById('comentarios').value == ""){
		document.getElementById("resultados").innerHTML="No olvide redactar su MENSAJE !!!";
	} else {
		llamarasincrono('envia_resp.php', 'form_resp');
	}
}
function llamarasincrono(url, id_contenedor){
	var pagina_requerida = false
	if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
		pagina_requerida = new XMLHttpRequest()
	} else if (window.ActiveXObject){ // pero si es IE
		try {
			pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){ // en caso que sea una versión antigua
			try{
				pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
			}
		catch (e){}
		}
	}
	else
	return false
	pagina_requerida.onreadystatechange=function(){ // función de respuesta
		cargarpagina(pagina_requerida, id_contenedor);
	}
	pagina_requerida.open('POST', url, true) // asignamos los métodos open y send
	if (id_contenedor == "miscelaneas"){
		pagina_requerida.send(null);
	} else if (id_contenedor == "formulario"){
		pagina_requerida.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		pagina_requerida.send(retornarRes());
	} else if (id_contenedor == "form_clas"){
		pagina_requerida.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		pagina_requerida.send(retornarAvi());
	} else if (id_contenedor == "form_resp"){
		pagina_requerida.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		pagina_requerida.send(retornarResp());
	} else if (id_contenedor == "clima"){
		var codigo=document.getElementById('clim').value;
		if(codigo != 0){
			cad='codigo='+encodeURIComponent(codigo);
			pagina_requerida.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			pagina_requerida.send(cad);
		}
	} else {
		pagina_requerida.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		pagina_requerida.send(retornarDatos());
	}
}
function retornarDatos(){
  var cad='';
  var dia=document.getElementById('select').value;
  var mes=document.getElementById('select2').value;
  var anio=document.getElementById('select3').value;
  cad='select='+encodeURIComponent(dia)+'&select2='+encodeURIComponent(mes)+'&select3='+encodeURIComponent(anio);
  return cad;
}
function retornarRes(){
  var cad='';
  var nombre=document.getElementById('nombre').value;
  var apellido=document.getElementById('apellido').value;
  var telefono=document.getElementById('telefono').value;
  var localidad=document.getElementById('localidad').value;
  var provincia=document.getElementById('provincia').value;
  var pais=document.getElementById('pais').value;
  var email=document.getElementById('email').value;
  var asunto=document.getElementById('asunto').value;
  var comentarios=document.getElementById('comentarios').value;
  var publicar=document.getElementById('publicar').checked;
  var susc=document.getElementById('news').checked;
  var acttion="save";
  cad='nombre='+encodeURIComponent(nombre)+'&apellido='+encodeURIComponent(apellido)+'&telefono='+encodeURIComponent(telefono)+'&localidad='+encodeURIComponent(localidad)+'&provincia='+encodeURIComponent(provincia)+'&pais='+encodeURIComponent(pais)+'&email='+encodeURIComponent(email)+'&asunto='+encodeURIComponent(asunto)+'&comentarios='+encodeURIComponent(comentarios)+'&publicar='+encodeURIComponent(publicar)+'&susc='+encodeURIComponent(susc)+'&acttion='+encodeURIComponent(acttion);
  //alert(cad);
  return cad;
}
function retornarAvi(){
  var cad='';
  var nombre=document.getElementById('nombre').value;
  var apellido=document.getElementById('apellido').value;
  var telefono=document.getElementById('telefono').value;
  var localidad=document.getElementById('localidad').value;
  var provincia=document.getElementById('provincia').value;
  var pais=document.getElementById('pais').value;
  var email=document.getElementById('email').value;
  var asunto=document.getElementById('asunto').value;
  var comentarios=document.getElementById('comentarios').value;
  var hacer=document.getElementById('hacer').value;
  var categoria=document.getElementById('categoria').value;
  var acttion="save";
  cad='nombre='+encodeURIComponent(nombre)+'&apellido='+encodeURIComponent(apellido)+'&telefono='+encodeURIComponent(telefono)+'&localidad='+encodeURIComponent(localidad)+'&provincia='+encodeURIComponent(provincia)+'&pais='+encodeURIComponent(pais)+'&email='+encodeURIComponent(email)+'&asunto='+encodeURIComponent(asunto)+'&comentarios='+encodeURIComponent(comentarios)+'&hacer='+encodeURIComponent(hacer)+'&categoria='+encodeURIComponent(categoria)+'&acttion='+encodeURIComponent(acttion);
  alert(hacer);
  return cad;
}
function retornarResp(){
  var cad='';
  var nombre=document.getElementById('nombre').value;
  var apellido=document.getElementById('apellido').value;
  var telefono=document.getElementById('telefono').value;
  var localidad=document.getElementById('localidad').value;
  var provincia=document.getElementById('provincia').value;
  var pais=document.getElementById('pais').value;
  var email=document.getElementById('email').value;
  var asunto=document.getElementById('asunto').value;
  var comentarios=document.getElementById('comentarios').value;
  var ema_dest=document.getElementById('ema_dest').value;
  var acttion="save";
  cad='nombre='+encodeURIComponent(nombre)+'&apellido='+encodeURIComponent(apellido)+'&telefono='+encodeURIComponent(telefono)+'&localidad='+encodeURIComponent(localidad)+'&provincia='+encodeURIComponent(provincia)+'&pais='+encodeURIComponent(pais)+'&email='+encodeURIComponent(email)+'&asunto='+encodeURIComponent(asunto)+'&comentarios='+encodeURIComponent(comentarios)+'&ema_dest='+encodeURIComponent(ema_dest)+'&acttion='+encodeURIComponent(acttion);
  return cad;
}

// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText;
	} else {
		if (id_contenedor == "formulario" || id_contenedor == "form_clas" || id_contenedor == "form_resp"){
			document.getElementById("resultados").innerHTML="Aguarde un momento por favor...<br>Conectando con la fuente de datos !!!";
		} else if(id_contenedor == "clima"){
			
		} else {
			document.getElementById(id_contenedor).innerHTML="Aguarde un momento por favor...<br>Conectando con la fuente de datos !!!";
		}
	}
}
// fin ajax
function ver_cat(param){
	if(param!=0){
		window.location='categorias.php?cat='+param;
	}
}
