function changePage(page)
{
	self.location.href = "?section=Home&action=show&subsection=5&pag=" + page;
}



function showEmailForm(button)
{
	obj = document.getElementById('email_form_div');
	
	obj.style.left = getAbsoluteLeftInput(button) + "px";
	obj.style.top = (getAbsoluteTopInput(button) + 23) + "px";
	
	form = document.forms.emailForm;
	
	form.emails.value = "";
	form.descripcion.value = "";
	
	Effect.toggle('email_form_div', '', {duration: 0.5});
}

function hideEmailForm()
{
	Effect.toggle('email_form_div', '', {duration: 0.5});
}

function showShareForm(button)
{
	obj = document.getElementById('share');
	
	obj.style.left = getAbsoluteLeftInput(button) + "px";
	obj.style.top = (getAbsoluteTopInput(button) + 23) + "px";
	
	
	Effect.toggle('share', '', {duration: 0.5});
	
}

function hideShareForm()
{
	obj = document.getElementById('share');
	obj.style.display = "none";
}



function submitEmailForm(id)
{
	loading = document.getElementById('enviando_email');
	formdiv = document.getElementById('email_form_div_intern');
	div = document.getElementById('email_form_div');
	
	form = document.forms.emailForm;

	
	var txt = form.emails.value.replace(/ /g, "");	

	if(txt.length == 0) 
	{
		alert("Debe ingresar al menos un E-Mail.");
		form.emails.focus();
		return;
	}
		
	
	myajax = new MyAjax();

	myajax.RegisterEvents(
	{
		onStart: function()
		{
			loading.style.display = "block";
			formdiv.style.display = "none";
		},
		onComplete: function()
		{
			loading.style.display = "none";
			formdiv.style.display = "block";
			div.style.display = "none";
		}
	});

	myajax.SendForm("?section=Home&action=emailnovedad&id=" + id,  form);
}

function userLikes(id)
{
	//form = document.forms.emailForm;

	myajax = new MyAjax();

	myajax.RegisterEvents(
	{
		onStart: function()
		{
		},
		onComplete: function()
		{
			var countSpan = parseInt(document.getElementById("count_" + id).innerHTML);
			countSpan++;
			document.getElementById("usersLike_" + id).innerHTML = "A " + countSpan + " personas les gusta este artículo.";
			document.getElementById("likeBtn_" + id).style.display = "none";
		}
	});

	myajax.Send("?section=Home&action=userlikes&id=" + id, "POST");
}

function showAll(id)
{
	document.getElementById('hiddencomments_' + id).style.display = "block";
	document.getElementById('tohidecomments_' + id).style.display = "none";		
}


function commentFocus(textarea, id)
{
	document.getElementById('btnComment_' + id).style.display = "inline";
	document.getElementById('userInfo_' + id).style.display = "block";
	
	textarea.style.color = "black";
	textarea.style.height = "50px";
	textarea.value = "";
	
	
}

function commentLostFocus(textarea, id)
{
	if(textarea.value == "")
	{
		document.getElementById('userInfo_' + id).style.display = "none";

		document.getElementById('btnComment_' + id).style.display = "none";
		textarea.style.color = "#aaa";
		textarea.style.height = "25px";
		textarea.value = "Escribir un comentario..";
	}
}


function sendComment(id)
{
	
	var iduser 	= document.getElementById('idusuario').value;
	var username= document.getElementById('username').value;	

	var name = "";
	var mail = "";
	
	if(username == "" || iduser == 0 || iduser == "")
	{
		name 	= document.getElementById('nombre_' + id).value;
		mail 	= document.getElementById('correo_' + id).value;
		username = name;

	}
	

	var comment = nl2br(document.getElementById('comment_' + id).value, false);
		
	
	if(comment.length == 0)
		return;
	
	if(iduser == 0)
	{
		if(name == "")
		{
			document.getElementById("err_nombre_" + id).innerHTML = "* Debe ingresar un nombre";
			document.getElementById("err_nombre_" + id).focus();
			return;
		}
		
		if(mail == "")
		{
			document.getElementById("err_correo_" + id).innerHTML = "* Debe ingresar un correo";
			document.getElementById("err_correo_" + id).focus();
			return;
		}
	}
	
		
	
	
	myajax = new MyAjax();
	myajax.RegisterEvents(
	{
		onStart: function()
		{
			document.getElementById('comment_' + id).disabled = true;	
			
			if(iduser == 0 || iduser == "")
			{
				document.getElementById('nombre_' + id).disabled = true;
				document.getElementById('correo_' + id).disabled = true;
			}
				
		},
		onComplete: function()
		{	
			document.getElementById('comment_' + id).disabled = false;	
			
			if(iduser == 0 || iduser == "")
			{
				document.getElementById('nombre_' + id).disabled = false;
				document.getElementById('correo_' + id).disabled = false;
			}
			
			content = '<div style="background: #F0DAEB; padding: 7px; margin-top: 1px;"><b>' + username + ':</b> ' + comment.replace(/[<|>]/g, "").replace(/-br-/g, "<br />") + '</div>';
			
			document.getElementById('hiddencomments_' + id).innerHTML += content;
			document.getElementById('tohidecomments_' + id).innerHTML += content;	
			
			document.getElementById('comment_' + id).value = "";
			commentLostFocus(document.getElementById('comment_' + id), id);	
		}
	});
	
	myajax.Send("?section=Home&action=addcoment&id=" + id + "&nombre=" + name + "&correo=" + mail + "&descripcion=" + comment, "POST");
	
}
