function contact(target)
{
var hash = 0;
var name = new Array();
name.lenght = 3;
// Name of the field to validate
name[0] = 'nom';
name[1] = 'courriel';
name[2] = 'message';
var string = new Array();
string.lenght = 2;
// regexp to aply on field
string['courriel'] = '^([a-zA-Z0-9\-_]){3,}(@){1,}([a-zA-Z0-9\-]){3,}([\.]){1}([^\d\s]){2,4}$';
string['nom'] = '^([a-zA-Z0-9\-.]){2,}$';
string['message'] = '.';
if(!target) {
for(i = 0; i <= name.lenght; i++) {
var rp = new RegExp(string[name[i]]);
var that = document.getElementById(name[i]);
if(that.value != '' && !that.value.match(rp)) {
alert('Le champ du '+name[i]+' contient des caractere ilégaux ou il est incomplet.');
return false;
}
if(that.value == '') {
that.style.backgroundColor = '#f4f4f4'
that.style.border = '1px solid red'
return false;
}
}
} else {
var rp = new RegExp(string[target]);
var that = document.getElementById(target);
if(that.value.match(rp)) {
that.style.backgroundImage = "url('images/ico/tick.gif')";
that.style.backgroundColor = 'white'
that.style.border = '1px solid #ccc'
}else{
that.style.backgroundImage = "url('images/ico/cross.gif')";
}
}
}