

var validations = new Array();
// Define which validations to perform. Each array item
// holds the form field to validate, and the validation
// to be applied. This is the only party you need to
// customize in order to use the script in a new page!
validations[0]=["document.form1.fullname", "notblank"];
validations[1]=["document.form1.address", "notblank"];
validations[2]=["document.form1.city", "notblank"];
validations[3]=["document.form1.zip", "notblank"];
validations[4]=["document.form1.state", "notblank"];
validations[5]=["document.form1.phone", "notblank"];
validations[6]=["document.form1.email", "validemail"];
validations[7]=["document.form1.fullname", "notblank"];
validations[8]=["document.form1.fullname", "notblank"];
// Customize above array when used with a new page.
function isEmpty(s)
{
if (s == null || s.length == 0)
return true;
// The test returns true if there is at least one non-
// whitespace, meaning the string is not empty. If the
// test returns true, the string is empty.
return !/\S/.test(s);
}
function looksLikeEmail(field)
{
var s = field.value;
if (isEmpty(s))
{
alert("Email may not be empty");
field.focus();
return false;
}
if (/[^@]+@\w+/.test(s))
return true;
alert("E-mail not in valid form.");
field.focus();
return false;
}
function isInteger(field)
{
var s = field.value;
if (isEmpty(s))
{
alert("Field cannot be empty");
field.focus();
return false;
}
if (!(/^-?\d+$/.test(s)))
{
alert("Field must contain only digits");
field.focus();
return false;
}
return true;
}

function validate()
{
var i;
var checkToMake;
var field;
for (i = 0; i < validations.length; i++)
{
field = eval(validations[i][0]);
checkToMake = validations[i][1];
switch (checkToMake)
{
case 'notblank': if (isEmpty(field.value))
{
alert("Field may not be empty");
field.focus();
return false;
}
break;
case 'validemail': if (!looksLikeEmail(field))
return false;
break;
case 'isnumber': if (!isInteger(field))
return false;
}
}
return true;
}


//Credit Card Validator
function checkLuhn(input)
  {
    var sum = 0;
    var numdigits = input.length;
    var parity = numdigits % 2;
    for(var i=0; i < numdigits; i++) {
      var digit = parseInt(input.charAt(i))
      if(i % 2 == parity) digit *= 2;
      if(digit > 9) digit -= 9;
      sum += digit;
    }
    return (sum % 10) == 0;
  }

//Calculating Script

// Set up form variables and constants
var widget1Cost = 1.50;
var widget2Cost = 2.50;
var widget3Cost = 3.50;
var taxRate = 0.000;
var shippingCost = 0;
function isNumberInput(field, event)
{
var key, keyChar;
if (window.event)
key = window.event.keyCode;
else if (event)
key = event.which;
else
return true;
// Check for special characters like backspace
if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
return true;
// Check to see if it.s a number
keyChar = String.fromCharCode(key);
if (/\d/.test(keyChar))
{
window.status = "";
return true;
}
else
{
window.status = "Field accepts numbers only.";
return false;
}
}
function format(value)
{
// Format to have only two decimal digits
var temp = Math.round(value * 100);
temp = temp / 100;
return temp;
}
function calc()
{
with (document.form1)
{
widgettotal.value = format(widget1.value * widget1Cost);
gadgettotal.value = format(widget2.value * widget2Cost);
thingietotal.value = format(widget3.value * widget3Cost);
subtotal.value = format(parseFloat(widgettotal.value) +
parseFloat(gadgettotal.value) +
parseFloat(thingietotal.value));
tax.value = format(subtotal.value * taxRate);
for (i=0; i < shipping.length; i++)
if (shipping[i].checked)
shippingcost = parseFloat(shipping[i].value);
grandtotal.value = format(parseFloat(subtotal.value) +
parseFloat(tax.value) +
shippingcost);
}
}

//checkbox enabler
function enable_text(status)
{
status=!status;
document.form1.widget1.disabled = status;
document.form1.widget2.disabled = status;
document.form1.widget3.disabled = status;
}





