function validateFormOnSubmit(theForm) {
var reason = "";

	reason += validateMonth(theForm.Month);
	reason += validateDay(theForm.Day);
	reason += validateYear(theForm.Year);
	reason += validateLocation(theForm.Location);
	reason += validateName(theForm.Name);
	reason += validateEmail(theForm.Email);
  	reason += validatePhone1(theForm.Phone1);
	reason += validatePhone2(theForm.Phone2);
	reason += validatePhone3(theForm.Phone3);
	reason += validateComments(theForm.Comments);
	reason += validateVerification(theForm.Verification);
      
  if (reason != "") {
    alert("Following field(s) need to be Filled:\n" + reason);
    return false;
  }
  if(checkValue(theForm)) { 
	insitePost(theForm); 
  }
  setTimeout(function(){theForm.submit();},500); // increase this value if it's not tracking properly
  return true;
}

function validateMonth(fld) {
    var error = "";
 
    if (fld.options[fld.selectedIndex].value == "" || fld.options[fld.selectedIndex].value == "Month") {
        fld.style.background = '#666666'; 
        error = "- Select the month you prefer.\n";
    } else {
        fld.style.background = '#000000';
    }
    return error;
}

function validateDay(fld) {
    var error = "";
 
    if (fld.options[fld.selectedIndex].value == "" || fld.options[fld.selectedIndex].value == "Date") {
        fld.style.background = '#666666'; 
        error = "- Select the day you prefer.\n";
    } else {
        fld.style.background = '#000000';
    }
    return error;
}

function validateYear(fld) {
    var error = "";
 
    if (fld.options[fld.selectedIndex].value == "" || fld.options[fld.selectedIndex].value == "Year") {
        fld.style.background = '#666666'; 
        error = "- Select the year you prefer.\n";
    } else {
        fld.style.background = '#000000';
    }
    return error;
}
function validateLocation(fld) {
    var error = "";
 
    if (fld.options[fld.selectedIndex].value == "" || fld.options[fld.selectedIndex].value == "Service") {
        fld.style.background = '#666666'; 
        error = "- Select the requesting service.\n";
    } else {
        fld.style.background = '#000000';
    }
    return error;
}


function validateName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#666666'; 
        error = "- Enter your name.\n"
    } else {
        fld.style.background = '#000000';
    }
    return error;  
}

function validateComments(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#666666'; 
        error = "- Enter your message.\n"
    } else {
        fld.style.background = '#000000';
    }
    return error;  
}

function validateVerification(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#666666'; 
        error = "- Enter the verification code.\n"
    } else {
        fld.style.background = '#000000';
    }
    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$/ ;
   
    if (fld.value == "") {
        fld.style.background = '#666666';
        error = "- Enter your email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#666666';
        error = "- Please enter a valid email address.\n";
    } else {
        fld.style.background = '#000000';
    }
    return error;
}

function validatePhone1(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- Please enter area code.\n";
        fld.style.background = '#666666';
    } else {
        fld.style.background = '#000000';
    }
    return error;
}
function validatePhone2(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- Please enter phone number prefix.\n";
        fld.style.background = '#666666';
    } else {
        fld.style.background = '#000000';
    }
    return error;
}
function validatePhone3(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- Please enter phone number suffix.\n";
        fld.style.background = '#666666';
    } else {
        fld.style.background = '#000000';
    }
    return error;
}


