rendered paste body /*************************************************************/
/* Name : Anthony Alves */
/*************************************************************/
function checkForm()
{
var error_message = "";
var temp_error = new Array(12);
temp_error[0] = surname();
temp_error[1] = clientid();
temp_error[2] = telephone();
temp_error[3] = dob();
temp_error[4] = size();
temp_error[5] = sauce();
if(temp_error[0] != "")
{
error_message += temp_error[0] + "\n";
}
if(temp_error[1] != "")
{
error_message += temp_error[1] + "\n";
}
if(temp_error[2] != "")
{
error_message += temp_error[2] + "\n";
}
if(temp_error[3] != "")
{
error_message += temp_error[3] + "\n";
}
if(temp_error[4] != "")
{
error_message += temp_error[4] + "\n";
}
if(temp_error[5] != "")
{
error_message += temp_error[5] + "\n";
}
if(error_message.length != "")
{
error_message = pageHeader(error_message);
error_message += temp_error[0];
error_message += temp_error[1];
error_message += temp_error[2];
error_message += temp_error[3];
error_message += temp_error[4];
error_message += temp_error[5];
error_message = pageFooter(error_message);
error_window = window.open("", "errors", 'width=450, height=300');
error_window.document.write(error_message);
error_window.document.close();
return false;
}
else
return true;
}
function surname()
{
var field01 = document.pizza.field01.value;
/*var field01 = document.getElementById('field01');*/
if(field01 == "")
return "Must have a surname. ";
else
{
for(var i=0; i<field01.length; i++)
{
if(field01.charCodeAt(i) < 65 || field01.charCodeAt(i) > 90 && field01.charCodeAt(i) < 97 || field01.charCodeAt(i) > 122)
{
if(field01.length < 4)
{
return "Customer surname must contain at least 4 characters, all must be alphabetic. ";
}
else
return "All characters in surname must be alphabetic. ";
}
}
if(field01.length < 4)
return "Customer surname must be at least 4 characters. ";
}
for(var i=0; i<field01.length; i++)
{
if(field01.charCodeAt(i) < 65 || field01.charCodeAt(i) > 90 && field01.charCodeAt(i) < 97 || field01.charCodeAt(i) > 122)
return "All characters in surname must be alphabetic. ";
}
return "";
}
function clientid()
{
var field02 = document.pizza.field02.value;
var left_sum = 0;
var right_sum = 0;
if(field02.length != 12)
return "ClientID must be 12 characters. ";
if(field02.charCodeAt(0) != 65 && field02.charCodeAt(0) != 70)
return "The first character in ClientID must be either an upper case A or F. ";
if(field02.charCodeAt(6) != 45)
return "The Seventh position must be a hyphen (-). ";
for(i=1; i<6; i++)
{
left_sum += eval(field02.charAt(i));
if(field02.charCodeAt(i) < 48 || field02.charCodeAt(i) > 57)
return "The second through sixth characters must be numeric. ";
}
for(i=7; i<12; i++)
{
right_sum += eval(field02.charAt(i));
if(field02.charCodeAt(i) < 48 || field02.charCodeAt(i) > 57)
return "The eighth through twelfth characters must be numeric. ";
}
if(left_sum > right_sum)
return "The sum of the second through sixth characters must be less than the sum of the eighth through twelfth characters. ";
return "";
}
function telephone()
{
var field03 = document.pizza.field03.value;
if(field03 == "")
return "Must have a telephone number. ";
if(field03.length < 12)
return "Not enough characters in the telephone number. ";
for(var i=1; i<6; i++)
{
if(i == 3 || i == 7)
i++;
if(field03.charCodeAt(i) < 48 || field03.charCodeAt(i) > 57)
return "The telephone number must consist of all numeric characters with the exception of hyphens (123-456-7890). ";
}
if(field03.charCodeAt(3) != 45 || field03.charCodeAt(7) != 45)
return "The fourth and eighth position of the telephone number must be a hyphen (123-456-7890). ";
if(field03.charAt(0) ==0 && field03.charAt(1) ==0 && field03.charAt(2) ==0)
return "The area code of the telephone number cannot be all 0's. ";
if(field03.charAt(4) ==0 && field03.charAt(5) ==0 && field03.charAt(6) ==0 && field03.charAt(8) ==0 && field03.charAt(9) ==0 && field03.charAt(10) ==0 && field03.charAt(11) ==0)
return "The telephone number cannot be all 0's. ";
return "";
}
function dob()
{
var field04 = document.pizza.field04.value;
var month = field04.substring(0,3);
var year = field04.substring(3,7);
var cur_date = new Date();
var cur_year = cur_date.getFullYear();
var age = eval('cur_year - year');
if(field04 == "")
return "Must have a date of birth. ";
if(field04.length < 7)
return "Not enough characters in the date of birth, please enter in format mmmyyyy. ";
if(month.toLowerCase() != "jan" && month.toLowerCase() != "feb" && month.toLowerCase() != "mar" && month.toLowerCase() != "apr" && month.toLowerCase() != "may" && month.toLowerCase() != "jun" && month.toLowerCase() != "jul" && month.toLowerCase() != "aug" && month.toLowerCase() != "sep" && month.toLowerCase() != "oct" && month.toLowerCase() != "nov" && month.toLowerCase() != "dec")
return "Not a valid month abbreviation in date of birth. ";
for(var i=3; i<7; i++)
{
if(field04.charCodeAt(i) < 48 || field04.charCodeAt(i) > 57)
return "The last four characters of date of birth must be numeric. ";
}
if(age < 19)
return "Invalid age, client is under 19 years of age. "
return "";
}
function size()
{
var field05 = document.pizza.field05.value;
if(field05 != "Small" && field05 != "Medium" && field05 != "Large")
return "A size of pizza must be selected. "
return "";
}
function sauce()
{
if(document.pizza.field09[0].checked == false && document.pizza.field09[1].checked == false && document.pizza.field09[2].checked == false)
return "A type of sauce must be selected. ";
return "";
}
function calculatePrice_s()
{
var total = 0;
s_oneCheck();
if(document.pizza.field05.value == "Small")
total = 13.35;
if(document.pizza.field05.value == "Medium")
total = 17.50;
if(document.pizza.field05.value == "Large")
total = 22.00;
for(var i=0; i<6; i++)
{
if(document.pizza.field10s[i].checked == true)
total += 1.25;
if(document.pizza.field10d[i].checked == true)
total+= 1.96;
}
document.pizza.field07.value = total;
}
function calculatePrice_d()
{
var total = 0;
d_oneCheck();
if(document.pizza.field05.value == "Small")
total = 13.35;
if(document.pizza.field05.value == "Medium")
total = 17.50;
if(document.pizza.field05.value == "Large")
total = 22.00;
for(var i=0; i<6; i++)
{
if(document.pizza.field10s[i].checked == true)
total += 1.25;
if(document.pizza.field10d[i].checked == true)
total+= 1.96;
}
document.pizza.field07.value = total;
}
function s_oneCheck()
{
for(var i=0; i<6; i++)
{
if(document.pizza.field10s[i].checked == true && document.pizza.field10d[i].checked == true)
document.pizza.field10d[i].checked = false;
}
}
function d_oneCheck()
{
for(var i=0; i<6; i++)
{
if(document.pizza.field10s[i].checked == true && document.pizza.field10d[i].checked == true)
document.pizza.field10s[i].checked = false;
}
}
function pageHeader(content) {
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) {
content += ' </ul>\n';
content += ' </body>\n';
content += ' </html>\n';
return content;
}