function checkContactForm()
{
	document.contact.action ="mail.php?id=1";
	var a = 1;
	for (i = 0 ; i <= (document.contact.length - 1) ; i++)
	{
		if (document.contact[i].className == "isRequired")
		{
			if (document.contact[i].value == '')
			{
				if (a == 1)
				{
					document.contact[i].focus();
				}
				document.getElementById(document.contact[i].name + 'Error').innerHTML = "<img src=\"images/icons/exclamation.png\" alt=\"Doit être remplis\" />";
				a = 0;
			}
			else
			{
				document.getElementById(document.contact[i].name + 'Error').innerHTML = "";
			}
		}
	}
	if (a == 0)
	{
		document.getElementById('error').innerHTML = "<br /><span class=\"important\" style=\"color:red;\">Veuillez remplir tous les champs avec un *.</span>";
	}
	else
	{
		document.getElementById('error').innerHTML = "";
		document.getElementById('waitingMail').style.display = "block";
		sendMail();
	}
}

function showMail(id, town, date)
{
	for (i = 0 ; i <= (document.contact.length - 1) ; i++)
	{
			if (document.contact[i].type != "button")
			{
				document.contact[i].value = '';
			}
	}
	Effect.Appear('sendMail', {duration:0.3});
	document.contact.type.value = id;
	document.contact.date.value = date;
	document.contact.salon.value = town;
	document.getElementById('titleContact').innerHTML = 'Invitation pour le salon de <br />' + town + '<br />' + date;
}

function closeMail()
{
	Effect.Fade('sendMail', {duration:0.3});
	document.getElementById('waitingMail').style.display = "none";
	document.getElementById('error').innerHTML = "";
}

function sendMail()
{
	new Ajax.Request(
		'includes/php/_contact_mail.php',
		{
			method: 'post',
			parameters: {country: $('country').value, tel: $('tel').value, name: $('name').value, rs: $('rs').value, date: $('date').value, salon: $('salon').value, email: $('email').value, type: $('type').value, addr: $('addr').value, codep: $('codep').value, town: $('town').value},
			onSuccess: function(test) {
					document.getElementById('error').innerHTML = test.responseText;
					//"<br /><table align=\"center\"><tr><td align=\"right\" valign=\"middle\"><img src=\"images/icons/accept.png\" alt=\"\" /></td><td valign=\"middle\"><span class=\"important\">Message envoy&eacute;</span></td></tr></table>"; 
					document.getElementById('waitingMail').style.display = "none";
			},
			onFailure: function(test) {
					document.getElementById('error').innerHTML = "<br /><table align=\"center\"><tr><td align=\"right\" valign=\"middle\"><img src=\"images/icons/exclamation.png\" alt=\"\" /></td><td valign=\"middle\"><span class=\"important\" style=\"color:red;\">Envoi &eacute;chou&eacute;</span></td></tr></table>"; 
					document.getElementById('waitingMail').style.display = "none";
			}
		}
	);
}