function check_value(var_n, field_n)
{
	if ($F(field_n) == '')
	{
		$(field_n  + '_check').innerHTML = '<img src="formulaires/images/warning.gif" />';
		$(field_n).style.border = '1px red solid';
		$(field_n).focus();
	}
	else
	{
		var opt = {
		method:'post', 
		postBody:'m=check&type=' + var_n + '&value=' + $F(field_n),
		onSuccess: function (t) { update_check(t, field_n); },
		onLoading: function() {}
		}
		new Ajax.Request('http://www.ohada.com/formulaires/ajax/SendToFriendForm.php', opt);
	}
}

function update_check(t, field_n)
{
	if(t.responseText == "0")
	{
		$(field_n  + '_check').innerHTML = '<img src="formulaires/images/warning.gif" />';
		$(field_n).style.border = '1px red solid';
		$(field_n).focus();
	}
	else if(t.responseText == "1")
	{
		//Good to go!
		$(field_n  + '_check').innerHTML = '<img src="formulaires/images/check.gif" />';
		$(field_n).style.border = '1px green solid';
		$('SendToFriendButton').value = 'Envoyer'; $('SendToFriendButton').disabled = false;
	}


}
function SendToFriend()
{
	//Basic error checking
	if($F('SendToFriendNom') == '' || $F('SendToFriendEmail') == '' || $F('SendToFriendNomAmi') == '' || $F('SendToFriendEmailAmi') == '' || $F('SendToFriendCode') == '')
	{
		alert("Tous les champs sont obligatoires");
		return;
	}
	else
	{
		//Construct the AJAX object, add all form fields in the SendToFriendForm to the paramaters
		var opt =
		{
			method:'post', 
			postBody:'m=send&' + Form.serialize('SendToFriendForm'),
			//onSuccess: function(t){document.getElementById('SendToFriendForm').innerHTML =t.responseText;},
			onLoading: function()
			{
				$('SendToFriendButton').value = 'En cours...'; $('SendToFriendButton').disabled = true;
			},
			onSuccess: function(t)
			{
				value = t.responseText,
				resultat = value.split('|');
				if (resultat[0] == "0")
				{
					value1 = value[1];
					resultat1 = value1.split('\n');
					for(var i=0; i<resultat.length; i++)
					{
						value2 = resultat[i],
						resultat2 = value2.split(',');
						if(resultat2[0] == "0")
						{
							$(resultat2[1]  + '_check').innerHTML = '<img src="formulaires/images/warning.gif" />';
							$(resultat2[1]).style.border = '1px red solid';
							$(resultat2[1]).focus();
						}
						else if(t.responseText == "1")
						{
							//Good to go!
							$(resultat2[1]  + '_check').innerHTML = '<img src="formulaires/images/check.gif" />';
							$(resultat2[1]).style.border = '1px green solid';
						}
					}

				}
				else if (resultat[0] == "1")
				{
					document.getElementById('SendToFriendForm').innerHTML =resultat[1];
				}

			}
		}
		new Ajax.Request('formulaires/ajax/SendToFriendForm.php', opt);
	}
}
