function buscarBlog(){
	var xmlHttp;
	xmlHttp = checkCapabilities();
	
	var tags = document.getElementById("tags").value;  
	var diad = document.getElementById("diad").value;
	var mesd = document.getElementById("mesd").value;
	var aniod = document.getElementById("aniod").value;

	var diah = document.getElementById("diah").value;
	var mesh = document.getElementById("mesh").value;
	var anioh = document.getElementById("anioh").value;

	fecha_desde = aniod + '/' + mesd + '/' + diad ;  
	fecha_hasta = anioh + '/' + mesh + '/' + diah ;
	  
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdResultados").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdResultados").innerHTML = xmlHttp.responseText;
		} 
	}
	xmlHttp.open("GET",baseURL+"getBusqueda.php?tags="+tags+"&fechad="+fecha_desde+"&fechah="+fecha_hasta,true);   

	xmlHttp.send(null);	
}

function getBlogById(id){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdBlog").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdBlog").innerHTML = xmlHttp.responseText;
			getComentarios(); 
		} 
	}
	xmlHttp.open("GET",baseURL+"getBlogById.php?id="+id,true);   
	
	xmlHttp.send(null);	
}

function comentar(id){
    var xmlHttp;
    var id 			= document.getElementById("idBlog").value; 
	var nombre 		= document.getElementById("nombre").value;
	var comentario 	= document.getElementById("comentario").value; 
	
	if(!nombre || !comentario) {
		alert("Faltan completar el datos");
		return;
	
	}else{
	
		xmlHttp = checkCapabilities();

		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState == 4){
				//alert(xmlHttp.responseText);
			//	$total = document.getElementById("total");
			//	$total.innerHTML = parseInt($total.innerHTML)+1;
				nombre = "";
				comentario = ""; 
				// getComentarios();
				window.location.href = $REDIR_URL;
			}
			
		}
		xmlHttp.open("GET",baseURL+"addComentario.php?comentario="+comentario+"&id="+id+"&nombre="+nombre,true);   
		
		xmlHttp.send(null);	
	}
}

function getComentarios(){
    var xmlHttp;
    var id = document.getElementById("idBlog").value;
    xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdComentario").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdComentario").innerHTML = xmlHttp.responseText;
		} 
	}
	xmlHttp.open("GET",baseURL+"getComentarios.php?id="+id,true);   
	
	xmlHttp.send(null);	
}

function addRecommend(){
    var xmlHttp;
    xmlHttp     = checkCapabilities();
	
	var $id         = document.getElementById("idBlog").value;
	var $userMail   = document.getElementById("userMail").value;
	var $userName   = document.getElementById("userName").value;
	var $destMail   = document.getElementById("destMail").value;
	var $destName   = document.getElementById("destName").value;
	//$texto      = document.getElementById("texto").value;
	//$recomendo  = document.getElementById("recomendo").value;
	
	if(!$id || !$userMail || !$destMail || !$destName){
		alert('Por favor complete los campos indicados como obligatorios y vuelva a intentarlo.');
		return ;
	}
    	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdAddRecommend").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdAddRecommend").innerHTML = xmlHttp.responseText;
		} 
	}
	
	xmlHttp.open("GET",baseURL+"addRecommend.php?USER_MAIL=" + $userMail + "&ID_BLOG=" + $id + "&DESTINO_MAIL=" + $destMail + "&DESTINO_NAME=" + $destName + "&USER_NAME=" + $userName ,true);   
	xmlHttp.send(null);	
}

function filtrarBlog(date, tag){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdResultados").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdResultados").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",baseURL+"getBusqueda.php?date="+date+"&tag="+tag,true);   		
	xmlHttp.send(null);	 
}

function pagination(actual){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("pagBlog").innerHTML = "<div align='center'><br><br><img src='images/various/loading.gif'><br><br></div>";
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("pagBlog").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",baseURL+"paginationBlog.php?page="+actual,true);   		
	xmlHttp.send(null);	 	
}
