function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm._fid_6);//company name
  reason += validateEmpty(theForm._fid_7);//company address
  reason += validateEmpty(theForm._fid_9);//company city
  reason += validateEmpty(theForm._fid_10);//company state
  reason += validateZip(theForm._fid_11);//company zip
  reason += validatePhone(theForm._fid_12);//company phone
  
  reason += validateEmpty(theForm._fid_25);//primary contact
  reason += validateEmail(theForm._fid_27);//primary contact email
  reason += validatePhone(theForm._fid_28);//primary contact phone
  
  reason += validateEmpty(theForm._fid_142);//Date Business Started
  //reason += validateEmpty(theForm._fid_44);//Type of Business
  reason += validateEmpty(theForm._fid_45);//Federal Tax Identification
  //reason += validateEmpty(theForm._fid_47);//affiliate or subsidiary
  
  //reason += validateEmpty(theForm._fid_116);//Disadvantaged Business
  //reason += validateEmpty(theForm._fid_52);//Union
  //industries servered
  //services provided
  //number of technitions on staff
  
  reason += validateEmpty(theForm._fid_73);//t&m hourly rate data
  reason += validateEmpty(theForm._fid_74);//t&m hourly rate electrical
  reason += validateEmpty(theForm._fid_76);//Coverage area
  
  reason += validateEmpty(theForm._fid_104);//reference 1 name
  reason += validateEmpty(theForm._fid_105);//reference 1 project
  reason += validateEmpty(theForm._fid_106);//reference 1 contactname
  reason += validateEmail(theForm._fid_107);//reference 1 email
  reason += validatePhone(theForm._fid_108);//reference 1 phone
  //reason += validateEmpty(theForm._fid_121);//contact reference1
  
  //reason += validateEmpty(theForm._fid_126);//Liability Coverage
  reason += validateEmpty(theForm._fid_123);//Limits per occurrence
  //reason += validateEmpty(theForm._fid_127);//Workers Compensation
  reason += validateEmpty(theForm._fid_115);//Current Limits per Accident
  reason += validateEmpty(theForm._fid_124);//Disease Policy
  reason += validateEmpty(theForm._fid_125);//Disease each
  //reason += validateEmpty(theForm.fieldname);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateEmpty(fld) {
    var error = "";
	var illegalChars= /[\(\)\<\>\;\:\\\"\[\]]/ ;
  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "A required field has not been filled in.\n"
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "A required field contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateZip(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter a zip code.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The zip code contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 5)) {
        error = "The zip code is the wrong length. Use 5 number format.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function validateRadioButton(fld) {
    var cnt = -1;
    for (var i=fld.length-1; i > -1; i--) {
        if (fld[i].checked) {cnt = i; i = -1;}
    }
    if (fld == null) 
	{
	error = "A required question has not been answered.\n";
		fld.style.background = 'Yellow';
	} else {
        fld.style.background = 'White';
    }
	return error;
}
                  
