function isValidCode ()
{
var v = GetObjectByRef ("Bevestigingscode");
if (v == null)
return true;
v = v.value;
return Math.floor (v / 100) % 97 == (v % 100);
}
function isFieldFilled (f)
{
var o = GetObjectByRef (f);
return o == null || o.value != "";
}
function isValidEmail (f)
{
var o = GetObjectByRef (f);
return o == null || (o.value.indexOf("@") > 0);
}
function isFilled ()
{
return isValidCode () && isFieldFilled ("Name") && isFieldFilled ("Email");
}
function SetInfo (id, info, valid)
{
var o = GetObjectByRef (id);
if (o == null)
return;
o.innerHTML = valid ? "": info;
}
function SetInfoNeeded (name, valid)
{
SetInfo ('Check'+name, "Dit veld is vereist", valid);
var o = GetObjectByRef (name);
if (o == null)
return;
var cn = GetClassName (o);
if (valid)
{
var pos = cn.indexOf (" Needed");
if (pos >= 0)
{
cn = cn.substr (0, cn);
SetClassName (o, cn);
} // if
}
else
{
var pos = cn.indexOf (" Needed");
if (pos < 0)
{
SetClassName (o, cn + " Needed");
} // if
} // if
}
function checkCode (obj)
{
var validCode = isValidCode ();
var validNaam = isFieldFilled ("Naam");
var validAdres = isFieldFilled ("Adres");
var validGemeente = isFieldFilled ("Gemeente");
var validTelefoon = isFieldFilled ("Telefoon");
var validEmail = isValidEmail ("Email");
var validSecCode = isFieldFilled ("Code");
SetInfo ("CheckBevestigingscode", "Dit is een ongeldige code", validCode);
SetInfoNeeded ("Naam", validNaam);
SetInfoNeeded ("Adres", validAdres);
SetInfoNeeded ("Gemeente", validGemeente);
SetInfoNeeded ("Telefoon", validTelefoon);
SetInfoNeeded ("Email", validEmail);
SetInfoNeeded ("Code", validSecCode);
var o = GetObjectByRef ("Send");
if (o != null)
o.style.display= isFilled () ? "inline" : "none";
var submit = GetObjectByRef ("SubmitButton");
if (submit !== null)
submit.disabled = !validCode || !validNaam || !validAdres || !validGemeente || !validTelefoon || !validEmail || !validSecCode;
}