window.onload=function(){
cambiar_evento();
}
function ampliar(objeto){
	new Effect.toggle(objeto+'_conta','appear');
	new Effect.toggle(objeto+'_ver_amigos','appear');
}
function ampliar1(objeto){
	new Effect.toggle(objeto+'_conta','appear');
}

function borrar_amigo(usuario){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=borrar_amigo&amigo='+usuario,
  		onSuccess: function(resp){
  			if(resp.responseText.charAt(0)==1){new Effect.toggle('tarjeta_'+usuario,'appear');}
  			else{alert(resp.responseText);}
  		}
  	});
}

function agregar_amigo(usuario){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=agregar_amigo&amigo='+usuario,
  		onSuccess: function(resp){/*alert(resp.responseText);*/}});
}

function aceptar_amigo(usuario){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=aceptar_amigo&amigo='+usuario,
  		onSuccess: function(resp){
  			if(resp.responseText.charAt(0)==1){new Effect.toggle('tarjeta_'+usuario,'appear');}
  			else{alert(resp.responseText);}
  		}});
}

function cancelar_amigo(usuario){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=cancelar_amigo&amigo='+usuario,
  		onSuccess: function(resp){
  			if(resp.responseText.charAt(0)==1){new Effect.toggle('tarjeta_'+usuario,'appear');}
  			else{alert(resp.responseText);}
  		}});
}

function aceptar_foto(idfoto,tipo){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=aceptar_foto&foto='+idfoto+'&tipo='+tipo,
  		onSuccess: function(resp){
  			if(resp.responseText.charAt(0)==1){new Effect.toggle('tarjeta_'+idfoto+'_'+tipo,'appear');}
  			else{alert(resp.responseText);}
  		}});
}

function cancelar_foto(idfoto,tipo){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=cancelar_foto&foto='+idfoto+'&tipo='+tipo,
  		onSuccess: function(resp){
  			if(resp.responseText.charAt(0)==1){new Effect.toggle('tarjeta_'+idfoto+'_'+tipo,'appear');}
  			else{alert(resp.responseText);}
  		}});
}

function buscar_na(){
	new Ajax.Request(window.location.pathname, {
  		method: 'post',
  		parameters: 'metodo=b_amigos&'+Form.serialize($('form_bna')),
  		onSuccess: function(resp){
  			$('cuerpo').innerHTML=resp.responseText;
  			cambiar_evento();
  		}});
}

function cambiar_evento(){
	//alert('cambiando evento');
	a=$('paginacion').getElementsByTagName('span');
	for(var i in a){
		if(typeof(a[i])=='object'){
			if(a[i].getElementsByTagName('a').length>0){
				if(a[i].getElementsByTagName('a')[0].addEventListener)
					a[i].getElementsByTagName('a')[0].addEventListener('click',pagina,false);
				else
					a[i].getElementsByTagName('a')[0].attachEvent('onclick',pagina);
			}
		}
	}
}
	
function pagina(e){
	ancla=e.currentTarget;
	//alert(ancla.href);
	new Ajax.Request(ancla.href,{
 		method: 'post',
 		parameters: 'metodo=b_amigos&'+Form.serialize($('form_bna')),
  	onSuccess: function(resp){
  		$('cuerpo').innerHTML=resp.responseText;
  		cambiar_evento();
  	}});

 	e.preventDefault();
}
