/**
 * Checks an e-mail address
 * @var strin The e-mail address
 */
function isEmail(email)
{
	var emailRegexp  = /(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z]{3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)(\.[a-z]{2})(\.[a-z]{2})*$)/i;
	return emailRegexp.test(email);
}

/**
 * Sets the background to the highlight color
 * @var object The document object
 */
function listMouseOver(object)
{
	object.style.background='#eeebd7';
}

/**
 * Sets the background to the highlight color
 * @var object The document object
 * @var integer The even/odd value
 */
function listMouseOut(object, i)
{
	if (i % 2)
	{
		//If modified, also change css #rest_list tr.odd
		object.style.background='#e4dfb8';
	}
	else
	{
		//If modified, also change css #rest_list tr.even
		object.style.background='#d8d1ab';
	}
}

/**
 * Sets the area name caption
 * @var object The document
 * @var string The new name
 */
function menuMouseOver(document, menuName, menuDesc)
{
	document.getElementById('menuName').innerHTML = menuName;
	document.getElementById('menuDesc').innerHTML = '- '+menuDesc;
}

/**
 * Removes the area name caption
 * @var document The document
 */
function menuMouseOut(document)
{
	document.getElementById('menuName').innerHTML = '&nbsp;';
	document.getElementById('menuDesc').innerHTML = '&nbsp;';
}


/**
 * Sets the area name caption
 * @var object The document
 * @var string The new name
 */
function areaMouseOver(document, areaName)
{
	document.getElementById('areaName').innerHTML = areaName;
}

/**
 * Removes the area name caption
 * @var document The document
 */
function areaMouseOut(document)
{
	document.getElementById('areaName').innerHTML = '&nbsp;';
}

/**
 * Sets the focus on a form's element
 * @var string The form name
 * @var string The element name (use '' to focus the first element)
 */
function selectElement(form, name)
{
	if (name == '')
	{
		for (var i = 0; i <= form.elements.length-1; i++)
		{
			if (form.elements[i].type != 'hidden')
			{
				form.elements[i].focus();
				break;
			}
		}
	}
	else
	{
		for (var i = 0; i <= form.elements.length-1; i++)
		{
			if (form.elements[i].name == name)
			{
				form.elements[i].focus();
				break;
			}
		}
	}
}

/**
 * Checks the login form fields
 */
function check_login(form) {
  if ((form.login.value.length == 0) || (form.password.value.length == 0)) {
    alert("Veuillez remplir tous les champs, s'il vous plaît.");
    return false;
  }
  return true;
}

/**
 * Sets the background to the highlight color (right navigation on restaurant)
 * @var object The document object
 */
function restaurantNavMouseOver(object)
{
	object.style.background='#eeebd7';
}

/**
 * Sets the background to the highlight color (right navigation on restaurant)
 * @var object The document object
 */
function restaurantNavMouseOut(object)
{
	object.style.background='#dcd5af';
}

/**
 * Sets the background to the highlight color (restaurant's groups links)
 * @var object The document object
 */
function restaurantGroupMouseOver(object)
{
	object.style.background='#f0f0f0';
}

/**
 * Sets the background to the highlight color (restaurant's groups links)
 * @var object The document object
 * @var color  The restaurant background color
 */
function restaurantGroupMouseOut(object, color)
{
	object.style.background=color;
}

/**
 * Sets the background to the highlight color (restaurant's groups links)
 * @var object The document object
 */
function carteMouseOver(object)
{
	object.style.background='#eeebd7';
}

/**
 * Sets the background to the highlight color (restaurant's groups links)
 * @var object The document object
 * @var integer The even/odd value
 */
function carteMouseOut(object, i)
{
	if (i % 2)
	{
		object.style.background='none';
	}
	else
	{
		//If modified, also change css #restaurant table.carte .even
		object.style.background='#ddd7bc';
	}
}

/**
 * Validates the user input into opinion form
 * @var object The form object
 */
function validateOpinion(form)
{
	var result = true;
	if (form['email'].value.length > 0)
		if (!isEmail(form['email'].value))
			result = false;
	if (!result) alert('Erreur de validation: L\'email est incorrect.');
	return result;
}

/**
 * Validates the user input into mailing list subscription form
 * @var object The form object
 */
function validateMailingList(form)
{
	var result = true;
	if (!isEmail(form['email'].value))
		result = false;
	if (!result) alert('Erreur de validation: L\'email est incorrect.');
	return result;
}
