function checkRunEnviarMensaje(){
	var asunto = document.getElementById('div_soc_asunto');
	var mensaje = document.getElementById('div_soc_mensaje1');
	var destinatario = document.getElementById('div_soc_destinatario').value;
	
	if (asunto.value == ''){alert('Complete el asunto'); asunto.focus(); return false;}
	if (mensaje.value == ''){alert('Complete el mensaje'); mensaje.focus(); return false;}
	
	var postData = "asunto="+escape(asunto.value)+"&mensaje="+escape(mensaje.value)+"&amigo="+destinatario;

	document.getElementById('div_soc_gif1').style.visibility = 'visible';

	var oBackEnvMsj = {success:okBackEnvMsj, failure: badBackEnvMsj};
	YAHOO.util.Connect.asyncRequest("POST", "enviar_mensaje.php", oBackEnvMsj, postData);

	return true;
}
var okBackEnvMsj = function(o)
{
	document.getElementById('div_soc_gif1').style.visibility = 'hidden';

	var resp = YAHOO.lang.JSON.parse(o.responseText);
	if (typeof resp != 'undefined') 
	{
		document.getElementById('div_soc_gal_2').style.display = 'none';
		alert(resp.mensaje);
	}
}
var badBackEnvMsj = function(o)
{
	
}
//------------------------------------------------------------------------------------
function checkRunAgregarAmigo(){
	var mensaje = document.getElementById('div_soc_mensaje2');
	var amigo = document.getElementById('div_soc_amigo').value;
	
	if (mensaje.value == '' || mensaje.value == 'Escribe un mensaje personal...'){
		alert('Ingresa el mensaje'); mensaje.focus(); return false;
	}
	var postData = "mensaje="+escape(mensaje.value)+"&usuario="+amigo;
	
	document.getElementById('div_soc_gif2').style.visibility = 'visible';

	var oBackAddAmigo = {success:okBackAddAmigo, failure: badBackAddAmigo};
	YAHOO.util.Connect.asyncRequest("POST", "enviar_solicitud.php", oBackAddAmigo, postData);
	
	return true;
}
var okBackAddAmigo = function(o){
	document.getElementById('div_soc_gif2').style.visibility = 'hidden';

	var resp = YAHOO.lang.JSON.parse(o.responseText);
	if (typeof resp != 'undefined'){
		document.getElementById('div_soc_gal_3').style.display = 'none';
		alert(resp.mensaje);
	}
}
var badBackAddAmigo = function(o){}
//------------------------------------------------------------------------------------
function runEnviarMensaje(destinatario, id_img){
	document.getElementById('div_soc_gal_1').style.display = 'none';
	document.getElementById('div_soc_gal_3').style.display = 'none';
	document.getElementById('div_soc_destinatario').value = destinatario;

	var img_1 = document.getElementById('img_' + id_img);
	var div_2 = document.getElementById('div_soc_gal_2');	
	var posx1 = pos_real(img_1, 'x') - 80;

	if (typeof ensociales != 'undefined'){
		var posy1 = pos_real(img_1, 'y') + 210;
	} else {
		var posy1 = pos_real(img_1, 'y') - 15;
	}
	div_2.style.left = posx1 + 'px';
	div_2.style.top  = posy1 + 'px';
	div_2.style.display = '';
}
//------------------------------------------------------------------------------------
function runAgregarAmigo(amigo, id_img){
	document.getElementById('div_soc_gal_1').style.display = 'none';
	document.getElementById('div_soc_gal_2').style.display = 'none';
	document.getElementById('div_soc_amigo').value = amigo;

	var img_1 = document.getElementById('img_' + id_img);
	var div_2 = document.getElementById('div_soc_gal_3');
	var posx1 = pos_real(img_1, 'x') - 80;
	
	if (typeof ensociales != 'undefined'){
		var posy1 = pos_real(img_1, 'y') + 215;
	} else {
		var posy1 = pos_real(img_1, 'y') - 15;
	}
	div_2.style.left = posx1 + 'px';
	div_2.style.top  = posy1 + 'px';
	div_2.style.display = '';
}
//------------------------------------------------------------------------------------
function openDivSocGaleria(usuario, logueado, id_img){
	
	if (logueado == 0){
		alert('Debe iniciar sesi\u00F3n para acceder a esta funcionalidad'); return false;
	}
	document.getElementById('div_soc_gal_2').style.display = 'none';
	document.getElementById('div_soc_gal_3').style.display = 'none';
	
	var axTop = typeof ensociales != 'undefined' ? 320 : 100;
	var runme = document.getElementById('div_run_mensaje');
	var runam = document.getElementById('div_run_amigo');
	var suesp = document.getElementById('div_soc_suespacio');
	var img_1 = document.getElementById('img_' + id_img);
	var div_1 = document.getElementById('div_soc_gal_1');
	
	var posx1 = pos_real(img_1, 'x') - 5;
	var posy1 = pos_real(img_1, 'y') + axTop;
  
 
	suesp.href = 'suespacio.php?su='+usuario;
	runme.href = 'javascript:runEnviarMensaje(' + usuario + ', ' + id_img + ');';
	runam.href = 'javascript:runAgregarAmigo(' + usuario + ', ' + id_img + ');';

	div_1.style.left = posx1 + 'px';
	div_1.style.top  = posy1 + 'px';
	div_1.style.display = '';

	return true;
	
}
//------------------------------------------------------------------------------------
function closeDivSocGaleria(cual){
	document.getElementById('div_soc_gal_'+cual).style.display = 'none';
}
//------------------------------------------------------------------------------------
function pos_real(objeto, cual){
	var curleft = curtop = 0;
	if (objeto.offsetParent){
		curleft= objeto.offsetLeft;
		curtop = objeto.offsetTop;
		while (objeto = objeto.offsetParent){
			curleft += objeto.offsetLeft;
			curtop += objeto.offsetTop;
	}}
	if (cual=='x'){return curleft;} else {return curtop;}
}
//------------------------------------------------------------------------------------
function verDivFpreview(accion, id_thumb){
	var oDiv = document.getElementById('o_DivFpreview_'+id_thumb);

	if (accion == 1){
		var oThb = document.getElementById('imgthumbsd_'+id_thumb);
		var xThb = pos_real(oThb, 'x');
		var auxX = xThb - 45;

		oDiv.style.visibility = 'visible';
		oDiv.style.left = auxX + 'px';	
	} else {
		oDiv.style.visibility = 'hidden';		
		
	}
}

