// JavaScript Document
Today = new Date();
TodayDay = Today.getDate();
TodayMon = Today.getMonth();
TodayYear = Today.getYear();
if (TodayYear < 2000) TodayYear += 1900;

if (TodayMon == 0) { TodayMonth = "January"; }
else if (TodayMon == 1) { TodayMonth = "February"; }
else if (TodayMon == 2) { TodayMonth = "March"; }
else if (TodayMon == 3) { TodayMonth = "April"; }
else if (TodayMon == 4) { TodayMonth = "May"; }
else if (TodayMon == 5) { TodayMonth = "June"; }
else if (TodayMon == 6) { TodayMonth = "July"; }
else if (TodayMon == 7) { TodayMonth = "August"; }
else if (TodayMon == 8) { TodayMonth = "September"; }
else if (TodayMon == 9) { TodayMonth = "October"; }
else if (TodayMon == 10) { TodayMonth = "November"; }
else if (TodayMon == 11) { TodayMonth = "December"; }
else { TodayMonth = TodayMon; }


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

  reason += validateName(theForm.name);
  reason += validateEmail(theForm.email);
/*  reason += validatePhone(theForm.phone);*/
  reason += validateMessage(theForm.message);
  
  /*reason += validateStreet(theForm.streetaddress);
  reason += validateCity(theForm.city);
  reason += validateZip(theForm.zip);*/
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
	
  }else{
	
	return true;
  }
}

function validateName(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a name.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    return error;
}

function validateMessage(fld) {
    var error = "";
  
    if (fld.value == "" || fld.value == "Please type message here...") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a message.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    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 = '#FFFFFF';
    } 
    return error;
}

function validateStreet(fld) {
    var error = "";
  
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Street.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    return error;
}

function validateCity(fld) {
    var error = "";
  
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a City.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    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 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 = '#FFFFFF';
    } 
    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 = '#FFFFFF';
    }
    return error;
}
	
function submitform() {
 if(document.form1.onsubmit()) {//this check triggers the validations
    document.form1.submit();
 }
}

function submitform() {
  document.form1.submit();
}


function validateName(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a name.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    return error;
}

function validateMessage(fld) {
    var error = "";
  
    if (fld.value == "" || fld.value == "Please type message here...") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a message.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    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 = '#FFFFFF';
    } 
    return error;
}

function validateStreet(fld) {
    var error = "";
  
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Street.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    return error;
}

function validateCity(fld) {
    var error = "";
  
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a City.\n";
    } else {
        fld.style.background = '#FFFFFF';
    } 
    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 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 = '#FFFFFF';
    } 
    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 = '#FFFFFF';
    }
    return error;
}
