function show_send2pal(lang)
{
//	document.getElementById("popup_send2pal").style.visibility = "visible";
	
	width = document.body.clientWidth;
	height = document.body.clientHeight;
	document.getElementById("popup_container").style.width = width+"px";
	document.getElementById("popup_container").style.height = height+"px";
	document.getElementById("popup_container").style.visibility = "visible";
	document.getElementById("popup_container").style.opacity = "0";
	document.getElementById("popup_container").style.filter = "alpha(opacity=0)";	
	document.getElementById("popup_send2pal").style.visibility = "visible";
	document.getElementById("popup_send2pal").style.opacity = "0";
	document.getElementById("popup_send2pal").style.filter = "alpha(opacity=0)";
		
	document.getElementById("send2pal_fromname").disabled = false;
	document.getElementById("send2pal_frommail").disabled = false;
	document.getElementById("send2pal_toname").disabled = false;
	document.getElementById("send2pal_tomail").disabled = false;
	document.getElementById("send2pal_tomsg").disabled = false;	
	document.getElementById("send2pal_submit").disabled = false;
	document.getElementById("send2pal_loading").style.visibility = "hidden";
		
	opacity("popup_container", 0, 90, 500);
	opacity("popup_send2pal", 0, 90, 500);
}

function hide_send2pal()
{
	opacity("popup_container", 100, 0, 500, true);
	opacity("popup_send2pal", 100, 0, 500, true);
}

function submit_send2pal()
{
	var fromname = document.getElementById("send2pal_fromname").value;
	var frommail = document.getElementById("send2pal_frommail").value;
	var toname = document.getElementById("send2pal_toname").value;
	var tomail = document.getElementById("send2pal_tomail").value;
	var tomsg = document.getElementById("send2pal_tomsg").value;
	var lang = document.getElementById("send2pal_lang").value;
	
	if (!fromname)
	{
		alert("Veuillez d'abord inscrire votre nom.\n\nPlease first input your name.");
		document.getElementById("send2pal_fromname").focus();
		return false;
	}
	
	if (!frommail || frommail.indexOf("@") == -1 || frommail.indexOf(".") == -1)
	{
		alert("Veuillez d'abord inscrire votre adresse courriel.\n\nPlease first input your email address.");
		document.getElementById("send2pal_frommail").focus();
		return false;
	}
	
	if (!toname)
	{
		alert("Veuillez d'abord inscrire le nom de votre ami(e).\n\nPlease first input your friend's name.");
		document.getElementById("send2pal_toname").focus();
		return false;
	}
	
	if (!tomail || tomail.indexOf("@") == -1 || tomail.indexOf(".") == -1)
	{
		alert("Veuillez d'abord inscrire l'adresse courriel de votre ami(e).\n\nPlease first input your friend's email address.");
		document.getElementById("send2pal_tomail").focus();
		return false;
	}
	
	document.getElementById("send2pal_fromname").disabled = true;
	document.getElementById("send2pal_frommail").disabled = true;
	document.getElementById("send2pal_toname").disabled = true;
	document.getElementById("send2pal_tomail").disabled = true;
	document.getElementById("send2pal_tomsg").disabled = true;	
	document.getElementById("send2pal_submit").disabled = true;
	document.getElementById("send2pal_loading").style.visibility = "visible";
	
	
	ajax_send2pal(fromname, frommail, toname, tomail, tomsg, lang, document.location);
}

function ajax_send2pal(fromname, frommail, toname, tomail, tomsg, lang, loc)
{
	var http_request = create_http_req();
	var url = "inc/send2pal.php";
	var data = "fromname="+fromname+"&frommail="+frommail+"&toname="+toname+"&tomail="+tomail+"&tomsg="+tomsg+"&lang="+lang+"&location="+loc;

	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				if (http_request.responseText == "error") failed = true;
				else
				{
					alert("Notre site web à été recommandé à votre ami(e) avec succès!.\n\nOur web site has been successfully recommenced to your friend!");
					hide_send2pal();
				}
			}
			else failed = true;
			
			if (failed)
			{
				 alert("Impossible d'envoyer la recommendation. Veuillez réessayer de nouveau.\n\nUnable to send recommendation, please try again.");
			
				document.getElementById("send2pal_fromname").disabled = false;
				document.getElementById("send2pal_frommail").disabled = false;
				document.getElementById("send2pal_toname").disabled = false;
				document.getElementById("send2pal_tomail").disabled = false;
				document.getElementById("send2pal_tomsg").disabled = false;	
				document.getElementById("send2pal_submit").disabled = false;
				document.getElementById("send2pal_loading").style.visibility = "hidden";
			}
		}
	};
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	http_request.send(data);
}