function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

// *********************************** validar email.. ********************************************
function valEmail(valor){
    
	var re=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_.]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}


  
function valida_suspcripcion() 
{
	   
var nom =document.getElementById("nombre_susp").value;
var emai = document.getElementById("email_susp").value;

 
	 ajax=objetoAjax();
		
			if(trim(nom)== "" )
			{
				//document.getElementById("respuesta2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("suscri").innerHTML = '<table width=213 border=0 align=center cellpadding=0 cellspacing=0><tr><td height=30 colspan=2 bgcolor="#860B0E" class="txtcpie"><div style=padding-left:20px;><span>* Ingrese su nombre</span>  </div></td></tr></table>' ; //imprimimos la palabrita EN:
			}
			else if(trim(emai) == "" )
			{
				//document.getElementById("respuesta_envio2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("suscri").innerHTML = '<table width=213 border=0 align=center cellpadding=0 cellspacing=0><tr><td height=30 colspan=2 bgcolor="#860B0E" class="txtcpie"><div style=padding-left:20px;><span>* Ingrese su email</span>  </div></td></tr></table>' ;
			}
			else if(valEmail(emai) == "" )
			{
				//document.getElementById("respuesta_envio2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("suscri").innerHTML = '<table width=213 border=0 align=center cellpadding=0 cellspacing=0><tr><td height=30 colspan=2 bgcolor="#860B0E" class="txtcpie"><div style=padding-left:20px;><span>Email invalido</span>  </div></td></tr></table>' ;
			}
			else
			{
				
				
				document.getElementById("suscri").innerHTML = '<table width=213 border=0 align=center cellpadding=0 cellspacing=0><tr><td height=30 colspan=2 bgcolor="#860B0E" class="txtcpie"><div style=padding-left:20px;><span>Enviando ...</span>  </div></td></tr></table>' ;
				
				
			ajax.open("POST", "validaciones/mailer-sucripcion.php",true);
					ajax.onreadystatechange=function() 
					{
						if (ajax.readyState==4) {
							//mostrar resultados en esta capa
						
							var res = trim(ajax.responseText);
							if(res=='enviado')
							{
								document.getElementById("suscri").innerHTML = '<table width=213 border=0 align=center cellpadding=0 cellspacing=0><tr><td height=30 colspan=2 bgcolor="#860B0E" class="txtcpie"><div style=padding-left:20px;><span> La suscripcion se ha enviado con exito</span>  </div></td></tr></table>' ;
								document.getElementById("nombre_susp").value='';
								document.getElementById("email_susp").value='';
								
							}
							
							
							
							
						}
					 
					}
					//como hacemos uso del metodo GET
					//colocamos null
			
					ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					ajax.send("nombre="+nom+"&email="+emai);

			}
		 
}

function buscaNoticia() 
{
	   
var nom =document.getElementById("campo").value;
 ajax=objetoAjax();
	
			if(trim(nom)!= "" )
			{
				if(ajax)
				{
					 
				 ajax.open("POST", "noticias.php",true);
				   		
					var query_string3 = crea_query_string3();
					ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					ajax.send(query_string3);
					ajax.onreadystatechange = envia;
					

				}
			}
		 
}
function envia() 
{
	   
 		 
	   document.busqueda.action = "noticias.php";
	   document.busqueda.submit();
			 
}

function crea_query_string3() {


var nom = document.getElementById("campo");


return "campo=" + encodeURIComponent(nom.value) + "&nocache=" + Math.random();



}
 

