// JavaScript Document
function objectFlash(theFile, largeur, hauteur, flashvars ) 
{
    document.write('<object type=\"application/x-shockwave-flash\" data=\"' + theFile + '\" width=\"' + largeur + '\" height=\"' + hauteur + '\">' +
    ' <param name=\"FlashVars\" value=\"' + flashvars + '\" />' +
    ' <param name=\"movie\" value=\"' + theFile + '\" />' + 
    ' </object>');

}

function valForm(lang)
{
	var checkresult = true;
	
	if (Trim(document.getElementById('nom').value) == '')
	{		
		if(lang == 'fr')
		{
			alert('Veuillez remplir le champ "Nom"');
		}	
		else if(lang == 'en')
		{
			alert('Please fill in the field "Name"');
		}
		document.getElementById('nom').focus();
		checkresult = false;
		return false;
	}
	
	if(!alpabets(Trim(document.getElementById('nom').value), 'Nom'))
	{			
		if(lang == 'fr')
		{
			alert('Caractère illégal dans le champ "Nom"')
		}	
		else if(lang == 'en')
		{
			 alert('Invalid character in the field "Name"');
		}
		document.getElementById('nom').focus();
		checkresult = false;
		return false;
	}
	
	if(!maxlen( document.getElementById('nom').value, 'Nom',3,'errors'))
	{
		if(lang == 'fr')
		{
			alert('Veuillez inserer un minimum de 3 caractères dans le champ "Nom"');
		}	
		else if(lang == 'en')
		{
			 alert('Please enter a minimum of 3 characters in the field "Name"');
		}
		document.getElementById('nom').focus();
		checkresult = false;
		return false;
	}
	
	if (Trim(document.getElementById('email').value) == '')
	{		
		if(lang == 'fr')
		{
			alert('Veuillez remplir le champ "Email"');
		}	
		else if(lang == 'en')
		{
			alert('Please fill in the field "Email"');
		}
		document.getElementById('email').focus();
		checkresult = false;
		return false;
	}
	
	if (!validateEmail(document.getElementById('email').value))
	{
		if(lang == 'fr')
		{
			alert('Adresse email invalide');
		}	
		else if(lang == 'en')
		{
			 alert('Invalid Email Address');
		}
		document.getElementById('email').focus();
		checkresult = false;
		return false;
	}
	
	if (Trim(document.getElementById('tel').value) == '')
	{
		if(lang == 'fr')
		{
			alert('Veuillez remplir le champ "Tel"');
		}	
		else if(lang == 'en')
		{
			 alert('Please fill in the field "Telephone"');
		}
		document.getElementById('tel').focus();
		checkresult = false;
		return false;
	}
	
	if (!validatePhone(document.getElementById('tel').value))
	{
		 if(lang == 'fr')
		{
			alert('Téléphone invalide');
		}	
		else if(lang == 'en')
		{
			 alert('Invalid telephone number');
		}	
		 document.getElementById('tel').focus();
		 checkresult = false;
		return false;
	}

	if (Trim(document.getElementById('sujet').value) == '')
	{		
		if(lang == 'fr')
		{
			alert('Veuillez remplir le champ "Sujet"');
		}	
		else if(lang == 'en')
		{
			alert('Please fill in the field "Subject"');
		}
		document.getElementById('sujet').focus();
		checkresult = false;
		return false;
	}
	
	if(!alpabets(Trim(document.getElementById('sujet').value), 'Sujet'))
	{			
		if(lang == 'fr')
		{
			alert('Caractère illégal dans le champ "Sujet"')
		}	
		else if(lang == 'en')
		{
			 alert('Invalid character in the field "Subject"');
		}
		document.getElementById('sujet').focus();
		checkresult = false;
		return false;
	}
	
	if(!maxlen( document.getElementById('sujet').value, 'Sujet',3,'errors'))
	{
		if(lang == 'fr')
		{
			alert('Veuillez inserer un minimum de 3 caractères dans le champ "Sujet"');
		}	
		else if(lang == 'en')
		{
			 alert('Please enter a minimum of 3 characters in the field "Subject"');
		}
		document.getElementById('sujet').focus();
		checkresult = false;
		return false;
	}
	
	if (Trim(document.getElementById('message').value) == '')
	{		
		if(lang == 'fr')
		{
			alert('Veuillez remplir le champ "Message"');
		}	
		else if(lang == 'en')
		{
			alert('Please fill in the field "Message"');
		}
		document.getElementById('message').focus();
		checkresult = false;
		return false;
	}
	
	if(!maxlen( document.getElementById('message').value, 'Message',25,'errors'))
	{
		if(lang == 'fr')
		{
			alert('Veuillez inserer un minimum de 25 caractères dans le champ "Message"');
		}	
		else if(lang == 'en')
		{
			 alert('Please enter a minimum of 25 characters in the field "Message"');
		}
		document.getElementById('message').focus();
		checkresult = false;
		return false;
	}
	
	if(checkresult)
	{
		document.getElementById('frmSubmit').submit();
	}
}

function Trim(TRIM_VALUE)
{
  if(TRIM_VALUE.length < 1)
  {
    return"";
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE=="")
  {
    return "";
  }
  else
  {
    return TRIM_VALUE;
  }
}

function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0)
  {
    return "";
  }
  var iTemp = v_length -1;
  while(iTemp > -1)
  {
    if(VALUE.charAt(iTemp) == w_space)
	{
    }
    else
	{
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  } //End While
  return strTemp;
} //End Function

function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1)
  {
    return"";
  }
  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;
  while(iTemp < v_length)
  {
    if(VALUE.charAt(iTemp) == w_space)
	{
    }
    else
	{
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } //End While
  return strTemp;
} //End Function

function validatePhone(theNumber)
{
  var phoneRegex = /^(\+)?(\d)?(\d)?(\d)?(\s)?(\d){7}(\d)?(\d)?(\d)?$/;
  var chknum = theNumber;
  var result = chknum.match(phoneRegex);
  return result;
}

function alpabets(string, fieldName)
{
	
	 var charpos = string.search("[^A-Za-z\-àâäèéêëîïôœûüÿç' ]"); 
	  if(string.length > 0 &&  charpos >= 0) 
	  { 
		return false; 
	  }
	return true;
}

function maxlen(strng, field, len,msg)
{
	 if (strng.length < len)
	 {
		return false;
	 }
	 else
	 {
	 	return true;
	 }
}

function validateEmail(emailStr) 
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:'\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		return false;
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
	
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				return false;
	   		}
		}
		return true;
	}
	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			return false;
	   	}
	}
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}