function nuevoAjax()
{ 
	var xmlhttp=false;
	try
	{	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e)
	{ 
		try
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(E)
		{if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();	}
	}
	return xmlhttp; 
}

function ocultarTododiv()
{

var cantidad_resultado  =  document.form.cantidad_resultado.value;
    var j = 1;
   while (j <= cantidad_resultado){		
		
		var div_respuesta       =  eval('document.getElementById(\'div_respuesta'+j+'\')');	

		div_respuesta.innerHTML="<div id=\"div_respuesta"+j+"\"></div>";

		j++;
   }
}


function ver_invitarAmigo(i, id_usuario)
{
	
   ocultarTododiv();

    var div_respuesta       =  eval('document.getElementById(\'div_respuesta'+i+'\')');	
	var ajax = nuevoAjax();
		ajax.open("GET", "buscar_respuesta.php?id="+i+"&id_usuario="+id_usuario+"&operacion=4", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
				div_respuesta.style.visibility='visible';
				div_respuesta.style.display="";
				div_respuesta.innerHTML=ajax.responseText;
			  
			} 
		}
		ajax.send(null);
}

function enviarInvitacion(i, confirmar)
{
    var div_m    =  eval('document.getElementById(\'div_m'+i+'\')');	
	
 	var id_usuario      =  eval('document.form.id_usuario.value');
	var mensaje        =  eval('document.form.mensaje.value');
	
		var clave = document.getElementById('codigo_valida');	
 
	
	ajax=nuevoAjax();
	ajax.open("GET", "buscar_verificar_codigo.php?codigo_valida="+clave.value,true);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
			
			if (ajax.responseText=="0")
			{
				alert("Por favor, introduzca el código de validación correcto");			
				document.form.codigo_valida.focus(); return; 
			}
			if (ajax.responseText=="1")
			{  
			    
			    var ajax2 = nuevoAjax();
				
				ajax2.open("GET", "buscar_respuesta.php?id="+i+"&id_usuario="+id_usuario+"&mensaje="+mensaje+"&confirmar="+confirmar+"&operacion=5", true);
				ajax2.onreadystatechange=function() 
				{ 
					if (ajax2.readyState==4)
					{
						div_m.innerHTML=ajax2.responseText;
					} 
				}
				ajax2.send(null);

			}

		}
	}
	ajax.send(null);



}

function agregarContacto(i, id_usuario, confirmacion)
{
	// Confirmacion indica si se requiere aprobacion por un usuario initado o no para poder formar parte de una red
	
ocultarTododiv();
   

    var span_m       =  eval('document.getElementById(\'span_m'+i+'\')');	
	var ajax = nuevoAjax();
		ajax.open("GET", "buscar_respuesta.php?id="+i+"&id_usuario="+id_usuario+"&confirmacion="+confirmacion+"&operacion=14", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
				span_m.style.visibility='visible';
				span_m.style.display="";
				span_m.innerHTML=ajax.responseText;
			  
			} 
		}
		ajax.send(null);
}




function agregarContacto2(i, id_usuario, confirmacion)
{
	// Confirmacion indica si se requiere aprobacion por un usuario initado o no para poder formar parte de una red
	
   

    var span_m       =  eval('document.getElementById(\'span_m'+i+'\')');	
	var ajax = nuevoAjax();
		ajax.open("GET", "buscar_respuesta.php?id="+i+"&id_usuario="+id_usuario+"&confirmacion="+confirmacion+"&operacion=14", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{ 
				span_m.style.visibility='visible';
				span_m.style.display="";
				span_m.innerHTML=ajax.responseText;
			  
			} 
		}
		ajax.send(null);
}



