
function checkAdhoc(theForm) {
var error="";

var input = theForm.elements.length
var errcond = new Array
var errconn = new Array
var m = (input - 6) / 4
var j = 4
var k = 0
for (i=0; i<m; i++ )
{
  if ((theForm.elements[j+2].value  !=  "") || (theForm.elements[j+2].selectedIndex > 0))
  {
    errcond[k] = ""
    errconn[k] = ""
    if (theForm.elements[j+1].selectedIndex == 0)
    {
      errcond[k] = theForm.elements[j].value + " must have a Condition for the selection.\n";
    }
    if (theForm.elements[j+3].selectedIndex == 0)
    {
      errconn[k] = (theForm.elements[j].value + " must have a Connector to the next selection.\n");
     }
    k = k  + 1
  }
  j = j+4
}
errconn[k-1] = "";


for (i=0; i<k; i++)
{
  error = error + errcond[i] + errconn[i] ;
}
return error;
}

// check that email address is correct structure

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

if (isNaN(stripped)) {
   error += "The phone number contains illegal characters.\n";
}

if (stripped.length != 10) {
  error += "The phone number is the wrong length. Make sure you included an area code.\n";
}
 
return error;
}

//  home phone number - strip out delimiters and check for 10 digits

function checkHomePhone (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

if (isNaN(stripped)) {
   error += "The home phone number contains illegal characters.\n";
}

if (stripped.length != 10) {
  error += "The home phone number is the wrong length. Make sure you included an area code.\n";
}
 
return error;
}

// work phone number - strip out delimiters and check for 10 digits

function checkWorkPhone (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

if (isNaN(stripped)) {
   error += "The work phone number contains illegal characters.\n";
}

if (stripped.length != 10) {
  error += "The work phone number is the wrong length. Make sure you included an area code.\n";
}
 
return error;
}

// cell phone number - strip out delimiters and check for 10 digits

function checkCellPhone (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

if (isNaN(stripped)) {
   error += "The cell phone number contains illegal characters.\n";
}

if (stripped.length != 10) {
  error += "The cell phone number is the wrong length. Make sure you included an area code.\n";
}
 
return error;
}

// fax phone number - strip out delimiters and check for 10 digits

function checkFaxPhone (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

if (isNaN(stripped)) {
   error += "The fax phone number contains illegal characters.\n";
}

if (stripped.length != 10) {
  error += "The fax phone number is the wrong length. Make sure you included an area code.\n";
}
 
return error;
}

// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
} 

// 5 digit Zip - 5 numbers only.

function checkZip5 (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the 5-digit Zip Code.\n";
}
else {

    var illegalChars = /\D/; // allow  numbers
    if (strng.length != 5) {
       error += "The 5-digit Zip Code is the wrong length.\n";
    }
    if (illegalChars.test(strng)) {
    error += "The 5-digit Zip Code contains illegal characters.\n";
    }
} 
return error;
} 


// +4 Zip - 4 numbers only.

function checkZip4 (strng) {

var error = "";
if (strng == "") {
   error = "You didn't enter the +4 Zip Code.\n";
}
else {

    var illegalChars = /\D/; // allow numbers
    if (strng.length != 4) {
       error += "The +4 Zip Code is the wrong length.\n";
    }
    if (illegalChars.test(strng)) {
    error += "The +4 Zip Code contains illegal characters.\n";
    }
} 
return error;
} 

// non-empty name

function isName(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must submit your name.\n";
  }
return error;
}

// non-empty firstname

function isFirst(strng1,strng2)
 {
var error = "";

  if ((strng2.length == 0) && (strng1.length == 0)) {
     error = "You must submit your first name.\n";
  }
return error;
}

// non-empty lastname

function isLast(strng1 ,strng2) {
var error = "";
  if ((strng2.length == 0) && (strng1.length == 0)) {
     error = "You must submit your last name.\n";
  }
return error;
}

// both lastname and organization have been input

function isBoth(strng1,strng2){
alert("Help!");
}


// non-empty street

function isStreet(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide your street name.\n";
  }
return error;
}

// non-empty city

function isCity(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide the city where you live.\n";
  }
return error;
}

// non-empty state

function isState(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide the state where you live.\n";
  }
return error;
}


// non-empty occupation

function isOccupation(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide your occupation.\n";
  }
return error;
}

// non-empty employer

function isEmployer(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide the name of your employer.\n";
  }
return error;
}

// non-empty employer location

function isEmpLocation(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You must provide the location of your employer.\n";
  }
return error;
}


// non-empty subject

function isSubject(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter the message subject.\n";
  }
return error;	  
}


// non-empty message

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "A message must be submitted.\n";
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// exactly one radio button is chosen

function checkReport(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please indicate the report needed.\n";
    }
return error;
}

// exactly one radio button is chosen for voter registration

function checkRegister(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please submit voter registration information.\n";
    }
return error;
}



// exactly one radio button is chosen for voter pledge

function checkPledge(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please respond to the Voter Pledge.\n";
    }
return error;
}

// exactly one radio button is chosen for picking records to process

function checkPick(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "You must select one record to process.\n";
    }
return error;
}

// exactly one radio button is chosen for action

function checkAct(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "You must select one action.\n";
    }
return error;
}

// exactly one radio button is chosen for voter pledge

function checkPrinciples(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please indicate your support for our principles.\n";
    }
return error;
}

// valid selector from dropdown list (generic)

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    

// valid selector from dropdown list (Condition)

function checkCondition(choice) {

var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the Condition drop-down list.\n";
    }    
return error;
}

// valid selector from dropdown list (Condition)

function checkAdditional(checkvalue) {

var error = "";
   
   if (checkvalue == "y") {
       error = "You need a Connector to add another Selection criterion.\n";
    }
 
return error;
}

function checkProcess(checkvalue) {

var error = "";
  
   if (checkvalue == "n") {
       error = "Since you wish to process the request, please remove the Connector.\n";
   }

return error;
}

function checkNoaction(checkvalue) {

var error = "";
  
   if (checkvalue == "") {
       error = "You must select either 'Add Another Selection' or 'Process The Request'.\n";
   }

return error;
}