function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}

function FAjax (url,capa,valores,metodo)
{
          var ajax=creaAjax();
          var capaContenedora = document.getElementById(capa);

/*Creamos y ejecutamos la instancia si el metodo elegido es POST*/
if(metodo.toUpperCase()=='POST'){
         ajax.open ('POST', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(valores);
         return;
}
/*Creamos y ejecutamos la instancia si el metodo elegido es GET*/
if (metodo.toUpperCase()=='GET'){

         ajax.open ('GET', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                                      capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200){
                                             document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                                             else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(null);
         return
}
} 

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
function mostrar_not(){ 
document.getElementById("noticias_panel").style.visibility="visible"; 
} 
function ocultar_not(){ 
document.getElementById("noticias_panel").style.visibility="hidden"; 
} 


function mostrar_pm(){ 
document.getElementById("policiames").style.visibility="visible"; 
} 
function ocultar_pm(){ 
document.getElementById("policiames").style.visibility="hidden"; 
} 

function mostrar_lp(){ 
document.getElementById("leyespolicia").style.visibility="visible"; 
} 
function ocultar_lp(){ 
document.getElementById("leyespolicia").style.visibility="hidden"; 
} 

function mostrar_cm(){ 
document.getElementById("cumpleaneromes").style.visibility="visible"; 
} 
function ocultar_cm(){ 
document.getElementById("cumpleaneromes").style.visibility="hidden"; 
}

function validarcomentario()
{
	nombres=document.formulario.nombres.value;
	telefono=document.formulario.telefono.value;
	email=document.formulario.email.value;
	comentarios=document.formulario.comentarios.value;

	error=0;
	mensaje="";
	
	if (comentarios=="")
	{
		error=1;
		mensaje="ingresa tus comentarios";
		document.formulario.comentarios.focus();
	}
	if (email=="")
	{
		error=1;
		mensaje="ingresa tu e-mail";
		document.formulario.email.focus();
	}
	else
	{
		var s = email;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		if (s.length == 0 ) return true;
		if (!filter.test(s))
		{
			error=1;
			mensaje="ingresa un e-mail valido";
			document.formulario.email.focus();
		}
	}
	if (telefono=="")
	{
		error=1;
		mensaje="ingresa tu telefono";
		document.formulario.telefono.focus();
	}
	if (nombres=="")
	{
		error=1;
		mensaje="ingresa tu nombre y apellido";
		document.formulario.nombres.focus();
	}
	if (error==1)
	{
		alert("Por favor "+mensaje);
		error=0;
	}
	else
	{
		variables="nombres="+nombres+"&tlf="+telefono+"&email="+email+"&comentario="+comentarios;
		FAjax('webinfantil_contactanos2.php','enviarformulario',''+variables,'post');
		document.formulario.reset();
	}
}
