function validateField(field)

//This function checks for whitespace in a form field

{
 var messageString =  field;

 if ( messageString.replace(/^\s*|\s+$/g, "") == "")
     {
      // there is nothing but whitespace in the field
      return false;
     }
 else
      return true;
}

//--------------------

function isAlphabetic(s)
{
var RefString = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
s+="";
for (Count=0; Count < s.length; Count++)
{
var TempChar=s.substring (Count, Count+1);
if (RefString.indexOf (TempChar, 0)==-1) return false;
}
return true;
}

//--------------------

function isAlphabeticPlus(s)
{
var RefString = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ., ";
s+="";
for (Count=0; Count < s.length; Count++)
{
var TempChar=s.substring (Count, Count+1);
if (RefString.indexOf (TempChar, 0)==-1) return false;
}
return true;
}

//--------------------

function isDigit(c)
{
var test = "" + c;
if (test =="0" || test == "1" || test == "2" || test == "3" || test == "4" || test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
{
return true;
}
return false;
}

//--------------------

function isAllDigits(s)
{
var test = "" + s;
for (var k = 0; k < test.length; k++)
{
var c = test.substring(k, k+1);
if (isDigit(c) == false) return false;
}
return true;
}

//Is the email address valid?

function validEmail(email)
{
var em = email;

if (em.indexOf('@')  == -1)
   return false;
else
     if (em.indexOf('.') ==  -1 )
          return false;
    else
          return true;
}

//Is the home phone number a valid length, if so, format it

function phoneHFormat(FCPHONEH) {
var n = FCPHONEH.replace(/\D/g,''); // remove all non-digits
if (n.length==10)
   {
    document.factoring_form.phone.value=n.substr(0,3)+'-'+n.substr(3,3)+'-'+n.substr(6); // format
    return true;
   }
   else
        return false;
 }

//Is the State code valid?

function checkCustomerData(form)
{
//Begin form validation

//validate the Name field

  if (validateField(document.factoring_form.name.value) == false)
     {
      alert("You must enter your Name.");
      form.name.select();
      return false;
     }

  if (isAlphabeticPlus(form.name.value) == false)
     {
      alert("Invalid Name.  Your Name must be alphabetic.");
      form.name.select();
      return false;
     }

//validate the Business Name field

  if (validateField(document.factoring_form.bname.value) == false)
     {
      alert("You must enter your Business Name.");
      form.bname.select();
      return false;
     }

//validate the Email field

  if (validateField(document.factoring_form.emailadd.value) == false) 
     {
      alert("You must enter an E-mail Address.");
      form.emailadd.select();
      return false;
     }

  if (validEmail(form.emailadd.value) == false)
     {
      alert("Invalid E-mail Address.  You must enter a valid E-mail Address.");
      form.emailadd.select();
      return false;
     }

//validate Phone field

  if (validateField(document.factoring_form.phone.value) == false)
     {
      alert("You must enter a Phone Number.");
      form.phone.select();
      return false;
     }

  if (phoneHFormat(form.phone.value) == false)
     {
      alert("Invalid Phone Number.  The Phone Number must be 10 digits long.");
      form.phone.select();
      return false;
     }

//End form validation    

}
