/**
This example function takes four parameters:

a
    defines the action you want the function to perform.
o
    the object in question.
c1
    the name of the first class
c2
    the name of the second class

Possible actions are:

swap
    replaces class c1 with class c2 in object o.
add
    adds class c1 to the object o.
remove
    removes class c1 from the object o.
check
    test if class c1 is already applied to object o and returns true or false.
 */
function jscss(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}


function validContact(lang)
{
	var r=true;
	
	if(document.getElementById && document.getElementById('contact'))
	{
		var inputs = document.getElementById('contact').getElementsByTagName('input');
		for(var i=0; i<inputs.length; i++)
		{
			if(jscss('check',inputs[i],'mandatory') && inputs[i].value == '')
			{
				jscss('add', inputs[i], 'forgotten');
				r = false;
			}
			else
			{
				jscss('remove', inputs[i], 'forgotten');
			}
		}
		
		var txtArea = document.getElementById('demande');
		if ( txtArea.value == "" )
		{
			jscss('add',txtArea,'forgotten');
			r = false;
		}
		else
		{
			jscss('remove',txtArea,'forgotten');
		}
	}
	
	if(!r)
	{
		if(lang=="en")
			alert("The boxes with an asterisk must be filled out");
		else
			alert("Les champs portant une astérisque sont obligatoires");
	}
	
	return r;
}

/**
 * Show a div for a certain time
 * @param div's ID
 * @param (int) display duration (in seconds)
 */
function showInfo(divId, time)
{
	$(divId).appear();
	setTimeout("$('"+divId+"').fade()", (time+1)*1000);
}
