var recommendWindow;
YAHOO.util.Event.addListener(window, "load", function()
{
	YAHOO.util.Event.addListener("recommendArticle", "click", recommendArticle );	
}
);

var recommendCallback = 
{
	success: function( o )
	{
		eval("var response="+o.responseText);
		if( response.Status == 0 )
			{
				recommendWindow.setBody("Va multumim! Recomandarea dvs. a fost trimisa!");
				// Hide the window after 3 seconds
				setTimeout( function()
				{
					recommendWindow.hide();
				}, 3000);
			}
		
		if( response.Status == 1 )
			{
			var errorContainer = document.getElementById("errorContainer");
			errorContainer.innerHTML = "Au aparut erori la trimiterea acestei recomandari!";
			errorContainer.innerHTML += ("<br />"+Base64.decode(response.Errors));
			}
	},
	failure: function ( o )
	{
	}
};


function recommendArticle()
{
	document.getElementById("recommendWindow").style.display = "block";
	recommendWindow = new YAHOO.widget.Panel("recommendWindow", {
		width: "400px",
		fixedcenter: true,
		visible: false,
		constraintoviewport: true
	}
				  );
	recommendWindow.render(document.body);
	recommendWindow.show();
}

function SendRecommend()
{
	var username = document.getElementById("yourName").value;
	var errorContainer = document.getElementById("errorContainer");
	errorContainer.innerHTML = "";
	if( username == "" )
		errorContainer.innerHTML += "<br />Trebuie sa introduceti numele dvs. pentru a putea recomanda articolul!";

	
	var email = document.getElementById("fromEmail").value;
	if( email == "" )
		errorContainer.innerHTML += "<br />Trebuie sa introduceti adresa dvs. de email pentru a putea recomanda articolul!";

	
	var toEmail = document.getElementById("toEmail").value;
	if( toEmail == "" )
		errorContainer.innerHTML += "<br />Trebuie sa introduceti adresa de email unde trimiteti recomandarea pentru a putea recomanda articolul!";
		

	var articleId = document.getElementById("article_id").value;
	if( errorContainer.innerHTML != "")
		return false;
	var postData = "yourName="+username+"&email="+email+"&toEmail="+toEmail+"&article_id="+articleId;
	YAHOO.util.Connect.asyncRequest("POST", siteUrl+"/articleManagement/recommend", recommendCallback, postData );
	 
}