function GetJSObject(object_name,mode)
{
if(document.all)
{
if(mode == "div") { object = document.all(object_name).style; } else { object = document.all(object_name); }
}
else if(document.getElementById) { object = document.getElementById(object_name); }
return object;
}
function ComparePwdFields(object_name)
{
err = '';
pre = '
' + err + '';
return false;
}
else
{
OKField(object1.name);
OKField(object2.name);
object3.innerHTML= pre + 'green>
Mot de passe accepté';
if(document.donut_form.donut_submit) { document.donut_form.donut_submit.disabled=false; }
}
}
function EnlightObject(object,what)
{
if(what == 'on')
{
object.style.borderColor = '#FF0000';
object.style.borderTopStyle = 'solid';
object.style.borderLeftStyle = 'solid';
object.style.borderWidth = 'medium';
}
else
{
object.style.borderColor = '#FFFFFF';
object.style.borderTopStyle = 'groove';
object.style.borderLeftStyle = 'groove';
object.style.borderWidth = 'thin';
}
}
function OnErrorField(field_name)
{
object = GetJSObject(field_name);
object.style.borderLeftColor = '#FF0000';
object.style.borderLeftWidth = '6px';
object.style.borderLeftStyle = 'solid';
}
function OKField(field_name)
{
object = GetJSObject(field_name);
object.style.borderLeftColor = '#000000';
object.style.borderLeftWidth = 'thin';
object.style.borderLeftStyle = 'groove';
}
function CheckFieldContent(field_name,field_label,type,enlight)
{
fieldstatus = false;
object = GetJSObject(field_name);
if(type == 'email') { fieldstatus = CheckEmailAddress(object.value); }
else if(type == 'date') { fieldstatus = CheckDate(object.value); }
else if(type == 'hour') { fieldstatus = CheckHour(object.value); }
else if(type == 'digits') { fieldstatus = CheckDigits(object.value); }
else if(object.value != '') { fieldstatus = true; }
if(fieldstatus == false)
{
if(enlight == true) { OnErrorField(field_name); }
object.value='';
alert('Valeur incorrecte pour le champ \'' + field_label + '\'');
return false;
}
else
{
if(enlight == true) { OKField(field_name); }
return true;
}
}
function CheckEmailAddress(address)
{
if(address.length > 0)
{
var global_length = address.length;
if(global_length < 7) return false;// min size for an e-mail
var nb1 = address.indexOf("@");
var nb2 = address.lastIndexOf("@");
if((nb1 != nb2)||(nb1 == '-1')) return false; // only one @ in an email
var adr_temp = address.substring(nb1+1,global_length);
var nbdot = adr_temp.lastIndexOf(".");
// e-mail struct elem1@elem2.elem3
var elem1 = address.substring(0,nb1);
var elem2 = adr_temp.substring(0,nbdot);
var elem3 = adr_temp.substring(nbdot+1,global_length);
//length and space tests
if((elem1.length==0)||(elem1.indexOf(" ")!=-1)) return false;
if((elem2.length<2)||(elem2.indexOf(" ")!=-1)) return false;
if((elem3.length<2)||(elem3.length>4)||(elem3.indexOf(" ")!=-1)) return false;
return true;
}
}
function CheckDate(date,country)
{
if(date.length > 0)
{
// verified the data's writing
if (!date.match(/^\d{1,2}[\/]\d{1,2}[\/]\d{4}$/)) return false; // a date must be x/x/xxxx or xx/xx/xxxx
// verified the data's coherence
var global_length = date.length;
var nbr1 = date.indexOf("/"); // place of the first "/"
var elem_1 = date.substring(0,nbr1);// elem_1 is the day
var temp_date = date.substring(nbr1+1,global_length);
var nbr2 = temp_date.indexOf("/"); // place of the second "/"
var elem_2 = temp_date.substring(0,nbr2); // elem_2 is the months
if (country == "US")
{
if (elem_1 > 12) return false;
if (elem_2 > 31) return false;
return true;
}
if (elem_1 > 31) return false;
if (elem_2 > 12) return false;
return true;
}
return true;
}
function CheckHour(hour)
{
if(hour.length > 0)
{
// first check the date structure
if (!hour.match(/^\d{1,2}[\h]\d{1,2}$/)) return false; // a time must be xx:xx or x:x
// verified the data's coherence
elem = hour.split('h');
if (elem[0]>24) return false;
if (elem[1]>59) return false;
return true;
}
return true;
}
function CheckDigits(digits)
{
if(isNaN(digits) == true) { return false; } else { return true; }
}