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 += ' <li>
}
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 += ' <li> The first letter in the user ID must be either "A" or "F"\n </li>';
}
//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 += ' <li> In the user ID there must be 5 digits after the first character\n </li>'
}
//RULE 3
if(f02.charCodeAt(6) != 45)
{
Errors += ' <li> In The user ID the seventh character must be a hyphen "-"\n </li>'
}
//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 += ' <li> In the user ID there must be 5 digits after the hyphen\n </li>'
}
//RULE 5
if(total1 < total2)
{
Errors += ' <li> The first 5 digits in the user ID must add up to less than the second 5 digits\n </li>'
}
}
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 += " <li> Client Surname must contain only alphabetic characters(a-z) (A-Z) </li>\n";
}
if(F01.value == "")
{
Errors += " <li> Must enter a surname </li>\n";
}
if(name_len < 4)
{
Errors += " <li> Client Surname must have at least 4 alphabetic characters (a-z) (A-Z) </li> \n";
}
}
function pageHeader() {
content = '<?xml version="1.0"encoding="UTF-8" ?>\n';
content += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
content += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
content += ' <html xmlns="http://www.w3.org/1999/xhtml">\n';
content += ' <head>\n';
content += ' <title>form validation</title>\n';
content += ' </head>\n';
content += ' <body>\n';
content += ' <h3>Please correct the following and resubmit the form</h3>\n';
content += ' <ul>\n';
return content;
}
function pageFooter() {
content += ' </ul>\n';
content += ' </body>\n';
content += ' </html>\n';
return content;
}