var Errors = "";
function checkForm()
{
Errors="";
surname();
userid();
telephone();
if(Errors.length != "")
{
pageHeader();
pageFooter();
error_window = window.open("", "errors", 'width=550, height=300');
error_window.document.write("ERRORS:\n");
error_window.document.write(Errors);
error_window.document.close();
return false;
}
else
return true;
}
function telephone()
{
var f03 = document.pizza.field03.value;
var pnumlength = f03.length;
if(f03.value == "")
{
Errors += '
}
function userid()
{
var f02 = document.pizza.field02.value;
var idlength = f02.length;
var wrong = 1;
var wrong2;
var total1 = 0;
var total2 = 0;
//RULE 1
if(f02.charCodeAt(0) != 65 && f02.charCodeAt(0) != 70)
{
Errors += ' The first letter in the user ID must be either "A" or "F"\n ';
}
//RULE 2
for(var i=1; i < 6; i++)
{
if(f02.charCodeAt(i) > 48 && f02.charCodeAt(i) < 57)
{
wrong = 0;
total1 += f02.charAt(i);
}
else
{
wrong = 1;
}
}
if(wrong==1)
{
Errors += ' In the user ID there must be 5 digits after the first character\n '
}
//RULE 3
if(f02.charCodeAt(6) != 45)
{
Errors += ' In The user ID the seventh character must be a hyphen "-"\n '
}
//RULE 4
for(var n=7; n < 12; n++)
{
if(f02.charCodeAt(n) > 48 && f02.charCodeAt(n) < 57)
{
wrong2 = 0;
total2 += f02.charAt(n);
}
else
{
wrong2 = 1;
}
}
if(wrong2==1)
{
Errors += ' In the user ID there must be 5 digits after the hyphen\n '
}
//RULE 5
if(total1 < total2)
{
Errors += ' The first 5 digits in the user ID must add up to less than the second 5 digits\n '
}
}
function surname()
{
var f01 = document.pizza.field01.value;
var F01 = document.getElementById('field01');
var name_len = f01.length;
var counters = 0;
for(var i=0 ; i <= name_len-1; i++)
{
if(f01.charCodeAt(i) < 65 || f01.charCodeAt(i) > 90 && f01.charCodeAt(i) < 97 || f01.charCodeAt(i) > 122)
{
counters=1;
}
}
if(counters==1)
{
Errors += " Client Surname must contain only alphabetic characters(a-z) (A-Z) \n";
}
if(F01.value == "")
{
Errors += " Must enter a surname \n";
}
if(name_len < 4)
{
Errors += " Client Surname must have at least 4 alphabetic characters (a-z) (A-Z) \n";
}
}
function pageHeader() {
content = '\n';
content += '\n';
content += ' \n';
content += ' \n';
content += ' form validation\n';
content += ' \n';
content += ' \n';
content += ' Please correct the following and resubmit the form
\n';
content += ' \n';
return content;
}
function pageFooter() {
content += '
\n';
content += ' \n';
content += ' \n';
return content;
}