function xmlhttpPost ( strURL )
{
	var xmlHttpReq = false ;
	var self       = this  ;

	// Mozilla/Safari
	if ( window.XMLHttpRequest )
	{
		self.xmlHttpReq = new XMLHttpRequest () ;
	}
	// IE
	else if ( window.ActiveXObject ) 
	{
		self.xmlHttpReq = new ActiveXObject ( "Microsoft.XMLHTTP" ) ;
	}

	self.xmlHttpReq.open ( 'POST' , strURL , true ) ;
	self.xmlHttpReq.setRequestHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;

	self.xmlHttpReq.onreadystatechange = function ()
	{
		if ( self.xmlHttpReq.readyState == 4 )
		{
			updatepage ( self.xmlHttpReq.responseText ) ;
		}
	}
	self.xmlHttpReq.send ( getquerystring () ) ;

	return ;

} // xmlhttpPost

function getquerystring () 
{
	var form      = document.forms [ 'contact' ] ;

        var nom         = form.nom.value         ;
	var email       = form.email.value       ;
	var tel         = form.tel.value         ;
	var pays        = form.pays.value        ;
	var found       = form.found.value       ;
	var message     = form.message.value     ;

        qstr =   'nom='         + escape ( nom         )
	       + '&email='      + escape ( email       )
	       + '&tel='        + escape ( tel         )
	       + '&pays='       + escape ( pays        )
	       + '&found='      + escape ( found       )
	       + '&message='    + escape ( message     ) ;

	return qstr ;

} // getquerystring


function updatepage ( str )
{
	if ( str == "ok" )
	{
		document.getElementById ( "formulaire").style.display = "none"  ;
		document.getElementById ( "ok"        ).style.display = "block" ;
		document.getElementById ( "erreur"    ).style.display = "none"  ;
	}
	else
	{
		document.getElementById ( "formulaire").style.display = "none"  ;
		document.getElementById ( "ok"        ).style.display = "none"  ;
		document.getElementById ( "erreur"    ).style.display = "block" ;
	}

	return ;

} // updatepage


// ========================================================================================
// La regex est un compromis. Elle n'est pas exhaustive. En fait, il n'existe pas de regex
// dÃ©finissant complÃ©tement tous les formats possible d'un email.
// voir :
// - http://fightingforalostcause.net/misc/2006/compare-email-regex.php
// - http://www.quirksmode.org/js/mailcheck.html
// ========================================================================================

function controle_courriel ( strEmail )
{
	var filter = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;

	return filter.test ( strEmail ) ;

} // controle_courriel

function trim ( stringToTrim ) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function controle_formulaire ( form )
{
	var alertControlBack = "#fba8a8" ;

	if ( form.nom.value == '' )
	{
		form.nom.focus () ;
		form.nom.style.background = alertControlBack ;
 		document.getElementById ( 'err_nom' ).style.display = 'block' ;
		return false ;
	}
	if ( !controle_courriel ( form.email.value ) )
	{
		form.email.focus () ;
		form.email.style.background = alertControlBack ;
 		document.getElementById ( 'err_email' ).style.display = 'block' ;
		return false ;
	}
	if ( form.email.value != form.email_conf.value )
	{
		form.email_conf.focus () ;
		form.email_conf.style.background = alertControlBack ;
 		document.getElementById ( 'err_email_conf' ).style.display = 'block' ;
		return false ;
	}
	if ( trim( form.message.value ) == '' )
	{
		form.message.focus () ;
		form.message.style.background = alertControlBack ;
		document.getElementById ( 'err_message' ).style.display = 'block' ;
		return false ;
	}


	return true ;

} // controle_formulaire


