function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function emailCheck (emailStr) {
	var myEMailIsValid = true;
	var myAtSymbolAt = emailStr.indexOf('@');
	var myLastDotAt = emailStr.lastIndexOf('.');
	var mySpaceAt = emailStr.indexOf(' ');
	var myLength = emailStr.length;
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 ) {
		myEMailIsValid = false;
	}
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt) {
		myEMailIsValid = false;
	}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	 
	if (myLength - myLastDotAt <= 2) {
		myEMailIsValid = false;
	}
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1) {
		myEMailIsValid = false
	}
		
	if (myEMailIsValid == true) {
		return true;
	}
	else {
		alert("Votre email n'est pas valide.");
		return false;
	}
}

function validationformulaire(){
	object = MM_findObj('nom')
	if ( object.value == "" ){
		alert("Veuillez saisir votre nom.");
		object.focus();
		return false;
	}
	object = MM_findObj('message')
	if (( object.value == "" ) | ( object.value == "Entrer ici votre message")){
		alert("Veuillez saisir votre message.");
		object.focus();
		return false;
	}
	object = MM_findObj('email')
	if ( object.value == "" ){
		alert("Veuillez saisir votre email.");
		object.focus();
		return false;
	}else{
		return emailCheck (object.value)
	}
	return true;
}

function getVar (nomVariable){
	nomVariable = nomVariable + "=";
	var taille = nomVariable.length;
	var variable=0;
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&";
	if (infos.indexOf("#")!=-1) {
		infos = infos.substring(0,infos.indexOf("#"))+"&";
	}
	if (infos.indexOf(nomVariable)!=-1) {
		variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"));
	}
	return variable;
}

function Position (tableau, valeur){
	searchString = valeur;
	var found = -1;
	
	for (var i = 0; i < tableau.length; i++) {
		if (tableau[i] == searchString) {
			found = i;
			break;
		}
	}
	return found;
}
